1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_ 7 8 #include <vector> 9 10 #include "base/gtest_prod_util.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/strings/string16.h" 13 #include "chrome/browser/bookmarks/bookmark_model_observer.h" 14 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" 15 #include "ui/base/glib/glib_integers.h" 16 #include "ui/base/gtk/gtk_signal.h" 17 18 class GURL; 19 20 typedef union _GdkEvent GdkEvent; 21 typedef struct _GdkEventButton GdkEventButton; 22 typedef struct _GtkTreeIter GtkTreeIter; 23 typedef struct _GtkTreeSelection GtkTreeSelection; 24 typedef struct _GtkTreeStore GtkTreeStore; 25 typedef struct _GtkWidget GtkWidget; 26 27 // GTK version of the bookmark editor dialog. 28 class BookmarkEditorGtk : public BookmarkEditor, 29 public BookmarkModelObserver { 30 public: 31 BookmarkEditorGtk(GtkWindow* window, 32 Profile* profile, 33 const BookmarkNode* parent, 34 const EditDetails& details, 35 BookmarkEditor::Configuration configuration); 36 37 virtual ~BookmarkEditorGtk(); 38 39 void Show(); 40 void Close(); 41 42 private: 43 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeParent); 44 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeParentAndURL); 45 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeURLToExistingURL); 46 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, EditTitleKeepsPosition); 47 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, EditURLKeepsPosition); 48 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ModelsMatch); 49 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, MoveToNewParent); 50 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, NewURL); 51 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeURLNoTree); 52 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeTitleNoTree); 53 54 class ContextMenuController; 55 friend class ContextMenuController; 56 57 void Init(GtkWindow* parent_window); 58 59 // BookmarkModel observer methods. Any structural change results in 60 // resetting the tree model. 61 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE {} 62 virtual void BookmarkNodeMoved(BookmarkModel* model, 63 const BookmarkNode* old_parent, 64 int old_index, 65 const BookmarkNode* new_parent, 66 int new_index) OVERRIDE; 67 virtual void BookmarkNodeAdded(BookmarkModel* model, 68 const BookmarkNode* parent, 69 int index) OVERRIDE; 70 virtual void BookmarkNodeRemoved(BookmarkModel* model, 71 const BookmarkNode* parent, 72 int old_index, 73 const BookmarkNode* node) OVERRIDE; 74 virtual void BookmarkAllNodesRemoved(BookmarkModel* model) OVERRIDE; 75 virtual void BookmarkNodeChanged(BookmarkModel* model, 76 const BookmarkNode* node) OVERRIDE {} 77 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, 78 const BookmarkNode* node) OVERRIDE; 79 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, 80 const BookmarkNode* node) OVERRIDE {} 81 82 // Resets the model of the tree and updates the various buttons appropriately. 83 void Reset(); 84 85 // Returns the current url the user has input. 86 GURL GetInputURL() const; 87 88 // Returns the title the user has input. 89 string16 GetInputTitle() const; 90 91 // Invokes ApplyEdits with the selected node. 92 // 93 // TODO(erg): This was copied from the windows version. Both should be 94 // cleaned up so that we don't overload ApplyEdits. 95 void ApplyEdits(); 96 97 // Applies the edits done by the user. |selected_parent| gives the parent of 98 // the URL being edited. 99 void ApplyEdits(GtkTreeIter* selected_parent); 100 101 // Adds a new folder parented on |parent| and sets |child| to point to this 102 // new folder. 103 void AddNewFolder(GtkTreeIter* parent, GtkTreeIter* child); 104 105 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnSelectionChanged); 106 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, void, OnResponse, int); 107 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnWindowDeleteEvent, 108 GdkEvent*); 109 110 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnWindowDestroy); 111 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnEntryChanged); 112 113 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnNewFolderClicked); 114 115 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnTreeViewButtonPressEvent, 116 GdkEventButton*); 117 118 void NewFolder(); 119 120 // Profile the entry is from. 121 Profile* profile_; 122 123 // The dialog to display on screen. 124 GtkWidget* dialog_; 125 GtkWidget* name_entry_; 126 GtkWidget* url_entry_; // This is NULL if IsEditingFolder. 127 GtkWidget* tree_view_; 128 GtkWidget* new_folder_button_; 129 130 // Helper object that manages the currently selected item in |tree_view_|. 131 GtkTreeSelection* tree_selection_; 132 133 // Our local copy of the bookmark data that we make from the BookmarkModel 134 // that we can modify as much as we want and still discard when the user 135 // clicks Cancel. 136 GtkTreeStore* tree_store_; 137 138 // TODO(erg): BookmarkEditorView has an EditorTreeModel object here; convert 139 // that into a GObject that implements the interface GtkTreeModel. 140 141 // Initial parent to select. Is only used if node_ is NULL. 142 const BookmarkNode* parent_; 143 144 // Details about the node we're editing. 145 const EditDetails details_; 146 147 // Mode used to create nodes from. 148 BookmarkModel* bb_model_; 149 150 // If true, we're running the menu for the bookmark bar or other bookmarks 151 // nodes. 152 bool running_menu_for_root_; 153 154 // Is the tree shown? 155 bool show_tree_; 156 157 // List of deleted bookmark folders. 158 std::vector<int64> deletes_; 159 160 // The context menu controller. 161 scoped_ptr<ContextMenuController> menu_controller_; 162 163 DISALLOW_COPY_AND_ASSIGN(BookmarkEditorGtk); 164 }; 165 166 #endif // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_ 167