Fixing history tab in sidebar to show history. Also hiding history tab by default.

This commit is contained in:
sfraser%netscape.com 2002-06-27 22:03:30 +00:00
parent fe24aa0f3d
commit 8d572e2c8e
42 changed files with 832 additions and 274 deletions

View File

@ -112,6 +112,7 @@
{
CLASS = CHHistoryDataSource;
LANGUAGE = ObjC;
OUTLETS = {mBrowserWindowController = id; };
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },

View File

@ -3,15 +3,15 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>41 39 480 309 0 0 1152 746 </string>
<string>31 46 632 495 0 0 1280 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 659 170 144 0 0 1152 848 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>523 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<string>523 439 195 457 0 0 1280 1002 </string>
<key>297</key>
<string>233 646 176 162 0 0 1152 848 </string>
<key>314</key>
@ -41,6 +41,10 @@
<array>
<integer>497</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>160</integer>
</array>
<key>IBSystem Version</key>
<string>5S66</string>
</dict>

Binary file not shown.

View File

@ -967,8 +967,10 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
#endif
// remove default tab from nib
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
// insert the tabs we want
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
#if USE_SEARCH_ITEM
@ -978,6 +980,17 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
#endif
BOOL showHistory = NO;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (pref) {
PRBool historyPref = PR_FALSE;
if (NS_SUCCEEDED(pref->GetBoolPref("chimera.show_history", &historyPref)))
showHistory = historyPref ? YES : NO;
}
if (!showHistory)
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:1]];
[mSidebarTabView selectFirstTabViewItem:self];
}

View File

