[gnome-text-editor] window: move menus to editor-window.ui



commit 4a3370e5a923316b8fc0975c78f2022bbe3856a3
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 30 11:05:06 2021 -0800

    window: move menus to editor-window.ui
    
    These can all be used from the editor-window.ui without having to maintain
    an extra menus.ui file. Also, doing this can simplify the process of doing
    things like #230 where we need a new copy of the menu anyway to avoid
    mutability across windows.

 src/editor-window.c                    |  13 ---
 src/editor-window.ui                   | 178 +++++++++++++++++++++++++++++++++
 src/menus.ui                           | 178 ---------------------------------
 src/org.gnome.TextEditor.gresource.xml |   1 -
 4 files changed, 178 insertions(+), 192 deletions(-)
---
diff --git a/src/editor-window.c b/src/editor-window.c
index 72cf55f..d85a0da 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -303,12 +303,8 @@ editor_window_constructed (GObject *object)
   EditorWindow *self = (EditorWindow *)object;
   GtkSourceStyleSchemeManager *sm;
   const char * const *scheme_ids;
-  GtkApplication *app;
   EditorSession *session;
   GtkPopover *popover;
-  GMenu *options_menu;
-  GMenu *primary_menu;
-  GMenu *tab_menu;
   GtkWidget *zoom_box;
   GtkWidget *zoom_out;
   GtkWidget *zoom_in;
@@ -317,20 +313,14 @@ editor_window_constructed (GObject *object)
 
   G_OBJECT_CLASS (editor_window_parent_class)->constructed (object);
 
-  app = GTK_APPLICATION (EDITOR_APPLICATION_DEFAULT);
   session = editor_application_get_session (EDITOR_APPLICATION_DEFAULT);
 
-  tab_menu = gtk_application_get_menu_by_id (app, "tab-menu");
-  adw_tab_view_set_menu_model (self->tab_view, G_MENU_MODEL (tab_menu));
 
   /* Set the recents list for the open popover */
   g_object_bind_property (session, "recents",
                           self->open_menu_popover, "model",
                           G_BINDING_SYNC_CREATE);
 
