[gnome-documents/wip/menus] Add Fullscreen and Quit menu items



commit 15523181c13f1a8ce45a49f3603749521e7ccb9b
Author: Colin Walters <walters verbum org>
Date:   Wed Nov 30 19:19:14 2011 -0500

    Add Fullscreen and Quit menu items

 src/application.js |   44 ++++++++++++++++++++++++++++++++++++++------
 src/mainWindow.js  |   12 ++++++------
 2 files changed, 44 insertions(+), 12 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 37ad66f..7ff9227 100644
--- a/src/application.js
+++ b/src/application.js
@@ -21,6 +21,7 @@
 
 const Lang = imports.lang;
 const Gettext = imports.gettext;
+const _ = imports.gettext.gettext;
 
 const GtkClutter = imports.gi.GtkClutter;
 const EvDoc = imports.gi.EvinceDocument;
@@ -56,6 +57,12 @@ function Application() {
 
 Application.prototype = {
     _init: function() {
+        Gettext.bindtextdomain('gnome-documents', Path.LOCALE_DIR);
+        Gettext.textdomain('gnome-documents');
+        GLib.set_prgname('gnome-documents');
+
+        Global.settings = new Gio.Settings({ schema: 'org.gnome.documents' });
+
         // TODO: subclass Gtk.Application once we support GObject inheritance,
         //       see https://bugzilla.gnome.org/show_bug.cgi?id=663492
         this.application = new Gtk.Application({
@@ -66,20 +73,46 @@ Application.prototype = {
             function() {
                 this._mainWindow.window.present();
             }));
+	this._actionGroup = new Gio.SimpleActionGroup();
+	this._menu = new Gio.Menu();
+	// this._viewAs = Gio.SimpleAction.new_stateful("view-as-list",
+	// 					     GLib.VariantType.new("b"),
+	// 					     Global.settings.get_value('list-view'));
+	// this._viewAs.connect('activate', Lang.bind(this, function () {
+	//     Global.settings.set_boolean('list-view', this._viewAs.state);
+	// }));
+	// this._actionGroup.insert(this._viewAs);
+	this._fullscreen = false;
+	this._fullscreenAction = new Gio.SimpleAction({ name: 'fullscreen'  });
+	this._fullscreenAction.connect('activate', Lang.bind(this, function() {
+	    this._fullscreen = !this._fullscreen;
+	    if (this._fullscreen)
+		this._mainWindow.window.fullscreen();
+	    else
+		this._mainWindow.window.unfullscreen();
+	}));
+	this._actionGroup.insert(this._fullscreenAction);
+	this._menu.append(_('Fullscreen'), "app.fullscreen");
+
+	this._quitAction = new Gio.SimpleAction({ name: 'quit' });
+	this._quitAction.connect('activate', Lang.bind(this, function() {
+	    this.application.release();
+	}));
+	this._actionGroup.insert(this._quitAction);
+	this._menu.append(_('Quit'), "app.quit");
+
+	this.application.set_action_group(this._actionGroup);
+	this.application.set_menu(this._menu);
     },
 
     _onStartup: function() {
-        Gettext.bindtextdomain('gnome-documents', Path.LOCALE_DIR);
-        Gettext.textdomain('gnome-documents');
         String.prototype.format = Format.format;
 
-        GLib.set_prgname('gnome-documents');
         GtkClutter.init(null, null);
         EvDoc.init();
         Tweener.init();
 
         Global.application = this;
-        Global.settings = new Gio.Settings({ schema: 'org.gnome.documents' });
         Global.offsetController = new OffsetController.OffsetController();
         Global.searchController = new Searchbar.SearchController();
         Global.errorHandler = new Error.ErrorHandler();
@@ -112,7 +145,6 @@ Application.prototype = {
         Global.selectionController = new Selections.SelectionController();
         Global.modeController = new WindowMode.ModeController();
 
-        this._mainWindow = new MainWindow.MainWindow();
-        this.application.add_window(this._mainWindow.window);
+        this._mainWindow = new MainWindow.MainWindow(this.application);
     }
 };
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 762f8a5..b9c5857 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -39,17 +39,17 @@ const _ = imports.gettext.gettext;
 
 const _CONFIGURE_ID_TIMEOUT = 100; // msecs
 
-function MainWindow() {
-    this._init();
+function MainWindow(app) {
+    this._init(app);
 }
 
 MainWindow.prototype = {
-    _init: function() {
+    _init: function(app) {
         this._configureId = 0;
 
-        this.window = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL,
-                                       window_position: Gtk.WindowPosition.CENTER,
-                                       title: _("Documents") });
+        this.window = new Gtk.ApplicationWindow({ application: app,
+						  window_position: Gtk.WindowPosition.CENTER,
+						  title: _("Documents") });
         this._clutterEmbed = new GtkClutter.Embed();
         this.window.add(this._clutterEmbed);
         this._clutterEmbed.show();



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