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_UI_GTK_BOOKMARK_EDITOR_GTK_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_BOOKMARK_EDITOR_GTK_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "app/gtk_integers.h" |
| 10 #include "app/gtk_signal.h" |
| 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string16.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
| 16 |
| 17 class GURL; |
| 18 |
| 19 typedef union _GdkEvent GdkEvent; |
| 20 typedef struct _GdkEventButton GdkEventButton; |
| 21 typedef struct _GtkTreeIter GtkTreeIter; |
| 22 typedef struct _GtkTreeSelection GtkTreeSelection; |
| 23 typedef struct _GtkTreeStore GtkTreeStore; |
| 24 typedef struct _GtkWidget GtkWidget; |
| 25 |
| 26 namespace gfx { |
| 27 class Point; |
| 28 } // namespace gfx |
| 29 |
| 30 // GTK version of the bookmark editor dialog. |
| 31 class BookmarkEditorGtk : public BookmarkEditor, |
| 32 public BookmarkModelObserver { |
| 33 public: |
| 34 BookmarkEditorGtk(GtkWindow* window, |
| 35 Profile* profile, |
| 36 const BookmarkNode* parent, |
| 37 const EditDetails& details, |
| 38 BookmarkEditor::Configuration configuration); |
| 39 |
| 40 virtual ~BookmarkEditorGtk(); |
| 41 |
| 42 void Show(); |
| 43 void Close(); |
| 44 |
| 45 private: |
| 46 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeParent); |
| 47 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeParentAndURL); |
| 48 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeURLToExistingURL); |
| 49 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, EditTitleKeepsPosition); |
| 50 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, EditURLKeepsPosition); |
| 51 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ModelsMatch); |
| 52 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, MoveToNewParent); |
| 53 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, NewURL); |
| 54 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeURLNoTree); |
| 55 FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeTitleNoTree); |
| 56 |
| 57 class ContextMenuController; |
| 58 friend class ContextMenuController; |
| 59 |
| 60 void Init(GtkWindow* parent_window); |
| 61 |
| 62 // BookmarkModel observer methods. Any structural change results in |
| 63 // resetting the tree model. |
| 64 virtual void Loaded(BookmarkModel* model) { } |
| 65 virtual void BookmarkNodeMoved(BookmarkModel* model, |
| 66 const BookmarkNode* old_parent, |
| 67 int old_index, |
| 68 const BookmarkNode* new_parent, |
| 69 int new_index); |
| 70 virtual void BookmarkNodeAdded(BookmarkModel* model, |
| 71 const BookmarkNode* parent, |
| 72 int index); |
| 73 virtual void BookmarkNodeRemoved(BookmarkModel* model, |
| 74 const BookmarkNode* parent, |
| 75 int old_index, |
| 76 const BookmarkNode* node); |
| 77 virtual void BookmarkNodeChanged(BookmarkModel* model, |
| 78 const BookmarkNode* node) {} |
| 79 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, |
| 80 const BookmarkNode* node); |
| 81 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, |
| 82 const BookmarkNode* node) {} |
| 83 |
| 84 // Resets the model of the tree and updates the various buttons appropriately. |
| 85 void Reset(); |
| 86 |
| 87 // Returns the current url the user has input. |
| 88 GURL GetInputURL() const; |
| 89 |
| 90 // Returns the title the user has input. |
| 91 string16 GetInputTitle() const; |
| 92 |
| 93 // Invokes ApplyEdits with the selected node. |
| 94 // |
| 95 // TODO(erg): This was copied from the windows version. Both should be |
| 96 // cleaned up so that we don't overload ApplyEdits. |
| 97 void ApplyEdits(); |
| 98 |
| 99 // Applies the edits done by the user. |selected_parent| gives the parent of |
| 100 // the URL being edited. |
| 101 void ApplyEdits(GtkTreeIter* selected_parent); |
| 102 |
| 103 // Adds a new group parented on |parent| and sets |child| to point to this |
| 104 // new group. |
| 105 void AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child); |
| 106 |
| 107 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnSelectionChanged); |
| 108 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, void, OnResponse, int); |
| 109 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnWindowDeleteEvent, |
| 110 GdkEvent*); |
| 111 |
| 112 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnWindowDestroy); |
| 113 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnEntryChanged); |
| 114 |
| 115 CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnNewFolderClicked); |
| 116 |
| 117 CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnTreeViewButtonPressEvent, |
| 118 GdkEventButton*); |
| 119 |
| 120 void ShowContextMenu(const gfx::Point& point); |
| 121 |
| 122 void NewFolder(); |
| 123 |
| 124 // Profile the entry is from. |
| 125 Profile* profile_; |
| 126 |
| 127 // The dialog to display on screen. |
| 128 GtkWidget* dialog_; |
| 129 GtkWidget* name_entry_; |
| 130 GtkWidget* url_entry_; // This is NULL if IsEditingFolder. |
| 131 GtkWidget* tree_view_; |
| 132 GtkWidget* new_folder_button_; |
| 133 |
| 134 // Helper object that manages the currently selected item in |tree_view_|. |
| 135 GtkTreeSelection* tree_selection_; |
| 136 |
| 137 // Our local copy of the bookmark data that we make from the BookmarkModel |
| 138 // that we can modify as much as we want and still discard when the user |
| 139 // clicks Cancel. |
| 140 GtkTreeStore* tree_store_; |
| 141 |
| 142 // TODO(erg): BookmarkEditorView has an EditorTreeModel object here; convert |
| 143 // that into a GObject that implements the interface GtkTreeModel. |
| 144 |
| 145 // Initial parent to select. Is only used if node_ is NULL. |
| 146 const BookmarkNode* parent_; |
| 147 |
| 148 // Details about the node we're editing. |
| 149 const EditDetails details_; |
| 150 |
| 151 // Mode used to create nodes from. |
| 152 BookmarkModel* bb_model_; |
| 153 |
| 154 // If true, we're running the menu for the bookmark bar or other bookmarks |
| 155 // nodes. |
| 156 bool running_menu_for_root_; |
| 157 |
| 158 // Is the tree shown? |
| 159 bool show_tree_; |
| 160 |
| 161 // The context menu controller. |
| 162 scoped_ptr<ContextMenuController> menu_controller_; |
| 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(BookmarkEditorGtk); |
| 165 }; |
| 166 |
| 167 #endif // CHROME_BROWSER_UI_GTK_BOOKMARK_EDITOR_GTK_H_ |
OLD | NEW |