[gtk+/places-sidebar] Apply custom names to XDG dirs if possible



commit f59a618db929d0db0e09e82d4563943e12a8c09a
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jan 21 17:38:34 2013 -0500

    Apply custom names to XDG dirs if possible
    
    And make it possible to rename them

 gtk/gtkbookmarksmanager.c |   10 ++++++++++
 gtk/gtkbookmarksmanager.h |    3 +++
 gtk/gtkplacessidebar.c    |   15 ++++++++++++---
 3 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkbookmarksmanager.c b/gtk/gtkbookmarksmanager.c
index 45acd47..91ccd89 100644
--- a/gtk/gtkbookmarksmanager.c
+++ b/gtk/gtkbookmarksmanager.c
@@ -303,6 +303,16 @@ find_bookmark_link_for_file (GSList *bookmarks, GFile *file, int *position_ret)
 }
 
 gboolean
+_gtk_bookmarks_manager_has_bookmark (GtkBookmarksManager *manager,
+                                     GFile               *file)
+{
+  GSList *link;
+
+  link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
+  return (link != NULL);
+}
+
+gboolean
 _gtk_bookmarks_manager_insert_bookmark (GtkBookmarksManager *manager,
 					GFile               *file,
 					gint                 position,
diff --git a/gtk/gtkbookmarksmanager.h b/gtk/gtkbookmarksmanager.h
index 44db7b6..f2efd65 100644
--- a/gtk/gtkbookmarksmanager.h
+++ b/gtk/gtkbookmarksmanager.h
@@ -69,6 +69,9 @@ gboolean _gtk_bookmarks_manager_reorder_bookmark (GtkBookmarksManager *manager,
 						  gint                 new_position,
 						  GError             **error);
 
+gboolean _gtk_bookmarks_manager_has_bookmark (GtkBookmarksManager *manager,
+                                              GFile               *file);
+
 gchar * _gtk_bookmarks_manager_get_bookmark_label (GtkBookmarksManager *manager,
 						   GFile               *file);
 
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 7b2e5dc..2a1003f 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -559,7 +559,12 @@ add_special_dirs (GtkPlacesSidebar *sidebar)
 		}
 
 		root = g_file_new_for_path (path);
-		name = g_file_get_basename (root);
+
+		name = _gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
+		if (!name) {
+			name = g_file_get_basename (root);
+		}
+
 		icon = special_directory_get_gicon (index);
 		mount_uri = g_file_get_uri (root);
 		tooltip = g_file_get_parse_name (root);
@@ -1725,7 +1730,7 @@ check_popup_sensitivity (GtkPlacesSidebar *sidebar, PopupMenuData *data, Selecti
 	gtk_widget_set_visible (data->add_shortcut_item, (info->type == PLACES_MOUNTED_VOLUME));
 
 	gtk_widget_set_sensitive (data->remove_item, (info->type == PLACES_BOOKMARK));
-	gtk_widget_set_sensitive (data->rename_item, (info->type == PLACES_BOOKMARK));
+	gtk_widget_set_sensitive (data->rename_item, (info->type == PLACES_BOOKMARK || info->type == PLACES_XDG_DIR));
 
  	check_visibility (info->mount, info->volume, info->drive,
  			  &show_mount, &show_unmount, &show_eject, &show_rescan, &show_start, &show_stop);
@@ -1992,7 +1997,7 @@ rename_selected_bookmark (GtkPlacesSidebar *sidebar)
 				    PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
 				    -1);
 
-		if (type != PLACES_BOOKMARK) {
+		if (type != PLACES_BOOKMARK && type != PLACES_XDG_DIR) {
 			return;
 		}
 
@@ -2969,6 +2974,10 @@ bookmarks_edited (GtkCellRenderer       *cell,
 	gtk_tree_path_free (path);
 
 	file = g_file_new_for_uri (uri);
+	if (!_gtk_bookmarks_manager_has_bookmark (sidebar->bookmarks_manager, file)) {
+		_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, file, -1, NULL);
+	}
+
 	_gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, file, new_text, NULL); /* NULL-GError */
 
 	g_object_unref (file);



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