summaryrefslogtreecommitdiff
path: root/src/nautilus-properties-window.c
diff options
context:
space:
mode:
authorApoorv Sachan <apoorv.99.sachan@gmail.com>2020-05-29 23:42:33 +0530
committerAntónio Fernandes <antoniojpfernandes@gmail.com>2020-08-05 13:48:10 +0000
commit6f175cf5d965a3d47b0c5c56bbfe22040db00bbe (patch)
tree01d935cd067210ebbafc3c8c6244e130daa0a678 /src/nautilus-properties-window.c
parent4f2e91af71cf8eadf3977bd6958b4045d960ab0d (diff)
downloadnautilus-6f175cf5d965a3d47b0c5c56bbfe22040db00bbe.tar.gz
properties-window: Populate Name row from template
We have been creating either an entry or a label for the name field, depending on whether we were able to edit the name or not. In GtkBuilder UI definitions we cannot do this anymore, as we have to define and build both the entry and the label. So, in order to only show the one we want on each situation, we are introducing a GtkStack to contain both.
Diffstat (limited to 'src/nautilus-properties-window.c')
-rw-r--r--src/nautilus-properties-window.c92
1 files changed, 29 insertions, 63 deletions
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 615ad88b4..866d1b902 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -92,7 +92,8 @@ struct _NautilusPropertiesWindow
GtkGrid *basic_grid;
- GtkLabel *name_label;
+ GtkLabel *name_title_label;
+ GtkStack *name_stack;
GtkWidget *name_field;
unsigned int name_row;
char *pending_name;
@@ -551,59 +552,29 @@ set_name_field (NautilusPropertiesWindow *window,
const gchar *original_name,
const gchar *name)
{
- gboolean new_widget;
+ GtkWidget *stack_child_label;
+ GtkWidget *stack_child_entry;
gboolean use_label;
- /* There are four cases here:
- * 1) Changing the text of a label
- * 2) Changing the text of an entry
- * 3) Creating label (potentially replacing entry)
- * 4) Creating entry (potentially replacing label)
- */
+ stack_child_label = gtk_stack_get_child_by_name (window->name_stack, "name_value_label");
+ stack_child_entry = gtk_stack_get_child_by_name (window->name_stack, "name_value_entry");
+
use_label = is_multi_file_window (window) || !nautilus_file_can_rename (get_original_file (window));
- new_widget = !window->name_field || (use_label ? GTK_IS_ENTRY (window->name_field) : GTK_IS_LABEL (window->name_field));
- if (new_widget)
+ if (use_label)
{
- if (window->name_field)
- {
- gtk_widget_destroy (window->name_field);
- }
-
- if (use_label)
- {
- window->name_field = GTK_WIDGET
- (attach_ellipsizing_value_label (window->basic_grid,
- GTK_WIDGET (window->name_label),
- name));
- }
- else
- {
- window->name_field = gtk_entry_new ();
- gtk_entry_set_text (GTK_ENTRY (window->name_field), name);
- gtk_widget_show (window->name_field);
-
- gtk_grid_attach_next_to (window->basic_grid, window->name_field,
- GTK_WIDGET (window->name_label),
- GTK_POS_RIGHT, 1, 1);
- gtk_label_set_mnemonic_widget (GTK_LABEL (window->name_label), window->name_field);
-
- g_signal_connect_object (window->name_field, "notify::has-focus",
- G_CALLBACK (name_field_focus_changed), window, 0);
- g_signal_connect_object (window->name_field, "activate",
- G_CALLBACK (name_field_activate), window, 0);
- }
-
- gtk_widget_show (window->name_field);
+ gtk_label_set_text (GTK_LABEL (stack_child_label), name);
+ gtk_stack_set_visible_child (window->name_stack, stack_child_label);
}
+ else
+ {
+ gtk_stack_set_visible_child (window->name_stack, stack_child_entry);
+ }
+
/* Only replace text if the file's name has changed. */
- else if (original_name == NULL || strcmp (original_name, name) != 0)
+ if (original_name == NULL || strcmp (original_name, name) != 0)
{
- if (use_label)
- {
- gtk_label_set_text (GTK_LABEL (window->name_field), name);
- }
- else
+ if (!use_label)
{
/* Only reset the text if it's different from what is
* currently showing. This causes minimal ripples (e.g.
@@ -624,7 +595,7 @@ update_name_field (NautilusPropertiesWindow *window)
{
NautilusFile *file;
- gtk_label_set_text_with_mnemonic (window->name_label,
+ gtk_label_set_text_with_mnemonic (window->name_title_label,
ngettext ("_Name:", "_Names:",
get_not_gone_original_file_count (window)));
@@ -681,10 +652,7 @@ update_name_field (NautilusPropertiesWindow *window)
* an edit in progress. If the name hasn't changed (but some other
* aspect of the file might have), then don't clobber changes.
*/
- if (window->name_field)
- {
- original_name = (const char *) g_object_get_data (G_OBJECT (window->name_field), "original_name");
- }
+ original_name = (const char *) g_object_get_data (G_OBJECT (window->name_field), "original_name");
set_name_field (window, original_name, current_name);
@@ -745,10 +713,7 @@ rename_callback (NautilusFile *file,
window->pending_name,
error,
GTK_WINDOW (window));
- if (window->name_field != NULL)
- {
- name_field_restore_original_name (window->name_field);
- }
+ name_field_restore_original_name (window->name_field);
}
g_object_unref (window);
@@ -3153,15 +3118,15 @@ setup_basic_page (NautilusPropertiesWindow *window)
grid = window->basic_grid;
- /* Name label. The text will be determined in update_name_field */
- window->name_label = attach_title_field (grid, NULL);
-
- /* Name field */
- window->name_field = NULL;
update_name_field (window);
+ g_signal_connect_object (window->name_field, "notify::has-focus",
+ G_CALLBACK (name_field_focus_changed), window, 0);
+ g_signal_connect_object (window->name_field, "activate",
+ G_CALLBACK (name_field_activate), window, 0);
+
/* Start with name field selected, if it's an entry. */
- if (GTK_IS_ENTRY (window->name_field))
+ if (GTK_IS_ENTRY (gtk_stack_get_visible_child (window->name_stack)))
{
gtk_widget_grab_focus (GTK_WIDGET (window->name_field));
}
@@ -5461,8 +5426,6 @@ real_destroy (GtkWidget *object)
stop_deep_count_for_file (window, window->deep_count_files->data);
}
- window->name_field = NULL;
-
g_list_free (window->permission_buttons);
window->permission_buttons = NULL;
@@ -5770,6 +5733,9 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button_image);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, basic_grid);
+ gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, name_title_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, name_stack);
+ gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, name_field);
}
static void