Permalink
Browse files

Add delete page action.

  • Loading branch information...
1 parent cbbb352 commit 4e5366c4b84b5b165cb0bd7594c9260d4a117f0a @pcapriotti committed Mar 14, 2010
Showing with 51 additions and 6 deletions.
  1. +2 −0 hikkiui.rc
  2. +30 −0 mainwindow.cpp
  3. +2 −0 mainwindow.h
  4. +8 −0 note.cpp
  5. +1 −0 note.h
  6. +7 −6 notebook.cpp
  7. +1 −0 notebook.h
View
@@ -4,6 +4,7 @@
<Menu name="file">
<Action name="edit_mode"/>
<Action name="display_mode"/>
+ <Action name="delete_note"/>
</Menu>
<Menu name="go">
<Text>&amp;Go</Text>
@@ -24,5 +25,6 @@
<Action name="go_home"/>
<Action name="back"/>
<Action name="forward"/>
+ <Action name="delete_note"/>
</ToolBar>
</kpartgui>
View
@@ -25,10 +25,12 @@
#include <QStackedWidget>
#include <QWebView>
+#include <QWebHistory>
#include <KAction>
#include <KActionCollection>
#include <QDebug>
#include <KLocalizedString>
+#include <KMessageBox>
#include <KTextEditor/EditorChooser>
#include <KTextEditor/ConfigInterface>
#include <KTextEditor/View>
@@ -124,6 +126,34 @@ void MainWindow::setupActions()
}
KStandardAction::home(this, SLOT(index()), actionCollection());
+
+ {
+ KAction* deleteAction = new KAction(
+ KIcon("list-remove"),
+ i18n("&Delete note"),
+ this);
+ actionCollection()->addAction("delete_note", deleteAction);
+ connect(deleteAction, SIGNAL(triggered()),
+ this, SLOT(deleteNote()));
+ }
+}
+
+void MainWindow::deleteNote()
+{
+ if (m_note)
+ {
+ int resp = KMessageBox::warningYesNo(this,
+ i18n("Are you sure you want to delete note <em>%1</em>?",
+ m_note->name()),
+ i18n("Confirm delete"));
+ if (resp == KMessageBox::Yes)
+ {
+ if (m_editor->document()->url().isValid())
+ m_editor->document()->closeUrl();
+ m_note->remove();
+ m_browser->view()->page()->history()->back();
+ }
+ }
}
void MainWindow::index()
View
@@ -24,6 +24,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
+#include <QList>
#include <QWidget>
#include <KParts/MainWindow>
#include "notebook.h"
@@ -63,6 +64,7 @@ public slots:
void editMode();
void displayMode();
void index();
+ void deleteNote();
void renderCurrentNote();
void noteChanged(const QString& path);
View
@@ -108,3 +108,11 @@ QString Note::name() const
return m_name;
}
+void Note::remove()
+{
+ // remove note
+ QFile(path()).remove();
+
+ // remove rendered
+ QFile(m_parent->renderedNotePath(m_name)).remove();
+}
View
1 note.h
@@ -39,6 +39,7 @@ class Note
QString path() const;
bool exists() const;
QString name() const;
+ void remove();
};
#endif // NOTE_H
View
@@ -37,12 +37,10 @@ Notebook::Notebook(const QString& base)
if (!m_base.exists())
kError() << "Invalid notebook directory" << base;
- kDebug() << "directory" << m_render_dir.name();
}
NotePtr Notebook::open(const QString& note)
{
- kDebug() << note;
return NotePtr(new Note(note, this));
}
@@ -60,16 +58,19 @@ NotePtr Notebook::openFromRendered(const QString& renderedFile)
{
QString rel = m_base.relativeFilePath(renderedFile);
QString note = QFileInfo(rel).baseName();
- kDebug() << note;
return open(note);
}
+QString Notebook::renderedNotePath(const QString& note)
+{
+ QString path = QFileInfo(m_render_dir.name(), note).absoluteFilePath();
+ return path + ".html";
+}
+
QString Notebook::saveRenderedNote(const QString& note,
const QString& content)
{
- kDebug() << note;
- QString path = QFileInfo(m_render_dir.name(), note).absoluteFilePath();
- path = path + ".html";
+ QString path = renderedNotePath(note);
QFile file(path);
if (file.open(QIODevice::WriteOnly)) {
file.write(m_header.toUtf8());
View
@@ -48,6 +48,7 @@ class Notebook
QString notePath(const QString& note) const;
QString saveRenderedNote(const QString& note,
const QString& content);
+ QString renderedNotePath(const QString& note);
};
#endif // NOTEBOOK_H

0 comments on commit 4e5366c

Please sign in to comment.