diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c index 88fb29154be681a2c7c8928ad4b07303b8888976..241915475e5519eb2fc1979ff62bf25761c65e8c 100644 --- a/thunar/thunar-application.c +++ b/thunar/thunar-application.c @@ -1281,9 +1281,9 @@ thunar_application_rename_file (ThunarApplication *application, /** - * thunar_application_create_folder: + * thunar_application_create_file: * @application : a #ThunarApplication. - * @parent_directory : the #ThunarFile of the parent directory + * @parent_directory : the #ThunarFile of the parent directory. * @content_type : the content type of the new file. * @screen : the #GdkScreen on which to open the window or %NULL * to open on the default screen. @@ -1348,6 +1348,77 @@ thunar_application_create_file (ThunarApplication *application, +/** + * thunar_application_create_file_from_template: + * @application : a #ThunarApplication. + * @parent_directory : the #ThunarFile of the parent directory. + * @template_file : the #ThunarFile of the template. + * @screen : the #GdkScreen on which to open the window or %NULL + * to open on the default screen. + * @startup_id : startup id from startup notification passed along + * with dbus to make focus stealing work properly. + * + * Prompts the user to create a new file or directory in @parent_directory + * from an existing @template_file which predefines the name and extension + * in the create dialog. + **/ +void +thunar_application_create_file_from_template (ThunarApplication *application, + ThunarFile *parent_directory, + ThunarFile *template_file, + GdkScreen *screen, + const gchar *startup_id) +{ + GList source_path_list; + GList target_path_list; + gchar *name; + gchar *title; + + _thunar_return_if_fail (THUNAR_IS_APPLICATION (application)); + _thunar_return_if_fail (THUNAR_IS_FILE (parent_directory)); + _thunar_return_if_fail (THUNAR_IS_FILE (template_file)); + _thunar_return_if_fail (GDK_IS_SCREEN (screen)); + _thunar_return_if_fail (startup_id != NULL); + + /* generate a title for the create dialog */ + title = g_strdup_printf (_("Create Document from template \"%s\""), + thunar_file_get_display_name (template_file)); + + /* TODO pass the startup ID to the rename dialog */ + + /* ask the user to enter a name for the new document */ + name = thunar_show_create_dialog (screen, + thunar_file_get_content_type (template_file), + thunar_file_get_display_name (template_file), + title); + if (G_LIKELY (name != NULL)) + { + /* fake the source file list */ + source_path_list.data = thunar_file_get_file (template_file); + source_path_list.prev = source_path_list.next = NULL; + + /* fake the target path list */ + target_path_list.data = g_file_get_child (thunar_file_get_file (parent_directory), name); + target_path_list.next = target_path_list.prev = NULL; + + /* launch the operation */ + thunar_application_copy_to (application, screen, + &source_path_list, &target_path_list, + NULL); + + /* release the target path */ + g_object_unref (target_path_list.data); + + /* release the file name */ + g_free (name); + } + + /* clean up */ + g_free (title); +} + + + /** * thunar_application_copy_to: * @application : a #ThunarApplication. diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h index eb04f94120b9e5ce479da447ef36561b1bb462e7..cb42877a62e1ccb1779224599ae0d1ec8fc1e70a 100644 --- a/thunar/thunar-application.h +++ b/thunar/thunar-application.h @@ -36,105 +36,110 @@ typedef struct _ThunarApplication ThunarApplication; #define THUNAR_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_APPLICATION)) #define THUNAR_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_APPLICATION, ThunarApplicationClass)) -GType thunar_application_get_type (void) G_GNUC_CONST; - -ThunarApplication *thunar_application_get (void); - -gboolean thunar_application_get_daemon (ThunarApplication *application); -void thunar_application_set_daemon (ThunarApplication *application, - gboolean daemon); - -GList *thunar_application_get_windows (ThunarApplication *application); - -gboolean thunar_application_has_windows (ThunarApplication *application); - -void thunar_application_take_window (ThunarApplication *application, - GtkWindow *window); - -GtkWidget *thunar_application_open_window (ThunarApplication *application, - ThunarFile *directory, - GdkScreen *screen, - const gchar *startup_id); - -gboolean thunar_application_bulk_rename (ThunarApplication *application, - const gchar *working_directory, - gchar **filenames, - gboolean standalone, - GdkScreen *screen, - const gchar *startup_id, - GError **error); - -GtkWidget *thunar_application_get_progress_dialog (ThunarApplication *application); - -gboolean thunar_application_process_filenames (ThunarApplication *application, - const gchar *working_directory, - gchar **filenames, - GdkScreen *screen, - const gchar *startup_id, - GError **error); - -gboolean thunar_application_is_processing (ThunarApplication *application); - -void thunar_application_rename_file (ThunarApplication *application, - ThunarFile *file, - GdkScreen *screen, - const gchar *startup_id); -void thunar_application_create_file (ThunarApplication *application, - ThunarFile *parent_directory, - const gchar *content_type, - GdkScreen *screen, - const gchar *startup_id); -void thunar_application_copy_to (ThunarApplication *application, - gpointer parent, - GList *source_file_list, - GList *target_file_list, - GClosure *new_files_closure); - -void thunar_application_copy_into (ThunarApplication *application, - gpointer parent, - GList *source_file_list, - GFile *target_file, - GClosure *new_files_closure); - -void thunar_application_link_into (ThunarApplication *application, - gpointer parent, - GList *source_file_list, - GFile *target_file, - GClosure *new_files_closure); - -void thunar_application_move_into (ThunarApplication *application, - gpointer parent, - GList *source_file_list, - GFile *target_file, - GClosure *new_files_closure); - -void thunar_application_unlink_files (ThunarApplication *application, - gpointer parent, - GList *file_list, - gboolean permanently); - -void thunar_application_trash (ThunarApplication *application, - gpointer parent, - GList *file_list); - -void thunar_application_creat (ThunarApplication *application, - gpointer parent, - GList *file_list, - GClosure *new_files_closure); - -void thunar_application_mkdir (ThunarApplication *application, - gpointer parent, - GList *file_list, - GClosure *new_files_closure); - -void thunar_application_empty_trash (ThunarApplication *application, - gpointer parent, - const gchar *startup_id); - -void thunar_application_restore_files (ThunarApplication *application, - gpointer parent, - GList *trash_file_list, - GClosure *new_files_closure); +GType thunar_application_get_type (void) G_GNUC_CONST; + +ThunarApplication *thunar_application_get (void); + +gboolean thunar_application_get_daemon (ThunarApplication *application); +void thunar_application_set_daemon (ThunarApplication *application, + gboolean daemon); + +GList *thunar_application_get_windows (ThunarApplication *application); + +gboolean thunar_application_has_windows (ThunarApplication *application); + +void thunar_application_take_window (ThunarApplication *application, + GtkWindow *window); + +GtkWidget *thunar_application_open_window (ThunarApplication *application, + ThunarFile *directory, + GdkScreen *screen, + const gchar *startup_id); + +gboolean thunar_application_bulk_rename (ThunarApplication *application, + const gchar *working_directory, + gchar **filenames, + gboolean standalone, + GdkScreen *screen, + const gchar *startup_id, + GError **error); + +GtkWidget *thunar_application_get_progress_dialog (ThunarApplication *application); + +gboolean thunar_application_process_filenames (ThunarApplication *application, + const gchar *working_directory, + gchar **filenames, + GdkScreen *screen, + const gchar *startup_id, + GError **error); + +gboolean thunar_application_is_processing (ThunarApplication *application); + +void thunar_application_rename_file (ThunarApplication *application, + ThunarFile *file, + GdkScreen *screen, + const gchar *startup_id); +void thunar_application_create_file (ThunarApplication *application, + ThunarFile *parent_directory, + const gchar *content_type, + GdkScreen *screen, + const gchar *startup_id); +void thunar_application_create_file_from_template (ThunarApplication *application, + ThunarFile *parent_directory, + ThunarFile *template_file, + GdkScreen *screen, + const gchar *startup_id); +void thunar_application_copy_to (ThunarApplication *application, + gpointer parent, + GList *source_file_list, + GList *target_file_list, + GClosure *new_files_closure); + +void thunar_application_copy_into (ThunarApplication *application, + gpointer parent, + GList *source_file_list, + GFile *target_file, + GClosure *new_files_closure); + +void thunar_application_link_into (ThunarApplication *application, + gpointer parent, + GList *source_file_list, + GFile *target_file, + GClosure *new_files_closure); + +void thunar_application_move_into (ThunarApplication *application, + gpointer parent, + GList *source_file_list, + GFile *target_file, + GClosure *new_files_closure); + +void thunar_application_unlink_files (ThunarApplication *application, + gpointer parent, + GList *file_list, + gboolean permanently); + +void thunar_application_trash (ThunarApplication *application, + gpointer parent, + GList *file_list); + +void thunar_application_creat (ThunarApplication *application, + gpointer parent, + GList *file_list, + GClosure *new_files_closure); + +void thunar_application_mkdir (ThunarApplication *application, + gpointer parent, + GList *file_list, + GClosure *new_files_closure); + +void thunar_application_empty_trash (ThunarApplication *application, + gpointer parent, + const gchar *startup_id); + +void thunar_application_restore_files (ThunarApplication *application, + gpointer parent, + GList *trash_file_list, + GClosure *new_files_closure); G_END_DECLS; diff --git a/thunar/thunar-dbus-service-infos.xml b/thunar/thunar-dbus-service-infos.xml index 4e3818c85ded8de3d18f8b31e5f1731635b3cd11..0a8dba8e63c96206e27be5504fdc225b576aa3a5 100644 --- a/thunar/thunar-dbus-service-infos.xml +++ b/thunar/thunar-dbus-service-infos.xml @@ -288,7 +288,7 @@ </method> <!-- - CreateFile (working_directory : STRING, display : STRING, startup_id : STRING) : VOID + CreateFile (working_directory : content_type : STRING, STRING, display : STRING, startup_id : STRING) : VOID parent_directory : the parent directory in which the file will be created. content_type : content type of the file to be created (text/plain assumed @@ -304,6 +304,23 @@ <arg direction="in" name="display" type="s" /> <arg direction="in" name="startup_id" type="s" /> </method> + + <!-- + CreateFileFromTemplate(working_directory : STRING, template_uri : STRING, display : STRING, start_id : STRING) : VOID + + parent_directory : the parent directory in which the file will be created. + template_uri : the URI or absolute path to the template file. + display : the screen on which to launch the filenames or "" + to use the default screen of the file manager. + startup_id : the DESKTOP_STARTUP_ID environment variable for properly + handling startup notification and focus stealing. + --> + <method name="CreateFileFromTemplate"> + <arg direction="in" name="parent_directory" type="s" /> + <arg direction="in" name="template_uri" type="s" /> + <arg direction="in" name="display" type="s" /> + <arg direction="in" name="startup_id" type="s" /> + </method> </interface> @@ -439,7 +456,6 @@ <arg direction="in" name="startup_id" type="s" /> </method> - <!-- Terminate () : VOID diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c index c8fcc0359a1bcd164b82afa2589f82730b2cb041..8a864a9ced9d7c2552241b6e494078f2d9056ff7 100644 --- a/thunar/thunar-dbus-service.c +++ b/thunar/thunar-dbus-service.c @@ -147,6 +147,12 @@ static gboolean thunar_dbus_service_create_file (ThunarDBusServi const gchar *display, const gchar *startup_id, GError **error); +static gboolean thunar_dbus_service_create_file_from_template (ThunarDBusService *dbus_service, + const gchar *parent_directory, + const gchar *template_uri, + const gchar *display, + const gchar *startup_id, + GError **error); static gboolean thunar_dbus_service_copy_to (ThunarDBusService *dbus_service, const gchar *working_directory, gchar **source_filenames, @@ -871,6 +877,42 @@ thunar_dbus_service_create_file (ThunarDBusService *dbus_service, +static gboolean +thunar_dbus_service_create_file_from_template (ThunarDBusService *dbus_service, + const gchar *parent_directory, + const gchar *template_uri, + const gchar *display, + const gchar *startup_id, + GError **error) +{ + ThunarApplication *application; + ThunarFile *file; + ThunarFile *template_file; + GdkScreen *screen; + + /* parse uri and display parameters */ + if (!thunar_dbus_service_parse_uri_and_display (dbus_service, parent_directory, display, &file, &screen, error)) + return FALSE; + + /* try to determine the file for the template URI */ + template_file = thunar_file_get_for_uri (template_uri, error); + if(template_file == NULL) + return FALSE; + + /* popup a new window for the folder */ + application = thunar_application_get (); + thunar_application_create_file_from_template (application, file, template_file, screen, startup_id); + g_object_unref (G_OBJECT (application)); + + /* cleanup */ + g_object_unref (G_OBJECT (screen)); + g_object_unref (G_OBJECT (file)); + + return TRUE; +} + + + static gboolean thunar_dbus_service_transfer_files (ThunarDBusTransferMode transfer_mode, const gchar *working_directory,