@ -10,8 +10,13 @@
#import "CHRDFOutlineViewDataSource.h"
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource {
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource
{
IBOutlet id mBrowserWindowController;
}
-(IBAction)openHistoryItem: (id)aSender;
@end

View File

@ -7,11 +7,15 @@
//
#import "CHHistoryDataSource.h"
#import "CHBrowserView.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFResource.h"
#include "nsXPIDLString.h"
#include "nsString.h"
#include "nsComponentManagerUtils.h"
@implementation CHHistoryDataSource
@ -26,7 +30,123 @@
mRDFService->GetResource("NC:HistoryByDate", &mRootResource);
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openHistoryItem:)];
[mOutlineView reloadData];
}
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
if (!mDataSource || !aItem)
return nil;
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return nil;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: literalValue.get() length:literalValue.Length()]];
if ([columnPropertyURI isEqualToString: @"http://home.netscape.com/NC-rdf#Name"])
{
NSMutableAttributedString *attachmentAttrString = nil;
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSCell *attachmentAttrStringCell;
//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];
if ([self outlineView:mOutlineView isItemExpandable:aItem]) {
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-5.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
-(IBAction)openHistoryItem: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
// expand if collapsed and double click
if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
return;
}
// get uri
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#URL", getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([item resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
NSString* url = [NSString stringWithCharacters: literalValue.get() length: literalValue.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
@end

View File

@ -50,9 +50,11 @@ class nsIRDFService;
nsIRDFContainer* mContainer;
nsIRDFContainerUtils* mContainerUtils;
nsIRDFResource* mRootResource;
nsIRDFService* mRDFService;
nsIRDFService* mRDFService;
IBOutlet id mOutlineView;
NSMutableDictionary* mDictionary;
}
// Initialization Methods

View File

@ -69,6 +69,8 @@
mDataSource = nsnull;
mRootResource = nsnull;
mDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
}
- (void) dealloc
@ -80,29 +82,35 @@
NS_IF_RELEASE(mDataSource);
NS_IF_RELEASE(mRootResource);
[mDictionary release];
[super dealloc];
}
- (nsIRDFDataSource*) dataSource
{
NS_IF_ADDREF(mDataSource);
return mDataSource;
}
- (nsIRDFResource*) rootResource
{
NS_IF_ADDREF(mRootResource);
return mRootResource;
}
- (void) setDataSource: (nsIRDFDataSource*) aDataSource
{
NS_IF_RELEASE(mDataSource);
nsIRDFDataSource* oldDataSource = mDataSource;
NS_IF_ADDREF(mDataSource = aDataSource);
NS_IF_RELEASE(oldDataSource);
}
- (void) setRootResource: (nsIRDFResource*) aResource
{
NS_IF_RELEASE(mRootResource);
nsIRDFResource* oldResource = mRootResource;
NS_IF_ADDREF(mRootResource = aResource);
NS_IF_RELEASE(oldResource);
}
//
@ -123,7 +131,7 @@
if (!aItem)
return YES; // The root is always open
nsCOMPtr<nsIRDFResource> itemResource = [aItem resource];
nsCOMPtr<nsIRDFResource> itemResource = dont_AddRef([aItem resource]);
PRBool isSeq = PR_FALSE;
mContainerUtils->IsSeq(mDataSource, itemResource, &isSeq);
@ -145,7 +153,7 @@
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
nsCOMPtr<nsIRDFResource> resource = !aItem ? dont_AddRef([self rootResource]) : dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFResource> ordinalResource;
mContainerUtils->IndexToOrdinalResource(aIndex + 1, getter_AddRefs(ordinalResource));
@ -159,55 +167,43 @@
if (childResource)
return [self MakeWrapperFor:childResource];
}
#if 0
else {
else
{
// Oh well, not a regular container. We need to count, dagnabbit.
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
NSLog(@"1");
nsCOMPtr<nsISimpleEnumerator> childNodes;
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
NSLog(@"2");
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
NSLog(@"3");
nsCOMPtr<nsISupports> supp;
while (hasMore && count < aIndex) {
PRInt32 count = 0;
PRBool hasMore = PR_FALSE;
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
childNodes->GetNext(getter_AddRefs(supp));
NSLog(@"4");
++count;
childNodes->HasMoreElements(&hasMore);
NSLog(@"5");
if (count == aIndex)
break;
count ++;
}
nsCOMPtr<nsIRDFResource> childResource(do_QueryInterface(supp));
NSLog(@"6");
if (childResource) {
NSLog(@"6.5");
RDFOutlineViewItem* thing = [self MakeWrapperFor:childResource];
NSLog(@"thing = %@", thing);
return thing;
return [self MakeWrapperFor:childResource];
}
}
NSLog(@"7");
#endif
return nil;
}
- (int) outlineView: (NSOutlineView*) aOutlineView numberOfChildrenOfItem: (id) aItem;
{
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
return 0;
nsCOMPtr<nsIRDFResource> resource = dont_AddRef(aItem ? [aItem resource] : [self rootResource]);
// XXX just assume NC:child is the only containment arc for now
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
@ -216,20 +212,16 @@
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
while (hasMore) {
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
nsCOMPtr<nsISupports> supp;
childNodes->GetNext(getter_AddRefs(supp));
++count;
childNodes->HasMoreElements(&hasMore);
count ++;
}
if (!count) {
if (count == 0) {
nsresult rv = mContainer->Init(mDataSource, resource);
if (NS_FAILED(rv))
return 0;
@ -243,27 +235,18 @@
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSLog(@"*** aItem = %@", aItem);
if (!mDataSource || !aItem)
return nil;
NSLog(@"1");
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
NSLog(@"2");
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
NSLog(@"3");
nsCOMPtr<nsIRDFResource> resource = [aItem resource];
NSLog(@"4");
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
@ -272,19 +255,13 @@
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
nsXPIDLString str3;
valueLiteral->GetValue(getter_Copies(str3));
nsCAutoString str2; str2.AssignWithConversion(str3);
NSLog(@"Value = %@", [NSString stringWithCString: str2.get()]);
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
nsCAutoString str; str.AssignWithConversion(literalValue);
return [NSString stringWithCString: str.get()];
return [NSString stringWithCharacters: literalValue.get() length:literalValue.Length()];
}
- (void) outlineView: (NSOutlineView*) aOutlineView setObjectValue: (id) aObject
@ -306,6 +283,11 @@
{
RDFOutlineViewItem* item = [[[RDFOutlineViewItem alloc] init] autorelease];
[item setResource: aRDFResource];
// keep a copy around
const char* resourceValue;
aRDFResource->GetValueConst(&resourceValue);
[mDictionary setObject:item forKey:[NSString stringWithCString:resourceValue]];
return item;
}
@ -314,14 +296,23 @@
@implementation RDFOutlineViewItem
- (void) dealloc
{
NS_IF_RELEASE(mResource);
[super dealloc];
}
- (nsIRDFResource*) resource
{
NS_IF_ADDREF(mResource);
return mResource;
}
- (void) setResource: (nsIRDFResource*) aResource
{
mResource = aResource;
nsIRDFResource* oldResource = mResource;
NS_IF_ADDREF(mResource = aResource);
NS_IF_RELEASE(oldResource);
}
@end

View File

@ -112,6 +112,7 @@
{
CLASS = CHHistoryDataSource;
LANGUAGE = ObjC;
OUTLETS = {mBrowserWindowController = id; };
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },

View File

@ -3,15 +3,15 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>41 39 480 309 0 0 1152 746 </string>
<string>31 46 632 495 0 0 1280 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 659 170 144 0 0 1152 848 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>523 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<string>523 439 195 457 0 0 1280 1002 </string>
<key>297</key>
<string>233 646 176 162 0 0 1152 848 </string>
<key>314</key>
@ -41,6 +41,10 @@
<array>
<integer>497</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>160</integer>
</array>
<key>IBSystem Version</key>
<string>5S66</string>
</dict>

Binary file not shown.

View File

@ -40,6 +40,7 @@
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (id)initWithWindowNibName:(NSString *)windowNibName

View File

@ -112,6 +112,7 @@
{
CLASS = CHHistoryDataSource;
LANGUAGE = ObjC;
OUTLETS = {mBrowserWindowController = id; };
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },

View File

@ -3,15 +3,15 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>41 39 480 309 0 0 1152 746 </string>
<string>31 46 632 495 0 0 1280 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 659 170 144 0 0 1152 848 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>523 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<string>523 439 195 457 0 0 1280 1002 </string>
<key>297</key>
<string>233 646 176 162 0 0 1152 848 </string>
<key>314</key>
@ -41,6 +41,10 @@
<array>
<integer>497</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>160</integer>
</array>
<key>IBSystem Version</key>
<string>5S66</string>
</dict>

View File

@ -967,8 +967,10 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
#endif
// remove default tab from nib
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
// insert the tabs we want
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
#if USE_SEARCH_ITEM
@ -978,6 +980,17 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
#endif
BOOL showHistory = NO;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (pref) {
PRBool historyPref = PR_FALSE;
if (NS_SUCCEEDED(pref->GetBoolPref("chimera.show_history", &historyPref)))
showHistory = historyPref ? YES : NO;
}
if (!showHistory)
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:1]];
[mSidebarTabView selectFirstTabViewItem:self];
}

