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.
4
5#ifndef CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
6#define CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
12#include "ui/base/models/combobox_model.h"
13
14class BookmarkModel;
15class BookmarkNode;
16
17// Model for the combobox showing the list of folders to choose from. The
18// list always contains the Bookmarks Bar, Other Bookmarks and the parent
19// folder. The list also contains an extra item that shows the text
20// "Choose Another Folder...".
21class RecentlyUsedFoldersComboModel : public ui::ComboboxModel {
22 public:
23  RecentlyUsedFoldersComboModel(BookmarkModel* model, const BookmarkNode* node);
24  virtual ~RecentlyUsedFoldersComboModel();
25
26  // Overridden from ui::ComboboxModel:
27  virtual int GetItemCount() const OVERRIDE;
28  virtual string16 GetItemAt(int index) OVERRIDE;
29  virtual bool IsItemSeparatorAt(int index) OVERRIDE;
30  virtual int GetDefaultIndex() const OVERRIDE;
31
32  // If necessary this function moves |node| into the corresponding folder for
33  // the given |selected_index|.
34  void MaybeChangeParent(const BookmarkNode* node, int selected_index);
35
36 private:
37  // Returns the node at the specified |index|.
38  const BookmarkNode* GetNodeAt(int index);
39
40  // Removes |node| from |items_|. Does nothing if |node| is not in |items_|.
41  void RemoveNode(const BookmarkNode* node);
42
43  struct Item;
44  std::vector<Item> items_;
45
46  BookmarkModel* bookmark_model_;
47
48  // The index of the original parent folder.
49  int node_parent_index_;
50
51  DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModel);
52};
53
54#endif  // CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
55