[nautilus/gsoc-2022] files-view: Allow creating new files
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gsoc-2022] files-view: Allow creating new files
- Date: Sat, 17 Sep 2022 09:27:01 +0000 (UTC)
commit d89a0b0742f6215883b14ac78cc4e50032bccfb1
Author: Ignacy Kuchciński <ignacykuchcinski gmail com>
Date: Mon Aug 1 22:01:05 2022 +0200
files-view: Allow creating new files
data/meson.build | 1 +
data/templates/document.odt | Bin 0 -> 8197 bytes
data/templates/meson.build | 9 +++++++++
data/templates/presentation.odp | Bin 0 -> 13165 bytes
data/templates/spreadsheet.ods | Bin 0 -> 6956 bytes
src/nautilus-files-view.c | 27 +++++++++++++++++++++++++--
6 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 2df5a226c..953b81408 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -135,4 +135,5 @@ if appstream_util.found()
endif
subdir('ontology')
+subdir('templates')
subdir('tracker')
diff --git a/data/templates/document.odt b/data/templates/document.odt
new file mode 100644
index 000000000..2a9ef52de
Binary files /dev/null and b/data/templates/document.odt differ
diff --git a/data/templates/meson.build b/data/templates/meson.build
new file mode 100644
index 000000000..1b00e15ab
--- /dev/null
+++ b/data/templates/meson.build
@@ -0,0 +1,9 @@
+templates_data = files(
+ 'document.odt',
+ 'spreadsheet.ods',
+ 'presentation.odp'
+)
+
+install_data(templates_data,
+ install_dir: join_paths(datadir, 'nautilus', 'templates')
+)
\ No newline at end of file
diff --git a/data/templates/presentation.odp b/data/templates/presentation.odp
new file mode 100644
index 000000000..6095afffb
Binary files /dev/null and b/data/templates/presentation.odp differ
diff --git a/data/templates/spreadsheet.ods b/data/templates/spreadsheet.ods
new file mode 100644
index 000000000..16d4f2348
Binary files /dev/null and b/data/templates/spreadsheet.ods differ
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 0b48c822e..d65d4cf58 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -350,6 +350,11 @@ static void set_search_query_internal (NautilusFilesView *files_view,
static gboolean nautilus_files_view_is_read_only (NautilusFilesView *view);
+static void nautilus_files_view_new_file (NautilusFilesView *directory_view,
+ const char *parent_uri,
+ const char *target_filename,
+ NautilusFile *source);
+
G_DEFINE_TYPE_WITH_CODE (NautilusFilesView,
nautilus_files_view,
ADW_TYPE_BIN,
@@ -2068,9 +2073,26 @@ new_file_dialog_controller_on_name_accepted (NautilusFileNameWidgetController *c
NautilusFilesView *self)
{
NautilusFilesViewPrivate *priv;
+ gchar *template_name = NULL;
+ g_autofree gchar *template_path = NULL;
+ g_autoptr (GFile) template_location = NULL;
+ g_autofree gchar *name = NULL;
+ g_autoptr (NautilusFile) file = NULL;
priv = nautilus_files_view_get_instance_private (self);
+ template_name = nautilus_new_file_dialog_controller_get_template_name
(NAUTILUS_NEW_FILE_DIALOG_CONTROLLER (controller));
+ name = nautilus_file_name_widget_controller_get_new_name (controller);
+
+ if (template_name != NULL)
+ {
+ template_path = g_build_filename (NAUTILUS_DATADIR, "templates", template_name, NULL);
+ template_location = g_file_new_for_path (template_path);
+ file = nautilus_file_get (template_location);
+ }
+
+ nautilus_files_view_new_file (self, NULL, name, file);
+
g_clear_object (&priv->new_file_controller);
gtk_widget_grab_focus (GTK_WIDGET (self));
@@ -2428,6 +2450,7 @@ nautilus_files_view_new_file_with_initial_contents (NautilusFilesView *view,
static void
nautilus_files_view_new_file (NautilusFilesView *directory_view,
const char *parent_uri,
+ const char *target_filename,
NautilusFile *source)
{
NewFolderData *data;
@@ -2445,7 +2468,7 @@ nautilus_files_view_new_file (NautilusFilesView *directory_view,
{
nautilus_files_view_new_file_with_initial_contents (directory_view,
parent_uri != NULL ? parent_uri : container_uri,
- NULL,
+ target_filename,
NULL,
0);
g_free (container_uri);
@@ -2458,7 +2481,7 @@ nautilus_files_view_new_file (NautilusFilesView *directory_view,
nautilus_file_operations_new_file_from_template (GTK_WIDGET (directory_view),
parent_uri != NULL ? parent_uri : container_uri,
- NULL,
+ target_filename,
source_uri,
new_folder_done, data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]