View File

@ -50,9 +50,11 @@ class nsIRDFService;
nsIRDFContainer* mContainer;
nsIRDFContainerUtils* mContainerUtils;
nsIRDFResource* mRootResource;
nsIRDFService* mRDFService;
nsIRDFService* mRDFService;
IBOutlet id mOutlineView;
NSMutableDictionary* mDictionary;
}
// Initialization Methods

View File

@ -69,6 +69,8 @@
mDataSource = nsnull;
mRootResource = nsnull;
mDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
}
- (void) dealloc
@ -80,29 +82,35 @@
NS_IF_RELEASE(mDataSource);
NS_IF_RELEASE(mRootResource);
[mDictionary release];
[super dealloc];
}
- (nsIRDFDataSource*) dataSource
{
NS_IF_ADDREF(mDataSource);
return mDataSource;
}
- (nsIRDFResource*) rootResource
{
NS_IF_ADDREF(mRootResource);
return mRootResource;
}
- (void) setDataSource: (nsIRDFDataSource*) aDataSource
{
NS_IF_RELEASE(mDataSource);
nsIRDFDataSource* oldDataSource = mDataSource;
NS_IF_ADDREF(mDataSource = aDataSource);
NS_IF_RELEASE(oldDataSource);
}
- (void) setRootResource: (nsIRDFResource*) aResource
{
NS_IF_RELEASE(mRootResource);
nsIRDFResource* oldResource = mRootResource;
NS_IF_ADDREF(mRootResource = aResource);
NS_IF_RELEASE(oldResource);
}
//
@ -123,7 +131,7 @@
if (!aItem)
return YES; // The root is always open
nsCOMPtr<nsIRDFResource> itemResource = [aItem resource];
nsCOMPtr<nsIRDFResource> itemResource = dont_AddRef([aItem resource]);
PRBool isSeq = PR_FALSE;
mContainerUtils->IsSeq(mDataSource, itemResource, &isSeq);
@ -145,7 +153,7 @@
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
nsCOMPtr<nsIRDFResource> resource = !aItem ? dont_AddRef([self rootResource]) : dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFResource> ordinalResource;
mContainerUtils->IndexToOrdinalResource(aIndex + 1, getter_AddRefs(ordinalResource));
@ -159,55 +167,43 @@
if (childResource)
return [self MakeWrapperFor:childResource];
}
#if 0
else {
else
{
// Oh well, not a regular container. We need to count, dagnabbit.
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
NSLog(@"1");
nsCOMPtr<nsISimpleEnumerator> childNodes;
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
NSLog(@"2");
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
NSLog(@"3");
nsCOMPtr<nsISupports> supp;
while (hasMore && count < aIndex) {
PRInt32 count = 0;
PRBool hasMore = PR_FALSE;
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
childNodes->GetNext(getter_AddRefs(supp));
NSLog(@"4");
++count;
childNodes->HasMoreElements(&hasMore);
NSLog(@"5");
if (count == aIndex)
break;
count ++;
}
nsCOMPtr<nsIRDFResource> childResource(do_QueryInterface(supp));
NSLog(@"6");
if (childResource) {
NSLog(@"6.5");
RDFOutlineViewItem* thing = [self MakeWrapperFor:childResource];
NSLog(@"thing = %@", thing);
return thing;
return [self MakeWrapperFor:childResource];
}
}
NSLog(@"7");
#endif
return nil;
}
- (int) outlineView: (NSOutlineView*) aOutlineView numberOfChildrenOfItem: (id) aItem;
{
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
return 0;
nsCOMPtr<nsIRDFResource> resource = dont_AddRef(aItem ? [aItem resource] : [self rootResource]);
// XXX just assume NC:child is the only containment arc for now
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
@ -216,20 +212,16 @@
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
while (hasMore) {
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
nsCOMPtr<nsISupports> supp;
childNodes->GetNext(getter_AddRefs(supp));
++count;
childNodes->HasMoreElements(&hasMore);
count ++;
}
if (!count) {
if (count == 0) {
nsresult rv = mContainer->Init(mDataSource, resource);
if (NS_FAILED(rv))
return 0;
@ -243,27 +235,18 @@
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSLog(@"*** aItem = %@", aItem);
if (!mDataSource || !aItem)
return nil;
NSLog(@"1");
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
NSLog(@"2");
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
NSLog(@"3");
nsCOMPtr<nsIRDFResource> resource = [aItem resource];
NSLog(@"4");
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
@ -272,19 +255,13 @@
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
nsXPIDLString str3;
valueLiteral->GetValue(getter_Copies(str3));
nsCAutoString str2; str2.AssignWithConversion(str3);
NSLog(@"Value = %@", [NSString stringWithCString: str2.get()]);
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
nsCAutoString str; str.AssignWithConversion(literalValue);
return [NSString stringWithCString: str.get()];
return [NSString stringWithCharacters: literalValue.get() length:literalValue.Length()];
}
- (void) outlineView: (NSOutlineView*) aOutlineView setObjectValue: (id) aObject
@ -306,6 +283,11 @@
{
RDFOutlineViewItem* item = [[[RDFOutlineViewItem alloc] init] autorelease];
[item setResource: aRDFResource];
// keep a copy around
const char* resourceValue;
aRDFResource->GetValueConst(&resourceValue);
[mDictionary setObject:item forKey:[NSString stringWithCString:resourceValue]];
return item;
}
@ -314,14 +296,23 @@
@implementation RDFOutlineViewItem
- (void) dealloc
{
NS_IF_RELEASE(mResource);
[super dealloc];
}
- (nsIRDFResource*) resource
{
NS_IF_ADDREF(mResource);
return mResource;
}
- (void) setResource: (nsIRDFResource*) aResource
{
mResource = aResource;
nsIRDFResource* oldResource = mResource;
NS_IF_ADDREF(mResource = aResource);
NS_IF_RELEASE(oldResource);
}
@end

View File

@ -40,6 +40,7 @@
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (id)initWithWindowNibName:(NSString *)windowNibName

View File

@ -10,8 +10,13 @@
#import "CHRDFOutlineViewDataSource.h"
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource {
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource
{
IBOutlet id mBrowserWindowController;
}
-(IBAction)openHistoryItem: (id)aSender;
@end

View File

@ -7,11 +7,15 @@
//
#import "CHHistoryDataSource.h"
#import "CHBrowserView.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFResource.h"
#include "nsXPIDLString.h"
#include "nsString.h"
#include "nsComponentManagerUtils.h"
@implementation CHHistoryDataSource
@ -26,7 +30,123 @@
mRDFService->GetResource("NC:HistoryByDate", &mRootResource);
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openHistoryItem:)];
[mOutlineView reloadData];
}
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
if (!mDataSource || !aItem)
return nil;
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return nil;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: literalValue.get() length:literalValue.Length()]];
if ([columnPropertyURI isEqualToString: @"http://home.netscape.com/NC-rdf#Name"])
{
NSMutableAttributedString *attachmentAttrString = nil;
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSCell *attachmentAttrStringCell;
//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];
if ([self outlineView:mOutlineView isItemExpandable:aItem]) {
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-5.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
-(IBAction)openHistoryItem: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
// expand if collapsed and double click
if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
return;
}
// get uri
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#URL", getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([item resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
NSString* url = [NSString stringWithCharacters: literalValue.get() length: literalValue.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
@end

View File

@ -112,6 +112,7 @@
{
CLASS = CHHistoryDataSource;
LANGUAGE = ObjC;
OUTLETS = {mBrowserWindowController = id; };
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },

View File

@ -3,15 +3,15 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>41 39 480 309 0 0 1152 746 </string>
<string>31 46 632 495 0 0 1280 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 659 170 144 0 0 1152 848 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>523 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<string>523 439 195 457 0 0 1280 1002 </string>
<key>297</key>
<string>233 646 176 162 0 0 1152 848 </string>
<key>314</key>
@ -41,6 +41,10 @@
<array>
<integer>497</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>160</integer>
</array>
<key>IBSystem Version</key>
<string>5S66</string>
</dict>

Binary file not shown.

View File

@ -967,8 +967,10 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
#endif
// remove default tab from nib
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
// insert the tabs we want
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
#if USE_SEARCH_ITEM
@ -978,6 +980,17 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
#endif
BOOL showHistory = NO;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (pref) {
PRBool historyPref = PR_FALSE;
if (NS_SUCCEEDED(pref->GetBoolPref("chimera.show_history", &historyPref)))
showHistory = historyPref ? YES : NO;
}
if (!showHistory)
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:1]];
[mSidebarTabView selectFirstTabViewItem:self];
}

