[nautilus/wip/alexpandelea/batchRename: 16/17] Switch back to GMenu
- From: Alexandru-Ionut Pandelea <alexpandelea src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/alexpandelea/batchRename: 16/17] Switch back to GMenu
- Date: Tue, 5 Jul 2016 16:49:51 +0000 (UTC)
commit 8106a97b72c3d6622222776eabf0bcf6fa74dfe9
Author: Alexandru Pandelea <alexandru pandelea gmail com>
Date: Fri Jul 1 23:45:03 2016 +0300
Switch back to GMenu
The GtkPopoverMenu is no longer used, since it's not really needed.
The sorting by name (ascending and descending) is changed.
Old commented code of handling conflicts is removed, because it was
used for the previous UI.
This commit also fixes some warnings.
https://bugzilla.gnome.org/show_bug.cgi?id=768311
src/nautilus-batch-rename-utilities.c | 64 ++++++----
src/nautilus-batch-rename-utilities.h | 12 ++
src/nautilus-batch-rename.c | 154 ++++++----------------
src/resources/ui/nautilus-batch-rename-dialog.ui | 76 +++++-------
4 files changed, 123 insertions(+), 183 deletions(-)
---
diff --git a/src/nautilus-batch-rename-utilities.c b/src/nautilus-batch-rename-utilities.c
index 624f8be..22861f2 100644
--- a/src/nautilus-batch-rename-utilities.c
+++ b/src/nautilus-batch-rename-utilities.c
@@ -204,47 +204,63 @@ concat(gchar *s1, gchar *s2)
}
gint
-compare_files_by_name_ascending (NautilusFile *f1,
- NautilusFile *f2)
+compare_files_by_name_ascending (gconstpointer a,
+ gconstpointer b)
{
- if (f1 == f2)
- return 0;
+ NautilusFile *f1;
+ NautilusFile *f2;
- if (strcmp (nautilus_file_get_name (f1), nautilus_file_get_name (f2)) >= 0) {
- return 1;
- }
- return -1;
+ f1 = NAUTILUS_FILE (a);
+ f2 = NAUTILUS_FILE (b);
+
+ return nautilus_file_compare_for_sort (f1,f2,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ FALSE, FALSE);
}
gint
-compare_files_by_name_descending (NautilusFile *f1,
- NautilusFile *f2)
+compare_files_by_name_descending (gconstpointer a,
+ gconstpointer b)
{
- if (f1 == f2)
- return 0;
+ NautilusFile *f1;
+ NautilusFile *f2;
- if (strcmp (nautilus_file_get_name (f1), nautilus_file_get_name (f2)) >= 0) {
- return -1;
- }
- return 1;
+ f1 = NAUTILUS_FILE (a);
+ f2 = NAUTILUS_FILE (b);
+
+ return nautilus_file_compare_for_sort (f1,f2,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ FALSE, TRUE);
}
gint
-compare_files_by_first_modified (NautilusFile *f1,
- NautilusFile *f2)
+compare_files_by_first_modified (gconstpointer a,
+ gconstpointer b)
{
+ NautilusFile *f1;
+ NautilusFile *f2;
+
+ f1 = NAUTILUS_FILE (a);
+ f2 = NAUTILUS_FILE (b);
+
return nautilus_file_compare_for_sort (f1,f2,
- NAUTILUS_FILE_SORT_BY_MTIME,
- FALSE, FALSE);
+ NAUTILUS_FILE_SORT_BY_MTIME,
+ FALSE, FALSE);
}
gint
-compare_files_by_last_modified (NautilusFile *f1,
- NautilusFile *f2)
+compare_files_by_last_modified (gconstpointer a,
+ gconstpointer b)
{
+ NautilusFile *f1;
+ NautilusFile *f2;
+
+ f1 = NAUTILUS_FILE (a);
+ f2 = NAUTILUS_FILE (b);
+
return nautilus_file_compare_for_sort (f1,f2,
- NAUTILUS_FILE_SORT_BY_MTIME,
- FALSE, TRUE);
+ NAUTILUS_FILE_SORT_BY_MTIME,
+ FALSE, TRUE);
}
GList*
diff --git a/src/nautilus-batch-rename-utilities.h b/src/nautilus-batch-rename-utilities.h
index 28df907..842da36 100644
--- a/src/nautilus-batch-rename-utilities.h
+++ b/src/nautilus-batch-rename-utilities.h
@@ -29,4 +29,16 @@ gchar* concat (gchar *s1,
GList* nautilus_batch_rename_sort (GList *selection,
SortingMode mode);
+gint compare_files_by_last_modified (gconstpointer a,
+ gconstpointer b);
+
+gint compare_files_by_first_modified (gconstpointer a,
+ gconstpointer b);
+
+gint compare_files_by_name_descending (gconstpointer a,
+ gconstpointer b);
+
+gint compare_files_by_name_ascending (gconstpointer a,
+ gconstpointer b);
+
#endif /* NAUTILUS_BATCH_RENAME_UTILITIES_H */
\ No newline at end of file
diff --git a/src/nautilus-batch-rename.c b/src/nautilus-batch-rename.c
index a5c2ae0..8420cb6 100644
--- a/src/nautilus-batch-rename.c
+++ b/src/nautilus-batch-rename.c
@@ -38,12 +38,10 @@ struct _NautilusBatchRename
GtkWidget *cancel_button;
GtkWidget *conflict_listbox;
GtkWidget *error_label;
- //GtkWidget *expander;
GtkWidget *name_entry;
GtkWidget *rename_button;
GtkWidget *find_entry;
GtkWidget *mode_stack;
- // GtkWidget *label_stack;
GtkWidget *replace_entry;
GtkWidget *format_mode_button;
GtkWidget *replace_mode_button;
@@ -64,6 +62,8 @@ struct _NautilusBatchRename
GtkWidget *expander_label;
GActionGroup *action_group;
+
+ GMenu *numbering_order_menu;
};
static void batch_rename_dialog_on_closed (GtkDialog *dialog);
@@ -72,61 +72,6 @@ static void file_names_widget_entry_on_changed (NautilusBatchRename
G_DEFINE_TYPE (NautilusBatchRename, nautilus_batch_rename, GTK_TYPE_DIALOG);
-/*
-static void
-numbering_order_changed_descending (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- NautilusBatchRename *dialog;
-
- dialog = NAUTILUS_BATCH_RENAME (user_data);
-
- dialog->selection = nautilus_batch_rename_sort (dialog->selection, ORIGINAL_DESCENDING);
-
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- "Original name (Descending)");
-
-
- file_names_widget_entry_on_changed (dialog);
-}
-
-static void
-numbering_order_changed_ascending (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- NautilusBatchRename *dialog;
-
- dialog = NAUTILUS_BATCH_RENAME (user_data);
-
- dialog->selection = nautilus_batch_rename_sort (dialog->selection, ORIGINAL_ASCENDING);
-
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- "Original name (Ascending) ");
-
-
- file_names_widget_entry_on_changed (dialog);
-}
-
-static void
-numbering_order_changed_first_modified (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- NautilusBatchRename *dialog;
-
- dialog = NAUTILUS_BATCH_RENAME (user_data);
-
- dialog->selection = nautilus_batch_rename_sort (dialog->selection, FIRST_MODIFIED);
-
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- "First Modified ");
-
-
- file_names_widget_entry_on_changed (dialog);
-}*/
-
static void
numbering_order_changed (GSimpleAction *action,
GVariant *value,
@@ -136,22 +81,47 @@ numbering_order_changed (GSimpleAction *action,
const gchar *target_name;
dialog = NAUTILUS_BATCH_RENAME (user_data);
- dialog->selection = nautilus_batch_rename_sort (dialog->selection, LAST_MODIFIED);
target_name = g_variant_get_string (value, NULL);
g_message("%s",target_name);
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- "Last Modified ");
+ if (g_strcmp0 (target_name, "name-ascending") == 0) {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ "Original name (Ascending) ");
+ dialog->selection = nautilus_batch_rename_sort (dialog->selection, ORIGINAL_ASCENDING);
+ }
+
+ if (g_strcmp0 (target_name, "name-descending") == 0) {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ "Original name (Descending)");
+ dialog->selection = nautilus_batch_rename_sort (dialog->selection,
+ ORIGINAL_DESCENDING);
+ }
+
+ if (g_strcmp0 (target_name, "first-modified") == 0) {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ "First Modified ");
+ dialog->selection = nautilus_batch_rename_sort (dialog->selection,
+ FIRST_MODIFIED);
+ }
+
+ if (g_strcmp0 (target_name, "last-modified") == 0) {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ "Last Modified ");
+ dialog->selection = nautilus_batch_rename_sort (dialog->selection,
+ LAST_MODIFIED);
+ }
+
+ g_simple_action_set_state (action, value);
- //g_simple_action_set_state (action, state);
+ g_signal_emit_by_name (dialog->numbering_order_popover, "closed");
/* update display text */
file_names_widget_entry_on_changed (dialog);
}
const GActionEntry dialog_entries[] = {
- { "numbering-order-changed", numbering_order_changed },
+ { "numbering-order-changed", NULL, "s", "'name-ascending'", numbering_order_changed }
};
static GList*
@@ -195,12 +165,6 @@ rename_files_on_names_accepted (NautilusBatchRename *dialog,
for (l1 = selection, l2 = new_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
file = NAUTILUS_FILE (l1->data);
- /* Put it on the queue for reveal after the view acknowledges the change */
- //do this sometime...
- /*g_hash_table_insert (dialog->view->details->pending_reveal,
- file,
- GUINT_TO_POINTER (FALSE));*/
-
nautilus_rename_file (file, l2->data, NULL, NULL);
}
@@ -317,12 +281,11 @@ static void
file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
{
gchar *entry_text;
- //gchar *replace_text;
gchar *file_name;
GList *new_names;
GList *duplicates;
gchar *display_text = NULL;
- gboolean singe_conflict;
+ gboolean single_conflict;
if(dialog->selection == NULL)
return;
@@ -331,7 +294,7 @@ file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
duplicates = list_has_duplicates (dialog->view, new_names, dialog->selection);
if (duplicates != NULL)
- singe_conflict = (duplicates->next == NULL) ? TRUE:FALSE;
+ single_conflict = (duplicates->next == NULL) ? TRUE:FALSE;
file_name = NULL;
entry_text = NULL;
@@ -340,48 +303,13 @@ file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
if (duplicates != NULL) {
gtk_widget_set_sensitive (dialog->rename_button, FALSE);
- /* check if there is more than one conflict */
- /*if (!singe_conflict)
- gtk_expander_set_label (GTK_EXPANDER (dialog->expander),
- "Multiple file conflicts");
- else {
- file_name = concat ("File conflict: ", duplicates->data);
-
- if (strlen (file_name) >= MAX_DISPLAY_LEN) {
- gtk_label_set_label (GTK_LABEL (dialog->expander_label), file_name);
-
- gtk_expander_set_label_widget (GTK_EXPANDER (dialog->expander),
- dialog->expander_label);
-
- gtk_widget_show (dialog->expander_label);
- } else {
- gtk_label_set_label (GTK_LABEL (dialog->error_label), file_name);
- }
- }*/
-
- if (!singe_conflict || strlen (file_name) >= MAX_DISPLAY_LEN) {
- // gtk_expander_set_expanded (GTK_EXPANDER (dialog->expander), FALSE);
- // gtk_stack_set_visible_child (GTK_STACK (dialog->label_stack),
- // GTK_WIDGET (dialog->expander));
- }
-
- /* add name conflicts to the listbox */
- //fill_conflict_listbox (dialog, duplicates);
-
- g_free (file_name);
-
return;
}
else
/* re-enable the rename button if there are no more name conflicts */
- if (duplicates == NULL && !gtk_widget_is_sensitive (dialog->rename_button)) {
- //gtk_expander_set_expanded (GTK_EXPANDER (dialog->expander), FALSE);
-
+ if (duplicates == NULL && !gtk_widget_is_sensitive (dialog->rename_button))
gtk_widget_set_sensitive (dialog->rename_button, TRUE);
- //gtk_stack_set_visible_child (GTK_STACK (dialog->label_stack), GTK_WIDGET
(dialog->error_label));
- }
-
/* Update listbox that shows the result of the renaming for each file */
fill_display_listbox (dialog, new_names);
@@ -390,7 +318,6 @@ file_names_widget_entry_on_changed (NautilusBatchRename *dialog)
g_free (entry_text);
g_free (file_name);
- //g_free (replace_text);
g_free (display_text);
}
@@ -498,7 +425,6 @@ nautilus_batch_rename_class_init (NautilusBatchRenameClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, cancel_button);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, conflict_listbox);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, error_label);
- //gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, expander);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, name_entry);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, rename_button);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, find_entry);
@@ -513,6 +439,7 @@ nautilus_batch_rename_class_init (NautilusBatchRenameClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, scrolled_window);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_popover);
gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_menu);
gtk_widget_class_bind_template_callback (widget_class, file_names_widget_entry_on_changed);
gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_on_closed);
@@ -545,9 +472,6 @@ nautilus_batch_rename_new (NautilusFilesView *view)
gtk_label_set_ellipsize (GTK_LABEL (dialog->error_label), PANGO_ELLIPSIZE_END);
gtk_label_set_max_width_chars (GTK_LABEL (dialog->error_label), MAX_DISPLAY_LEN);
- //gtk_label_set_ellipsize (GTK_LABEL (dialog->expander_label), PANGO_ELLIPSIZE_END);
- //gtk_label_set_max_width_chars (GTK_LABEL (dialog->expander_label), MAX_DISPLAY_LEN - 1);
-
gtk_label_set_markup_with_mnemonic (GTK_LABEL (dialog->add_button_label),
"<b>+</b> _Add");
@@ -562,6 +486,10 @@ nautilus_batch_rename_new (NautilusFilesView *view)
sprintf (dialog_title, "Renaming %d files", files_nr);
gtk_window_set_title (GTK_WINDOW (dialog), dialog_title);
+ gtk_popover_bind_model (GTK_POPOVER (dialog->numbering_order_popover),
+ G_MENU_MODEL (dialog->numbering_order_menu),
+ NULL);
+
nautilus_batch_rename_initialize_actions (dialog);
/* update display text */
@@ -582,7 +510,5 @@ nautilus_batch_rename_init (NautilusBatchRename *self)
self,
NULL);
- //self->expander_label = gtk_label_new ("");
-
self->mode = NAUTILUS_BATCH_RENAME_PREPEND;
}
\ No newline at end of file
diff --git a/src/resources/ui/nautilus-batch-rename-dialog.ui
b/src/resources/ui/nautilus-batch-rename-dialog.ui
index 6c5f7e5..edf4d80 100644
--- a/src/resources/ui/nautilus-batch-rename-dialog.ui
+++ b/src/resources/ui/nautilus-batch-rename-dialog.ui
@@ -321,52 +321,38 @@
<property name="visible">True</property>
<property name="icon_name">object-select-symbolic</property>
</object>
- <object class="GtkPopoverMenu" id="numbering_order_popover">
- <property name="relative-to">numbering_order_button</property>
+ <menu id="numbering_order_menu">
+ <section>
+ <item>
+ <attribute name="id">name_ascending</attribute>
+ <attribute name="label" translatable="yes">Original name (Ascending) </attribute>
+ <attribute name="action">dialog.numbering-order-changed</attribute>
+ <attribute name="target">name-ascending</attribute>
+ </item>
+ <item>
+ <attribute name="id">name_descending</attribute>
+ <attribute name="label" translatable="yes">Original name (Descending)</attribute>
+ <attribute name="action">dialog.numbering-order-changed</attribute>
+ <attribute name="target">name-descending</attribute>
+ </item>
+ <item>
+ <attribute name="id">first_modified</attribute>
+ <attribute name="label" translatable="yes">First Modified</attribute>
+ <attribute name="action">dialog.numbering-order-changed</attribute>
+ <attribute name="target">first-modified</attribute>
+ </item>
+ <item>
+ <attribute name="id">last_modified</attribute>
+ <attribute name="label" translatable="yes">Last Modified</attribute>
+ <attribute name="action">dialog.numbering-order-changed</attribute>
+ <attribute name="verb-icon">object-select-symbolic</attribute>
+ <attribute name="target">last-modified</attribute>
+ </item>
+ </section>
+ </menu>
+ <object class="GtkPopover" id="numbering_order_popover">
<property name="position">bottom</property>
+ <property name="relative-to">numbering_order_button</property>
<signal name="closed" handler="numbering_order_popover_closed" swapped="yes" />
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkModelButton" id="original_ascending">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="text" translatable="yes">Original name (Ascending) </property>
- <property name="action-name">dialog.numbering-order-changed</property>
- <property name="action-target">'name-ascending'</property>
- </object>
- </child>
- <child>
- <object class="GtkModelButton" id="original_descending">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="text" translatable="yes">Original name (Descending) </property>
- <property name="action-name">dialog.numbering-order-changed</property>
- <property name="action-target">'name-descending'</property>
- </object>
- </child>
- <child>
- <object class="GtkModelButton" id="first_modified">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="text" translatable="yes">First Modified</property>
- <property name="action-name">dialog.numbering-order-changed</property>
- <property name="action-target">'first-modified'</property>
- </object>
- </child>
- <child>
- <object class="GtkModelButton" id="last_modified">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="text" translatable="yes">Last Modified</property>
- <property name="action-name">dialog.numbering-order-changed</property>
- <property name="action-target">'last-modified'</property>
- </object>
- </child>
- </object>
- </child>
</object>
</interface>
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]