Chromium Code Reviews| 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" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 dest_folder->item_list()->CreatePositionBefore(position)); | 212 dest_folder->item_list()->CreatePositionBefore(position)); |
| 213 AddItemToFolderItemAndNotify(dest_folder, item_ptr.Pass()); | 213 AddItemToFolderItemAndNotify(dest_folder, item_ptr.Pass()); |
| 214 } else { | 214 } else { |
| 215 item_ptr->set_position( | 215 item_ptr->set_position( |
| 216 top_level_item_list_->CreatePositionBefore(position)); | 216 top_level_item_list_->CreatePositionBefore(position)); |
| 217 AddItemToItemListAndNotifyUpdate(item_ptr.Pass()); | 217 AddItemToItemListAndNotifyUpdate(item_ptr.Pass()); |
| 218 } | 218 } |
| 219 return true; | 219 return true; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void AppListModel::DeleteUninstalledItem(const std::string& id) { | |
| 223 AppListItem* item = FindItem(id); | |
| 224 if (!item) | |
| 225 return; | |
| 226 AppListFolderItem* folder = FindFolderItem(item->folder_id()); | |
| 227 DeleteItem(id); | |
|
stevenjb
2015/03/25 22:24:00
What happens if this is the last item in a folder?
Greg Levin
2015/03/26 19:45:11
Yes, good call.
| |
| 228 | |
| 229 // Issue 368111: Upon uninstall of 2nd-to-last folder item, reparent last item | |
| 230 // to top and remove folder. | |
| 231 if (folder && folder->ChildItemCount() == 1u) { | |
| 232 FOR_EACH_OBSERVER(AppListModelObserver, observers_, | |
| 233 OnSingleItemFolderWillBeDeleted()); | |
| 234 | |
| 235 // Move last item in model, folder and views will update themselves. | |
| 236 AppListItem* last_item = folder->item_list()->item_at(0); | |
| 237 MoveItemToFolderAt(last_item, "", folder->position()); | |
| 238 } | |
| 239 } | |
| 240 | |
| 222 void AppListModel::SetItemPosition(AppListItem* item, | 241 void AppListModel::SetItemPosition(AppListItem* item, |
| 223 const syncer::StringOrdinal& new_position) { | 242 const syncer::StringOrdinal& new_position) { |
| 224 if (!item->IsInFolder()) { | 243 if (!item->IsInFolder()) { |
| 225 top_level_item_list_->SetItemPosition(item, new_position); | 244 top_level_item_list_->SetItemPosition(item, new_position); |
| 226 // Note: this will trigger OnListItemMoved which will signal observers. | 245 // Note: this will trigger OnListItemMoved which will signal observers. |
| 227 // (This is done this way because some View code still moves items within | 246 // (This is done this way because some View code still moves items within |
| 228 // the item list directly). | 247 // the item list directly). |
| 229 return; | 248 return; |
| 230 } | 249 } |
| 231 AppListFolderItem* folder = FindFolderItem(item->folder_id()); | 250 AppListFolderItem* folder = FindFolderItem(item->folder_id()); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 scoped_ptr<AppListItem> result = folder->item_list()->RemoveItem(item->id()); | 454 scoped_ptr<AppListItem> result = folder->item_list()->RemoveItem(item->id()); |
| 436 result->set_folder_id(""); | 455 result->set_folder_id(""); |
| 437 if (folder->item_list()->item_count() == 0) { | 456 if (folder->item_list()->item_count() == 0) { |
| 438 DVLOG(2) << "Deleting empty folder: " << folder->ToDebugString(); | 457 DVLOG(2) << "Deleting empty folder: " << folder->ToDebugString(); |
| 439 DeleteItem(folder_id); | 458 DeleteItem(folder_id); |
| 440 } | 459 } |
| 441 return result.Pass(); | 460 return result.Pass(); |
| 442 } | 461 } |
| 443 | 462 |
| 444 } // namespace app_list | 463 } // namespace app_list |
| OLD | NEW |