Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/cocoa/bookmark_editor_base_controller.h

Issue 393006: Change the folder presentation in the Bookmark Editor and the Bookmark All Ta... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_COCOA_BOOKMARK_EDITOR_BASE_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_COCOA_BOOKMARK_EDITOR_BASE_CONTROLLER_H_
6 #define CHROME_BROWSER_COCOA_BOOKMARK_EDITOR_BASE_CONTROLLER_H_ 6 #define CHROME_BROWSER_COCOA_BOOKMARK_EDITOR_BASE_CONTROLLER_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #import "base/cocoa_protocols_mac.h" 10 #import "base/cocoa_protocols_mac.h"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/scoped_nsobject.h" 12 #include "base/scoped_nsobject.h"
13 #include "chrome/browser/bookmarks/bookmark_editor.h" 13 #include "chrome/browser/bookmarks/bookmark_editor.h"
14 14
15 class BookmarkModel;
15 @class BookmarkTreeBrowserCell; 16 @class BookmarkTreeBrowserCell;
16 class BookmarkModel;
17 17
18 // A base controller class for bookmark creation and editing dialogs which 18 // A base controller class for bookmark creation and editing dialogs which
19 // present the current bookmark folder structure in a tree view. Do not 19 // present the current bookmark folder structure in a tree view. Do not
20 // instantiate this controller directly -- use one of its derived classes. 20 // instantiate this controller directly -- use one of its derived classes.
21 // NOTE: If your derived classes is intended to be dispatched via the 21 // NOTE: If a derived class is intended to be dispatched via the
22 // BookmarkEditor::Show static function found in the accompanying 22 // BookmarkEditor::Show static function found in the accompanying
23 // implementation will need to update that function. 23 // implementation, that function will need to be update.
24 @interface BookmarkEditorBaseController : 24 @interface BookmarkEditorBaseController : NSWindowController {
25 NSWindowController<NSMatrixDelegate, NSTextFieldDelegate> {
26 @private 25 @private
27 IBOutlet NSBrowser* folderBrowser_;
28 IBOutlet NSButton* newFolderButton_; 26 IBOutlet NSButton* newFolderButton_;
29 IBOutlet NSButton* okButton_; // Used for unit testing only. 27 IBOutlet NSButton* okButton_; // Used for unit testing only.
28 IBOutlet NSTreeController* folderTreeController_;
29 IBOutlet NSOutlineView* folderTreeView_;
30 30
31 NSWindow* parentWindow_; 31 NSWindow* parentWindow_; // weak
32 Profile* profile_; // weak 32 Profile* profile_; // weak
33 const BookmarkNode* parentNode_; // weak; owned by the model 33 const BookmarkNode* parentNode_; // weak; owned by the model
34 BookmarkEditor::Configuration configuration_; 34 BookmarkEditor::Configuration configuration_;
35 scoped_ptr<BookmarkEditor::Handler> handler_; // we take ownership 35 scoped_ptr<BookmarkEditor::Handler> handler_; // we take ownership
36 NSString* initialName_; 36 NSString* initialName_;
37 NSString* displayName_; // Bound to a text field in the dialog. 37 NSString* displayName_; // Bound to a text field in the dialog.
38 BOOL okEnabled_; // Bound to the OK button. 38 BOOL okEnabled_; // Bound to the OK button.
39 // An array of BookmarkFolderInfo where each item describes a folder in the
40 // BookmarkNode structure.
41 scoped_nsobject<NSArray> folderTreeArray_;
42 // Bound to the table view giving a path to the current selections, of which
43 // there should only ever be one.
44 scoped_nsobject<NSArray> tableSelectionPaths_;
39 } 45 }
40 46
41 @property (copy) NSString* initialName; 47 @property (copy) NSString* initialName;
42 @property (copy) NSString* displayName; 48 @property (copy) NSString* displayName;
43 @property (assign) BOOL okEnabled; 49 @property (assign) BOOL okEnabled;
50 @property (retain, readonly) NSArray* folderTreeArray;
51 @property (copy) NSArray* tableSelectionPaths;
44 52
45 // Designated initializer. Derived classes should call through to this init. 53 // Designated initializer. Derived classes should call through to this init.
46 - (id)initWithParentWindow:(NSWindow*)parentWindow 54 - (id)initWithParentWindow:(NSWindow*)parentWindow
47 nibName:(NSString*)nibName 55 nibName:(NSString*)nibName
48 profile:(Profile*)profile 56 profile:(Profile*)profile
49 parent:(const BookmarkNode*)parent 57 parent:(const BookmarkNode*)parent
50 configuration:(BookmarkEditor::Configuration)configuration 58 configuration:(BookmarkEditor::Configuration)configuration
51 handler:(BookmarkEditor::Handler*)handler; 59 handler:(BookmarkEditor::Handler*)handler;
52 60
53 // Run the bookmark editor as a modal sheet. Does not block. 61 // Run the bookmark editor as a modal sheet. Does not block.
54 - (void)runAsModalSheet; 62 - (void)runAsModalSheet;
55 63
56 // Create a new folder at the end of the selected parent folder, give it 64 // Create a new folder at the end of the selected parent folder, give it
57 // an untitled name, and put it into editing mode. 65 // an untitled name, and put it into editing mode.
58 - (IBAction)newFolder:(id)sender; 66 - (IBAction)newFolder:(id)sender;
59 67
60 // Actions for the buttons at the bottom of the window. 68 // The cancel action will dismiss the dialog. Derived classes which
69 // override cancel:, must call this after accessing any dialog-related
70 // data.
61 - (IBAction)cancel:(id)sender; 71 - (IBAction)cancel:(id)sender;
62 72
63 // The OK action will record the edited bookmark. The default dismisses 73 // The OK action will dismiss the dialog. This action is bound
64 // the dialog and should be called by the derived class if overridden. 74 // to the OK button of a dialog which presents a tree view of a profile's
75 // folder hierarchy and allows the creation of new folders within that tree.
76 // When the OK button is pressed, this function will: 1) call the derived
77 // class's -[willCommit] function, 2) create any new folders created by
78 // the user while the dialog is presented, 3) call the derived class's
79 // -[didCommit] function, and then 4) dismiss the dialog. At least one
80 // of -[willCommit] and -[didCommit] must be provided by the derived class
81 // and should return a NSNumber containing a BOOL or nil ('nil' means YES)
82 // indicating if the operation should be allowed to continue.
83 // Note: A derived class should not override the ok: action.
65 - (IBAction)ok:(id)sender; 84 - (IBAction)ok:(id)sender;
66 85
67 // Methods for use by derived classes only. 86 // Methods for use by derived classes only.
68 87
69 // Determine and returns the rightmost selected/highlighted element (node) 88 // Determine and returns the rightmost selected/highlighted element (node)
70 // in the bookmark tree view if the tree view is showing, otherwise returns 89 // in the bookmark tree view if the tree view is showing, otherwise returns
71 // the original |parentNode_|. If the tree view is showing but nothing is 90 // the original |parentNode_|. If the tree view is showing but nothing is
72 // selected then return the root node. This assumes that leaf nodes (pure 91 // selected then the root node is returned.
73 // bookmarks) are not being presented.
74 - (const BookmarkNode*)selectedNode; 92 - (const BookmarkNode*)selectedNode;
75 93
76 // Select/highlight the given node within the browser tree view. If the 94 // Select/highlight the given node within the browser tree view. If the
77 // node is nil then select the bookmark bar node. Exposed for unit test. 95 // node is nil then select the bookmark bar node. Exposed for unit test.
78 - (void)selectNodeInBrowser:(const BookmarkNode*)node; 96 - (void)selectNodeInBrowser:(const BookmarkNode*)node;
79 97
80 // Notify the handler, if any, of a node creation. 98 // Notify the handler, if any, of a node creation.
81 - (void)NotifyHandlerCreatedNode:(const BookmarkNode*)node; 99 - (void)notifyHandlerCreatedNode:(const BookmarkNode*)node;
82 100
83 // Accessors 101 // Accessors
84 - (BookmarkModel*)bookmarkModel; 102 - (BookmarkModel*)bookmarkModel;
85 - (const BookmarkNode*)parentNode; 103 - (const BookmarkNode*)parentNode;
86 104
87 @end 105 @end
88 106
107 // Describes the profile's bookmark folder structure: the folder name, the
108 // original BookmarkNode pointer (if the folder already exists), a BOOL
109 // indicating if the folder is new (meaning: created during this session
110 // but not yet committed to the bookmark structure), and an NSArray of
111 // child folder BookmarkFolderInfo's following this same structure.
112 @interface BookmarkFolderInfo : NSObject {
113 @private
114 NSString* folderName_;
115 const BookmarkNode* folderNode_; // weak
116 NSMutableArray* children_;
117 BOOL newFolder_;
118 }
119
120 @property (copy, readwrite) NSString* folderName;
121 @property (assign, readwrite) const BookmarkNode* folderNode;
122 @property (retain, readwrite) NSMutableArray* children;
123 @property (assign, readwrite) BOOL newFolder;
124
125 // Convenience creator for adding a new folder to the editor's bookmark
126 // structure. This folder will be added to the bookmark model when the
127 // user accepts the dialog. |folderName| must be provided.
128 + (id)bookmarkFolderInfoWithFolderName:(NSString*)folderName;
129
130 // Designated initializer. |folderName| must be provided. For folders which
131 // already exist in the bookmark model, |folderNode| and |children| (if any
132 // children are already attached to this folder) must be provided and
133 // |newFolder| should be NO. For folders which the user has added during
134 // this session and which have not been committed yet, |newFolder| should be
135 // YES and |folderNode| and |children| should be NULL/nil.
136 - (id)initWithFolderName:(NSString*)folderName
137 folderNode:(const BookmarkNode*)folderNode
138 children:(NSMutableArray*)children
139 newFolder:(BOOL)newFolder;
140
141 // Convenience creator used during construction of the editor's bookmark
142 // structure. |folderName| and |folderNode| must be provided. |children|
143 // is optional. Private: exposed here for unit testing purposes.
144 + (id)bookmarkFolderInfoWithFolderName:(NSString*)folderName
145 folderNode:(const BookmarkNode*)folderNode
146 children:(NSMutableArray*)children;
147
148 @end
149
89 @interface BookmarkEditorBaseController(TestingAPI) 150 @interface BookmarkEditorBaseController(TestingAPI)
151
90 @property (readonly) BOOL okButtonEnabled; 152 @property (readonly) BOOL okButtonEnabled;
153
154 // Create any newly added folders. New folders are nodes in folderTreeArray
155 // which are marked as being new (i.e. their kFolderTreeNewFolderKey
156 // dictionary item is YES). This is called by -[ok:].
157 - (void)createNewFolders;
158
159 // Select the given bookmark node within the tree view.
91 - (void)selectTestNodeInBrowser:(const BookmarkNode*)node; 160 - (void)selectTestNodeInBrowser:(const BookmarkNode*)node;
92 + (const BookmarkNode*)folderChildForParent:(const BookmarkNode*)parent 161
93 withFolderIndex:(NSInteger)index; 162 // Return the dictionary for the folder selected in the tree.
94 + (int)indexOfFolderChild:(const BookmarkNode*)child; 163 - (BookmarkFolderInfo*)selectedFolder;
164
95 @end 165 @end
96 166
97 #endif /* CHROME_BROWSER_COCOA_BOOKMARK_EDITOR_BASE_CONTROLLER_H_ */ 167 #endif /* CHROME_BROWSER_COCOA_BOOKMARK_EDITOR_BASE_CONTROLLER_H_ */
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_all_tabs_controller_unittest.mm ('k') | chrome/browser/cocoa/bookmark_editor_base_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698