mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 13:21:28 +00:00
Fix for bug 155920: added string truncation utility on our NSString category, and used it to truncat strings that are put into menu items in the UI and window titles.
This commit is contained in:
parent
a78c1cf8e4
commit
dd5f5f9830
@ -287,7 +287,8 @@ BookmarksService::BookmarkChanged(nsIContent* aItem, bool shouldFlush = true)
|
|||||||
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
[childItem setTitle: [NSString stringWith_nsAString: name]];
|
NSString* bookmarkTitle = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
[childItem setTitle: bookmarkTitle];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -740,7 +741,7 @@ BookmarksService::AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent
|
|||||||
{
|
{
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
NSString* title = [NSString stringWith_nsAString: name];
|
NSString* title = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// Create a menu or menu item for the child.
|
// Create a menu or menu item for the child.
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#import "NSString+Utils.h"
|
||||||
|
|
||||||
#import "CHBrowserWrapper.h"
|
#import "CHBrowserWrapper.h"
|
||||||
#import "BrowserWindowController.h"
|
#import "BrowserWindowController.h"
|
||||||
#import "BookmarksService.h"
|
#import "BookmarksService.h"
|
||||||
@ -358,7 +360,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
NSString* newTitle = nil;
|
NSString* newTitle = nil;
|
||||||
if (mOffline) {
|
if (mOffline) {
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
newTitle = [title stringByAppendingString: @" [Working Offline]"]; // XXX localize me
|
||||||
else
|
else
|
||||||
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
||||||
mTitle = [newTitle retain];
|
mTitle = [newTitle retain];
|
||||||
@ -368,12 +370,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
mTitle = [title retain];
|
mTitle = [title retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mIsPrimary && mWindowController )
|
if ( mIsPrimary && mWindowController )
|
||||||
[[mWindowController window] setTitle:mTitle];
|
[[mWindowController window] setTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]];
|
||||||
|
|
||||||
// Always set the tab.
|
// Always set the tab.
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
[mTab setLabel:title];
|
[mTab setLabel:title]; // tab titles get truncated when setting them to tabs
|
||||||
else
|
else
|
||||||
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,7 @@ static const int kDividerTag = 4000;
|
|||||||
// the maximum number of history entry menuitems to display
|
// the maximum number of history entry menuitems to display
|
||||||
static const int kMaxItems = 15;
|
static const int kMaxItems = 15;
|
||||||
// the maximum number of characters in a menu title before cropping it
|
// the maximum number of characters in a menu title before cropping it
|
||||||
static const unsigned int kMaxTitleLength = 60;
|
static const unsigned int kMaxTitleLength = 80;
|
||||||
// the ellipsis string to insert into cropped strings
|
|
||||||
static const NSString *kEllipsis = @"...";
|
|
||||||
|
|
||||||
@implementation CHGoMenu
|
@implementation CHGoMenu
|
||||||
|
|
||||||
@ -134,21 +132,7 @@ static const NSString *kEllipsis = @"...";
|
|||||||
|
|
||||||
nsXPIDLString textStr;
|
nsXPIDLString textStr;
|
||||||
entry->GetTitle(getter_Copies(textStr));
|
entry->GetTitle(getter_Copies(textStr));
|
||||||
NSString* title = [NSString stringWith_nsAString: textStr];
|
NSString* title = [[NSString stringWith_nsAString: textStr] stringByTruncatingTo:kMaxTitleLength at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// if the title is too long, crop it in the middle
|
|
||||||
if ([title length] > kMaxTitleLength) {
|
|
||||||
NSMutableString *croppedTitle = [NSMutableString stringWithCapacity:kMaxTitleLength+[kEllipsis length]];
|
|
||||||
int len1 = kMaxTitleLength/2;
|
|
||||||
int len2 = kMaxTitleLength - len1;
|
|
||||||
NSString *part1 = [title substringWithRange:NSMakeRange(0, len1)];
|
|
||||||
NSString *part2 = [title substringWithRange:NSMakeRange([title length]-len2, len2)];
|
|
||||||
[croppedTitle appendString:part1];
|
|
||||||
[croppedTitle appendString:kEllipsis];
|
|
||||||
[croppedTitle appendString:part2];
|
|
||||||
title = croppedTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
||||||
[newItem setTarget:self];
|
[newItem setTarget:self];
|
||||||
[newItem setTag:kDividerTag+1+i];
|
[newItem setTag:kDividerTag+1+i];
|
||||||
|
@ -1644,6 +1644,48 @@
|
|||||||
settings = {
|
settings = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
F522EFC502F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseClipboard.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseClipboard.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC602F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseDragService.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseDragService.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC702F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseWidget.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseWidget.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC802F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsClipboardHelper.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsClipboardHelper.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC902F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsDataFlavor.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsDataFlavor.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCA02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsPrimitiveHelpers.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsPrimitiveHelpers.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCB02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsTransferable.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsTransferable.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
F5247C2D02289FD9013DD99A = {
|
F5247C2D02289FD9013DD99A = {
|
||||||
isa = PBXFileReference;
|
isa = PBXFileReference;
|
||||||
path = alert.nib;
|
path = alert.nib;
|
||||||
@ -7422,6 +7464,13 @@
|
|||||||
F5EA337C02EF889001A96654,
|
F5EA337C02EF889001A96654,
|
||||||
F5EA337D02EF889001A96654,
|
F5EA337D02EF889001A96654,
|
||||||
F5EA337E02EF889001A96654,
|
F5EA337E02EF889001A96654,
|
||||||
|
F522EFC502F73CF901A96654,
|
||||||
|
F522EFC602F73CF901A96654,
|
||||||
|
F522EFC702F73CF901A96654,
|
||||||
|
F522EFC802F73CF901A96654,
|
||||||
|
F522EFC902F73CF901A96654,
|
||||||
|
F522EFCA02F73CF901A96654,
|
||||||
|
F522EFCB02F73CF901A96654,
|
||||||
);
|
);
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
name = widget;
|
name = widget;
|
||||||
|
@ -180,7 +180,7 @@ ContentClickListener::MouseDown(nsIDOMEvent* aEvent)
|
|||||||
option->GetLabel(text);
|
option->GetLabel(text);
|
||||||
if (text.IsEmpty())
|
if (text.IsEmpty())
|
||||||
option->GetText(text);
|
option->GetText(text);
|
||||||
NSString* title = [NSString stringWith_nsAString: text];
|
NSString* title = [[NSString stringWith_nsAString: text] stringByTruncatingTo:75 at:kTruncateAtMiddle];
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
[menu addItem: menuItem];
|
[menu addItem: menuItem];
|
||||||
[menuItem setTag: contentID];
|
[menuItem setTag: contentID];
|
||||||
|
@ -40,6 +40,14 @@
|
|||||||
|
|
||||||
class nsAString;
|
class nsAString;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
kTruncateAtStart,
|
||||||
|
kTruncateAtMiddle,
|
||||||
|
kTruncateAtEnd
|
||||||
|
} ETruncationType;
|
||||||
|
|
||||||
|
|
||||||
// a category to extend NSString
|
// a category to extend NSString
|
||||||
@interface NSString (ChimeraStringUtils)
|
@interface NSString (ChimeraStringUtils)
|
||||||
|
|
||||||
@ -49,5 +57,6 @@ class nsAString;
|
|||||||
|
|
||||||
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
||||||
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -117,4 +117,53 @@
|
|||||||
return cleanString;
|
return cleanString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
|
||||||
|
{
|
||||||
|
unichar ellipsisChar = 0x2026;
|
||||||
|
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
|
||||||
|
|
||||||
|
if ([self length] > maxCharacters)
|
||||||
|
{
|
||||||
|
NSMutableString *croppedString = [NSMutableString stringWithCapacity:maxCharacters + [ellipsisString length]];
|
||||||
|
|
||||||
|
switch (truncationType)
|
||||||
|
{
|
||||||
|
case kTruncateAtStart:
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange([self length] - maxCharacters, maxCharacters)]];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtMiddle:
|
||||||
|
{
|
||||||
|
int len1 = maxCharacters / 2;
|
||||||
|
int len2 = maxCharacters - len1;
|
||||||
|
NSString *part1 = [self substringWithRange:NSMakeRange(0, len1)];
|
||||||
|
NSString *part2 = [self substringWithRange:NSMakeRange([self length] - len2, len2)];
|
||||||
|
[croppedString appendString:part1];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:part2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtEnd:
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange(0, maxCharacters)]];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
#if DEBUG
|
||||||
|
NSLog(@"Unknown truncation type in stringByTruncatingTo::");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return croppedString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [[self copy] autorelease];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -1644,6 +1644,48 @@
|
|||||||
settings = {
|
settings = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
F522EFC502F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseClipboard.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseClipboard.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC602F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseDragService.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseDragService.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC702F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseWidget.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseWidget.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC802F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsClipboardHelper.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsClipboardHelper.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC902F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsDataFlavor.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsDataFlavor.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCA02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsPrimitiveHelpers.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsPrimitiveHelpers.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCB02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsTransferable.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsTransferable.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
F5247C2D02289FD9013DD99A = {
|
F5247C2D02289FD9013DD99A = {
|
||||||
isa = PBXFileReference;
|
isa = PBXFileReference;
|
||||||
path = alert.nib;
|
path = alert.nib;
|
||||||
@ -7422,6 +7464,13 @@
|
|||||||
F5EA337C02EF889001A96654,
|
F5EA337C02EF889001A96654,
|
||||||
F5EA337D02EF889001A96654,
|
F5EA337D02EF889001A96654,
|
||||||
F5EA337E02EF889001A96654,
|
F5EA337E02EF889001A96654,
|
||||||
|
F522EFC502F73CF901A96654,
|
||||||
|
F522EFC602F73CF901A96654,
|
||||||
|
F522EFC702F73CF901A96654,
|
||||||
|
F522EFC802F73CF901A96654,
|
||||||
|
F522EFC902F73CF901A96654,
|
||||||
|
F522EFCA02F73CF901A96654,
|
||||||
|
F522EFCB02F73CF901A96654,
|
||||||
);
|
);
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
name = widget;
|
name = widget;
|
||||||
|
@ -287,7 +287,8 @@ BookmarksService::BookmarkChanged(nsIContent* aItem, bool shouldFlush = true)
|
|||||||
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
[childItem setTitle: [NSString stringWith_nsAString: name]];
|
NSString* bookmarkTitle = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
[childItem setTitle: bookmarkTitle];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -740,7 +741,7 @@ BookmarksService::AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent
|
|||||||
{
|
{
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
NSString* title = [NSString stringWith_nsAString: name];
|
NSString* title = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// Create a menu or menu item for the child.
|
// Create a menu or menu item for the child.
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#import "NSString+Utils.h"
|
||||||
|
|
||||||
#import "CHBrowserWrapper.h"
|
#import "CHBrowserWrapper.h"
|
||||||
#import "BrowserWindowController.h"
|
#import "BrowserWindowController.h"
|
||||||
#import "BookmarksService.h"
|
#import "BookmarksService.h"
|
||||||
@ -358,7 +360,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
NSString* newTitle = nil;
|
NSString* newTitle = nil;
|
||||||
if (mOffline) {
|
if (mOffline) {
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
newTitle = [title stringByAppendingString: @" [Working Offline]"]; // XXX localize me
|
||||||
else
|
else
|
||||||
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
||||||
mTitle = [newTitle retain];
|
mTitle = [newTitle retain];
|
||||||
@ -368,12 +370,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
mTitle = [title retain];
|
mTitle = [title retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mIsPrimary && mWindowController )
|
if ( mIsPrimary && mWindowController )
|
||||||
[[mWindowController window] setTitle:mTitle];
|
[[mWindowController window] setTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]];
|
||||||
|
|
||||||
// Always set the tab.
|
// Always set the tab.
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
[mTab setLabel:title];
|
[mTab setLabel:title]; // tab titles get truncated when setting them to tabs
|
||||||
else
|
else
|
||||||
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ ContentClickListener::MouseDown(nsIDOMEvent* aEvent)
|
|||||||
option->GetLabel(text);
|
option->GetLabel(text);
|
||||||
if (text.IsEmpty())
|
if (text.IsEmpty())
|
||||||
option->GetText(text);
|
option->GetText(text);
|
||||||
NSString* title = [NSString stringWith_nsAString: text];
|
NSString* title = [[NSString stringWith_nsAString: text] stringByTruncatingTo:75 at:kTruncateAtMiddle];
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
[menu addItem: menuItem];
|
[menu addItem: menuItem];
|
||||||
[menuItem setTag: contentID];
|
[menuItem setTag: contentID];
|
||||||
|
@ -41,9 +41,7 @@ static const int kDividerTag = 4000;
|
|||||||
// the maximum number of history entry menuitems to display
|
// the maximum number of history entry menuitems to display
|
||||||
static const int kMaxItems = 15;
|
static const int kMaxItems = 15;
|
||||||
// the maximum number of characters in a menu title before cropping it
|
// the maximum number of characters in a menu title before cropping it
|
||||||
static const unsigned int kMaxTitleLength = 60;
|
static const unsigned int kMaxTitleLength = 80;
|
||||||
// the ellipsis string to insert into cropped strings
|
|
||||||
static const NSString *kEllipsis = @"...";
|
|
||||||
|
|
||||||
@implementation CHGoMenu
|
@implementation CHGoMenu
|
||||||
|
|
||||||
@ -134,21 +132,7 @@ static const NSString *kEllipsis = @"...";
|
|||||||
|
|
||||||
nsXPIDLString textStr;
|
nsXPIDLString textStr;
|
||||||
entry->GetTitle(getter_Copies(textStr));
|
entry->GetTitle(getter_Copies(textStr));
|
||||||
NSString* title = [NSString stringWith_nsAString: textStr];
|
NSString* title = [[NSString stringWith_nsAString: textStr] stringByTruncatingTo:kMaxTitleLength at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// if the title is too long, crop it in the middle
|
|
||||||
if ([title length] > kMaxTitleLength) {
|
|
||||||
NSMutableString *croppedTitle = [NSMutableString stringWithCapacity:kMaxTitleLength+[kEllipsis length]];
|
|
||||||
int len1 = kMaxTitleLength/2;
|
|
||||||
int len2 = kMaxTitleLength - len1;
|
|
||||||
NSString *part1 = [title substringWithRange:NSMakeRange(0, len1)];
|
|
||||||
NSString *part2 = [title substringWithRange:NSMakeRange([title length]-len2, len2)];
|
|
||||||
[croppedTitle appendString:part1];
|
|
||||||
[croppedTitle appendString:kEllipsis];
|
|
||||||
[croppedTitle appendString:part2];
|
|
||||||
title = croppedTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
||||||
[newItem setTarget:self];
|
[newItem setTarget:self];
|
||||||
[newItem setTag:kDividerTag+1+i];
|
[newItem setTag:kDividerTag+1+i];
|
||||||
|
@ -40,6 +40,14 @@
|
|||||||
|
|
||||||
class nsAString;
|
class nsAString;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
kTruncateAtStart,
|
||||||
|
kTruncateAtMiddle,
|
||||||
|
kTruncateAtEnd
|
||||||
|
} ETruncationType;
|
||||||
|
|
||||||
|
|
||||||
// a category to extend NSString
|
// a category to extend NSString
|
||||||
@interface NSString (ChimeraStringUtils)
|
@interface NSString (ChimeraStringUtils)
|
||||||
|
|
||||||
@ -49,5 +57,6 @@ class nsAString;
|
|||||||
|
|
||||||
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
||||||
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -117,4 +117,53 @@
|
|||||||
return cleanString;
|
return cleanString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
|
||||||
|
{
|
||||||
|
unichar ellipsisChar = 0x2026;
|
||||||
|
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
|
||||||
|
|
||||||
|
if ([self length] > maxCharacters)
|
||||||
|
{
|
||||||
|
NSMutableString *croppedString = [NSMutableString stringWithCapacity:maxCharacters + [ellipsisString length]];
|
||||||
|
|
||||||
|
switch (truncationType)
|
||||||
|
{
|
||||||
|
case kTruncateAtStart:
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange([self length] - maxCharacters, maxCharacters)]];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtMiddle:
|
||||||
|
{
|
||||||
|
int len1 = maxCharacters / 2;
|
||||||
|
int len2 = maxCharacters - len1;
|
||||||
|
NSString *part1 = [self substringWithRange:NSMakeRange(0, len1)];
|
||||||
|
NSString *part2 = [self substringWithRange:NSMakeRange([self length] - len2, len2)];
|
||||||
|
[croppedString appendString:part1];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:part2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtEnd:
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange(0, maxCharacters)]];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
#if DEBUG
|
||||||
|
NSLog(@"Unknown truncation type in stringByTruncatingTo::");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return croppedString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [[self copy] autorelease];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -287,7 +287,8 @@ BookmarksService::BookmarkChanged(nsIContent* aItem, bool shouldFlush = true)
|
|||||||
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
[childItem setTitle: [NSString stringWith_nsAString: name]];
|
NSString* bookmarkTitle = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
[childItem setTitle: bookmarkTitle];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -740,7 +741,7 @@ BookmarksService::AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent
|
|||||||
{
|
{
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
NSString* title = [NSString stringWith_nsAString: name];
|
NSString* title = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// Create a menu or menu item for the child.
|
// Create a menu or menu item for the child.
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#import "NSString+Utils.h"
|
||||||
|
|
||||||
#import "CHBrowserWrapper.h"
|
#import "CHBrowserWrapper.h"
|
||||||
#import "BrowserWindowController.h"
|
#import "BrowserWindowController.h"
|
||||||
#import "BookmarksService.h"
|
#import "BookmarksService.h"
|
||||||
@ -358,7 +360,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
NSString* newTitle = nil;
|
NSString* newTitle = nil;
|
||||||
if (mOffline) {
|
if (mOffline) {
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
newTitle = [title stringByAppendingString: @" [Working Offline]"]; // XXX localize me
|
||||||
else
|
else
|
||||||
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
||||||
mTitle = [newTitle retain];
|
mTitle = [newTitle retain];
|
||||||
@ -368,12 +370,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
mTitle = [title retain];
|
mTitle = [title retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mIsPrimary && mWindowController )
|
if ( mIsPrimary && mWindowController )
|
||||||
[[mWindowController window] setTitle:mTitle];
|
[[mWindowController window] setTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]];
|
||||||
|
|
||||||
// Always set the tab.
|
// Always set the tab.
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
[mTab setLabel:title];
|
[mTab setLabel:title]; // tab titles get truncated when setting them to tabs
|
||||||
else
|
else
|
||||||
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,7 @@ static const int kDividerTag = 4000;
|
|||||||
// the maximum number of history entry menuitems to display
|
// the maximum number of history entry menuitems to display
|
||||||
static const int kMaxItems = 15;
|
static const int kMaxItems = 15;
|
||||||
// the maximum number of characters in a menu title before cropping it
|
// the maximum number of characters in a menu title before cropping it
|
||||||
static const unsigned int kMaxTitleLength = 60;
|
static const unsigned int kMaxTitleLength = 80;
|
||||||
// the ellipsis string to insert into cropped strings
|
|
||||||
static const NSString *kEllipsis = @"...";
|
|
||||||
|
|
||||||
@implementation CHGoMenu
|
@implementation CHGoMenu
|
||||||
|
|
||||||
@ -134,21 +132,7 @@ static const NSString *kEllipsis = @"...";
|
|||||||
|
|
||||||
nsXPIDLString textStr;
|
nsXPIDLString textStr;
|
||||||
entry->GetTitle(getter_Copies(textStr));
|
entry->GetTitle(getter_Copies(textStr));
|
||||||
NSString* title = [NSString stringWith_nsAString: textStr];
|
NSString* title = [[NSString stringWith_nsAString: textStr] stringByTruncatingTo:kMaxTitleLength at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// if the title is too long, crop it in the middle
|
|
||||||
if ([title length] > kMaxTitleLength) {
|
|
||||||
NSMutableString *croppedTitle = [NSMutableString stringWithCapacity:kMaxTitleLength+[kEllipsis length]];
|
|
||||||
int len1 = kMaxTitleLength/2;
|
|
||||||
int len2 = kMaxTitleLength - len1;
|
|
||||||
NSString *part1 = [title substringWithRange:NSMakeRange(0, len1)];
|
|
||||||
NSString *part2 = [title substringWithRange:NSMakeRange([title length]-len2, len2)];
|
|
||||||
[croppedTitle appendString:part1];
|
|
||||||
[croppedTitle appendString:kEllipsis];
|
|
||||||
[croppedTitle appendString:part2];
|
|
||||||
title = croppedTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
||||||
[newItem setTarget:self];
|
[newItem setTarget:self];
|
||||||
[newItem setTag:kDividerTag+1+i];
|
[newItem setTag:kDividerTag+1+i];
|
||||||
|
@ -1644,6 +1644,48 @@
|
|||||||
settings = {
|
settings = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
F522EFC502F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseClipboard.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseClipboard.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC602F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseDragService.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseDragService.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC702F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseWidget.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseWidget.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC802F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsClipboardHelper.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsClipboardHelper.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC902F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsDataFlavor.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsDataFlavor.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCA02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsPrimitiveHelpers.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsPrimitiveHelpers.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCB02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsTransferable.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsTransferable.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
F5247C2D02289FD9013DD99A = {
|
F5247C2D02289FD9013DD99A = {
|
||||||
isa = PBXFileReference;
|
isa = PBXFileReference;
|
||||||
path = alert.nib;
|
path = alert.nib;
|
||||||
@ -7422,6 +7464,13 @@
|
|||||||
F5EA337C02EF889001A96654,
|
F5EA337C02EF889001A96654,
|
||||||
F5EA337D02EF889001A96654,
|
F5EA337D02EF889001A96654,
|
||||||
F5EA337E02EF889001A96654,
|
F5EA337E02EF889001A96654,
|
||||||
|
F522EFC502F73CF901A96654,
|
||||||
|
F522EFC602F73CF901A96654,
|
||||||
|
F522EFC702F73CF901A96654,
|
||||||
|
F522EFC802F73CF901A96654,
|
||||||
|
F522EFC902F73CF901A96654,
|
||||||
|
F522EFCA02F73CF901A96654,
|
||||||
|
F522EFCB02F73CF901A96654,
|
||||||
);
|
);
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
name = widget;
|
name = widget;
|
||||||
|
@ -180,7 +180,7 @@ ContentClickListener::MouseDown(nsIDOMEvent* aEvent)
|
|||||||
option->GetLabel(text);
|
option->GetLabel(text);
|
||||||
if (text.IsEmpty())
|
if (text.IsEmpty())
|
||||||
option->GetText(text);
|
option->GetText(text);
|
||||||
NSString* title = [NSString stringWith_nsAString: text];
|
NSString* title = [[NSString stringWith_nsAString: text] stringByTruncatingTo:75 at:kTruncateAtMiddle];
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
[menu addItem: menuItem];
|
[menu addItem: menuItem];
|
||||||
[menuItem setTag: contentID];
|
[menuItem setTag: contentID];
|
||||||
|
@ -40,6 +40,14 @@
|
|||||||
|
|
||||||
class nsAString;
|
class nsAString;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
kTruncateAtStart,
|
||||||
|
kTruncateAtMiddle,
|
||||||
|
kTruncateAtEnd
|
||||||
|
} ETruncationType;
|
||||||
|
|
||||||
|
|
||||||
// a category to extend NSString
|
// a category to extend NSString
|
||||||
@interface NSString (ChimeraStringUtils)
|
@interface NSString (ChimeraStringUtils)
|
||||||
|
|
||||||
@ -49,5 +57,6 @@ class nsAString;
|
|||||||
|
|
||||||
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
||||||
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -117,4 +117,53 @@
|
|||||||
return cleanString;
|
return cleanString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
|
||||||
|
{
|
||||||
|
unichar ellipsisChar = 0x2026;
|
||||||
|
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
|
||||||
|
|
||||||
|
if ([self length] > maxCharacters)
|
||||||
|
{
|
||||||
|
NSMutableString *croppedString = [NSMutableString stringWithCapacity:maxCharacters + [ellipsisString length]];
|
||||||
|
|
||||||
|
switch (truncationType)
|
||||||
|
{
|
||||||
|
case kTruncateAtStart:
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange([self length] - maxCharacters, maxCharacters)]];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtMiddle:
|
||||||
|
{
|
||||||
|
int len1 = maxCharacters / 2;
|
||||||
|
int len2 = maxCharacters - len1;
|
||||||
|
NSString *part1 = [self substringWithRange:NSMakeRange(0, len1)];
|
||||||
|
NSString *part2 = [self substringWithRange:NSMakeRange([self length] - len2, len2)];
|
||||||
|
[croppedString appendString:part1];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:part2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtEnd:
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange(0, maxCharacters)]];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
#if DEBUG
|
||||||
|
NSLog(@"Unknown truncation type in stringByTruncatingTo::");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return croppedString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [[self copy] autorelease];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -1644,6 +1644,48 @@
|
|||||||
settings = {
|
settings = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
F522EFC502F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseClipboard.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseClipboard.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC602F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseDragService.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseDragService.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC702F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsBaseWidget.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsBaseWidget.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC802F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsClipboardHelper.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsClipboardHelper.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFC902F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsDataFlavor.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsDataFlavor.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCA02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsPrimitiveHelpers.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsPrimitiveHelpers.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
|
F522EFCB02F73CF901A96654 = {
|
||||||
|
isa = PBXFileReference;
|
||||||
|
name = nsTransferable.cpp;
|
||||||
|
path = ../widget/src/xpwidgets/nsTransferable.cpp;
|
||||||
|
refType = 2;
|
||||||
|
};
|
||||||
F5247C2D02289FD9013DD99A = {
|
F5247C2D02289FD9013DD99A = {
|
||||||
isa = PBXFileReference;
|
isa = PBXFileReference;
|
||||||
path = alert.nib;
|
path = alert.nib;
|
||||||
@ -7422,6 +7464,13 @@
|
|||||||
F5EA337C02EF889001A96654,
|
F5EA337C02EF889001A96654,
|
||||||
F5EA337D02EF889001A96654,
|
F5EA337D02EF889001A96654,
|
||||||
F5EA337E02EF889001A96654,
|
F5EA337E02EF889001A96654,
|
||||||
|
F522EFC502F73CF901A96654,
|
||||||
|
F522EFC602F73CF901A96654,
|
||||||
|
F522EFC702F73CF901A96654,
|
||||||
|
F522EFC802F73CF901A96654,
|
||||||
|
F522EFC902F73CF901A96654,
|
||||||
|
F522EFCA02F73CF901A96654,
|
||||||
|
F522EFCB02F73CF901A96654,
|
||||||
);
|
);
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
name = widget;
|
name = widget;
|
||||||
|
@ -287,7 +287,8 @@ BookmarksService::BookmarkChanged(nsIContent* aItem, bool shouldFlush = true)
|
|||||||
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
NSMenuItem* childItem = [menu itemWithTag: contentID];
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aItem->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
[childItem setTitle: [NSString stringWith_nsAString: name]];
|
NSString* bookmarkTitle = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
[childItem setTitle: bookmarkTitle];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -740,7 +741,7 @@ BookmarksService::AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent
|
|||||||
{
|
{
|
||||||
nsAutoString name;
|
nsAutoString name;
|
||||||
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
aChild->GetAttr(kNameSpaceID_None, gNameAtom, name);
|
||||||
NSString* title = [NSString stringWith_nsAString: name];
|
NSString* title = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// Create a menu or menu item for the child.
|
// Create a menu or menu item for the child.
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#import "NSString+Utils.h"
|
||||||
|
|
||||||
#import "CHBrowserWrapper.h"
|
#import "CHBrowserWrapper.h"
|
||||||
#import "BrowserWindowController.h"
|
#import "BrowserWindowController.h"
|
||||||
#import "BookmarksService.h"
|
#import "BookmarksService.h"
|
||||||
@ -358,7 +360,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
NSString* newTitle = nil;
|
NSString* newTitle = nil;
|
||||||
if (mOffline) {
|
if (mOffline) {
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
newTitle = [title stringByAppendingString: @" [Working Offline]"]; // XXX localize me
|
||||||
else
|
else
|
||||||
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
newTitle = [NSString stringWithString:@"Untitled [Working Offline]"];
|
||||||
mTitle = [newTitle retain];
|
mTitle = [newTitle retain];
|
||||||
@ -368,12 +370,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||||||
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
mTitle = [title retain];
|
mTitle = [title retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mIsPrimary && mWindowController )
|
if ( mIsPrimary && mWindowController )
|
||||||
[[mWindowController window] setTitle:mTitle];
|
[[mWindowController window] setTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]];
|
||||||
|
|
||||||
// Always set the tab.
|
// Always set the tab.
|
||||||
if (title && ![title isEqualToString:@""])
|
if (title && ![title isEqualToString:@""])
|
||||||
[mTab setLabel:title];
|
[mTab setLabel:title]; // tab titles get truncated when setting them to tabs
|
||||||
else
|
else
|
||||||
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
[mTab setLabel:NSLocalizedString(@"UntitledPageTitle", @"")];
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ ContentClickListener::MouseDown(nsIDOMEvent* aEvent)
|
|||||||
option->GetLabel(text);
|
option->GetLabel(text);
|
||||||
if (text.IsEmpty())
|
if (text.IsEmpty())
|
||||||
option->GetText(text);
|
option->GetText(text);
|
||||||
NSString* title = [NSString stringWith_nsAString: text];
|
NSString* title = [[NSString stringWith_nsAString: text] stringByTruncatingTo:75 at:kTruncateAtMiddle];
|
||||||
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
|
||||||
[menu addItem: menuItem];
|
[menu addItem: menuItem];
|
||||||
[menuItem setTag: contentID];
|
[menuItem setTag: contentID];
|
||||||
|
@ -41,9 +41,7 @@ static const int kDividerTag = 4000;
|
|||||||
// the maximum number of history entry menuitems to display
|
// the maximum number of history entry menuitems to display
|
||||||
static const int kMaxItems = 15;
|
static const int kMaxItems = 15;
|
||||||
// the maximum number of characters in a menu title before cropping it
|
// the maximum number of characters in a menu title before cropping it
|
||||||
static const unsigned int kMaxTitleLength = 60;
|
static const unsigned int kMaxTitleLength = 80;
|
||||||
// the ellipsis string to insert into cropped strings
|
|
||||||
static const NSString *kEllipsis = @"...";
|
|
||||||
|
|
||||||
@implementation CHGoMenu
|
@implementation CHGoMenu
|
||||||
|
|
||||||
@ -134,21 +132,7 @@ static const NSString *kEllipsis = @"...";
|
|||||||
|
|
||||||
nsXPIDLString textStr;
|
nsXPIDLString textStr;
|
||||||
entry->GetTitle(getter_Copies(textStr));
|
entry->GetTitle(getter_Copies(textStr));
|
||||||
NSString* title = [NSString stringWith_nsAString: textStr];
|
NSString* title = [[NSString stringWith_nsAString: textStr] stringByTruncatingTo:kMaxTitleLength at:kTruncateAtMiddle];
|
||||||
|
|
||||||
// if the title is too long, crop it in the middle
|
|
||||||
if ([title length] > kMaxTitleLength) {
|
|
||||||
NSMutableString *croppedTitle = [NSMutableString stringWithCapacity:kMaxTitleLength+[kEllipsis length]];
|
|
||||||
int len1 = kMaxTitleLength/2;
|
|
||||||
int len2 = kMaxTitleLength - len1;
|
|
||||||
NSString *part1 = [title substringWithRange:NSMakeRange(0, len1)];
|
|
||||||
NSString *part2 = [title substringWithRange:NSMakeRange([title length]-len2, len2)];
|
|
||||||
[croppedTitle appendString:part1];
|
|
||||||
[croppedTitle appendString:kEllipsis];
|
|
||||||
[croppedTitle appendString:part2];
|
|
||||||
title = croppedTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""];
|
||||||
[newItem setTarget:self];
|
[newItem setTarget:self];
|
||||||
[newItem setTag:kDividerTag+1+i];
|
[newItem setTag:kDividerTag+1+i];
|
||||||
|
@ -40,6 +40,14 @@
|
|||||||
|
|
||||||
class nsAString;
|
class nsAString;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
kTruncateAtStart,
|
||||||
|
kTruncateAtMiddle,
|
||||||
|
kTruncateAtEnd
|
||||||
|
} ETruncationType;
|
||||||
|
|
||||||
|
|
||||||
// a category to extend NSString
|
// a category to extend NSString
|
||||||
@interface NSString (ChimeraStringUtils)
|
@interface NSString (ChimeraStringUtils)
|
||||||
|
|
||||||
@ -49,5 +57,6 @@ class nsAString;
|
|||||||
|
|
||||||
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
|
||||||
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string;
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -117,4 +117,53 @@
|
|||||||
return cleanString;
|
return cleanString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*)stringByTruncatingTo:(int)maxCharacters at:(ETruncationType)truncationType
|
||||||
|
{
|
||||||
|
unichar ellipsisChar = 0x2026;
|
||||||
|
NSString* ellipsisString = [NSString stringWithCharacters:&ellipsisChar length:1]; // @"...";
|
||||||
|
|
||||||
|
if ([self length] > maxCharacters)
|
||||||
|
{
|
||||||
|
NSMutableString *croppedString = [NSMutableString stringWithCapacity:maxCharacters + [ellipsisString length]];
|
||||||
|
|
||||||
|
switch (truncationType)
|
||||||
|
{
|
||||||
|
case kTruncateAtStart:
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange([self length] - maxCharacters, maxCharacters)]];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtMiddle:
|
||||||
|
{
|
||||||
|
int len1 = maxCharacters / 2;
|
||||||
|
int len2 = maxCharacters - len1;
|
||||||
|
NSString *part1 = [self substringWithRange:NSMakeRange(0, len1)];
|
||||||
|
NSString *part2 = [self substringWithRange:NSMakeRange([self length] - len2, len2)];
|
||||||
|
[croppedString appendString:part1];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
[croppedString appendString:part2];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kTruncateAtEnd:
|
||||||
|
[croppedString appendString:[self substringWithRange:NSMakeRange(0, maxCharacters)]];
|
||||||
|
[croppedString appendString:ellipsisString];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
#if DEBUG
|
||||||
|
NSLog(@"Unknown truncation type in stringByTruncatingTo::");
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return croppedString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [[self copy] autorelease];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user