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.
5 #ifndef CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_
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"
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;
27 // GTK version of the bookmark editor dialog.
28 class BookmarkEditorGtk : public BookmarkEditor,
29 public BookmarkModelObserver {
31 BookmarkEditorGtk(GtkWindow* window,
33 const BookmarkNode* parent,
34 const EditDetails& details,
35 BookmarkEditor::Configuration configuration);
37 virtual ~BookmarkEditorGtk();
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);
54 class ContextMenuController;
55 friend class ContextMenuController;
57 void Init(GtkWindow* parent_window);
59 // BookmarkModel observer methods. Any structural change results in
60 // resetting the tree model.
61 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE {}
62 virtual void BookmarkNodeMoved(BookmarkModel* model,
63 const BookmarkNode* old_parent,
65 const BookmarkNode* new_parent,
66 int new_index) OVERRIDE;
67 virtual void BookmarkNodeAdded(BookmarkModel* model,
68 const BookmarkNode* parent,
70 virtual void BookmarkNodeRemoved(BookmarkModel* model,
71 const BookmarkNode* parent,
73 const BookmarkNode* node) OVERRIDE;
74 virtual void BookmarkAllNodesRemoved(BookmarkModel* model) OVERRIDE;
75 virtual void BookmarkNodeChanged(BookmarkModel* model,
76 const BookmarkNode* node) OVERRIDE {}
77 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
78 const BookmarkNode* node) OVERRIDE;
79 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
80 const BookmarkNode* node) OVERRIDE {}
82 // Resets the model of the tree and updates the various buttons appropriately.
85 // Returns the current url the user has input.
86 GURL GetInputURL() const;
88 // Returns the title the user has input.
89 string16 GetInputTitle() const;
91 // Invokes ApplyEdits with the selected node.
93 // TODO(erg): This was copied from the windows version. Both should be
94 // cleaned up so that we don't overload ApplyEdits.
97 // Applies the edits done by the user. |selected_parent| gives the parent of
98 // the URL being edited.
99 void ApplyEdits(GtkTreeIter* selected_parent);
101 // Adds a new folder parented on |parent| and sets |child| to point to this
103 void AddNewFolder(GtkTreeIter* parent, GtkTreeIter* child);
105 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnSelectionChanged);
106 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, void, OnResponse, int);
107 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnWindowDeleteEvent,
110 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnWindowDestroy);
111 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnEntryChanged);
113 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnNewFolderClicked);
115 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnTreeViewButtonPressEvent,
120 // Profile the entry is from.
123 // The dialog to display on screen.
125 GtkWidget* name_entry_;
126 GtkWidget* url_entry_; // This is NULL if IsEditingFolder.
127 GtkWidget* tree_view_;
128 GtkWidget* new_folder_button_;
130 // Helper object that manages the currently selected item in |tree_view_|.
131 GtkTreeSelection* tree_selection_;
133 // Our local copy of the bookmark data that we make from the BookmarkModel
134 // that we can modify as much as we want and still discard when the user
136 GtkTreeStore* tree_store_;
138 // TODO(erg): BookmarkEditorView has an EditorTreeModel object here; convert
139 // that into a GObject that implements the interface GtkTreeModel.
141 // Initial parent to select. Is only used if node_ is NULL.
142 const BookmarkNode* parent_;
144 // Details about the node we're editing.
145 const EditDetails details_;
147 // Mode used to create nodes from.
148 BookmarkModel* bb_model_;
150 // If true, we're running the menu for the bookmark bar or other bookmarks
152 bool running_menu_for_root_;
154 // Is the tree shown?
157 // List of deleted bookmark folders.
158 std::vector<int64> deletes_;
160 // The context menu controller.
161 scoped_ptr<ContextMenuController> menu_controller_;
163 DISALLOW_COPY_AND_ASSIGN(BookmarkEditorGtk);
166 #endif // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_