summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/bookmark_manager_view.h
blob: a6242815f33b3ffea4a118da89873df6fe8f5229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_VIEWS_BOOKMARK_MANAGER_VIEW_H_
#define CHROME_BROWSER_VIEWS_BOOKMARK_MANAGER_VIEW_H_

#include "base/ref_counted.h"
#include "base/task.h"
#include "chrome/browser/bookmarks/bookmark_context_menu.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/shell_dialogs.h"
#include "views/controls/menu/view_menu_delegate.h"
#include "views/controls/table/table_view.h"
#include "views/controls/text_field.h"
#include "views/controls/tree/tree_view.h"
#include "views/view.h"
#include "views/window/window_delegate.h"
#include "webkit/glue/window_open_disposition.h"

class BookmarkFolderTreeModel;
class BookmarkFolderTreeView;
class BookmarkTableModel;
class BookmarkTableView;
class PrefService;
class Profile;

namespace views {
class SingleSplitView;
}
// A view that lets the user manage their bookmarks. The bookmark manager
// shows a tree on the left with a table on the right. The tree shows the
// folder nodes and the table the contents of the selected tree node. The
// tree is a BookmarkFolderTreeView and the table a BookmarkTableView. A
// text field is also provided that allows the user to search the contents
// of the bookmarks.
class BookmarkManagerView : public views::View,
                            public views::WindowDelegate,
                            public views::TreeViewController,
                            public views::TableViewObserver,
                            public views::TextField::Controller,
                            public BookmarkModelObserver,
                            public views::ContextMenuController,
                            public views::ViewMenuDelegate,
                            public views::MenuDelegate,
                            public SelectFileDialog::Listener {
 public:
  enum CutCopyPasteType {
    CUT,
    COPY,
    PASTE,
    NONE
  };

  explicit BookmarkManagerView(Profile* profile);
  virtual ~BookmarkManagerView();

  static void RegisterPrefs(PrefService* prefs);

  // Shows the bookmark manager. Only one bookmark manager exists.
  static void Show(Profile* profile);

  // Returns the current manager, or NULL if the manager is not showing.
  static BookmarkManagerView* current();

  // Selects the specified node in the tree. If node is a URL it's parent is
  // selected and node is selected in the table.
  void SelectInTree(BookmarkNode* node);

  // Expands all the children of the selected folder.
  void ExpandAll(BookmarkNode* node);

  // Returns the selected folder in the tree, which may be null.
  BookmarkNode* GetSelectedFolder();

  // Returns the selection of the table.
  std::vector<BookmarkNode*> GetSelectedTableNodes();

  virtual void PaintBackground(ChromeCanvas* canvas);

  virtual gfx::Size GetPreferredSize();

  // WindowDelegate methods.
  virtual bool CanResize() const { return true; }
  virtual bool CanMaximize() const { return true; }
  virtual std::wstring GetWindowTitle() const;
  virtual std::wstring GetWindowName() const;
  virtual View* GetContentsView() { return this; }
  // TODO(sky): implement these when we have an icon.
  //virtual SkBitmap GetWindowIcon();
  //virtual bool ShouldShowWindowIcon() const { return true; }
  virtual void WindowClosing();

  Profile* profile() const { return profile_; }

 private:
  // TableViewObserver methods.
  virtual void OnSelectionChanged() {}
  // Overriden to open the selected table nodes in the current browser.
  virtual void OnDoubleClick();
  virtual void OnTableViewDelete(views::TableView* table);
  virtual void OnKeyDown(unsigned short virtual_keycode);

  // TreeViewController methods.
  virtual void OnTreeViewSelectionChanged(views::TreeView* tree_view);
  virtual void OnTreeViewKeyDown(unsigned short virtual_keycode);

  // BookmarkModelObserver. We're only installed as an observer until the
  // bookmarks are loaded.
  virtual void Loaded(BookmarkModel* model);
  virtual void BookmarkModelBeingDeleted(BookmarkModel* model) {}
  virtual void BookmarkNodeMoved(BookmarkModel* model,
                                 BookmarkNode* old_parent,
                                 int old_index,
                                 BookmarkNode* new_parent,
                                 int new_index) {}
  virtual void BookmarkNodeAdded(BookmarkModel* model,
                                 BookmarkNode* parent,
                                 int index) {}
  virtual void BookmarkNodeRemoved(BookmarkModel* model,
                                   BookmarkNode* parent,
                                   int index) {}
  virtual void BookmarkNodeRemoved(BookmarkModel* model,
                                   BookmarkNode* parent,
                                   int old_index,
                                   BookmarkNode* node) {}
  virtual void BookmarkNodeChanged(BookmarkModel* model,
                                   BookmarkNode* node) {}
  virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
                                             BookmarkNode* node) {}
  virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
                                         BookmarkNode* node) {}

  // TextField::Controller methods.
  // Starts a timer to search for the search text.
  virtual void ContentsChanged(views::TextField* sender,
                               const std::wstring& new_contents);
  // If return has been pressed this performs an immediate search.
  virtual bool HandleKeystroke(views::TextField* sender,
                               UINT message, TCHAR key, UINT repeat_count,
                               UINT flags);

  // ContextMenuController.
  virtual void ShowContextMenu(views::View* source,
                               int x,
                               int y,
                               bool is_mouse_gesture);

  // ViewMenuDelegate.
  virtual void RunMenu(views::View* source, const CPoint& pt, HWND hwnd);

  // MenuDelegate.
  virtual void ExecuteCommand(int id);

  // SelectFileDialog::Listener.
  virtual void FileSelected(const FilePath& path,
                            int index, void* params);
  virtual void FileSelectionCanceled(void* params);

  // Creates the table model to use when searching. This returns NULL if there
  // is no search text.
  BookmarkTableModel* CreateSearchTableModel();

  // Sets the model of the table and its parent node. If |is_search| is true,
  // it means the table is showing search results.
  void SetTableModel(BookmarkTableModel* new_table_model,
                     BookmarkNode* parent_node,
                     bool is_search);

  // Sets the table's model to the results of CreateSearchTableModel and selects
  // the search node in the tree.
  void PerformSearch();

  // Invoked prior to showing. If the BookmarkModel is loaded this invokes
  // LoadedImpl.
  void PrepareForShow();

  // Invoked when we're parented and the BookmarkModel is loaded. Sets the
  // models of the tree/table appropriately and expands the necessary nodes.
  void LoadedImpl();

  // Returns the BookmarkModel.
  BookmarkModel* GetBookmarkModel() const;

  // Shows the menu. This is invoked to show the context menu for table/tree
  // as well as to show the menu from the organize button.
  void ShowMenu(HWND host,
                int x,
                int y,
                BookmarkContextMenu::ConfigurationType config);

  // Invoked to handle cut/copy/paste from the table or tree. If |from_table|
  // is true the source is the table.
  void OnCutCopyPaste(CutCopyPasteType type, bool from_table);

  // Shows the tools menu.
  void ShowToolsMenu(HWND host, int x, int y);

  // Shows the import/export file chooser. These invoke
  // FileSelected/FileSelectionCanceled when done.
  void ShowImportBookmarksFileChooser();
  void ShowExportBookmarksFileChooser();

  Profile* profile_;
  BookmarkTableView* table_view_;
  BookmarkFolderTreeView* tree_view_;
  scoped_ptr<BookmarkTableModel> table_model_;
  scoped_ptr<BookmarkFolderTreeModel> tree_model_;
  views::TextField* search_tf_;
  views::SingleSplitView* split_view_;

  // Import/export file dialog.
  scoped_refptr<SelectFileDialog> select_file_dialog_;

  // Factory used for delaying search.
  ScopedRunnableMethodFactory<BookmarkManagerView> search_factory_;

  DISALLOW_COPY_AND_ASSIGN(BookmarkManagerView);
};

#endif  // CHROME_BROWSER_VIEWS_BOOKMARK_MANAGER_VIEW_H_