This is an automated email from the git hooks/post-receive script. o c h o s i p u s h e d a c o m m i t t o b r a n c h m a s t e r in repository xfce/xfce4-panel.
commit ab86c3c8a1c075b2a5ca4c70b7272ea36b301faf Author: cryptogopher <x...@michalczyk.pro> Date: Tue Dec 10 16:24:28 2019 +0100 directorymenu: Add create folder/document menuitems (Bug #15639) --- plugins/directorymenu/directorymenu-dialog.glade | 78 +++++++- plugins/directorymenu/directorymenu.c | 244 ++++++++++++++++++++++- 2 files changed, 312 insertions(+), 10 deletions(-) diff --git a/plugins/directorymenu/directorymenu-dialog.glade b/plugins/directorymenu/directorymenu-dialog.glade index b7e6960..6daa61d 100644 --- a/plugins/directorymenu/directorymenu-dialog.glade +++ b/plugins/directorymenu/directorymenu-dialog.glade @@ -140,9 +140,56 @@ <property name="top_attach">0</property> </packing> </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Appearance</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkFrame" id="frame2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <child> + <object class="GtkGrid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">18</property> + <property name="row_spacing">6</property> + <property name="column_spacing">12</property> <child> - <object class="GtkCheckButton" id="open-folder"> - <property name="label" translatable="yes">Show 'Open _Folder'</property> + <object class="GtkCheckButton" id="new-document"> + <property name="label" translatable="yes">Show 'New Text _Document'</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="new-folder"> + <property name="label" translatable="yes">Show '_New Folder'</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">False</property> @@ -153,7 +200,6 @@ <packing> <property name="left_attach">0</property> <property name="top_attach">2</property> - <property name="width">2</property> </packing> </child> <child> @@ -168,17 +214,31 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">3</property> - <property name="width">2</property> + <property name="top_attach">1</property> + </packing> + </child> + <child> + <object class="GtkCheckButton" id="open-folder"> + <property name="label" translatable="yes">Show '_Open _Folder'</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_underline">True</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> </packing> </child> </object> </child> <child type="label"> - <object class="GtkLabel" id="label1"> + <object class="GtkLabel" id="label5"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">Appearance</property> + <property name="label" translatable="yes">Menu</property> <attributes> <attribute name="weight" value="bold"/> </attributes> @@ -188,7 +248,7 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">0</property> + <property name="position">1</property> </packing> </child> <child> @@ -260,7 +320,7 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> </object> diff --git a/plugins/directorymenu/directorymenu.c b/plugins/directorymenu/directorymenu.c index b7e50d9..4bddec1 100644 --- a/plugins/directorymenu/directorymenu.c +++ b/plugins/directorymenu/directorymenu.c @@ -38,6 +38,8 @@ #define DEFAULT_ICON_NAME "folder" +#define DIALOG_RESPONSE_CREATE 0 +#define DIALOG_RESPONSE_OPEN 1 struct _DirectoryMenuPluginClass { @@ -55,6 +57,8 @@ struct _DirectoryMenuPlugin gchar *icon_name; guint open_folder; guint open_in_terminal; + guint new_folder; + guint new_document; gchar *file_pattern; guint hidden_files : 1; @@ -73,7 +77,9 @@ enum PROP_FILE_PATTERN, PROP_HIDDEN_FILES, PROP_OPEN_FOLDER, - PROP_OPEN_IN_TERMINAL + PROP_OPEN_IN_TERMINAL, + PROP_NEW_FOLDER, + PROP_NEW_DOCUMENT }; @@ -154,6 +160,20 @@ directory_menu_plugin_class_init (DirectoryMenuPluginClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, + PROP_NEW_FOLDER, + g_param_spec_boolean ("new-folder", + NULL, NULL, + TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, + PROP_NEW_DOCUMENT, + g_param_spec_boolean ("new-document", + NULL, NULL, + TRUE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, PROP_FILE_PATTERN, g_param_spec_string ("file-pattern", NULL, NULL, @@ -189,6 +209,8 @@ directory_menu_plugin_init (DirectoryMenuPlugin *plugin) plugin->open_folder = TRUE; plugin->open_in_terminal = TRUE; + plugin->new_folder = TRUE; + plugin->new_document = TRUE; } @@ -224,6 +246,14 @@ directory_menu_plugin_get_property (GObject *object, g_value_set_boolean (value, plugin->open_in_terminal); break; + case PROP_NEW_FOLDER: + g_value_set_boolean (value, plugin->new_folder); + break; + + case PROP_NEW_DOCUMENT: + g_value_set_boolean (value, plugin->new_document); + break; + case PROP_FILE_PATTERN: g_value_set_string (value, panel_str_is_empty (plugin->file_pattern) ? "" : plugin->file_pattern); @@ -290,6 +320,14 @@ directory_menu_plugin_set_property (GObject *object, plugin->open_in_terminal = g_value_get_boolean (value); break; + case PROP_NEW_FOLDER: + plugin->new_folder = g_value_get_boolean (value); + break; + + case PROP_NEW_DOCUMENT: + plugin->new_document = g_value_get_boolean (value); + break; + case PROP_FILE_PATTERN: g_free (plugin->file_pattern); plugin->file_pattern = g_value_dup_string (value); @@ -330,6 +368,8 @@ directory_menu_plugin_construct (XfcePanelPlugin *panel_plugin) { "icon-name", G_TYPE_STRING }, { "open-folder", G_TYPE_BOOLEAN }, { "open-in-terminal", G_TYPE_BOOLEAN }, + { "new-folder", G_TYPE_BOOLEAN }, + { "new-document", G_TYPE_BOOLEAN }, { "file-pattern", G_TYPE_STRING }, { "hidden-files", G_TYPE_BOOLEAN }, { NULL } @@ -500,6 +540,18 @@ directory_menu_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) G_OBJECT (object), "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + object = gtk_builder_get_object (builder, "new-folder"); + panel_return_if_fail (GTK_IS_CHECK_BUTTON (object)); + g_object_bind_property (G_OBJECT (plugin), "new-folder", + G_OBJECT (object), "active", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + + object = gtk_builder_get_object (builder, "new-document"); + panel_return_if_fail (GTK_IS_CHECK_BUTTON (object)); + g_object_bind_property (G_OBJECT (plugin), "new-document", + G_OBJECT (object), "active", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + object = gtk_builder_get_object (builder, "file-pattern"); panel_return_if_fail (GTK_IS_ENTRY (object)); g_object_bind_property (G_OBJECT (plugin), "file-pattern", @@ -823,6 +875,162 @@ directory_menu_plugin_menu_open_folder (GtkWidget *mi, static void +directory_menu_plugin_menu_name_entry_changed (GtkEditable *editable, + gpointer dialog) +{ + const gchar *text; + GtkWidget *create_button; + GtkWidget *open_button; + + create_button = gtk_dialog_get_widget_for_response (GTK_DIALOG(dialog), + DIALOG_RESPONSE_CREATE); + open_button = gtk_dialog_get_widget_for_response (GTK_DIALOG(dialog), + DIALOG_RESPONSE_OPEN); + + text = gtk_entry_get_text (GTK_ENTRY(editable)); + if (strlen(text) > 0) + { + gtk_widget_set_sensitive (create_button, TRUE); + gtk_widget_set_sensitive (open_button, TRUE); + } + else + { + gtk_widget_set_sensitive (create_button, FALSE); + gtk_widget_set_sensitive (open_button, FALSE); + } +} + + + +static void +directory_menu_plugin_create_new (GtkWidget *mi, + GFile *parent_dir, + gboolean is_folder) +{ + GtkWidget *dialog; + const gchar *dialog_title; + gint dialog_retval; + GtkWidget *content; + GtkWidget *grid; + GtkWidget *icon; + GtkWidget *label; + GtkWidget *entry; + GDateTime *date; + gchar *formatted_date; + const gchar *filename; + gchar *filepath; + GFile *new_file = NULL; + GError *error = NULL; + + if (is_folder) + { + dialog_title = _("Create New Folder"); + icon = gtk_image_new_from_icon_name ("folder", GTK_ICON_SIZE_DIALOG); + } + else + { + dialog_title = _("Create New Text Document"); + icon = gtk_image_new_from_icon_name ("text-x-generic", GTK_ICON_SIZE_DIALOG); + } + + dialog = gtk_dialog_new_with_buttons (dialog_title, NULL, + GTK_DIALOG_MODAL, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("C_reate"), DIALOG_RESPONSE_CREATE, + _("Create & _Open"), DIALOG_RESPONSE_OPEN, + NULL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), 1); + + grid = gtk_grid_new (); + gtk_grid_set_row_spacing (GTK_GRID (grid), 9); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + gtk_widget_set_margin_start (grid, 6); + gtk_widget_set_margin_end (grid, 6); + gtk_widget_set_margin_top (grid, 6); + gtk_widget_set_margin_bottom (grid, 6); + + gtk_grid_attach (GTK_GRID (grid), icon, 0, 0, 1, 2); + + label = gtk_label_new (_("Enter the new name:")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1); + + date = g_date_time_new_now_local (); + formatted_date = g_date_time_format (date, "%F %T"); + entry = gtk_entry_new (); + gtk_widget_set_hexpand (entry, TRUE); + gtk_entry_set_text (GTK_ENTRY(entry), formatted_date); + g_free (formatted_date); + g_date_time_unref (date); + gtk_grid_attach (GTK_GRID (grid), entry, 1, 1, 1, 1); + g_signal_connect (entry, "changed", + G_CALLBACK (directory_menu_plugin_menu_name_entry_changed), + dialog); + + content = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + gtk_container_add (GTK_CONTAINER (content), grid); + gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); + gtk_widget_show_all (dialog); + + dialog_retval = gtk_dialog_run (GTK_DIALOG (dialog)); + if (dialog_retval >= 0) + { + filename = gtk_entry_get_text (GTK_ENTRY(entry)); + if (strlen(filename) > 0) + { + new_file = g_file_get_child (parent_dir, filename); + if (is_folder) + g_file_make_directory (new_file, NULL, &error); + else + g_file_create (new_file, G_FILE_CREATE_NONE, NULL, &error); + + if (error != NULL) + { + filepath = g_file_get_parse_name (new_file); + xfce_dialog_show_error (NULL, error, _("Failed to create folder: %s"), filepath); + g_free (filepath); + g_error_free (error); + } + else if (dialog_retval == DIALOG_RESPONSE_OPEN) + { + if (is_folder) + directory_menu_plugin_menu_open (mi, new_file, "FileManager", TRUE); + else + directory_menu_plugin_menu_launch (mi, new_file); + } + g_object_unref (new_file); + } + } + + gtk_widget_destroy (dialog); +} + + +static void +directory_menu_plugin_menu_new_folder (GtkWidget *mi, + GFile *dir) +{ + panel_return_if_fail (GTK_IS_WIDGET (mi)); + panel_return_if_fail (G_IS_FILE (dir)); + + directory_menu_plugin_create_new (mi, dir, TRUE); +} + + + +static void +directory_menu_plugin_menu_new_document (GtkWidget *mi, + GFile *dir) +{ + panel_return_if_fail (GTK_IS_WIDGET (mi)); + panel_return_if_fail (G_IS_FILE (dir)); + + directory_menu_plugin_create_new (mi, dir, FALSE); +} + + + +static void directory_menu_plugin_menu_unload (GtkWidget *menu) { /* delay destruction so we can handle the activate event first */ @@ -896,6 +1104,40 @@ G_GNUC_END_IGNORE_DEPRECATIONS gtk_widget_show (image); } + if (plugin->new_folder) { +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + mi = gtk_image_menu_item_new_with_label (_("Create Folder...")); +G_GNUC_END_IGNORE_DEPRECATIONS + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); + g_signal_connect_data (G_OBJECT (mi), "activate", + G_CALLBACK (directory_menu_plugin_menu_new_folder), + g_object_ref (dir), (GClosureNotify) (void (*)(void)) g_object_unref, 0); + gtk_widget_show (mi); + + image = gtk_image_new_from_icon_name ("folder-new", GTK_ICON_SIZE_MENU); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image); +G_GNUC_END_IGNORE_DEPRECATIONS + gtk_widget_show (image); + } + + if (plugin->new_document) { +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + mi = gtk_image_menu_item_new_with_label (_("Create Text Document...")); +G_GNUC_END_IGNORE_DEPRECATIONS + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); + g_signal_connect_data (G_OBJECT (mi), "activate", + G_CALLBACK (directory_menu_plugin_menu_new_document), + g_object_ref (dir), (GClosureNotify) (void (*)(void)) g_object_unref, 0); + gtk_widget_show (mi); + + image = gtk_image_new_from_icon_name ("document-new", GTK_ICON_SIZE_MENU); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image); +G_GNUC_END_IGNORE_DEPRECATIONS + gtk_widget_show (image); + } + iter = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE -- To stop receiving notification emails like this one, please contact the administrator of this repository. _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits