[gnome-builder/wip/chergert/perspective] source-view: use EggWidgetActionGroup and EggMenuManager
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/perspective] source-view: use EggWidgetActionGroup and EggMenuManager
- Date: Fri, 4 Dec 2015 05:23:36 +0000 (UTC)
commit 2e457844edd5d0cb5a8752a50d13944320555ff5
Author: Christian Hergert <chergert redhat com>
Date: Thu Dec 3 21:22:29 2015 -0800
source-view: use EggWidgetActionGroup and EggMenuManager
Now that we have menu merging, we can stop using the default popup
menu items. This allows plugins to extend the menu.
data/gtk/menus.ui | 107 ++++++++++++++++++++++++++++++++++++++++++++++
libide/ide-source-view.c | 79 +++++++++-------------------------
2 files changed, 128 insertions(+), 58 deletions(-)
---
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index 80b44bb..b7b56ca 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -213,4 +213,111 @@
</item>
</section>
</menu>
+ <menu id="ide-source-view-popup-menu">
+ <section id="ide-source-view-popup-menu-jump-section">
+ <item>
+ <attribute name="label" translatable="yes">_Go to Definition</attribute>
+ <attribute name="action">sourceview.goto-definition</attribute>
+ </item>
+ </section>
+ <section id="ide-source-view-popup-menu-undo-section">
+ <item>
+ <attribute name="label" translatable="yes">_Undo</attribute>
+ <attribute name="action">sourceview.undo</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Redo</attribute>
+ <attribute name="action">sourceview.redo</attribute>
+ </item>
+ </section>
+ <section id="ide-source-view-popup-menu-clipboard-section">
+ <item>
+ <attribute name="label" translatable="yes">C_ut</attribute>
+ <attribute name="action">sourceview.cut-clipboard</attribute>
+ </item>
+ <item>
+ <attribute name="id">copy</attribute>
+ <attribute name="label" translatable="yes">_Copy</attribute>
+ <attribute name="action">sourceview.copy-clipboard</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Paste</attribute>
+ <attribute name="action">sourceview.paste-clipboard</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Delete</attribute>
+ <attribute name="action">sourceview.delete-selection</attribute>
+ </item>
+ </section>
+ <section id="ide-source-view-popup-menu-selection-section">
+ <submenu id="ide-source-view-popup-menu-selection-submenu">
+ <attribute name="label" translatable="yes">Selection</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Select _All</attribute>
+ <attribute name="action">sourceview.select-all</attribute>
+ <attribute name="target" type="(b)">(true,)</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Select _None</attribute>
+ <attribute name="action">sourceview.select-all</attribute>
+ <attribute name="target" type="(b)">(false,)</attribute>
+ </item>
+ <section id="ide-source-view-popup-menu-case-section">
+ <item>
+ <attribute name="label" translatable="yes">All _Upper Case</attribute>
+ <attribute name="action">sourceview.change-case</attribute>
+ <attribute name="target" type="(u)">(1,)</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">All _Lower Case</attribute>
+ <attribute name="action">sourceview.change-case</attribute>
+ <attribute name="target" type="(u)">(0,)</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Invert Case</attribute>
+ <attribute name="action">sourceview.change-case</attribute>
+ <attribute name="target" type="(u)">(2,)</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Title Case</attribute>
+ <attribute name="action">sourceview.change-case</attribute>
+ <attribute name="target" type="(u)">(3,)</attribute>
+ </item>
+ </section>
+ <section id="ide-source-view-popup-menu-line-section">
+ <item>
+ <attribute name="label" translatable="yes">Join Lines</attribute>
+ <attribute name="action">sourceview.join-lines</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Sort Lines</attribute>
+ <attribute name="action">sourceview.sort</attribute>
+ <attribute name="target" type="(bb)">(false,false)</attribute>
+ </item>
+ </section>
+ </submenu>
+ </section>
+ <section id="ide-source-view-popup-menu-zoom-section">
+ <submenu id="ide-source-view-popup-menu-zoom-section-submenu">
+ <attribute name="label" translatable="yes">Zoom</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Zoom _In</attribute>
+ <attribute name="action">sourceview.increase-font-size</attribute>
+ <attribute name="accel"><control>plus</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Zoom _Out</attribute>
+ <attribute name="action">sourceview.decrease-font-size</attribute>
+ <attribute name="accel"><control>minus</attribute>
+ </item>
+ <section id="ide-source-view-popup-menu-zoom-section-submenu-reset">
+ <item>
+ <attribute name="label" translatable="yes">Reset</attribute>
+ <attribute name="action">sourceview.reset-font-size</attribute>
+ <attribute name="accel"><control>0</attribute>
+ </item>
+ </section>
+ </submenu>
+ </section>
+ </menu>
</interface>
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index dfb2e7e..828e083 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -20,11 +20,14 @@
#include <glib/gi18n.h>
#include <stdlib.h>
+
+#include "egg-animation.h"
#include "egg-binding-group.h"
#include "egg-counter.h"
#include "egg-signal-group.h"
+#include "egg-widget-action-group.h"
-#include "egg-animation.h"
+#include "ide-application.h"
#include "ide-back-forward-item.h"
#include "ide-back-forward-list.h"
#include "ide-box-theatric.h"
@@ -1430,6 +1433,7 @@ ide_source_view_bind_buffer (IdeSourceView *self,
GtkTextMark *insert;
GtkTextIter iter;
IdeContext *context;
+ GActionGroup *actions;
IDE_ENTRY;
@@ -1510,6 +1514,16 @@ ide_source_view_bind_buffer (IdeSourceView *self,
insert = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer));
ide_source_view_scroll_mark_onscreen (self, insert, TRUE, 0.5, 0.5);
+ actions = gtk_widget_get_action_group (GTK_WIDGET (self), "sourceview");
+
+ g_object_bind_property (buffer, "can-redo",
+ g_action_map_lookup_action (G_ACTION_MAP (actions), "redo"), "enabled",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (buffer, "can-undo",
+ g_action_map_lookup_action (G_ACTION_MAP (actions), "undo"), "enabled",
+ G_BINDING_SYNC_CREATE);
+
IDE_EXIT;
}
@@ -4560,15 +4574,6 @@ ide_source_view__fixit_activate (IdeSourceView *self,
}
static void
-ide_source_view_sort_selected_lines (IdeSourceView *source_view,
- GtkMenuItem *menu_item)
-{
- g_assert (IDE_IS_SOURCE_VIEW (source_view));
-
- ide_source_view_real_sort (source_view, FALSE, FALSE);
-}
-
-static void
ide_source_view_real_populate_popup (GtkTextView *text_view,
GtkWidget *popup)
{
@@ -4581,6 +4586,7 @@ ide_source_view_real_populate_popup (GtkTextView *text_view,
GtkTextIter begin;
GtkTextIter end;
IdeDiagnostic *diagnostic;
+ GMenu *model;
g_assert (GTK_IS_TEXT_VIEW (text_view));
g_assert (GTK_IS_WIDGET (popup));
@@ -4594,6 +4600,9 @@ ide_source_view_real_populate_popup (GtkTextView *text_view,
if (!IDE_IS_BUFFER (buffer))
return;
+ model = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "ide-source-view-popup-menu");
+ gtk_menu_shell_bind_model (GTK_MENU_SHELL (popup), G_MENU_MODEL (model), NULL, TRUE);
+
gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
/*
@@ -4662,54 +4671,6 @@ ide_source_view_real_populate_popup (GtkTextView *text_view,
}
}
}
-
- /*
- * Sort/Join Lines.
- */
- sep = g_object_new (GTK_TYPE_SEPARATOR_MENU_ITEM,
- "visible", TRUE,
- NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (popup), GTK_WIDGET (sep));
-
- menu_item = g_object_new (GTK_TYPE_MENU_ITEM,
- "label", _("Join Lines"),
- "sensitive", !gtk_text_iter_equal (&begin, &end),
- "visible", TRUE,
- NULL);
- g_signal_connect_swapped (menu_item,
- "activate",
- G_CALLBACK (ide_source_view_real_join_lines),
- self);
- gtk_menu_shell_append (GTK_MENU_SHELL (popup), GTK_WIDGET (menu_item));
-
- menu_item = g_object_new (GTK_TYPE_MENU_ITEM,
- "label", _("Sort Lines"),
- "sensitive", !gtk_text_iter_equal (&begin, &end),
- "visible", TRUE,
- NULL);
- g_signal_connect_swapped (menu_item,
- "activate",
- G_CALLBACK (ide_source_view_sort_selected_lines),
- self);
- gtk_menu_shell_append (GTK_MENU_SHELL (popup), GTK_WIDGET (menu_item));
-
- /*
- * Go to definition.
- */
- sep = g_object_new (GTK_TYPE_SEPARATOR_MENU_ITEM,
- "visible", TRUE,
- NULL);
- gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), GTK_WIDGET (sep));
-
- menu_item = g_object_new (GTK_TYPE_MENU_ITEM,
- "label", _("Go to Definition"),
- "visible", TRUE,
- NULL);
- g_signal_connect_swapped (menu_item,
- "activate",
- G_CALLBACK (ide_source_view_real_goto_definition),
- self);
- gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), GTK_WIDGET (menu_item));
}
static void
@@ -6151,6 +6112,8 @@ ide_source_view_init (IdeSourceView *self)
target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (self));
if (target_list)
gtk_target_list_add_uri_targets (target_list, TARGET_URI_LIST);
+
+ egg_widget_action_group_attach (self, "sourceview");
}
const PangoFontDescription *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]