[baobab/wip/new-design: 28/59] First cut at menus



commit 3927cfdcc2567e2d4e9ec59366c932ddc2902ed0
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Jan 15 14:48:18 2012 +0100

    First cut at menus

 data/Makefile.am            |    1 +
 data/baobab-menu.ui         |   37 +++++++++++++++++++++++++++++++++++++
 src/baobab-application.vala |   34 ++++++++++++++++++++++++++++++++--
 src/baobab-window.vala      |   34 ++++++++++++++++++++++++++++------
 4 files changed, 98 insertions(+), 8 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 919f6df..0e4c1d1 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,6 +1,7 @@
 uidir = $(datadir)/baobab
 ui_DATA = \
 	baobab-main-window.ui \
+	baobab-menu.ui \
 	baobab-preferences-dialog.ui
 
 baobabappdir	   = $(datadir)/applications
diff --git a/data/baobab-menu.ui b/data/baobab-menu.ui
new file mode 100644
index 0000000..20a612a
--- /dev/null
+++ b/data/baobab-menu.ui
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <menu id="appmenu">
+    <section>
+      <item label="_Help" action="app.help" accel="F1"/>
+      <item label="_About" action="app.about"/>
+      <item label="_Quit" action="app.quit" accel="&lt;Primary&gt;q"/>
+    </section>
+  </menu>
+  <menu id="menubar">
+    <submenu label="_Analyzer">
+      <section>
+        <item label="_Scan Home" action="win.scan-home" accel="&lt;Primary&gt;h"/>
+        <item label="Scan _Filesystem" action="win.scan-filesystem" accel="&lt;Primary&gt;f"/>
+        <item label="Scan F_older" action="win.scan-folder" accel="&lt;Primary&gt;o"/>
+      </section>
+    </submenu>
+    <submenu label="_View">
+      <section>
+        <item label="_Stop" action="win.stop"/>
+        <item label="_Reload" action="win.reload" accel="&lt;Primary&gt;r"/>
+      </section>
+      <section>
+        <item label="_Toolbar" action="win.show-toolbar"/>
+        <item label="_Statusbar" action="win.show-statusbar"/>
+      </section>
+      <section>
+        <item label="_Allocated Space" action="win.show-allocated"/>
+      </section>
+      <section>
+        <item label="_Expand All" action="win.expand-all"/>
+        <item label="_Collapse All" action="win.collapse-all"/>
+      </section>
+    </submenu>
+  </menu>
+</interface>
diff --git a/src/baobab-application.vala b/src/baobab-application.vala
index 06ea0a5..8f65b51 100644
--- a/src/baobab-application.vala
+++ b/src/baobab-application.vala
@@ -1,11 +1,17 @@
 namespace Baobab {
 	public class Application : Gtk.Application {
+		static Application baobab;
+
+		private const GLib.ActionEntry[] action_entries = {
+			{ "help", on_help_activate },
+			{ "about", on_about_activate },
+			{ "quit", on_quit_activate }
+		};
+
 		Settings desktop_settings;
 		Settings prefs_settings;
 		Settings ui_settings;
 
-		static Application baobab;
-
 		protected override void activate () {
 			new Window (this);
 		}
@@ -44,9 +50,22 @@ namespace Baobab {
 
 			baobab = this;
 
+			// Settings
 			ui_settings = new Settings ("org.gnome.baobab.ui");
 			prefs_settings = new Settings ("org.gnome.baobab.preferences");
 			desktop_settings = new Settings ("org.gnome.desktop.interface");
+
+			// Menus
+			var builder = new Gtk.Builder ();
+			try {
+				builder.add_from_file (Config.PKGDATADIR + "/baobab-menu.ui");
+			} catch (Error e) {
+				error ("loading menu builder file: %s", e.message);
+			}
+			var app_menu = builder.get_object ("appmenu") as MenuModel;
+			var menubar = builder.get_object ("menubar") as MenuModel;
+			set_app_menu (app_menu);
+			set_menubar (menubar);
 		}
 
 		protected override bool local_command_line ([CCode (array_length = false, array_null_terminated = true)] ref unowned string[] arguments, out int exit_status) {
@@ -61,6 +80,8 @@ namespace Baobab {
 
 		public Application () {
 			Object (application_id: "org.gnome.baobab", flags: ApplicationFlags.HANDLES_OPEN);
+
+			add_action_entries (action_entries, this);
 		}
 
 		public static Settings get_desktop_settings () {
@@ -77,5 +98,14 @@ namespace Baobab {
 			var app = baobab;
 			return app.ui_settings;
 		}
+
+		void on_help_activate () {
+		}
+
+		void on_about_activate () {
+		}
+
+		void on_quit_activate () {
+		}
 	}
 }
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 55ac367..b93a256 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -9,12 +9,17 @@ namespace Baobab {
 		static Gdk.Cursor busy_cursor;
 
 		private const GLib.ActionEntry[] action_entries = {
-			{ "scan-home",       on_scan_home_activate       },
+			{ "scan-home", on_scan_home_activate },
 			{ "scan-filesystem", on_scan_filesystem_activate },
-			{ "scan-folder",     on_scan_folder_activate     },
-			{ "scan-remote",     on_scan_remote_activate     },
-			{ "stop",            on_stop_activate            },
-			{ "refresh",         on_refresh_activate         }
+			{ "scan-folder", on_scan_folder_activate },
+			{ "scan-remote", on_scan_remote_activate },
+			{ "stop", on_stop_activate },
+			{ "reload", on_reload_activate },
+			{ "show-toolbar", on_show_toolbar },
+			{ "show-statusbar", on_show_statusbar },
+			{ "show-allocated", on_show_allocated },
+			{ "expand-all", on_expand_all },
+			{ "collapse-all", on_collapse_all }
 		};
 
 		private enum DndTargets {
@@ -107,12 +112,29 @@ namespace Baobab {
 			}
 		}
 
-		void on_refresh_activate () {
+		void on_reload_activate () {
 			if (scanner != null) {
 				scan_directory (scanner.directory);
 			}
 		}
 
+		void on_show_toolbar () {
+		}
+
+		void on_show_statusbar () {
+		}
+
+		void on_show_allocated () {
+		}
+
+		void on_expand_all () {
+			treeview.expand_all ();
+		}
+
+		void on_collapse_all () {
+			treeview.collapse_all ();
+		}
+
 		void on_drag_data_received (Gtk.Widget widget, Gdk.DragContext context, int x, int y,
 		                            Gtk.SelectionData selection_data, uint target_type, uint time) {
 			File dir = null;



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