[nautilus/gsoc-2022: 285/286] templates-dialog: Add basic dialog structure
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gsoc-2022: 285/286] templates-dialog: Add basic dialog structure
- Date: Mon, 15 Aug 2022 19:32:48 +0000 (UTC)
commit 216d5c2dddda8c2a0182b6110a11214875d948ab
Author: Ignacy Kuchciński <ignacykuchcinski gmail com>
Date: Sat Jul 16 02:06:19 2022 +0200
templates-dialog: Add basic dialog structure
The actual list of templates is not yet here.
It's not accessible from the UI yet.
Part of https://gitlab.gnome.org/GNOME/nautilus/-/issues/2205
src/meson.build | 2 +
src/nautilus-templates-dialog.c | 96 +++++++++++++++++++++++++++
src/nautilus-templates-dialog.h | 33 +++++++++
src/resources/nautilus.gresource.xml | 1 +
src/resources/ui/nautilus-templates-dialog.ui | 73 ++++++++++++++++++++
5 files changed, 205 insertions(+)
---
diff --git a/src/meson.build b/src/meson.build
index 339a50aa0..e682b99ba 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -176,6 +176,8 @@ libnautilus_sources = [
'nautilus-file-name-widget-controller.h',
'nautilus-rename-file-popover-controller.c',
'nautilus-rename-file-popover-controller.h',
+ 'nautilus-templates-dialog.c',
+ 'nautilus-templates-dialog.h',
'nautilus-new-folder-dialog-controller.c',
'nautilus-new-folder-dialog-controller.h',
'nautilus-compress-dialog-controller.c',
diff --git a/src/nautilus-templates-dialog.c b/src/nautilus-templates-dialog.c
new file mode 100644
index 000000000..62ddea9bc
--- /dev/null
+++ b/src/nautilus-templates-dialog.c
@@ -0,0 +1,96 @@
+/* nautilus-templates-dialog.c
+ *
+ * Copyright 2022 Ignacy Kuchciński <ignacykuchcinski gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "nautilus-templates-dialog.h"
+
+#include <glib/gi18n.h>
+
+#include "nautilus-file-operations.h"
+
+struct _NautilusTemplatesDialog
+{
+ GtkDialog parent_instance;
+};
+
+G_DEFINE_TYPE (NautilusTemplatesDialog, nautilus_templates_dialog, GTK_TYPE_DIALOG)
+
+static void
+on_import_response (GtkNativeDialog *native,
+ int response,
+ NautilusTemplatesDialog *self)
+{
+ if (response == GTK_RESPONSE_ACCEPT)
+ {
+ GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
+ g_autoptr (GFile) file = gtk_file_chooser_get_file (chooser);
+ g_autoptr (GFile) templates_location = NULL;
+ g_autofree char *path = NULL;
+
+ path = g_file_get_path (file);
+ templates_location =
+ g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES));
+ nautilus_file_operations_copy_async (&(GList){.data = file},
+ templates_location,
+ GTK_WINDOW (self),
+ NULL, NULL, NULL);
+ }
+
+ g_object_unref (native);
+}
+
+static void
+nautilus_templates_dialog_import_template_dialog (NautilusTemplatesDialog *self G_GNUC_UNUSED)
+{
+ GtkFileChooserNative *native = gtk_file_chooser_native_new (_("Import Template"),
+ GTK_WINDOW (self),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ _("_Import"),
+ NULL);
+
+ g_signal_connect (native,
+ "response",
+ G_CALLBACK (on_import_response),
+ self);
+
+ gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
+}
+
+NautilusTemplatesDialog *
+nautilus_templates_dialog_new (GtkWindow *parent_window)
+{
+ return g_object_new (NAUTILUS_TYPE_TEMPLATES_DIALOG,
+ "use-header-bar", TRUE,
+ "transient-for", parent_window, NULL);
+}
+
+static void
+nautilus_templates_dialog_class_init (NautilusTemplatesDialogClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/nautilus/ui/nautilus-templates-dialog.ui");
+ gtk_widget_class_bind_template_callback (widget_class, nautilus_templates_dialog_import_template_dialog);
+}
+
+static void
+nautilus_templates_dialog_init (NautilusTemplatesDialog *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/src/nautilus-templates-dialog.h b/src/nautilus-templates-dialog.h
new file mode 100644
index 000000000..a95857ad4
--- /dev/null
+++ b/src/nautilus-templates-dialog.h
@@ -0,0 +1,33 @@
+/* nautilus-templates-dialog.h
+ *
+ * Copyright 2022 Ignacy Kuchciński <ignacykuchcinski gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_TEMPLATES_DIALOG (nautilus_templates_dialog_get_type ())
+
+G_DECLARE_FINAL_TYPE (NautilusTemplatesDialog, nautilus_templates_dialog, NAUTILUS, TEMPLATES_DIALOG,
GtkDialog)
+
+NautilusTemplatesDialog * nautilus_templates_dialog_new (GtkWindow *parent_window);
+
+G_END_DECLS
diff --git a/src/resources/nautilus.gresource.xml b/src/resources/nautilus.gresource.xml
index 6057d7eac..2866224ff 100644
--- a/src/resources/nautilus.gresource.xml
+++ b/src/resources/nautilus.gresource.xml
@@ -12,6 +12,7 @@
<file>ui/nautilus-toolbar-view-menu.ui</file>
<file>ui/nautilus-column-chooser.ui</file>
<file>ui/nautilus-list-view-column-editor.ui</file>
+ <file>ui/nautilus-templates-dialog.ui</file>
<file>ui/nautilus-create-folder-dialog.ui</file>
<file>ui/nautilus-compress-dialog.ui</file>
<file>ui/nautilus-rename-file-popover.ui</file>
diff --git a/src/resources/ui/nautilus-templates-dialog.ui b/src/resources/ui/nautilus-templates-dialog.ui
new file mode 100644
index 000000000..13e960a87
--- /dev/null
+++ b/src/resources/ui/nautilus-templates-dialog.ui
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="NautilusTemplatesDialog" parent="GtkDialog">
+ <property name="title" translatable="yes">Create File</property>
+ <property name="modal">True</property>
+ <property name="default-width">550</property>
+ <property name="default-height">450</property>
+ <child internal-child="content_area">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkStack">
+ <child>
+ <object class="GtkStackPage">
+ <property name="child">
+ <object class="AdwStatusPage">
+ <property name="icon-name">folder-templates-symbolic</property>
+ <property name="title" translatable="yes">No Templates Found</property>
+ <property name="description" translatable="yes">Add more templates by importing them from
files.</property>
+ <property name="child">
+ <object class="GtkButton">
+ <property name="label" translatable="yes">Import</property>
+ <property name="halign">center</property>
+ <signal name="clicked" handler="nautilus_templates_dialog_import_template_dialog"
swapped="yes"/>
+ <style>
+ <class name="pill"/>
+ </style>
+ </object>
+ </property>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkStackPage">
+ <property name="child">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkButton">
+ <property name="label" translatable="yes">Import</property>
+ <property name="halign">center</property>
+ <signal name="clicked" handler="nautilus_templates_dialog_import_template_dialog"
swapped="yes"/>
+ <style>
+ <class name="pill"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="cancel_button">
+ <property name="label" translatable="yes">Cancel</property>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="ok_button">
+ <property name="label" translatable="yes">Create</property>
+ <property name="sensitive">False</property>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="ok" default="true">ok_button</action-widget>
+ <action-widget response="cancel">cancel_button</action-widget>
+ </action-widgets>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]