Merge lp:~moimael/simple-scan/app-menu into lp:~simple-scan-team/simple-scan/trunk

Proposed by moimael
Status: Merged
Merged at revision: 677
Proposed branch: lp:~moimael/simple-scan/app-menu
Merge into: lp:~simple-scan-team/simple-scan/trunk
Diff against target: 354 lines (+188/-13)
5 files modified
data/Makefile.am (+1/-0)
data/simple-scan-menu.ui (+62/-0)
data/simple-scan.gresource.xml (+1/-0)
data/simple-scan.ui (+1/-1)
src/ui.vala (+123/-12)
To merge this branch: bzr merge lp:~moimael/simple-scan/app-menu
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+200076@code.launchpad.net

Description of the change

Add an app menu for gnome-shell.

To post a comment you must log in.
lp:~moimael/simple-scan/app-menu updated
679. By moimael

Standardize Help/About/Quit

680. By moimael

Add accelerators back to app menu

Revision history for this message
Robert Ancell (robert-ancell) wrote :

I'm not 100% sure on the logic on showing the app menu, but works well.

Pushed with minor style changes, thanks!

review: Approve
Revision history for this message
moimael (moimael) wrote :

I took the logic from gedit so it should be ok :)

Please take a look on the bug report, there is a one liner patch you should apply to fix scrollbar (was introduced by the cleanup).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/Makefile.am'
2--- data/Makefile.am 2013-09-03 00:57:48 +0000
3+++ data/Makefile.am 2014-01-01 22:44:25 +0000
4@@ -16,6 +16,7 @@
5 EXTRA_DIST = simple-scan.desktop.in \
6 org.gnome.SimpleScan.gschema.xml.in \
7 simple-scan.ui \
8+ simple-scan-menu.ui \
9 simple-scan.gresource.xml
10
11 DISTCLEANFILES = \
12
13=== added file 'data/simple-scan-menu.ui'
14--- data/simple-scan-menu.ui 1970-01-01 00:00:00 +0000
15+++ data/simple-scan-menu.ui 2014-01-01 22:44:25 +0000
16@@ -0,0 +1,62 @@
17+<?xml version="1.0"?>
18+<interface>
19+ <!-- interface-requires gtk+ 3.8 -->
20+ <menu id="appmenu">
21+ <section>
22+ <item>
23+ <attribute name="label" translatable="yes">New Document</attribute>
24+ <attribute name="action">app.new_document</attribute>
25+ <attribute name="accel"><![CDATA[<Ctrl>N]]></attribute>
26+ </item>
27+ </section>
28+ <section>
29+ <submenu>
30+ <attribute name="label" translatable="yes">Document</attribute>
31+ <section>
32+ <item>
33+ <attribute name="label" translatable="yes">Save</attribute>
34+ <attribute name="action">app.save</attribute>
35+ <attribute name="accel"><![CDATA[<Ctrl>S]]></attribute>
36+ </item>
37+ <item>
38+ <attribute name="label" translatable="yes">Save As...</attribute>
39+ <attribute name="action">app.save_as</attribute>
40+ <attribute name="accel"><![CDATA[<Shift><Ctrl>S]]></attribute>
41+ </item>
42+ <item>
43+ <attribute name="label" translatable="yes">Email...</attribute>
44+ <attribute name="action">app.email</attribute>
45+ <attribute name="accel"><![CDATA[<Ctrl>E]]></attribute>
46+ </item>
47+ <item>
48+ <attribute name="label" translatable="yes">Print...</attribute>
49+ <attribute name="action">app.print</attribute>
50+ <attribute name="accel"><![CDATA[<Ctrl>P]]></attribute>
51+ </item>
52+ </section>
53+ </submenu>
54+ </section>
55+ <section>
56+ <item>
57+ <attribute name="label" translatable="yes">Preferences</attribute>
58+ <attribute name="action">app.preferences</attribute>
59+ </item>
60+ </section>
61+ <section>
62+ <item>
63+ <attribute name="label" translatable="yes">Help</attribute>
64+ <attribute name="action">app.help</attribute>
65+ <attribute name="accel"><![CDATA[F1]]></attribute>
66+ </item>
67+ <item>
68+ <attribute name="label" translatable="yes">About</attribute>
69+ <attribute name="action">app.about</attribute>
70+ </item>
71+ <item>
72+ <attribute name="label" translatable="yes">Quit</attribute>
73+ <attribute name="action">app.quit</attribute>
74+ <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
75+ </item>
76+ </section>
77+ </menu>
78+</interface>
79
80=== modified file 'data/simple-scan.gresource.xml'
81--- data/simple-scan.gresource.xml 2013-04-18 08:49:12 +0000
82+++ data/simple-scan.gresource.xml 2014-01-01 22:44:25 +0000
83@@ -2,5 +2,6 @@
84 <gresources>
85 <gresource prefix="/org/gnome/SimpleScan">
86 <file preprocess="xml-stripblanks">simple-scan.ui</file>
87+ <file preprocess="xml-stripblanks">simple-scan-menu.ui</file>
88 </gresource>
89 </gresources>
90
91=== modified file 'data/simple-scan.ui'
92--- data/simple-scan.ui 2013-12-17 21:00:01 +0000
93+++ data/simple-scan.ui 2014-01-01 22:44:25 +0000
94@@ -240,7 +240,7 @@
95 <property name="step_increment">1</property>
96 <property name="page_increment">10</property>
97 </object>
98- <object class="GtkWindow" id="simple_scan_window">
99+ <object class="GtkApplicationWindow" id="simple_scan_window">
100 <property name="can_focus">False</property>
101 <property name="title" translatable="yes" comments="Title of scan window">Simple Scan</property>
102 <property name="icon_name">scanner</property>
103
104=== modified file 'src/ui.vala'
105--- src/ui.vala 2013-11-24 21:28:01 +0000
106+++ src/ui.vala 2014-01-01 22:44:25 +0000
107@@ -14,11 +14,26 @@
108 private const int DEFAULT_TEXT_DPI = 150;
109 private const int DEFAULT_PHOTO_DPI = 300;
110
111+ private const GLib.ActionEntry[] action_entries =
112+ {
113+ { "new_document", new_document_activate_cb },
114+ { "save", save_document_activate_cb },
115+ { "save_as", save_as_document_activate_cb },
116+ { "email", email_document_activate_cb },
117+ { "print", print_document_activate_cb },
118+ { "preferences", preferences_activate_cb },
119+ { "help", help_contents_activate_cb },
120+ { "about", about_activate_cb },
121+ { "quit", quit_activate_cb }
122+ };
123+
124 private Settings settings;
125
126 private Gtk.Builder builder;
127
128- private Gtk.Window window;
129+ private Gtk.ApplicationWindow window;
130+ private GLib.MenuModel app_menu;
131+ private Gtk.MenuBar menubar;
132 private Gtk.Box main_vbox;
133 private Gtk.InfoBar info_bar;
134 private Gtk.Image info_bar_image;
135@@ -607,8 +622,7 @@
136 copy_to_clipboard_menuitem.set_sensitive (false);
137 }
138
139- [CCode (cname = "G_MODULE_EXPORT new_button_clicked_cb", instance_pos = -1)]
140- public void new_button_clicked_cb (Gtk.Widget widget)
141+ private void new_document ()
142 {
143 if (!prompt_to_save (/* Text in dialog warning when a document is about to be lost */
144 _("Save current document?"),
145@@ -621,6 +635,17 @@
146 clear_document ();
147 }
148
149+ [CCode (cname = "G_MODULE_EXPORT new_button_clicked_cb", instance_pos = -1)]
150+ public void new_button_clicked_cb (Gtk.Widget widget)
151+ {
152+ new_document();
153+ }
154+
155+ public void new_document_activate_cb ()
156+ {
157+ new_document();
158+ }
159+
160 private void set_document_hint (string document_hint)
161 {
162 this.document_hint = document_hint;
163@@ -793,6 +818,11 @@
164 preferences_dialog.present ();
165 }
166
167+ public void preferences_activate_cb ()
168+ {
169+ preferences_dialog.present ();
170+ }
171+
172 [CCode (cname = "G_MODULE_EXPORT preferences_dialog_delete_event_cb", instance_pos = -1)]
173 public bool preferences_dialog_delete_event_cb (Gtk.Widget widget)
174 {
175@@ -1061,6 +1091,11 @@
176 save_document (false);
177 }
178
179+ public void save_document_activate_cb ()
180+ {
181+ save_document (false);
182+ }
183+
184 [CCode (cname = "G_MODULE_EXPORT copy_to_clipboard_button_clicked_cb", instance_pos = -1)]
185 public void copy_to_clipboard_button_clicked_cb (Gtk.Widget widget)
186 {
187@@ -1075,6 +1110,11 @@
188 save_document (true);
189 }
190
191+ public void save_as_document_activate_cb ()
192+ {
193+ save_document (true);
194+ }
195+
196 private void draw_page (Gtk.PrintOperation operation,
197 Gtk.PrintContext print_context,
198 int page_number)
199@@ -1106,8 +1146,12 @@
200 email (document_hint, quality);
201 }
202
203- [CCode (cname = "G_MODULE_EXPORT print_button_clicked_cb", instance_pos = -1)]
204- public void print_button_clicked_cb (Gtk.Widget widget)
205+ public void email_document_activate_cb ()
206+ {
207+ email (document_hint, quality);
208+ }
209+
210+ private void print_document ()
211 {
212 var print = new Gtk.PrintOperation ();
213 print.set_n_pages ((int) book.n_pages);
214@@ -1125,8 +1169,18 @@
215 print.draw_page.disconnect (draw_page);
216 }
217
218- [CCode (cname = "G_MODULE_EXPORT help_contents_menuitem_activate_cb", instance_pos = -1)]
219- public void help_contents_menuitem_activate_cb (Gtk.Widget widget)
220+ [CCode (cname = "G_MODULE_EXPORT print_button_clicked_cb", instance_pos = -1)]
221+ public void print_button_clicked_cb (Gtk.Widget widget)
222+ {
223+ print_document ();
224+ }
225+
226+ public void print_document_activate_cb ()
227+ {
228+ print_document ();
229+ }
230+
231+ private void show_help ()
232 {
233 try
234 {
235@@ -1140,8 +1194,18 @@
236 }
237 }
238
239- [CCode (cname = "G_MODULE_EXPORT about_menuitem_activate_cb", instance_pos = -1)]
240- public void about_menuitem_activate_cb (Gtk.Widget widget)
241+ [CCode (cname = "G_MODULE_EXPORT help_contents_menuitem_activate_cb", instance_pos = -1)]
242+ public void help_contents_menuitem_activate_cb (Gtk.Widget widget)
243+ {
244+ show_help ();
245+ }
246+
247+ public void help_contents_activate_cb ()
248+ {
249+ show_help ();
250+ }
251+
252+ private void show_about ()
253 {
254 string[] authors = { "Robert Ancell <robert.ancell@canonical.com>" };
255
256@@ -1169,6 +1233,17 @@
257 null);
258 }
259
260+ [CCode (cname = "G_MODULE_EXPORT about_menuitem_activate_cb", instance_pos = -1)]
261+ public void about_menuitem_activate_cb (Gtk.Widget widget)
262+ {
263+ show_about ();
264+ }
265+
266+ public void about_activate_cb ()
267+ {
268+ show_about ();
269+ }
270+
271 private bool on_quit ()
272 {
273 if (!prompt_to_save (/* Text in dialog warning when a document is about to be lost */
274@@ -1213,6 +1288,11 @@
275 on_quit ();
276 }
277
278+ public void quit_activate_cb ()
279+ {
280+ on_quit ();
281+ }
282+
283 [CCode (cname = "G_MODULE_EXPORT simple_scan_window_configure_event_cb", instance_pos = -1)]
284 public bool simple_scan_window_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
285 {
286@@ -1333,16 +1413,40 @@
287 copy_to_clipboard_menuitem.set_sensitive (true);
288 }
289
290+ private bool simple_scan_has_app_menu (Gtk.Application app)
291+ {
292+ Gtk.Settings gtk_settings;
293+ bool show_app_menu = false;
294+ bool show_menubar = true;
295+
296+ /* We have three cases:
297+ * - GNOME 3: show-app-menu true, show-menubar false -> use the app menu
298+ * - Unity, OSX: show-app-menu and show-menubar true -> use the normal menu
299+ * - Other WM, Windows: show-app-menu and show-menubar false -> use the normal menu
300+ */
301+ gtk_settings = Gtk.Settings.get_default ();
302+
303+ gtk_settings.get ("gtk-shell-shows-app-menu", &show_app_menu, "gtk-shell-shows-menubar", &show_menubar, null);
304+
305+ return show_app_menu && !show_menubar;
306+ }
307+
308 private void load ()
309 {
310 Gtk.IconTheme.get_default ().append_search_path (ICON_DIR);
311
312 Gtk.Window.set_default_icon_name ("scanner");
313
314+ var app = Application.get_default () as Gtk.Application;
315+
316 builder = new Gtk.Builder ();
317 try
318 {
319 builder.add_from_resource ("/org/gnome/SimpleScan/simple-scan.ui");
320+ if (simple_scan_has_app_menu (app))
321+ {
322+ builder.add_from_resource ("/org/gnome/SimpleScan/simple-scan-menu.ui");
323+ }
324 }
325 catch (Error e)
326 {
327@@ -1355,9 +1459,16 @@
328 }
329 builder.connect_signals (this);
330
331- window = (Gtk.Window) builder.get_object ("simple_scan_window");
332- var app = Application.get_default () as Gtk.Application;
333+ window = (Gtk.ApplicationWindow) builder.get_object ("simple_scan_window");
334 app.add_window (window);
335+ menubar = (Gtk.MenuBar) builder.get_object ("menubar");
336+ if (simple_scan_has_app_menu (app))
337+ {
338+ app_menu = (GLib.MenuModel) builder.get_object ("appmenu");
339+ app.add_action_entries (action_entries, this);
340+ app.set_app_menu (app_menu);
341+ menubar.set_visible(false);
342+ }
343 main_vbox = (Gtk.Box) builder.get_object ("main_vbox");
344 page_move_left_menuitem = (Gtk.MenuItem) builder.get_object ("page_move_left_menuitem");
345 page_move_right_menuitem = (Gtk.MenuItem) builder.get_object ("page_move_right_menuitem");
346@@ -1590,7 +1701,7 @@
347 {
348 Gtk.ProgressBar bar;
349
350- public ProgressBarDialog (Gtk.Window parent, string title)
351+ public ProgressBarDialog (Gtk.ApplicationWindow parent, string title)
352 {
353 bar = new Gtk.ProgressBar ();
354 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5);

Subscribers

People subscribed via source and target branches