[file-roller: 12/26] file selector: added ability to show/hide the hidden files



commit 88fbe71f513d0b9f69aeb792d16a3c9a055126d8
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Aug 9 10:56:02 2012 +0200

    file selector: added ability to show/hide the hidden files

 data/org.gnome.FileRoller.gschema.xml.in |    3 +
 src/actions.c                            |    1 -
 src/fr-file-selector-dialog.c            |   62 ++++++++++++---
 src/ui/file-selector.ui                  |  123 +++++++++++++++--------------
 4 files changed, 116 insertions(+), 73 deletions(-)
---
diff --git a/data/org.gnome.FileRoller.gschema.xml.in b/data/org.gnome.FileRoller.gschema.xml.in
index 2733f42..947d43a 100644
--- a/data/org.gnome.FileRoller.gschema.xml.in
+++ b/data/org.gnome.FileRoller.gschema.xml.in
@@ -136,6 +136,9 @@
     <key name='window-size' type='(ii)'>
       <default>(-1, -1)</default>
     </key>
+    <key name="show-hidden" type="b">
+      <default>false</default>
+    </key>
   </schema>
 
   <schema id="org.gnome.FileRoller.General" path="/org/gnome/file-roller/general/" gettext-domain="file-roller">
diff --git a/src/actions.c b/src/actions.c
index f9b0e90..362c5dc 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -206,7 +206,6 @@ void
 activate_action_add (GtkAction *action,
 		     gpointer   data)
 {
-	/* FIXME: dlg_add (FR_WINDOW (data)) */
 	dlg_add (FR_WINDOW (data));
 }
 
diff --git a/src/fr-file-selector-dialog.c b/src/fr-file-selector-dialog.c
index 8314177..4f6d8ce 100644
--- a/src/fr-file-selector-dialog.c
+++ b/src/fr-file-selector-dialog.c
@@ -29,6 +29,7 @@
 
 #define GET_WIDGET(x) (_gtk_builder_get_widget (self->priv->builder, (x)))
 #define PREF_FILE_SELECTOR_WINDOW_SIZE "window-size"
+#define PREF_FILE_SELECTOR_SHOW_HIDDEN "show-hidden"
 
 
 G_DEFINE_TYPE (FrFileSelectorDialog, fr_file_selector_dialog, GTK_TYPE_DIALOG)
@@ -149,6 +150,7 @@ struct _FrFileSelectorDialogPrivate {
 	GSettings     *settings;
 	GList         *special_places;
 	GList         *bookmarks;
+	gboolean       show_hidden;
 };
 
 
@@ -690,8 +692,12 @@ fr_file_selector_dialog_unmap (GtkWidget *widget)
 
 	gtk_window_get_size (GTK_WINDOW (self), &width, &height);
 	g_settings_set (self->priv->settings, PREF_FILE_SELECTOR_WINDOW_SIZE, "(ii)", width, height);
+	g_settings_set_boolean (self->priv->settings, PREF_FILE_SELECTOR_SHOW_HIDDEN, self->priv->show_hidden);
 
-	/* FIXME: cancel all operations */
+	if (self->priv->current_operation != NULL)
+		g_cancellable_cancel (self->priv->current_operation->cancellable);
+	if (self->priv->places_operation != NULL)
+		g_cancellable_cancel (self->priv->places_operation->cancellable);
 
 	GTK_WIDGET_CLASS (fr_file_selector_dialog_parent_class)->unmap (widget);
 }
@@ -982,6 +988,30 @@ go_up_button_clicked_cb (GtkButton *button,
 
 
 static void
+_set_current_folder (FrFileSelectorDialog *self,
+		     GFile                *folder,
+		     GList                *files);
+
+
+static void
+hidden_files_togglebutton_toggled_cb (GtkToggleButton *toggle_button,
+				      gpointer         user_data)
+{
+	FrFileSelectorDialog *self = user_data;
+	GFile                *folder;
+	GList                *selected_files;
+
+	self->priv->show_hidden = gtk_toggle_button_get_active (toggle_button);
+	folder = fr_file_selector_dialog_get_current_folder (self);
+	selected_files = fr_file_selector_dialog_get_selected_files (self);
+	_set_current_folder (self, folder, selected_files);
+
+	_g_object_list_unref (selected_files);
+	_g_object_unref (folder);
+}
+
+
+static void
 fr_file_selector_dialog_init (FrFileSelectorDialog *self)
 {
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, FR_TYPE_FILE_SELECTOR_DIALOG, FrFileSelectorDialogPrivate);
@@ -990,6 +1020,7 @@ fr_file_selector_dialog_init (FrFileSelectorDialog *self)
 	self->priv->icon_cache = gth_icon_cache_new_for_widget (GTK_WIDGET (self), GTK_ICON_SIZE_MENU);
 	self->priv->settings = g_settings_new ("org.gnome.FileRoller.FileSelector");
 	self->priv->special_places = NULL;
+	self->priv->show_hidden = g_settings_get_boolean (self->priv->settings, PREF_FILE_SELECTOR_SHOW_HIDDEN);
 
 	gtk_container_set_border_width (GTK_CONTAINER (self), 5);
 	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))), GET_WIDGET ("content"));
