Bläddra i källkod

Activation de la fenêtre des raccourcis clavier

vetetix 1 månad sedan
förälder
incheckning
46301261cd
5 ändrade filer med 73 tillägg och 14 borttagningar
  1. 41 0
      src/gtk/help-overlay.ui
  2. 15 8
      src/main.c
  3. 14 4
      src/text-viewer-application.c
  4. 1 1
      src/text-viewer-window.ui
  5. 2 1
      src/text-viewer.gresource.xml

+ 41 - 0
src/gtk/help-overlay.ui

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkShortcutsWindow" id="help_overlay">
+    <property name="modal">True</property>
+    <child>
+      <object class="GtkShortcutsSection">
+        <property name="section-name">shortcuts</property>
+        <property name="max-height">10</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="title" translatable="yes" context="shortcut window">General</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="title" translatable="yes" context="shortcut window">Show Shortcuts</property>
+                <property name="action-name">win.show-help-overlay</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="title" translatable="yes" context="shortcut window">Quit</property>
+                <property name="action-name">app.quit</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="title" translatable="yes" context="shortcut window">Open</property>
+                <property name="action-name">win.open</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="title" translatable="yes" context="shortcut window">Save as</property>
+                <property name="action-name">win.save-as</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>

+ 15 - 8
src/main.c

@@ -28,15 +28,22 @@ int
 main (int   argc,
       char *argv[])
 {
-	g_autoptr(TextViewerApplication) app = NULL;
-	int ret;
+  g_autoptr(TextViewerApplication) app = NULL;
+  int ret;
 
-	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-	textdomain (GETTEXT_PACKAGE);
+  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
 
-	app = text_viewer_application_new ("com.example.TextViewer", G_APPLICATION_DEFAULT_FLAGS);
-	ret = g_application_run (G_APPLICATION (app), argc, argv);
+  /* Since this example is running uninstalled,
+   * we have to help it find its schema. This
+   * is *not* necessary in properly installed
+   * application.
+   */
+  /*g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);*/
 
-	return ret;
+  app = text_viewer_application_new ("com.example.TextViewer", G_APPLICATION_DEFAULT_FLAGS);
+  ret = g_application_run (G_APPLICATION (app), argc, argv);
+
+  return ret;
 }

+ 14 - 4
src/text-viewer-application.c

@@ -168,18 +168,28 @@ text_viewer_application_quit_action (GSimpleAction *action,
 	g_application_quit (G_APPLICATION (self));
 }
 
+/*static void
+text_viewer_application_shortcuts_action (GSimpleAction *action,
+                                          GVariant      *parameter,
+                                          gpointer       user_data)
+{
+  TextViewerApplication *self = user_data;
+
+}*/
+
 static const GActionEntry app_actions[] = {
-	{ "quit", text_viewer_application_quit_action },
-	{ "about", text_viewer_application_about_action },
+  { "quit", text_viewer_application_quit_action },
+  { "about", text_viewer_application_about_action },
+  /*{ "shortcuts", text_viewer_application_shortcuts_action },*/
 };
 
 static void
 text_viewer_application_init (TextViewerApplication *self)
 {
-  //gtk_init();
+  gboolean dark_mode;
   self->settings = g_settings_new ("com.example.TextViewer");
 
-  gboolean dark_mode = g_settings_get_boolean (self->settings, "dark-mode");
+  dark_mode = g_settings_get_boolean (self->settings, "dark-mode");
 
   /*AdwStyleManager *style_manager = adw_style_manager_get_default ();
   if (dark_mode)

+ 1 - 1
src/text-viewer-window.ui

@@ -76,7 +76,7 @@
       </item>
       <item>
         <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
-        <attribute name="action">app.shortcuts</attribute>
+        <attribute name="action">win.show-help-overlay</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">_About Text-viewer</attribute>

+ 2 - 1
src/text-viewer.gresource.xml

@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/com/example/TextViewer">
     <file preprocess="xml-stripblanks">text-viewer-window.ui</file>
-    <file preprocess="xml-stripblanks">shortcuts-dialog.ui</file>
+    <!--<file preprocess="xml-stripblanks">shortcuts-dialog.ui</file>-->
+    <file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
   </gresource>
 </gresources>