Merge lp:~ricotz/slingshot/static-appentry-menu into lp:~elementary-pantheon/slingshot/trunk

Proposed by Rico Tzschichholz on 2015-02-16
Status: Merged
Approved by: Cody Garver on 2015-02-17
Approved revision: 505
Merged at revision: 506
Proposed branch: lp:~ricotz/slingshot/static-appentry-menu
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 62 lines (+16/-11)
1 file modified
src/Widgets/AppEntry.vala (+16/-11)
To merge this branch: bzr merge lp:~ricotz/slingshot/static-appentry-menu
Reviewer Review Type Date Requested Status
elementary Pantheon team 2015-02-16 Pending
Review via email: mp+249873@code.launchpad.net

Commit message

appentry: Use one Gtk.Menu which gets created on demand

Description of the change

appentry: Use one Gtk.Menu which gets created on demand

To post a comment you must log in.
Rory (roryj) wrote :

Doesn't something like this make more sense? Otherwise you are creating a menu everytime that a button is pressed while hovering it.

        this.button_press_event.connect ((e) => {
            if (e.button != Gdk.BUTTON_SECONDARY)
                return false;

            create_menu ();
            if (menu != null && menu.get_children () != null) {
                menu.popup (null, null, null, e.button, e.time);
                return true;
            }

            return false;
        });

505. By Rico Tzschichholz on 2015-02-16

appentry: Use one Gtk.Menu which gets created on demand

Rico Tzschichholz (ricotz) wrote :

This makes absolute sense!

> Doesn't something like this make more sense? Otherwise you are creating a menu
> everytime that a button is pressed while hovering it.
>
> this.button_press_event.connect ((e) => {
> if (e.button != Gdk.BUTTON_SECONDARY)
> return false;
>
> create_menu ();
> if (menu != null && menu.get_children () != null) {
> menu.popup (null, null, null, e.button, e.time);
> return true;
> }
>
> return false;
> });

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/AppEntry.vala'
2--- src/Widgets/AppEntry.vala 2015-02-01 22:32:07 +0000
3+++ src/Widgets/AppEntry.vala 2015-02-16 22:09:28 +0000
4@@ -17,6 +17,8 @@
5 //
6
7 public class Slingshot.Widgets.AppEntry : Gtk.Button {
8+ private static Gtk.Menu menu;
9+
10 public Gtk.Label app_label;
11 private Gdk.Pixbuf icon;
12 private new Gtk.Image image;
13@@ -32,7 +34,6 @@
14 private bool dragging = false; //prevent launching
15
16 private Backend.App application;
17- private Gtk.Menu menu;
18
19 public AppEntry (Backend.App app) {
20 Gtk.TargetEntry dnd = {"text/uri-list", 0, 0};
21@@ -74,18 +75,14 @@
22 add (grid);
23 set_size_request (Pixels.ITEM_SIZE, Pixels.ITEM_SIZE);
24
25- menu = new Gtk.Menu ();
26- create_menu ();
27-
28 this.clicked.connect (launch_app);
29- // Showing a menu reverts the effect of the grab_device function.
30- menu.hide.connect (() => {
31- var slingshot_app = (Gtk.Application) GLib.Application.get_default ();
32- ((SlingshotView)slingshot_app.active_window).grab_device ();
33- });
34
35 this.button_press_event.connect ((e) => {
36- if (e.button == Gdk.BUTTON_SECONDARY && menu.get_children ().length () > 0) {
37+ if (e.button != Gdk.BUTTON_SECONDARY)
38+ return false;
39+
40+ create_menu ();
41+ if (menu != null && menu.get_children () != null) {
42 menu.popup (null, null, null, e.button, e.time);
43 return true;
44 }
45@@ -139,8 +136,16 @@
46 }
47 }
48
49+ menu = new Gtk.Menu ();
50+
51+ // Showing a menu reverts the effect of the grab_device function.
52+ menu.hide.connect (() => {
53+ var slingshot_app = (Gtk.Application) GLib.Application.get_default ();
54+ ((SlingshotView)slingshot_app.active_window).grab_device ();
55+ });
56+
57 foreach (var action in application.actions) {
58- var menuitem = new Gtk.MenuItem.with_label (action);
59+ var menuitem = new Gtk.MenuItem.with_mnemonic (action);
60 menu.add (menuitem);
61
62 menuitem.activate.connect (() => {

Subscribers

People subscribed via source and target branches