| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/app_list/app_list_model.h" | 5 #include "ui/app_list/app_list_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "ui/app_list/app_list_folder_item.h" | 9 #include "ui/app_list/app_list_folder_item.h" |
| 10 #include "ui/app_list/app_list_item.h" | 10 #include "ui/app_list/app_list_item.h" |
| 11 #include "ui/app_list/app_list_model_observer.h" | 11 #include "ui/app_list/app_list_model_observer.h" |
| 12 #include "ui/app_list/search_box_model.h" | 12 #include "ui/app_list/search_box_model.h" |
| 13 #include "ui/app_list/search_result.h" | |
| 14 | 13 |
| 15 namespace app_list { | 14 namespace app_list { |
| 16 | 15 |
| 17 AppListModel::AppListModel() | 16 AppListModel::AppListModel() |
| 18 : top_level_item_list_(new AppListItemList), | 17 : top_level_item_list_(new AppListItemList), |
| 19 search_box_(new SearchBoxModel), | 18 search_box_(new SearchBoxModel), |
| 20 results_(new SearchResults), | 19 results_(new SearchResults), |
| 21 status_(STATUS_NORMAL), | 20 status_(STATUS_NORMAL), |
| 22 folders_enabled_(false) { | 21 folders_enabled_(false) { |
| 23 top_level_item_list_->AddObserver(this); | 22 top_level_item_list_->AddObserver(this); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 child->set_folder_id(""); | 277 child->set_folder_id(""); |
| 279 AddItemToItemListAndNotifyUpdate(child.Pass()); | 278 AddItemToItemListAndNotifyUpdate(child.Pass()); |
| 280 } | 279 } |
| 281 folder_ids.push_back(folder->id()); | 280 folder_ids.push_back(folder->id()); |
| 282 } | 281 } |
| 283 // Delete folders. | 282 // Delete folders. |
| 284 for (size_t i = 0; i < folder_ids.size(); ++i) | 283 for (size_t i = 0; i < folder_ids.size(); ++i) |
| 285 DeleteItem(folder_ids[i]); | 284 DeleteItem(folder_ids[i]); |
| 286 } | 285 } |
| 287 | 286 |
| 287 std::vector<SearchResult*> AppListModel::FilterSearchResultsByDisplayType( |
| 288 SearchResults* results, |
| 289 SearchResult::DisplayType display_type, |
| 290 size_t max_results) { |
| 291 std::vector<SearchResult*> matches; |
| 292 for (size_t i = 0; i < results->item_count(); ++i) { |
| 293 SearchResult* item = results->GetItemAt(i); |
| 294 if (item->display_type() == display_type) { |
| 295 matches.push_back(item); |
| 296 if (matches.size() == max_results) |
| 297 break; |
| 298 } |
| 299 } |
| 300 return matches; |
| 301 } |
| 302 |
| 288 // Private methods | 303 // Private methods |
| 289 | 304 |
| 290 void AppListModel::OnListItemMoved(size_t from_index, | 305 void AppListModel::OnListItemMoved(size_t from_index, |
| 291 size_t to_index, | 306 size_t to_index, |
| 292 AppListItem* item) { | 307 AppListItem* item) { |
| 293 FOR_EACH_OBSERVER(AppListModelObserver, | 308 FOR_EACH_OBSERVER(AppListModelObserver, |
| 294 observers_, | 309 observers_, |
| 295 OnAppListItemUpdated(item)); | 310 OnAppListItemUpdated(item)); |
| 296 } | 311 } |
| 297 | 312 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 scoped_ptr<AppListItem> result = folder->item_list()->RemoveItem(item->id()); | 381 scoped_ptr<AppListItem> result = folder->item_list()->RemoveItem(item->id()); |
| 367 result->set_folder_id(""); | 382 result->set_folder_id(""); |
| 368 if (folder->item_list()->item_count() == 0) { | 383 if (folder->item_list()->item_count() == 0) { |
| 369 DVLOG(2) << "Deleting empty folder: " << folder->ToDebugString(); | 384 DVLOG(2) << "Deleting empty folder: " << folder->ToDebugString(); |
| 370 DeleteItem(folder_id); | 385 DeleteItem(folder_id); |
| 371 } | 386 } |
| 372 return result.Pass(); | 387 return result.Pass(); |
| 373 } | 388 } |
| 374 | 389 |
| 375 } // namespace app_list | 390 } // namespace app_list |
| OLD | NEW |