Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(686)

Side by Side Diff: chrome/browser/views/bookmark_editor_view.h

Issue 1912: Renames BoomarkBarModel to BookmarkModel. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H__ 5 #ifndef CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H_
6 #define CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H__ 6 #define CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "chrome/views/tree_node_model.h" 10 #include "chrome/views/tree_node_model.h"
11 #include "chrome/browser/bookmarks/bookmark_bar_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/views/checkbox.h" 12 #include "chrome/views/checkbox.h"
13 #include "chrome/views/dialog_delegate.h" 13 #include "chrome/views/dialog_delegate.h"
14 #include "chrome/views/menu.h" 14 #include "chrome/views/menu.h"
15 #include "chrome/views/native_button.h" 15 #include "chrome/views/native_button.h"
16 #include "chrome/views/text_field.h" 16 #include "chrome/views/text_field.h"
17 17
18 namespace ChromeViews { 18 namespace ChromeViews {
19 class Window; 19 class Window;
20 } 20 }
21 21
22 class GURL; 22 class GURL;
23 class Menu; 23 class Menu;
24 class Profile; 24 class Profile;
25 25
26 // View that allows the user to edit a bookmark/starred URL. The user can 26 // View that allows the user to edit a bookmark/starred URL. The user can
27 // change the URL, title and where the bookmark appears as well as adding 27 // change the URL, title and where the bookmark appears as well as adding
28 // new groups and changing the name of other groups. 28 // new groups and changing the name of other groups.
29 // 29 //
30 // Edits are applied to the BookmarkBarModel when the user presses 'OK'. 30 // Edits are applied to the BookmarkModel when the user presses 'OK'.
31 // 31 //
32 // To use BookmarkEditorView invoke the static show method. 32 // To use BookmarkEditorView invoke the static show method.
33 33
34 class BookmarkEditorView : public ChromeViews::View, 34 class BookmarkEditorView : public ChromeViews::View,
35 public ChromeViews::NativeButton::Listener, 35 public ChromeViews::NativeButton::Listener,
36 public ChromeViews::TreeViewController, 36 public ChromeViews::TreeViewController,
37 public ChromeViews::DialogDelegate, 37 public ChromeViews::DialogDelegate,
38 public ChromeViews::TextField::Controller, 38 public ChromeViews::TextField::Controller,
39 public ChromeViews::ContextMenuController, 39 public ChromeViews::ContextMenuController,
40 public Menu::Delegate, 40 public Menu::Delegate,
41 public BookmarkBarModelObserver { 41 public BookmarkModelObserver {
42 FRIEND_TEST(BookmarkEditorViewTest, ChangeParent); 42 FRIEND_TEST(BookmarkEditorViewTest, ChangeParent);
43 FRIEND_TEST(BookmarkEditorViewTest, ChangeURLToExistingURL); 43 FRIEND_TEST(BookmarkEditorViewTest, ChangeURLToExistingURL);
44 FRIEND_TEST(BookmarkEditorViewTest, EditTitleKeepsPosition); 44 FRIEND_TEST(BookmarkEditorViewTest, EditTitleKeepsPosition);
45 FRIEND_TEST(BookmarkEditorViewTest, EditURLKeepsPosition); 45 FRIEND_TEST(BookmarkEditorViewTest, EditURLKeepsPosition);
46 FRIEND_TEST(BookmarkEditorViewTest, ModelsMatch); 46 FRIEND_TEST(BookmarkEditorViewTest, ModelsMatch);
47 FRIEND_TEST(BookmarkEditorViewTest, MoveToNewParent); 47 FRIEND_TEST(BookmarkEditorViewTest, MoveToNewParent);
48 public: 48 public:
49 // Shows the BookmarkEditorView editing the specified entry. 49 // Shows the BookmarkEditorView editing the specified entry.
50 static void Show(HWND parent_window, 50 static void Show(HWND parent_window,
51 Profile* profile, 51 Profile* profile,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void Close(); 103 void Close();
104 104
105 // Shows the context menu. 105 // Shows the context menu.
106 virtual void ShowContextMenu(View* source, 106 virtual void ShowContextMenu(View* source,
107 int x, 107 int x,
108 int y, 108 int y,
109 bool is_mouse_gesture); 109 bool is_mouse_gesture);
110 110
111 private: 111 private:
112 // Type of node in the tree. 112 // Type of node in the tree.
113 typedef ChromeViews::TreeNodeWithValue<int> BookmarkNode; 113 typedef ChromeViews::TreeNodeWithValue<int> EditorNode;
114 114
115 // Model for the TreeView. Trivial subclass that doesn't allow titles with 115 // Model for the TreeView. Trivial subclass that doesn't allow titles with
116 // empty strings. 116 // empty strings.
117 class BookmarkTreeModel : public ChromeViews::TreeNodeModel<BookmarkNode> { 117 class EditorTreeModel : public ChromeViews::TreeNodeModel<EditorNode> {
118 public: 118 public:
119 explicit BookmarkTreeModel(BookmarkNode* root) 119 explicit EditorTreeModel(EditorNode* root)
120 : TreeNodeModel<BookmarkNode>(root) {} 120 : TreeNodeModel<EditorNode>(root) {}
121 121
122 virtual void SetTitle(ChromeViews::TreeModelNode* node, 122 virtual void SetTitle(ChromeViews::TreeModelNode* node,
123 const std::wstring& title) { 123 const std::wstring& title) {
124 if (!title.empty()) 124 if (!title.empty())
125 TreeNodeModel::SetTitle(node, title); 125 TreeNodeModel::SetTitle(node, title);
126 } 126 }
127 127
128 private: 128 private:
129 DISALLOW_EVIL_CONSTRUCTORS(BookmarkTreeModel); 129 DISALLOW_COPY_AND_ASSIGN(EditorTreeModel);
130 }; 130 };
131 131
132 // Creates the necessary sub-views, configures them, adds them to the layout, 132 // Creates the necessary sub-views, configures them, adds them to the layout,
133 // and requests the entries to display from the database. 133 // and requests the entries to display from the database.
134 void Init(); 134 void Init();
135 135
136 // BookmarkBarModel observer methods. Any structural change results in 136 // BookmarkModel observer methods. Any structural change results in
137 // resetting the tree model. 137 // resetting the tree model.
138 virtual void Loaded(BookmarkBarModel* model); 138 virtual void Loaded(BookmarkModel* model);
139 virtual void BookmarkNodeMoved(BookmarkBarModel* model, 139 virtual void BookmarkNodeMoved(BookmarkModel* model,
140 BookmarkBarNode* old_parent, 140 BookmarkNode* old_parent,
141 int old_index, 141 int old_index,
142 BookmarkBarNode* new_parent, 142 BookmarkNode* new_parent,
143 int new_index); 143 int new_index);
jcampan 2008/09/10 23:01:24 Indent is off.
144 virtual void BookmarkNodeAdded(BookmarkBarModel* model, 144 virtual void BookmarkNodeAdded(BookmarkModel* model,
145 BookmarkBarNode* parent, 145 BookmarkNode* parent,
146 int index); 146 int index);
147 virtual void BookmarkNodeRemoved(BookmarkBarModel* model, 147 virtual void BookmarkNodeRemoved(BookmarkModel* model,
148 BookmarkBarNode* parent, 148 BookmarkNode* parent,
149 int index); 149 int index);
150 virtual void BookmarkNodeChanged(BookmarkBarModel* model, 150 virtual void BookmarkNodeChanged(BookmarkModel* model,
151 BookmarkBarNode* node) {} 151 BookmarkNode* node) {}
152 virtual void BookmarkNodeFavIconLoaded(BookmarkBarModel* model, 152 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
153 BookmarkBarNode* node) {} 153 BookmarkNode* node) {}
154 154
155 // Resets the model of the tree and updates the various buttons appropriately. 155 // Resets the model of the tree and updates the various buttons appropriately.
156 // If first_time is true, Reset is being invoked from the constructor or 156 // If first_time is true, Reset is being invoked from the constructor or
157 // once the bookmark bar has finished loading. 157 // once the bookmark bar has finished loading.
158 void Reset(bool first_time); 158 void Reset(bool first_time);
159 159
160 // Expands all the nodes in the tree and selects the parent node of the 160 // Expands all the nodes in the tree and selects the parent node of the
161 // url we're editing or the most recent parent if the url being editted isn't 161 // url we're editing or the most recent parent if the url being editted isn't
162 // starred. 162 // starred.
163 void ExpandAndSelect(); 163 void ExpandAndSelect();
164 164
165 // Creates a returns the new root node. This invokes CreateNodes to do 165 // Creates a returns the new root node. This invokes CreateNodes to do
166 // the real work. 166 // the real work.
167 BookmarkNode* CreateRootNode(); 167 EditorNode* CreateRootNode();
168 168
169 // Adds and creates a child node in b_node for all children of bb_node that 169 // Adds and creates a child node in b_node for all children of bb_node that
170 // are groups. 170 // are groups.
171 void CreateNodes(BookmarkBarNode* bb_node, 171 void CreateNodes(BookmarkNode* bb_node, EditorNode* b_node);
172 BookmarkNode* b_node);
173 172
174 // Returns the node with the specified id, or NULL if one can't be found. 173 // Returns the node with the specified id, or NULL if one can't be found.
175 BookmarkNode* FindNodeWithID(BookmarkEditorView::BookmarkNode* node, int id); 174 EditorNode* FindNodeWithID(BookmarkEditorView::EditorNode* node, int id);
176 175
177 // Invokes ApplyEdits with the selected node. 176 // Invokes ApplyEdits with the selected node.
178 void ApplyEdits(); 177 void ApplyEdits();
179 178
180 // Applies the edits done by the user. |parent| gives the parent of the URL 179 // Applies the edits done by the user. |parent| gives the parent of the URL
181 // being edited. 180 // being edited.
182 void ApplyEdits(BookmarkNode* parent); 181 void ApplyEdits(EditorNode* parent);
183 182
184 // Recursively adds newly created groups and sets the title of nodes to 183 // Recursively adds newly created groups and sets the title of nodes to
185 // match the user edited title. 184 // match the user edited title.
186 // 185 //
187 // bb_node gives the BookmarkBarNode the edits are to be applied to, 186 // bb_node gives the BookmarkNode the edits are to be applied to, with b_node
188 // with b_node the source of the edits. 187 // the source of the edits.
189 // 188 //
190 // If b_node == parent_b_node, parent_bb_node is set to bb_node. This is 189 // If b_node == parent_b_node, parent_bb_node is set to bb_node. This is
191 // used to determine the new BookmarkBarNode parent based on the BookmarkNode 190 // used to determine the new BookmarkNode parent based on the EditorNode
192 // parent. 191 // parent.
193 void ApplyNameChangesAndCreateNewGroups( 192 void ApplyNameChangesAndCreateNewGroups(
194 BookmarkBarNode* bb_node, 193 BookmarkNode* bb_node,
195 BookmarkEditorView::BookmarkNode* b_node, 194 BookmarkEditorView::EditorNode* b_node,
196 BookmarkEditorView::BookmarkNode* parent_b_node, 195 BookmarkEditorView::EditorNode* parent_b_node,
197 BookmarkBarNode** parent_bb_node); 196 BookmarkNode** parent_bb_node);
198 197
199 // Returns the current url the user has input. 198 // Returns the current url the user has input.
200 GURL GetInputURL() const; 199 GURL GetInputURL() const;
201 200
202 // Returns the title the user has input. 201 // Returns the title the user has input.
203 std::wstring GetInputTitle() const; 202 std::wstring GetInputTitle() const;
204 203
205 // Invoked when the url or title has possibly changed. Updates the background 204 // Invoked when the url or title has possibly changed. Updates the background
206 // of textfields and ok button appropriately. 205 // of textfields and ok button appropriately.
207 void UserInputChanged(); 206 void UserInputChanged();
208 207
209 // Creates a new group as a child of the selected node. If no node is 208 // Creates a new group as a child of the selected node. If no node is
210 // selected, the new group is added as a child of the bookmark node. Starts 209 // selected, the new group is added as a child of the bookmark node. Starts
211 // editing on the new gorup as well. 210 // editing on the new gorup as well.
212 void NewGroup(); 211 void NewGroup();
213 212
214 // Creates a new BookmarkNode as the last child of parent. The new node is 213 // Creates a new EditorNode as the last child of parent. The new node is
215 // added to the model and returned. This does NOT start editing. This is used 214 // added to the model and returned. This does NOT start editing. This is used
216 // internally by NewGroup and broken into a separate method for testing. 215 // internally by NewGroup and broken into a separate method for testing.
217 BookmarkNode* AddNewGroup(BookmarkNode* parent); 216 EditorNode* AddNewGroup(EditorNode* parent);
218 217
219 // Profile the entry is from. 218 // Profile the entry is from.
220 Profile* profile_; 219 Profile* profile_;
221 220
222 // Model driving the TreeView. 221 // Model driving the TreeView.
223 scoped_ptr<BookmarkTreeModel> tree_model_; 222 scoped_ptr<EditorTreeModel> tree_model_;
224 223
225 // Displays star groups. 224 // Displays star groups.
226 ChromeViews::TreeView tree_view_; 225 ChromeViews::TreeView tree_view_;
227 226
228 // Used to create a new group. 227 // Used to create a new group.
229 ChromeViews::NativeButton new_group_button_; 228 ChromeViews::NativeButton new_group_button_;
230 229
231 // Used for editing the URL. 230 // Used for editing the URL.
232 ChromeViews::TextField url_tf_; 231 ChromeViews::TextField url_tf_;
233 232
234 // Used for editing the title. 233 // Used for editing the title.
235 ChromeViews::TextField title_tf_; 234 ChromeViews::TextField title_tf_;
236 235
237 // URL we were created with. 236 // URL we were created with.
238 const GURL url_; 237 const GURL url_;
239 238
240 // The context menu. 239 // The context menu.
241 scoped_ptr<Menu> context_menu_; 240 scoped_ptr<Menu> context_menu_;
242 241
243 // Title of the url to display. 242 // Title of the url to display.
244 std::wstring title_; 243 std::wstring title_;
245 244
246 // Mode used to create nodes from. 245 // Mode used to create nodes from.
247 BookmarkBarModel* bb_model_; 246 BookmarkModel* bb_model_;
248 247
249 // If true, we're running the menu for the bookmark bar or other bookmarks 248 // If true, we're running the menu for the bookmark bar or other bookmarks
250 // nodes. 249 // nodes.
251 bool running_menu_for_root_; 250 bool running_menu_for_root_;
252 251
253 DISALLOW_EVIL_CONSTRUCTORS(BookmarkEditorView); 252 DISALLOW_COPY_AND_ASSIGN(BookmarkEditorView);
254 }; 253 };
255 254
256 #endif // CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H__ 255 #endif // CHROME_BROWSER_VIEWS_BOOKMARK_EDITOR_VIEW_H_
257
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698