diff options
-rw-r--r-- | chrome/browser/gtk/bookmark_editor_gtk.cc | 13 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.cc | 21 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.h | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_tree_model.cc | 43 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_tree_model.h | 7 |
5 files changed, 78 insertions, 13 deletions
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc index 93d2c14..1ff0197 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk.cc +++ b/chrome/browser/gtk/bookmark_editor_gtk.cc @@ -313,11 +313,11 @@ void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) { gtk_tree_store_append(tree_store_, child, parent); gtk_tree_store_set( tree_store_, child, - bookmark_utils::FOLDER_ICON, - GtkThemeProvider::GetFolderIcon(true), + bookmark_utils::FOLDER_ICON, GtkThemeProvider::GetFolderIcon(true), bookmark_utils::FOLDER_NAME, - l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME).c_str(), + l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME).c_str(), bookmark_utils::ITEM_ID, static_cast<int64>(0), + bookmark_utils::IS_EDITABLE, TRUE, -1); } @@ -394,6 +394,11 @@ void BookmarkEditorGtk::OnNewFolderClicked(GtkWidget* button, GtkTreePath* path = gtk_tree_model_get_path( GTK_TREE_MODEL(dialog->tree_store_), &new_item_iter); gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dialog->tree_view_), path); - gtk_tree_selection_select_path(dialog->tree_selection_, path); + + // Make the folder name editable. + gtk_tree_view_set_cursor(GTK_TREE_VIEW(dialog->tree_view_), path, + gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->tree_view_), 0), + TRUE); + gtk_tree_path_free(path); } diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index 390fda2..65167db 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -446,6 +446,11 @@ GtkWidget* BookmarkManagerGtk::MakeLeftPane() { g_signal_connect(left_tree_view_, "key-press-event", G_CALLBACK(OnTreeViewKeyPress), this); + GtkCellRenderer* cell_renderer_text = bookmark_utils::GetCellRendererText( + GTK_TREE_VIEW(left_tree_view_)); + g_signal_connect(cell_renderer_text, "edited", + G_CALLBACK(OnFolderNameEdited), this); + // The left side is only a drag destination (not a source). gtk_drag_dest_set(left_tree_view_, GTK_DEST_DEFAULT_DROP, NULL, 0, GDK_ACTION_MOVE); @@ -627,6 +632,7 @@ void BookmarkManagerGtk::BuildLeftStore() { l10n_util::GetStringUTF8( IDS_BOOKMARK_TREE_RECENTLY_BOOKMARKED_NODE_TITLE).c_str(), bookmark_utils::ITEM_ID, kRecentID, + bookmark_utils::IS_EDITABLE, FALSE, -1); GdkPixbuf* search_icon = gtk_widget_render_icon( @@ -639,6 +645,7 @@ void BookmarkManagerGtk::BuildLeftStore() { l10n_util::GetStringUTF8( IDS_BOOKMARK_TREE_SEARCH_NODE_TITLE).c_str(), bookmark_utils::ITEM_ID, kSearchID, + bookmark_utils::IS_EDITABLE, FALSE, -1); g_object_unref(search_icon); } @@ -1308,6 +1315,20 @@ gboolean BookmarkManagerGtk::OnTreeViewKeyPress( } // static +void BookmarkManagerGtk::OnFolderNameEdited(GtkCellRendererText* render, + gchar* path, gchar* new_folder_name, BookmarkManagerGtk* bm) { + // A folder named was edited in place. Sync the change to the bookmark + // model. + GtkTreeIter iter; + GtkTreePath* tree_path = gtk_tree_path_new_from_string(path); + gboolean rv = gtk_tree_model_get_iter(GTK_TREE_MODEL(bm->left_store_), + &iter, tree_path); + DCHECK(rv); + bm->model_->SetTitle(bm->GetNodeAt(GTK_TREE_MODEL(bm->left_store_), &iter), + UTF8ToWide(new_folder_name)); +} + +// static void BookmarkManagerGtk::OnImportItemActivated( GtkMenuItem* menuitem, BookmarkManagerGtk* bm) { SelectFileDialog::FileTypeInfo file_type_info; diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h index c86150c..d70872e 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.h +++ b/chrome/browser/gtk/bookmark_manager_gtk.h @@ -251,6 +251,13 @@ class BookmarkManagerGtk : public BookmarkModelObserver, GdkEventKey* key, BookmarkManagerGtk* bm); + // Callback from inline edits to folder names. This changes the name in the + // model. + static void OnFolderNameEdited(GtkCellRendererText* render, + gchar* path, + gchar* new_folder_name, + BookmarkManagerGtk* bm); + // Tools menu item callbacks. static void OnImportItemActivated(GtkMenuItem* menuitem, BookmarkManagerGtk* bm); diff --git a/chrome/browser/gtk/bookmark_tree_model.cc b/chrome/browser/gtk/bookmark_tree_model.cc index dd63a8d..2d59a18 100644 --- a/chrome/browser/gtk/bookmark_tree_model.cc +++ b/chrome/browser/gtk/bookmark_tree_model.cc @@ -14,6 +14,8 @@ namespace { +const char* kCellRendererTextKey = "__CELL_RENDERER_TEXT__"; + void AddSingleNodeToTreeStore(GtkTreeStore* store, const BookmarkNode* node, GtkTreeIter *iter, GtkTreeIter* parent) { gtk_tree_store_append(store, iter, parent); @@ -23,12 +25,11 @@ void AddSingleNodeToTreeStore(GtkTreeStore* store, const BookmarkNode* node, // (and indeed, Nautilus does not render an expanded directory any // differently). gtk_tree_store_set(store, iter, - bookmark_utils::FOLDER_ICON, - GtkThemeProvider::GetFolderIcon(true), - bookmark_utils::FOLDER_NAME, - WideToUTF8(node->GetTitle()).c_str(), - bookmark_utils::ITEM_ID, node->id(), - -1); + bookmark_utils::FOLDER_ICON, GtkThemeProvider::GetFolderIcon(true), + bookmark_utils::FOLDER_NAME, WideToUTF8(node->GetTitle()).c_str(), + bookmark_utils::ITEM_ID, node->id(), + bookmark_utils::IS_EDITABLE, node->is_folder(), + -1); } // Helper function for CommitTreeStoreDifferencesBetween() which recursively @@ -73,13 +74,27 @@ void RecursiveResolve(BookmarkModel* bb_model, const BookmarkNode* bb_node, } } +// Update the folder name in the GtkTreeStore. +void OnFolderNameEdited(GtkCellRendererText* render, + gchar* path, gchar* new_folder_name, GtkTreeStore* tree_store) { + GtkTreeIter folder_iter; + GtkTreePath* tree_path = gtk_tree_path_new_from_string(path); + gboolean rv = gtk_tree_model_get_iter(GTK_TREE_MODEL(tree_store), + &folder_iter, tree_path); + DCHECK(rv); + gtk_tree_store_set(tree_store, &folder_iter, + bookmark_utils::FOLDER_NAME, new_folder_name, + -1); + gtk_tree_path_free(tree_path); +} + } // namespace namespace bookmark_utils { GtkTreeStore* MakeFolderTreeStore() { return gtk_tree_store_new(FOLDER_STORE_NUM_COLUMNS, GDK_TYPE_PIXBUF, - G_TYPE_STRING, G_TYPE_INT64); + G_TYPE_STRING, G_TYPE_INT64, G_TYPE_BOOLEAN); } void AddToTreeStore(BookmarkModel* model, int64 selected_id, @@ -99,18 +114,28 @@ GtkWidget* MakeTreeViewForStore(GtkTreeStore* store) { "pixbuf", FOLDER_ICON); GtkCellRenderer* text_renderer = gtk_cell_renderer_text_new(); g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); + g_signal_connect(text_renderer, "edited", G_CALLBACK(OnFolderNameEdited), + store); gtk_tree_view_column_pack_start(column, text_renderer, TRUE); - gtk_tree_view_column_add_attribute(column, text_renderer, - "text", FOLDER_NAME); + gtk_tree_view_column_set_attributes(column, text_renderer, + "text", FOLDER_NAME, + "editable", IS_EDITABLE, + NULL); GtkWidget* tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); // Let |tree_view| own the store. g_object_unref(store); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), FALSE); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); + g_object_set_data(G_OBJECT(tree_view), kCellRendererTextKey, text_renderer); return tree_view; } +GtkCellRenderer* GetCellRendererText(GtkTreeView* tree_view) { + return static_cast<GtkCellRenderer*>( + g_object_get_data(G_OBJECT(tree_view), kCellRendererTextKey)); +} + void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id, GtkTreeStore* store, GtkTreeIter* selected_iter, GtkTreeIter* parent) { diff --git a/chrome/browser/gtk/bookmark_tree_model.h b/chrome/browser/gtk/bookmark_tree_model.h index 6656b61..80b1984 100644 --- a/chrome/browser/gtk/bookmark_tree_model.h +++ b/chrome/browser/gtk/bookmark_tree_model.h @@ -11,9 +11,11 @@ class BookmarkModel; class BookmarkNode; +typedef struct _GtkCellRenderer GtkCellRenderer; typedef struct _GtkTreeIter GtkTreeIter; typedef struct _GtkTreeModel GtkTreeModel; typedef struct _GtkTreeStore GtkTreeStore; +typedef struct _GtkTreeView GtkTreeView; typedef struct _GdkPixbuf GdkPixbuf; typedef struct _GtkWidget GtkWidget; @@ -23,6 +25,7 @@ enum FolderTreeStoreColumns { FOLDER_ICON, FOLDER_NAME, ITEM_ID, + IS_EDITABLE, FOLDER_STORE_NUM_COLUMNS }; @@ -51,6 +54,10 @@ void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id, // returned widget has a floating reference. GtkWidget* MakeTreeViewForStore(GtkTreeStore* store); +// A helper method for getting pointer back to the GtkCellRendererText used for +// the folder names. +GtkCellRenderer* GetCellRendererText(GtkTreeView* tree_view); + // Commits changes to a GtkTreeStore built from BuildTreeStoreFrom() back // into the BookmarkModel it was generated from. Returns the BookmarkNode that // represented by |selected|. |