diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 17:45:36 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 17:45:36 +0000 |
commit | 588deb653812e8c77941797997e2e6750c330a93 (patch) | |
tree | 741a6cd936bd5e20478277b253ee2d62735ee4b7 /chrome/browser/views | |
parent | e44ba4f3b82bb38597b58cae52cfdea8d449b2d2 (diff) | |
download | chromium_src-588deb653812e8c77941797997e2e6750c330a93.zip chromium_src-588deb653812e8c77941797997e2e6750c330a93.tar.gz chromium_src-588deb653812e8c77941797997e2e6750c330a93.tar.bz2 |
Adds the ability to sort TableView. Contrary to what we spoke about
the other day I ended up doing the sorting in tableview. This makes it
a heck of lot easier than having every model have to deal with it. As
part of this I removed the optional non-caching logic from TableView,
which was never used. Sadly though, this means there are coordinate
transformations.
I've only enabled sorting in the keyword editor, I have to make sure
all the other places that use TableView can deal with it. For example,
task manager can't deal with it currently as it expects the getters to
be called only once where as when sorting they may be called multiple
times.
BUG=2790
TEST=This enables sorting ONLY in the keyword editor. Make sure there
aren't any problems in adding/removing/changing entries in the
keyword editor after this.
Review URL: http://codereview.chromium.org/4276
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/keyword_editor_view.cc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/chrome/browser/views/keyword_editor_view.cc b/chrome/browser/views/keyword_editor_view.cc index a4e446d..9ef5527 100644 --- a/chrome/browser/views/keyword_editor_view.cc +++ b/chrome/browser/views/keyword_editor_view.cc @@ -471,12 +471,20 @@ void KeywordEditorView::Init() { columns.push_back( TableColumn(IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN, TableColumn::LEFT, -1, .75)); + columns.back().sortable = true; columns.push_back( TableColumn(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN, TableColumn::LEFT, -1, .25)); + columns.back().sortable = true; table_view_ = new ChromeViews::TableView(table_model_.get(), columns, ChromeViews::ICON_AND_TEXT, false, true, true); table_view_->SetObserver(this); + // Make the table initially sorted by name. + ChromeViews::TableView::SortDescriptors sort; + sort.push_back( + ChromeViews::TableView::SortDescriptor( + IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN, true)); + table_view_->SetSortDescriptors(sort); add_button_ = new ChromeViews::NativeButton( l10n_util::GetString(IDS_SEARCH_ENGINES_EDITOR_NEW_BUTTON)); @@ -586,20 +594,20 @@ void KeywordEditorView::ButtonPressed(ChromeViews::NativeButton* sender) { // Remove the observer while we modify the model, that way we don't need to // worry about the model calling us back when we mutate it. url_model_->RemoveObserver(this); - int last_row = -1; + int last_view_row = -1; for (ChromeViews::TableView::iterator i = table_view_->SelectionBegin(); i != table_view_->SelectionEnd(); ++i) { - last_row = *i; - const TemplateURL* template_url = &table_model_->GetTemplateURL(last_row); + last_view_row = table_view_->model_to_view(*i); + const TemplateURL* template_url = &table_model_->GetTemplateURL(*i); // Make sure to remove from the table model first, otherwise the // TemplateURL would be freed. - table_model_->Remove(last_row); + table_model_->Remove(*i); url_model_->Remove(template_url); } - if (last_row >= table_model_->RowCount()) - last_row = table_model_->RowCount() - 1; - if (last_row >= 0) - table_view_->Select(last_row); + if (last_view_row >= table_model_->RowCount()) + last_view_row = table_model_->RowCount() - 1; + if (last_view_row >= 0) + table_view_->Select(table_view_->view_to_model(last_view_row)); url_model_->AddObserver(this); // We may have removed the default provider. Enable the Suggest checkbox @@ -676,5 +684,5 @@ void KeywordEditorView::MakeDefaultSearchProvider(int index) { table_model_->MoveToMainGroup(index); // And select it. - table_view_->Select(new_index); + table_view_->Select(table_model_->IndexOfTemplateURL(keyword)); } |