Home | History | Annotate | Download | only in bookmarks
      1 // Copyright 2013 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_BOOKMARK_EDITOR_H_
      6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_EDITOR_H_
      7 
      8 #include <utility>
      9 #include <vector>
     10 
     11 #include "base/strings/string16.h"
     12 #include "chrome/browser/bookmarks/bookmark_model.h"
     13 #include "ui/gfx/native_widget_types.h"
     14 
     15 class GURL;
     16 class Profile;
     17 
     18 // Small, cross platform interface that shows the correct platform specific
     19 // bookmark editor dialog.
     20 class BookmarkEditor {
     21  public:
     22   // An enumeration of the possible configurations offered.
     23   enum Configuration {
     24     // If Configuration is SHOW_TREE, a tree is shown allowing the user to
     25     // choose the parent of the node.
     26     SHOW_TREE,
     27     NO_TREE
     28   };
     29 
     30   // Describes what the user is editing.
     31   class EditDetails {
     32    public:
     33     // Returns the type of the existing or new node.
     34     BookmarkNode::Type GetNodeType() const;
     35 
     36     // Returns the resource id for the string resource to use on the window
     37     // title for this edit operation.
     38     int GetWindowTitleId() const;
     39 
     40     // Returns an EditDetails instance for the user editing the given bookmark.
     41     static EditDetails EditNode(const BookmarkNode* node);
     42 
     43     // Returns an EditDetails instance for the user adding a bookmark within
     44     // a given parent node with a specified index.
     45     static EditDetails AddNodeInFolder(const BookmarkNode* parent_node,
     46                                        int index,
     47                                        const GURL& url,
     48                                        const string16& title);
     49 
     50     // Returns an EditDetails instance for the user adding a folder within a
     51     // given parent node with a specified index.
     52     static EditDetails AddFolder(const BookmarkNode* parent_node,
     53                                  int index);
     54 
     55     enum Type {
     56       // The user is editing an existing node in the model. The node the user
     57       // is editing is set in |existing_node|.
     58       EXISTING_NODE,
     59 
     60       // A new bookmark should be created if the user accepts the edit.
     61       // |existing_node| is null in this case.
     62       NEW_URL,
     63 
     64       // A new folder bookmark should be created if the user accepts the edit.
     65       // The contents of the folder should be that of |urls|.
     66       // |existing_node| is null in this case.
     67       NEW_FOLDER
     68     };
     69 
     70     ~EditDetails();
     71 
     72     // See description of enum value for details.
     73     const Type type;
     74 
     75     // If type == EXISTING_NODE this gives the existing node.
     76     const BookmarkNode* existing_node;
     77 
     78     // If type == NEW_URL or type == NEW_FOLDER this gives the initial parent
     79     // node to place the new node in.
     80     const BookmarkNode* parent_node;
     81 
     82     // If type == NEW_URL or type == NEW_FOLDER this gives the index to insert
     83     // the new node at.
     84     int index;
     85 
     86     // If type == NEW_URL this gives the URL/title.
     87     GURL url;
     88     string16 title;
     89 
     90     // If type == NEW_FOLDER, this is the urls/title pairs to add to the
     91     // folder.
     92     std::vector<std::pair<GURL, string16> > urls;
     93 
     94    private:
     95     explicit EditDetails(Type node_type);
     96   };
     97 
     98   // Shows the bookmark editor. The bookmark editor allows editing an existing
     99   // node or creating a new bookmark node (as determined by |details.type|).
    100   // |details.parent_node| is only used if |details.existing_node| is null.
    101   static void Show(gfx::NativeWindow parent_window,
    102                    Profile* profile,
    103                    const EditDetails& details,
    104                    Configuration configuration);
    105 
    106   // Modifies a bookmark node (assuming that there's no magic that needs to be
    107   // done regarding moving from one folder to another).  If a new node is
    108   // explicitly being added, returns a pointer to the new node that was created.
    109   // Otherwise the return value is identically |node|.
    110   static const BookmarkNode* ApplyEditsWithNoFolderChange(
    111       BookmarkModel* model,
    112       const BookmarkNode* parent,
    113       const EditDetails& details,
    114       const base::string16& new_title,
    115       const GURL& new_url);
    116 
    117   // Modifies a bookmark node assuming that the parent of the node may have
    118   // changed and the node will need to be removed and reinserted.  If a new node
    119   // is explicitly being added, returns a pointer to the new node that was
    120   // created.  Otherwise the return value is identically |node|.
    121   static const BookmarkNode* ApplyEditsWithPossibleFolderChange(
    122       BookmarkModel* model,
    123       const BookmarkNode* new_parent,
    124       const EditDetails& details,
    125       const base::string16& new_title,
    126       const GURL& new_url);
    127 };
    128 
    129 #endif  // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_EDITOR_H_
    130