Rewrite the add bookmark code (no bug) so that we don't need a BookmarksViewController for this.

Fix bug 285339 (progressive slowdown with more tabs) by releasing all the nib members of the BookmarksEditing nib when closing tabs.
Delay loading the bookmarks editing nib until bookmarks are shown, making new tab creation faster.
When creating a bookmark when bookmarks are showing, use the previous page as the bookmark by looking back in session history.
Save the state of the history folders for a given bookmarks view.
Fix bug 247543 (remember last used Add Bookmark folder across windows).
Change [BookmarkItem description] to [BookmarkItem itemDescription] because -description should be reserved.
When creating a new folder deep in bookmarks, expand all parent folders so that the new folder is visible.
Rename various "add bookmark" methods so that they are all consistent (allowing us to write to FirstResponder when appropriate).
This commit is contained in:
smfr%smfr.org 2005-03-10 18:10:23 +00:00
Родитель ce2ec689bd
Коммит 61495240a5
37 изменённых файлов: 1338 добавлений и 464 удалений

Просмотреть файл

@ -975,6 +975,48 @@
settings = {
};
};
0F4752D207DC0F4D002AEE9F = {
fileEncoding = 30;
isa = PBXFileReference;
lastKnownFileType = sourcecode.c.h;
name = AddBookmarkDialogController.h;
path = src/bookmarks/AddBookmarkDialogController.h;
refType = 2;
sourceTree = SOURCE_ROOT;
};
0F4752D307DC0F4D002AEE9F = {
fileEncoding = 30;
isa = PBXFileReference;
lastKnownFileType = sourcecode.cpp.objcpp;
name = AddBookmarkDialogController.mm;
path = src/bookmarks/AddBookmarkDialogController.mm;
refType = 2;
sourceTree = SOURCE_ROOT;
};
0F4752D407DC0F4D002AEE9F = {
fileRef = 0F4752D207DC0F4D002AEE9F;
isa = PBXBuildFile;
settings = {
};
};
0F4752D507DC0F4D002AEE9F = {
fileRef = 0F4752D307DC0F4D002AEE9F;
isa = PBXBuildFile;
settings = {
};
};
0F4752D607DC0F4D002AEE9F = {
fileRef = 0F4752D207DC0F4D002AEE9F;
isa = PBXBuildFile;
settings = {
};
};
0F4752D707DC0F4D002AEE9F = {
fileRef = 0F4752D307DC0F4D002AEE9F;
isa = PBXBuildFile;
settings = {
};
};
0F66E4A807D6D8D500444E2A = {
fileRef = 0FCCE56707D6D7DA006DD3D1;
isa = PBXBuildFile;
@ -1169,6 +1211,36 @@
refType = 2;
sourceTree = SOURCE_ROOT;
};
0FACBFEC07DC020D00DEE23A = {
children = (
0FACBFED07DC020D00DEE23A,
);
isa = PBXVariantGroup;
name = AddBookmark.nib;
path = "";
refType = 2;
sourceTree = SOURCE_ROOT;
};
0FACBFED07DC020D00DEE23A = {
isa = PBXFileReference;
lastKnownFileType = wrapper.nib;
name = English;
path = resources/localized/English.lproj/AddBookmark.nib;
refType = 4;
sourceTree = "<group>";
};
0FACBFEE07DC020D00DEE23A = {
fileRef = 0FACBFEC07DC020D00DEE23A;
isa = PBXBuildFile;
settings = {
};
};
0FACBFEF07DC020D00DEE23A = {
fileRef = 0FACBFEC07DC020D00DEE23A;
isa = PBXBuildFile;
settings = {
};
};
0FBC0EC90798F92600E8E0E2 = {
children = (
0FBC0ECA0798F92600E8E0E2,
@ -2386,6 +2458,7 @@
0FBC0ED60798F96100E8E0E2,
0FBC0EE30798FA2700E8E0E2,
0F13A30F07D7F3930034B176,
0F4752D407DC0F4D002AEE9F,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -2987,6 +3060,7 @@
0FFE0A82079B147F00966027,
0FFE0A83079B147F00966027,
0FCCE56807D6D7DA006DD3D1,
0FACBFEE07DC020D00DEE23A,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -3510,6 +3584,7 @@
0FBC0EDD0798F9B400E8E0E2,
0FBC0EE00798FA1900E8E0E2,
0F13A31007D7F3930034B176,
0F4752D507DC0F4D002AEE9F,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -6260,6 +6335,7 @@
0FBC0ED80798F96100E8E0E2,
0FBC0EE40798FA2700E8E0E2,
0F13A31107D7F3930034B176,
0F4752D607DC0F4D002AEE9F,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -6860,6 +6936,7 @@
0FFE0A85079B147F00966027,
0FFE0A86079B147F00966027,
0FCCE56907D6D7DA006DD3D1,
0FACBFEF07DC020D00DEE23A,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -7384,6 +7461,7 @@
0FBC0EDE0798F9B400E8E0E2,
0FBC0EE10798FA1900E8E0E2,
0F13A31207D7F3930034B176,
0F4752D707DC0F4D002AEE9F,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@ -9660,9 +9738,9 @@
3FB2BA860545EA80002B9691 = {
fileEncoding = 30;
isa = PBXFileReference;
lastKnownFileType = sourcecode.c.objc;
name = BookmarkItem.m;
path = src/bookmarks/BookmarkItem.m;
lastKnownFileType = sourcecode.cpp.objcpp;
name = BookmarkItem.mm;
path = src/bookmarks/BookmarkItem.mm;
refType = 2;
sourceTree = SOURCE_ROOT;
};
@ -13979,6 +14057,7 @@
F507A84103116E1D01026D5D,
F507A84403116E5501026D5D,
0FBC0EC90798F92600E8E0E2,
0FACBFEC07DC020D00DEE23A,
F507A84A03116E6E01026D5D,
F583E3BB03B820AC01A80166,
F507A84D03116E7401026D5D,
@ -14101,14 +14180,10 @@
F53E012C02AEE93601A967F3,
3FB2BA7D0545EA80002B9691,
3FB2BA7E0545EA80002B9691,
3FB2BA7F0545EA80002B9691,
3FB2BA800545EA80002B9691,
3FB2BA810545EA80002B9691,
3FB2BA820545EA80002B9691,
3FB2BA830545EA80002B9691,
3FB2BA840545EA80002B9691,
3FB2BA850545EA80002B9691,
3FB2BA860545EA80002B9691,
3FB2BA810545EA80002B9691,
3FB2BA820545EA80002B9691,
3FB2BA870545EA80002B9691,
3FB2BA880545EA80002B9691,
3FB2BA890545EA80002B9691,
@ -14118,8 +14193,14 @@
3FB2BA8D0545EA80002B9691,
3FB2BA8E0545EA80002B9691,
3FB2BA8F0545EA80002B9691,
3FB2BA7F0545EA80002B9691,
3FB2BA800545EA80002B9691,
3FB2BA900545EA80002B9691,
3FB2BA910545EA80002B9691,
0F4752D207DC0F4D002AEE9F,
0F4752D307DC0F4D002AEE9F,
3FB2BA830545EA80002B9691,
3FB2BA840545EA80002B9691,
);
isa = PBXGroup;
name = Bookmarks;

Просмотреть файл

@ -3,18 +3,12 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>48 35 356 240 0 0 1280 832 </string>
<string>65 45 356 240 0 0 1600 1002 </string>
<key>IBFramework Version</key>
<string>364.0</string>
<key>IBLockedObjects</key>
<array>
<integer>26</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>26</integer>
</array>
<array/>
<key>IBSystem Version</key>
<string>7M34</string>
<string>7U16</string>
</dict>
</plist>

Двоичные данные
camino/resources/localized/English.lproj/BookmarkImportDlg.nib/keyedobjects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -7,10 +7,9 @@
},
{
ACTIONS = {
addBookmark = id;
addBookmarkFolder = id;
addBookmarkSeparator = id;
addCollection = id;
addFolder = id;
addSeparator = id;
deleteBookmarks = id;
locateBookmark = id;
openBookmark = id;
@ -46,10 +45,16 @@
};
SUPERCLASS = NSObject;
},
{CLASS = BookmarksEditingView; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = ExtendedTableView; LANGUAGE = ObjC; SUPERCLASS = NSTableView; },
{
ACTIONS = {unimplemented = id; };
ACTIONS = {
addBookmark = id;
addBookmarkFolder = id;
addBookmarkSeparator = id;
unimplemented = id;
};
CLASS = FirstResponder;
LANGUAGE = ObjC;
SUPERCLASS = NSObject;

Просмотреть файл

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>19 32 506 368 0 0 1600 1002 </string>
<string>18 22 506 368 0 0 1600 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>116</key>
@ -11,7 +11,7 @@
<key>137</key>
<string>355 423 176 87 0 0 1600 1002 </string>
<key>160</key>
<string>38 392 77 125 0 0 1600 1002 </string>
<string>38 392 98 125 0 0 1600 1002 </string>
<key>169</key>
<string>167 413 116 163 0 0 1600 1002 </string>
<key>18</key>
@ -20,10 +20,8 @@
<string>555 448 454 439 0 0 1600 1002 </string>
<key>261</key>
<string>554 476 457 383 0 0 1600 1002 </string>
<key>283</key>
<string>19 406 130 49 0 0 1600 1002 </string>
<key>64</key>
<string>367 446 170 137 0 0 1600 1002 </string>
<string>367 446 170 118 0 0 1600 1002 </string>
<key>68</key>
<string>174 384 142 87 0 0 1600 1002 </string>
<key>70</key>

Двоичные данные
camino/resources/localized/English.lproj/BookmarksEditing.nib/keyedobjects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -94,12 +94,13 @@
},
{
ACTIONS = {
addBookmark = id;
addBookmarkFolder = id;
addBookmarkForLink = id;
addBookmarkSeparator = id;
addToAddressBook = id;
back = id;
biggerTextSize = id;
bookmarkLink = id;
bookmarkPage = id;
cancelAddBookmarkSheet = id;
cancelLocationSheet = id;
cancelSearchSheet = id;
closeCurrentTab = id;
@ -110,10 +111,8 @@
copyImage = id;
copyImageLocation = id;
copyLinkLocation = id;
endAddBookmarkSheet = id;
endLocationSheet = id;
endSearchSheet = id;
ensureBrowserVisible = id;
forward = id;
frameToNewTab = id;
frameToNewWindow = id;
@ -143,8 +142,6 @@
sendURLFromLink = id;
smallerTextSize = id;
stop = id;
toggleBookmarkManager = id;
toggleSidebar = id;
unblockAllSites = id;
unblockSite = id;
viewOnlyThisImage = id;
@ -154,10 +151,6 @@
CLASS = BrowserWindowController;
LANGUAGE = ObjC;
OUTLETS = {
mAddBookmarkCheckbox = NSButton;
mAddBookmarkFolderField = NSPopUpButton;
mAddBookmarkSheetWindow = NSWindow;
mAddBookmarkTitleField = NSTextField;
mAddToAddressBook = NSMenuItem;
mAddToAddressBook2 = NSMenuItem;
mBackItem = NSMenuItem;
@ -198,7 +191,12 @@
},
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = ExtendedTableView; LANGUAGE = ObjC; SUPERCLASS = NSTableView; },
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{
ACTIONS = {addBookmark = id; addBookmarkFolder = id; addBookmarkSeparator = id; };
CLASS = FirstResponder;
LANGUAGE = ObjC;
SUPERCLASS = NSObject;
},
{
ACTIONS = {deleteHistoryItems = id; openHistoryItem = id; };
CLASS = HistoryDataSource;

Просмотреть файл

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>56 16 538 485 0 0 1280 832 </string>
<string>126 353 538 485 0 0 1600 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>1014</key>
@ -11,15 +11,15 @@
<key>1022</key>
<string>52 797 169 156 0 0 1600 1002 </string>
<key>297</key>
<string>72 297 213 294 0 0 1152 746 </string>
<string>558 586 213 306 0 0 1600 1002 </string>
<key>314</key>
<string>55 435 213 150 0 0 1280 832 </string>
<string>306 574 213 156 0 0 1600 1002 </string>
<key>336</key>
<string>122 534 213 206 0 0 1280 832 </string>
<string>159 679 213 206 0 0 1600 1002 </string>
<key>365</key>
<string>97 563 93 168 0 0 1280 832 </string>
<string>123 707 93 168 0 0 1600 1002 </string>
<key>463</key>
<string>268 375 213 264 0 0 1280 832 </string>
<string>348 489 213 275 0 0 1600 1002 </string>
<key>56</key>
<string>419 485 314 64 0 0 1152 746 </string>
<key>654</key>
@ -27,7 +27,7 @@
<key>801</key>
<string>418 469 201 79 0 0 1024 746 </string>
<key>826</key>
<string>84 401 213 60 0 0 1152 746 </string>
<string>124 551 213 61 0 0 1600 1002 </string>
</dict>
<key>IBFramework Version</key>
<string>364.0</string>
@ -37,10 +37,6 @@
<integer>910</integer>
<integer>889</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>336</integer>
</array>
<key>IBSystem Version</key>
<string>7U16</string>
</dict>

Двоичные данные
camino/resources/localized/English.lproj/BrowserWindow.nib/keyedobjects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -5,16 +5,18 @@
LANGUAGE = ObjC;
SUPERCLASS = ToolbarController;
},
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{
ACTIONS = {addBookmark = id; addBookmarkFolder = id; addBookmarkSeparator = id; };
CLASS = FirstResponder;
LANGUAGE = ObjC;
SUPERCLASS = NSObject;
},
{CLASS = GoMenu; LANGUAGE = ObjC; SUPERCLASS = NSMenu; },
{
ACTIONS = {
aboutPlugins = id;
aboutServers = id;
aboutWindow = id;
addBookmark = id;
addFolder = id;
addSeparator = id;
biggerTextSize = id;
closeTab = id;
connectToServer = id;

Просмотреть файл

@ -3,21 +3,17 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>70 21 482 240 0 0 1600 1002 </string>
<string>100 49 608 498 0 0 1600 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>29</key>
<string>342 563 433 44 0 0 1280 832 </string>
<string>471 684 433 44 0 0 1600 1002 </string>
<key>494</key>
<string>507 508 116 61 0 0 1152 848 </string>
</dict>
<key>IBFramework Version</key>
<string>364.0</string>
<key>IBOpenObjects</key>
<array>
<integer>29</integer>
</array>
<key>IBSystem Version</key>
<string>7M34</string>
<string>7U16</string>
</dict>
</plist>

Двоичные данные
camino/resources/localized/English.lproj/MainMenu.nib/keyedobjects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -143,10 +143,8 @@ typedef enum EBookmarkOpenBehavior
// Bookmarks menu actions.
-(IBAction) importBookmarks:(id)aSender;
-(IBAction) exportBookmarks:(id)aSender;
-(IBAction) addBookmark:(id)aSender;
-(IBAction) openMenuBookmark:(id)aSender;
-(IBAction) addFolder:(id)aSender;
-(IBAction) addSeparator:(id)aSender;
// Window menu actions
-(IBAction) newTab:(id)aSender;

Просмотреть файл

@ -917,25 +917,6 @@ Otherwise, we return the URL we originally got. Right now this supports .url and
[[BookmarkManager sharedBookmarkManager] writeSafariFile:[savePanel filename]];
}
-(IBAction) addBookmark:(id)aSender
{
BrowserWindowController* browserController = [self getMainWindowBrowserController];
if (browserController)
[browserController addBookmarkExtended: NO URL:nil title:nil];
}
-(IBAction) addFolder:(id)aSender
{
BrowserWindowController* browserController = [self getMainWindowBrowserController];
if (browserController)
[browserController addBookmarkExtended: YES URL:nil title:nil];
}
-(IBAction) addSeparator:(id)aSender
{
NSLog(@"Separators not implemented yet");
}
-(IBAction) openMenuBookmark:(id)aSender
{
BookmarkItem* item = [aSender representedObject];
@ -1088,6 +1069,7 @@ Otherwise, we return the URL we originally got. Right now this supports .url and
// NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action);
// XXX some of these should be wired to the First Responder (like reload:).
if (action == @selector(printPage:) ||
/* ... many more items go here ... */
/* action == @selector(goHome:) || */ // always enabled

Просмотреть файл

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
extern NSString* const kAddBookmarkItemURLKey;
extern NSString* const kAddBookmarkItemTitleKey;
@class BookmarkFolder;
@class BookmarkViewController;
@interface AddBookmarkDialogController : NSWindowController
{
IBOutlet NSTextField* mTitleField;
IBOutlet NSPopUpButton* mParentFolderPopup;
IBOutlet NSButton* mTabGroupCheckbox;
BookmarkViewController* mBookmarkViewController; // not retained
BookmarkFolder* mInitialParentFolder;
NSArray* mBookmarkItems; // array of NSDictionary
BOOL mCreatingFolder;
}
+ (AddBookmarkDialogController*)sharedAddBookmarkDialogController;
- (IBAction)confirmAddBookmark:(id)sender;
- (IBAction)cancelAddBookmark:(id)sender;
- (IBAction)parentFolderChanged:(id)sender;
- (void)setDefaultParentFolder:(BookmarkFolder*)inFolder;
- (void)setBookmarkViewController:(BookmarkViewController*)inBMViewController;
// inItems is an NSArray of NSDictionary, one per possible item
- (void)showDialogWithLocationsAndTitles:(NSArray*)inItems isFolder:(BOOL)inIsFolder onWindow:(NSWindow*)inWindow;
@end

Просмотреть файл

@ -0,0 +1,261 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "NSString+Utils.h"
#import "BookmarkFolder.h"
#import "Bookmark.h"
#import "BookmarkManager.h"
#import "AddBookmarkDialogController.h"
NSString* const kAddBookmarkItemURLKey = @"url";
NSString* const kAddBookmarkItemTitleKey = @"title";
@interface AddBookmarkDialogController(Private)
+ (NSString*)bookmarkUrlForItem:(NSDictionary*)inItem;
+ (NSString*)bookmarkTitleForItem:(NSDictionary*)inItem;
- (void)buildBookmarksFolderPopup;
- (void)createBookmarks;
- (void)clearState;
@end
#pragma mark -
@implementation AddBookmarkDialogController
+ (AddBookmarkDialogController*)sharedAddBookmarkDialogController
{
static AddBookmarkDialogController* sSharedController = nil;
if (!sSharedController)
{
sSharedController = [[AddBookmarkDialogController alloc] initWithWindowNibName:@"AddBookmark"];
[sSharedController window]; // force nib loading
}
return sSharedController;
}
- (void)awakeFromNib
{
[mTabGroupCheckbox retain]; // so we can remove it
}
- (void)dealloc
{
[mTabGroupCheckbox release];
[super dealloc];
}
- (IBAction)confirmAddBookmark:(id)sender
{
[[self window] orderOut:self];
[NSApp endSheet:[self window] returnCode:1];
[self createBookmarks];
[self clearState];
}
- (IBAction)cancelAddBookmark:(id)sender
{
[[self window] orderOut:self];
[NSApp endSheet:[self window] returnCode:1];
[self clearState];
}
- (IBAction)parentFolderChanged:(id)sender
{
}
- (void)setDefaultParentFolder:(BookmarkFolder*)inFolder
{
[mInitialParentFolder autorelease];
mInitialParentFolder = [inFolder retain];
}
- (void)setBookmarkViewController:(BookmarkViewController*)inBMViewController
{
mBookmarkViewController = inBMViewController;
}
- (void)showDialogWithLocationsAndTitles:(NSArray*)inItems isFolder:(BOOL)inIsFolder onWindow:(NSWindow*)inWindow
{
if (!inIsFolder && [inItems count] == 0)
return;
[mBookmarkItems autorelease];
mBookmarkItems = [inItems retain];
mCreatingFolder = inIsFolder;
// set title field
NSString* titleString = @"";
if (mCreatingFolder)
titleString = NSLocalizedString(@"NewBookmarkFolder", @"");
else
titleString = [AddBookmarkDialogController bookmarkTitleForItem:[inItems objectAtIndex:0]];
[mTitleField setStringValue:titleString];
// setup tab checkbox
if (!mCreatingFolder)
{
if (![mTabGroupCheckbox superview])
[[[self window] contentView] addSubview:mTabGroupCheckbox];
[mTabGroupCheckbox setEnabled:([inItems count] > 1)];
}
else
{
[mTabGroupCheckbox removeFromSuperview];
}
[self buildBookmarksFolderPopup];
[NSApp beginSheet:[self window]
modalForWindow:inWindow
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
}
#pragma mark -
+ (NSString*)bookmarkUrlForItem:(NSDictionary*)inItem
{
return [inItem objectForKey:kAddBookmarkItemURLKey];
}
+ (NSString*)bookmarkTitleForItem:(NSDictionary*)inItem
{
NSString* bookmarkTitle = [inItem objectForKey:kAddBookmarkItemTitleKey];
bookmarkTitle = [bookmarkTitle stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "];
if (!bookmarkTitle)
bookmarkTitle = [AddBookmarkDialogController bookmarkUrlForItem:inItem];
return bookmarkTitle;
}
- (void)buildBookmarksFolderPopup
{
[mParentFolderPopup removeAllItems];
[[[BookmarkManager sharedBookmarkManager] rootBookmarks] buildFlatFolderList:[mParentFolderPopup menu] depth:1];
BookmarkFolder* initialFolder = mInitialParentFolder;
if (!initialFolder)
initialFolder = [[BookmarkManager sharedBookmarkManager] lastUsedBookmarkFolder];
if (initialFolder)
{
int initialItemIndex = [[mParentFolderPopup menu] indexOfItemWithRepresentedObject:initialFolder];
if (initialItemIndex != -1)
[mParentFolderPopup selectItemAtIndex:initialItemIndex];
}
else
{
[mParentFolderPopup selectItemAtIndex:0];
}
[mParentFolderPopup synchronizeTitleAndSelectedItem];
}
- (void)createBookmarks
{
BookmarkFolder* parentFolder = [[mParentFolderPopup selectedItem] representedObject];
NSString* titleString = [mTitleField stringValue];
BookmarkItem* newItem = nil;
if (mCreatingFolder)
{
newItem = [parentFolder addBookmarkFolder:titleString inPosition:[parentFolder count] isGroup:NO];
}
else
{
if (([mBookmarkItems count] > 1) && ([mTabGroupCheckbox state] == NSOnState))
{
// bookmark all tabs
BookmarkFolder* newGroup = [parentFolder addBookmarkFolder:titleString inPosition:[parentFolder count] isGroup:YES];
unsigned int numItems = [mBookmarkItems count];
for (unsigned int i = 0; i < numItems; i++)
{
id curItem = [mBookmarkItems objectAtIndex:i];
NSString* itemTitle = [AddBookmarkDialogController bookmarkTitleForItem:curItem];
NSString* itemURL = [AddBookmarkDialogController bookmarkUrlForItem:curItem];
newItem = [newGroup addBookmark:itemTitle url:itemURL inPosition:i isSeparator:NO];
}
}
else
{
id curItem = [mBookmarkItems objectAtIndex:0];
NSString* itemTitle = [AddBookmarkDialogController bookmarkTitleForItem:curItem];
NSString* itemURL = [AddBookmarkDialogController bookmarkUrlForItem:curItem];
newItem = [parentFolder addBookmark:itemTitle url:itemURL inPosition:[parentFolder count] isSeparator:NO];
}
}
[mBookmarkViewController revealItem:newItem selecting:YES];
[[BookmarkManager sharedBookmarkManager] setLastUsedBookmarkFolder:parentFolder];
}
- (void)clearState
{
[mTitleField setStringValue:@""];
[mTabGroupCheckbox setState:NSOffState];
[mInitialParentFolder release];
mInitialParentFolder = nil;
mCreatingFolder = NO;
[mBookmarkItems release];
mBookmarkItems = nil;
mBookmarkViewController = nil;
}
@end

Просмотреть файл

@ -243,7 +243,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
[self setAccumulateUpdateNotifications:YES];
[self setTitle:[aDict objectForKey:BMTitleKey]];
[self setDescription:[aDict objectForKey:BMDescKey]];
[self setItemDescription:[aDict objectForKey:BMDescKey]];
[self setKeyword:[aDict objectForKey:BMKeywordKey]];
[self setUrl:[aDict objectForKey:BMURLKey]];
[self setLastVisit:[aDict objectForKey:BMLastVisitKey]];
@ -284,7 +284,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
[self setAccumulateUpdateNotifications:YES];
[self setTitle:[[attribDict objectForKey:CaminoNameKey] stringByRemovingAmpEscapes]];
[self setKeyword:[[attribDict objectForKey:CaminoKeywordKey] stringByRemovingAmpEscapes]];
[self setDescription:[[attribDict objectForKey:CaminoDescKey] stringByRemovingAmpEscapes]];
[self setItemDescription:[[attribDict objectForKey:CaminoDescKey] stringByRemovingAmpEscapes]];
[self setUrl:[[attribDict objectForKey:CaminoURLKey] stringByRemovingAmpEscapes]];
//fire an update notification
[self setAccumulateUpdateNotifications:NO];

Просмотреть файл

@ -114,6 +114,7 @@ enum {
// searching
-(NSArray *) resolveKeyword:(NSString *)aString;
-(NSSet *) bookmarksWithString:(NSString *)searchString inFieldWithTag:(int)tag;
- (BOOL)containsChildItem:(BookmarkItem*)inItem;
//Scripting - should be a protocol we could use for these
//two, but i'm not sure which one, so we'll declare them here

Просмотреть файл

@ -413,7 +413,7 @@ NSString* const BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
[theBookmark setTitle:aTitle];
[theBookmark setKeyword:aKeyword];
[theBookmark setUrl:aURL];
[theBookmark setDescription:aDescription];
[theBookmark setItemDescription:aDescription];
[theBookmark setLastVisit:aDate];
[theBookmark setStatus:aStatus];
[theBookmark setIsSeparator:aSeparator];
@ -651,28 +651,30 @@ NSString* const BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
-(void)buildFlatFolderList:(NSMenu *)menu depth:(unsigned)depth
{
NSEnumerator *children = [mChildArray objectEnumerator];
NSMutableString *paddedTitle;
id aKid;
while ((aKid = [children nextObject])) {
if ([aKid isKindOfClass:[BookmarkFolder class]]) {
if (![aKid isSmartFolder]) {
paddedTitle = [[aKid title] mutableCopyWithZone:nil];
if ([paddedTitle length] > 80)
[paddedTitle stringByTruncatingTo:80 at:kTruncateAtMiddle];
NSString* paddedTitle = [[aKid title] stringByTruncatingTo:80 at:kTruncateAtMiddle];
NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle: paddedTitle action: NULL keyEquivalent: @""];
[paddedTitle release];
[menuItem setRepresentedObject:aKid];
NSImage *curIcon = [aKid icon];
NSSize iconSize = [curIcon size];
NSImage *shiftedIcon = [[NSImage alloc] initWithSize:NSMakeSize(depth*(iconSize.width), iconSize.height)];
[shiftedIcon lockFocus];
[curIcon drawInRect:NSMakeRect(([shiftedIcon size].width-iconSize.width),0,iconSize.width,iconSize.height) fromRect:NSMakeRect(0,0,iconSize.width,iconSize.height) operation:NSCompositeCopy fraction:1];
[curIcon drawInRect:NSMakeRect(([shiftedIcon size].width - iconSize.width), 0, iconSize.width, iconSize.height)
fromRect:NSMakeRect(0, 0, iconSize.width, iconSize.height)
operation:NSCompositeCopy
fraction:1];
[shiftedIcon unlockFocus];
[menuItem setImage:shiftedIcon];
[shiftedIcon release];
[menu addItem:menuItem];
[menuItem release];
[aKid buildFlatFolderList:menu depth:(depth+1)];
[aKid buildFlatFolderList:menu depth:(depth + 1)];
}
}
}
@ -763,6 +765,28 @@ NSString* const BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
return foundSet;
}
- (BOOL)containsChildItem:(BookmarkItem*)inItem
{
if (inItem == self)
return YES;
unsigned int numChildren = [mChildArray count];
for (unsigned int i = 0; i < numChildren; i ++)
{
BookmarkItem* curChild = [mChildArray objectAtIndex:i];
if (curChild == inItem)
return YES;
if ([curChild isKindOfClass:[BookmarkFolder class]])
{
if ([curChild containsChildItem:inItem])
return YES;
}
}
return NO;
}
//
// Notification stuff
//
@ -806,7 +830,7 @@ NSString* const BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
NSEnumerator *enumerator;
BOOL noErr = YES;
[self setTitle:[aDict objectForKey:BMTitleKey]];
[self setDescription:[aDict objectForKey:BMFolderDescKey]];
[self setItemDescription:[aDict objectForKey:BMFolderDescKey]];
[self setKeyword:[aDict objectForKey:BMFolderKeywordKey]];
unsigned int flag = [[aDict objectForKey:BMFolderTypeKey] unsignedIntValue];
// on the off chance we've imported somebody else's bookmarks after startup,
@ -866,7 +890,7 @@ NSString* const BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
if (elementInfoPtr) {
NSDictionary* attribDict = (NSDictionary*)elementInfoPtr->attributes;
[self setTitle:[[attribDict objectForKey:CaminoNameKey] stringByRemovingAmpEscapes]];
[self setDescription:[[attribDict objectForKey:CaminoDescKey] stringByRemovingAmpEscapes]];
[self setItemDescription:[[attribDict objectForKey:CaminoDescKey] stringByRemovingAmpEscapes]];
if ([[attribDict objectForKey:CaminoTypeKey] isEqualToString:CaminoToolbarKey])
[self setIsToolbar:YES];
if ([[attribDict objectForKey:CaminoGroupKey] isEqualToString:CaminoTrueKey])

Просмотреть файл

@ -51,10 +51,12 @@
-(NSString *) getSaltedBookmarkPathForProfile: (NSString *) aPath;
-(void) beginImportFrom:(NSString *) aPath intoFolder:(BookmarkFolder *) aFolder;
-(void) beginOmniWeb5ImportFrom:(NSArray *)anArray intoFolder:(BookmarkFolder *)aFolder;
-(void) finishImport:(BOOL)success fromFile:(NSString *)aFile;
-(void) finishImport:(BOOL)success fromFile:(NSString *)aFile intoFolder:(BookmarkFolder*)aFolder;
@end
#pragma mark -
@implementation BookmarkImportDlgController
-(void) windowDidLoad
@ -68,15 +70,15 @@
{
NSString *mozPath;
// Remove everything but the "Select a file..." option, on the off-chance that someone brings
// Remove everything but the separator and "Select a file..." option, on the off-chance that someone brings
// up the import dialog, throws away a profile, then brings up the import dialog again
while ([mBrowserListButton numberOfItems] > 1)
while ([mBrowserListButton numberOfItems] > 2)
[mBrowserListButton removeItemAtIndex:0];
[self tryAddImportFromBrowser:@"iCab" withBookmarkPath:@"~/Library/Preferences/iCab Preferences/Hotlist.html"];
[self tryAddImportFromBrowser:@"Opera" withBookmarkPath:@"~/Library/Preferences/Opera Preferences/Bookmarks"];
[self tryAddImportFromBrowser:@"OmniWeb 4" withBookmarkPath:@"~/Library/Application Support/Omniweb/Bookmarks.html"];
// Stupid OmniWeb 5 has between 0 and 3 bookmark files. Dumb.
// OmniWeb 5 has between 0 and 3 bookmark files.
[self tryOmniWeb5Import];
[self tryAddImportFromBrowser:@"Internet Explorer" withBookmarkPath:@"~/Library/Preferences/Explorer/Favorites.html"];
[self tryAddImportFromBrowser:@"Safari" withBookmarkPath:@"~/Library/Safari/Bookmarks.plist"];
@ -109,7 +111,7 @@
}
}
// Stupid OmniWeb 5
// Special treatment for OmniWeb 5
-(void) tryOmniWeb5Import
{
NSArray *owFiles = [NSArray arrayWithObjects:
@ -216,23 +218,30 @@
[mImportButton setEnabled:NO];
NSEnumerator *enumerator = [anArray objectEnumerator];
NSString *aPath;
NSString *aFile;
NSString* curFilename = nil;
BOOL success = TRUE;
while ( success && (aPath = [enumerator nextObject] ) ) {
aFile = [aPath lastPathComponent];
NSString *curPath;
while ( success && (curPath = [enumerator nextObject] ) )
{
curFilename = [curPath lastPathComponent];
// What folder we import into depends on what OmniWeb file we're importing.
if ([aFile isEqualToString:@"Bookmarks.html"] ) {
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:aPath intoFolder:aFolder];
if ([curFilename isEqualToString:@"Bookmarks.html"] )
{
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:curPath intoFolder:aFolder];
}
else if ([aFile isEqualToString:@"Favorites.html"] ) {
else if ([curFilename isEqualToString:@"Favorites.html"] )
{
BookmarkFolder *favoriteFolder = [aFolder addBookmarkFolder];
[favoriteFolder setTitle:NSLocalizedString(@"OmniWeb Favorites",@"OmniWeb Favorites")];
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:aPath intoFolder:favoriteFolder];
} else if ([aFile isEqualToString:@"Published.html"]) {
[favoriteFolder setTitle:NSLocalizedString(@"OmniWeb Favorites", @"OmniWeb Favorites")];
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:curPath intoFolder:favoriteFolder];
}
else if ([curFilename isEqualToString:@"Published.html"])
{
BookmarkFolder *publishedFolder = [aFolder addBookmarkFolder];
[publishedFolder setTitle:NSLocalizedString(@"OmniWeb Published",@"OmniWeb Published")];
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:aPath intoFolder:publishedFolder];
[publishedFolder setTitle:NSLocalizedString(@"OmniWeb Published", @"OmniWeb Published")];
success = [[BookmarkManager sharedBookmarkManager] importBookmarks:curPath intoFolder:publishedFolder];
}
}
@ -240,7 +249,7 @@
[mImportButton setEnabled:YES];
// Non-rigorous reporting of errors
[self finishImport:success fromFile:aFile];
[self finishImport:success fromFile:curFilename intoFolder:aFolder];
}
-(void) beginImportFrom:(NSString *) aPath intoFolder:(BookmarkFolder *) aFolder
@ -253,20 +262,22 @@
[mCancelButton setEnabled:YES];
[mImportButton setEnabled:YES];
[self finishImport:success fromFile:[aPath lastPathComponent]];
[self finishImport:success fromFile:[aPath lastPathComponent] intoFolder:aFolder];
}
-(void) finishImport:(BOOL)success fromFile:(NSString *)aFile
-(void) finishImport:(BOOL)success fromFile:(NSString *)aFile intoFolder:(BookmarkFolder*)aFolder
{
if (success) { //show them the imported bookmarks if import succeeded
//show them the imported bookmarks if import succeeded
if (success)
{
[[self window] orderOut:self];
BrowserWindowController *windowController = [(MainController *)[NSApp delegate] openBrowserWindowWithURL:@"" andReferrer:nil behind:nil allowPopups:NO];
[windowController manageBookmarks:self];
BookmarkViewController *bmController = [windowController bookmarkViewController];
[bmController selectContainer:[bmController containerCount]-1];
} else {
BrowserWindowController* windowController = [(MainController *)[NSApp delegate] openBrowserWindowWithURL:@"about:bookmarks" andReferrer:nil behind:nil allowPopups:NO];
BookmarkViewController* bmController = [windowController bookmarkViewController];
[bmController setItemToRevealOnLoad:aFolder];
}
else
{
NSBeginAlertSheet(NSLocalizedString(@"ImportFailureTitle", @"Import Failed"), // title
@"", // default button
nil, // no cancel buttton

Просмотреть файл

@ -159,13 +159,13 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
if (!changedField) {
if ((tabViewItem == mBookmarkInfoTabView) && isBookmark) {
[mBookmarkItem setTitle:[mBookmarkNameField stringValue]];
[mBookmarkItem setDescription:[mBookmarkDescField stringValue]];
[mBookmarkItem setItemDescription:[mBookmarkDescField stringValue]];
[mBookmarkItem setKeyword:[mBookmarkKeywordField stringValue]];
[(Bookmark *)mBookmarkItem setUrl:[mBookmarkLocationField stringValue]];
}
else if ([mDummyView contentView] == mFolderView && !isBookmark) {
[mBookmarkItem setTitle:[mFolderNameField stringValue]];
[mBookmarkItem setDescription:[mFolderDescField stringValue]];
[mBookmarkItem setItemDescription:[mFolderDescField stringValue]];
if ([(BookmarkFolder *)mBookmarkItem isGroup])
[mBookmarkItem setKeyword:[mFolderKeywordField stringValue]];
}
@ -175,7 +175,7 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
else if ((changedField == mBookmarkKeywordField) || (changedField == mFolderKeywordField))
[mBookmarkItem setKeyword:[changedField stringValue]];
else if ((changedField == mBookmarkDescField) || (changedField == mFolderDescField))
[mBookmarkItem setDescription:[changedField stringValue]];
[mBookmarkItem setItemDescription:[changedField stringValue]];
else if ((changedField == mBookmarkLocationField) && isBookmark)
[(Bookmark *)mBookmarkItem setUrl:[changedField stringValue]];
@ -233,7 +233,7 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
if ([aBookmark isKindOfClass:[Bookmark class]]) {
newView = mBookmarkView;
[mBookmarkNameField setStringValue: [aBookmark title]];
[mBookmarkDescField setStringValue: [aBookmark description]];
[mBookmarkDescField setStringValue: [aBookmark itemDescription]];
[mBookmarkKeywordField setStringValue: [aBookmark keyword]];
[mBookmarkLocationField setStringValue: [(Bookmark *)aBookmark url]];
[mNumberVisitsField setIntValue:[(Bookmark *)aBookmark numberOfVisits]];
@ -268,7 +268,7 @@ static BookmarkInfoController *sharedBookmarkInfoController = nil;
}
[mFolderNameField setStringValue: [aBookmark title]];
[mFolderKeywordField setStringValue: [aBookmark keyword]];
[mFolderDescField setStringValue: [aBookmark description]];
[mFolderDescField setStringValue: [aBookmark itemDescription]];
// we can't just unselect dock menu - we have to pick a new one
if ([(BookmarkFolder *)aBookmark isDockMenu]) {
[mDockMenuCheckbox setState:NSOnState];

Просмотреть файл

@ -55,20 +55,20 @@
// Setters/Getters
-(id) parent;
-(NSString *) title;
-(NSString *) description;
-(NSString *) itemDescription; // don't use "description"
-(NSString *) keyword;
-(NSImage *) icon;
-(NSString *) UUID;
-(void) setParent:(id)aParent;
-(void) setParent:(id)aParent; // note that the parent of root items is the BookmarksManager, for some reason
-(void) setTitle:(NSString *)aString;
-(void) setDescription:(NSString *)aString;
-(void) setItemDescription:(NSString *)aString;
-(void) setKeyword:(NSString *)aKeyword;
-(void) setIcon:(NSImage *)aIcon;
-(void) setUUID:(NSString *)aUUID;
// Status checks
-(BOOL) isChildOfItem:(BookmarkItem *)anItem;
- (BOOL)isChildOfItem:(BookmarkItem *)anItem;
- (BOOL)hasAncestor:(BookmarkItem*)inItem;
// Searching

Просмотреть файл

@ -0,0 +1,337 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Haas <haasd@cae.wisc.edu>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "NSString+Utils.h"
#import "BookmarksClient.h"
#import "BookmarkItem.h"
// Notifications
NSString* const BookmarkItemChangedNotification = @"bi_cg";
NSString* const BookmarkIconChangedNotification = @"bicon_cg";
// all our saving/loading keys
// Safari & Camino plist keys
NSString* const BMTitleKey = @"Title";
NSString* const BMChildrenKey = @"Children";
// Camino plist keys
NSString* const BMFolderDescKey = @"FolderDescription";
NSString* const BMFolderTypeKey = @"FolderType";
NSString* const BMFolderKeywordKey = @"FolderKeyword";
NSString* const BMDescKey = @"Description";
NSString* const BMStatusKey = @"Status";
NSString* const BMURLKey = @"URL";
NSString* const BMKeywordKey = @"Keyword";
NSString* const BMLastVisitKey = @"LastVisitedDate";
NSString* const BMNumberVisitsKey = @"VisitCount";
// safari keys
NSString* const SafariTypeKey = @"WebBookmarkType";
NSString* const SafariLeaf = @"WebBookmarkTypeLeaf";
NSString* const SafariList = @"WebBookmarkTypeList";
NSString* const SafariAutoTab = @"WebBookmarkAutoTab";
NSString* const SafariUUIDKey = @"WebBookmarkUUID";
NSString* const SafariURIDictKey = @"URIDictionary";
NSString* const SafariBookmarkTitleKey = @"title";
NSString* const SafariURLStringKey = @"URLString";
// camino XML keys
NSString* const CaminoNameKey = @"name";
NSString* const CaminoDescKey = @"description";
NSString* const CaminoTypeKey = @"type";
NSString* const CaminoKeywordKey = @"id";
NSString* const CaminoURLKey = @"href";
NSString* const CaminoToolbarKey = @"toolbar";
NSString* const CaminoDockMenuKey = @"dockmenu";
NSString* const CaminoGroupKey = @"group";
NSString* const CaminoBookmarkKey = @"bookmark";
NSString* const CaminoFolderKey = @"folder";
NSString* const CaminoTrueKey = @"true";
@implementation BookmarkItem
static BOOL gSuppressAllUpdates = NO;
//Initialization
-(id) init
{
if ((self = [super init]))
{
mParent = NULL;
mTitle = [[NSString alloc] init]; //retain count +1
mKeyword = [mTitle retain]; //retain count +2
mDescription = [mTitle retain]; //retain count +3! and just 1 allocation.
mUUID = nil;
// if we set the icon here, we will get a memory leak. so don't.
// subclass will provide icon.
mIcon = NULL;
mAccumulateItemChangeUpdates = NO;
}
return self;
}
-(id) copyWithZone:(NSZone *)zone
{
//descend from NSObject - so don't call super
id doppleganger = [[[self class] allocWithZone:zone] init];
[doppleganger setTitle:[self title]];
[doppleganger setItemDescription:[self itemDescription]];
[doppleganger setKeyword:[self keyword]];
[doppleganger setParent:[self parent]];
[doppleganger setIcon:[self icon]];
// do NOT copy the UUID. It wouldn't be "U" then, would it?
return doppleganger;
}
-(void)dealloc
{
[mTitle release];
[mDescription release];
[mKeyword release];
[mIcon release];
[mUUID release];
[super dealloc];
}
// Basic properties
-(id) parent
{
return mParent;
}
-(NSString *) title
{
return mTitle;
}
-(NSString *) itemDescription
{
return mDescription;
}
-(NSString *) keyword
{
return mKeyword;
}
// if we ask for a UUID, it means we need
// one. So generate it if it doesn't exist.
-(NSString *) UUID
{
if (!mUUID)
mUUID = [[NSString stringWithUUID] retain];
return mUUID;
}
-(NSImage *)icon
{
return mIcon;
}
- (BOOL)isChildOfItem:(BookmarkItem *)anItem
{
if (![[self parent] isKindOfClass:[BookmarkItem class]])
return NO;
if ([self parent] == anItem)
return YES;
return [[self parent] isChildOfItem:anItem];
}
- (BOOL)hasAncestor:(BookmarkItem*)inItem
{
if (inItem == self)
return YES;
id myParent = [self parent];
if (myParent && [myParent isKindOfClass:[BookmarkItem class]])
{
return [myParent hasAncestor:inItem];
}
return NO;
}
-(void) setParent:(id) aParent
{
mParent = aParent; // no reference on the parent, so it better not disappear on us.
}
-(void) setTitle:(NSString *)aTitle
{
if (!aTitle)
return;
[aTitle retain];
[mTitle release];
mTitle = aTitle;
[self itemUpdatedNote];
}
-(void) setItemDescription:(NSString *)aDescription
{
if (!aDescription)
return;
[aDescription retain];
[mDescription release];
mDescription = aDescription;
}
- (void) setKeyword:(NSString *)aKeyword
{
if (!aKeyword)
return;
[aKeyword retain];
[mKeyword release];
mKeyword = aKeyword;
}
-(void) setIcon:(NSImage *)aIcon
{
if (!aIcon)
return;
[aIcon retain];
[mIcon release];
mIcon = aIcon;
if (![BookmarkItem allowNotifications]) return;
NSNotification *note = [NSNotification notificationWithName:BookmarkIconChangedNotification
object:self userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotification:note];
}
-(BOOL)matchesString:(NSString*)searchString inFieldWithTag:(int)tag
{
switch (tag)
{
case eBookmarksSearchFieldAll:
return (([[self title] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound) ||
([[self keyword] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound) ||
([[self itemDescription] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound));
case eBookmarksSearchFieldTitle:
return ([[self title] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound);
// case eBookmarksSearchFieldURL: // Bookmark subclass has to check this
case eBookmarksSearchFieldKeyword:
return ([[self keyword] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound);
case eBookmarksSearchFieldDescription:
return ([[self itemDescription] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound);
}
return NO;
}
// Prevents all NSNotification posting from any BookmarkItem.
// Useful for suppressing all the pointless notifications during load.
+(void) setSuppressAllUpdateNotifications:(BOOL)suppressUpdates
{
gSuppressAllUpdates = suppressUpdates;
}
+(BOOL) allowNotifications
{
return !gSuppressAllUpdates;
}
// Helps prevent spamming from itemUpdatedNote:
// calling with YES will prevent itemUpdatedNote from doing anything
// and calling with NO will restore itemUpdatedNote and then call it.
-(void) setAccumulateUpdateNotifications:(BOOL)accumulateUpdates
{
mAccumulateItemChangeUpdates = accumulateUpdates;
if (!mAccumulateItemChangeUpdates)
[self itemUpdatedNote]; //fire an update to cover the updates that weren't sent
}
-(void) itemUpdatedNote
{
if (gSuppressAllUpdates || mAccumulateItemChangeUpdates) return;
NSNotification *note = [NSNotification notificationWithName:BookmarkItemChangedNotification object:self userInfo:nil];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotification:note];
}
// stub functions to avoid warning
-(void) refreshIcon
{
}
//Reading/writing to & from disk - all just stubs.
-(BOOL) readNativeDictionary:(NSDictionary *)aDict
{
return NO;
}
-(BOOL) readSafariDictionary:(NSDictionary *)aDict
{
return NO;
}
-(BOOL) readCaminoXML:(CFXMLTreeRef)aTreeRef
{
return NO;
}
-(NSDictionary *)writeNativeDictionary
{
return [NSDictionary dictionary];
}
-(NSDictionary *)writeSafariDictionary
{
return [NSDictionary dictionary];
}
-(NSString *)writeHTML:(unsigned)aPad
{
return [NSString string];
}
@end

Просмотреть файл

@ -59,12 +59,14 @@ enum {
KindaSmartFolderManager* mSmartFolderManager; // brains behind 4 smart folders
NSUndoManager* mUndoManager; // handles deletes, adds of bookmarks
BookmarkImportDlgController* mImportDlgController;
NSString* mPathToBookmarkFile; // exactly what it looks like
NSString* mPathToBookmarkFile;
// smart folders
BookmarkFolder* mTop10Container;
BookmarkFolder* mRendezvousContainer;
BookmarkFolder* mAddressBookContainer;
BookmarkFolder* mLastUsedFolder;
}
// Class Methods & shutdown stuff
@ -85,6 +87,11 @@ enum {
-(BookmarkFolder *) rendezvousFolder;
-(BookmarkFolder *) addressBookFolder;
-(BookmarkFolder *) historyFolder;
// get/set folder last used by "Add Bookmarks"
- (BookmarkFolder*)lastUsedBookmarkFolder;
- (void)setLastUsedBookmarkFolder:(BookmarkFolder*)inFolder;
-(BookmarkItem*) itemWithUUID:(NSString*)uuid;
-(NSUndoManager *) undoManager;
-(void) setRootBookmarks:(BookmarkFolder *)anArray;

Просмотреть файл

@ -149,7 +149,7 @@ static unsigned gFirstUserCollection = 0;
{
if ((self = [super init])) {
BookmarkFolder* root = [[BookmarkFolder alloc] init];
[root setParent:self];
[root setParent:self]; // XXX why?
[root setIsRoot:YES];
[root setTitle:NSLocalizedString(@"BookmarksRootName", @"")];
[self setRootBookmarks:root];
@ -209,18 +209,24 @@ static unsigned gFirstUserCollection = 0;
-(void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[mTop10Container release];
[mRendezvousContainer release];
[mAddressBookContainer release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[mLastUsedFolder release];
[mUndoManager release];
[mRootBookmarks release];
[mPathToBookmarkFile release];
[mSmartFolderManager release];
if (mImportDlgController)
[mImportDlgController release];
if (self == gBookmarksManager)
gBookmarksManager = nil;
[super dealloc];
}
@ -363,6 +369,17 @@ static unsigned gFirstUserCollection = 0;
return mAddressBookContainer;
}
- (BookmarkFolder*)lastUsedBookmarkFolder
{
return mLastUsedFolder;
}
- (void)setLastUsedBookmarkFolder:(BookmarkFolder*)inFolder
{
[mLastUsedFolder autorelease];
mLastUsedFolder = [inFolder retain];
}
-(BookmarkItem*) itemWithUUID:(NSString*)uuid
{
return [mRootBookmarks itemWithUUID:uuid];
@ -500,7 +517,7 @@ static unsigned gFirstUserCollection = 0;
[contextMenu addItem:[NSMenuItem separatorItem]];
// create new folder
menuTitle = NSLocalizedString(@"Create New Folder...", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(addFolder:) keyEquivalent:@""] autorelease];
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(addBookmarkFolder:) keyEquivalent:@""] autorelease];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
}
@ -533,6 +550,16 @@ static unsigned gFirstUserCollection = 0;
- (void)bookmarkRemoved:(NSNotification *)note
{
[self bookmarkChanged:nil];
BookmarkItem* bmItem = [[note userInfo] objectForKey:BookmarkFolderChildKey];
if ([bmItem isKindOfClass:[BookmarkFolder class]])
{
if ([(BookmarkFolder*)bmItem containsChildItem:mLastUsedFolder])
{
[mLastUsedFolder release];
mLastUsedFolder = nil;
}
}
}
- (void)bookmarkChanged:(NSNotification *)aNote
@ -638,7 +665,7 @@ static unsigned gFirstUserCollection = 0;
{
NSData* fileAsData = [[NSData alloc] initWithContentsOfFile:pathToFile];
if (!fileAsData) {
NSLog(@"decodedTextFile: file %@ cannot be read.",pathToFile);
NSLog(@"decodedTextFile: file %@ cannot be read.", pathToFile);
return nil;
}
// we're gonna assume for now it's ascii and hope for the best.
@ -647,7 +674,7 @@ static unsigned gFirstUserCollection = 0;
// know this for sure. but we'll have to do 2 decodings. big whoop.
NSString *fileString = [[NSString alloc] initWithData:fileAsData encoding:NSASCIIStringEncoding];
if (!fileString) {
NSLog(@"decodedTextFile: file %@ doesn't want to become a string. Exiting.",pathToFile);
NSLog(@"decodedTextFile: file %@ doesn't want to become a string. Exiting.", pathToFile);
[fileAsData release];
return nil;
}
@ -683,12 +710,12 @@ static unsigned gFirstUserCollection = 0;
// if we're here, we don't have a clue as to the encoding. we'll guess default
[fileString release];
if ((fileString = [[NSString alloc] initWithData:fileAsData encoding:[NSString defaultCStringEncoding]])) {
NSLog(@"decodedTextFile: file %@ encoding unknown. Assume default and proceed.",pathToFile);
NSLog(@"decodedTextFile: file %@ encoding unknown. Assume default and proceed.", pathToFile);
[fileAsData release];
return [fileString autorelease];
}
// we suck. this is almost certainly wrong, but oh well.
NSLog(@"decodedTextFile: file %@ encoding unknown, and NOT default. Use ASCII and proceed.",pathToFile);
NSLog(@"decodedTextFile: file %@ encoding unknown, and NOT default. Use ASCII and proceed.", pathToFile);
fileString = [[NSString alloc] initWithData:fileAsData encoding:NSASCIIStringEncoding];
[fileAsData release];
return [fileString autorelease];
@ -720,7 +747,7 @@ static unsigned gFirstUserCollection = 0;
// omniweb setup - start at <bookmarkInfo
[fileScanner scanUpToString:@"<bookmarkInfo" intoString:NULL];
else {
NSLog(@"Unrecognized style of Bookmark File. Read fails.");
NSLog(@"Unrecognized style of Bookmark File. Read fails.");
[fileScanner release];
return NO;
}
@ -792,7 +819,7 @@ static unsigned gFirstUserCollection = 0;
[fileScanner scanUpToString:@">" intoString:NULL];
[fileScanner setScanLocation:([fileScanner scanLocation]+1)];
[fileScanner scanUpToString:@"<" intoString:&tokenString];
[currentItem setDescription:[tokenString stringByRemovingAmpEscapes]];
[currentItem setItemDescription:[tokenString stringByRemovingAmpEscapes]];
justSetTitle = NO;
}
else if ([tokenTag isEqualToString:@"<H3"]) {
@ -845,7 +872,7 @@ static unsigned gFirstUserCollection = 0;
if (justSetTitle)
[currentItem setTitle:[[currentItem title] stringByAppendingString:tempItem]];
else
[currentItem setDescription:[[currentItem description] stringByAppendingString:tempItem]];
[currentItem setItemDescription:[[currentItem itemDescription] stringByAppendingString:tempItem]];
[fileScanner setScanLocation:(scanIndex+1)];
}
else if ([tokenTag isEqualToString:@"</H"]) {
@ -859,7 +886,7 @@ static unsigned gFirstUserCollection = 0;
if (justSetTitle)
[currentItem setTitle:[[currentItem title] stringByAppendingString:tempItem]];
else
[currentItem setDescription:[[currentItem description] stringByAppendingString:tempItem]];
[currentItem setItemDescription:[[currentItem itemDescription] stringByAppendingString:tempItem]];
[fileScanner setScanLocation:([fileScanner scanLocation]+1)];
}
[tempItem release];
@ -1016,7 +1043,7 @@ static unsigned gFirstUserCollection = 0;
// ... followed by Description
aRange = [aLine rangeOfString:@"DESCRIPTION="];
if (NSNotFound != aRange.location) {
[currentItem setDescription:[aLine substringFromIndex:(aRange.location + aRange.length)]];
[currentItem setItemDescription:[aLine substringFromIndex:(aRange.location + aRange.length)]];
}
}
}

Просмотреть файл

@ -55,6 +55,7 @@
@class BrowserWindowController;
@class BookmarkOutlineView;
@class BookmarkFolder;
@class BookmarkItem;
@class SearchTextField;
@ -110,6 +111,8 @@
NSArray* mSearchResultArray;
int mOpenActionFlag;
BookmarkItem* mItemToReveal;
HistoryDataSource* mHistoryDataSource;
}
@ -122,9 +125,8 @@
//
-(IBAction) setAsDockMenuFolder:(id)aSender;
-(IBAction) addCollection:(id)aSender;
-(IBAction) addBookmark:(id)aSender;
-(IBAction) addFolder:(id)aSender;
-(IBAction) addSeparator:(id)aSender;
-(IBAction) addBookmarkSeparator:(id)aSender;
-(IBAction) addBookmarkFolder:(id)aSender;
-(IBAction) openBookmark: (id)aSender;
-(IBAction) openBookmarkInNewTab:(id)aSender;
-(IBAction) openBookmarkInNewWindow:(id)aSender;
@ -138,20 +140,17 @@
-(NSView*)bookmarksEditingView;
-(int) containerCount;
-(void) selectContainer:(int)inRowIndex;
-(void) selectLastContainer;
-(NSMutableDictionary *)expandedStatusDictionary;
-(void) restoreFolderExpandedStates;
-(BOOL) isExpanded:(id)anItem;
-(BOOL) haveSelectedRow;
-(int)numberOfSelectedRows;
-(void) setItem:(BookmarkFolder *)anItem isExpanded:(BOOL)aBool;
-(void) setActiveCollection:(BookmarkFolder *)aFolder;
-(BookmarkFolder *)activeCollection;
-(void)addItem:(id)aSender isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle;
-(void)addItem:(id)aSender withParent:(BookmarkFolder *)parent isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle;
-(void)endAddBookmark: (int)aCode;
-(BookmarkFolder *)selectedItemFolderAndIndex:(int*)outIndex;
-(void)revealItem:(BookmarkItem*)item selecting:(BOOL)inSelectItem;
- (void)setItemToRevealOnLoad:(BookmarkItem*)inItem;
-(void)deleteCollection:(id)aSender;
-(void)focus;

Просмотреть файл

@ -20,7 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
* Simon Fraser <smfr@smfr.org>
* Max Horn <max@quendi.de>
* David Haas <haasd@cae.wisc.edu>
* Simon Woodside <sbwoodside@yahoo.com>
@ -51,6 +51,7 @@
#import "BookmarkInfoController.h"
#import "BookmarkFolder.h"
#import "Bookmark.h"
#import "AddBookmarkDialogController.h"
#import "MainController.h"
@ -96,6 +97,7 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
@interface BookmarkViewController (Private) <BookmarksClient, NetworkServicesClient>
- (void)ensureNibLoaded;
- (void)completeSetup;
- (void)setupAppearanceOfTableView:(NSTableView*)tableView;
@ -109,6 +111,8 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
- (void)searchFor:(NSString*)searchString inFieldWithTag:(int)tag;
- (void)clearSearchResults;
- (void)selectContainer:(int)inRowIndex;
- (void)selectItems:(NSArray*)items expandingContainers:(BOOL)expandContainers scrollIntoView:(BOOL)scroll;
- (void)selectItem:(BookmarkItem*)item expandingContainers:(BOOL)expandContainers scrollIntoView:(BOOL)scroll byExtendingSelection:(BOOL)extendSelection;
@ -117,6 +121,14 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
- (NSOutlineView*)activeOutlineView; // return the outline view of the visible tab
- (void)setActiveOutlineView:(NSOutlineView*)outlineView;
- (NSMutableDictionary *)expandedStateDictionary;
- (void)restoreFolderExpandedStates;
- (BOOL)hasExpandedState:(id)anItem;
- (void)setStateOfItem:(BookmarkFolder *)anItem toExpanded:(BOOL)aBool;
- (void)expandAllParentsOfItem:(BookmarkItem*)inItem;
- (void)actionButtonWillDisplay:(NSNotification *)notification;
- (NSDragOperation)preferredDragOperationForSourceMask:(NSDragOperation)srcMask;
@ -146,8 +158,8 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
// wait for |-completeSetup| to be called to lazily complete our setup
mSetupComplete = NO;
// load our nib (maybe we can delay this until we actually need to show UI?)
[NSBundle loadNibNamed:@"BookmarksEditing" owner:self];
// we'll delay loading the nib until we need to show UI
// (important because we get created for every new tab)
}
return self;
}
@ -160,18 +172,36 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
[[NSNotificationCenter defaultCenter] removeObserver:self];
// make sure its dealloc is called to unregister from notifications.
// balance the extra retains
[mBookmarksHostView release];
[mHistoryHostView release];
// release the views
// Note: we have to be careful only to release top-level items in the nib,
// not any random subview we might have an outlet to.
[mBookmarksEditingView release];
[mBookmarksHostView release];
[mHistoryHostView release];
[mActionMenuBookmarks release];
[mActionMenuHistory release];
[mSortMenuBookmarks release];
[mSortMenuHistory release];
[mQuickSearchMenuBookmarks release];
[mQuickSearchMenuHistory release];
[mHistoryOutlineViewDelegate release];
// release data
[mItemToReveal release];
[mCachedHref release];
[mExpandedStatus release];
[mActiveRootCollection release];
[mRootBookmarks release];
[mSearchResultArray release];
[mBookmarksHostView release];
[mHistoryHostView release];
[mHistoryDataSource release];
[super dealloc];
@ -199,6 +229,12 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
[self ensureBookmarks];
}
- (void)ensureNibLoaded
{
if (!mBookmarksEditingView)
[NSBundle loadNibNamed:@"BookmarksEditing" owner:self];
}
- (void)completeSetup
{
// set up the table appearance for item and search views
@ -334,16 +370,6 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
}
}
-(IBAction)addBookmark:(id)aSender
{
[self addItem: aSender isFolder: NO URL:nil title:nil];
}
-(IBAction)addFolder:(id)aSender
{
[self addItem: aSender isFolder: YES URL:nil title:nil];
}
-(IBAction)addCollection:(id)aSender
{
BookmarkFolder *aFolder = [mRootBookmarks addBookmarkFolder];
@ -353,195 +379,29 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
[mContainersTableView editColumn:0 row:index withEvent:nil select:YES];
}
-(IBAction)addSeparator:(id)aSender
-(IBAction)addBookmarkSeparator:(id)aSender
{
Bookmark *aBookmark = [[Bookmark alloc] init];
[aBookmark setIsSeparator:YES];
BookmarkFolder *parentFolder = nil;
unsigned int index = 0;
if ([mBookmarksOutlineView numberOfSelectedRows] == 1)
{
int row = [mBookmarksOutlineView selectedRow];
BookmarkItem *item = [mBookmarksOutlineView itemAtRow:row];
if ([item respondsToSelector:@selector(parent)])
{
parentFolder = [item parent];
index = [parentFolder indexOfObject:item] + 1;
}
}
if (!parentFolder) {
parentFolder = [self activeCollection];
index = [parentFolder count];
}
int index;
BookmarkFolder *parentFolder = [self selectedItemFolderAndIndex:&index];
[parentFolder insertChild:aBookmark atIndex:index isMove:NO];
[self selectItem:aBookmark expandingContainers:YES scrollIntoView:YES byExtendingSelection:NO];
[aBookmark release];
}
-(void)addItem:(id)aSender isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle
-(IBAction)addBookmarkFolder:(id)aSender
{
// We ALWAYS use the selected item to determine the parent.
BookmarkFolder *parentFolder = nil;
BookmarkItem* item = nil;
if ([mBookmarksOutlineView numberOfSelectedRows] == 1)
{
// There is only one selected row. If it is a folder, use it as our parent.
// Otherwise, use selected row's parent.
int index = [mBookmarksOutlineView selectedRow];
item = [mBookmarksOutlineView itemAtRow: index];
if ([item isKindOfClass:[BookmarkFolder class]])
parentFolder = item;
else if ([item respondsToSelector:@selector(parent)]) // history items have no parent, for example
parentFolder = [item parent];
}
else
{
parentFolder = [self activeCollection];
}
AddBookmarkDialogController* addBookmarkController = [AddBookmarkDialogController sharedAddBookmarkDialogController];
[self addItem:aSender withParent:parentFolder isFolder:aIsFolder URL:aURL title:aTitle];
}
int itemIndex;
BookmarkFolder* parentFolder = [self selectedItemFolderAndIndex:&itemIndex];
[addBookmarkController setDefaultParentFolder:parentFolder];
[addBookmarkController setBookmarkViewController:self];
-(void)addItem:(id)aSender withParent:(BookmarkFolder*)parent isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle
{
NSString* titleString = aTitle;
NSString* urlString = aURL;
if (!aIsFolder)
{
// If no URL and title were specified, get them from the current page.
if (!aURL || !aTitle)
[[mBrowserWindowController getBrowserWrapper] getTitle:&titleString andHref:&urlString];
mCachedHref = [NSString stringWithString:urlString];
[mCachedHref retain];
} else { // Folder
mCachedHref = nil;
titleString = NSLocalizedString(@"NewBookmarkFolder", @"");
}
NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
NSString* bookmarkTitle = titleString;
NSString* cleanedTitle = [bookmarkTitle stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "];
if (!cleanedTitle)
cleanedTitle = urlString;
[textField setStringValue: cleanedTitle];
// XXX this is all rather ugly; why does it have to talk to the BWC? We should make
// the add dialog window have its own controller.
[mBrowserWindowController cacheBookmarkVC: self];
// Show/hide the bookmark all tabs checkbox as appropriate.
NSTabView* tabView = [mBrowserWindowController getTabBrowser];
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
BOOL hasSuperview = [checkbox superview] != nil;
if (aIsFolder && hasSuperview) {
// Just don't show it at all.
[checkbox removeFromSuperview];
[checkbox retain];
}
else if (!aIsFolder && !hasSuperview) {
// Put it back in.
[[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox];
[checkbox autorelease];
}
// Enable the bookmark all tabs checkbox if appropriate.
if (!aIsFolder)
[[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)];
// Build up the folder list.
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
[popup removeAllItems];
[mRootBookmarks buildFlatFolderList:[popup menu] depth:1];
int itemIndex = [popup indexOfItemWithRepresentedObject:parent];
if (itemIndex != -1)
[popup selectItemAtIndex:itemIndex];
[popup synchronizeTitleAndSelectedItem];
[NSApp beginSheet: [mBrowserWindowController getAddBookmarkSheetWindow]
modalForWindow: [mBrowserWindowController window]
modalDelegate: nil //self
didEndSelector: nil //@selector(sheetDidEnd:)
contextInfo: nil];
}
-(void)endAddBookmark: (int)aCode
{
if (aCode == 0)
return;
BOOL isGroup = NO;
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState))
{
[mCachedHref release];
mCachedHref = nil;
isGroup = YES;
}
NSString* titleString = [[mBrowserWindowController getAddBookmarkTitle] stringValue];
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
NSMenuItem* selectedItem = [popup selectedItem];
BookmarkFolder* parentFolder = [selectedItem representedObject];
BookmarkItem* newBM = nil;
if (isGroup)
{
BookmarkFolder* newGroup = [parentFolder addBookmarkFolder:titleString inPosition:[parentFolder count] isGroup:YES];
id tabBrowser = [mBrowserWindowController getTabBrowser];
int count = [tabBrowser numberOfTabViewItems];
for (int i = 0; i < count; i++)
{
BrowserWrapper* browserWrapper = (BrowserWrapper*)[[tabBrowser tabViewItemAtIndex: i] view];
NSString* curTitleString = nil;
NSString* hrefString = nil;
[browserWrapper getTitle:&curTitleString andHref:&hrefString];
newBM = [newGroup addBookmark:curTitleString url:hrefString inPosition:i isSeparator:NO];
}
}
else
{
if (mCachedHref)
{
newBM = [parentFolder addBookmark:titleString url:mCachedHref inPosition:[parentFolder count] isSeparator:NO];
[mCachedHref release];
mCachedHref = nil;
}
else
{
newBM = [parentFolder addBookmarkFolder:titleString inPosition:[parentFolder count] isGroup:NO];
}
}
// if (!newBM)
// [self selectItem:newBM expandingContainers:YES scrollInfoView:YES byExtendingSelection:NO];
// if we're NOT visible, set the selection to this bookmark's new parent folder
// to ensure a selection exists. The next time we use the UI to add a bookmark, it will
// use this parent as the suggested location in the UI. If the parent is a top-level
// container (bookmark menu, toolbar bookmarks, etc), clear the item panel's selection entirely,
// which will fall back to checking the selected container panel's selection. If
// the manager is visible, don't muck with the selection.
if (![mBrowserWindowController bookmarkManagerIsVisible])
{
[self displayBookmarkInOutlineView:parentFolder];
long parentRow = [mBookmarksOutlineView rowForItem:parentFolder]; // will be -1 if top-level container
if (parentRow >= 0)
[mBookmarksOutlineView selectRow:parentRow byExtendingSelection:NO];
else {
// clear selection, next 'add bookmark' will subsequently use the container
// panel's selection.
NSEnumerator* iter = [mBookmarksOutlineView selectedRowEnumerator];
NSNumber* row = nil;
while ( (row = [iter nextObject]) )
[mBookmarksOutlineView deselectRow:[row intValue]];
}
}
[addBookmarkController showDialogWithLocationsAndTitles:nil isFolder:YES onWindow:[mBookmarksEditingView window]];
}
-(IBAction)deleteCollection:(id)aSender
@ -802,24 +662,94 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
return mActiveRootCollection;
}
- (BOOL)isExpanded:(id)anItem
-(BookmarkFolder *)selectedItemFolderAndIndex:(int*)outIndex
{
NSMutableDictionary *dict = [self expandedStatusDictionary];
NSNumber *aBool = [dict objectForKey:[NSNumber numberWithUnsignedInt:[anItem hash]]];
if (aBool)
return [aBool boolValue];
return NO;
BookmarkFolder *parentFolder = nil;
*outIndex = 0;
if ([mBookmarksOutlineView numberOfSelectedRows] == 1)
{
int row = [mBookmarksOutlineView selectedRow];
BookmarkItem *item = [mBookmarksOutlineView itemAtRow:row];
if ([item respondsToSelector:@selector(parent)]) // when would it not?
{
parentFolder = [item parent];
*outIndex = [parentFolder indexOfObject:item] + 1;
}
}
if (!parentFolder)
{
parentFolder = [self activeCollection];
*outIndex = [parentFolder count];
}
return parentFolder;
}
-(BOOL) isExpandedInView:(NSOutlineView *)aView
- (void)setItemToRevealOnLoad:(BookmarkItem*)inItem
{
return NO;
[mItemToReveal autorelease];
mItemToReveal = [inItem retain];
}
-(void) setItem:(BookmarkFolder *)anItem isExpanded:(BOOL)aBool
-(void)revealItem:(BookmarkItem*)item selecting:(BOOL)inSelectItem
{
NSMutableDictionary *dict = [self expandedStatusDictionary];
[dict setObject:[NSNumber numberWithBool:aBool] forKey:[NSNumber numberWithUnsignedInt:[anItem hash]]];
BookmarkManager* bmManager = [BookmarkManager sharedBookmarkManager];
if ([item hasAncestor:[bmManager bookmarkMenuFolder]])
[self selectContainer:kBookmarkMenuContainerIndex];
else if ([item hasAncestor:[bmManager toolbarFolder]])
[self selectContainer:kToolbarContainerIndex];
else if ([item parent] == [bmManager rootBookmarks])
{
int itemRow = [[bmManager rootBookmarks] indexOfObject:item];
[mContainersTableView selectRow:itemRow byExtendingSelection:NO];
return;
}
[self expandAllParentsOfItem:item];
int itemRow = [mBookmarksOutlineView rowForItem:item];
if (itemRow == -1) return;
if (inSelectItem)
[mBookmarksOutlineView selectRow:itemRow byExtendingSelection:NO];
[mBookmarksOutlineView scrollRowToVisible:itemRow];
}
- (void)expandAllParentsOfItem:(BookmarkItem*)inItem
{
// make an array of parents
NSMutableArray* parentArray = [[NSMutableArray alloc] initWithCapacity:10];
id curItem = [inItem parent];
while (curItem)
{
if (![curItem respondsToSelector:@selector(parent)])
break;
[parentArray addObject:curItem];
curItem = [curItem parent];
}
// now expand from the top down (as required by the outline view)
NSEnumerator* parentsEnum = [parentArray reverseObjectEnumerator];
while ((curItem = [parentsEnum nextObject]))
[mBookmarksOutlineView expandItem:curItem];
[parentArray release];
}
- (BOOL)hasExpandedState:(id)anItem
{
NSMutableDictionary *dict = [self expandedStateDictionary];
return [[dict objectForKey:[anItem UUID]] boolValue];
}
- (void)setStateOfItem:(BookmarkFolder *)anItem toExpanded:(BOOL)aBool
{
NSMutableDictionary *dict = [self expandedStateDictionary];
[dict setObject:[NSNumber numberWithBool:aBool] forKey:[anItem UUID]];
}
- (void)restoreFolderExpandedStates
@ -830,7 +760,7 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
id item = [mBookmarksOutlineView itemAtRow:curRow];
if ([item isKindOfClass:[BookmarkFolder class]])
{
if ([self isExpanded:item])
if ([self hasExpandedState:item])
[mBookmarksOutlineView expandItem: item];
else
[mBookmarksOutlineView collapseItem: item];
@ -839,11 +769,10 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
}
}
-(NSMutableDictionary *)expandedStatusDictionary
- (NSMutableDictionary *)expandedStateDictionary
{
if (mExpandedStatus)
return mExpandedStatus;
mExpandedStatus = [[NSMutableDictionary alloc] initWithCapacity:20];
if (!mExpandedStatus)
mExpandedStatus = [[NSMutableDictionary alloc] initWithCapacity:20];
return mExpandedStatus;
}
@ -1166,16 +1095,23 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
-(NSMenu *)tableView:(NSTableView *)aTableView contextMenuForRow:(int)rowIndex
{
if (aTableView == mContainersTableView) {
if (aTableView == mContainersTableView)
{
NSMenu *contextMenu = [[[aTableView menu] copy] autorelease];
if ([aTableView numberOfSelectedRows] > 0) {
if ([aTableView numberOfSelectedRows] > 0)
{
[contextMenu addItem:[NSMenuItem separatorItem]];
NSMenuItem *useAsDockItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Use as Dock Menu", @"Use as Dock Menu") action:@selector(setAsDockMenuFolder:) keyEquivalent:[NSString string]];
NSMenuItem *useAsDockItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Use as Dock Menu", @"Use as Dock Menu")
action:@selector(setAsDockMenuFolder:)
keyEquivalent:[NSString string]];
[useAsDockItem setTarget:self];
[contextMenu addItem:useAsDockItem];
[useAsDockItem release];
if (rowIndex >= (int)[[BookmarkManager sharedBookmarkManager] firstUserCollection]) {
NSMenuItem *deleteItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Delete", @"Delete") action:@selector(deleteCollection:) keyEquivalent:[NSString string]];
if (rowIndex >= (int)[[BookmarkManager sharedBookmarkManager] firstUserCollection])
{
NSMenuItem *deleteItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Delete", @"Delete")
action:@selector(deleteCollection:)
keyEquivalent:[NSString string]];
[deleteItem setTarget:self];
[contextMenu addItem:deleteItem];
[deleteItem release];
@ -1325,14 +1261,14 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item
{
if ([item isKindOfClass:[Bookmark class]]) {
if ([[item description] length] > 0)
return [NSString stringWithFormat:@"%@\n%@",[item url], [item description]];
if ([[item itemDescription] length] > 0)
return [NSString stringWithFormat:@"%@\n%@",[item url], [item itemDescription]];
else
return [item url];
}
else if ([item isKindOfClass:[BookmarkFolder class]]) {
if ([[item description] length] > 0)
return [item description];
if ([[item itemDescription] length] > 0)
return [item itemDescription];
else
return [item title];
}
@ -1387,7 +1323,7 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
if ([self activeOutlineView] == mBookmarksOutlineView)
{
if (action == @selector(addSeparator:))
if (action == @selector(addBookmarkSeparator:))
{
BookmarkFolder *activeCollection = [self activeCollection];
return (![activeCollection isRoot] && ![activeCollection isSmartFolder]);
@ -1418,7 +1354,7 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
if (action == @selector(addFolder:))
return NO;
if (action == @selector(addSeparator:))
if (action == @selector(addBookmarkSeparator:))
return NO;
}
@ -1466,17 +1402,18 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
return YES;
}
*/
*/
- (void)outlineViewItemDidExpand:(NSNotification *)notification
{
id item = [[notification userInfo] objectForKey:@"NSObject"];
[self setItem:item isExpanded:YES];
[self setStateOfItem:item toExpanded:YES];
}
- (void)outlineViewItemDidCollapse:(NSNotification *)notification
{
id item = [[notification userInfo] objectForKey:@"NSObject"];
[self setItem:item isExpanded:NO];
[self setStateOfItem:item toExpanded:NO];
}
#pragma mark -
@ -1541,6 +1478,7 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
}
}
// share code with revealItem:selecting:
- (void)selectItem:(BookmarkItem*)item expandingContainers:(BOOL)expandContainers scrollIntoView:(BOOL)scroll byExtendingSelection:(BOOL)extendSelection
{
int itemRow = [mBookmarksOutlineView rowForItem:item];
@ -1661,28 +1599,41 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
//
- (void)bookmarkAdded:(NSNotification *)note
{
BookmarkFolder *aFolder = [note object];
if ((aFolder == [[BookmarkManager sharedBookmarkManager] rootBookmarks]))
BookmarkItem* addedItem = [note object];
if ((addedItem == [[BookmarkManager sharedBookmarkManager] rootBookmarks]))
{
[mContainersTableView reloadData];
BookmarkFolder *updatedFolder = [[note userInfo] objectForKey:BookmarkFolderChildKey];
[self selectContainer:[aFolder indexOfObjectIdenticalTo:updatedFolder]];
[self selectContainer:[(BookmarkFolder*)addedItem indexOfObjectIdenticalTo:updatedFolder]];
return;
}
else if (aFolder == mActiveRootCollection)
aFolder = nil;
[self reloadDataForItem:aFolder reloadChildren:YES];
if (addedItem == mActiveRootCollection)
addedItem = nil;
[self reloadDataForItem:addedItem reloadChildren:YES];
}
- (void)bookmarkRemoved:(NSNotification *)note
{
BookmarkFolder *aFolder = [note object];
if ((aFolder == [[BookmarkManager sharedBookmarkManager] rootBookmarks])) {
BookmarkItem* removedItem = [note object];
if (removedItem == mItemToReveal)
{
[mItemToReveal autorelease];
mItemToReveal = nil;
}
if ((removedItem == [[BookmarkManager sharedBookmarkManager] rootBookmarks]))
{
[mContainersTableView reloadData];
return;
} else if (aFolder == mActiveRootCollection)
aFolder = nil;
[self reloadDataForItem:aFolder reloadChildren:YES];
}
if (removedItem == mActiveRootCollection)
removedItem = nil;
[self reloadDataForItem:removedItem reloadChildren:YES];
}
- (void)bookmarkChanged:(NSNotification *)note
@ -1718,12 +1669,22 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
- (NSView*)provideContentViewForURL:(NSString*)inURL
{
[self ensureNibLoaded];
if ([[inURL lowercaseString] isEqualToString:@"about:history"])
[self selectContainer:kHistoryContainerIndex];
else
[self selectContainer:kBookmarkMenuContainerIndex];
if (mItemToReveal)
{
[self revealItem:mItemToReveal selecting:YES];
[mItemToReveal release];
mItemToReveal = nil;
}
return mBookmarksEditingView;
}
@end

Просмотреть файл

@ -111,10 +111,6 @@ typedef enum
IBOutlet BrowserContentView* mContentView;
IBOutlet BookmarkToolbar* mPersonalToolbar;
IBOutlet NSWindow* mAddBookmarkSheetWindow;
IBOutlet NSTextField* mAddBookmarkTitleField;
IBOutlet NSPopUpButton* mAddBookmarkFolderField;
IBOutlet NSButton* mAddBookmarkCheckbox;
IBOutlet SearchTextField* mSearchBar;
IBOutlet SearchTextField* mSearchSheetTextField;
@ -162,9 +158,6 @@ typedef enum
nsIDOMEvent* mContextMenuEvent;
nsIDOMNode* mContextMenuNode;
// Cached bookmark ds used when adding through a sheet
BookmarkViewController* mCachedBMVC;
// Throbber state variables.
ThrobberHandler* mThrobberHandler;
NSArray* mThrobberImages;
@ -215,11 +208,6 @@ typedef enum
- (IBAction)endSearchSheet:(id)sender;
- (IBAction)cancelSearchSheet:(id)sender;
- (IBAction)cancelAddBookmarkSheet:(id)sender;
- (IBAction)endAddBookmarkSheet:(id)sender;
- (void)cacheBookmarkVC:(BookmarkViewController *)aDS;
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize;
- (IBAction)viewSource:(id)aSender; // focussed frame or page
@ -246,7 +234,6 @@ typedef enum
- (BOOL)shouldShowBookmarkToolbar;
- (void)addBookmarkExtended: (BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle;
- (IBAction)manageBookmarks: (id)aSender;
- (IBAction)manageHistory: (id)aSender;
@ -297,11 +284,6 @@ typedef enum
-(void)setChromeMask:(unsigned int)aMask;
-(unsigned int)chromeMask;
-(id)getAddBookmarkSheetWindow;
-(id)getAddBookmarkTitle;
-(id)getAddBookmarkFolder;
-(id)getAddBookmarkCheckbox;
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
- (void)prepareAddToAddressBookMenuItem:(NSMenuItem*)addToAddressBookItem address:(NSString*)emailAddress;
@ -323,8 +305,10 @@ typedef enum
- (IBAction)viewOnlyThisImage:(id)aSender;
- (IBAction)bookmarkPage: (id)aSender;
- (IBAction)bookmarkLink: (id)aSender;
- (IBAction)addBookmark:(id)aSender;
- (IBAction)addBookmarkForLink:(id)aSender;
- (IBAction)addBookmarkFolder:(id)aSender;
- (IBAction)addBookmarkSeparator:(id)aSender;
- (IBAction)copyLinkLocation:(id)aSender;
- (IBAction)copyImage:(id)sender;

Просмотреть файл

@ -46,6 +46,7 @@
#import "BookmarkToolbar.h"
#import "BookmarkViewController.h"
#import "BookmarkManager.h"
#import "AddBookmarkDialogController.h"
#import "ProgressDlgController.h"
#import "BrowserContentViews.h"
@ -358,6 +359,7 @@ enum BWCOpenDest {
- (void)goToLocationFromToolbarURLField:(AutoCompleteTextField *)inURLField inView:(BWCOpenDest)inDest inBackground:(BOOL)inLoadInBG;
- (BookmarkViewController*)bookmarkViewControllerForCurrentTab;
- (void)bookmarkableTitle:(NSString **)outTitle URL:(NSString**)outURLString forWrapper:(BrowserWrapper*)inWrapper;
// create back/forward session history menus on toolbar button
- (IBAction)backMenu:(id)inSender;
@ -1170,7 +1172,7 @@ enum BWCOpenDest {
return enable;
}
else if (action == @selector(reload:))
return [mBrowserView isBusy] == NO;
return (![mBrowserView isBusy] && ![self bookmarkManagerIsVisible]);
else if (action == @selector(stop:))
return [mBrowserView isBusy];
else if (action == @selector(bookmarkPage:))
@ -1339,6 +1341,56 @@ enum BWCOpenDest {
return nil;
}
// this gets the previous entry in session history if bookmarks are showing
- (void)bookmarkableTitle:(NSString **)outTitle URL:(NSString**)outURLString forWrapper:(BrowserWrapper*)inWrapper
{
*outTitle = nil;
*outURLString = nil;
NSString* curTitle = nil;
NSString* curURL = nil;
[inWrapper getTitle:&curTitle andHref:&curURL];
// if we're currently showing history or bookmarks, hand back the last URL.
if ([[curURL lowercaseString] isEqualToString:@"about:bookmarks"] ||
[[curURL lowercaseString] isEqualToString:@"about:history"])
{
nsCOMPtr<nsIWebBrowser> webBrowser = getter_AddRefs([[inWrapper getBrowserView] getWebBrowser]);
if (webBrowser)
{
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(webBrowser));
nsCOMPtr<nsISHistory> sessionHistory;
webNav->GetSessionHistory(getter_AddRefs(sessionHistory));
if (sessionHistory)
{
PRInt32 curEntryIndex;
sessionHistory->GetIndex(&curEntryIndex);
if (curEntryIndex > 0)
{
nsCOMPtr<nsIHistoryEntry> entry;
sessionHistory->GetEntryAtIndex(curEntryIndex - 1, PR_FALSE, getter_AddRefs(entry));
nsCAutoString uriSpec;
nsCOMPtr<nsIURI> entryURI;
entry->GetURI(getter_AddRefs(entryURI));
if (entryURI)
entryURI->GetSpec(uriSpec);
nsXPIDLString textStr;
entry->GetTitle(getter_Copies(textStr));
curTitle = [NSString stringWith_nsAString:textStr];
curURL = [NSString stringWithUTF8String:uriSpec.get()];
}
}
}
}
*outTitle = curTitle;
*outURLString = curURL;
}
- (void)performAppropriateLocationAction
{
NSToolbar *toolbar = [[self window] toolbar];
@ -1443,25 +1495,6 @@ enum BWCOpenDest {
[NSApp endSheet:mSearchSheetWindow returnCode:0];
}
-(IBAction)cancelAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMVC endAddBookmark: 0];
}
-(IBAction)endAddBookmarkSheet:(id)sender
{
[mAddBookmarkSheetWindow orderOut:self];
[NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
[mCachedBMVC endAddBookmark: 1];
}
- (void)cacheBookmarkVC:(BookmarkViewController *)aVC
{
mCachedBMVC = aVC;
}
//
// - manageBookmarks:
//
@ -1841,14 +1874,6 @@ enum BWCOpenDest {
return [[mBrowserView getBrowserView] lastFindText];
}
- (void)addBookmarkExtended:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle
{
// XXX this should be changed so that we don't need a BookmarksViewController
BookmarkViewController* bookmarksController = [self bookmarkViewControllerForCurrentTab];
[bookmarksController ensureBookmarks];
[bookmarksController addItem: self isFolder: aIsFolder URL:aURL title:aTitle];
}
- (BOOL)bookmarkManagerIsVisible
{
NSString* currentURL = [[[self getBrowserWrapper] getCurrentURLSpec] lowercaseString];
@ -1869,13 +1894,28 @@ enum BWCOpenDest {
return ([bookmarksController numberOfSelectedRows] == 1);
}
- (IBAction)bookmarkPage: (id)aSender
- (IBAction)addBookmark:(id)aSender
{
[self addBookmarkExtended:NO URL:nil title:nil];
int numTabs = [mTabBrowser numberOfTabViewItems];
NSMutableArray* itemsArray = [NSMutableArray arrayWithCapacity:numTabs];
for (int i = 0; i < numTabs; i++)
{
BrowserWrapper* browserWrapper = (BrowserWrapper*)[[mTabBrowser tabViewItemAtIndex:i] view];
NSString* curTitleString = nil;
NSString* hrefString = nil;
[self bookmarkableTitle:&curTitleString URL:&hrefString forWrapper:browserWrapper];
NSDictionary* itemInfo = [NSDictionary dictionaryWithObjectsAndKeys:
curTitleString, kAddBookmarkItemTitleKey,
hrefString, kAddBookmarkItemURLKey,
nil];
[itemsArray addObject:itemInfo];
}
[[AddBookmarkDialogController sharedAddBookmarkDialogController] showDialogWithLocationsAndTitles:itemsArray isFolder:NO onWindow:[self window]];
}
- (IBAction)bookmarkLink: (id)aSender
- (IBAction)addBookmarkForLink:(id)aSender
{
nsCOMPtr<nsIDOMElement> linkContent;
nsAutoString href;
@ -1884,7 +1924,32 @@ enum BWCOpenDest {
GeckoUtils::GatherTextUnder(linkContent, linkText);
NSString* urlStr = [NSString stringWith_nsAString:href];
NSString* titleStr = [NSString stringWith_nsAString:linkText];
[self addBookmarkExtended:NO URL:urlStr title:titleStr];
NSDictionary* itemInfo = [NSDictionary dictionaryWithObjectsAndKeys:
titleStr, kAddBookmarkItemTitleKey,
urlStr, kAddBookmarkItemURLKey,
nil];
NSArray* items = [NSArray arrayWithObject:itemInfo];
[[AddBookmarkDialogController sharedAddBookmarkDialogController] showDialogWithLocationsAndTitles:items isFolder:NO onWindow:[self window]];
}
- (IBAction)addBookmarkFolder:(id)aSender
{
if ([self bookmarkManagerIsVisible])
{
// if the bookmarks view controller is visible, delegate to it (so that it can use the
// selection to set the parent folder)
BookmarkViewController* bookmarksController = [self bookmarkViewControllerForCurrentTab];
[bookmarksController addBookmarkFolder:aSender];
}
[[AddBookmarkDialogController sharedAddBookmarkDialogController] showDialogWithLocationsAndTitles:nil isFolder:YES onWindow:[self window]];
}
- (IBAction)addBookmarkSeparator:(id)aSender
{
BookmarkViewController* bookmarksController = [self bookmarkViewControllerForCurrentTab];
[bookmarksController addBookmarkSeparator:aSender];
}
//
@ -2588,26 +2653,6 @@ enum BWCOpenDest {
return YES;
}
-(id)getAddBookmarkSheetWindow
{
return mAddBookmarkSheetWindow;
}
-(id)getAddBookmarkTitle
{
return mAddBookmarkTitleField;
}
-(id)getAddBookmarkFolder
{
return mAddBookmarkFolderField;
}
-(id)getAddBookmarkCheckbox
{
return mAddBookmarkCheckbox;
}
// Called when a context menu should be shown.
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
{

Просмотреть файл

@ -58,6 +58,7 @@
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIWebBrowser.h"
#include "nsIWebNavigation.h"
#include "nsIWebBrowserSetup.h"
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLDocument.h"

Просмотреть файл

@ -53,6 +53,7 @@ typedef enum
@interface NSString (ChimeraStringUtils)
+ (id)ellipsisString;
+ (NSString*)stringWithUUID;
+ (id)escapedURLString:(NSString *)unescapedString;
+ (NSString*)unescapedURLString:(NSString*)escapedString;
+ (id)stringWithPRUnichars:(const PRUnichar*)inString;

Просмотреть файл

@ -60,6 +60,18 @@
return sEllipsisString;
}
+ (NSString*)stringWithUUID
{
NSString* uuidString = nil;
CFUUIDRef newUUID = CFUUIDCreate(kCFAllocatorDefault);
if (newUUID)
{
uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, newUUID);
CFRelease(newUUID);
}
return [uuidString autorelease];
}
+ (id)escapedURLString:(NSString *)unescapedString
{
NSString *escapedString = (NSString *) CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)unescapedString, NULL, NULL, kCFStringEncodingUTF8);

Просмотреть файл

@ -74,6 +74,7 @@ class nsIHistoryItem;
// a history category item (a folder in the outliner)
@interface HistoryCategoryItem : HistoryItem
{
NSString* mUUIDString; // used to identify folders for outliner state saving
NSString* mTitle;
NSDate* mStartDate;
NSMutableArray* mChildren; // array of HistoryItems (may be heterogeneous)
@ -81,6 +82,7 @@ class nsIHistoryItem;
- (id)initWithTitle:(NSString*)title childCapacity:(int)capacity;
- (NSString*)title;
- (NSString*)identifier; // return UUID for this folder
// start date only valid when grouping by date
- (NSDate*)startDate;
- (void)setStartDate:(NSDate*)date;

Просмотреть файл

@ -169,6 +169,7 @@ enum
{
[mTitle release];
[mChildren release];
[mUUIDString release];
[super dealloc];
}
@ -177,6 +178,13 @@ enum
return mTitle;
}
- (NSString*)identifier
{
if (!mUUIDString)
mUUIDString = [[NSString stringWithUUID] retain];
return mUUIDString;
}
- (NSDate*)startDate
{
return mStartDate;

Просмотреть файл

@ -57,6 +57,8 @@
BrowserWindowController* mBrowserWindowController;
BOOL mUpdatesDisabled;
BOOL mHistoryLoaded;
NSMutableDictionary* mExpandedStates;
}
- (void)setBrowserWindowController:(BrowserWindowController*)bwController;

Просмотреть файл

@ -85,6 +85,12 @@ enum
- (int)tagForSortOrder:(BOOL)sortDescending;
- (NSMutableDictionary *)expandedStateDictionary;
- (BOOL)hasExpandedState:(HistoryItem*)inItem;
- (void)setStateOfItem:(HistoryItem*)inItem toExpanded:(BOOL)inExpanded;
- (void)restoreFolderExpandedStates;
@end
@implementation HistoryOutlineViewDelegate
@ -92,6 +98,9 @@ enum
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[mExpandedStates release];
[super dealloc];
}
@ -133,6 +142,7 @@ enum
mUpdatesDisabled = NO;
[mHistoryOutlineView reloadData];
[self restoreFolderExpandedStates];
[self updateSortMenuState];
}
else
@ -219,6 +229,7 @@ enum
mUpdatesDisabled = NO;
[mHistoryOutlineView reloadData];
[self restoreFolderExpandedStates];
}
@ -338,6 +349,18 @@ enum
return mOutlinerContextMenu;
}
- (void)outlineViewItemDidExpand:(NSNotification *)notification
{
id item = [[notification userInfo] objectForKey:@"NSObject"];
[self setStateOfItem:item toExpanded:YES];
}
- (void)outlineViewItemDidCollapse:(NSNotification *)notification
{
id item = [[notification userInfo] objectForKey:@"NSObject"];
[self setStateOfItem:item toExpanded:NO];
}
#pragma mark -
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
@ -369,7 +392,10 @@ enum
if (rootChangedItem)
[mHistoryOutlineView reloadItem:rootChangedItem reloadChildren:!itemOnlyChanged];
else
{
[mHistoryOutlineView reloadData];
[self restoreFolderExpandedStates];
}
}
- (NSArray*)selectedItems
@ -517,4 +543,42 @@ enum
return (sortDescending) ? kSortDescendingItemTag : kSortAscendingItemTag;
}
#pragma mark -
- (NSMutableDictionary *)expandedStateDictionary
{
if (!mExpandedStates)
mExpandedStates = [[NSMutableDictionary alloc] initWithCapacity:20];
return mExpandedStates;
}
- (BOOL)hasExpandedState:(HistoryItem*)inItem
{
NSMutableDictionary *dict = [self expandedStateDictionary];
return [[dict objectForKey:[inItem identifier]] boolValue];
}
- (void)setStateOfItem:(HistoryItem*)inItem toExpanded:(BOOL)inExpanded
{
NSMutableDictionary *dict = [self expandedStateDictionary];
[dict setObject:[NSNumber numberWithBool:inExpanded] forKey:[inItem identifier]];
}
- (void)restoreFolderExpandedStates
{
int curRow = 0;
while (curRow < [mHistoryOutlineView numberOfRows])
{
id item = [mHistoryOutlineView itemAtRow:curRow];
if ([item isKindOfClass:[HistoryCategoryItem class]])
{
if ([self hasExpandedState:item])
[mHistoryOutlineView expandItem: item];
else
[mHistoryOutlineView collapseItem: item];
}
curRow ++;
}
}
@end

Просмотреть файл

@ -1372,6 +1372,12 @@ nsSimpleGlobalHistory::RemoveMatchingRows(rowMatchCallback aMatchFunc,
if (inNotify)
NotifyObserversItemRemoved(row);
#if 0
nsCAutoString url;
GetRowValue(row, kToken_URLColumn, url);
printf("Removing row %s\n", url.get());
#endif
// Officially cut the row *now*, before notifying any observers:
// that way, any re-entrant calls won't find the row.
err = mTable->CutRow(mEnv, row);