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
|
// 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_KEYWORD_EDITOR_VIEW_H_
#define CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_
#pragma once
#include <gtk/gtk.h>
#include "app/table_model_observer.h"
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "chrome/browser/search_engines/edit_search_engine_controller.h"
#include "chrome/browser/search_engines/template_url_model_observer.h"
class AccessibleWidgetHelper;
class KeywordEditorController;
class Profile;
class TemplateURLTableModel;
class KeywordEditorView : public TableModelObserver,
public TemplateURLModelObserver,
public EditSearchEngineControllerDelegate {
public:
virtual ~KeywordEditorView();
// Create (if necessary) and show the keyword editor window.
static void Show(Profile* profile);
// Overriden from EditSearchEngineControllerDelegate.
virtual void OnEditedKeyword(const TemplateURL* template_url,
const string16& title,
const string16& keyword,
const std::string& url);
private:
// Column ids for |list_store_|.
enum {
COL_FAVICON,
COL_TITLE,
COL_KEYWORD,
COL_IS_HEADER,
COL_IS_SEPARATOR,
COL_WEIGHT,
COL_WEIGHT_SET,
COL_COUNT,
};
explicit KeywordEditorView(Profile* profile);
void Init();
// Enable buttons based on selection state.
void EnableControls();
// Set the column values for |row| of |table_model_| in the |list_store_| at
// |iter|.
void SetColumnValues(int row, GtkTreeIter* iter);
// Get the row number in the GtkListStore corresponding to |model_row|.
int GetListStoreRowForModelRow(int model_row) const;
// Get the row number in the TemplateURLTableModel corresponding to |path|.
int GetModelRowForPath(GtkTreePath* path) const;
// Get the row number in the TemplateURLTableModel corresponding to |iter|.
int GetModelRowForIter(GtkTreeIter* iter) const;
// Get the row number in the TemplateURLTableModel of the current selection,
// or -1 if no row is selected.
int GetSelectedModelRow() const;
// Select the row in the |tree_| corresponding to |model_row|.
void SelectModelRow(int model_row);
// Add the values from |row| of |table_model_|.
void AddNodeToList(int row);
// TableModelObserver implementation.
virtual void OnModelChanged();
virtual void OnItemsChanged(int start, int length);
virtual void OnItemsAdded(int start, int length);
virtual void OnItemsRemoved(int start, int length);
// TemplateURLModelObserver notification.
virtual void OnTemplateURLModelChanged();
// Callback for window destruction.
static void OnWindowDestroy(GtkWidget* widget, KeywordEditorView* window);
// Callback for dialog buttons.
static void OnResponse(GtkDialog* dialog, int response_id,
KeywordEditorView* window);
// Callback checking whether a row should be drawn as a separator.
static gboolean OnCheckRowIsSeparator(GtkTreeModel* model,
GtkTreeIter* iter,
gpointer user_data);
// Callback checking whether a row may be selected. We use some rows in the
// table as headers/separators for the groups, which should not be selectable.
static gboolean OnSelectionFilter(GtkTreeSelection* selection,
GtkTreeModel* model,
GtkTreePath* path,
gboolean path_currently_selected,
gpointer user_data);
// Callback for when user selects something.
static void OnSelectionChanged(GtkTreeSelection* selection,
KeywordEditorView* editor);
// Callbacks for user actions modifying the table.
static void OnRowActivated(GtkTreeView* tree_view,
GtkTreePath* path,
GtkTreeViewColumn* column,
KeywordEditorView* editor);
static void OnAddButtonClicked(GtkButton* button,
KeywordEditorView* editor);
static void OnEditButtonClicked(GtkButton* button,
KeywordEditorView* editor);
static void OnRemoveButtonClicked(GtkButton* button,
KeywordEditorView* editor);
static void OnMakeDefaultButtonClicked(GtkButton* button,
KeywordEditorView* editor);
// The table listing the search engines.
GtkWidget* tree_;
GtkListStore* list_store_;
GtkTreeSelection* selection_;
// Buttons for acting on the table.
GtkWidget* add_button_;
GtkWidget* edit_button_;
GtkWidget* remove_button_;
GtkWidget* make_default_button_;
// The containing dialog.
GtkWidget* dialog_;
// The profile.
Profile* profile_;
scoped_ptr<KeywordEditorController> controller_;
TemplateURLTableModel* table_model_;
// We store our own index of the start of the second group within the model,
// as when OnItemsRemoved is called the value in the model is already updated
// but we need the old value to know which row to remove from the
// |list_store_|.
int model_second_group_index_;
// Helper object to manage accessibility metadata.
scoped_ptr<AccessibleWidgetHelper> accessible_widget_helper_;
friend class KeywordEditorViewTest;
FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Empty);
FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Add);
FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, MakeDefault);
FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Remove);
FRIEND_TEST_ALL_PREFIXES(KeywordEditorViewTest, Edit);
DISALLOW_COPY_AND_ASSIGN(KeywordEditorView);
};
#endif // CHROME_BROWSER_GTK_KEYWORD_EDITOR_VIEW_H_
|