-  primary_menu = gtk_application_get_menu_by_id (GTK_APPLICATION (app), "primary-menu");
-  gtk_menu_button_set_menu_model (self->primary_menu, G_MENU_MODEL (primary_menu));
-
   /* The primary menu has some custom widgets added to it */
   popover = gtk_menu_button_get_popover (self->primary_menu);
   gtk_popover_menu_add_child (GTK_POPOVER_MENU (popover),
@@ -369,9 +359,6 @@ editor_window_constructed (GObject *object)
   gtk_box_append (GTK_BOX (zoom_box), zoom_in);
   gtk_popover_menu_add_child (GTK_POPOVER_MENU (popover), zoom_box, "zoom");
 
-  options_menu = gtk_application_get_menu_by_id (GTK_APPLICATION (app), "options-menu");
-  gtk_menu_button_set_menu_model (self->options_menu, G_MENU_MODEL (options_menu));
-
   /* Populate schemes for preferences */
   sm = gtk_source_style_scheme_manager_get_default ();
   if ((scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (sm)))
diff --git a/src/editor-window.ui b/src/editor-window.ui
index 7213c16..3b13b77 100644
--- a/src/editor-window.ui
+++ b/src/editor-window.ui
@@ -102,6 +102,7 @@
                   <object class="GtkMenuButton" id="options_menu">
                     <property name="tooltip-text" translatable="yes">View</property>
                     <property name="icon-name">document-properties-symbolic</property>
+                    <property name="menu-model">options_menu_model</property>
                     <accessibility>
                       <property name="label" translatable="yes">View</property>
                     </accessibility>
@@ -110,6 +111,7 @@
                 <child>
                   <object class="GtkMenuButton" id="primary_menu">
                     <property name="icon-name">open-menu-symbolic</property>
+                    <property name="menu-model">primary_menu_model</property>
                     <accessibility>
                       <property name="label" translatable="yes">Menu</property>
                     </accessibility>
@@ -149,6 +151,7 @@
                       <object class="AdwTabView" id="tab_view">
                         <property name="hexpand">true</property>
                         <property name="vexpand">true</property>
+                        <property name="menu-model">tab_menu</property>
                         <signal name="close-page" handler="on_tab_view_close_page_cb" swapped="true"/>
                         <signal name="setup-menu" handler="on_tab_view_setup_menu_cb" swapped="true"/>
                         <signal name="create-window" handler="on_tab_view_create_window_cb" swapped="true"/>
@@ -300,4 +303,179 @@ Or, press Ctrl+W to close the window.</property>
       </object>
     </child>
   </template>
+  <menu id="primary_menu_model">
+    <section>
+      <item>
+        <attribute name="custom">theme</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="custom">zoom</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_New Window</attribute>
+        <attribute name="action">app.new-window</attribute>
+        <attribute name="accel">&lt;control&gt;n</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="id">save</attribute>
+        <attribute name="label" translatable="yes">_Save</attribute>
+        <attribute name="action">page.save</attribute>
+        <attribute name="accel">&lt;control&gt;s</attribute>
+      </item>
+      <item>
+        <attribute name="id">save-as</attribute>
+        <attribute name="label" translatable="yes">Save _As…</attribute>
+        <attribute name="action">page.save-as</attribute>
+        <attribute name="accel">&lt;control&gt;&lt;shift&gt;s</attribute>
+      </item>
+      <item>
+        <attribute name="id">discard-changes</attribute>
+        <attribute name="label" translatable="yes">_Discard Changes</attribute>
+        <attribute name="action">page.discard-changes</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Find/Replace…</attribute>
+        <attribute name="action">page.begin-search</attribute>
+        <attribute name="accel">&lt;control&gt;f</attribute>
+      </item>
+      <item>
+        <attribute name="id">print</attribute>
+        <attribute name="label" translatable="yes">_Print</attribute>
+        <attribute name="action">page.print</attribute>
+        <attribute name="accel">&lt;control&gt;p</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Preferences</attribute>
+        <attribute name="action">win.show-preferences</attribute>
+        <attribute name="accel">&lt;control&gt;comma</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
+        <attribute name="action">win.show-help-overlay</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Help</attribute>
+        <attribute name="action">app.help</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_About Text Editor</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+    </section>
+  </menu>
+  <menu id="options_menu_model">
+    <section>
+      <attribute name="label" translatable="yes">Show</attribute>
+      <item>
+        <attribute name="label" translatable="yes">_Line Numbers</attribute>
+        <attribute name="action">settings.show-line-numbers</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Right Margin</attribute>
+        <attribute name="action">settings.show-right-margin</attribute>
+      </item>
+    </section>
+    <section>
+      <attribute name="label" translatable="yes">Indentation</attribute>
+      <item>
+        <attribute name="label" translatable="yes">_Automatic Indentation</attribute>
+        <attribute name="action">settings.auto-indent</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Tabs</attribute>
+        <attribute name="action">settings.indent-style</attribute>
+        <attribute name="target" type="s">'tab'</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Spaces</attribute>
+        <attribute name="action">settings.indent-style</attribute>
+        <attribute name="target" type="s">'space'</attribute>
+      </item>
+      <submenu>
+        <attribute name="label" translatable="yes">Spaces _Per Tab</attribute>
+        <section>
+          <item>
+            <attribute name="label" translatable="yes">_2</attribute>
+            <attribute name="action">settings.tab-width</attribute>
+            <attribute name="target" type="u">2</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">_4</attribute>
+            <attribute name="action">settings.tab-width</attribute>
+            <attribute name="target" type="u">4</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">_6</attribute>
+            <attribute name="action">settings.tab-width</attribute>
+            <attribute name="target" type="u">6</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">_8</attribute>
+            <attribute name="action">settings.tab-width</attribute>
+            <attribute name="target" type="u">8</attribute>
+          </item>
+        </section>
+      </submenu>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">T_ext Wrapping</attribute>
+        <attribute name="action">settings.wrap-text</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Automatic Margin Position</attribute>
+        <attribute name="action">settings.discover-settings</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Chec_k Spelling</attribute>
+        <attribute name="action">settings.spellcheck</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Document Type</attribute>
+        <attribute name="action">page.change-language</attribute>
+      </item>
+    </section>
+  </menu>
+  <menu id="tab_menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Move _Left</attribute>
+        <attribute name="action">page.move-left</attribute>
+        <attribute name="accel">&lt;control&gt;&lt;shift&gt;&lt;alt&gt;Page_Up</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Move _Right</attribute>
+        <attribute name="action">page.move-right</attribute>
+        <attribute name="accel">&lt;control&gt;&lt;shift&gt;&lt;alt&gt;Page_Down</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Move to New Window</attribute>
+        <attribute name="action">page.move-to-new-window</attribute>
+        <attribute name="accel">&lt;control&gt;&lt;shift&gt;n</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Close _Other Tabs</attribute>
+        <attribute name="action">win.close-other-pages</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Close</attribute>
+        <attribute name="action">win.close-current-page</attribute>
+        <attribute name="accel">&lt;control&gt;w</attribute>
+      </item>
+    </section>
+  </menu>
 </interface>
diff --git a/src/org.gnome.TextEditor.gresource.xml b/src/org.gnome.TextEditor.gresource.xml
index f61780d..f2d1e20 100644
--- a/src/org.gnome.TextEditor.gresource.xml
+++ b/src/org.gnome.TextEditor.gresource.xml
@@ -17,7 +17,6 @@
     <file>TextEditor.css</file>
   </gresource>
   <gresource prefix="/org/gnome/TextEditor/gtk">
-    <file preprocess="xml-stripblanks">menus.ui</file>
     <file preprocess="xml-stripblanks">help-overlay.ui</file>
   </gresource>
   <gresource prefix="/plugins/modelines">


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