[gnome-documents] Added a menu (open, print) to the Preview Toolbar



commit 2e8028ba2f01bc6bd845f2e70bb07fd6a8244d5b
Author: Anna Zacchi <annazacchi src gnome org>
Date:   Tue Jul 17 22:16:12 2012 +0200

    Added a menu (open, print) to the Preview Toolbar

 src/application.js        |   17 ++++++++++++++
 src/global.js             |    9 ++++++-
 src/lib/gd-main-toolbar.c |   26 +++++++++++++++++++++
 src/lib/gd-main-toolbar.h |    3 ++
 src/mainToolbar.js        |   54 ++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 107 insertions(+), 2 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 3d2f9b1..1d789f0 100644
--- a/src/application.js
+++ b/src/application.js
@@ -41,6 +41,7 @@ const GDataMiner = imports.gDataMiner;
 const Global = imports.global;
 const Main = imports.main;
 const MainWindow = imports.mainWindow;
+const MainToolbar = imports.mainToolbar;
 const Manager = imports.manager;
 const Notifications = imports.notifications;
 const Path = imports.path;
@@ -136,6 +137,22 @@ const Application = new Lang.Class({
 
         this.application.add_accelerator('<Primary>q', 'app.quit', null);
         this.application.add_accelerator('F11', 'app.fullscreen', null);
+
+        //setting actions for other menus in topBar
+        let saveAction = new Gio.SimpleAction({ name: 'open' });
+        saveAction.connect('activate', Lang.bind(this,
+                function() {
+                MainToolbar.fileOpen();
+            }));
+        this.application.add_action(saveAction);
+        
+        let openAction = new Gio.SimpleAction({ name: 'print' });
+        openAction.connect('activate', Lang.bind(this,
+                function() {
+                MainToolbar.filePrint();
+            }));
+        this.application.add_action(openAction);
+
     },
 
     _refreshMinerNow: function(miner) {
diff --git a/src/global.js b/src/global.js
index 6beddc5..a24c356 100644
--- a/src/global.js
+++ b/src/global.js
@@ -25,6 +25,10 @@ const Query = imports.query;
 const Searchbar = imports.searchbar;
 const Sources = imports.sources;
 const TrackerController = imports.trackerController;
+const EvView = imports.gi.EvinceView;//for printing
+const Notifications = imports.notifications;//for printing
+const Lang = imports.lang;//for printing
+const Gtk = imports.gi.Gtk;//for opening
 
 let application = null;
 let collectionManager = null;
@@ -44,6 +48,7 @@ let selectionController = null;
 let settings = null;
 let sourceManager = null;
 let trackerController = null;
+let screen = null;
 
 function initSearch() {
     sourceManager = new Sources.SourceManager();
@@ -57,4 +62,6 @@ function initSearch() {
     offsetController = new OffsetController.OffsetController();
     queryBuilder = new Query.QueryBuilder();
     connectionQueue = new TrackerController.TrackerConnectionQueue();
-}
+};
+
+
diff --git a/src/lib/gd-main-toolbar.c b/src/lib/gd-main-toolbar.c
index f6d132c..349bf79 100644
--- a/src/lib/gd-main-toolbar.c
+++ b/src/lib/gd-main-toolbar.c
@@ -291,3 +291,29 @@ gd_main_toolbar_add_button (GdMainToolbar *self,
 
   return button;
 }
+
+/**
+ * gd_main_toolbar_add_menu:
+ * @self:
+ * @pack_start:
+ *
+ * Returns: (transfer none):
+ */
+GtkWidget *
+gd_main_toolbar_add_menu (GdMainToolbar *self,
+                            gboolean pack_start)
+{
+  GtkWidget *menuButton;
+
+  menuButton = gtk_menu_button_new ();
+
+  if (pack_start)
+    gtk_container_add (GTK_CONTAINER (self->priv->left_grid), menuButton);
+  else
+    gtk_container_add (GTK_CONTAINER (self->priv->right_grid), menuButton);
+
+  gtk_widget_show_all (menuButton);
+
+  return menuButton;
+}
+
diff --git a/src/lib/gd-main-toolbar.h b/src/lib/gd-main-toolbar.h
index 5244d5e..6506394 100644
--- a/src/lib/gd-main-toolbar.h
+++ b/src/lib/gd-main-toolbar.h
@@ -81,6 +81,9 @@ GtkWidget * gd_main_toolbar_add_button (GdMainToolbar *self,
                                         const gchar *label,
                                         gboolean pack_start);
 
+GtkWidget * gd_main_toolbar_add_menu (GdMainToolbar *self,
+                                        gboolean pack_start);
+
 G_END_DECLS
 
 #endif /* __GD_MAIN_TOOLBAR_H__ */
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index 2aa1b04..c7822e2 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -38,6 +38,9 @@ const Searchbar = imports.searchbar;
 const Tweener = imports.util.tweener;
 const WindowMode = imports.windowMode;
 
+const EvView = imports.gi.EvinceView;//for printing
+const Notifications = imports.notifications;//for printing
+
 const MainToolbar = new Lang.Class({
     Name: 'MainToolbar',
 
@@ -231,6 +234,7 @@ const MainToolbar = new Lang.Class({
     },
 
     _populateForPreview: function(model) {
+        //back button, on the left of the toolbar
         let iconName =
             (this.widget.get_direction() == Gtk.TextDirection.RTL) ?
             'go-next-symbolic' : 'go-previous-symbolic';
@@ -241,6 +245,15 @@ const MainToolbar = new Lang.Class({
             function() {
                 Global.documentManager.setActiveItem(null);
             }));
+        
+        //menu button, on the right of the toolbar (false)
+        this._menuButton = 
+            this.widget.add_menu( false );
+        this._initMenus();
+        let menu = new Gtk.Menu.new_from_model(this.menuModel);
+        menu.show();
+        this._menuButton.set_menu( menu );
+        Global.screen = this.widget.get_screen();
     },
 
     _populateForOverview: function() {
@@ -306,7 +319,16 @@ const MainToolbar = new Lang.Class({
             }));
 
         this._setToolbarTitle();
-    }
+    },
+    
+    _initMenus: function() {
+        this.menuModel = new Gio.Menu(); 
+  
+        let menuItemOpen = Gio.MenuItem.new(_("Open"), 'app.open');
+        let menuItemPrint = Gio.MenuItem.new(_("Print"), 'app.print');
+        this.menuModel.append_item(menuItemOpen);
+        this.menuModel.append_item(menuItemPrint);
+    },
 });
 
 const PreviewToolbar = new Lang.Class({
@@ -359,3 +381,33 @@ const OverviewToolbar = new Lang.Class({
             this.searchbar.show();
     }
 });
+
+function fileOpen(screen) {
+    print ("No fileOpen here.  This is temp.");
+    let doc = Global.documentManager.getActiveItem();
+    //let doc = documentManager.getActiveItem();
+    doc.open(Global.screen, Gtk.get_current_event_time());
+    
+};
+
+/**
+ * Prints the current document
+ */
+function filePrint() {
+    print ("No filePrint here.  This is temp.");
+    let doc = Global.documentManager.getActiveItem();
+    //let doc = documentManager.getActiveItem();
+    doc.load(null, Lang.bind(this,
+            function(doc, evDoc, error) {
+                if (!evDoc) {
+                    // TODO: handle error here!
+                    return;
+                }
+
+                let printOp = EvView.PrintOperation.new(evDoc);
+                let printNotification = new Notifications.PrintNotification(printOp, doc);
+
+                let toplevel = this.widget.get_toplevel();
+                printOp.run(toplevel);
+            }));
+};



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]