OLD | NEW |
| (Empty) |
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 BookmarkModelLoaded(BookmarkModel* model, | |
62 bool ids_reassigned) OVERRIDE {} | |
63 virtual void BookmarkNodeMoved(BookmarkModel* model, | |
64 const BookmarkNode* old_parent, | |
65 int old_index, | |
66 const BookmarkNode* new_parent, | |
67 int new_index) OVERRIDE; | |
68 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
69 const BookmarkNode* parent, | |
70 int index) OVERRIDE; | |
71 virtual void BookmarkNodeRemoved(BookmarkModel* model, | |
72 const BookmarkNode* parent, | |
73 int old_index, | |
74 const BookmarkNode* node) OVERRIDE; | |
75 virtual void BookmarkAllNodesRemoved(BookmarkModel* model) OVERRIDE; | |
76 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
77 const BookmarkNode* node) OVERRIDE {} | |
78 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | |
79 const BookmarkNode* node) OVERRIDE; | |
80 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, | |
81 const BookmarkNode* node) OVERRIDE {} | |
82 | |
83 // Resets the model of the tree and updates the various buttons appropriately. | |
84 void Reset(); | |
85 | |
86 // Returns the current url the user has input. | |
87 GURL GetInputURL() const; | |
88 | |
89 // Returns the title the user has input. | |
90 base::string16 GetInputTitle() const; | |
91 | |
92 // Invokes ApplyEdits with the selected node. | |
93 // | |
94 // TODO(erg): This was copied from the windows version. Both should be | |
95 // cleaned up so that we don't overload ApplyEdits. | |
96 void ApplyEdits(); | |
97 | |
98 // Applies the edits done by the user. |selected_parent| gives the parent of | |
99 // the URL being edited. | |
100 void ApplyEdits(GtkTreeIter* selected_parent); | |
101 | |
102 // Adds a new folder parented on |parent| and sets |child| to point to this | |
103 // new folder. | |
104 void AddNewFolder(GtkTreeIter* parent, GtkTreeIter* child); | |
105 | |
106 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnSelectionChanged); | |
107 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, void, OnResponse, int); | |
108 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnWindowDeleteEvent, | |
109 GdkEvent*); | |
110 | |
111 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnWindowDestroy); | |
112 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnEntryChanged); | |
113 | |
114 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnNewFolderClicked); | |
115 | |
116 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnTreeViewButtonPressEvent, | |
117 GdkEventButton*); | |
118 | |
119 void NewFolder(); | |
120 | |
121 // Profile the entry is from. | |
122 Profile* profile_; | |
123 | |
124 // The dialog to display on screen. | |
125 GtkWidget* dialog_; | |
126 GtkWidget* name_entry_; | |
127 GtkWidget* url_entry_; // This is NULL if IsEditingFolder. | |
128 GtkWidget* tree_view_; | |
129 GtkWidget* new_folder_button_; | |
130 | |
131 // Helper object that manages the currently selected item in |tree_view_|. | |
132 GtkTreeSelection* tree_selection_; | |
133 | |
134 // Our local copy of the bookmark data that we make from the BookmarkModel | |
135 // that we can modify as much as we want and still discard when the user | |
136 // clicks Cancel. | |
137 GtkTreeStore* tree_store_; | |
138 | |
139 // TODO(erg): BookmarkEditorView has an EditorTreeModel object here; convert | |
140 // that into a GObject that implements the interface GtkTreeModel. | |
141 | |
142 // Initial parent to select. Is only used if node_ is NULL. | |
143 const BookmarkNode* parent_; | |
144 | |
145 // Details about the node we're editing. | |
146 const EditDetails details_; | |
147 | |
148 // Mode used to create nodes from. | |
149 BookmarkModel* bb_model_; | |
150 | |
151 // If true, we're running the menu for the bookmark bar or other bookmarks | |
152 // nodes. | |
153 bool running_menu_for_root_; | |
154 | |
155 // Is the tree shown? | |
156 bool show_tree_; | |
157 | |
158 // List of deleted bookmark folders. | |
159 std::vector<int64> deletes_; | |
160 | |
161 // The context menu controller. | |
162 scoped_ptr<ContextMenuController> menu_controller_; | |
163 | |
164 DISALLOW_COPY_AND_ASSIGN(BookmarkEditorGtk); | |
165 }; | |
166 | |
167 #endif // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_ | |
OLD | NEW |