зеркало из https://github.com/mozilla/pjs.git
Adding a Get Info item to the Edit menu, which, for now, only applies to the selected bookmark in the bookmarks sidebar. This is part of bug 155484.
This commit is contained in:
Родитель
02c62b89e1
Коммит
38ed722467
|
@ -1,122 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Appkit/Appkit.h>
|
||||
|
||||
#import "MainController.h"
|
||||
#import "CHBookmarksToolbar.h"
|
||||
#import "CHExtendedOutlineView.h"
|
||||
|
||||
class nsIContent;
|
||||
class BookmarksService;
|
||||
|
||||
@class BookmarkInfoController;
|
||||
|
||||
// data source for the bookmarks sidebar. We make one per browser window.
|
||||
@interface BookmarksDataSource : NSObject
|
||||
{
|
||||
BookmarksService* mBookmarks;
|
||||
|
||||
IBOutlet id mOutlineView;
|
||||
IBOutlet id mBrowserWindowController;
|
||||
IBOutlet id mEditBookmarkButton;
|
||||
IBOutlet id mDeleteBookmarkButton;
|
||||
|
||||
NSString* mCachedHref;
|
||||
}
|
||||
|
||||
-(id) init;
|
||||
-(void) windowClosing;
|
||||
|
||||
-(void) ensureBookmarks;
|
||||
|
||||
-(IBAction)addBookmark:(id)aSender;
|
||||
-(void)endAddBookmark: (int)aCode;
|
||||
|
||||
-(IBAction)deleteBookmarks: (id)aSender;
|
||||
-(void)deleteBookmark: (id)aItem;
|
||||
|
||||
-(IBAction)addFolder:(id)aSender;
|
||||
|
||||
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle;
|
||||
|
||||
-(NSString*)resolveKeyword:(NSString*)aKeyword;
|
||||
|
||||
-(IBAction)openBookmarkInNewTab:(id)aSender;
|
||||
-(IBAction)openBookmarkInNewWindow:(id)aSender;
|
||||
|
||||
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
|
||||
-(IBAction)showBookmarkInfo:(id)aSender;
|
||||
|
||||
// Datasource methods.
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
|
||||
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
|
||||
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
|
||||
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
|
||||
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
|
||||
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
|
||||
|
||||
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
|
||||
|
||||
// Delegate methods
|
||||
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
|
||||
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
|
||||
|
||||
@end
|
||||
|
||||
@interface BookmarkItem : NSObject
|
||||
{
|
||||
nsIContent* mContentNode;
|
||||
NSImage* mSiteIcon;
|
||||
}
|
||||
|
||||
- (nsIContent*)contentNode;
|
||||
- (void)setContentNode: (nsIContent*)aContentNode;
|
||||
- (void)setSiteIcon:(NSImage*)image;
|
||||
- (NSString*)url;
|
||||
- (NSImage*)siteIcon;
|
||||
- (NSNumber*)contentID;
|
||||
- (id)copyWithZone:(NSZone *)aZone;
|
||||
- (BOOL)isFolder;
|
||||
|
||||
@end
|
|
@ -1,923 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import "NSString+Utils.h"
|
||||
|
||||
#import "BookmarksDataSource.h"
|
||||
#import "BookmarkInfoController.h"
|
||||
#import "SiteIconProvider.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsINamespaceManager.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#import "BookmarksService.h"
|
||||
|
||||
@implementation BookmarksDataSource
|
||||
|
||||
-(id) init
|
||||
{
|
||||
if ( (self = [super init]) ) {
|
||||
mBookmarks = nsnull;
|
||||
mCachedHref = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) awakeFromNib
|
||||
{
|
||||
// make sure these are disabled at the start since the outliner
|
||||
// starts off with no selection.
|
||||
[mEditBookmarkButton setEnabled:NO];
|
||||
[mDeleteBookmarkButton setEnabled:NO];
|
||||
}
|
||||
|
||||
-(void) windowClosing
|
||||
{
|
||||
if (mBookmarks) {
|
||||
mBookmarks->RemoveObserver();
|
||||
delete mBookmarks;
|
||||
}
|
||||
}
|
||||
|
||||
-(void) ensureBookmarks
|
||||
{
|
||||
if (mBookmarks)
|
||||
return;
|
||||
|
||||
mBookmarks = new BookmarksService(self);
|
||||
mBookmarks->AddObserver();
|
||||
|
||||
[mOutlineView setTarget: self];
|
||||
[mOutlineView setDoubleAction: @selector(openBookmark:)];
|
||||
[mOutlineView setDeleteAction: @selector(deleteBookmarks:)];
|
||||
[mOutlineView reloadData];
|
||||
}
|
||||
|
||||
-(IBAction)addBookmark:(id)aSender
|
||||
{
|
||||
[self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(IBAction)addFolder:(id)aSender
|
||||
{
|
||||
[self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return;
|
||||
|
||||
// We use the selected item to determine the parent only if aUseSel is YES.
|
||||
BookmarkItem* item = nil;
|
||||
if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) {
|
||||
// There is only one selected row. If it is a folder, use it as our parent.
|
||||
// Otherwise, use our parent,
|
||||
int index = [mOutlineView selectedRow];
|
||||
item = [mOutlineView itemAtRow: index];
|
||||
if (![mOutlineView isExpandable: item]) {
|
||||
// We can't be used as the parent. Try our parent.
|
||||
nsIContent* content = [item contentNode];
|
||||
if (!content)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIContent> parentContent;
|
||||
content->GetParent(*getter_AddRefs(parentContent));
|
||||
nsCOMPtr<nsIContent> root;
|
||||
mBookmarks->GetRootContent(getter_AddRefs(root));
|
||||
|
||||
// The root has no item, so we don't need to do a lookup unless we
|
||||
// aren't the root.
|
||||
if (parentContent != root) {
|
||||
PRUint32 contentID;
|
||||
parentContent->GetContentID(&contentID);
|
||||
item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
|
||||
|
||||
nsAutoString title, href;
|
||||
if (!aIsFolder) {
|
||||
|
||||
// If no URL and title were specified, get them from the current page.
|
||||
if (aURL && aTitle) {
|
||||
[aURL assignTo_nsAString:href];
|
||||
[aTitle assignTo_nsAString:title];
|
||||
} else {
|
||||
BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView],
|
||||
title, href);
|
||||
}
|
||||
|
||||
mCachedHref = [NSString stringWith_nsAString: href];
|
||||
[mCachedHref retain];
|
||||
|
||||
} else { // Folder
|
||||
mCachedHref = nil;
|
||||
title = NS_LITERAL_STRING("New Folder"); // XXX localize me
|
||||
}
|
||||
|
||||
NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
|
||||
NSString* bookmarkTitle = [NSString stringWith_nsAString: title];
|
||||
NSString* cleanedTitle = [bookmarkTitle stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "];
|
||||
|
||||
[textField setStringValue: cleanedTitle];
|
||||
|
||||
[mBrowserWindowController cacheBookmarkDS: 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];
|
||||
BookmarksService::ConstructAddBookmarkFolderList(popup, item);
|
||||
|
||||
[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 = nil;
|
||||
isGroup = YES;
|
||||
}
|
||||
|
||||
nsAutoString title;
|
||||
[[[mBrowserWindowController getAddBookmarkTitle] stringValue] assignTo_nsAString:title];
|
||||
|
||||
nsAutoString tagName;
|
||||
if (mCachedHref)
|
||||
tagName = NS_LITERAL_STRING("bookmark");
|
||||
else
|
||||
tagName = NS_LITERAL_STRING("folder");
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
|
||||
nsCOMPtr<nsIDOMElement> elt;
|
||||
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
|
||||
tagName,
|
||||
getter_AddRefs(elt));
|
||||
|
||||
elt->SetAttribute(NS_LITERAL_STRING("name"), title);
|
||||
|
||||
if (mCachedHref) {
|
||||
nsAutoString href;
|
||||
[mCachedHref assignTo_nsAString:href];
|
||||
[mCachedHref release];
|
||||
elt->SetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
}
|
||||
|
||||
if (isGroup) {
|
||||
// We have to iterate over each tab and create content nodes using the
|
||||
// title/href of all the pages. They are inserted underneath the parent.
|
||||
elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true"));
|
||||
id tabBrowser = [mBrowserWindowController getTabBrowser];
|
||||
int count = [tabBrowser numberOfTabViewItems];
|
||||
for (int i = 0; i < count; i++) {
|
||||
id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView];
|
||||
nsAutoString title, href;
|
||||
BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href);
|
||||
nsCOMPtr<nsIDOMElement> childElt;
|
||||
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
|
||||
NS_LITERAL_STRING("bookmark"),
|
||||
getter_AddRefs(childElt));
|
||||
childElt->SetAttribute(NS_LITERAL_STRING("name"), title);
|
||||
childElt->SetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
elt->AppendChild(childElt, getter_AddRefs(dummy));
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out the parent element.
|
||||
nsCOMPtr<nsIDOMElement> parentElt;
|
||||
nsCOMPtr<nsIContent> parentContent;
|
||||
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
|
||||
NSMenuItem* selectedItem = [popup selectedItem];
|
||||
int tag = [selectedItem tag];
|
||||
if (tag == -1) {
|
||||
mBookmarks->GetRootContent(getter_AddRefs(parentContent));
|
||||
parentElt = do_QueryInterface(parentContent);
|
||||
}
|
||||
else {
|
||||
BookmarkItem* item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: tag]];
|
||||
// Get the content node.
|
||||
parentContent = [item contentNode];
|
||||
parentElt = do_QueryInterface(parentContent);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
parentElt->AppendChild(elt, getter_AddRefs(dummy));
|
||||
|
||||
nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
|
||||
mBookmarks->BookmarkAdded(parentContent, childContent);
|
||||
}
|
||||
|
||||
-(IBAction)deleteBookmarks: (id)aSender
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return;
|
||||
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
// first, see how many items are selected
|
||||
BOOL haveBookmarks = NO;
|
||||
|
||||
NSEnumerator* testSelRows = [mOutlineView selectedRowEnumerator];
|
||||
for (NSNumber* currIndex = [testSelRows nextObject];
|
||||
currIndex != nil;
|
||||
currIndex = [testSelRows nextObject])
|
||||
{
|
||||
index = [currIndex intValue];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
if ([mOutlineView isExpandable: item]) {
|
||||
// dumb check to see if we're deleting an empty folder. Should really
|
||||
// recurse down
|
||||
if ([self outlineView:mOutlineView numberOfChildrenOfItem: item] > 0)
|
||||
haveBookmarks = YES;
|
||||
} else
|
||||
haveBookmarks = YES;
|
||||
}
|
||||
|
||||
// ideally, we should count the number of doomed bookmarks and tell the user
|
||||
if (haveBookmarks) {
|
||||
NSString *alert = NSLocalizedString(@"DeteleBookmarksAlert",@"");
|
||||
NSString *message = NSLocalizedString(@"DeteleBookmarksMsg",@"");
|
||||
NSString *okButton = NSLocalizedString(@"DeteleBookmarksOKButton",@"");
|
||||
NSString *cancelButton = NSLocalizedString(@"DeteleBookmarksCancelButton",@"");
|
||||
if (NSRunAlertPanel(alert, message, okButton, cancelButton, nil) != NSAlertDefaultReturn)
|
||||
return;
|
||||
}
|
||||
|
||||
// The alert panel was the key window. As soon as we dismissed it, Cocoa will
|
||||
// pick a new one for us. Ideally, it'll be the window we were using when
|
||||
// we clicked the delete button. However, if by chance the BookmarkInfoController
|
||||
// is visible, it will become the key window since it's a panel. If we then delete
|
||||
// the bookmark and try to close the window before we've setup a new bookmark,
|
||||
// we'll trigger the windowDidResignKey message, which will try to update the bookmark
|
||||
// we just deleted, and things will crash. So, we'll trigger windowDidResignKey now
|
||||
// and avoid the unpleasentness of a crash log.
|
||||
|
||||
if (![[mBrowserWindowController window] isKeyWindow])
|
||||
[[mBrowserWindowController window] makeKeyWindow];
|
||||
|
||||
// we'll run into problems if a parent item and one if its children are both selected.
|
||||
// A cheap way of having to avoid scanning the list to remove children is to have the
|
||||
// outliner collapse all items that are being deleted. This will cull the selection
|
||||
// for us and eliminate any children that happened to be selected.
|
||||
NSEnumerator* selRows = [mOutlineView selectedRowEnumerator];
|
||||
for (NSNumber* currIndex = [selRows nextObject];
|
||||
currIndex != nil;
|
||||
currIndex = [selRows nextObject]) {
|
||||
index = [currIndex intValue];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
[mOutlineView collapseItem: item];
|
||||
}
|
||||
|
||||
// create array of items we need to delete. Deleting items out of of the
|
||||
// selection array is problematic for some reason.
|
||||
NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease];
|
||||
selRows = [mOutlineView selectedRowEnumerator];
|
||||
for (NSNumber* currIndex = [selRows nextObject];
|
||||
currIndex != nil;
|
||||
currIndex = [selRows nextObject]) {
|
||||
index = [currIndex intValue];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
[itemsToDelete addObject: item];
|
||||
}
|
||||
|
||||
// delete all bookmarks that are in our array
|
||||
int count = [itemsToDelete count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
BookmarkItem* item = [itemsToDelete objectAtIndex: i];
|
||||
[self deleteBookmark: item];
|
||||
}
|
||||
|
||||
// restore selection to location near last item deleted or last item
|
||||
int total = [mOutlineView numberOfRows];
|
||||
if (index >= total)
|
||||
index = total - 1;
|
||||
[mOutlineView selectRow: index byExtendingSelection: NO];
|
||||
// lame, but makes sure we catch all delete events in Info Panel
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"NSOutlineViewSelectionDidChangeNotification" object:mOutlineView];
|
||||
|
||||
}
|
||||
|
||||
-(void)deleteBookmark:(id)aItem
|
||||
{
|
||||
nsCOMPtr<nsIContent> content = [aItem contentNode];
|
||||
nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
|
||||
if (!child)
|
||||
return;
|
||||
if (child == BookmarksService::gToolbarRoot)
|
||||
return; // Don't allow the personal toolbar to be deleted.
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
child->GetParentNode(getter_AddRefs(parent));
|
||||
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parent));
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
if (parent)
|
||||
parent->RemoveChild(child, getter_AddRefs(dummy));
|
||||
mBookmarks->BookmarkRemoved(parentContent, content);
|
||||
}
|
||||
|
||||
-(IBAction)openBookmark: (id)aSender
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
id item = [mOutlineView itemAtRow: index];
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
nsIContent* content = [item contentNode];
|
||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
|
||||
nsAutoString group;
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
|
||||
if (!group.IsEmpty())
|
||||
mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt);
|
||||
else if ([mOutlineView isExpandable: item]) {
|
||||
if ([mOutlineView isItemExpanded: item])
|
||||
[mOutlineView collapseItem: item];
|
||||
else
|
||||
[mOutlineView expandItem: item];
|
||||
}
|
||||
else {
|
||||
nsAutoString href;
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
|
||||
if (!href.IsEmpty()) {
|
||||
NSString* url = [NSString stringWith_nsAString: href];
|
||||
[[mBrowserWindowController getBrowserWrapper] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(NSString*) resolveKeyword: (NSString*) aKeyword
|
||||
{
|
||||
return BookmarksService::ResolveKeyword(aKeyword);
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
//
|
||||
// outlineView:shouldEditTableColumn:item: (delegate method)
|
||||
//
|
||||
// Called by the outliner to determine whether or not we should allow the
|
||||
// user to edit this item. For now, Cocoa doesn't correctly handle editing
|
||||
// of attributed strings with icons, so we can't turn this on. :(
|
||||
//
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return nil;
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
if (!item)
|
||||
BookmarksService::GetRootContent(getter_AddRefs(content));
|
||||
else
|
||||
content = [item contentNode];
|
||||
|
||||
nsCOMPtr<nsIContent> child;
|
||||
content->ChildAt(index, *getter_AddRefs(child));
|
||||
if ( child )
|
||||
return BookmarksService::GetWrapperFor(child);
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return NO;
|
||||
|
||||
if (!item)
|
||||
return YES; // The root node is always open.
|
||||
|
||||
BOOL isExpandable = [item isFolder];
|
||||
|
||||
// XXXben - persistence of folder open state
|
||||
// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's
|
||||
// row count. Currently the items are expanded, but the outline view continues to believe it had
|
||||
// the number of rows it had before the item was opened visible, until the view is resized.
|
||||
#if 0
|
||||
if (isExpandable) {
|
||||
PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom);
|
||||
if (isOpen)
|
||||
[mOutlineView expandItem: item];
|
||||
else
|
||||
[mOutlineView collapseItem: item];
|
||||
}
|
||||
#endif
|
||||
|
||||
return isExpandable;
|
||||
}
|
||||
|
||||
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return 0;
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
if (!item)
|
||||
mBookmarks->GetRootContent(getter_AddRefs(content));
|
||||
else
|
||||
content = [item contentNode];
|
||||
|
||||
PRInt32 childCount;
|
||||
content->ChildCount(childCount);
|
||||
|
||||
return childCount;
|
||||
}
|
||||
|
||||
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
|
||||
{
|
||||
NSString *columnName = [tableColumn identifier];
|
||||
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
|
||||
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
|
||||
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
|
||||
NSMutableAttributedString *attachmentAttrString = nil;
|
||||
NSCell *attachmentAttrStringCell;
|
||||
|
||||
if ([columnName isEqualToString: @"name"]) {
|
||||
nsIContent* content = [item contentNode];
|
||||
nsAutoString nameAttr;
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
|
||||
|
||||
//Set cell's textual contents
|
||||
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWith_nsAString: nameAttr]];
|
||||
|
||||
//Create an attributed string to hold the empty attachment, then release the components.
|
||||
attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain];
|
||||
[textAttachment release];
|
||||
[fileWrapper release];
|
||||
|
||||
//Get the cell of the text attachment.
|
||||
attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell];
|
||||
|
||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
|
||||
NSImage* bookmarkImage = mBookmarks->CreateIconForBookmark(elt);
|
||||
[attachmentAttrStringCell setImage:bookmarkImage];
|
||||
|
||||
//Insert the image
|
||||
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
|
||||
|
||||
//Tweak the baseline to vertically center the text.
|
||||
[cellValue addAttribute:NSBaselineOffsetAttributeName
|
||||
value:[NSNumber numberWithFloat:-3.0]
|
||||
range:NSMakeRange(0, 1)];
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
|
||||
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
|
||||
{
|
||||
#if NOT_USED
|
||||
// ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn
|
||||
// this code back on. We have to remove the attributes from the string in order to correctly
|
||||
// set it in the DOM.
|
||||
|
||||
NSString *columnName = [tableColumn identifier];
|
||||
if ( [columnName isEqualTo:@"name"] ) {
|
||||
// remove the attributes
|
||||
int strLen = [object length];
|
||||
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object];
|
||||
[cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)];
|
||||
[cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)];
|
||||
|
||||
// extract the unicode
|
||||
strLen = [cellValue length];
|
||||
PRUnichar* buffer = new PRUnichar[strLen + 1];
|
||||
buffer[strLen] = '\0';
|
||||
if ( !buffer )
|
||||
return;
|
||||
[cellValue getCharacters: buffer];
|
||||
nsAutoString nameAttr;
|
||||
nameAttr.Adopt(buffer);
|
||||
|
||||
// stash it into the dom.
|
||||
nsIContent* content = [item contentNode];
|
||||
content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE);
|
||||
|
||||
[cellValue release];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return NO;
|
||||
|
||||
#ifdef FILTER_DESCENDANT_ON_DRAG
|
||||
NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items);
|
||||
#else
|
||||
NSArray *toDrag = items;
|
||||
#endif
|
||||
int count = [toDrag count];
|
||||
if (count > 0) {
|
||||
// Create Pasteboard Data
|
||||
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
|
||||
|
||||
if (count == 1) {
|
||||
// if we have just one item, we add some more flavours
|
||||
[pboard declareTypes: [NSArray arrayWithObjects:
|
||||
@"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self];
|
||||
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
|
||||
|
||||
NSString* itemURL = [[toDrag objectAtIndex: 0] url];
|
||||
[pboard setString:itemURL forType: NSStringPboardType];
|
||||
[[NSURL URLWithString:itemURL] writeToPasteboard: pboard];
|
||||
// maybe construct the @"MozURLType" type here also
|
||||
}
|
||||
else {
|
||||
// multiple bookmarks. Array sof strings or NSURLs seem to
|
||||
// confuse receivers. Not sure what the correct way is.
|
||||
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
|
||||
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
|
||||
{
|
||||
NSArray* types = [[info draggingPasteboard] types];
|
||||
|
||||
// if the index is -1, deny the drop
|
||||
if (index == NSOutlineViewDropOnItemIndex)
|
||||
return NSDragOperationNone;
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"]) {
|
||||
NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
|
||||
BookmarkItem* parent;
|
||||
parent = (item) ? item : BookmarksService::GetRootItem();
|
||||
return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone;
|
||||
} else if ([types containsObject: @"MozURLType"]) {
|
||||
return NSDragOperationGeneric;
|
||||
} else if ([types containsObject: NSStringPboardType]) {
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
|
||||
{
|
||||
NSArray *types = [[info draggingPasteboard] types];
|
||||
BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem();
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"])
|
||||
{
|
||||
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
|
||||
return BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
|
||||
}
|
||||
else if ([types containsObject: @"MozURLType"])
|
||||
{
|
||||
NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
|
||||
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
|
||||
return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
|
||||
}
|
||||
else if ([types containsObject: NSStringPboardType])
|
||||
{
|
||||
NSString* draggedText = [[info draggingPasteboard] stringForType:NSStringPboardType];
|
||||
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
|
||||
return BookmarksService::PerformURLDrop(parent, beforeItem, draggedText, draggedText);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item
|
||||
{
|
||||
NSString* descStr = nil;
|
||||
NSString* hrefStr = nil;
|
||||
nsIContent* content = [item contentNode];
|
||||
nsAutoString value;
|
||||
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gDescriptionAtom, value);
|
||||
if (value.Length())
|
||||
descStr = [NSString stringWith_nsAString:value];
|
||||
|
||||
// Only description for folders
|
||||
if ([item isFolder])
|
||||
return descStr;
|
||||
|
||||
// Extract the URL from the item
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, value);
|
||||
if (value.Length())
|
||||
hrefStr = [NSString stringWith_nsAString:value];
|
||||
|
||||
if (!hrefStr)
|
||||
return descStr;
|
||||
else if (!descStr)
|
||||
return hrefStr;
|
||||
|
||||
// Display both URL and description
|
||||
return [NSString stringWithFormat:@"%@\n%@", hrefStr, descStr];
|
||||
}
|
||||
|
||||
/*
|
||||
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item
|
||||
{
|
||||
// TODO - return (custom?) context menu for item here.
|
||||
// Note that according to HIG, there should never be disabled items in
|
||||
// a context menu - instead, items that do not apply should be removed.
|
||||
// We could nicely do that here.
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren
|
||||
{
|
||||
if (!item)
|
||||
[mOutlineView reloadData];
|
||||
else
|
||||
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
|
||||
}
|
||||
|
||||
-(IBAction)openBookmarkInNewTab:(id)aSender
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
if ([mOutlineView numberOfSelectedRows] == 1) {
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return; // Something bad happened if we can't get prefs.
|
||||
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
nsAutoString hrefAttr;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
|
||||
|
||||
// stuff it into the string
|
||||
NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr];
|
||||
|
||||
PRBool loadInBackground;
|
||||
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
|
||||
|
||||
[mBrowserWindowController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction)openBookmarkInNewWindow:(id)aSender
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
if ([mOutlineView numberOfSelectedRows] == 1) {
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return; // Something bad happened if we can't get prefs.
|
||||
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
nsAutoString hrefAttr;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
|
||||
|
||||
// stuff it into the string
|
||||
NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr];
|
||||
|
||||
PRBool loadInBackground;
|
||||
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
|
||||
|
||||
nsAutoString group;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
|
||||
if (group.IsEmpty())
|
||||
[mBrowserWindowController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
|
||||
else {
|
||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
|
||||
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: loadInBackground];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
|
||||
{
|
||||
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
|
||||
}
|
||||
|
||||
-(IBAction)showBookmarkInfo:(id)aSender
|
||||
{
|
||||
BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController];
|
||||
|
||||
int index = [mOutlineView selectedRow];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
[bic setBookmark:item];
|
||||
|
||||
[bic showWindow:bic];
|
||||
}
|
||||
|
||||
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
|
||||
{
|
||||
BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController];
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1) {
|
||||
[mEditBookmarkButton setEnabled:NO];
|
||||
[mDeleteBookmarkButton setEnabled:NO];
|
||||
[bic close];
|
||||
}
|
||||
else {
|
||||
[mEditBookmarkButton setEnabled:YES];
|
||||
[mDeleteBookmarkButton setEnabled:YES];
|
||||
if ([[bic window] isVisible])
|
||||
[bic setBookmark:[mOutlineView itemAtRow:index]];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return NO;
|
||||
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
|
||||
|
||||
nsAutoString group;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
|
||||
BOOL isGroup = !group.IsEmpty();
|
||||
|
||||
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
|
||||
// Bookmarks and Bookmark Groups can be opened in a new window
|
||||
return (isBookmark || isGroup);
|
||||
}
|
||||
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
|
||||
// Only Bookmarks can be opened in new tabs
|
||||
return isBookmark && [mBrowserWindowController newTabsAllowed];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)outlineViewItemWillExpand:(NSNotification *)notification
|
||||
{
|
||||
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
|
||||
[item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE);
|
||||
}
|
||||
|
||||
- (void)outlineViewItemWillCollapse:(NSNotification *)notification
|
||||
{
|
||||
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
|
||||
[item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation BookmarkItem
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
[mSiteIcon release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(nsIContent*)contentNode
|
||||
{
|
||||
return mContentNode;
|
||||
}
|
||||
|
||||
- (NSNumber*)contentID
|
||||
{
|
||||
PRUint32 contentID = 0;
|
||||
mContentNode->GetContentID(&contentID);
|
||||
return [NSNumber numberWithInt: contentID];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
nsCOMPtr<nsIContent> item = [self contentNode];
|
||||
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
|
||||
nsAutoString href;
|
||||
element->GetAttribute(NS_LITERAL_STRING("name"), href);
|
||||
NSString* info = [NSString stringWith_nsAString: href];
|
||||
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
|
||||
}
|
||||
|
||||
- (NSString *)url
|
||||
{
|
||||
nsCOMPtr<nsIContent> item = [self contentNode];
|
||||
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
|
||||
nsAutoString href;
|
||||
element->GetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
return [NSString stringWith_nsAString: href];
|
||||
}
|
||||
|
||||
- (void)setSiteIcon:(NSImage*)image
|
||||
{
|
||||
//NSLog(@"Setting site icon for %@", [self url]);
|
||||
[mSiteIcon autorelease];
|
||||
mSiteIcon = [image retain];
|
||||
}
|
||||
|
||||
- (NSImage*)siteIcon
|
||||
{
|
||||
return mSiteIcon;
|
||||
}
|
||||
|
||||
-(void)setContentNode: (nsIContent*)aContentNode
|
||||
{
|
||||
mContentNode = aContentNode;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)aZone
|
||||
{
|
||||
BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
|
||||
[copy setContentNode: mContentNode];
|
||||
[copy setSiteIcon: mSiteIcon];
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (BOOL)isFolder
|
||||
{
|
||||
nsCOMPtr<nsIAtom> tagName;
|
||||
mContentNode->GetTag(*getter_AddRefs(tagName));
|
||||
|
||||
return (tagName == BookmarksService::gFolderAtom);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 71 632 495 0 0 1280 1002 </string>
|
||||
<string>112 15 632 495 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>124</key>
|
||||
<string>305 659 170 144 0 0 1152 848 </string>
|
||||
<string>345 803 170 144 0 0 1280 1002 </string>
|
||||
<key>160</key>
|
||||
<string>524 326 195 666 0 0 1280 1002 </string>
|
||||
<key>28</key>
|
||||
|
|
Двоичный файл не отображается.
|
@ -196,8 +196,11 @@ class nsIDOMNode;
|
|||
- (void)stopThrobber;
|
||||
- (void)clickThrobber:(id)aSender;
|
||||
|
||||
-(void) biggerTextSize;
|
||||
-(void) smallerTextSize;
|
||||
- (void)biggerTextSize;
|
||||
- (void)smallerTextSize;
|
||||
- (void)getInfo:(id)sender;
|
||||
|
||||
- (BOOL)canGetInfo;
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar;
|
||||
|
||||
|
@ -205,6 +208,7 @@ class nsIDOMNode;
|
|||
- (IBAction)manageBookmarks: (id)aSender;
|
||||
- (void)importBookmarks: (NSString*)aURLSpec;
|
||||
- (IBAction)toggleSidebar:(id)aSender;
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection;
|
||||
|
||||
- (void)newTab:(BOOL)allowHomepage;
|
||||
- (void)closeTab;
|
||||
|
|
|
@ -850,16 +850,23 @@ static NSArray* sToolbarDefaults = nil;
|
|||
BOOL useSel = aIsFromMenu;
|
||||
if (aIsFromMenu) {
|
||||
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
|
||||
if ([mSidebarDrawer state] == NSDrawerClosedState)
|
||||
useSel = NO;
|
||||
else
|
||||
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
|
||||
useSel = NO;
|
||||
useSel = [self bookmarksAreVisible:NO];
|
||||
}
|
||||
|
||||
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle];
|
||||
}
|
||||
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection
|
||||
{
|
||||
// we should really identify the tab by identifier, not index.
|
||||
BOOL bookmarksShowing = ([mSidebarDrawer state] == NSDrawerOpenState) &&
|
||||
([mSidebarTabView tabViewItemAtIndex: 0] == [mSidebarTabView selectedTabViewItem]);
|
||||
|
||||
if (inRequireSelection)
|
||||
bookmarksShowing &= ([mSidebarBookmarksDataSource haveSelectedRow]);
|
||||
|
||||
return bookmarksShowing;
|
||||
}
|
||||
|
||||
- (IBAction)bookmarkPage: (id)aSender
|
||||
{
|
||||
|
@ -1217,6 +1224,17 @@ static NSArray* sToolbarDefaults = nil;
|
|||
markupViewer->SetTextZoom(zoom);
|
||||
}
|
||||
|
||||
- (void)getInfo:(id)sender
|
||||
{
|
||||
[mSidebarBookmarksDataSource ensureBookmarks];
|
||||
[mSidebarBookmarksDataSource showBookmarkInfo:sender];
|
||||
}
|
||||
|
||||
- (BOOL)canGetInfo
|
||||
{
|
||||
return [self bookmarksAreVisible:YES];
|
||||
}
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar
|
||||
{
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 71 632 495 0 0 1280 1002 </string>
|
||||
<string>112 15 632 495 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>124</key>
|
||||
<string>305 659 170 144 0 0 1152 848 </string>
|
||||
<string>345 803 170 144 0 0 1280 1002 </string>
|
||||
<key>160</key>
|
||||
<string>524 326 195 666 0 0 1280 1002 </string>
|
||||
<key>28</key>
|
||||
|
|
Двоичный файл не отображается.
|
@ -21,6 +21,7 @@
|
|||
feedbackLink = id;
|
||||
findAgain = id;
|
||||
findInPage = id;
|
||||
getInfo = id;
|
||||
goBack = id;
|
||||
goForward = id;
|
||||
goHome = id;
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 23 477 485 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>266</key>
|
||||
<string>483 623 277 90 0 0 1280 1002 </string>
|
||||
<key>29</key>
|
||||
<string>8 957 446 44 0 0 1280 1002 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>248.0</string>
|
||||
<key>IBGroupedObjects</key>
|
||||
<dict>
|
||||
<key>0</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
<key>1</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
</dict>
|
||||
<key>IBLastGroupID</key>
|
||||
<string>2</string>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5S66</string>
|
||||
</dict>
|
||||
</plist>
|
Двоичный файл не отображается.
|
@ -1,157 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "BrowserWindowController.h"
|
||||
#import "MVPreferencesController.h"
|
||||
#import "CHSplashScreenWindow.h"
|
||||
#import "FindDlgController.h"
|
||||
#import "CHPreferenceManager.h"
|
||||
|
||||
class BookmarksService;
|
||||
|
||||
@interface MainController : NSObject
|
||||
{
|
||||
IBOutlet NSApplication* mApplication;
|
||||
|
||||
// The following two items are used by the filter list when saving files.
|
||||
IBOutlet NSView* mFilterView;
|
||||
IBOutlet NSPopUpButton* mFilterList;
|
||||
|
||||
// IBOutlet NSMenuItem* mOfflineMenuItem;
|
||||
IBOutlet NSMenuItem* mCloseWindowMenuItem;
|
||||
IBOutlet NSMenuItem* mCloseTabMenuItem;
|
||||
IBOutlet NSMenuItem* mToggleSidebarMenuItem;
|
||||
|
||||
// The bookmarks menu.
|
||||
IBOutlet NSMenu* mBookmarksMenu;
|
||||
|
||||
IBOutlet NSMenuItem* mBookmarksToolbarMenuItem;
|
||||
IBOutlet NSMenuItem* mAddBookmarkMenuItem;
|
||||
IBOutlet NSMenuItem* mCreateBookmarksFolderMenuItem;
|
||||
IBOutlet NSMenuItem* mCreateBookmarksSeparatorMenuItem;
|
||||
|
||||
BOOL mOffline;
|
||||
|
||||
CHSplashScreenWindow* mSplashScreen;
|
||||
|
||||
CHPreferenceManager* mPreferenceManager;
|
||||
|
||||
BookmarksService* mMenuBookmarks;
|
||||
|
||||
FindDlgController* mFindDialog;
|
||||
|
||||
MVPreferencesController* mPreferencesController;
|
||||
|
||||
NSString* mStartURL;
|
||||
}
|
||||
|
||||
-(void)dealloc;
|
||||
|
||||
// File menu actions.
|
||||
-(IBAction) newWindow:(id)aSender;
|
||||
-(IBAction) openFile:(id)aSender;
|
||||
-(IBAction) openLocation:(id)aSender;
|
||||
-(IBAction) savePage:(id)aSender;
|
||||
-(IBAction) printPreview:(id)aSender;
|
||||
-(IBAction) printPage:(id)aSender;
|
||||
-(IBAction) toggleOfflineMode:(id)aSender;
|
||||
|
||||
// Edit menu actions.
|
||||
-(IBAction) findInPage:(id)aSender;
|
||||
-(IBAction) findAgain:(id)aSender;
|
||||
|
||||
// Go menu actions.
|
||||
-(IBAction) goBack:(id)aSender;
|
||||
-(IBAction) goForward:(id)aSender;
|
||||
-(IBAction) goHome:(id)aSender;
|
||||
-(IBAction) doSearch:(id)aSender;
|
||||
-(IBAction) previousTab:(id)aSender;
|
||||
-(IBAction) nextTab:(id)aSender;
|
||||
|
||||
// View menu actions.
|
||||
-(IBAction) toggleSidebar:(id)sender;
|
||||
-(IBAction) toggleBookmarksToolbar:(id)aSender;
|
||||
-(IBAction) doReload:(id)aSender;
|
||||
-(IBAction) doStop:(id)aSender;
|
||||
-(IBAction) biggerTextSize:(id)aSender;
|
||||
-(IBAction) smallerTextSize:(id)aSender;
|
||||
-(IBAction) viewSource:(id)aSender;
|
||||
|
||||
// Bookmarks menu actions.
|
||||
-(IBAction) importBookmarks:(id)aSender;
|
||||
-(IBAction) addBookmark:(id)aSender;
|
||||
-(IBAction) openMenuBookmark:(id)aSender;
|
||||
-(IBAction) manageBookmarks: (id)aSender;
|
||||
-(IBAction) addFolder:(id)aSender;
|
||||
-(IBAction) addSeparator:(id)aSender;
|
||||
|
||||
//Window menu actions
|
||||
-(IBAction) newTab:(id)aSender;
|
||||
-(IBAction) closeTab:(id)aSender;
|
||||
|
||||
//Help menu actions
|
||||
-(IBAction) infoLink:(id)aSender;
|
||||
-(IBAction) feedbackLink:(id)aSender;
|
||||
|
||||
-(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer;
|
||||
- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer:(NSString*)aReferrer;
|
||||
|
||||
- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs;
|
||||
- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs;
|
||||
- (void)fixCloseMenuItemKeyEquivalents;
|
||||
|
||||
- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost;
|
||||
|
||||
-(NSWindow*)getFrontmostBrowserWindow;
|
||||
|
||||
- (MVPreferencesController *)preferencesController;
|
||||
- (void)displayPreferencesWindow:sender;
|
||||
- (CHPreferenceManager *)preferenceManager;
|
||||
- (BOOL)isMainWindowABrowserWindow;
|
||||
|
||||
// if the main window is a browser window, return its controller, otherwise nil
|
||||
- (BrowserWindowController*)getMainWindowBrowserController;
|
||||
|
||||
- (IBAction)showAboutBox:(id)sender;
|
||||
|
||||
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle;
|
||||
|
||||
- (void)updatePrebinding;
|
||||
- (void)prebindFinished:(NSNotification *)aNotification;
|
||||
|
||||
@end
|
|
@ -1,927 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
#import "MainController.h"
|
||||
#import "BrowserWindowController.h"
|
||||
#import "BookmarksService.h"
|
||||
#import "nsCocoaBrowserService.h"
|
||||
#import "CHAboutBox.h"
|
||||
#import "CHUserDefaults.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsEmbedAPI.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
|
||||
|
||||
#ifdef _BUILD_STATIC_BIN
|
||||
#include "nsStaticComponent.h"
|
||||
nsresult PR_CALLBACK
|
||||
app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count);
|
||||
#endif
|
||||
|
||||
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
||||
|
||||
@implementation MainController
|
||||
|
||||
-(id)init
|
||||
{
|
||||
if ( (self = [super init]) ) {
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
if ([defaults boolForKey:USER_DEFAULTS_AUTOREGISTER_KEY]) {
|
||||
// This option causes us to simply initialize embedding and exit.
|
||||
NSString *path = [[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent];
|
||||
setenv("MOZILLA_FIVE_HOME", [path fileSystemRepresentation], 1);
|
||||
|
||||
#ifdef _BUILD_STATIC_BIN
|
||||
NSGetStaticModuleInfo = app_getModuleInfo;
|
||||
#endif
|
||||
|
||||
if (NS_SUCCEEDED(NS_InitEmbedding(nsnull, nsnull))) {
|
||||
// Register new chrome
|
||||
nsCOMPtr<nsIChromeRegistry> chromeReg =
|
||||
do_GetService("@mozilla.org/chrome/chrome-registry;1");
|
||||
if (chromeReg) {
|
||||
chromeReg->CheckForNewChrome();
|
||||
chromeReg = 0;
|
||||
}
|
||||
NS_TermEmbedding();
|
||||
}
|
||||
|
||||
[NSApp terminate:self];
|
||||
return self;
|
||||
}
|
||||
|
||||
NSString* url = [defaults stringForKey:USER_DEFAULTS_URL_KEY];
|
||||
mStartURL = url ? [url retain] : nil;
|
||||
mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:NSMakeRect(0,0,0,0)];
|
||||
mFindDialog = nil;
|
||||
mMenuBookmarks = nil;
|
||||
|
||||
[NSApp setServicesProvider:self];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
[mFindDialog release];
|
||||
[super dealloc];
|
||||
#if DEBUG
|
||||
NSLog(@"Main controller died");
|
||||
#endif
|
||||
}
|
||||
|
||||
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
#ifdef _BUILD_STATIC_BIN
|
||||
[self updatePrebinding];
|
||||
#endif
|
||||
// initialize if we haven't already.
|
||||
[self preferenceManager];
|
||||
|
||||
// don't open a new browser window if we already have one
|
||||
// (for example, from an GetURL Apple Event)
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow)
|
||||
[self newWindow: self];
|
||||
|
||||
[mSplashScreen close];
|
||||
|
||||
[mBookmarksMenu setAutoenablesItems: NO];
|
||||
mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil);
|
||||
mMenuBookmarks->AddObserver();
|
||||
BookmarksService::ConstructBookmarksMenu(mBookmarksMenu, nsnull);
|
||||
BookmarksService::gMainController = self;
|
||||
|
||||
// Initialize offline mode.
|
||||
mOffline = NO;
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
// Set the menu item's text to "Go Online" if we're currently
|
||||
// offline.
|
||||
/*
|
||||
if (mOffline)
|
||||
[mOfflineMenuItem setTitle: @"Go Online"]; // XXX localize me
|
||||
*/
|
||||
}
|
||||
|
||||
-(void)applicationWillTerminate: (NSNotification*)aNotification
|
||||
{
|
||||
#if DEBUG
|
||||
NSLog(@"Termination notification");
|
||||
#endif
|
||||
|
||||
// Autosave one of the windows.
|
||||
[[[mApplication mainWindow] windowController] autosaveWindowFrame];
|
||||
|
||||
mMenuBookmarks->RemoveObserver();
|
||||
delete mMenuBookmarks;
|
||||
mMenuBookmarks = nsnull;
|
||||
|
||||
// Release before calling TermEmbedding since we need to access XPCOM
|
||||
// to save preferences
|
||||
[mPreferencesController release];
|
||||
[mPreferenceManager release];
|
||||
|
||||
nsCocoaBrowserService::TermEmbedding();
|
||||
|
||||
[self autorelease];
|
||||
}
|
||||
|
||||
-(IBAction)newWindow:(id)aSender
|
||||
{
|
||||
// If we have a key window, have it autosave its dimensions before
|
||||
// we open a new window. That ensures the size ends up matching.
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] )
|
||||
[[mainWindow windowController] autosaveWindowFrame];
|
||||
|
||||
// Now open the new window.
|
||||
NSString* homePage = mStartURL ? mStartURL : [mPreferenceManager homePage:YES];
|
||||
BrowserWindowController* controller = [self openBrowserWindowWithURL:homePage andReferrer:nil];
|
||||
|
||||
if ([homePage isEqualToString: @"about:blank"])
|
||||
[controller focusURLBar];
|
||||
else
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
|
||||
// Only load the command-line specified URL for the first window we open
|
||||
if (mStartURL) {
|
||||
[mStartURL release];
|
||||
mStartURL = nil;
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction)newTab:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController newTab:NO];
|
||||
}
|
||||
|
||||
-(IBAction)closeTab:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController closeTab];
|
||||
}
|
||||
|
||||
-(IBAction) previousTab:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController previousTab];
|
||||
}
|
||||
|
||||
-(IBAction) nextTab:(id)aSender;
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController nextTab];
|
||||
}
|
||||
|
||||
-(IBAction) openFile:(id)aSender
|
||||
{
|
||||
NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease];
|
||||
[openPanel setCanChooseFiles: YES];
|
||||
[openPanel setCanChooseDirectories: NO];
|
||||
[openPanel setAllowsMultipleSelection: NO];
|
||||
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
|
||||
@"txt",@"text",
|
||||
@"gif",@"jpg",@"jpeg",@"png",@"bmp",
|
||||
nil];
|
||||
int result = [openPanel runModalForTypes: array];
|
||||
if (result == NSOKButton) {
|
||||
NSArray* urlArray = [openPanel URLs];
|
||||
if ([urlArray count] == 0)
|
||||
return;
|
||||
NSURL* url = [urlArray objectAtIndex: 0];
|
||||
// ----------------------
|
||||
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
|
||||
// ----------------------
|
||||
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController loadURL:[url absoluteString] referrer:nil activate:YES];
|
||||
else
|
||||
[self openBrowserWindowWithURL:[url absoluteString] andReferrer:nil];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction) openLocation:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self openBrowserWindowWithURL: @"about:blank" andReferrer:nil];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
else if (![browserWindow isMainWindow]) {
|
||||
[browserWindow makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
[[browserWindow windowController] performAppropriateLocationAction];
|
||||
}
|
||||
|
||||
-(IBAction) savePage:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController saveDocument: mFilterView filterList: mFilterList];
|
||||
}
|
||||
|
||||
-(IBAction) printPage:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController printDocument:aSender];
|
||||
}
|
||||
|
||||
-(IBAction) printPreview:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController printPreview];
|
||||
}
|
||||
|
||||
-(IBAction) toggleOfflineMode:(id)aSender
|
||||
{
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
ioService->SetOffline(!offline);
|
||||
mOffline = !offline;
|
||||
|
||||
// Update the menu item text.
|
||||
// Set the menu item's text to "Go Online" if we're currently
|
||||
// offline.
|
||||
/*
|
||||
if (mOffline)
|
||||
[mOfflineMenuItem setTitle: @"Go Online"];
|
||||
else
|
||||
[mOfflineMenuItem setTitle: @"Work Offline"];
|
||||
*/
|
||||
|
||||
// Indicate that we are working offline.
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
|
||||
}
|
||||
|
||||
// Edit menu actions.
|
||||
|
||||
|
||||
//
|
||||
// -findInPage
|
||||
//
|
||||
// Called in response to "Find" in edit menu. Opens the find dialog. We only keep
|
||||
// one around for the whole app to use, showing/hiding as we see fit.
|
||||
//
|
||||
-(IBAction) findInPage:(id)aSender
|
||||
{
|
||||
if ( !mFindDialog )
|
||||
mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"];
|
||||
[mFindDialog showWindow:self];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// -findAgain
|
||||
//
|
||||
// Called in response to "Find Again" in edit menu. Tells the find controller
|
||||
// to find the next occurrance of what's already been found.
|
||||
//
|
||||
-(IBAction) findAgain:(id)aSender
|
||||
{
|
||||
if ( mFindDialog )
|
||||
[mFindDialog findAgain:aSender];
|
||||
else
|
||||
NSBeep();
|
||||
}
|
||||
|
||||
-(IBAction) goBack:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController back: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) goForward:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController forward: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) doReload:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController reload: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) doStop:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController stop: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) goHome:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (browserWindow) {
|
||||
if (![browserWindow isMainWindow])
|
||||
[browserWindow makeKeyAndOrderFront:self];
|
||||
|
||||
[[browserWindow windowController] home: aSender];
|
||||
}
|
||||
else {
|
||||
[self newWindow:self];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction) doSearch:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (browserWindow) {
|
||||
if (![browserWindow isMainWindow])
|
||||
[browserWindow makeKeyAndOrderFront:self];
|
||||
|
||||
[[browserWindow windowController] performSearch: aSender];
|
||||
}
|
||||
else {
|
||||
[self newWindow:self];
|
||||
browserWindow = [self getFrontmostBrowserWindow];
|
||||
[[browserWindow windowController] performSearch: aSender];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost;
|
||||
{
|
||||
[mAddBookmarkMenuItem setEnabled:inBrowserWindowFrontmost];
|
||||
[mCreateBookmarksFolderMenuItem setEnabled:inBrowserWindowFrontmost];
|
||||
[mCreateBookmarksSeparatorMenuItem setEnabled:NO]; // separators are not implemented yet
|
||||
}
|
||||
|
||||
-(NSWindow*)getFrontmostBrowserWindow
|
||||
{
|
||||
// for some reason, [NSApp mainWindow] doesn't always work, so we have to
|
||||
// do this manually
|
||||
NSArray *windowList = [NSApp orderedWindows];
|
||||
NSWindow *foundWindow = NULL;
|
||||
|
||||
for (unsigned int i = 0; i < [windowList count]; i ++)
|
||||
{
|
||||
NSWindow* thisWindow = [windowList objectAtIndex:i];
|
||||
|
||||
if ([[thisWindow windowController] isMemberOfClass:[BrowserWindowController class]] &&
|
||||
([[thisWindow windowController] chromeMask] == 0)) // only get windows with full chrome
|
||||
{
|
||||
foundWindow = thisWindow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return foundWindow;
|
||||
}
|
||||
|
||||
// open a new URL. This method always makes a new browser window
|
||||
-(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer
|
||||
{
|
||||
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
|
||||
|
||||
// The process of creating a new tab in this brand new window loads about:blank for us as a
|
||||
// side effect of calling GetDocument(). We don't need to do it again.
|
||||
if ( [aURL isEqualToString:@"about:blank"] )
|
||||
[browser disableLoadPage];
|
||||
else
|
||||
[browser loadURL: aURL referrer:aReferrer activate:YES];
|
||||
[browser showWindow: self];
|
||||
return browser;
|
||||
}
|
||||
|
||||
// open a new URL, observing the prefs on how to behave
|
||||
- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer: (NSString*)aReferrer
|
||||
{
|
||||
// make sure we're initted
|
||||
[self preferenceManager];
|
||||
|
||||
PRBool reuseWindow = PR_FALSE;
|
||||
PRBool loadInBackground = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
|
||||
if ( prefService ) {
|
||||
prefService->GetBoolPref("browser.always_reuse_window", &reuseWindow);
|
||||
prefService->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
|
||||
}
|
||||
|
||||
// reuse the main window if there is one. The user may have closed all of
|
||||
// them or we may get this event at startup before we've had time to load
|
||||
// our window.
|
||||
BrowserWindowController* controller = [self getMainWindowBrowserController];
|
||||
if (reuseWindow && controller && [controller newTabsAllowed]) {
|
||||
[controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground];
|
||||
}
|
||||
else {
|
||||
// should use BrowserWindowController openNewWindowWithURL, but that method
|
||||
// really needs to be on the MainController
|
||||
controller = [self openBrowserWindowWithURL: inURLString andReferrer:aReferrer];
|
||||
}
|
||||
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
}
|
||||
|
||||
// Bookmarks menu actions.
|
||||
-(IBAction) importBookmarks:(id)aSender
|
||||
{
|
||||
// IE favorites: ~/Library/Preferences/Explorer/Favorites.html
|
||||
// Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html
|
||||
// For now, open the panel to IE's favorites.
|
||||
NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease];
|
||||
[openPanel setCanChooseFiles: YES];
|
||||
[openPanel setCanChooseDirectories: NO];
|
||||
[openPanel setAllowsMultipleSelection: NO];
|
||||
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"xml", nil];
|
||||
int result = [openPanel runModalForDirectory: @"~/Library/Preferences/Explorer/"
|
||||
file: @"Favorites.html"
|
||||
types: array];
|
||||
if (result == NSOKButton) {
|
||||
NSArray* urlArray = [openPanel URLs];
|
||||
if ([urlArray count] == 0)
|
||||
return;
|
||||
NSURL* url = [urlArray objectAtIndex: 0];
|
||||
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self newWindow: self];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
|
||||
[[browserWindow windowController] importBookmarks: [url absoluteString]];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction) addBookmark:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController addBookmarkExtended: YES isFolder: NO URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(IBAction) addFolder:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController addBookmarkExtended: YES isFolder: YES URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(IBAction) addSeparator:(id)aSender
|
||||
{
|
||||
NSLog(@"Separators not implemented yet");
|
||||
}
|
||||
|
||||
-(IBAction) openMenuBookmark:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self openBrowserWindowWithURL: @"about:blank" andReferrer:nil];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
|
||||
BookmarksService::OpenMenuBookmark([browserWindow windowController], aSender);
|
||||
}
|
||||
|
||||
-(IBAction)manageBookmarks: (id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self newWindow:self];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
|
||||
[[browserWindow windowController] manageBookmarks: aSender];
|
||||
}
|
||||
|
||||
- (CHPreferenceManager *)preferenceManager
|
||||
{
|
||||
if (!mPreferenceManager)
|
||||
mPreferenceManager = [[CHPreferenceManager sharedInstance] retain];
|
||||
return mPreferenceManager;
|
||||
}
|
||||
|
||||
- (MVPreferencesController *)preferencesController
|
||||
{
|
||||
if (!mPreferencesController) {
|
||||
mPreferencesController = [[MVPreferencesController sharedInstance] retain];
|
||||
}
|
||||
return mPreferencesController;
|
||||
}
|
||||
|
||||
- (void)displayPreferencesWindow:sender
|
||||
{
|
||||
[[self preferencesController] showPreferences:nil] ;
|
||||
}
|
||||
|
||||
- (IBAction)showAboutBox:(id)sender
|
||||
{
|
||||
[[CHAboutBox sharedInstance] showPanel:sender];
|
||||
}
|
||||
|
||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||
{
|
||||
/*
|
||||
// On the off chance that we're getting this message off a launch,
|
||||
// we may not have initialized our embedded mozilla. So check here,
|
||||
// and if it's not initialized, do it now.
|
||||
[self preferenceManager];
|
||||
|
||||
// Make sure it's a browser window b/c "about box" can also become main window.
|
||||
if ([self isMainWindowABrowserWindow]) {
|
||||
[[[mApplication mainWindow] windowController] loadURL:[[NSURL fileURLWithPath:filename] absoluteString]];
|
||||
}
|
||||
else {
|
||||
[self openBrowserWindowWithURL:[[NSURL fileURLWithPath:filename] absoluteString]];
|
||||
}
|
||||
*/
|
||||
[self openNewWindowOrTabWithURL:[[NSURL fileURLWithPath:filename] absoluteString] andReferrer:nil];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (IBAction)biggerTextSize:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController biggerTextSize];
|
||||
}
|
||||
|
||||
- (IBAction)smallerTextSize:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController smallerTextSize];
|
||||
}
|
||||
|
||||
-(IBAction) viewSource:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController viewSource: aSender];
|
||||
}
|
||||
|
||||
-(BOOL)isMainWindowABrowserWindow
|
||||
{
|
||||
// see also getFrontmostBrowserWindow
|
||||
return [[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]];
|
||||
}
|
||||
|
||||
- (BrowserWindowController*)getMainWindowBrowserController
|
||||
{
|
||||
NSWindowController* mainWindowController = [[mApplication mainWindow] windowController];
|
||||
if (mainWindowController && [mainWindowController isMemberOfClass:[BrowserWindowController class]])
|
||||
return (BrowserWindowController*)mainWindowController;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs
|
||||
{
|
||||
// capitalization of the key equivalent affects whether the shift modifer is used.
|
||||
[mCloseWindowMenuItem setKeyEquivalent: inHaveTabs ? @"W" : @"w"];
|
||||
}
|
||||
|
||||
- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs
|
||||
{
|
||||
if (inHaveTabs) {
|
||||
[mCloseTabMenuItem setKeyEquivalent:@"w"];
|
||||
[mCloseTabMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
|
||||
}
|
||||
else {
|
||||
[mCloseTabMenuItem setKeyEquivalent:@""];
|
||||
[mCloseTabMenuItem setKeyEquivalentModifierMask:0];
|
||||
}
|
||||
}
|
||||
|
||||
// see if we have a window with tabs open, and adjust the key equivalents for
|
||||
// Close Tab/Close Window accordingly
|
||||
- (void)fixCloseMenuItemKeyEquivalents
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController) {
|
||||
BOOL windowWithMultipleTabs = ([[browserController getTabBrowser] numberOfTabViewItems] > 1);
|
||||
[self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs];
|
||||
[self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
|
||||
// disable items that aren't relevant if there's no main browser window open
|
||||
SEL action = [aMenuItem action];
|
||||
|
||||
//NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action);
|
||||
|
||||
if (action == @selector(printPage:) ||
|
||||
/* ... many more items go here ... */
|
||||
/* action == @selector(goHome:) || */ // always enabled
|
||||
/* action == @selector(doSearch:) || */ // always enabled
|
||||
action == @selector(findInPage:) ||
|
||||
action == @selector(doReload:) ||
|
||||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(savePage:)) {
|
||||
if (browserController)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (action == @selector(newTab:)) {
|
||||
if (browserController && [browserController newTabsAllowed])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
// check if someone has previously done a find before allowing findAgain to be enabled
|
||||
if (action == @selector(findAgain:)) {
|
||||
if (browserController)
|
||||
return (mFindDialog && [[mFindDialog getSearchText] length] > 0);
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// check what the state of the personal toolbar should be, but only if there is a browser
|
||||
// window open. Popup windows that have the personal toolbar removed should always gray
|
||||
// out this menu.
|
||||
if (action == @selector(toggleBookmarksToolbar:)) {
|
||||
if (browserController) {
|
||||
NSView* bookmarkToolbar = [browserController bookmarksToolbar];
|
||||
if ( bookmarkToolbar ) {
|
||||
float height = [bookmarkToolbar frame].size.height;
|
||||
BOOL toolbarShowing = (height > 0);
|
||||
if (toolbarShowing)
|
||||
[mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Hide Bookmarks Toolbar",@"")];
|
||||
else
|
||||
[mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Show Bookmarks Toolbar",@"")];
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (action == @selector(toggleSidebar:)) {
|
||||
if (browserController) {
|
||||
NSDrawer *sidebar = [browserController sidebarDrawer];
|
||||
if (sidebar) {
|
||||
int sidebarState = [sidebar state];
|
||||
if (sidebarState == NSDrawerOpenState)
|
||||
[mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Hide Sidebar",@"")];
|
||||
else
|
||||
[mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Show Sidebar",@"")];
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:)))
|
||||
{
|
||||
if (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(doStop:) ) {
|
||||
if (browserController)
|
||||
return [[browserController getBrowserWrapper] isBusy];
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
if (browserController) {
|
||||
CHBrowserView* browserView = [[browserController getBrowserWrapper] getBrowserView];
|
||||
if (action == @selector(goBack:))
|
||||
return [browserView canGoBack];
|
||||
if (action == @selector(goForward:))
|
||||
return [browserView canGoForward];
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// default return
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(IBAction) toggleSidebar:(id)sender
|
||||
{
|
||||
BrowserWindowController *browserController = [self getMainWindowBrowserController];
|
||||
if (!browserController) return;
|
||||
|
||||
[browserController toggleSidebar:sender];
|
||||
}
|
||||
|
||||
-(IBAction) toggleBookmarksToolbar:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (!browserController) return;
|
||||
|
||||
float height = [[browserController bookmarksToolbar] frame].size.height;
|
||||
BOOL showToolbar = (BOOL)(!(height > 0));
|
||||
|
||||
[[browserController bookmarksToolbar] showBookmarksToolbar: showToolbar];
|
||||
|
||||
// save prefs here
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults setInteger: ((showToolbar) ? 0 : 1) forKey: USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY];
|
||||
}
|
||||
|
||||
-(IBAction) infoLink:(id)aSender
|
||||
{
|
||||
NSString* pageToLoad = NSLocalizedStringFromTable(@"InfoPageDefault", @"WebsiteDefaults", nil);
|
||||
if (![pageToLoad isEqualToString:@"InfoPageDefault"])
|
||||
[self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil];
|
||||
}
|
||||
|
||||
-(IBAction) feedbackLink:(id)aSender
|
||||
{
|
||||
NSString *pageToLoad = NSLocalizedStringFromTable(@"FeedbackPageDefault", @"WebsiteDefaults", nil);
|
||||
if (![pageToLoad isEqualToString:@"FeedbackPageDefault"])
|
||||
[self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil];
|
||||
}
|
||||
|
||||
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle
|
||||
{
|
||||
NSImage* image;
|
||||
NSSize titleSize, imageSize;
|
||||
NSRect imageRect;
|
||||
NSDictionary* stringAttrs;
|
||||
|
||||
// get the size of the new image we are creating
|
||||
titleSize = [aTitle sizeWithAttributes:nil];
|
||||
imageSize = NSMakeSize(titleSize.width + [aIcon size].width,
|
||||
titleSize.height > [aIcon size].height ?
|
||||
titleSize.height : [aIcon size].height);
|
||||
|
||||
// create the image and lock drawing focus on it
|
||||
image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
|
||||
[image lockFocus];
|
||||
|
||||
// draw the image and title in image with translucency
|
||||
imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height);
|
||||
[aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8];
|
||||
|
||||
stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8]
|
||||
forKey: NSForegroundColorAttributeName];
|
||||
[aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs];
|
||||
|
||||
[image unlockFocus];
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApp hasVisibleWindows:(BOOL)flag
|
||||
{
|
||||
// If AppKit knows what to do, let it.
|
||||
if (flag)
|
||||
return YES;
|
||||
|
||||
// If window available, wake it up. |mainWindow| should always be null.
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if (!mainWindow)
|
||||
[self newWindow:self];
|
||||
else { // Don't think this will ever happen, but just in case
|
||||
if ([[mainWindow windowController]respondsToSelector:@selector(showWindow:)])
|
||||
[[mainWindow windowController] showWindow:self];
|
||||
else
|
||||
[self newWindow:self];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) applicationDidChangeScreenParameters:(NSNotification *)aNotification
|
||||
{
|
||||
[NSApp makeWindowsPerform:@selector(display) inOrder:YES];
|
||||
}
|
||||
|
||||
- (void) updatePrebinding
|
||||
{
|
||||
// Check our prebinding status. If we didn't launch prebound,
|
||||
// fork the update script.
|
||||
|
||||
if (!_dyld_launched_prebound()) {
|
||||
NSLog(@"Not prebound, launching update script");
|
||||
NSTask* aTask = [[NSTask alloc] init];
|
||||
NSArray* args = [NSArray arrayWithObject: @"redo-prebinding.sh"];
|
||||
|
||||
[aTask setCurrentDirectoryPath:[[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]];
|
||||
[aTask setLaunchPath:@"/bin/sh"];
|
||||
[aTask setArguments:args];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||
selector:@selector(prebindFinished:)
|
||||
name:NSTaskDidTerminateNotification
|
||||
object: nil];
|
||||
|
||||
[aTask launch];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)prebindFinished:(NSNotification *)aNotification
|
||||
{
|
||||
[[aNotification object] release];
|
||||
}
|
||||
|
||||
// services
|
||||
|
||||
- (void)openURL:(NSPasteboard *) pboard userData:(NSString *) userData error:(NSString **) error
|
||||
{
|
||||
NSMutableString *urlString = [[[NSMutableString alloc] init] autorelease];
|
||||
if ( !urlString )
|
||||
return;
|
||||
|
||||
NSArray* types = [pboard types];
|
||||
if (![types containsObject:NSStringPboardType]) {
|
||||
*error = NSLocalizedString(@"Error: couldn't open URL.",
|
||||
@"pboard couldn't give URL string.");
|
||||
return;
|
||||
}
|
||||
NSString* pboardString = [pboard stringForType:NSStringPboardType];
|
||||
if (!pboardString) {
|
||||
*error = NSLocalizedString(@"Error: couldn't open URL.",
|
||||
@"pboard couldn't give URL string.");
|
||||
return;
|
||||
}
|
||||
NSScanner* scanner = [NSScanner scannerWithString:pboardString];
|
||||
[scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&urlString];
|
||||
while(![scanner isAtEnd]) {
|
||||
NSString *tmpString;
|
||||
[scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&tmpString];
|
||||
[urlString appendString:tmpString];
|
||||
}
|
||||
|
||||
[self openNewWindowOrTabWithURL:urlString andReferrer:nil];
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,79 +0,0 @@
|
|||
{
|
||||
IBClasses = (
|
||||
{
|
||||
CLASS = BrowserToolbarController;
|
||||
LANGUAGE = ObjC;
|
||||
SUPERCLASS = ToolbarController;
|
||||
},
|
||||
{CLASS = CHGoMenu; LANGUAGE = ObjC; SUPERCLASS = NSMenu; },
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
ACTIONS = {
|
||||
addBookmark = id;
|
||||
addFolder = id;
|
||||
addSeparator = id;
|
||||
biggerTextSize = id;
|
||||
closeTab = id;
|
||||
displayPreferencesWindow = id;
|
||||
doReload = id;
|
||||
doSearch = id;
|
||||
doStop = id;
|
||||
feedbackLink = id;
|
||||
findAgain = id;
|
||||
findInPage = id;
|
||||
goBack = id;
|
||||
goForward = id;
|
||||
goHome = id;
|
||||
importBookmarks = id;
|
||||
infoLink = id;
|
||||
manageBookmarks = id;
|
||||
newTab = id;
|
||||
newWindow = id;
|
||||
nextTab = id;
|
||||
openFile = id;
|
||||
openLocation = id;
|
||||
openMenuBookmark = id;
|
||||
previousTab = id;
|
||||
printPage = id;
|
||||
printPreview = id;
|
||||
savePage = id;
|
||||
showAboutBox = id;
|
||||
smallerTextSize = id;
|
||||
toggleBookmarksToolbar = id;
|
||||
toggleOfflineMode = id;
|
||||
toggleSidebar = id;
|
||||
viewSource = id;
|
||||
};
|
||||
CLASS = MainController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {
|
||||
mAddBookmarkMenuItem = NSMenuItem;
|
||||
mApplication = NSApplication;
|
||||
mBookmarksMenu = NSMenu;
|
||||
mBookmarksToolbarMenuItem = NSMenuItem;
|
||||
mCloseTabMenuItem = NSMenuItem;
|
||||
mCloseWindowMenuItem = NSMenuItem;
|
||||
mCreateBookmarksFolderMenuItem = NSMenuItem;
|
||||
mCreateBookmarksSeparatorMenuItem = NSMenuItem;
|
||||
mFilterList = NSPopUpButton;
|
||||
mFilterView = NSView;
|
||||
mToggleSidebarMenuItem = NSMenuItem;
|
||||
};
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {load = id; };
|
||||
CLASS = MyBrowserView;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {progress = id; progressSuper = id; status = id; urlbar = id; };
|
||||
SUPERCLASS = NSView;
|
||||
},
|
||||
{
|
||||
CLASS = ToolbarController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {mBrowserView = id; mWindow = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 23 477 485 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>266</key>
|
||||
<string>483 623 277 90 0 0 1280 1002 </string>
|
||||
<key>29</key>
|
||||
<string>8 957 446 44 0 0 1280 1002 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>248.0</string>
|
||||
<key>IBGroupedObjects</key>
|
||||
<dict>
|
||||
<key>0</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
<key>1</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
</dict>
|
||||
<key>IBLastGroupID</key>
|
||||
<string>2</string>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5S66</string>
|
||||
</dict>
|
||||
</plist>
|
Двоичный файл не отображается.
|
@ -3,11 +3,11 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 71 632 495 0 0 1280 1002 </string>
|
||||
<string>112 15 632 495 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>124</key>
|
||||
<string>305 659 170 144 0 0 1152 848 </string>
|
||||
<string>345 803 170 144 0 0 1280 1002 </string>
|
||||
<key>160</key>
|
||||
<string>524 326 195 666 0 0 1280 1002 </string>
|
||||
<key>28</key>
|
||||
|
|
Двоичные данные
camino/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичные данные
camino/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичный файл не отображается.
|
@ -21,6 +21,7 @@
|
|||
feedbackLink = id;
|
||||
findAgain = id;
|
||||
findInPage = id;
|
||||
getInfo = id;
|
||||
goBack = id;
|
||||
goForward = id;
|
||||
goHome = id;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 23 477 485 0 0 1280 1002 </string>
|
||||
<string>108 107 477 485 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>266</key>
|
||||
|
@ -29,6 +29,10 @@
|
|||
</dict>
|
||||
<key>IBLastGroupID</key>
|
||||
<string>2</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>29</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5S66</string>
|
||||
</dict>
|
||||
|
|
Двоичный файл не отображается.
|
@ -94,6 +94,7 @@ class BookmarksService;
|
|||
// Edit menu actions.
|
||||
-(IBAction) findInPage:(id)aSender;
|
||||
-(IBAction) findAgain:(id)aSender;
|
||||
-(IBAction) getInfo:(id)aSender;
|
||||
|
||||
// Go menu actions.
|
||||
-(IBAction) goBack:(id)aSender;
|
||||
|
|
|
@ -345,6 +345,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
NSBeep();
|
||||
}
|
||||
|
||||
-(IBAction) getInfo:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController getInfo: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) goBack:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
|
@ -679,25 +686,17 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(savePage:)) {
|
||||
if (browserController)
|
||||
return YES;
|
||||
return NO;
|
||||
action == @selector(savePage:))
|
||||
{
|
||||
return (browserController != nil);
|
||||
}
|
||||
|
||||
if (action == @selector(newTab:)) {
|
||||
if (browserController && [browserController newTabsAllowed])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
if (action == @selector(newTab:))
|
||||
return (browserController && [browserController newTabsAllowed]);
|
||||
|
||||
// check if someone has previously done a find before allowing findAgain to be enabled
|
||||
if (action == @selector(findAgain:)) {
|
||||
if (browserController)
|
||||
return (mFindDialog && [[mFindDialog getSearchText] length] > 0);
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
if (action == @selector(findAgain:))
|
||||
return (browserController && mFindDialog && [[mFindDialog getSearchText] length] > 0);
|
||||
|
||||
// check what the state of the personal toolbar should be, but only if there is a browser
|
||||
// window open. Popup windows that have the personal toolbar removed should always gray
|
||||
|
@ -739,24 +738,20 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(getInfo:) )
|
||||
return (browserController && [browserController canGetInfo]);
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:)))
|
||||
action == @selector(nextTab:) ||
|
||||
action == @selector(previousTab:)))
|
||||
{
|
||||
if (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
return (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1);
|
||||
}
|
||||
|
||||
if ( action == @selector(doStop:) ) {
|
||||
if (browserController)
|
||||
return [[browserController getBrowserWrapper] isBusy];
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
if ( action == @selector(doStop:) )
|
||||
return (browserController && [[browserController getBrowserWrapper] isBusy]);
|
||||
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
if (browserController) {
|
||||
CHBrowserView* browserView = [[browserController getBrowserWrapper] getBrowserView];
|
||||
|
|
|
@ -79,11 +79,12 @@ class BookmarksService;
|
|||
|
||||
-(NSString*)resolveKeyword:(NSString*)aKeyword;
|
||||
|
||||
-(IBAction)openBookmarkInNewTab:(id)aSender;
|
||||
-(IBAction)openBookmarkInNewWindow:(id)aSender;
|
||||
- (IBAction)openBookmarkInNewTab:(id)aSender;
|
||||
- (IBAction)openBookmarkInNewWindow:(id)aSender;
|
||||
|
||||
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
|
||||
-(IBAction)showBookmarkInfo:(id)aSender;
|
||||
- (void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
|
||||
- (IBAction)showBookmarkInfo:(id)aSender;
|
||||
- (BOOL)haveSelectedRow;
|
||||
|
||||
// Datasource methods.
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
|
||||
|
|
|
@ -790,6 +790,11 @@
|
|||
[bic showWindow:bic];
|
||||
}
|
||||
|
||||
- (BOOL)haveSelectedRow
|
||||
{
|
||||
return ([mOutlineView selectedRow] != -1);
|
||||
}
|
||||
|
||||
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
|
||||
{
|
||||
BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController];
|
||||
|
|
|
@ -196,8 +196,11 @@ class nsIDOMNode;
|
|||
- (void)stopThrobber;
|
||||
- (void)clickThrobber:(id)aSender;
|
||||
|
||||
-(void) biggerTextSize;
|
||||
-(void) smallerTextSize;
|
||||
- (void)biggerTextSize;
|
||||
- (void)smallerTextSize;
|
||||
- (void)getInfo:(id)sender;
|
||||
|
||||
- (BOOL)canGetInfo;
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar;
|
||||
|
||||
|
@ -205,6 +208,7 @@ class nsIDOMNode;
|
|||
- (IBAction)manageBookmarks: (id)aSender;
|
||||
- (void)importBookmarks: (NSString*)aURLSpec;
|
||||
- (IBAction)toggleSidebar:(id)aSender;
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection;
|
||||
|
||||
- (void)newTab:(BOOL)allowHomepage;
|
||||
- (void)closeTab;
|
||||
|
|
|
@ -850,16 +850,23 @@ static NSArray* sToolbarDefaults = nil;
|
|||
BOOL useSel = aIsFromMenu;
|
||||
if (aIsFromMenu) {
|
||||
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
|
||||
if ([mSidebarDrawer state] == NSDrawerClosedState)
|
||||
useSel = NO;
|
||||
else
|
||||
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
|
||||
useSel = NO;
|
||||
useSel = [self bookmarksAreVisible:NO];
|
||||
}
|
||||
|
||||
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle];
|
||||
}
|
||||
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection
|
||||
{
|
||||
// we should really identify the tab by identifier, not index.
|
||||
BOOL bookmarksShowing = ([mSidebarDrawer state] == NSDrawerOpenState) &&
|
||||
([mSidebarTabView tabViewItemAtIndex: 0] == [mSidebarTabView selectedTabViewItem]);
|
||||
|
||||
if (inRequireSelection)
|
||||
bookmarksShowing &= ([mSidebarBookmarksDataSource haveSelectedRow]);
|
||||
|
||||
return bookmarksShowing;
|
||||
}
|
||||
|
||||
- (IBAction)bookmarkPage: (id)aSender
|
||||
{
|
||||
|
@ -1217,6 +1224,17 @@ static NSArray* sToolbarDefaults = nil;
|
|||
markupViewer->SetTextZoom(zoom);
|
||||
}
|
||||
|
||||
- (void)getInfo:(id)sender
|
||||
{
|
||||
[mSidebarBookmarksDataSource ensureBookmarks];
|
||||
[mSidebarBookmarksDataSource showBookmarkInfo:sender];
|
||||
}
|
||||
|
||||
- (BOOL)canGetInfo
|
||||
{
|
||||
return [self bookmarksAreVisible:YES];
|
||||
}
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar
|
||||
{
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Appkit/Appkit.h>
|
||||
|
||||
#import "MainController.h"
|
||||
#import "CHBookmarksToolbar.h"
|
||||
#import "CHExtendedOutlineView.h"
|
||||
|
||||
class nsIContent;
|
||||
class BookmarksService;
|
||||
|
||||
@class BookmarkInfoController;
|
||||
|
||||
// data source for the bookmarks sidebar. We make one per browser window.
|
||||
@interface BookmarksDataSource : NSObject
|
||||
{
|
||||
BookmarksService* mBookmarks;
|
||||
|
||||
IBOutlet id mOutlineView;
|
||||
IBOutlet id mBrowserWindowController;
|
||||
IBOutlet id mEditBookmarkButton;
|
||||
IBOutlet id mDeleteBookmarkButton;
|
||||
|
||||
NSString* mCachedHref;
|
||||
}
|
||||
|
||||
-(id) init;
|
||||
-(void) windowClosing;
|
||||
|
||||
-(void) ensureBookmarks;
|
||||
|
||||
-(IBAction)addBookmark:(id)aSender;
|
||||
-(void)endAddBookmark: (int)aCode;
|
||||
|
||||
-(IBAction)deleteBookmarks: (id)aSender;
|
||||
-(void)deleteBookmark: (id)aItem;
|
||||
|
||||
-(IBAction)addFolder:(id)aSender;
|
||||
|
||||
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle;
|
||||
|
||||
-(NSString*)resolveKeyword:(NSString*)aKeyword;
|
||||
|
||||
-(IBAction)openBookmarkInNewTab:(id)aSender;
|
||||
-(IBAction)openBookmarkInNewWindow:(id)aSender;
|
||||
|
||||
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
|
||||
-(IBAction)showBookmarkInfo:(id)aSender;
|
||||
|
||||
// Datasource methods.
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
|
||||
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
|
||||
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
|
||||
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
|
||||
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
|
||||
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
|
||||
|
||||
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
|
||||
|
||||
// Delegate methods
|
||||
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
|
||||
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
|
||||
|
||||
@end
|
||||
|
||||
@interface BookmarkItem : NSObject
|
||||
{
|
||||
nsIContent* mContentNode;
|
||||
NSImage* mSiteIcon;
|
||||
}
|
||||
|
||||
- (nsIContent*)contentNode;
|
||||
- (void)setContentNode: (nsIContent*)aContentNode;
|
||||
- (void)setSiteIcon:(NSImage*)image;
|
||||
- (NSString*)url;
|
||||
- (NSImage*)siteIcon;
|
||||
- (NSNumber*)contentID;
|
||||
- (id)copyWithZone:(NSZone *)aZone;
|
||||
- (BOOL)isFolder;
|
||||
|
||||
@end
|
|
@ -1,923 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import "NSString+Utils.h"
|
||||
|
||||
#import "BookmarksDataSource.h"
|
||||
#import "BookmarkInfoController.h"
|
||||
#import "SiteIconProvider.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsINamespaceManager.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#import "BookmarksService.h"
|
||||
|
||||
@implementation BookmarksDataSource
|
||||
|
||||
-(id) init
|
||||
{
|
||||
if ( (self = [super init]) ) {
|
||||
mBookmarks = nsnull;
|
||||
mCachedHref = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void) awakeFromNib
|
||||
{
|
||||
// make sure these are disabled at the start since the outliner
|
||||
// starts off with no selection.
|
||||
[mEditBookmarkButton setEnabled:NO];
|
||||
[mDeleteBookmarkButton setEnabled:NO];
|
||||
}
|
||||
|
||||
-(void) windowClosing
|
||||
{
|
||||
if (mBookmarks) {
|
||||
mBookmarks->RemoveObserver();
|
||||
delete mBookmarks;
|
||||
}
|
||||
}
|
||||
|
||||
-(void) ensureBookmarks
|
||||
{
|
||||
if (mBookmarks)
|
||||
return;
|
||||
|
||||
mBookmarks = new BookmarksService(self);
|
||||
mBookmarks->AddObserver();
|
||||
|
||||
[mOutlineView setTarget: self];
|
||||
[mOutlineView setDoubleAction: @selector(openBookmark:)];
|
||||
[mOutlineView setDeleteAction: @selector(deleteBookmarks:)];
|
||||
[mOutlineView reloadData];
|
||||
}
|
||||
|
||||
-(IBAction)addBookmark:(id)aSender
|
||||
{
|
||||
[self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(IBAction)addFolder:(id)aSender
|
||||
{
|
||||
[self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return;
|
||||
|
||||
// We use the selected item to determine the parent only if aUseSel is YES.
|
||||
BookmarkItem* item = nil;
|
||||
if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) {
|
||||
// There is only one selected row. If it is a folder, use it as our parent.
|
||||
// Otherwise, use our parent,
|
||||
int index = [mOutlineView selectedRow];
|
||||
item = [mOutlineView itemAtRow: index];
|
||||
if (![mOutlineView isExpandable: item]) {
|
||||
// We can't be used as the parent. Try our parent.
|
||||
nsIContent* content = [item contentNode];
|
||||
if (!content)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIContent> parentContent;
|
||||
content->GetParent(*getter_AddRefs(parentContent));
|
||||
nsCOMPtr<nsIContent> root;
|
||||
mBookmarks->GetRootContent(getter_AddRefs(root));
|
||||
|
||||
// The root has no item, so we don't need to do a lookup unless we
|
||||
// aren't the root.
|
||||
if (parentContent != root) {
|
||||
PRUint32 contentID;
|
||||
parentContent->GetContentID(&contentID);
|
||||
item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
|
||||
|
||||
nsAutoString title, href;
|
||||
if (!aIsFolder) {
|
||||
|
||||
// If no URL and title were specified, get them from the current page.
|
||||
if (aURL && aTitle) {
|
||||
[aURL assignTo_nsAString:href];
|
||||
[aTitle assignTo_nsAString:title];
|
||||
} else {
|
||||
BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView],
|
||||
title, href);
|
||||
}
|
||||
|
||||
mCachedHref = [NSString stringWith_nsAString: href];
|
||||
[mCachedHref retain];
|
||||
|
||||
} else { // Folder
|
||||
mCachedHref = nil;
|
||||
title = NS_LITERAL_STRING("New Folder"); // XXX localize me
|
||||
}
|
||||
|
||||
NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
|
||||
NSString* bookmarkTitle = [NSString stringWith_nsAString: title];
|
||||
NSString* cleanedTitle = [bookmarkTitle stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "];
|
||||
|
||||
[textField setStringValue: cleanedTitle];
|
||||
|
||||
[mBrowserWindowController cacheBookmarkDS: 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];
|
||||
BookmarksService::ConstructAddBookmarkFolderList(popup, item);
|
||||
|
||||
[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 = nil;
|
||||
isGroup = YES;
|
||||
}
|
||||
|
||||
nsAutoString title;
|
||||
[[[mBrowserWindowController getAddBookmarkTitle] stringValue] assignTo_nsAString:title];
|
||||
|
||||
nsAutoString tagName;
|
||||
if (mCachedHref)
|
||||
tagName = NS_LITERAL_STRING("bookmark");
|
||||
else
|
||||
tagName = NS_LITERAL_STRING("folder");
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
|
||||
nsCOMPtr<nsIDOMElement> elt;
|
||||
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
|
||||
tagName,
|
||||
getter_AddRefs(elt));
|
||||
|
||||
elt->SetAttribute(NS_LITERAL_STRING("name"), title);
|
||||
|
||||
if (mCachedHref) {
|
||||
nsAutoString href;
|
||||
[mCachedHref assignTo_nsAString:href];
|
||||
[mCachedHref release];
|
||||
elt->SetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
}
|
||||
|
||||
if (isGroup) {
|
||||
// We have to iterate over each tab and create content nodes using the
|
||||
// title/href of all the pages. They are inserted underneath the parent.
|
||||
elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true"));
|
||||
id tabBrowser = [mBrowserWindowController getTabBrowser];
|
||||
int count = [tabBrowser numberOfTabViewItems];
|
||||
for (int i = 0; i < count; i++) {
|
||||
id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView];
|
||||
nsAutoString title, href;
|
||||
BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href);
|
||||
nsCOMPtr<nsIDOMElement> childElt;
|
||||
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
|
||||
NS_LITERAL_STRING("bookmark"),
|
||||
getter_AddRefs(childElt));
|
||||
childElt->SetAttribute(NS_LITERAL_STRING("name"), title);
|
||||
childElt->SetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
elt->AppendChild(childElt, getter_AddRefs(dummy));
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out the parent element.
|
||||
nsCOMPtr<nsIDOMElement> parentElt;
|
||||
nsCOMPtr<nsIContent> parentContent;
|
||||
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
|
||||
NSMenuItem* selectedItem = [popup selectedItem];
|
||||
int tag = [selectedItem tag];
|
||||
if (tag == -1) {
|
||||
mBookmarks->GetRootContent(getter_AddRefs(parentContent));
|
||||
parentElt = do_QueryInterface(parentContent);
|
||||
}
|
||||
else {
|
||||
BookmarkItem* item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: tag]];
|
||||
// Get the content node.
|
||||
parentContent = [item contentNode];
|
||||
parentElt = do_QueryInterface(parentContent);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
parentElt->AppendChild(elt, getter_AddRefs(dummy));
|
||||
|
||||
nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
|
||||
mBookmarks->BookmarkAdded(parentContent, childContent);
|
||||
}
|
||||
|
||||
-(IBAction)deleteBookmarks: (id)aSender
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return;
|
||||
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
// first, see how many items are selected
|
||||
BOOL haveBookmarks = NO;
|
||||
|
||||
NSEnumerator* testSelRows = [mOutlineView selectedRowEnumerator];
|
||||
for (NSNumber* currIndex = [testSelRows nextObject];
|
||||
currIndex != nil;
|
||||
currIndex = [testSelRows nextObject])
|
||||
{
|
||||
index = [currIndex intValue];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
if ([mOutlineView isExpandable: item]) {
|
||||
// dumb check to see if we're deleting an empty folder. Should really
|
||||
// recurse down
|
||||
if ([self outlineView:mOutlineView numberOfChildrenOfItem: item] > 0)
|
||||
haveBookmarks = YES;
|
||||
} else
|
||||
haveBookmarks = YES;
|
||||
}
|
||||
|
||||
// ideally, we should count the number of doomed bookmarks and tell the user
|
||||
if (haveBookmarks) {
|
||||
NSString *alert = NSLocalizedString(@"DeteleBookmarksAlert",@"");
|
||||
NSString *message = NSLocalizedString(@"DeteleBookmarksMsg",@"");
|
||||
NSString *okButton = NSLocalizedString(@"DeteleBookmarksOKButton",@"");
|
||||
NSString *cancelButton = NSLocalizedString(@"DeteleBookmarksCancelButton",@"");
|
||||
if (NSRunAlertPanel(alert, message, okButton, cancelButton, nil) != NSAlertDefaultReturn)
|
||||
return;
|
||||
}
|
||||
|
||||
// The alert panel was the key window. As soon as we dismissed it, Cocoa will
|
||||
// pick a new one for us. Ideally, it'll be the window we were using when
|
||||
// we clicked the delete button. However, if by chance the BookmarkInfoController
|
||||
// is visible, it will become the key window since it's a panel. If we then delete
|
||||
// the bookmark and try to close the window before we've setup a new bookmark,
|
||||
// we'll trigger the windowDidResignKey message, which will try to update the bookmark
|
||||
// we just deleted, and things will crash. So, we'll trigger windowDidResignKey now
|
||||
// and avoid the unpleasentness of a crash log.
|
||||
|
||||
if (![[mBrowserWindowController window] isKeyWindow])
|
||||
[[mBrowserWindowController window] makeKeyWindow];
|
||||
|
||||
// we'll run into problems if a parent item and one if its children are both selected.
|
||||
// A cheap way of having to avoid scanning the list to remove children is to have the
|
||||
// outliner collapse all items that are being deleted. This will cull the selection
|
||||
// for us and eliminate any children that happened to be selected.
|
||||
NSEnumerator* selRows = [mOutlineView selectedRowEnumerator];
|
||||
for (NSNumber* currIndex = [selRows nextObject];
|
||||
currIndex != nil;
|
||||
currIndex = [selRows nextObject]) {
|
||||
index = [currIndex intValue];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
[mOutlineView collapseItem: item];
|
||||
}
|
||||
|
||||
// create array of items we need to delete. Deleting items out of of the
|
||||
// selection array is problematic for some reason.
|
||||
NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease];
|
||||
selRows = [mOutlineView selectedRowEnumerator];
|
||||
for (NSNumber* currIndex = [selRows nextObject];
|
||||
currIndex != nil;
|
||||
currIndex = [selRows nextObject]) {
|
||||
index = [currIndex intValue];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
[itemsToDelete addObject: item];
|
||||
}
|
||||
|
||||
// delete all bookmarks that are in our array
|
||||
int count = [itemsToDelete count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
BookmarkItem* item = [itemsToDelete objectAtIndex: i];
|
||||
[self deleteBookmark: item];
|
||||
}
|
||||
|
||||
// restore selection to location near last item deleted or last item
|
||||
int total = [mOutlineView numberOfRows];
|
||||
if (index >= total)
|
||||
index = total - 1;
|
||||
[mOutlineView selectRow: index byExtendingSelection: NO];
|
||||
// lame, but makes sure we catch all delete events in Info Panel
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"NSOutlineViewSelectionDidChangeNotification" object:mOutlineView];
|
||||
|
||||
}
|
||||
|
||||
-(void)deleteBookmark:(id)aItem
|
||||
{
|
||||
nsCOMPtr<nsIContent> content = [aItem contentNode];
|
||||
nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
|
||||
if (!child)
|
||||
return;
|
||||
if (child == BookmarksService::gToolbarRoot)
|
||||
return; // Don't allow the personal toolbar to be deleted.
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
child->GetParentNode(getter_AddRefs(parent));
|
||||
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parent));
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
if (parent)
|
||||
parent->RemoveChild(child, getter_AddRefs(dummy));
|
||||
mBookmarks->BookmarkRemoved(parentContent, content);
|
||||
}
|
||||
|
||||
-(IBAction)openBookmark: (id)aSender
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
id item = [mOutlineView itemAtRow: index];
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
nsIContent* content = [item contentNode];
|
||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
|
||||
nsAutoString group;
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
|
||||
if (!group.IsEmpty())
|
||||
mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt);
|
||||
else if ([mOutlineView isExpandable: item]) {
|
||||
if ([mOutlineView isItemExpanded: item])
|
||||
[mOutlineView collapseItem: item];
|
||||
else
|
||||
[mOutlineView expandItem: item];
|
||||
}
|
||||
else {
|
||||
nsAutoString href;
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
|
||||
if (!href.IsEmpty()) {
|
||||
NSString* url = [NSString stringWith_nsAString: href];
|
||||
[[mBrowserWindowController getBrowserWrapper] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(NSString*) resolveKeyword: (NSString*) aKeyword
|
||||
{
|
||||
return BookmarksService::ResolveKeyword(aKeyword);
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
//
|
||||
// outlineView:shouldEditTableColumn:item: (delegate method)
|
||||
//
|
||||
// Called by the outliner to determine whether or not we should allow the
|
||||
// user to edit this item. For now, Cocoa doesn't correctly handle editing
|
||||
// of attributed strings with icons, so we can't turn this on. :(
|
||||
//
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return nil;
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
if (!item)
|
||||
BookmarksService::GetRootContent(getter_AddRefs(content));
|
||||
else
|
||||
content = [item contentNode];
|
||||
|
||||
nsCOMPtr<nsIContent> child;
|
||||
content->ChildAt(index, *getter_AddRefs(child));
|
||||
if ( child )
|
||||
return BookmarksService::GetWrapperFor(child);
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return NO;
|
||||
|
||||
if (!item)
|
||||
return YES; // The root node is always open.
|
||||
|
||||
BOOL isExpandable = [item isFolder];
|
||||
|
||||
// XXXben - persistence of folder open state
|
||||
// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's
|
||||
// row count. Currently the items are expanded, but the outline view continues to believe it had
|
||||
// the number of rows it had before the item was opened visible, until the view is resized.
|
||||
#if 0
|
||||
if (isExpandable) {
|
||||
PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom);
|
||||
if (isOpen)
|
||||
[mOutlineView expandItem: item];
|
||||
else
|
||||
[mOutlineView collapseItem: item];
|
||||
}
|
||||
#endif
|
||||
|
||||
return isExpandable;
|
||||
}
|
||||
|
||||
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return 0;
|
||||
|
||||
nsCOMPtr<nsIContent> content;
|
||||
if (!item)
|
||||
mBookmarks->GetRootContent(getter_AddRefs(content));
|
||||
else
|
||||
content = [item contentNode];
|
||||
|
||||
PRInt32 childCount;
|
||||
content->ChildCount(childCount);
|
||||
|
||||
return childCount;
|
||||
}
|
||||
|
||||
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
|
||||
{
|
||||
NSString *columnName = [tableColumn identifier];
|
||||
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
|
||||
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
|
||||
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
|
||||
NSMutableAttributedString *attachmentAttrString = nil;
|
||||
NSCell *attachmentAttrStringCell;
|
||||
|
||||
if ([columnName isEqualToString: @"name"]) {
|
||||
nsIContent* content = [item contentNode];
|
||||
nsAutoString nameAttr;
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
|
||||
|
||||
//Set cell's textual contents
|
||||
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWith_nsAString: nameAttr]];
|
||||
|
||||
//Create an attributed string to hold the empty attachment, then release the components.
|
||||
attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain];
|
||||
[textAttachment release];
|
||||
[fileWrapper release];
|
||||
|
||||
//Get the cell of the text attachment.
|
||||
attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell];
|
||||
|
||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
|
||||
NSImage* bookmarkImage = mBookmarks->CreateIconForBookmark(elt);
|
||||
[attachmentAttrStringCell setImage:bookmarkImage];
|
||||
|
||||
//Insert the image
|
||||
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
|
||||
|
||||
//Tweak the baseline to vertically center the text.
|
||||
[cellValue addAttribute:NSBaselineOffsetAttributeName
|
||||
value:[NSNumber numberWithFloat:-3.0]
|
||||
range:NSMakeRange(0, 1)];
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
|
||||
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
|
||||
{
|
||||
#if NOT_USED
|
||||
// ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn
|
||||
// this code back on. We have to remove the attributes from the string in order to correctly
|
||||
// set it in the DOM.
|
||||
|
||||
NSString *columnName = [tableColumn identifier];
|
||||
if ( [columnName isEqualTo:@"name"] ) {
|
||||
// remove the attributes
|
||||
int strLen = [object length];
|
||||
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object];
|
||||
[cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)];
|
||||
[cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)];
|
||||
|
||||
// extract the unicode
|
||||
strLen = [cellValue length];
|
||||
PRUnichar* buffer = new PRUnichar[strLen + 1];
|
||||
buffer[strLen] = '\0';
|
||||
if ( !buffer )
|
||||
return;
|
||||
[cellValue getCharacters: buffer];
|
||||
nsAutoString nameAttr;
|
||||
nameAttr.Adopt(buffer);
|
||||
|
||||
// stash it into the dom.
|
||||
nsIContent* content = [item contentNode];
|
||||
content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE);
|
||||
|
||||
[cellValue release];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
|
||||
{
|
||||
if (!mBookmarks)
|
||||
return NO;
|
||||
|
||||
#ifdef FILTER_DESCENDANT_ON_DRAG
|
||||
NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items);
|
||||
#else
|
||||
NSArray *toDrag = items;
|
||||
#endif
|
||||
int count = [toDrag count];
|
||||
if (count > 0) {
|
||||
// Create Pasteboard Data
|
||||
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
|
||||
|
||||
if (count == 1) {
|
||||
// if we have just one item, we add some more flavours
|
||||
[pboard declareTypes: [NSArray arrayWithObjects:
|
||||
@"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self];
|
||||
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
|
||||
|
||||
NSString* itemURL = [[toDrag objectAtIndex: 0] url];
|
||||
[pboard setString:itemURL forType: NSStringPboardType];
|
||||
[[NSURL URLWithString:itemURL] writeToPasteboard: pboard];
|
||||
// maybe construct the @"MozURLType" type here also
|
||||
}
|
||||
else {
|
||||
// multiple bookmarks. Array sof strings or NSURLs seem to
|
||||
// confuse receivers. Not sure what the correct way is.
|
||||
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
|
||||
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
|
||||
{
|
||||
NSArray* types = [[info draggingPasteboard] types];
|
||||
|
||||
// if the index is -1, deny the drop
|
||||
if (index == NSOutlineViewDropOnItemIndex)
|
||||
return NSDragOperationNone;
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"]) {
|
||||
NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
|
||||
BookmarkItem* parent;
|
||||
parent = (item) ? item : BookmarksService::GetRootItem();
|
||||
return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone;
|
||||
} else if ([types containsObject: @"MozURLType"]) {
|
||||
return NSDragOperationGeneric;
|
||||
} else if ([types containsObject: NSStringPboardType]) {
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
|
||||
{
|
||||
NSArray *types = [[info draggingPasteboard] types];
|
||||
BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem();
|
||||
|
||||
if ([types containsObject: @"MozBookmarkType"])
|
||||
{
|
||||
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
|
||||
return BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
|
||||
}
|
||||
else if ([types containsObject: @"MozURLType"])
|
||||
{
|
||||
NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
|
||||
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
|
||||
return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
|
||||
}
|
||||
else if ([types containsObject: NSStringPboardType])
|
||||
{
|
||||
NSString* draggedText = [[info draggingPasteboard] stringForType:NSStringPboardType];
|
||||
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
|
||||
return BookmarksService::PerformURLDrop(parent, beforeItem, draggedText, draggedText);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item
|
||||
{
|
||||
NSString* descStr = nil;
|
||||
NSString* hrefStr = nil;
|
||||
nsIContent* content = [item contentNode];
|
||||
nsAutoString value;
|
||||
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gDescriptionAtom, value);
|
||||
if (value.Length())
|
||||
descStr = [NSString stringWith_nsAString:value];
|
||||
|
||||
// Only description for folders
|
||||
if ([item isFolder])
|
||||
return descStr;
|
||||
|
||||
// Extract the URL from the item
|
||||
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, value);
|
||||
if (value.Length())
|
||||
hrefStr = [NSString stringWith_nsAString:value];
|
||||
|
||||
if (!hrefStr)
|
||||
return descStr;
|
||||
else if (!descStr)
|
||||
return hrefStr;
|
||||
|
||||
// Display both URL and description
|
||||
return [NSString stringWithFormat:@"%@\n%@", hrefStr, descStr];
|
||||
}
|
||||
|
||||
/*
|
||||
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item
|
||||
{
|
||||
// TODO - return (custom?) context menu for item here.
|
||||
// Note that according to HIG, there should never be disabled items in
|
||||
// a context menu - instead, items that do not apply should be removed.
|
||||
// We could nicely do that here.
|
||||
}
|
||||
*/
|
||||
|
||||
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren
|
||||
{
|
||||
if (!item)
|
||||
[mOutlineView reloadData];
|
||||
else
|
||||
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
|
||||
}
|
||||
|
||||
-(IBAction)openBookmarkInNewTab:(id)aSender
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
if ([mOutlineView numberOfSelectedRows] == 1) {
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return; // Something bad happened if we can't get prefs.
|
||||
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
nsAutoString hrefAttr;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
|
||||
|
||||
// stuff it into the string
|
||||
NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr];
|
||||
|
||||
PRBool loadInBackground;
|
||||
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
|
||||
|
||||
[mBrowserWindowController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction)openBookmarkInNewWindow:(id)aSender
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return;
|
||||
if ([mOutlineView numberOfSelectedRows] == 1) {
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return; // Something bad happened if we can't get prefs.
|
||||
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
nsAutoString hrefAttr;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
|
||||
|
||||
// stuff it into the string
|
||||
NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr];
|
||||
|
||||
PRBool loadInBackground;
|
||||
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
|
||||
|
||||
nsAutoString group;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
|
||||
if (group.IsEmpty())
|
||||
[mBrowserWindowController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground];
|
||||
else {
|
||||
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
|
||||
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: loadInBackground];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
|
||||
{
|
||||
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
|
||||
}
|
||||
|
||||
-(IBAction)showBookmarkInfo:(id)aSender
|
||||
{
|
||||
BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController];
|
||||
|
||||
int index = [mOutlineView selectedRow];
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
[bic setBookmark:item];
|
||||
|
||||
[bic showWindow:bic];
|
||||
}
|
||||
|
||||
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
|
||||
{
|
||||
BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController];
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1) {
|
||||
[mEditBookmarkButton setEnabled:NO];
|
||||
[mDeleteBookmarkButton setEnabled:NO];
|
||||
[bic close];
|
||||
}
|
||||
else {
|
||||
[mEditBookmarkButton setEnabled:YES];
|
||||
[mDeleteBookmarkButton setEnabled:YES];
|
||||
if ([[bic window] isVisible])
|
||||
[bic setBookmark:[mOutlineView itemAtRow:index]];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
|
||||
{
|
||||
int index = [mOutlineView selectedRow];
|
||||
if (index == -1)
|
||||
return NO;
|
||||
|
||||
BookmarkItem* item = [mOutlineView itemAtRow: index];
|
||||
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
|
||||
|
||||
nsAutoString group;
|
||||
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
|
||||
BOOL isGroup = !group.IsEmpty();
|
||||
|
||||
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
|
||||
// Bookmarks and Bookmark Groups can be opened in a new window
|
||||
return (isBookmark || isGroup);
|
||||
}
|
||||
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
|
||||
// Only Bookmarks can be opened in new tabs
|
||||
return isBookmark && [mBrowserWindowController newTabsAllowed];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)outlineViewItemWillExpand:(NSNotification *)notification
|
||||
{
|
||||
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
|
||||
[item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE);
|
||||
}
|
||||
|
||||
- (void)outlineViewItemWillCollapse:(NSNotification *)notification
|
||||
{
|
||||
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
|
||||
[item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation BookmarkItem
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
[mSiteIcon release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(nsIContent*)contentNode
|
||||
{
|
||||
return mContentNode;
|
||||
}
|
||||
|
||||
- (NSNumber*)contentID
|
||||
{
|
||||
PRUint32 contentID = 0;
|
||||
mContentNode->GetContentID(&contentID);
|
||||
return [NSNumber numberWithInt: contentID];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
nsCOMPtr<nsIContent> item = [self contentNode];
|
||||
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
|
||||
nsAutoString href;
|
||||
element->GetAttribute(NS_LITERAL_STRING("name"), href);
|
||||
NSString* info = [NSString stringWith_nsAString: href];
|
||||
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
|
||||
}
|
||||
|
||||
- (NSString *)url
|
||||
{
|
||||
nsCOMPtr<nsIContent> item = [self contentNode];
|
||||
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
|
||||
nsAutoString href;
|
||||
element->GetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
return [NSString stringWith_nsAString: href];
|
||||
}
|
||||
|
||||
- (void)setSiteIcon:(NSImage*)image
|
||||
{
|
||||
//NSLog(@"Setting site icon for %@", [self url]);
|
||||
[mSiteIcon autorelease];
|
||||
mSiteIcon = [image retain];
|
||||
}
|
||||
|
||||
- (NSImage*)siteIcon
|
||||
{
|
||||
return mSiteIcon;
|
||||
}
|
||||
|
||||
-(void)setContentNode: (nsIContent*)aContentNode
|
||||
{
|
||||
mContentNode = aContentNode;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)aZone
|
||||
{
|
||||
BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
|
||||
[copy setContentNode: mContentNode];
|
||||
[copy setSiteIcon: mSiteIcon];
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (BOOL)isFolder
|
||||
{
|
||||
nsCOMPtr<nsIAtom> tagName;
|
||||
mContentNode->GetTag(*getter_AddRefs(tagName));
|
||||
|
||||
return (tagName == BookmarksService::gFolderAtom);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 71 632 495 0 0 1280 1002 </string>
|
||||
<string>112 15 632 495 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>124</key>
|
||||
<string>305 659 170 144 0 0 1152 848 </string>
|
||||
<string>345 803 170 144 0 0 1280 1002 </string>
|
||||
<key>160</key>
|
||||
<string>524 326 195 666 0 0 1280 1002 </string>
|
||||
<key>28</key>
|
||||
|
|
Двоичный файл не отображается.
|
@ -196,8 +196,11 @@ class nsIDOMNode;
|
|||
- (void)stopThrobber;
|
||||
- (void)clickThrobber:(id)aSender;
|
||||
|
||||
-(void) biggerTextSize;
|
||||
-(void) smallerTextSize;
|
||||
- (void)biggerTextSize;
|
||||
- (void)smallerTextSize;
|
||||
- (void)getInfo:(id)sender;
|
||||
|
||||
- (BOOL)canGetInfo;
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar;
|
||||
|
||||
|
@ -205,6 +208,7 @@ class nsIDOMNode;
|
|||
- (IBAction)manageBookmarks: (id)aSender;
|
||||
- (void)importBookmarks: (NSString*)aURLSpec;
|
||||
- (IBAction)toggleSidebar:(id)aSender;
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection;
|
||||
|
||||
- (void)newTab:(BOOL)allowHomepage;
|
||||
- (void)closeTab;
|
||||
|
|
|
@ -850,16 +850,23 @@ static NSArray* sToolbarDefaults = nil;
|
|||
BOOL useSel = aIsFromMenu;
|
||||
if (aIsFromMenu) {
|
||||
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
|
||||
if ([mSidebarDrawer state] == NSDrawerClosedState)
|
||||
useSel = NO;
|
||||
else
|
||||
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
|
||||
useSel = NO;
|
||||
useSel = [self bookmarksAreVisible:NO];
|
||||
}
|
||||
|
||||
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle];
|
||||
}
|
||||
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection
|
||||
{
|
||||
// we should really identify the tab by identifier, not index.
|
||||
BOOL bookmarksShowing = ([mSidebarDrawer state] == NSDrawerOpenState) &&
|
||||
([mSidebarTabView tabViewItemAtIndex: 0] == [mSidebarTabView selectedTabViewItem]);
|
||||
|
||||
if (inRequireSelection)
|
||||
bookmarksShowing &= ([mSidebarBookmarksDataSource haveSelectedRow]);
|
||||
|
||||
return bookmarksShowing;
|
||||
}
|
||||
|
||||
- (IBAction)bookmarkPage: (id)aSender
|
||||
{
|
||||
|
@ -1217,6 +1224,17 @@ static NSArray* sToolbarDefaults = nil;
|
|||
markupViewer->SetTextZoom(zoom);
|
||||
}
|
||||
|
||||
- (void)getInfo:(id)sender
|
||||
{
|
||||
[mSidebarBookmarksDataSource ensureBookmarks];
|
||||
[mSidebarBookmarksDataSource showBookmarkInfo:sender];
|
||||
}
|
||||
|
||||
- (BOOL)canGetInfo
|
||||
{
|
||||
return [self bookmarksAreVisible:YES];
|
||||
}
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar
|
||||
{
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 71 632 495 0 0 1280 1002 </string>
|
||||
<string>112 15 632 495 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>124</key>
|
||||
<string>305 659 170 144 0 0 1152 848 </string>
|
||||
<string>345 803 170 144 0 0 1280 1002 </string>
|
||||
<key>160</key>
|
||||
<string>524 326 195 666 0 0 1280 1002 </string>
|
||||
<key>28</key>
|
||||
|
|
Двоичный файл не отображается.
|
@ -21,6 +21,7 @@
|
|||
feedbackLink = id;
|
||||
findAgain = id;
|
||||
findInPage = id;
|
||||
getInfo = id;
|
||||
goBack = id;
|
||||
goForward = id;
|
||||
goHome = id;
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 23 477 485 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>266</key>
|
||||
<string>483 623 277 90 0 0 1280 1002 </string>
|
||||
<key>29</key>
|
||||
<string>8 957 446 44 0 0 1280 1002 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>248.0</string>
|
||||
<key>IBGroupedObjects</key>
|
||||
<dict>
|
||||
<key>0</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
<key>1</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
</dict>
|
||||
<key>IBLastGroupID</key>
|
||||
<string>2</string>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5S66</string>
|
||||
</dict>
|
||||
</plist>
|
Двоичный файл не отображается.
|
@ -1,157 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "BrowserWindowController.h"
|
||||
#import "MVPreferencesController.h"
|
||||
#import "CHSplashScreenWindow.h"
|
||||
#import "FindDlgController.h"
|
||||
#import "CHPreferenceManager.h"
|
||||
|
||||
class BookmarksService;
|
||||
|
||||
@interface MainController : NSObject
|
||||
{
|
||||
IBOutlet NSApplication* mApplication;
|
||||
|
||||
// The following two items are used by the filter list when saving files.
|
||||
IBOutlet NSView* mFilterView;
|
||||
IBOutlet NSPopUpButton* mFilterList;
|
||||
|
||||
// IBOutlet NSMenuItem* mOfflineMenuItem;
|
||||
IBOutlet NSMenuItem* mCloseWindowMenuItem;
|
||||
IBOutlet NSMenuItem* mCloseTabMenuItem;
|
||||
IBOutlet NSMenuItem* mToggleSidebarMenuItem;
|
||||
|
||||
// The bookmarks menu.
|
||||
IBOutlet NSMenu* mBookmarksMenu;
|
||||
|
||||
IBOutlet NSMenuItem* mBookmarksToolbarMenuItem;
|
||||
IBOutlet NSMenuItem* mAddBookmarkMenuItem;
|
||||
IBOutlet NSMenuItem* mCreateBookmarksFolderMenuItem;
|
||||
IBOutlet NSMenuItem* mCreateBookmarksSeparatorMenuItem;
|
||||
|
||||
BOOL mOffline;
|
||||
|
||||
CHSplashScreenWindow* mSplashScreen;
|
||||
|
||||
CHPreferenceManager* mPreferenceManager;
|
||||
|
||||
BookmarksService* mMenuBookmarks;
|
||||
|
||||
FindDlgController* mFindDialog;
|
||||
|
||||
MVPreferencesController* mPreferencesController;
|
||||
|
||||
NSString* mStartURL;
|
||||
}
|
||||
|
||||
-(void)dealloc;
|
||||
|
||||
// File menu actions.
|
||||
-(IBAction) newWindow:(id)aSender;
|
||||
-(IBAction) openFile:(id)aSender;
|
||||
-(IBAction) openLocation:(id)aSender;
|
||||
-(IBAction) savePage:(id)aSender;
|
||||
-(IBAction) printPreview:(id)aSender;
|
||||
-(IBAction) printPage:(id)aSender;
|
||||
-(IBAction) toggleOfflineMode:(id)aSender;
|
||||
|
||||
// Edit menu actions.
|
||||
-(IBAction) findInPage:(id)aSender;
|
||||
-(IBAction) findAgain:(id)aSender;
|
||||
|
||||
// Go menu actions.
|
||||
-(IBAction) goBack:(id)aSender;
|
||||
-(IBAction) goForward:(id)aSender;
|
||||
-(IBAction) goHome:(id)aSender;
|
||||
-(IBAction) doSearch:(id)aSender;
|
||||
-(IBAction) previousTab:(id)aSender;
|
||||
-(IBAction) nextTab:(id)aSender;
|
||||
|
||||
// View menu actions.
|
||||
-(IBAction) toggleSidebar:(id)sender;
|
||||
-(IBAction) toggleBookmarksToolbar:(id)aSender;
|
||||
-(IBAction) doReload:(id)aSender;
|
||||
-(IBAction) doStop:(id)aSender;
|
||||
-(IBAction) biggerTextSize:(id)aSender;
|
||||
-(IBAction) smallerTextSize:(id)aSender;
|
||||
-(IBAction) viewSource:(id)aSender;
|
||||
|
||||
// Bookmarks menu actions.
|
||||
-(IBAction) importBookmarks:(id)aSender;
|
||||
-(IBAction) addBookmark:(id)aSender;
|
||||
-(IBAction) openMenuBookmark:(id)aSender;
|
||||
-(IBAction) manageBookmarks: (id)aSender;
|
||||
-(IBAction) addFolder:(id)aSender;
|
||||
-(IBAction) addSeparator:(id)aSender;
|
||||
|
||||
//Window menu actions
|
||||
-(IBAction) newTab:(id)aSender;
|
||||
-(IBAction) closeTab:(id)aSender;
|
||||
|
||||
//Help menu actions
|
||||
-(IBAction) infoLink:(id)aSender;
|
||||
-(IBAction) feedbackLink:(id)aSender;
|
||||
|
||||
-(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer;
|
||||
- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer:(NSString*)aReferrer;
|
||||
|
||||
- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs;
|
||||
- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs;
|
||||
- (void)fixCloseMenuItemKeyEquivalents;
|
||||
|
||||
- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost;
|
||||
|
||||
-(NSWindow*)getFrontmostBrowserWindow;
|
||||
|
||||
- (MVPreferencesController *)preferencesController;
|
||||
- (void)displayPreferencesWindow:sender;
|
||||
- (CHPreferenceManager *)preferenceManager;
|
||||
- (BOOL)isMainWindowABrowserWindow;
|
||||
|
||||
// if the main window is a browser window, return its controller, otherwise nil
|
||||
- (BrowserWindowController*)getMainWindowBrowserController;
|
||||
|
||||
- (IBAction)showAboutBox:(id)sender;
|
||||
|
||||
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle;
|
||||
|
||||
- (void)updatePrebinding;
|
||||
- (void)prebindFinished:(NSNotification *)aNotification;
|
||||
|
||||
@end
|
|
@ -1,927 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
#import "MainController.h"
|
||||
#import "BrowserWindowController.h"
|
||||
#import "BookmarksService.h"
|
||||
#import "nsCocoaBrowserService.h"
|
||||
#import "CHAboutBox.h"
|
||||
#import "CHUserDefaults.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsEmbedAPI.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
|
||||
|
||||
#ifdef _BUILD_STATIC_BIN
|
||||
#include "nsStaticComponent.h"
|
||||
nsresult PR_CALLBACK
|
||||
app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count);
|
||||
#endif
|
||||
|
||||
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
||||
|
||||
@implementation MainController
|
||||
|
||||
-(id)init
|
||||
{
|
||||
if ( (self = [super init]) ) {
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
if ([defaults boolForKey:USER_DEFAULTS_AUTOREGISTER_KEY]) {
|
||||
// This option causes us to simply initialize embedding and exit.
|
||||
NSString *path = [[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent];
|
||||
setenv("MOZILLA_FIVE_HOME", [path fileSystemRepresentation], 1);
|
||||
|
||||
#ifdef _BUILD_STATIC_BIN
|
||||
NSGetStaticModuleInfo = app_getModuleInfo;
|
||||
#endif
|
||||
|
||||
if (NS_SUCCEEDED(NS_InitEmbedding(nsnull, nsnull))) {
|
||||
// Register new chrome
|
||||
nsCOMPtr<nsIChromeRegistry> chromeReg =
|
||||
do_GetService("@mozilla.org/chrome/chrome-registry;1");
|
||||
if (chromeReg) {
|
||||
chromeReg->CheckForNewChrome();
|
||||
chromeReg = 0;
|
||||
}
|
||||
NS_TermEmbedding();
|
||||
}
|
||||
|
||||
[NSApp terminate:self];
|
||||
return self;
|
||||
}
|
||||
|
||||
NSString* url = [defaults stringForKey:USER_DEFAULTS_URL_KEY];
|
||||
mStartURL = url ? [url retain] : nil;
|
||||
mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:NSMakeRect(0,0,0,0)];
|
||||
mFindDialog = nil;
|
||||
mMenuBookmarks = nil;
|
||||
|
||||
[NSApp setServicesProvider:self];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
[mFindDialog release];
|
||||
[super dealloc];
|
||||
#if DEBUG
|
||||
NSLog(@"Main controller died");
|
||||
#endif
|
||||
}
|
||||
|
||||
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
#ifdef _BUILD_STATIC_BIN
|
||||
[self updatePrebinding];
|
||||
#endif
|
||||
// initialize if we haven't already.
|
||||
[self preferenceManager];
|
||||
|
||||
// don't open a new browser window if we already have one
|
||||
// (for example, from an GetURL Apple Event)
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow)
|
||||
[self newWindow: self];
|
||||
|
||||
[mSplashScreen close];
|
||||
|
||||
[mBookmarksMenu setAutoenablesItems: NO];
|
||||
mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil);
|
||||
mMenuBookmarks->AddObserver();
|
||||
BookmarksService::ConstructBookmarksMenu(mBookmarksMenu, nsnull);
|
||||
BookmarksService::gMainController = self;
|
||||
|
||||
// Initialize offline mode.
|
||||
mOffline = NO;
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
// Set the menu item's text to "Go Online" if we're currently
|
||||
// offline.
|
||||
/*
|
||||
if (mOffline)
|
||||
[mOfflineMenuItem setTitle: @"Go Online"]; // XXX localize me
|
||||
*/
|
||||
}
|
||||
|
||||
-(void)applicationWillTerminate: (NSNotification*)aNotification
|
||||
{
|
||||
#if DEBUG
|
||||
NSLog(@"Termination notification");
|
||||
#endif
|
||||
|
||||
// Autosave one of the windows.
|
||||
[[[mApplication mainWindow] windowController] autosaveWindowFrame];
|
||||
|
||||
mMenuBookmarks->RemoveObserver();
|
||||
delete mMenuBookmarks;
|
||||
mMenuBookmarks = nsnull;
|
||||
|
||||
// Release before calling TermEmbedding since we need to access XPCOM
|
||||
// to save preferences
|
||||
[mPreferencesController release];
|
||||
[mPreferenceManager release];
|
||||
|
||||
nsCocoaBrowserService::TermEmbedding();
|
||||
|
||||
[self autorelease];
|
||||
}
|
||||
|
||||
-(IBAction)newWindow:(id)aSender
|
||||
{
|
||||
// If we have a key window, have it autosave its dimensions before
|
||||
// we open a new window. That ensures the size ends up matching.
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] )
|
||||
[[mainWindow windowController] autosaveWindowFrame];
|
||||
|
||||
// Now open the new window.
|
||||
NSString* homePage = mStartURL ? mStartURL : [mPreferenceManager homePage:YES];
|
||||
BrowserWindowController* controller = [self openBrowserWindowWithURL:homePage andReferrer:nil];
|
||||
|
||||
if ([homePage isEqualToString: @"about:blank"])
|
||||
[controller focusURLBar];
|
||||
else
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
|
||||
// Only load the command-line specified URL for the first window we open
|
||||
if (mStartURL) {
|
||||
[mStartURL release];
|
||||
mStartURL = nil;
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction)newTab:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController newTab:NO];
|
||||
}
|
||||
|
||||
-(IBAction)closeTab:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController closeTab];
|
||||
}
|
||||
|
||||
-(IBAction) previousTab:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController previousTab];
|
||||
}
|
||||
|
||||
-(IBAction) nextTab:(id)aSender;
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController nextTab];
|
||||
}
|
||||
|
||||
-(IBAction) openFile:(id)aSender
|
||||
{
|
||||
NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease];
|
||||
[openPanel setCanChooseFiles: YES];
|
||||
[openPanel setCanChooseDirectories: NO];
|
||||
[openPanel setAllowsMultipleSelection: NO];
|
||||
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
|
||||
@"txt",@"text",
|
||||
@"gif",@"jpg",@"jpeg",@"png",@"bmp",
|
||||
nil];
|
||||
int result = [openPanel runModalForTypes: array];
|
||||
if (result == NSOKButton) {
|
||||
NSArray* urlArray = [openPanel URLs];
|
||||
if ([urlArray count] == 0)
|
||||
return;
|
||||
NSURL* url = [urlArray objectAtIndex: 0];
|
||||
// ----------------------
|
||||
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
|
||||
// ----------------------
|
||||
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController loadURL:[url absoluteString] referrer:nil activate:YES];
|
||||
else
|
||||
[self openBrowserWindowWithURL:[url absoluteString] andReferrer:nil];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction) openLocation:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self openBrowserWindowWithURL: @"about:blank" andReferrer:nil];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
else if (![browserWindow isMainWindow]) {
|
||||
[browserWindow makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
[[browserWindow windowController] performAppropriateLocationAction];
|
||||
}
|
||||
|
||||
-(IBAction) savePage:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController saveDocument: mFilterView filterList: mFilterList];
|
||||
}
|
||||
|
||||
-(IBAction) printPage:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController printDocument:aSender];
|
||||
}
|
||||
|
||||
-(IBAction) printPreview:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController printPreview];
|
||||
}
|
||||
|
||||
-(IBAction) toggleOfflineMode:(id)aSender
|
||||
{
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
ioService->SetOffline(!offline);
|
||||
mOffline = !offline;
|
||||
|
||||
// Update the menu item text.
|
||||
// Set the menu item's text to "Go Online" if we're currently
|
||||
// offline.
|
||||
/*
|
||||
if (mOffline)
|
||||
[mOfflineMenuItem setTitle: @"Go Online"];
|
||||
else
|
||||
[mOfflineMenuItem setTitle: @"Work Offline"];
|
||||
*/
|
||||
|
||||
// Indicate that we are working offline.
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
|
||||
}
|
||||
|
||||
// Edit menu actions.
|
||||
|
||||
|
||||
//
|
||||
// -findInPage
|
||||
//
|
||||
// Called in response to "Find" in edit menu. Opens the find dialog. We only keep
|
||||
// one around for the whole app to use, showing/hiding as we see fit.
|
||||
//
|
||||
-(IBAction) findInPage:(id)aSender
|
||||
{
|
||||
if ( !mFindDialog )
|
||||
mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"];
|
||||
[mFindDialog showWindow:self];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// -findAgain
|
||||
//
|
||||
// Called in response to "Find Again" in edit menu. Tells the find controller
|
||||
// to find the next occurrance of what's already been found.
|
||||
//
|
||||
-(IBAction) findAgain:(id)aSender
|
||||
{
|
||||
if ( mFindDialog )
|
||||
[mFindDialog findAgain:aSender];
|
||||
else
|
||||
NSBeep();
|
||||
}
|
||||
|
||||
-(IBAction) goBack:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController back: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) goForward:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController forward: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) doReload:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController reload: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) doStop:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController stop: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) goHome:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (browserWindow) {
|
||||
if (![browserWindow isMainWindow])
|
||||
[browserWindow makeKeyAndOrderFront:self];
|
||||
|
||||
[[browserWindow windowController] home: aSender];
|
||||
}
|
||||
else {
|
||||
[self newWindow:self];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction) doSearch:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (browserWindow) {
|
||||
if (![browserWindow isMainWindow])
|
||||
[browserWindow makeKeyAndOrderFront:self];
|
||||
|
||||
[[browserWindow windowController] performSearch: aSender];
|
||||
}
|
||||
else {
|
||||
[self newWindow:self];
|
||||
browserWindow = [self getFrontmostBrowserWindow];
|
||||
[[browserWindow windowController] performSearch: aSender];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost;
|
||||
{
|
||||
[mAddBookmarkMenuItem setEnabled:inBrowserWindowFrontmost];
|
||||
[mCreateBookmarksFolderMenuItem setEnabled:inBrowserWindowFrontmost];
|
||||
[mCreateBookmarksSeparatorMenuItem setEnabled:NO]; // separators are not implemented yet
|
||||
}
|
||||
|
||||
-(NSWindow*)getFrontmostBrowserWindow
|
||||
{
|
||||
// for some reason, [NSApp mainWindow] doesn't always work, so we have to
|
||||
// do this manually
|
||||
NSArray *windowList = [NSApp orderedWindows];
|
||||
NSWindow *foundWindow = NULL;
|
||||
|
||||
for (unsigned int i = 0; i < [windowList count]; i ++)
|
||||
{
|
||||
NSWindow* thisWindow = [windowList objectAtIndex:i];
|
||||
|
||||
if ([[thisWindow windowController] isMemberOfClass:[BrowserWindowController class]] &&
|
||||
([[thisWindow windowController] chromeMask] == 0)) // only get windows with full chrome
|
||||
{
|
||||
foundWindow = thisWindow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return foundWindow;
|
||||
}
|
||||
|
||||
// open a new URL. This method always makes a new browser window
|
||||
-(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer
|
||||
{
|
||||
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
|
||||
|
||||
// The process of creating a new tab in this brand new window loads about:blank for us as a
|
||||
// side effect of calling GetDocument(). We don't need to do it again.
|
||||
if ( [aURL isEqualToString:@"about:blank"] )
|
||||
[browser disableLoadPage];
|
||||
else
|
||||
[browser loadURL: aURL referrer:aReferrer activate:YES];
|
||||
[browser showWindow: self];
|
||||
return browser;
|
||||
}
|
||||
|
||||
// open a new URL, observing the prefs on how to behave
|
||||
- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer: (NSString*)aReferrer
|
||||
{
|
||||
// make sure we're initted
|
||||
[self preferenceManager];
|
||||
|
||||
PRBool reuseWindow = PR_FALSE;
|
||||
PRBool loadInBackground = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
|
||||
if ( prefService ) {
|
||||
prefService->GetBoolPref("browser.always_reuse_window", &reuseWindow);
|
||||
prefService->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
|
||||
}
|
||||
|
||||
// reuse the main window if there is one. The user may have closed all of
|
||||
// them or we may get this event at startup before we've had time to load
|
||||
// our window.
|
||||
BrowserWindowController* controller = [self getMainWindowBrowserController];
|
||||
if (reuseWindow && controller && [controller newTabsAllowed]) {
|
||||
[controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground];
|
||||
}
|
||||
else {
|
||||
// should use BrowserWindowController openNewWindowWithURL, but that method
|
||||
// really needs to be on the MainController
|
||||
controller = [self openBrowserWindowWithURL: inURLString andReferrer:aReferrer];
|
||||
}
|
||||
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
}
|
||||
|
||||
// Bookmarks menu actions.
|
||||
-(IBAction) importBookmarks:(id)aSender
|
||||
{
|
||||
// IE favorites: ~/Library/Preferences/Explorer/Favorites.html
|
||||
// Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html
|
||||
// For now, open the panel to IE's favorites.
|
||||
NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease];
|
||||
[openPanel setCanChooseFiles: YES];
|
||||
[openPanel setCanChooseDirectories: NO];
|
||||
[openPanel setAllowsMultipleSelection: NO];
|
||||
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"xml", nil];
|
||||
int result = [openPanel runModalForDirectory: @"~/Library/Preferences/Explorer/"
|
||||
file: @"Favorites.html"
|
||||
types: array];
|
||||
if (result == NSOKButton) {
|
||||
NSArray* urlArray = [openPanel URLs];
|
||||
if ([urlArray count] == 0)
|
||||
return;
|
||||
NSURL* url = [urlArray objectAtIndex: 0];
|
||||
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self newWindow: self];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
|
||||
[[browserWindow windowController] importBookmarks: [url absoluteString]];
|
||||
}
|
||||
}
|
||||
|
||||
-(IBAction) addBookmark:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController addBookmarkExtended: YES isFolder: NO URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(IBAction) addFolder:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController addBookmarkExtended: YES isFolder: YES URL:nil title:nil];
|
||||
}
|
||||
|
||||
-(IBAction) addSeparator:(id)aSender
|
||||
{
|
||||
NSLog(@"Separators not implemented yet");
|
||||
}
|
||||
|
||||
-(IBAction) openMenuBookmark:(id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self openBrowserWindowWithURL: @"about:blank" andReferrer:nil];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
|
||||
BookmarksService::OpenMenuBookmark([browserWindow windowController], aSender);
|
||||
}
|
||||
|
||||
-(IBAction)manageBookmarks: (id)aSender
|
||||
{
|
||||
NSWindow* browserWindow = [self getFrontmostBrowserWindow];
|
||||
if (!browserWindow) {
|
||||
[self newWindow:self];
|
||||
browserWindow = [mApplication mainWindow];
|
||||
}
|
||||
|
||||
[[browserWindow windowController] manageBookmarks: aSender];
|
||||
}
|
||||
|
||||
- (CHPreferenceManager *)preferenceManager
|
||||
{
|
||||
if (!mPreferenceManager)
|
||||
mPreferenceManager = [[CHPreferenceManager sharedInstance] retain];
|
||||
return mPreferenceManager;
|
||||
}
|
||||
|
||||
- (MVPreferencesController *)preferencesController
|
||||
{
|
||||
if (!mPreferencesController) {
|
||||
mPreferencesController = [[MVPreferencesController sharedInstance] retain];
|
||||
}
|
||||
return mPreferencesController;
|
||||
}
|
||||
|
||||
- (void)displayPreferencesWindow:sender
|
||||
{
|
||||
[[self preferencesController] showPreferences:nil] ;
|
||||
}
|
||||
|
||||
- (IBAction)showAboutBox:(id)sender
|
||||
{
|
||||
[[CHAboutBox sharedInstance] showPanel:sender];
|
||||
}
|
||||
|
||||
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
||||
{
|
||||
/*
|
||||
// On the off chance that we're getting this message off a launch,
|
||||
// we may not have initialized our embedded mozilla. So check here,
|
||||
// and if it's not initialized, do it now.
|
||||
[self preferenceManager];
|
||||
|
||||
// Make sure it's a browser window b/c "about box" can also become main window.
|
||||
if ([self isMainWindowABrowserWindow]) {
|
||||
[[[mApplication mainWindow] windowController] loadURL:[[NSURL fileURLWithPath:filename] absoluteString]];
|
||||
}
|
||||
else {
|
||||
[self openBrowserWindowWithURL:[[NSURL fileURLWithPath:filename] absoluteString]];
|
||||
}
|
||||
*/
|
||||
[self openNewWindowOrTabWithURL:[[NSURL fileURLWithPath:filename] absoluteString] andReferrer:nil];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (IBAction)biggerTextSize:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController biggerTextSize];
|
||||
}
|
||||
|
||||
- (IBAction)smallerTextSize:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController smallerTextSize];
|
||||
}
|
||||
|
||||
-(IBAction) viewSource:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController viewSource: aSender];
|
||||
}
|
||||
|
||||
-(BOOL)isMainWindowABrowserWindow
|
||||
{
|
||||
// see also getFrontmostBrowserWindow
|
||||
return [[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]];
|
||||
}
|
||||
|
||||
- (BrowserWindowController*)getMainWindowBrowserController
|
||||
{
|
||||
NSWindowController* mainWindowController = [[mApplication mainWindow] windowController];
|
||||
if (mainWindowController && [mainWindowController isMemberOfClass:[BrowserWindowController class]])
|
||||
return (BrowserWindowController*)mainWindowController;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs
|
||||
{
|
||||
// capitalization of the key equivalent affects whether the shift modifer is used.
|
||||
[mCloseWindowMenuItem setKeyEquivalent: inHaveTabs ? @"W" : @"w"];
|
||||
}
|
||||
|
||||
- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs
|
||||
{
|
||||
if (inHaveTabs) {
|
||||
[mCloseTabMenuItem setKeyEquivalent:@"w"];
|
||||
[mCloseTabMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
|
||||
}
|
||||
else {
|
||||
[mCloseTabMenuItem setKeyEquivalent:@""];
|
||||
[mCloseTabMenuItem setKeyEquivalentModifierMask:0];
|
||||
}
|
||||
}
|
||||
|
||||
// see if we have a window with tabs open, and adjust the key equivalents for
|
||||
// Close Tab/Close Window accordingly
|
||||
- (void)fixCloseMenuItemKeyEquivalents
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController) {
|
||||
BOOL windowWithMultipleTabs = ([[browserController getTabBrowser] numberOfTabViewItems] > 1);
|
||||
[self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs];
|
||||
[self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
|
||||
// disable items that aren't relevant if there's no main browser window open
|
||||
SEL action = [aMenuItem action];
|
||||
|
||||
//NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action);
|
||||
|
||||
if (action == @selector(printPage:) ||
|
||||
/* ... many more items go here ... */
|
||||
/* action == @selector(goHome:) || */ // always enabled
|
||||
/* action == @selector(doSearch:) || */ // always enabled
|
||||
action == @selector(findInPage:) ||
|
||||
action == @selector(doReload:) ||
|
||||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(savePage:)) {
|
||||
if (browserController)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (action == @selector(newTab:)) {
|
||||
if (browserController && [browserController newTabsAllowed])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
// check if someone has previously done a find before allowing findAgain to be enabled
|
||||
if (action == @selector(findAgain:)) {
|
||||
if (browserController)
|
||||
return (mFindDialog && [[mFindDialog getSearchText] length] > 0);
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// check what the state of the personal toolbar should be, but only if there is a browser
|
||||
// window open. Popup windows that have the personal toolbar removed should always gray
|
||||
// out this menu.
|
||||
if (action == @selector(toggleBookmarksToolbar:)) {
|
||||
if (browserController) {
|
||||
NSView* bookmarkToolbar = [browserController bookmarksToolbar];
|
||||
if ( bookmarkToolbar ) {
|
||||
float height = [bookmarkToolbar frame].size.height;
|
||||
BOOL toolbarShowing = (height > 0);
|
||||
if (toolbarShowing)
|
||||
[mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Hide Bookmarks Toolbar",@"")];
|
||||
else
|
||||
[mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Show Bookmarks Toolbar",@"")];
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (action == @selector(toggleSidebar:)) {
|
||||
if (browserController) {
|
||||
NSDrawer *sidebar = [browserController sidebarDrawer];
|
||||
if (sidebar) {
|
||||
int sidebarState = [sidebar state];
|
||||
if (sidebarState == NSDrawerOpenState)
|
||||
[mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Hide Sidebar",@"")];
|
||||
else
|
||||
[mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Show Sidebar",@"")];
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:)))
|
||||
{
|
||||
if (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(doStop:) ) {
|
||||
if (browserController)
|
||||
return [[browserController getBrowserWrapper] isBusy];
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
if (browserController) {
|
||||
CHBrowserView* browserView = [[browserController getBrowserWrapper] getBrowserView];
|
||||
if (action == @selector(goBack:))
|
||||
return [browserView canGoBack];
|
||||
if (action == @selector(goForward:))
|
||||
return [browserView canGoForward];
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// default return
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(IBAction) toggleSidebar:(id)sender
|
||||
{
|
||||
BrowserWindowController *browserController = [self getMainWindowBrowserController];
|
||||
if (!browserController) return;
|
||||
|
||||
[browserController toggleSidebar:sender];
|
||||
}
|
||||
|
||||
-(IBAction) toggleBookmarksToolbar:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (!browserController) return;
|
||||
|
||||
float height = [[browserController bookmarksToolbar] frame].size.height;
|
||||
BOOL showToolbar = (BOOL)(!(height > 0));
|
||||
|
||||
[[browserController bookmarksToolbar] showBookmarksToolbar: showToolbar];
|
||||
|
||||
// save prefs here
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults setInteger: ((showToolbar) ? 0 : 1) forKey: USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY];
|
||||
}
|
||||
|
||||
-(IBAction) infoLink:(id)aSender
|
||||
{
|
||||
NSString* pageToLoad = NSLocalizedStringFromTable(@"InfoPageDefault", @"WebsiteDefaults", nil);
|
||||
if (![pageToLoad isEqualToString:@"InfoPageDefault"])
|
||||
[self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil];
|
||||
}
|
||||
|
||||
-(IBAction) feedbackLink:(id)aSender
|
||||
{
|
||||
NSString *pageToLoad = NSLocalizedStringFromTable(@"FeedbackPageDefault", @"WebsiteDefaults", nil);
|
||||
if (![pageToLoad isEqualToString:@"FeedbackPageDefault"])
|
||||
[self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil];
|
||||
}
|
||||
|
||||
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle
|
||||
{
|
||||
NSImage* image;
|
||||
NSSize titleSize, imageSize;
|
||||
NSRect imageRect;
|
||||
NSDictionary* stringAttrs;
|
||||
|
||||
// get the size of the new image we are creating
|
||||
titleSize = [aTitle sizeWithAttributes:nil];
|
||||
imageSize = NSMakeSize(titleSize.width + [aIcon size].width,
|
||||
titleSize.height > [aIcon size].height ?
|
||||
titleSize.height : [aIcon size].height);
|
||||
|
||||
// create the image and lock drawing focus on it
|
||||
image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
|
||||
[image lockFocus];
|
||||
|
||||
// draw the image and title in image with translucency
|
||||
imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height);
|
||||
[aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8];
|
||||
|
||||
stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8]
|
||||
forKey: NSForegroundColorAttributeName];
|
||||
[aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs];
|
||||
|
||||
[image unlockFocus];
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApp hasVisibleWindows:(BOOL)flag
|
||||
{
|
||||
// If AppKit knows what to do, let it.
|
||||
if (flag)
|
||||
return YES;
|
||||
|
||||
// If window available, wake it up. |mainWindow| should always be null.
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if (!mainWindow)
|
||||
[self newWindow:self];
|
||||
else { // Don't think this will ever happen, but just in case
|
||||
if ([[mainWindow windowController]respondsToSelector:@selector(showWindow:)])
|
||||
[[mainWindow windowController] showWindow:self];
|
||||
else
|
||||
[self newWindow:self];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) applicationDidChangeScreenParameters:(NSNotification *)aNotification
|
||||
{
|
||||
[NSApp makeWindowsPerform:@selector(display) inOrder:YES];
|
||||
}
|
||||
|
||||
- (void) updatePrebinding
|
||||
{
|
||||
// Check our prebinding status. If we didn't launch prebound,
|
||||
// fork the update script.
|
||||
|
||||
if (!_dyld_launched_prebound()) {
|
||||
NSLog(@"Not prebound, launching update script");
|
||||
NSTask* aTask = [[NSTask alloc] init];
|
||||
NSArray* args = [NSArray arrayWithObject: @"redo-prebinding.sh"];
|
||||
|
||||
[aTask setCurrentDirectoryPath:[[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]];
|
||||
[aTask setLaunchPath:@"/bin/sh"];
|
||||
[aTask setArguments:args];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||
selector:@selector(prebindFinished:)
|
||||
name:NSTaskDidTerminateNotification
|
||||
object: nil];
|
||||
|
||||
[aTask launch];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)prebindFinished:(NSNotification *)aNotification
|
||||
{
|
||||
[[aNotification object] release];
|
||||
}
|
||||
|
||||
// services
|
||||
|
||||
- (void)openURL:(NSPasteboard *) pboard userData:(NSString *) userData error:(NSString **) error
|
||||
{
|
||||
NSMutableString *urlString = [[[NSMutableString alloc] init] autorelease];
|
||||
if ( !urlString )
|
||||
return;
|
||||
|
||||
NSArray* types = [pboard types];
|
||||
if (![types containsObject:NSStringPboardType]) {
|
||||
*error = NSLocalizedString(@"Error: couldn't open URL.",
|
||||
@"pboard couldn't give URL string.");
|
||||
return;
|
||||
}
|
||||
NSString* pboardString = [pboard stringForType:NSStringPboardType];
|
||||
if (!pboardString) {
|
||||
*error = NSLocalizedString(@"Error: couldn't open URL.",
|
||||
@"pboard couldn't give URL string.");
|
||||
return;
|
||||
}
|
||||
NSScanner* scanner = [NSScanner scannerWithString:pboardString];
|
||||
[scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&urlString];
|
||||
while(![scanner isAtEnd]) {
|
||||
NSString *tmpString;
|
||||
[scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&tmpString];
|
||||
[urlString appendString:tmpString];
|
||||
}
|
||||
|
||||
[self openNewWindowOrTabWithURL:urlString andReferrer:nil];
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,79 +0,0 @@
|
|||
{
|
||||
IBClasses = (
|
||||
{
|
||||
CLASS = BrowserToolbarController;
|
||||
LANGUAGE = ObjC;
|
||||
SUPERCLASS = ToolbarController;
|
||||
},
|
||||
{CLASS = CHGoMenu; LANGUAGE = ObjC; SUPERCLASS = NSMenu; },
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
ACTIONS = {
|
||||
addBookmark = id;
|
||||
addFolder = id;
|
||||
addSeparator = id;
|
||||
biggerTextSize = id;
|
||||
closeTab = id;
|
||||
displayPreferencesWindow = id;
|
||||
doReload = id;
|
||||
doSearch = id;
|
||||
doStop = id;
|
||||
feedbackLink = id;
|
||||
findAgain = id;
|
||||
findInPage = id;
|
||||
goBack = id;
|
||||
goForward = id;
|
||||
goHome = id;
|
||||
importBookmarks = id;
|
||||
infoLink = id;
|
||||
manageBookmarks = id;
|
||||
newTab = id;
|
||||
newWindow = id;
|
||||
nextTab = id;
|
||||
openFile = id;
|
||||
openLocation = id;
|
||||
openMenuBookmark = id;
|
||||
previousTab = id;
|
||||
printPage = id;
|
||||
printPreview = id;
|
||||
savePage = id;
|
||||
showAboutBox = id;
|
||||
smallerTextSize = id;
|
||||
toggleBookmarksToolbar = id;
|
||||
toggleOfflineMode = id;
|
||||
toggleSidebar = id;
|
||||
viewSource = id;
|
||||
};
|
||||
CLASS = MainController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {
|
||||
mAddBookmarkMenuItem = NSMenuItem;
|
||||
mApplication = NSApplication;
|
||||
mBookmarksMenu = NSMenu;
|
||||
mBookmarksToolbarMenuItem = NSMenuItem;
|
||||
mCloseTabMenuItem = NSMenuItem;
|
||||
mCloseWindowMenuItem = NSMenuItem;
|
||||
mCreateBookmarksFolderMenuItem = NSMenuItem;
|
||||
mCreateBookmarksSeparatorMenuItem = NSMenuItem;
|
||||
mFilterList = NSPopUpButton;
|
||||
mFilterView = NSView;
|
||||
mToggleSidebarMenuItem = NSMenuItem;
|
||||
};
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {load = id; };
|
||||
CLASS = MyBrowserView;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {progress = id; progressSuper = id; status = id; urlbar = id; };
|
||||
SUPERCLASS = NSView;
|
||||
},
|
||||
{
|
||||
CLASS = ToolbarController;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {mBrowserView = id; mWindow = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 23 477 485 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>266</key>
|
||||
<string>483 623 277 90 0 0 1280 1002 </string>
|
||||
<key>29</key>
|
||||
<string>8 957 446 44 0 0 1280 1002 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>248.0</string>
|
||||
<key>IBGroupedObjects</key>
|
||||
<dict>
|
||||
<key>0</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
<key>1</key>
|
||||
<array>
|
||||
<string>0</string>
|
||||
<string>0</string>
|
||||
</array>
|
||||
</dict>
|
||||
<key>IBLastGroupID</key>
|
||||
<string>2</string>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5S66</string>
|
||||
</dict>
|
||||
</plist>
|
Двоичный файл не отображается.
|
@ -3,11 +3,11 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 71 632 495 0 0 1280 1002 </string>
|
||||
<string>112 15 632 495 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>124</key>
|
||||
<string>305 659 170 144 0 0 1152 848 </string>
|
||||
<string>345 803 170 144 0 0 1280 1002 </string>
|
||||
<key>160</key>
|
||||
<string>524 326 195 666 0 0 1280 1002 </string>
|
||||
<key>28</key>
|
||||
|
|
Двоичные данные
chimera/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичные данные
chimera/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичный файл не отображается.
|
@ -21,6 +21,7 @@
|
|||
feedbackLink = id;
|
||||
findAgain = id;
|
||||
findInPage = id;
|
||||
getInfo = id;
|
||||
goBack = id;
|
||||
goForward = id;
|
||||
goHome = id;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>60 23 477 485 0 0 1280 1002 </string>
|
||||
<string>108 107 477 485 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>266</key>
|
||||
|
@ -29,6 +29,10 @@
|
|||
</dict>
|
||||
<key>IBLastGroupID</key>
|
||||
<string>2</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>29</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5S66</string>
|
||||
</dict>
|
||||
|
|
Двоичный файл не отображается.
|
@ -94,6 +94,7 @@ class BookmarksService;
|
|||
// Edit menu actions.
|
||||
-(IBAction) findInPage:(id)aSender;
|
||||
-(IBAction) findAgain:(id)aSender;
|
||||
-(IBAction) getInfo:(id)aSender;
|
||||
|
||||
// Go menu actions.
|
||||
-(IBAction) goBack:(id)aSender;
|
||||
|
|
|
@ -345,6 +345,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
NSBeep();
|
||||
}
|
||||
|
||||
-(IBAction) getInfo:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
if (browserController)
|
||||
[browserController getInfo: aSender];
|
||||
}
|
||||
|
||||
-(IBAction) goBack:(id)aSender
|
||||
{
|
||||
BrowserWindowController* browserController = [self getMainWindowBrowserController];
|
||||
|
@ -679,25 +686,17 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(savePage:)) {
|
||||
if (browserController)
|
||||
return YES;
|
||||
return NO;
|
||||
action == @selector(savePage:))
|
||||
{
|
||||
return (browserController != nil);
|
||||
}
|
||||
|
||||
if (action == @selector(newTab:)) {
|
||||
if (browserController && [browserController newTabsAllowed])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
if (action == @selector(newTab:))
|
||||
return (browserController && [browserController newTabsAllowed]);
|
||||
|
||||
// check if someone has previously done a find before allowing findAgain to be enabled
|
||||
if (action == @selector(findAgain:)) {
|
||||
if (browserController)
|
||||
return (mFindDialog && [[mFindDialog getSearchText] length] > 0);
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
if (action == @selector(findAgain:))
|
||||
return (browserController && mFindDialog && [[mFindDialog getSearchText] length] > 0);
|
||||
|
||||
// check what the state of the personal toolbar should be, but only if there is a browser
|
||||
// window open. Popup windows that have the personal toolbar removed should always gray
|
||||
|
@ -739,24 +738,20 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(getInfo:) )
|
||||
return (browserController && [browserController canGetInfo]);
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:)))
|
||||
action == @selector(nextTab:) ||
|
||||
action == @selector(previousTab:)))
|
||||
{
|
||||
if (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
return (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1);
|
||||
}
|
||||
|
||||
if ( action == @selector(doStop:) ) {
|
||||
if (browserController)
|
||||
return [[browserController getBrowserWrapper] isBusy];
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
if ( action == @selector(doStop:) )
|
||||
return (browserController && [[browserController getBrowserWrapper] isBusy]);
|
||||
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
if (browserController) {
|
||||
CHBrowserView* browserView = [[browserController getBrowserWrapper] getBrowserView];
|
||||
|
|
|
@ -79,11 +79,12 @@ class BookmarksService;
|
|||
|
||||
-(NSString*)resolveKeyword:(NSString*)aKeyword;
|
||||
|
||||
-(IBAction)openBookmarkInNewTab:(id)aSender;
|
||||
-(IBAction)openBookmarkInNewWindow:(id)aSender;
|
||||
- (IBAction)openBookmarkInNewTab:(id)aSender;
|
||||
- (IBAction)openBookmarkInNewWindow:(id)aSender;
|
||||
|
||||
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
|
||||
-(IBAction)showBookmarkInfo:(id)aSender;
|
||||
- (void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
|
||||
- (IBAction)showBookmarkInfo:(id)aSender;
|
||||
- (BOOL)haveSelectedRow;
|
||||
|
||||
// Datasource methods.
|
||||
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
|
||||
|
|
|
@ -790,6 +790,11 @@
|
|||
[bic showWindow:bic];
|
||||
}
|
||||
|
||||
- (BOOL)haveSelectedRow
|
||||
{
|
||||
return ([mOutlineView selectedRow] != -1);
|
||||
}
|
||||
|
||||
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
|
||||
{
|
||||
BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController];
|
||||
|
|
|
@ -196,8 +196,11 @@ class nsIDOMNode;
|
|||
- (void)stopThrobber;
|
||||
- (void)clickThrobber:(id)aSender;
|
||||
|
||||
-(void) biggerTextSize;
|
||||
-(void) smallerTextSize;
|
||||
- (void)biggerTextSize;
|
||||
- (void)smallerTextSize;
|
||||
- (void)getInfo:(id)sender;
|
||||
|
||||
- (BOOL)canGetInfo;
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar;
|
||||
|
||||
|
@ -205,6 +208,7 @@ class nsIDOMNode;
|
|||
- (IBAction)manageBookmarks: (id)aSender;
|
||||
- (void)importBookmarks: (NSString*)aURLSpec;
|
||||
- (IBAction)toggleSidebar:(id)aSender;
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection;
|
||||
|
||||
- (void)newTab:(BOOL)allowHomepage;
|
||||
- (void)closeTab;
|
||||
|
|
|
@ -850,16 +850,23 @@ static NSArray* sToolbarDefaults = nil;
|
|||
BOOL useSel = aIsFromMenu;
|
||||
if (aIsFromMenu) {
|
||||
// Use selection only if the sidebar is open and the bookmarks panel is displaying.
|
||||
if ([mSidebarDrawer state] == NSDrawerClosedState)
|
||||
useSel = NO;
|
||||
else
|
||||
if ([mSidebarTabView tabViewItemAtIndex: 0] != [mSidebarTabView selectedTabViewItem])
|
||||
useSel = NO;
|
||||
useSel = [self bookmarksAreVisible:NO];
|
||||
}
|
||||
|
||||
[mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle];
|
||||
}
|
||||
|
||||
- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection
|
||||
{
|
||||
// we should really identify the tab by identifier, not index.
|
||||
BOOL bookmarksShowing = ([mSidebarDrawer state] == NSDrawerOpenState) &&
|
||||
([mSidebarTabView tabViewItemAtIndex: 0] == [mSidebarTabView selectedTabViewItem]);
|
||||
|
||||
if (inRequireSelection)
|
||||
bookmarksShowing &= ([mSidebarBookmarksDataSource haveSelectedRow]);
|
||||
|
||||
return bookmarksShowing;
|
||||
}
|
||||
|
||||
- (IBAction)bookmarkPage: (id)aSender
|
||||
{
|
||||
|
@ -1217,6 +1224,17 @@ static NSArray* sToolbarDefaults = nil;
|
|||
markupViewer->SetTextZoom(zoom);
|
||||
}
|
||||
|
||||
- (void)getInfo:(id)sender
|
||||
{
|
||||
[mSidebarBookmarksDataSource ensureBookmarks];
|
||||
[mSidebarBookmarksDataSource showBookmarkInfo:sender];
|
||||
}
|
||||
|
||||
- (BOOL)canGetInfo
|
||||
{
|
||||
return [self bookmarksAreVisible:YES];
|
||||
}
|
||||
|
||||
- (BOOL)shouldShowBookmarkToolbar
|
||||
{
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
|
Загрузка…
Ссылка в новой задаче