[Xfce4-commits] <thunar:master> Add CreateFile() method to the org.xfce.FileManager D-Bus service.
Jannis Pohlmann
noreply at xfce.org
Tue Oct 19 13:06:02 CEST 2010
Updating branch refs/heads/master
to c4c9c6ab55e7eba3d12d6c7fdf04a168f97598b7 (commit)
from ec96d9f50b2c9d39fc07948d5beabc8fc90ffea8 (commit)
commit c4c9c6ab55e7eba3d12d6c7fdf04a168f97598b7
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Oct 19 13:02:48 2010 +0200
Add CreateFile() method to the org.xfce.FileManager D-Bus service.
This method takes a parent directory, a content type, a display and a
startup ID and prompts the user to enter a new name for the file (or
directory) to be created.
thunar/thunar-application.c | 71 +++++++++++++++++++++++++++++++++-
thunar/thunar-application.h | 6 ++-
thunar/thunar-dbus-service-infos.xml | 18 +++++++++
thunar/thunar-dbus-service.c | 40 +++++++++++++++++++
4 files changed, 133 insertions(+), 2 deletions(-)
diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index 950604a..88fb291 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -44,6 +44,7 @@
#include <thunar/thunar-application.h>
#include <thunar/thunar-browser.h>
+#include <thunar/thunar-create-dialog.h>
#include <thunar/thunar-dialogs.h>
#include <thunar/thunar-gdk-extensions.h>
#include <thunar/thunar-gobject-extensions.h>
@@ -1280,10 +1281,78 @@ thunar_application_rename_file (ThunarApplication *application,
/**
+ * thunar_application_create_folder:
+ * @application : a #ThunarApplication.
+ * @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.
+ * @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.
+ * The @content_type defines the icon and other elements in the filename
+ * prompt dialog.
+ **/
+void
+thunar_application_create_file (ThunarApplication *application,
+ ThunarFile *parent_directory,
+ const gchar *content_type,
+ GdkScreen *screen,
+ const gchar *startup_id)
+{
+ const gchar *dialog_title;
+ const gchar *title;
+ gboolean is_directory;
+ GList path_list;
+ gchar *name;
+
+ _thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
+ _thunar_return_if_fail (THUNAR_IS_FILE (parent_directory));
+ _thunar_return_if_fail (content_type != NULL && *content_type != '\0');
+ _thunar_return_if_fail (GDK_IS_SCREEN (screen));
+ _thunar_return_if_fail (startup_id != NULL);
+
+ is_directory = (g_strcmp0 (content_type, "inode/directory") == 0);
+
+ if (is_directory)
+ {
+ dialog_title = _("New Folder");
+ title = _("Create New Folder");
+ }
+ else
+ {
+ dialog_title = _("New File");
+ title = _("Create New File");
+ }
+
+ /* TODO pass the startup ID to the rename dialog */
+
+ /* ask the user to enter a name for the new folder */
+ name = thunar_show_create_dialog (screen, content_type, dialog_title, title);
+ if (G_LIKELY (name != NULL))
+ {
+ path_list.data = g_file_get_child (thunar_file_get_file (parent_directory), name);
+ path_list.next = path_list.prev = NULL;
+
+ /* launch the operation */
+ if (is_directory)
+ thunar_application_mkdir (application, screen, &path_list, NULL);
+ else
+ thunar_application_creat (application, screen, &path_list, NULL);
+
+ g_object_unref (path_list.data);
+ g_free (name);
+ }
+}
+
+
+
+/**
* thunar_application_copy_to:
* @application : a #ThunarApplication.
* @parent : a #GdkScreen, a #GtkWidget or %NULL.
- * @source_file_list : the list of #GFile<!---->s that should be copied.
+ * @source_file_list : the lst of #GFile<!---->s that should be copied.
* @target_file_list : the list of #GFile<!---->s where files should be copied to.
* @new_files_closure : a #GClosure to connect to the job's "new-files" signal,
* which will be emitted when the job finishes with the
diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h
index f00be2a..eb04f94 100644
--- a/thunar/thunar-application.h
+++ b/thunar/thunar-application.h
@@ -79,7 +79,11 @@ void thunar_application_rename_file (ThunarApplication *ap
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,
diff --git a/thunar/thunar-dbus-service-infos.xml b/thunar/thunar-dbus-service-infos.xml
index fd53a52..4e3818c 100644
--- a/thunar/thunar-dbus-service-infos.xml
+++ b/thunar/thunar-dbus-service-infos.xml
@@ -286,6 +286,24 @@
<arg direction="in" name="display" type="s" />
<arg direction="in" name="startup_id" type="s" />
</method>
+
+ <!--
+ CreateFile (working_directory : 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
+ when empty).
+ 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="CreateFile">
+ <arg direction="in" name="parent_directory" type="s" />
+ <arg direction="in" name="content_type" type="s" />
+ <arg direction="in" name="display" type="s" />
+ <arg direction="in" name="startup_id" type="s" />
+ </method>
</interface>
diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c
index 672a0de..c8fcc03 100644
--- a/thunar/thunar-dbus-service.c
+++ b/thunar/thunar-dbus-service.c
@@ -141,6 +141,12 @@ static gboolean thunar_dbus_service_rename_file (ThunarDBusServi
const gchar *display,
const gchar *startup_id,
GError **error);
+static gboolean thunar_dbus_service_create_file (ThunarDBusService *dbus_service,
+ const gchar *parent_directory,
+ const gchar *content_type,
+ 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,
@@ -832,6 +838,40 @@ thunar_dbus_service_rename_file (ThunarDBusService *dbus_service,
static gboolean
+thunar_dbus_service_create_file (ThunarDBusService *dbus_service,
+ const gchar *parent_directory,
+ const gchar *content_type,
+ const gchar *display,
+ const gchar *startup_id,
+ GError **error)
+{
+ ThunarApplication *application;
+ ThunarFile *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;
+
+ /* fall back to plain text file if no content type is provided */
+ if (content_type == NULL || *content_type == '\0')
+ content_type = "text/plain";
+
+ /* popup a new window for the folder */
+ application = thunar_application_get ();
+ thunar_application_create_file (application, file, content_type, 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,
const gchar * const *source_filenames,
More information about the Xfce4-commits
mailing list