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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
// Copyright (c) 2010 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_GTK_BOOKMARK_MANAGER_GTK_H_
#define CHROME_BROWSER_GTK_BOOKMARK_MANAGER_GTK_H_
#include <gtk/gtk.h>
#include <vector>
#include "base/basictypes.h"
#include "base/gfx/rect.h"
#include "base/ref_counted.h"
#include "base/task.h"
#include "chrome/browser/bookmarks/bookmark_context_menu_controller.h"
#include "chrome/browser/bookmarks/bookmark_model_observer.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/shell_dialogs.h"
#include "chrome/common/gtk_tree.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
class BookmarkModel;
class BookmarkTableModel;
class MenuGtk;
class Profile;
class BookmarkManagerGtk : public BookmarkModelObserver,
public ProfileSyncServiceObserver,
public gtk_tree::TableAdapter::Delegate,
public SelectFileDialog::Listener,
public BookmarkContextMenuControllerDelegate {
public:
virtual ~BookmarkManagerGtk();
Profile* profile() { return profile_; }
// Show the node in the tree.
void SelectInTree(const BookmarkNode* node, bool expand);
// Shows the bookmark manager. Only one bookmark manager exists.
static void Show(Profile* profile);
// BookmarkModelObserver implementation.
// The implementations of these functions only affect the left side tree view
// as changes to the right side are handled via TableModelObserver callbacks.
virtual void Loaded(BookmarkModel* model);
virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
virtual void BookmarkNodeMoved(BookmarkModel* model,
const BookmarkNode* old_parent,
int old_index,
const BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
const BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
const BookmarkNode* parent,
int old_index,
const BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
const BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
const BookmarkNode* node);
// gtk_tree::TableAdapter::Delegate implementation.
virtual void SetColumnValues(int row, GtkTreeIter* iter);
virtual void OnModelChanged();
// SelectFileDialog::Listener implemenation.
virtual void FileSelected(const FilePath& path,
int index, void* params);
// ProfileSyncServiceObserver implementation.
virtual void OnStateChanged();
// BookmarkContextMenuController::Delegate implementation.
virtual void CloseMenu();
private:
friend class BookmarkManagerTest;
FRIEND_TEST(BookmarkManagerTest, Crash);
explicit BookmarkManagerGtk(Profile* profile);
void InitWidgets();
GtkWidget* MakeLeftPane();
GtkWidget* MakeRightPane();
// Get the currently showing bookmark manager. Only used in testing.
static BookmarkManagerGtk* GetCurrentManager();
// Set |window_|'s initial size, using its previous size if that was saved.
void SetInitialWindowSize();
// Connects the ctrl-w accelerator to the window.
void ConnectAccelerators();
// If |left|, then make the organize menu refer to that which is selected in
// the left pane, otherwise use the right pane selection.
void ResetOrganizeMenu(bool left);
// Pack the data from the bookmark model into the stores. This does not
// create the stores, which is done in Make{Left,Right}Pane().
// This one should only be called once (when the bookmark model is loaded).
void BuildLeftStore();
// This one clears the old right pane and refills it with the contents of
// whatever folder is selected on the left. It can be called multiple times.
void BuildRightStore();
// Reset the TableModel backing the right pane.
void ResetRightStoreModel();
// Get the ID of the item at |iter|.
int64 GetRowIDAt(GtkTreeModel* model, GtkTreeIter* iter);
// Get the node from |model| at |iter|. If the item is not a node, return
// NULL.
const BookmarkNode* GetNodeAt(GtkTreeModel* model, GtkTreeIter* iter);
// Get the node that is selected in the left tree view.
const BookmarkNode* GetFolder();
// Get the ID of the selected row.
int GetSelectedRowID();
// Get the nodes that are selected in the right tree view.
std::vector<const BookmarkNode*> GetRightSelection();
// Set the size of a column based on the user prefs, and also sets the sizing
// properties of the column.
void SizeColumn(GtkTreeViewColumn* column,
const wchar_t* prefname);
// Calls SizeColumn() on each of the right tree view columns.
void SizeColumns();
// Save the column widths into the pref service. Column widths are stored
// separately depending on whether the path column is showing.
void SaveColumnConfiguration();
// Flush the saved mousedown. Should only be called when |delaying_mousedown_|
// is true.
void SendDelayedMousedown();
GtkTreeSelection* left_selection() {
return gtk_tree_view_get_selection(GTK_TREE_VIEW(left_tree_view_));
}
GtkTreeSelection* right_selection() {
return gtk_tree_view_get_selection(GTK_TREE_VIEW(right_tree_view_));
}
// Use these to temporarily disable updating the right store. You can stack
// calls to Suppress(), but they should always be matched by an equal number
// of calls to Allow().
void SuppressUpdatesToRightStore();
void AllowUpdatesToRightStore();
// Tries to find the node with id |target_id|. If found, returns true and set
// |iter| to point to the entry. If you pass a |iter| with stamp of 0, then it
// will be treated as the first row of |model|.
bool RecursiveFind(GtkTreeModel* model, GtkTreeIter* iter, int64 target_id);
// Search helpers.
void PerformSearch();
void OnSearchTextChanged();
static void OnSearchTextChangedThunk(GtkWidget* search_entry,
BookmarkManagerGtk* bookmark_manager) {
bookmark_manager->OnSearchTextChanged();
}
// TreeView signal handlers.
static void OnLeftSelectionChanged(GtkTreeSelection* selection,
BookmarkManagerGtk* bm);
static void OnRightSelectionChanged(GtkTreeSelection* selection,
BookmarkManagerGtk* bm);
static void OnLeftTreeViewDragReceived(GtkWidget* tree_view,
GdkDragContext* context,
gint x,
gint y,
GtkSelectionData* selection_data,
guint target_type,
guint time,
BookmarkManagerGtk* bm);
static gboolean OnLeftTreeViewDragMotion(GtkWidget* tree_view,
GdkDragContext* context,
gint x,
gint y,
guint time,
BookmarkManagerGtk* bm);
static void OnLeftTreeViewRowCollapsed(GtkTreeView* tree_view,
GtkTreeIter* iter,
GtkTreePath* path,
BookmarkManagerGtk* bm);
static void OnRightTreeViewDragGet(GtkWidget* tree_view,
GdkDragContext* context,
GtkSelectionData* selection_data,
guint target_type,
guint time,
BookmarkManagerGtk* bm);
static void OnRightTreeViewDragReceived(GtkWidget* tree_view,
GdkDragContext* context,
gint x,
gint y,
GtkSelectionData* selection_data,
guint target_type,
guint time,
BookmarkManagerGtk* bm);
static void OnRightTreeViewDragBegin(GtkWidget* tree_view,
GdkDragContext* drag_context,
BookmarkManagerGtk* bm);
static gboolean OnRightTreeViewDragMotion(GtkWidget* tree_view,
GdkDragContext* context,
gint x,
gint y,
guint time,
BookmarkManagerGtk* bm);
static void OnRightTreeViewRowActivated(GtkTreeView* tree_view,
GtkTreePath* path,
GtkTreeViewColumn* column,
BookmarkManagerGtk* bm);
static void OnRightTreeViewFocusIn(GtkTreeView* tree_view,
GdkEventFocus* event,
BookmarkManagerGtk* bm);
static void OnLeftTreeViewFocusIn(GtkTreeView* tree_view,
GdkEventFocus* event,
BookmarkManagerGtk* bm);
static gboolean OnRightTreeViewButtonPress(GtkWidget* tree_view,
GdkEventButton* event,
BookmarkManagerGtk* bm);
static gboolean OnRightTreeViewMotion(GtkWidget* tree_view,
GdkEventMotion* event,
BookmarkManagerGtk* bm);
static gboolean OnTreeViewButtonPress(GtkWidget* tree_view,
GdkEventButton* button,
BookmarkManagerGtk* bm);
static gboolean OnTreeViewButtonRelease(GtkWidget* tree_view,
GdkEventButton* button,
BookmarkManagerGtk* bm);
static gboolean OnTreeViewKeyPress(GtkWidget* tree_view,
GdkEventKey* key,
BookmarkManagerGtk* bm);
// Callback from inline edits to folder names. This changes the name in the
// model.
static void OnFolderNameEdited(GtkCellRendererText* render,
gchar* path,
gchar* new_folder_name,
BookmarkManagerGtk* bm);
// Tools menu item callbacks.
static void OnImportItemActivated(GtkMenuItem* menuitem,
BookmarkManagerGtk* bm);
static void OnExportItemActivated(GtkMenuItem* menuitem,
BookmarkManagerGtk* bm);
// Sync status menu item callback.
static void OnSyncStatusMenuActivated(GtkMenuItem* menu_item,
BookmarkManagerGtk* bm);
// Window callbacks.
static gboolean OnWindowDestroyedThunk(GtkWidget* window, gpointer self) {
return reinterpret_cast<BookmarkManagerGtk*>(self)->
OnWindowDestroyed(window);
}
gboolean OnWindowDestroyed(GtkWidget* window);
static gboolean OnWindowStateChangedThunk(GtkWidget* window,
GdkEventWindowState* event,
gpointer self) {
return reinterpret_cast<BookmarkManagerGtk*>(self)->
OnWindowStateChanged(window, event);
}
gboolean OnWindowStateChanged(GtkWidget* window, GdkEventWindowState* event);
static gboolean OnWindowConfiguredThunk(GtkWidget* window,
GdkEventConfigure* event,
gpointer self) {
return reinterpret_cast<BookmarkManagerGtk*>(self)->
OnWindowConfigured(window, event);
}
gboolean OnWindowConfigured(GtkWidget* window, GdkEventConfigure* event);
// Handles an accelerator being pressed.
static gboolean OnGtkAccelerator(GtkAccelGroup* accel_group,
GObject* acceleratable,
guint keyval,
GdkModifierType modifier,
BookmarkManagerGtk* bookmark_manager);
void UpdateSyncStatus();
GtkWidget* window_;
GtkWidget* search_entry_;
Profile* profile_;
BookmarkModel* model_;
GtkWidget* paned_;
GtkWidget* left_tree_view_;
GtkWidget* right_tree_view_;
enum {
RIGHT_PANE_PIXBUF,
RIGHT_PANE_TITLE,
RIGHT_PANE_URL,
RIGHT_PANE_PATH,
RIGHT_PANE_ID,
RIGHT_PANE_NUM
};
GtkTreeStore* left_store_;
GtkListStore* right_store_;
GtkTreeViewColumn* title_column_;
GtkTreeViewColumn* url_column_;
GtkTreeViewColumn* path_column_;
scoped_ptr<BookmarkTableModel> right_tree_model_;
scoped_ptr<gtk_tree::TableAdapter> right_tree_adapter_;
// |window_|'s current position and size.
gfx::Rect window_bounds_;
// Flags describing |window_|'s current state.
GdkWindowState window_state_;
// The Organize menu item.
GtkWidget* organize_;
// The submenu the item pops up.
// The controller.
scoped_ptr<BookmarkContextMenuController> organize_menu_controller_;
// The view.
scoped_ptr<MenuGtk> organize_menu_;
// Whether the menu refers to the left selection.
bool organize_is_for_left_;
// The sync status menu item that notifies the user about the current status
// of bookmarks synchronization.
GtkWidget* sync_status_menu_;
// A pointer to the ProfileSyncService instance if one exists.
ProfileSyncService* sync_service_;
// True if the cached credentials have expired and we need to prompt the
// user to re-enter their password.
bool sync_relogin_required_;
// Factory used for delaying search.
ScopedRunnableMethodFactory<BookmarkManagerGtk> search_factory_;
scoped_refptr<SelectFileDialog> select_file_dialog_;
// These variables are used for the workaround for http://crbug.com/15240.
// The last mouse down we got. Only valid while |delaying_mousedown| is true.
GdkEventButton mousedown_event_;
bool delaying_mousedown_;
// This is true while we are propagating a delayed mousedown. It is used to
// tell the button press handler to ignore the event.
bool sending_delayed_mousedown_;
// This is used to avoid recursively calling our right click handler. It is
// only true when a right click is already being handled.
bool ignore_rightclicks_;
GtkAccelGroup* accel_group_;
};
#endif // CHROME_BROWSER_GTK_BOOKMARK_MANAGER_GTK_H_
|