View File

@ -10,8 +10,13 @@
#import "CHRDFOutlineViewDataSource.h"
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource {
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource
{
IBOutlet id mBrowserWindowController;
}
-(IBAction)openHistoryItem: (id)aSender;
@end

View File

@ -7,11 +7,15 @@
//
#import "CHHistoryDataSource.h"
#import "CHBrowserView.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFResource.h"
#include "nsXPIDLString.h"
#include "nsString.h"
#include "nsComponentManagerUtils.h"
@implementation CHHistoryDataSource
@ -26,7 +30,123 @@
mRDFService->GetResource("NC:HistoryByDate", &mRootResource);
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openHistoryItem:)];
[mOutlineView reloadData];
}
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
if (!mDataSource || !aItem)
return nil;
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return nil;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: literalValue.get() length:literalValue.Length()]];
if ([columnPropertyURI isEqualToString: @"http://home.netscape.com/NC-rdf#Name"])
{
NSMutableAttributedString *attachmentAttrString = nil;
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSCell *attachmentAttrStringCell;
//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];
if ([self outlineView:mOutlineView isItemExpandable:aItem]) {
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-5.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
-(IBAction)openHistoryItem: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
// expand if collapsed and double click
if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
return;
}
// get uri
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#URL", getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([item resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
NSString* url = [NSString stringWithCharacters: literalValue.get() length: literalValue.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
@end

View File

@ -50,9 +50,11 @@ class nsIRDFService;
nsIRDFContainer* mContainer;
nsIRDFContainerUtils* mContainerUtils;
nsIRDFResource* mRootResource;
nsIRDFService* mRDFService;
nsIRDFService* mRDFService;
IBOutlet id mOutlineView;
NSMutableDictionary* mDictionary;
}
// Initialization Methods

View File

@ -69,6 +69,8 @@
mDataSource = nsnull;
mRootResource = nsnull;
mDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
}
- (void) dealloc
@ -80,29 +82,35 @@
NS_IF_RELEASE(mDataSource);
NS_IF_RELEASE(mRootResource);
[mDictionary release];
[super dealloc];
}
- (nsIRDFDataSource*) dataSource
{
NS_IF_ADDREF(mDataSource);
return mDataSource;
}
- (nsIRDFResource*) rootResource
{
NS_IF_ADDREF(mRootResource);
return mRootResource;
}
- (void) setDataSource: (nsIRDFDataSource*) aDataSource
{
NS_IF_RELEASE(mDataSource);
nsIRDFDataSource* oldDataSource = mDataSource;
NS_IF_ADDREF(mDataSource = aDataSource);
NS_IF_RELEASE(oldDataSource);
}
- (void) setRootResource: (nsIRDFResource*) aResource
{
NS_IF_RELEASE(mRootResource);
nsIRDFResource* oldResource = mRootResource;
NS_IF_ADDREF(mRootResource = aResource);
NS_IF_RELEASE(oldResource);
}
//
@ -123,7 +131,7 @@
if (!aItem)
return YES; // The root is always open
nsCOMPtr<nsIRDFResource> itemResource = [aItem resource];
nsCOMPtr<nsIRDFResource> itemResource = dont_AddRef([aItem resource]);
PRBool isSeq = PR_FALSE;
mContainerUtils->IsSeq(mDataSource, itemResource, &isSeq);
@ -145,7 +153,7 @@
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
nsCOMPtr<nsIRDFResource> resource = !aItem ? dont_AddRef([self rootResource]) : dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFResource> ordinalResource;
mContainerUtils->IndexToOrdinalResource(aIndex + 1, getter_AddRefs(ordinalResource));
@ -159,55 +167,43 @@
if (childResource)
return [self MakeWrapperFor:childResource];
}
#if 0
else {
else
{
// Oh well, not a regular container. We need to count, dagnabbit.
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
NSLog(@"1");
nsCOMPtr<nsISimpleEnumerator> childNodes;
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
NSLog(@"2");
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
NSLog(@"3");
nsCOMPtr<nsISupports> supp;
while (hasMore && count < aIndex) {
PRInt32 count = 0;
PRBool hasMore = PR_FALSE;
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
childNodes->GetNext(getter_AddRefs(supp));
NSLog(@"4");
++count;
childNodes->HasMoreElements(&hasMore);
NSLog(@"5");
if (count == aIndex)
break;
count ++;
}
nsCOMPtr<nsIRDFResource> childResource(do_QueryInterface(supp));
NSLog(@"6");
if (childResource) {
NSLog(@"6.5");
RDFOutlineViewItem* thing = [self MakeWrapperFor:childResource];
NSLog(@"thing = %@", thing);
return thing;
return [self MakeWrapperFor:childResource];
}
}
NSLog(@"7");
#endif
return nil;
}
- (int) outlineView: (NSOutlineView*) aOutlineView numberOfChildrenOfItem: (id) aItem;
{
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
return 0;
nsCOMPtr<nsIRDFResource> resource = dont_AddRef(aItem ? [aItem resource] : [self rootResource]);
// XXX just assume NC:child is the only containment arc for now
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
@ -216,20 +212,16 @@
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
while (hasMore) {
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
nsCOMPtr<nsISupports> supp;
childNodes->GetNext(getter_AddRefs(supp));
++count;
childNodes->HasMoreElements(&hasMore);
count ++;
}
if (!count) {
if (count == 0) {
nsresult rv = mContainer->Init(mDataSource, resource);
if (NS_FAILED(rv))
return 0;
@ -243,27 +235,18 @@
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSLog(@"*** aItem = %@", aItem);
if (!mDataSource || !aItem)
return nil;
NSLog(@"1");
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
NSLog(@"2");
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
NSLog(@"3");
nsCOMPtr<nsIRDFResource> resource = [aItem resource];
NSLog(@"4");
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
@ -272,19 +255,13 @@
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
nsXPIDLString str3;
valueLiteral->GetValue(getter_Copies(str3));
nsCAutoString str2; str2.AssignWithConversion(str3);
NSLog(@"Value = %@", [NSString stringWithCString: str2.get()]);
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
nsCAutoString str; str.AssignWithConversion(literalValue);
return [NSString stringWithCString: str.get()];
return [NSString stringWithCharacters: literalValue.get() length:literalValue.Length()];
}
- (void) outlineView: (NSOutlineView*) aOutlineView setObjectValue: (id) aObject
@ -306,6 +283,11 @@
{
RDFOutlineViewItem* item = [[[RDFOutlineViewItem alloc] init] autorelease];
[item setResource: aRDFResource];
// keep a copy around
const char* resourceValue;
aRDFResource->GetValueConst(&resourceValue);
[mDictionary setObject:item forKey:[NSString stringWithCString:resourceValue]];
return item;
}
@ -314,14 +296,23 @@
@implementation RDFOutlineViewItem
- (void) dealloc
{
NS_IF_RELEASE(mResource);
[super dealloc];
}
- (nsIRDFResource*) resource
{
NS_IF_ADDREF(mResource);
return mResource;
}
- (void) setResource: (nsIRDFResource*) aResource
{
mResource = aResource;
nsIRDFResource* oldResource = mResource;
NS_IF_ADDREF(mResource = aResource);
NS_IF_RELEASE(oldResource);
}
@end

View File

@ -112,6 +112,7 @@
{
CLASS = CHHistoryDataSource;
LANGUAGE = ObjC;
OUTLETS = {mBrowserWindowController = id; };
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },

View File

@ -3,15 +3,15 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>41 39 480 309 0 0 1152 746 </string>
<string>31 46 632 495 0 0 1280 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 659 170 144 0 0 1152 848 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>523 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<string>523 439 195 457 0 0 1280 1002 </string>
<key>297</key>
<string>233 646 176 162 0 0 1152 848 </string>
<key>314</key>
@ -41,6 +41,10 @@
<array>
<integer>497</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>160</integer>
</array>
<key>IBSystem Version</key>
<string>5S66</string>
</dict>

Binary file not shown.

View File

@ -40,6 +40,7 @@
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (id)initWithWindowNibName:(NSString *)windowNibName

View File

@ -112,6 +112,7 @@
{
CLASS = CHHistoryDataSource;
LANGUAGE = ObjC;
OUTLETS = {mBrowserWindowController = id; };
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },

View File

@ -3,15 +3,15 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>41 39 480 309 0 0 1152 746 </string>
<string>31 46 632 495 0 0 1280 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>305 659 170 144 0 0 1152 848 </string>
<key>160</key>
<string>478 172 195 666 0 0 1152 848 </string>
<string>523 326 195 666 0 0 1280 1002 </string>
<key>28</key>
<string>478 351 195 457 0 0 1152 848 </string>
<string>523 439 195 457 0 0 1280 1002 </string>
<key>297</key>
<string>233 646 176 162 0 0 1152 848 </string>
<key>314</key>
@ -41,6 +41,10 @@
<array>
<integer>497</integer>
</array>
<key>IBOpenObjects</key>
<array>
<integer>160</integer>
</array>
<key>IBSystem Version</key>
<string>5S66</string>
</dict>

View File

@ -967,8 +967,10 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
#endif
// remove default tab from nib
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
// insert the tabs we want
[mSidebarTabView insertTabViewItem:bookItem atIndex:0];
[mSidebarTabView insertTabViewItem:histItem atIndex:1];
#if USE_SEARCH_ITEM
@ -978,6 +980,17 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
#endif
BOOL showHistory = NO;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (pref) {
PRBool historyPref = PR_FALSE;
if (NS_SUCCEEDED(pref->GetBoolPref("chimera.show_history", &historyPref)))
showHistory = historyPref ? YES : NO;
}
if (!showHistory)
[mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:1]];
[mSidebarTabView selectFirstTabViewItem:self];
}

View File

@ -50,9 +50,11 @@ class nsIRDFService;
nsIRDFContainer* mContainer;
nsIRDFContainerUtils* mContainerUtils;
nsIRDFResource* mRootResource;
nsIRDFService* mRDFService;
nsIRDFService* mRDFService;
IBOutlet id mOutlineView;
NSMutableDictionary* mDictionary;
}
// Initialization Methods

View File

@ -69,6 +69,8 @@
mDataSource = nsnull;
mRootResource = nsnull;
mDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
}
- (void) dealloc
@ -80,29 +82,35 @@
NS_IF_RELEASE(mDataSource);
NS_IF_RELEASE(mRootResource);
[mDictionary release];
[super dealloc];
}
- (nsIRDFDataSource*) dataSource
{
NS_IF_ADDREF(mDataSource);
return mDataSource;
}
- (nsIRDFResource*) rootResource
{
NS_IF_ADDREF(mRootResource);
return mRootResource;
}
- (void) setDataSource: (nsIRDFDataSource*) aDataSource
{
NS_IF_RELEASE(mDataSource);
nsIRDFDataSource* oldDataSource = mDataSource;
NS_IF_ADDREF(mDataSource = aDataSource);
NS_IF_RELEASE(oldDataSource);
}
- (void) setRootResource: (nsIRDFResource*) aResource
{
NS_IF_RELEASE(mRootResource);
nsIRDFResource* oldResource = mRootResource;
NS_IF_ADDREF(mRootResource = aResource);
NS_IF_RELEASE(oldResource);
}
//
@ -123,7 +131,7 @@
if (!aItem)
return YES; // The root is always open
nsCOMPtr<nsIRDFResource> itemResource = [aItem resource];
nsCOMPtr<nsIRDFResource> itemResource = dont_AddRef([aItem resource]);
PRBool isSeq = PR_FALSE;
mContainerUtils->IsSeq(mDataSource, itemResource, &isSeq);
@ -145,7 +153,7 @@
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
nsCOMPtr<nsIRDFResource> resource = !aItem ? dont_AddRef([self rootResource]) : dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFResource> ordinalResource;
mContainerUtils->IndexToOrdinalResource(aIndex + 1, getter_AddRefs(ordinalResource));
@ -159,55 +167,43 @@
if (childResource)
return [self MakeWrapperFor:childResource];
}
#if 0
else {
else
{
// Oh well, not a regular container. We need to count, dagnabbit.
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
NSLog(@"1");
nsCOMPtr<nsISimpleEnumerator> childNodes;
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
NSLog(@"2");
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
NSLog(@"3");
nsCOMPtr<nsISupports> supp;
while (hasMore && count < aIndex) {
PRInt32 count = 0;
PRBool hasMore = PR_FALSE;
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
childNodes->GetNext(getter_AddRefs(supp));
NSLog(@"4");
++count;
childNodes->HasMoreElements(&hasMore);
NSLog(@"5");
if (count == aIndex)
break;
count ++;
}
nsCOMPtr<nsIRDFResource> childResource(do_QueryInterface(supp));
NSLog(@"6");
if (childResource) {
NSLog(@"6.5");
RDFOutlineViewItem* thing = [self MakeWrapperFor:childResource];
NSLog(@"thing = %@", thing);
return thing;
return [self MakeWrapperFor:childResource];
}
}
NSLog(@"7");
#endif
return nil;
}
- (int) outlineView: (NSOutlineView*) aOutlineView numberOfChildrenOfItem: (id) aItem;
{
if (!mDataSource)
return nil;
nsCOMPtr<nsIRDFResource> resource = !aItem ? mRootResource : [aItem resource];
return 0;
nsCOMPtr<nsIRDFResource> resource = dont_AddRef(aItem ? [aItem resource] : [self rootResource]);
// XXX just assume NC:child is the only containment arc for now
nsCOMPtr<nsIRDFResource> childProperty;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty));
@ -216,20 +212,16 @@
mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes));
PRBool hasMore = PR_FALSE;
childNodes->HasMoreElements(&hasMore);
PRInt32 count = 0;
while (hasMore) {
while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore)
{
nsCOMPtr<nsISupports> supp;
childNodes->GetNext(getter_AddRefs(supp));
++count;
childNodes->HasMoreElements(&hasMore);
count ++;
}
if (!count) {
if (count == 0) {
nsresult rv = mContainer->Init(mDataSource, resource);
if (NS_FAILED(rv))
return 0;
@ -243,27 +235,18 @@
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSLog(@"*** aItem = %@", aItem);
if (!mDataSource || !aItem)
return nil;
NSLog(@"1");
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
NSLog(@"2");
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
NSLog(@"3");
nsCOMPtr<nsIRDFResource> resource = [aItem resource];
NSLog(@"4");
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
@ -272,19 +255,13 @@
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
nsXPIDLString str3;
valueLiteral->GetValue(getter_Copies(str3));
nsCAutoString str2; str2.AssignWithConversion(str3);
NSLog(@"Value = %@", [NSString stringWithCString: str2.get()]);
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
nsCAutoString str; str.AssignWithConversion(literalValue);
return [NSString stringWithCString: str.get()];
return [NSString stringWithCharacters: literalValue.get() length:literalValue.Length()];
}
- (void) outlineView: (NSOutlineView*) aOutlineView setObjectValue: (id) aObject
@ -306,6 +283,11 @@
{
RDFOutlineViewItem* item = [[[RDFOutlineViewItem alloc] init] autorelease];
[item setResource: aRDFResource];
// keep a copy around
const char* resourceValue;
aRDFResource->GetValueConst(&resourceValue);
[mDictionary setObject:item forKey:[NSString stringWithCString:resourceValue]];
return item;
}
@ -314,14 +296,23 @@
@implementation RDFOutlineViewItem
- (void) dealloc
{
NS_IF_RELEASE(mResource);
[super dealloc];
}
- (nsIRDFResource*) resource
{
NS_IF_ADDREF(mResource);
return mResource;
}
- (void) setResource: (nsIRDFResource*) aResource
{
mResource = aResource;
nsIRDFResource* oldResource = mResource;
NS_IF_ADDREF(mResource = aResource);
NS_IF_RELEASE(oldResource);
}
@end

View File

@ -40,6 +40,7 @@
#import "CHFind.h"
#include "nsCOMPtr.h"
@implementation FindDlgController
- (id)initWithWindowNibName:(NSString *)windowNibName

View File

@ -10,8 +10,13 @@
#import "CHRDFOutlineViewDataSource.h"
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource {
@interface CHHistoryDataSource : CHRDFOutlineViewDataSource
{
IBOutlet id mBrowserWindowController;
}
-(IBAction)openHistoryItem: (id)aSender;
@end

View File

@ -7,11 +7,15 @@
//
#import "CHHistoryDataSource.h"
#import "CHBrowserView.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFResource.h"
#include "nsXPIDLString.h"
#include "nsString.h"
#include "nsComponentManagerUtils.h"
@implementation CHHistoryDataSource
@ -26,7 +30,123 @@
mRDFService->GetResource("NC:HistoryByDate", &mRootResource);
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openHistoryItem:)];
[mOutlineView reloadData];
}
- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn
byItem: (id) aItem
{
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
if (!mDataSource || !aItem)
return nil;
// The table column's identifier is the RDF Resource URI of the property being displayed in
// that column, e.g. "http://home.netscape.com/NC-rdf#Name"
NSString* columnPropertyURI = [aTableColumn identifier];
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource([columnPropertyURI cString], getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([aItem resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return nil;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return nil;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: literalValue.get() length:literalValue.Length()]];
if ([columnPropertyURI isEqualToString: @"http://home.netscape.com/NC-rdf#Name"])
{
NSMutableAttributedString *attachmentAttrString = nil;
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSCell *attachmentAttrStringCell;
//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];
if ([self outlineView:mOutlineView isItemExpandable:aItem]) {
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-5.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
-(IBAction)openHistoryItem: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
// expand if collapsed and double click
if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
return;
}
// get uri
nsCOMPtr<nsIRDFResource> propertyResource;
mRDFService->GetResource("http://home.netscape.com/NC-rdf#URL", getter_AddRefs(propertyResource));
nsCOMPtr<nsIRDFResource> resource = dont_AddRef([item resource]);
nsCOMPtr<nsIRDFNode> valueNode;
mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode));
if (!valueNode) {
NSLog(@"ValueNode is null!");
return;
}
nsCOMPtr<nsIRDFLiteral> valueLiteral(do_QueryInterface(valueNode));
if (!valueLiteral)
return;
nsXPIDLString literalValue;
valueLiteral->GetValue(getter_Copies(literalValue));
NSString* url = [NSString stringWithCharacters: literalValue.get() length: literalValue.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
@end