Commit b41d44d1 authored by APOORV SACHAN's avatar APOORV SACHAN 🦋 Committed by António Fernandes

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.
parent 2af7f424
......@@ -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 @@ create_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;
......@@ -5763,6 +5726,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
......
......@@ -75,28 +75,52 @@
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
<object class="GtkLabel" id="name_title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Name:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">name_field</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkStack" id="name_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="name_value_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="selectable">True</property>
<property name="ellipsize">end</property>
<property name="max_width_chars">24</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="name">name_value_label</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="name_field">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="name">name_value_entry</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<placeholder/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment