Hook up bookmarks context menu items for the sidebar view. The behaviour is a little broken in that you need to actually have selected something before any of these work, but it was like that before I touched it, and we can fix that. I'm just hooking up functionality. More specifically:

- Delete
- Open in New Window
- Open in New Tab
- New Folde
This commit is contained in:
ben%netscape.com 2002-06-02 08:28:10 +00:00
parent 724a445970
commit 181ca4c488
26 changed files with 230 additions and 18 deletions

View File

@ -81,6 +81,9 @@ class nsIAtom;
-(IBAction)cancelRenameBookmarkSheet:(id)sender;
-(IBAction)doRenameBookmarkSheet:(id)sender;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -45,6 +45,7 @@
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMCharacterData.h"
#include "nsIPrefBranch.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsIFile.h"
@ -635,6 +636,49 @@
mBookmarks->BookmarkChanged([item contentNode]);
}
-(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 stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
}
}
@end
@implementation BookmarkItem

View File

@ -9,6 +9,8 @@
cancelRenameBookmarkSheet = id;
deleteBookmarks = id;
doRenameBookmarkSheet = id;
openBookmarkInNewTab = id;
openBookmarkInNewWindow = id;
};
CLASS = BookmarksDataSource;
LANGUAGE = ObjC;

View File

@ -7,9 +7,9 @@
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 656 170 180 0 0 1152 848 </string>
<string>345 807 170 180 0 0 1280 1002 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>564 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<key>297</key>
@ -17,7 +17,7 @@
<key>314</key>
<string>218 602 139 66 0 0 1152 848 </string>
<key>336</key>
<string>630 666 200 132 0 0 1152 848 </string>
<string>715 809 200 132 0 0 1280 1002 </string>
<key>365</key>
<string>22 587 93 162 0 0 1152 848 </string>
<key>463</key>
@ -43,7 +43,9 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>336</integer>
<integer>160</integer>
<integer>124</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>

Binary file not shown.

View File

@ -9,6 +9,8 @@
cancelRenameBookmarkSheet = id;
deleteBookmarks = id;
doRenameBookmarkSheet = id;
openBookmarkInNewTab = id;
openBookmarkInNewWindow = id;
};
CLASS = BookmarksDataSource;
LANGUAGE = ObjC;

View File

@ -7,9 +7,9 @@
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 656 170 180 0 0 1152 848 </string>
<string>345 807 170 180 0 0 1280 1002 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>564 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<key>297</key>
@ -17,7 +17,7 @@
<key>314</key>
<string>218 602 139 66 0 0 1152 848 </string>
<key>336</key>
<string>630 666 200 132 0 0 1152 848 </string>
<string>715 809 200 132 0 0 1280 1002 </string>
<key>365</key>
<string>22 587 93 162 0 0 1152 848 </string>
<key>463</key>
@ -43,7 +43,9 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>336</integer>
<integer>160</integer>
<integer>124</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>

Binary file not shown.

View File

@ -9,6 +9,8 @@
cancelRenameBookmarkSheet = id;
deleteBookmarks = id;
doRenameBookmarkSheet = id;
openBookmarkInNewTab = id;
openBookmarkInNewWindow = id;
};
CLASS = BookmarksDataSource;
LANGUAGE = ObjC;

View File

@ -7,9 +7,9 @@
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 656 170 180 0 0 1152 848 </string>
<string>345 807 170 180 0 0 1280 1002 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>564 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<key>297</key>
@ -17,7 +17,7 @@
<key>314</key>
<string>218 602 139 66 0 0 1152 848 </string>
<key>336</key>
<string>630 666 200 132 0 0 1152 848 </string>
<string>715 809 200 132 0 0 1280 1002 </string>
<key>365</key>
<string>22 587 93 162 0 0 1152 848 </string>
<key>463</key>
@ -43,7 +43,9 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>336</integer>
<integer>160</integer>
<integer>124</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>

View File

@ -81,6 +81,9 @@ class nsIAtom;
-(IBAction)cancelRenameBookmarkSheet:(id)sender;
-(IBAction)doRenameBookmarkSheet:(id)sender;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -45,6 +45,7 @@
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMCharacterData.h"
#include "nsIPrefBranch.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsIFile.h"
@ -635,6 +636,49 @@
mBookmarks->BookmarkChanged([item contentNode]);
}
-(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 stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
}
}
@end
@implementation BookmarkItem

View File

@ -81,6 +81,9 @@ class nsIAtom;
-(IBAction)cancelRenameBookmarkSheet:(id)sender;
-(IBAction)doRenameBookmarkSheet:(id)sender;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -45,6 +45,7 @@
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMCharacterData.h"
#include "nsIPrefBranch.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsIFile.h"
@ -635,6 +636,49 @@
mBookmarks->BookmarkChanged([item contentNode]);
}
-(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 stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
}
}
@end
@implementation BookmarkItem

View File

@ -9,6 +9,8 @@
cancelRenameBookmarkSheet = id;
deleteBookmarks = id;
doRenameBookmarkSheet = id;
openBookmarkInNewTab = id;
openBookmarkInNewWindow = id;
};
CLASS = BookmarksDataSource;
LANGUAGE = ObjC;

View File

@ -7,9 +7,9 @@
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 656 170 180 0 0 1152 848 </string>
<string>345 807 170 180 0 0 1280 1002 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>564 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<key>297</key>
@ -17,7 +17,7 @@
<key>314</key>
<string>218 602 139 66 0 0 1152 848 </string>
<key>336</key>
<string>630 666 200 132 0 0 1152 848 </string>
<string>715 809 200 132 0 0 1280 1002 </string>
<key>365</key>
<string>22 587 93 162 0 0 1152 848 </string>
<key>463</key>
@ -43,7 +43,9 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>336</integer>
<integer>160</integer>
<integer>124</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>

Binary file not shown.

View File

@ -9,6 +9,8 @@
cancelRenameBookmarkSheet = id;
deleteBookmarks = id;
doRenameBookmarkSheet = id;
openBookmarkInNewTab = id;
openBookmarkInNewWindow = id;
};
CLASS = BookmarksDataSource;
LANGUAGE = ObjC;

View File

@ -7,9 +7,9 @@
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 656 170 180 0 0 1152 848 </string>
<string>345 807 170 180 0 0 1280 1002 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>564 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<key>297</key>
@ -17,7 +17,7 @@
<key>314</key>
<string>218 602 139 66 0 0 1152 848 </string>
<key>336</key>
<string>630 666 200 132 0 0 1152 848 </string>
<string>715 809 200 132 0 0 1280 1002 </string>
<key>365</key>
<string>22 587 93 162 0 0 1152 848 </string>
<key>463</key>
@ -43,7 +43,9 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>336</integer>
<integer>160</integer>
<integer>124</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>

Binary file not shown.

View File

@ -9,6 +9,8 @@
cancelRenameBookmarkSheet = id;
deleteBookmarks = id;
doRenameBookmarkSheet = id;
openBookmarkInNewTab = id;
openBookmarkInNewWindow = id;
};
CLASS = BookmarksDataSource;
LANGUAGE = ObjC;

View File

@ -7,9 +7,9 @@
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 656 170 180 0 0 1152 848 </string>
<string>345 807 170 180 0 0 1280 1002 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>564 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<key>297</key>
@ -17,7 +17,7 @@
<key>314</key>
<string>218 602 139 66 0 0 1152 848 </string>
<key>336</key>
<string>630 666 200 132 0 0 1152 848 </string>
<string>715 809 200 132 0 0 1280 1002 </string>
<key>365</key>
<string>22 587 93 162 0 0 1152 848 </string>
<key>463</key>
@ -43,7 +43,9 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>336</integer>
<integer>160</integer>
<integer>124</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>

View File

@ -81,6 +81,9 @@ class nsIAtom;
-(IBAction)cancelRenameBookmarkSheet:(id)sender;
-(IBAction)doRenameBookmarkSheet:(id)sender;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;

View File

@ -45,6 +45,7 @@
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMCharacterData.h"
#include "nsIPrefBranch.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsIFile.h"
@ -635,6 +636,49 @@
mBookmarks->BookmarkChanged([item contentNode]);
}
-(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 stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
[mBrowserWindowController openNewWindowWithURL: urlToLoad loadInBackground: NO];
}
}
@end
@implementation BookmarkItem