[passepartout] added recent files support
- From: Sven Herzberg <herzi src gnome org>
- To: svn-commits-list gnome org
- Subject: [passepartout] added recent files support
- Date: Mon, 13 Apr 2009 09:38:47 -0400 (EDT)
commit 6341f2069fae9fae8e4456e33c5262c0a2e59c63
Author: Sven Herzberg <herzi lanedo com>
Date: Mon Apr 13 11:23:55 2009 +0200
added recent files support
* src/pptout/document/document.cc: tell the recent files manager when we've
opened or saved a file
* src/pptout/window.cc,
* src/pptout/window.h: added a recent file handler
* src/pptout/windowmenus.cc: added a recent files submenu menu
---
src/pptout/document/document.cc | 10 ++++++++++
src/pptout/window.cc | 10 ++++++++++
src/pptout/window.h | 2 ++
src/pptout/windowmenus.cc | 17 +++++++++++++++--
4 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/pptout/document/document.cc b/src/pptout/document/document.cc
index 08280f4..700b21c 100644
--- a/src/pptout/document/document.cc
+++ b/src/pptout/document/document.cc
@@ -9,6 +9,9 @@
#include <libxml++/libxml++.h>
+#include <glib.h>
+#include <gtkmm/recentmanager.h>
+
#include "document.h"
#include "fileerrors.h"
#include "page.h"
@@ -362,6 +365,10 @@ void Document::open(const std::string &filename) {
xml_open(ElementWrap(filename, *rootnode));
else
throw std::runtime_error("No such file or no rootnode");
+
+ g_return_if_fail (g_path_is_absolute (filename.c_str()));
+ Glib::RefPtr<Gtk::RecentManager> manager = Gtk::RecentManager::get_default();
+ manager->add_item ("file://" + filename);
}
catch(const xmlpp::exception& e) {
throw OpenFailed(filename, e); /// \todo Signify the "bad xml" level?
@@ -375,6 +382,9 @@ void Document::save(const std::string &filename) {
try {
std::auto_ptr<xmlpp::Document> tree(xml_save(FileContext(filename)));
tree->write_to_file_formatted(filename);
+ g_return_if_fail (g_path_is_absolute (filename.c_str()));
+ Glib::RefPtr<Gtk::RecentManager> manager = Gtk::RecentManager::get_default();
+ manager->add_item ("file://" + filename);
}
catch (const xmlpp::exception& err) {
throw UserError("Failed to write " + filename, err);
diff --git a/src/pptout/window.cc b/src/pptout/window.cc
index 4be07bc..fede6cc 100644
--- a/src/pptout/window.cc
+++ b/src/pptout/window.cc
@@ -72,6 +72,16 @@ bool FrameWindow::on_key_press_event (GdkEventKey* event)
return Gtk::Window::on_key_press_event (event);
}
+void FrameWindow::on_recent_file (const Glib::RefPtr<Gtk::RecentAction>& recent)
+{
+ Glib::ustring path = Glib::filename_from_uri (recent->get_current_item()->get_uri());
+ if(document_view.get_document())
+ new FrameWindow(path);
+ else {
+ document_view.set_document (DocMeta(Document::create(path, false), path));
+ }
+}
+
void FrameWindow::constructor_common() {
open_dialog.reset(new Filesel(*this, _("Open")));
save_dialog.reset(new Filesel(*this, _("Save As"),
diff --git a/src/pptout/window.h b/src/pptout/window.h
index 38ee541..250976a 100644
--- a/src/pptout/window.h
+++ b/src/pptout/window.h
@@ -51,6 +51,8 @@ private:
bool on_focus_in_event(GdkEventFocus*);
bool on_key_press_event(GdkEventKey*);
+ void on_recent_file (const Glib::RefPtr<Gtk::RecentAction>& recent);
+
void constructor_common();
void set_filename(const Glib::ustring&);
diff --git a/src/pptout/windowmenus.cc b/src/pptout/windowmenus.cc
index e333c11..6779e9a 100644
--- a/src/pptout/windowmenus.cc
+++ b/src/pptout/windowmenus.cc
@@ -154,7 +154,19 @@ void FrameWindow::create_menus() {
main_group->add(Action::create("FileOpen", Stock::OPEN, _("_Open ..."),
_("Open a document")),
mem_fun(*open_dialog, &Filesel::show_all));
-
+
+ Glib::RefPtr<RecentAction> action = RecentAction::create ("FileOpenRecent",
+ _("Open _recent file"),
+ _("Open one of these recently opened files"));
+ action->set_show_numbers (true);
+ action->set_local_only ();
+ RecentFilter* filter = Gtk::manage(new RecentFilter);
+ filter->add_mime_type ("application/x-passepartout");
+ action->add_filter (*filter);
+ main_group->add (action);
+ action->signal_item_activated ().connect (bind (mem_fun (*this, &FrameWindow::on_recent_file),
+ action));
+
doc_group->add(Action::create("FileSave", Stock::SAVE, _("_Save ..."),
_("Save document")),
mem_fun(*this, &FrameWindow::save));
@@ -179,7 +191,7 @@ void FrameWindow::create_menus() {
_("Document properties")),
AccelKey("<Mod1>Return"),
bind(sigc::ptr_fun(&show_doc_props_dialog), &document_view));
-
+
main_group->add(Action::create("FileClose", Stock::CLOSE),
mem_fun(*this, &FrameWindow::close));
@@ -346,6 +358,7 @@ void FrameWindow::create_menus() {
" <menuitem action='FileNew'/>"
" <menuitem action='FileNewView'/>"
" <menuitem action='FileOpen'/>"
+ " <menuitem action='FileOpenRecent'/>"
" <separator/>"
" <menuitem action='FileSave'/>"
" <menuitem action='FileSaveAs'/>"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]