@@ -1003,6 +1034,8 @@ fr_file_selector_dialog_init (FrFileSelectorDialog *self)
 	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("places_liststore")), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
 	gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (GET_WIDGET ("places_treeview")), places_treeview_row_separator_func, self, NULL);
 
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("hidden_files_togglebutton")), self->priv->show_hidden);
+
 	g_signal_connect (GET_WIDGET ("is_selected_cellrenderertoggle"),
 			  "toggled",
 			  G_CALLBACK (is_selected_cellrenderertoggle_toggled_cb),
@@ -1015,12 +1048,17 @@ fr_file_selector_dialog_init (FrFileSelectorDialog *self)
 			  "clicked",
 			  G_CALLBACK (go_up_button_clicked_cb),
 			  self);
+	g_signal_connect (GET_WIDGET ("hidden_files_togglebutton"),
+			  "toggled",
+			  G_CALLBACK (hidden_files_togglebutton_toggled_cb),
+			  self);
 	g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("places_treeview"))),
 			  "changed",
 			  G_CALLBACK (places_treeview_selection_changed_cb),
 			  self);
 
 	_fr_file_selector_dialog_update_size (self);
+	gtk_widget_grab_focus (GET_WIDGET ("files_treeview"));
 }
 
 
@@ -1085,24 +1123,22 @@ static void
 set_current_folder (FrFileSelectorDialog *self,
 		    GFile                *folder)
 {
-	char        *folder_name;
-	GtkTreeIter  iter;
-
+	char             *folder_name;
+	GtkTreeIter       iter;
+	GtkTreeSelection *tree_selection;
 	_g_object_unref (self->priv->current_folder);
 	self->priv->current_folder = g_object_ref (folder);
 
 	folder_name = g_file_get_parse_name (folder);
 	gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("location_entry")), folder_name);
 
-	if (_gtk_list_store_get_iter_for_file (GTK_LIST_STORE (GET_WIDGET ("places_liststore")), &iter, folder)) {
-		GtkTreeSelection *tree_selection;
-
-		tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("places_treeview")));
-
-		g_signal_handlers_block_by_func (tree_selection, places_treeview_selection_changed_cb, self);
+	tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("places_treeview")));
+	g_signal_handlers_block_by_func (tree_selection, places_treeview_selection_changed_cb, self);
+	if (_gtk_list_store_get_iter_for_file (GTK_LIST_STORE (GET_WIDGET ("places_liststore")), &iter, folder))
 		gtk_tree_selection_select_iter (tree_selection, &iter);
-		g_signal_handlers_unblock_by_func (tree_selection, places_treeview_selection_changed_cb, self);
-	}
+	else
+		gtk_tree_selection_unselect_all (tree_selection);
+	g_signal_handlers_unblock_by_func (tree_selection, places_treeview_selection_changed_cb, self);
 }
 
 
