OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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_VIEWS_BOOKMARK_MANAGER_VIEW_H_ | |
6 #define CHROME_BROWSER_VIEWS_BOOKMARK_MANAGER_VIEW_H_ | |
7 | |
8 #include "base/keyboard_codes.h" | |
9 #include "base/ref_counted.h" | |
10 #include "base/task.h" | |
11 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | |
12 #include "chrome/browser/shell_dialogs.h" | |
13 #include "chrome/browser/sync/profile_sync_service.h" | |
14 #include "chrome/browser/views/bookmark_context_menu.h" | |
15 #include "views/controls/button/text_button.h" | |
16 #include "views/controls/menu/view_menu_delegate.h" | |
17 #include "views/controls/table/table_view_observer.h" | |
18 #include "views/controls/textfield/textfield.h" | |
19 #include "views/controls/tree/tree_view.h" | |
20 #include "views/view.h" | |
21 #include "views/window/window_delegate.h" | |
22 #include "webkit/glue/window_open_disposition.h" | |
23 | |
24 class BookmarkFolderTreeModel; | |
25 class BookmarkFolderTreeView; | |
26 class BookmarkTableModel; | |
27 class BookmarkTableView; | |
28 class Profile; | |
29 | |
30 namespace views { | |
31 class SingleSplitView; | |
32 } | |
33 // A view that lets the user manage their bookmarks. The bookmark manager | |
34 // shows a tree on the left with a table on the right. The tree shows the | |
35 // folder nodes and the table the contents of the selected tree node. The | |
36 // tree is a BookmarkFolderTreeView and the table a BookmarkTableView. A | |
37 // text field is also provided that allows the user to search the contents | |
38 // of the bookmarks. | |
39 class BookmarkManagerView : public views::View, | |
40 public views::ContextMenuController, | |
41 public views::MenuDelegate, | |
42 public views::TableViewObserver, | |
43 public views::Textfield::Controller, | |
44 public views::TreeViewController, | |
45 public views::ViewMenuDelegate, | |
46 public views::WindowDelegate, | |
47 public views::ButtonListener, | |
48 public ProfileSyncServiceObserver, | |
49 public BookmarkModelObserver, | |
50 public SelectFileDialog::Listener { | |
51 public: | |
52 enum CutCopyPasteType { | |
53 CUT, | |
54 COPY, | |
55 PASTE, | |
56 NONE | |
57 }; | |
58 | |
59 explicit BookmarkManagerView(Profile* profile); | |
60 virtual ~BookmarkManagerView(); | |
61 | |
62 // Shows the bookmark manager. Only one bookmark manager exists. | |
63 static void Show(Profile* profile); | |
64 | |
65 // Returns the current manager, or NULL if the manager is not showing. | |
66 static BookmarkManagerView* current(); | |
67 | |
68 // Selects the specified node in the tree. If node is a URL it's parent is | |
69 // selected and node is selected in the table. | |
70 void SelectInTree(const BookmarkNode* node); | |
71 | |
72 // Expands all the children of the selected folder. | |
73 void ExpandAll(const BookmarkNode* node); | |
74 | |
75 // Returns the selected folder in the tree, which may be null. | |
76 const BookmarkNode* GetSelectedFolder(); | |
77 | |
78 // Returns the selection of the table. | |
79 std::vector<const BookmarkNode*> GetSelectedTableNodes(); | |
80 | |
81 virtual void PaintBackground(gfx::Canvas* canvas); | |
82 | |
83 virtual gfx::Size GetPreferredSize(); | |
84 | |
85 // WindowDelegate methods. | |
86 virtual bool CanResize() const { return true; } | |
87 virtual bool CanMaximize() const { return true; } | |
88 virtual std::wstring GetWindowTitle() const; | |
89 virtual std::wstring GetWindowName() const; | |
90 virtual View* GetContentsView() { return this; } | |
91 // TODO(sky): implement these when we have an icon. | |
92 // virtual SkBitmap GetWindowIcon(); | |
93 // virtual bool ShouldShowWindowIcon() const { return true; } | |
94 virtual void WindowClosing(); | |
95 | |
96 // ProfileSyncServiceObserver method. | |
97 virtual void OnStateChanged(); | |
98 | |
99 Profile* profile() const { return profile_; } | |
100 | |
101 protected: | |
102 // View methods. | |
103 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); | |
104 | |
105 private: | |
106 // TableViewObserver methods. | |
107 virtual void OnSelectionChanged() {} | |
108 // Overriden to open the selected table nodes in the current browser. | |
109 virtual void OnDoubleClick(); | |
110 virtual void OnMiddleClick(); | |
111 virtual void OnTableViewDelete(views::TableView* table); | |
112 virtual void OnKeyDown(base::KeyboardCode keycode); | |
113 | |
114 // TreeViewController methods. | |
115 virtual void OnTreeViewSelectionChanged(views::TreeView* tree_view); | |
116 virtual void OnTreeViewKeyDown(base::KeyboardCode keycode); | |
117 | |
118 // views::ButtonListener method. | |
119 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | |
120 | |
121 // BookmarkModelObserver. We're only installed as an observer until the | |
122 // bookmarks are loaded. | |
123 virtual void Loaded(BookmarkModel* model); | |
124 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) {} | |
125 virtual void BookmarkNodeMoved(BookmarkModel* model, | |
126 const BookmarkNode* old_parent, | |
127 int old_index, | |
128 const BookmarkNode* new_parent, | |
129 int new_index) {} | |
130 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
131 const BookmarkNode* parent, | |
132 int index) {} | |
133 virtual void BookmarkNodeRemoved(BookmarkModel* model, | |
134 const BookmarkNode* parent, | |
135 int old_index, | |
136 const BookmarkNode* node) {} | |
137 virtual void BookmarkNodeChanged(BookmarkModel* model, | |
138 const BookmarkNode* node) {} | |
139 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, | |
140 const BookmarkNode* node) {} | |
141 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, | |
142 const BookmarkNode* node) {} | |
143 | |
144 // Textfield::Controller methods. | |
145 // Starts a timer to search for the search text. | |
146 virtual void ContentsChanged(views::Textfield* sender, | |
147 const std::wstring& new_contents); | |
148 // If return has been pressed this performs an immediate search. | |
149 virtual bool HandleKeystroke(views::Textfield* sender, | |
150 const views::Textfield::Keystroke& key); | |
151 | |
152 // ContextMenuController. | |
153 virtual void ShowContextMenu(views::View* source, | |
154 const gfx::Point& p, | |
155 bool is_mouse_gesture); | |
156 | |
157 // ViewMenuDelegate. | |
158 virtual void RunMenu(views::View* source, const gfx::Point& pt); | |
159 | |
160 // MenuDelegate. | |
161 virtual void ExecuteCommand(int id); | |
162 | |
163 // SelectFileDialog::Listener. | |
164 virtual void FileSelected(const FilePath& path, | |
165 int index, void* params); | |
166 virtual void FileSelectionCanceled(void* params); | |
167 | |
168 // Creates the table model to use when searching. This returns NULL if there | |
169 // is no search text. | |
170 BookmarkTableModel* CreateSearchTableModel(); | |
171 | |
172 // Sets the model of the table and its parent node. If |is_search| is true, | |
173 // it means the table is showing search results. | |
174 void SetTableModel(BookmarkTableModel* new_table_model, | |
175 const BookmarkNode* parent_node, | |
176 bool is_search); | |
177 | |
178 // Sets the table's model to the results of CreateSearchTableModel and selects | |
179 // the search node in the tree. | |
180 void PerformSearch(); | |
181 | |
182 // Invoked prior to showing. If the BookmarkModel is loaded this invokes | |
183 // LoadedImpl. | |
184 void PrepareForShow(); | |
185 | |
186 // Invoked when we're parented and the BookmarkModel is loaded. Sets the | |
187 // models of the tree/table appropriately and expands the necessary nodes. | |
188 void LoadedImpl(); | |
189 | |
190 // Returns the BookmarkModel. | |
191 BookmarkModel* GetBookmarkModel() const; | |
192 | |
193 // Shows the menu. This is invoked to show the context menu for table/tree | |
194 // as well as to show the menu from the organize button. | |
195 void ShowMenu(const gfx::Point& p, | |
196 BookmarkContextMenuControllerViews::ConfigurationType config); | |
197 | |
198 // Invoked to handle cut/copy/paste from the table or tree. If |from_table| | |
199 // is true the source is the table. | |
200 void OnCutCopyPaste(CutCopyPasteType type, bool from_table); | |
201 | |
202 // Shows the tools menu. | |
203 void ShowToolsMenu(const gfx::Point& p); | |
204 | |
205 // Shows the import/export file chooser. These invoke | |
206 // FileSelected/FileSelectionCanceled when done. | |
207 void ShowImportBookmarksFileChooser(); | |
208 void ShowExportBookmarksFileChooser(); | |
209 | |
210 void UpdateSyncStatus(); | |
211 | |
212 Profile* profile_; | |
213 BookmarkTableView* table_view_; | |
214 BookmarkFolderTreeView* tree_view_; | |
215 scoped_ptr<BookmarkTableModel> table_model_; | |
216 scoped_ptr<BookmarkFolderTreeModel> tree_model_; | |
217 views::Textfield* search_tf_; | |
218 views::SingleSplitView* split_view_; | |
219 | |
220 // Import/export file dialog. | |
221 scoped_refptr<SelectFileDialog> select_file_dialog_; | |
222 | |
223 // The sync status button that notifies the user about the current status of | |
224 // bookmarks synchronization. | |
225 views::TextButton* sync_status_button_; | |
226 | |
227 // A pointer to the ProfileSyncService instance if one exists. | |
228 ProfileSyncService* sync_service_; | |
229 | |
230 // True if the cached credentials have expired and we need to prompt the | |
231 // user to re-enter their password. | |
232 bool sync_relogin_required_; | |
233 | |
234 // Factory used for delaying search. | |
235 ScopedRunnableMethodFactory<BookmarkManagerView> search_factory_; | |
236 | |
237 DISALLOW_COPY_AND_ASSIGN(BookmarkManagerView); | |
238 }; | |
239 | |
240 #endif // CHROME_BROWSER_VIEWS_BOOKMARK_MANAGER_VIEW_H_ | |
OLD | NEW |