[gnome-flashback] desktop: add right click menus



commit 29408d96270a748eef601d0dba7736306e483ec8
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Nov 11 22:05:56 2019 +0200

    desktop: add right click menus

 gnome-flashback/libdesktop/gf-icon-view.c | 75 ++++++++++++++++++++++++++++++-
 gnome-flashback/libdesktop/gf-icon.c      | 46 +++++++++++++++++++
 po/POTFILES.in                            |  2 +
 3 files changed, 121 insertions(+), 2 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index c31a379..28d9f3b 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -18,6 +18,8 @@
 #include "config.h"
 #include "gf-icon-view.h"
 
+#include <glib/gi18n.h>
+
 #include "gf-desktop-enum-types.h"
 #include "gf-icon.h"
 #include "gf-monitor-view.h"
@@ -371,6 +373,69 @@ desktop_changed_cb (GFileMonitor      *monitor,
     }
 }
 
+static void
+open_terminal_cb (GtkMenuItem *item,
+                  GfIconView  *self)
+{
+  GError *error;
+
+  error = NULL;
+  if (!gf_launch_desktop_file ("org.gnome.Terminal.desktop", &error))
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+    }
+}
+
+static void
+change_background_cb (GtkMenuItem *item,
+                      GfIconView  *self)
+{
+  GError *error;
+
+  error = NULL;
+  if (!gf_launch_desktop_file ("gnome-background-panel.desktop", &error))
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+    }
+}
+
+static GtkWidget *
+create_popup_menu (GfIconView *self)
+{
+  GtkWidget *popup_menu;
+  GtkStyleContext *context;
+  GtkWidget *item;
+
+  popup_menu = gtk_menu_new ();
+
+  context = gtk_widget_get_style_context (popup_menu);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_CONTEXT_MENU);
+
+  item = gtk_menu_item_new_with_label (_("Open Terminal"));
+  gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
+  gtk_widget_show (item);
+
+  g_signal_connect (item, "activate",
+                    G_CALLBACK (open_terminal_cb),
+                    self);
+
+  item = gtk_separator_menu_item_new ();
+  gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
+  gtk_widget_show (item);
+
+  item = gtk_menu_item_new_with_label (_("Change Background"));
+  gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
+  gtk_widget_show (item);
+
+  g_signal_connect (item, "activate",
+                    G_CALLBACK (change_background_cb),
+                    self);
+
+  return popup_menu;
+}
+
 static void
 multi_press_pressed_cb (GtkGestureMultiPress *gesture,
                         gint                  n_press,
@@ -389,13 +454,19 @@ multi_press_pressed_cb (GtkGestureMultiPress *gesture,
   if (event == NULL)
     return;
 
-  unselect_icons (self);
-
   if (button == GDK_BUTTON_PRIMARY)
     {
+      unselect_icons (self);
     }
   else if (button == GDK_BUTTON_SECONDARY)
     {
+      GtkWidget *popup_menu;
+
+      popup_menu = create_popup_menu (self);
+      g_object_ref_sink (popup_menu);
+
+      gtk_menu_popup_at_pointer (GTK_MENU (popup_menu), event);
+      g_object_unref (popup_menu);
     }
 }
 
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index ab23248..eef6423 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -18,6 +18,8 @@
 #include "config.h"
 #include "gf-icon.h"
 
+#include <glib/gi18n.h>
+
 #include "gf-desktop-enums.h"
 #include "gf-desktop-enum-types.h"
 #include "gf-utils.h"
@@ -98,6 +100,36 @@ icon_open (GfIcon *self)
   g_free (uri);
 }
 
+static void
+open_cb (GtkMenuItem *item,
+         GfIcon      *self)
+{
+  icon_open (self);
+}
+
+static GtkWidget *
+create_popup_menu (GfIcon *self)
+{
+  GtkWidget *popup_menu;
+  GtkStyleContext *context;
+  GtkWidget *item;
+
+  popup_menu = gtk_menu_new ();
+
+  context = gtk_widget_get_style_context (popup_menu);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_CONTEXT_MENU);
+
+  item = gtk_menu_item_new_with_label (_("Open"));
+  gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item);
+  gtk_widget_show (item);
+
+  g_signal_connect (item, "activate",
+                    G_CALLBACK (open_cb),
+                    self);
+
+  return popup_menu;
+}
+
 static void
 multi_press_pressed_cb (GtkGestureMultiPress *gesture,
                         gint                  n_press,
@@ -155,6 +187,20 @@ multi_press_pressed_cb (GtkGestureMultiPress *gesture,
     }
   else if (button == GDK_BUTTON_SECONDARY)
     {
+      GtkWidget *popup_menu;
+
+      if (!self->selected && !control_pressed)
+        flags |= GF_ICON_SELECTED_CLEAR;
+      flags |= GF_ICON_SELECTED_ADD;
+
+      gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+      gf_icon_set_selected (self, TRUE, flags);
+
+      popup_menu = create_popup_menu (self);
+      g_object_ref_sink (popup_menu);
+
+      gtk_menu_popup_at_pointer (GTK_MENU (popup_menu), event);
+      g_object_unref (popup_menu);
     }
   else if (button == GDK_BUTTON_MIDDLE)
     {
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3b2d9a8..846e7dd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,6 +21,8 @@ gnome-flashback/libaudio-device-selection/gf-audio-device-selection-dialog.c
 gnome-flashback/libautomount-manager/gsd-automount-manager.c
 gnome-flashback/libautomount-manager/gsd-autorun.c
 gnome-flashback/libbluetooth-applet/gf-bluetooth-applet.c
+gnome-flashback/libdesktop/gf-icon.c
+gnome-flashback/libdesktop/gf-icon-view.c
 gnome-flashback/libend-session-dialog/gf-inhibit-dialog.c
 gnome-flashback/libend-session-dialog/gf-inhibit-dialog.ui
 gnome-flashback/libinput-sources/gf-input-sources.c


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