summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2022-07-23 20:32:09 +0200
committerAntónio Fernandes <antoniof@gnome.org>2022-07-28 19:16:34 +0100
commita451c763b4164e41842dcf3ef96eec2f44d6245b (patch)
tree6eab3f5d73ff4e517c59682d5cc95eddc25b52f5
parent2a1d8c61569cb744d97d0cbf968d5f7c3e67ffb8 (diff)
downloadnautilus-a451c763b4164e41842dcf3ef96eec2f44d6245b.tar.gz
properties-window: Show Executable switch in main page
And only for the files where it makes sense: binaries, text files, etc.
-rw-r--r--src/nautilus-properties-window.c108
-rw-r--r--src/resources/ui/nautilus-properties-window.ui56
2 files changed, 46 insertions, 118 deletions
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 723ab2202..9f38a2ea2 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -156,9 +156,7 @@ struct _NautilusPropertiesWindow
AdwComboRow *others_folder_access_row;
AdwComboRow *others_file_access_row;
- GtkWidget *execution_list_box;
AdwComboRow *execution_row;
- GtkRevealer *execution_inconsistent_revealer;
GtkSwitch *execution_switch;
GtkWidget *security_context_list_box;
@@ -2701,48 +2699,6 @@ update_permissions (NautilusPropertiesWindow *self,
}
}
-static gboolean
-initial_permission_state_consistent (NautilusPropertiesWindow *self,
- guint32 mask,
- FilterType filter_type)
-{
- gboolean first = TRUE;
- guint32 first_permissions = 0;
-
- for (GList *l = self->target_files; l != NULL; l = l->next)
- {
- NautilusFile *file = l->data;
- guint32 permissions;
-
- if (!file_matches_filter_type (file, filter_type))
- {
- continue;
- }
-
- permissions = GPOINTER_TO_INT (g_hash_table_lookup (self->initial_permissions,
- file));
-
- if (first)
- {
- if ((permissions & mask) != mask &&
- (permissions & mask) != 0)
- {
- /* Not fully on or off -> inconsistent */
- return FALSE;
- }
-
- first_permissions = permissions;
- first = FALSE;
- }
- else if ((permissions & mask) != (first_permissions & mask))
- {
- /* Not same permissions as first -> inconsistent */
- return FALSE;
- }
- }
- return TRUE;
-}
-
static void
execution_bit_changed (NautilusPropertiesWindow *self,
GParamSpec *params,
@@ -2753,20 +2709,27 @@ execution_bit_changed (NautilusPropertiesWindow *self,
/* if activated from switch, switch state is already toggled, thus invert value via XOR. */
gboolean active = gtk_switch_get_state (self->execution_switch) ^ GTK_IS_SWITCH (widget);
-
- gboolean inconsistent = gtk_revealer_get_child_revealed (self->execution_inconsistent_revealer);
- gboolean initial_inconsistent = !initial_permission_state_consistent (self, permission_mask, filter_type);
-
- /* If original execution permissions were inconsistent, circle through
- * states: inconsistent -> on -> off -> inconsistent -> … */
- gboolean set_executable = !active && (inconsistent || !initial_inconsistent);
- gboolean set_inconsistent = !active && !inconsistent && initial_inconsistent;
+ gboolean set_executable = !active;
update_permissions (self,
set_executable ? permission_mask : 0,
permission_mask,
filter_type,
- set_inconsistent);
+ FALSE);
+}
+
+static gboolean
+should_show_exectution_switch (NautilusPropertiesWindow *self)
+{
+ g_autofree gchar *mime_type = NULL;
+
+ if (is_multi_file_window (self))
+ {
+ return FALSE;
+ }
+
+ mime_type = nautilus_file_get_mime_type (get_target_file (self));
+ return g_content_type_can_be_executable (mime_type);
}
static void
@@ -2775,37 +2738,27 @@ update_execution_row (GtkWidget *row,
{
NautilusPropertiesWindow *self = target_perm->window;
- if (target_perm->has_folders)
+ if (!should_show_exectution_switch (self))
{
- gtk_widget_hide (self->execution_list_box);
+ gtk_widget_hide (GTK_WIDGET (self->execution_row));
}
else
{
- gboolean inconsistent = target_perm->file_exec_permissions == PERMISSION_INCONSISTENT;
-
- gtk_revealer_set_reveal_child (self->execution_inconsistent_revealer, inconsistent);
- gtk_widget_set_has_tooltip (row, inconsistent);
+ g_signal_handlers_block_by_func (self->execution_switch,
+ G_CALLBACK (execution_bit_changed),
+ self);
- /* Only toggle switch if permissions are consistent. This still allows switching in case
- * not all permissions can be set. */
- if (!inconsistent)
- {
- g_signal_handlers_block_by_func (self->execution_switch,
- G_CALLBACK (execution_bit_changed),
- self);
+ gtk_switch_set_state (self->execution_switch,
+ target_perm->file_exec_permissions == PERMISSION_EXEC);
- gtk_switch_set_state (self->execution_switch,
- target_perm->file_exec_permissions == PERMISSION_EXEC);
-
- g_signal_handlers_unblock_by_func (self->execution_switch,
- G_CALLBACK (execution_bit_changed),
- self);
- }
+ g_signal_handlers_unblock_by_func (self->execution_switch,
+ G_CALLBACK (execution_bit_changed),
+ self);
gtk_widget_set_sensitive (row,
target_perm->can_set_any_file_permission);
- gtk_widget_show (self->execution_list_box);
+ gtk_widget_show (GTK_WIDGET (self->execution_row));
}
}
@@ -4050,6 +4003,11 @@ create_properties_window (StartupData *startup_data)
gtk_widget_show (window->permissions_navigation_row);
}
+ if (should_show_exectution_switch (window))
+ {
+ gtk_widget_show (GTK_WIDGET (window->execution_row));
+ }
+
if (should_show_open_with (window))
{
setup_open_with_page (window);
@@ -4636,9 +4594,7 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, others_access_row);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, others_folder_access_row);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, others_file_access_row);
- gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, execution_list_box);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, execution_row);
- gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, execution_inconsistent_revealer);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, execution_switch);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, security_context_list_box);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, security_context_value_label);
diff --git a/src/resources/ui/nautilus-properties-window.ui b/src/resources/ui/nautilus-properties-window.ui
index b27a32f57..9db3c6279 100644
--- a/src/resources/ui/nautilus-properties-window.ui
+++ b/src/resources/ui/nautilus-properties-window.ui
@@ -581,6 +581,20 @@
</child>
</object>
</child>
+ <child>
+ <object class="AdwActionRow" id="execution_row">
+ <property name="visible">False</property>
+ <property name="activatable">True</property>
+ <property name="title" translatable="yes">_Executable as Program</property>
+ <property name="use-underline">True</property>
+ <child>
+ <object class="GtkSwitch" id="execution_switch">
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ </object>
+ </child>
+ </object>
+ </child>
<style>
<class name="boxed-list"/>
</style>
@@ -989,48 +1003,6 @@
</object>
</child>
<child>
- <object class="GtkListBox" id="execution_list_box">
- <property name="visible">False</property>
- <property name="selection-mode">none</property>
- <child>
- <object class="AdwActionRow" id="execution_row">
- <property name="activatable">True</property>
- <property name="title" translatable="yes">_Executable as Program</property>
- <property name="tooltip-text" translatable="yes">Not all files are marked executable for all users</property>
- <property name="use-underline">True</property>
- <child>
- <object class="GtkBox">
- <property name="spacing">6</property>
- <child>
- <object class="GtkRevealer" id="execution_inconsistent_revealer">
- <property name="transition-type">crossfade</property>
- <property name="reveal-child">False</property>
- <child>
- <object class="GtkLabel">
- <property name="label" translatable="yes">Inconsistent</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkSwitch" id="execution_switch">
- <property name="halign">center</property>
- <property name="valign">center</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <style>
- <class name="boxed-list"/>
- </style>
- </object>
- </child>
- <child>
<object class="GtkListBox" id="security_context_list_box">
<property name="visible">False</property>
<child>