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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/observer_list.h"
13 #include "components/bookmarks/browser/bookmark_model_observer.h"
14 #include "ui/base/models/combobox_model.h"
21 // Model for the combobox showing the list of folders to choose from. The
22 // list always contains the Bookmarks Bar, Other Bookmarks and the parent
23 // folder. The list also contains an extra item that shows the text
24 // "Choose Another Folder...".
25 class RecentlyUsedFoldersComboModel
: public ui::ComboboxModel
,
26 public bookmarks::BookmarkModelObserver
{
28 RecentlyUsedFoldersComboModel(bookmarks::BookmarkModel
* model
,
29 const bookmarks::BookmarkNode
* node
);
30 ~RecentlyUsedFoldersComboModel() override
;
32 // Overridden from ui::ComboboxModel:
33 int GetItemCount() const override
;
34 base::string16
GetItemAt(int index
) override
;
35 bool IsItemSeparatorAt(int index
) override
;
36 int GetDefaultIndex() const override
;
37 void AddObserver(ui::ComboboxModelObserver
* observer
) override
;
38 void RemoveObserver(ui::ComboboxModelObserver
* observer
) override
;
40 // Overriden from bookmarks::BookmarkModelObserver:
41 void BookmarkModelLoaded(bookmarks::BookmarkModel
* model
,
42 bool ids_reassigned
) override
;
43 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel
* model
) override
;
44 void BookmarkNodeMoved(bookmarks::BookmarkModel
* model
,
45 const bookmarks::BookmarkNode
* old_parent
,
47 const bookmarks::BookmarkNode
* new_parent
,
48 int new_index
) override
;
49 void BookmarkNodeAdded(bookmarks::BookmarkModel
* model
,
50 const bookmarks::BookmarkNode
* parent
,
52 void OnWillRemoveBookmarks(bookmarks::BookmarkModel
* model
,
53 const bookmarks::BookmarkNode
* parent
,
55 const bookmarks::BookmarkNode
* node
) override
;
56 void BookmarkNodeRemoved(bookmarks::BookmarkModel
* model
,
57 const bookmarks::BookmarkNode
* parent
,
59 const bookmarks::BookmarkNode
* node
,
60 const std::set
<GURL
>& removed_urls
) override
;
61 void BookmarkNodeChanged(bookmarks::BookmarkModel
* model
,
62 const bookmarks::BookmarkNode
* node
) override
;
63 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel
* model
,
64 const bookmarks::BookmarkNode
* node
) override
;
65 void BookmarkNodeChildrenReordered(
66 bookmarks::BookmarkModel
* model
,
67 const bookmarks::BookmarkNode
* node
) override
;
68 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel
* model
,
69 const std::set
<GURL
>& removed_urls
) override
;
71 // If necessary this function moves |node| into the corresponding folder for
72 // the given |selected_index|.
73 void MaybeChangeParent(const bookmarks::BookmarkNode
* node
,
77 // Returns the node at the specified |index|.
78 const bookmarks::BookmarkNode
* GetNodeAt(int index
);
80 // Removes |node| from |items_|. Does nothing if |node| is not in |items_|.
81 void RemoveNode(const bookmarks::BookmarkNode
* node
);
84 std::vector
<Item
> items_
;
86 bookmarks::BookmarkModel
* bookmark_model_
;
88 // The index of the original parent folder.
89 int node_parent_index_
;
91 base::ObserverList
<ui::ComboboxModelObserver
> observers_
;
93 DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModel
);
96 #endif // CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_