Home | History | Annotate | Download | only in bookmarks
      1 // Copyright (c) 2011 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_GTK_BOOKMARKS_BOOKMARK_TREE_MODEL_H_
      6 #define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_TREE_MODEL_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/strings/string16.h"
     10 
     11 class BookmarkModel;
     12 class BookmarkNode;
     13 
     14 typedef struct _GtkCellRenderer GtkCellRenderer;
     15 typedef struct _GtkTreeIter GtkTreeIter;
     16 typedef struct _GtkTreeModel GtkTreeModel;
     17 typedef struct _GtkTreeStore GtkTreeStore;
     18 typedef struct _GtkTreeView GtkTreeView;
     19 typedef struct _GdkPixbuf GdkPixbuf;
     20 typedef struct _GtkWidget GtkWidget;
     21 
     22 namespace bookmark_utils {
     23 
     24 enum FolderTreeStoreColumns {
     25   FOLDER_ICON,
     26   FOLDER_NAME,
     27   ITEM_ID,
     28   IS_EDITABLE,
     29   FOLDER_STORE_NUM_COLUMNS
     30 };
     31 
     32 // Make a tree store that has two columns: name and id.
     33 GtkTreeStore* MakeFolderTreeStore();
     34 
     35 // Copies the folders in the model's root node into a GtkTreeStore. We
     36 // want the user to be able to modify the tree of folders, but to be able to
     37 // click Cancel and discard their modifications. |selected_id| is the
     38 // node->id() of the BookmarkNode that should selected on
     39 // node->screen. |selected_iter| is an out value that points to the
     40 // node->representation of the node associated with |selected_id| in |store|.
     41 // |recursive| indicates whether to recurse into sub-directories (if false,
     42 // the tree store will effectively be a list). |only_folders| indicates whether
     43 // to include bookmarks in the tree, or to only show folders.
     44 void AddToTreeStore(BookmarkModel* model, int64 selected_id,
     45                     GtkTreeStore* store, GtkTreeIter* selected_iter);
     46 
     47 // As above, but inserts just the tree rooted at |node| as a child of |parent|.
     48 // If |parent| is NULL, add it at the top level.
     49 void AddToTreeStoreAt(const BookmarkNode* node, int64 selected_id,
     50                       GtkTreeStore* store, GtkTreeIter* selected_iter,
     51                       GtkTreeIter* parent);
     52 
     53 // Makes a tree view for the store. This will take ownership of |store| and the
     54 // returned widget has a floating reference.
     55 GtkWidget* MakeTreeViewForStore(GtkTreeStore* store);
     56 
     57 // A helper method for getting pointer back to the GtkCellRendererText used for
     58 // the folder names.
     59 GtkCellRenderer* GetCellRendererText(GtkTreeView* tree_view);
     60 
     61 // Commits changes to a GtkTreeStore built from BuildTreeStoreFrom() back
     62 // into the BookmarkModel it was generated from.  Returns the BookmarkNode that
     63 // represented by |selected|.
     64 const BookmarkNode* CommitTreeStoreDifferencesBetween(
     65     BookmarkModel* model, GtkTreeStore* tree_store,
     66     GtkTreeIter* selected);
     67 
     68 // Returns the id field of the row pointed to by |iter|.
     69 int64 GetIdFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter);
     70 
     71 // Returns the title field in utf8 of the row pointed to by |iter|.
     72 string16 GetTitleFromTreeIter(GtkTreeModel* model, GtkTreeIter* iter);
     73 
     74 }  // namespace bookmark_utils
     75 
     76 #endif  // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_TREE_MODEL_H_
     77