| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_ | 5 #ifndef CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_ |
| 6 #define CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_ | 6 #define CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_ |
| 7 | 7 |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "app/table_model_observer.h" |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "chrome/browser/search_engines/edit_search_engine_controller.h" | 12 #include "chrome/browser/search_engines/edit_search_engine_controller.h" |
| 12 #include "chrome/browser/search_engines/template_url_model.h" | 13 #include "chrome/browser/search_engines/template_url_model.h" |
| 13 | 14 |
| 15 class KeywordEditorController; |
| 14 class Profile; | 16 class Profile; |
| 17 class TemplateURLTableModel; |
| 15 | 18 |
| 16 class KeywordEditorView : public TemplateURLModelObserver, | 19 class KeywordEditorView : public TableModelObserver, |
| 20 public TemplateURLModelObserver, |
| 17 public EditSearchEngineControllerDelegate { | 21 public EditSearchEngineControllerDelegate { |
| 18 public: | 22 public: |
| 19 virtual ~KeywordEditorView(); | 23 virtual ~KeywordEditorView(); |
| 20 | 24 |
| 21 // Create (if necessary) and show the keyword editor window. | 25 // Create (if necessary) and show the keyword editor window. |
| 22 static void Show(Profile* profile); | 26 static void Show(Profile* profile); |
| 23 | 27 |
| 24 // Overriden from EditSearchEngineControllerDelegate. | 28 // Overriden from EditSearchEngineControllerDelegate. |
| 25 virtual void OnEditedKeyword(const TemplateURL* template_url, | 29 virtual void OnEditedKeyword(const TemplateURL* template_url, |
| 26 const std::wstring& title, | 30 const std::wstring& title, |
| 27 const std::wstring& keyword, | 31 const std::wstring& keyword, |
| 28 const std::wstring& url); | 32 const std::wstring& url); |
| 29 private: | 33 private: |
| 30 explicit KeywordEditorView(Profile* profile); | 34 explicit KeywordEditorView(Profile* profile); |
| 31 void Init(); | 35 void Init(); |
| 32 | 36 |
| 33 // Enable buttons based on selection state. | 37 // Enable buttons based on selection state. |
| 34 void EnableControls(); | 38 void EnableControls(); |
| 35 | 39 |
| 40 // Set the column values for |row| of |table_model_| in the |list_store_| at |
| 41 // |iter|. |
| 42 void SetColumnValues(int row, GtkTreeIter* iter); |
| 43 |
| 44 // Get the row number in the GtkListStore corresponding to |model_row|. |
| 45 int GetListStoreRowForModelRow(int model_row) const; |
| 46 |
| 47 // Get the row number in the TemplateURLTableModel corresponding to |path|. |
| 48 int GetModelRowForPath(GtkTreePath* path) const; |
| 49 |
| 50 // Get the row number in the TemplateURLTableModel corresponding to |iter|. |
| 51 int GetModelRowForIter(GtkTreeIter* iter) const; |
| 52 |
| 53 // Get the row number in the TemplateURLTableModel of the current selection, |
| 54 // or -1 if no row is selected. |
| 55 int GetSelectedModelRow() const; |
| 56 |
| 57 // Select the row in the |tree_| corresponding to |model_row|. |
| 58 void SelectModelRow(int model_row); |
| 59 |
| 60 // Add the values from |row| of |table_model_|. |
| 61 void AddNodeToList(int row); |
| 62 |
| 63 // TableModelObserver implementation. |
| 64 virtual void OnModelChanged(); |
| 65 virtual void OnItemsChanged(int start, int length); |
| 66 virtual void OnItemsAdded(int start, int length); |
| 67 virtual void OnItemsRemoved(int start, int length); |
| 68 |
| 36 // TemplateURLModelObserver notification. | 69 // TemplateURLModelObserver notification. |
| 37 virtual void OnTemplateURLModelChanged(); | 70 virtual void OnTemplateURLModelChanged(); |
| 38 | 71 |
| 39 // Callback for window destruction. | 72 // Callback for window destruction. |
| 40 static void OnWindowDestroy(GtkWidget* widget, KeywordEditorView* window); | 73 static void OnWindowDestroy(GtkWidget* widget, KeywordEditorView* window); |
| 41 | 74 |
| 42 // Callback for dialog buttons. | 75 // Callback for dialog buttons. |
| 43 static void OnResponse(GtkDialog* dialog, int response_id, | 76 static void OnResponse(GtkDialog* dialog, int response_id, |
| 44 KeywordEditorView* window); | 77 KeywordEditorView* window); |
| 45 | 78 |
| 79 // Callback checking whether a row should be drawn as a separator. |
| 80 static gboolean OnCheckRowIsSeparator(GtkTreeModel* model, |
| 81 GtkTreeIter* iter, |
| 82 gpointer user_data); |
| 83 |
| 84 // Callback checking whether a row may be selected. We use some rows in the |
| 85 // table as headers/separators for the groups, which should not be selectable. |
| 86 static gboolean OnSelectionFilter(GtkTreeSelection* selection, |
| 87 GtkTreeModel* model, |
| 88 GtkTreePath* path, |
| 89 gboolean path_currently_selected, |
| 90 gpointer user_data); |
| 91 |
| 46 // Callback for when user selects something. | 92 // Callback for when user selects something. |
| 47 static void OnSelectionChanged(GtkTreeSelection *selection, | 93 static void OnSelectionChanged(GtkTreeSelection *selection, |
| 48 KeywordEditorView* editor); | 94 KeywordEditorView* editor); |
| 49 | 95 |
| 50 // Callbacks for buttons modifying the table. | 96 // Callbacks for user actions modifying the table. |
| 97 static void OnRowActivated(GtkTreeView* tree_view, |
| 98 GtkTreePath* path, |
| 99 GtkTreeViewColumn* column, |
| 100 KeywordEditorView* editor); |
| 51 static void OnAddButtonClicked(GtkButton* button, | 101 static void OnAddButtonClicked(GtkButton* button, |
| 52 KeywordEditorView* editor); | 102 KeywordEditorView* editor); |
| 53 static void OnEditButtonClicked(GtkButton* button, | 103 static void OnEditButtonClicked(GtkButton* button, |
| 54 KeywordEditorView* editor); | 104 KeywordEditorView* editor); |
| 55 static void OnRemoveButtonClicked(GtkButton* button, | 105 static void OnRemoveButtonClicked(GtkButton* button, |
| 56 KeywordEditorView* editor); | 106 KeywordEditorView* editor); |
| 57 static void OnMakeDefaultButtonClicked(GtkButton* button, | 107 static void OnMakeDefaultButtonClicked(GtkButton* button, |
| 58 KeywordEditorView* editor); | 108 KeywordEditorView* editor); |
| 59 | 109 |
| 60 // The table listing the search engines. | 110 // The table listing the search engines. |
| 61 GtkWidget* tree_; | 111 GtkWidget* tree_; |
| 62 GtkListStore* list_store_; | 112 GtkListStore* list_store_; |
| 63 GtkTreeSelection* selection_; | 113 GtkTreeSelection* selection_; |
| 64 | 114 |
| 65 // Buttons for acting on the table. | 115 // Buttons for acting on the table. |
| 66 GtkWidget* add_button_; | 116 GtkWidget* add_button_; |
| 67 GtkWidget* edit_button_; | 117 GtkWidget* edit_button_; |
| 68 GtkWidget* remove_button_; | 118 GtkWidget* remove_button_; |
| 69 GtkWidget* make_default_button_; | 119 GtkWidget* make_default_button_; |
| 70 | 120 |
| 71 // The containing dialog. | 121 // The containing dialog. |
| 72 GtkWidget* dialog_; | 122 GtkWidget* dialog_; |
| 73 | 123 |
| 74 // The profile. | 124 // The profile. |
| 75 Profile* profile_; | 125 Profile* profile_; |
| 76 | 126 |
| 77 // Model containing TemplateURLs. We listen for changes on this and propagate | 127 scoped_ptr<KeywordEditorController> controller_; |
| 78 // them to the table model. | 128 |
| 79 TemplateURLModel* url_model_; | 129 TemplateURLTableModel* table_model_; |
| 130 |
| 131 // We store our own index of the start of the second group within the model, |
| 132 // as when OnItemsRemoved is called the value in the model is already updated |
| 133 // but we need the old value to know which row to remove from the |
| 134 // |list_store_|. |
| 135 int model_second_group_index_; |
| 80 | 136 |
| 81 DISALLOW_COPY_AND_ASSIGN(KeywordEditorView); | 137 DISALLOW_COPY_AND_ASSIGN(KeywordEditorView); |
| 82 }; | 138 }; |
| 83 | 139 |
| 84 #endif // CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_ | 140 #endif // CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_ |
| OLD | NEW |