@@ -1168,7 +1204,7 @@ get_folder_content_done_cb (GError   *error,
 		char      *collate_key;
 		gboolean   is_folder;
 
-		if (g_file_info_get_is_hidden (file_info->info))
+		if (! self->priv->show_hidden && g_file_info_get_is_hidden (file_info->info))
 			continue;
 
 		gtk_list_store_append (list_store, &iter);
diff --git a/src/ui/file-selector.ui b/src/ui/file-selector.ui
index d55691b..a113c64 100644
--- a/src/ui/file-selector.ui
+++ b/src/ui/file-selector.ui
@@ -1,6 +1,30 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkListStore" id="files_liststore">
+    <columns>
+      <!-- column-name icon -->
+      <column type="GdkPixbuf"/>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+      <!-- column-name size -->
+      <column type="gchararray"/>
+      <!-- column-name modified -->
+      <column type="gchararray"/>
+      <!-- column-name file -->
+      <column type="GObject"/>
+      <!-- column-name name_order -->
+      <column type="gchararray"/>
+      <!-- column-name size_order -->
+      <column type="gint64"/>
+      <!-- column-name modified_order -->
+      <column type="gint64"/>
+      <!-- column-name is_folder -->
+      <column type="gboolean"/>
+      <!-- column-name is_selected -->
+      <column type="gboolean"/>
+    </columns>
+  </object>
   <object class="GtkBox" id="content">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -14,49 +38,43 @@
         <property name="orientation">vertical</property>
         <property name="spacing">12</property>
         <child>
-          <object class="GtkBox" id="box1">
+          <object class="GtkBox" id="toolbox">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="spacing">12</property>
             <child>
-              <object class="GtkBox" id="box3">
+              <object class="GtkButton" id="go_up_button">
+                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="has_tooltip">True</property>
+                <property name="tooltip_markup" translatable="yes">Go up one level</property>
+                <property name="tooltip_text" translatable="yes">Go up one level</property>
+                <property name="use_action_appearance">False</property>
+                <property name="relief">none</property>
                 <child>
-                  <object class="GtkButton" id="go_up_button">
-                    <property name="use_action_appearance">False</property>
+                  <object class="GtkImage" id="image1">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="tooltip_text" translatable="yes">Go up one level</property>
-                    <property name="use_action_appearance">False</property>
-                    <property name="relief">none</property>
-                    <child>
-                      <object class="GtkImage" id="image1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="stock">gtk-go-up</property>
-                      </object>
-                    </child>
+                    <property name="can_focus">False</property>
+                    <property name="stock">gtk-go-up</property>
+                    <property name="icon-size">2</property>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">0</property>
-                  </packing>
                 </child>
               </object>
               <packing>
                 <property name="expand">False</property>
-                <property name="fill">True</property>
+                <property name="fill">False</property>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkSeparator" id="separator1">
+              <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="orientation">vertical</property>
+                <property name="label" translatable="yes">_Location:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">location_entry</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -65,28 +83,38 @@
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="label1">
+              <object class="GtkEntry" id="location_entry">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">_Location:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">location_entry</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">â</property>
+                <property name="invisible_char_set">True</property>
+                <property name="primary_icon_name">folder</property>
               </object>
               <packing>
-                <property name="expand">False</property>
+                <property name="expand">True</property>
                 <property name="fill">True</property>
                 <property name="position">2</property>
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="location_entry">
+              <object class="GtkToggleButton" id="hidden_files_togglebutton">
+                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="invisible_char">â</property>
-                <property name="invisible_char_set">True</property>
+                <property name="receives_default">True</property>
+                <property name="tooltip_text" translatable="yes">Show hidden files</property>
+                <property name="use_action_appearance">False</property>
+                <property name="relief">none</property>
+                <child>
+                  <object class="GtkImage" id="image2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon_name">emblem-system-symbolic</property>
+                  </object>
+                </child>
               </object>
               <packing>
-                <property name="expand">True</property>
+                <property name="expand">False</property>
                 <property name="fill">True</property>
                 <property name="position">3</property>
               </packing>
@@ -257,30 +285,6 @@
       </packing>
     </child>
   </object>
-  <object class="GtkListStore" id="files_liststore">
-    <columns>
-      <!-- column-name icon -->
-      <column type="GdkPixbuf"/>
-      <!-- column-name name -->
-      <column type="gchararray"/>
-      <!-- column-name size -->
-      <column type="gchararray"/>
-      <!-- column-name modified -->
-      <column type="gchararray"/>
-      <!-- column-name file -->
-      <column type="GObject"/>
-      <!-- column-name name_order -->
-      <column type="gchararray"/>
-      <!-- column-name size_order -->
-      <column type="gint64"/>
-      <!-- column-name modified_order -->
-      <column type="gint64"/>
-      <!-- column-name is_folder -->
-      <column type="gboolean"/>
-      <!-- column-name is_selected -->
-      <column type="gboolean"/>
-    </columns>
-  </object>
   <object class="GtkListStore" id="places_liststore">
     <columns>
       <!-- column-name icon -->
@@ -297,4 +301,5 @@
       <column type="gint"/>
     </columns>
   </object>
+  <object class="GtkSizeGroup" id="toolbar_sizegroup"/>
 </interface>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]