[nautilus/gsoc-2022: 286/286] TEMPORARY COMMIT: add "New" menu item that opens templates dialog




commit 9b67d8c9ed9b66842fc700e525e737ddc4dceee2
Author: Ignacy Kuchciński <ignacykuchcinski gmail com>
Date:   Fri Jul 15 23:33:46 2022 +0200

    TEMPORARY COMMIT: add "New" menu item that opens templates dialog
    
    For development testing only. Proper soluction comes later.

 src/nautilus-files-view.c                          | 63 ++++++++++++++++++++++
 .../ui/nautilus-files-view-context-menus.ui        |  4 ++
 2 files changed, 67 insertions(+)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 32f08cce6..3f4903eb5 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -75,6 +75,7 @@
 #include "nautilus-metadata.h"
 #include "nautilus-mime-actions.h"
 #include "nautilus-module.h"
+#include "nautilus-templates-dialog.h"
 #include "nautilus-new-folder-dialog-controller.h"
 #include "nautilus-previewer.h"
 #include "nautilus-profile.h"
@@ -173,6 +174,7 @@ typedef struct
     NautilusQuery *search_query;
 
     NautilusRenameFilePopoverController *rename_file_controller;
+    NautilusTemplatesDialog *templates_dialog;
     NautilusNewFolderDialogController *new_folder_controller;
     NautilusCompressDialogController *compress_controller;
 
@@ -2108,6 +2110,48 @@ new_folder_dialog_controller_on_cancelled (NautilusNewFolderDialogController *co
     g_clear_object (&priv->new_folder_controller);
 }
 
+static void
+templates_dialog_on_response (GtkDialog *dialog,
+                              int        response_id,
+                              gpointer  *user_data)
+{
+    NautilusFilesView *view;
+    NautilusFilesViewPrivate *priv;
+
+    view = NAUTILUS_FILES_VIEW (user_data);
+    priv = nautilus_files_view_get_instance_private (view);
+
+    gtk_window_destroy (GTK_WINDOW (dialog));
+    priv->templates_dialog = NULL;
+}
+
+static void
+nautilus_files_view_new_dialog_new (NautilusFilesView *view)
+{
+    g_autoptr (NautilusDirectory) containing_directory = NULL;
+    NautilusFilesViewPrivate *priv;
+    g_autofree char *uri = NULL;
+
+    priv = nautilus_files_view_get_instance_private (view);
+
+    if (priv->templates_dialog != NULL)
+    {
+        return;
+    }
+
+    uri = nautilus_files_view_get_backing_uri (view);
+    containing_directory = nautilus_directory_get_by_uri (uri);
+
+    priv->templates_dialog =
+        nautilus_templates_dialog_new (nautilus_files_view_get_containing_window (view));
+    gtk_window_present (GTK_WINDOW (priv->templates_dialog));
+
+    g_signal_connect (priv->templates_dialog,
+                      "response",
+                      G_CALLBACK (templates_dialog_on_response),
+                      view);
+}
+
 static void
 nautilus_files_view_new_folder_dialog_new (NautilusFilesView *view,
                                            gboolean           with_selection)
@@ -2487,6 +2531,16 @@ nautilus_files_view_new_file (NautilusFilesView *directory_view,
     g_free (container_uri);
 }
 
+static void
+action_new (GSimpleAction *action,
+            GVariant      *state,
+            gpointer       user_data)
+{
+    g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+
+    nautilus_files_view_new_dialog_new (NAUTILUS_FILES_VIEW (user_data));
+}
+
 static void
 action_new_folder (GSimpleAction *action,
                    GVariant      *state,
@@ -7070,6 +7124,7 @@ const GActionEntry view_entries[] =
     { "zoom-standard", action_zoom_standard },
     { "show-hidden-files", NULL, NULL, "true", action_show_hidden_files },
     /* Background menu */
+    { "new", action_new },
     { "new-folder", action_new_folder },
     { "select-all", action_select_all },
     { "paste", action_paste_files },
@@ -7591,6 +7646,10 @@ real_update_actions_state (NautilusFilesView *view)
                                  (selection_contains_recent || selection_contains_search ||
                                   selection_contains_starred));
 
+    action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+                                         "new");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
+
     action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
                                          "new-folder");
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
@@ -7787,6 +7846,9 @@ real_update_actions_state (NautilusFilesView *view)
                                  !selection_contains_recent &&
                                  !selection_contains_search &&
                                  !selection_contains_starred);
+    action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+                                         "new");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
     action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
                                          "new-folder");
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
@@ -9782,6 +9844,7 @@ nautilus_files_view_init (NautilusFilesView *view)
      * make sure the focus is on the files view.
      */
     nautilus_application_set_accelerator (app, "view.paste_accel", "<control>v");
+    nautilus_application_set_accelerator (app, "view.new", "<control><shift>nd");
     nautilus_application_set_accelerator (app, "view.new-folder", "<control><shift>n");
     nautilus_application_set_accelerator (app, "view.select-pattern", "<control>s");
     nautilus_application_set_accelerators (app, "view.zoom-standard", zoom_standard_accels);
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui 
b/src/resources/ui/nautilus-files-view-context-menus.ui
index 46cd7bdcf..48620e380 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -11,6 +11,10 @@
       <attribute name="nautilus-menu-item">templates-submenu</attribute>
       <link name="submenu" id="templates-submenu"/>
     </item>
+    <item>
+      <attribute name="label" translatable="yes">_New File…</attribute>
+      <attribute name="action">view.new</attribute>
+    </item>
     <item>
       <attribute name="label" translatable="yes">Open _With…</attribute>
       <attribute name="action">view.open-current-directory-with-other-application</attribute>


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