use of ch.cyberduck.binding.foundation.NSMutableAttributedString in project cyberduck by iterate-ch.
the class BookmarkMenuDelegate method menuNeedsUpdate.
public void menuNeedsUpdate(final NSMenu menu) {
if (!this.isPopulated()) {
if (log.isTraceEnabled()) {
log.trace(String.format("Build menu %s", menu));
}
for (int i = menu.numberOfItems().intValue() - 1; i >= BOOKMARKS_INDEX; i--) {
menu.removeItemAtIndex(new NSInteger(i));
}
{
final NSMenuItem item = NSMenuItem.itemWithTitle(LocaleFactory.get().localize("History", "Localizable"), null, StringUtils.EMPTY);
item.setEnabled(true);
item.setImage(IconCacheFactory.<NSImage>get().iconNamed("history.tiff", 16));
item.setTarget(this.id());
item.setAction(Foundation.selector("historyMenuClicked:"));
historyMenu.setSupermenu(null);
item.setSubmenu(historyMenu);
menu.addItem(item);
}
{
final NSMenuItem item = NSMenuItem.itemWithTitle(LocaleFactory.get().localize("Bonjour", "Main"), null, StringUtils.EMPTY);
item.setEnabled(true);
item.setImage(IconCacheFactory.<NSImage>get().iconNamed("rendezvous.tiff", 16));
rendezvousMenu.setSupermenu(null);
item.setSubmenu(rendezvousMenu);
menu.addItem(item);
}
menu.addItem(NSMenuItem.separatorItem());
bookmarks.groups(HostFilter.NONE).forEach((label, bookmarks) -> {
final NSMenu submenu;
if (StringUtils.isNotBlank(label)) {
final NSMenuItem group = NSMenuItem.itemWithTitle(label, null, StringUtils.EMPTY);
final NSMutableAttributedString title = NSMutableAttributedString.create(label);
title.appendAttributedString(NSAttributedString.attributedStringWithAttributes(String.format("\n%s", MessageFormat.format(LocaleFactory.localizedString("{0} Bookmarks", "Localizable"), bookmarks.size())), BundleController.MENU_HELP_FONT_ATTRIBUTES));
group.setAttributedTitle(title);
switch(preferences.getInteger("bookmark.menu.icon.size")) {
default:
group.setImage(IconCacheFactory.<NSImage>get().iconNamed("NSFolder", CollectionMenuDelegate.SMALL_ICON_SIZE));
break;
case BookmarkCell.MEDIUM_BOOKMARK_SIZE:
group.setImage(IconCacheFactory.<NSImage>get().iconNamed("NSFolder", CollectionMenuDelegate.MEDIUM_ICON_SIZE));
break;
case BookmarkCell.LARGE_BOOKMARK_SIZE:
group.setImage(IconCacheFactory.<NSImage>get().iconNamed("NSFolder", CollectionMenuDelegate.LARGE_ICON_SIZE));
break;
}
submenu = NSMenu.menu();
group.setSubmenu(submenu);
menu.addItem(group);
} else {
submenu = menu;
}
for (Host h : bookmarks) {
submenu.addItem(build(h));
}
});
}
}
use of ch.cyberduck.binding.foundation.NSMutableAttributedString in project cyberduck by iterate-ch.
the class BookmarkMenuDelegate method build.
private NSMenuItem build(final Host h) {
final NSMenuItem item = NSMenuItem.itemWithTitle(BookmarkNameProvider.toString(h), this.getDefaultAction(), StringUtils.EMPTY);
final NSMutableAttributedString title = NSMutableAttributedString.create(BookmarkNameProvider.toString(h));
if (preferences.getInteger("bookmark.menu.icon.size") >= BookmarkCell.MEDIUM_BOOKMARK_SIZE) {
title.appendAttributedString(NSAttributedString.attributedStringWithAttributes(String.format("\n%s", h.getHostname()), BundleController.MENU_HELP_FONT_ATTRIBUTES));
}
if (preferences.getInteger("bookmark.menu.icon.size") >= BookmarkCell.LARGE_BOOKMARK_SIZE) {
title.appendAttributedString(NSAttributedString.attributedStringWithAttributes(String.format("\n%s", StringUtils.isNotBlank(h.getCredentials().getUsername()) ? h.getCredentials().getUsername() : StringUtils.EMPTY), BundleController.MENU_HELP_FONT_ATTRIBUTES));
}
item.setAttributedTitle(title);
item.setTitle(BookmarkNameProvider.toString(h));
switch(preferences.getInteger("bookmark.menu.icon.size")) {
default:
item.setImage(IconCacheFactory.<NSImage>get().iconNamed(h.getProtocol().icon(), CollectionMenuDelegate.SMALL_ICON_SIZE));
break;
case BookmarkCell.MEDIUM_BOOKMARK_SIZE:
item.setImage(IconCacheFactory.<NSImage>get().iconNamed(h.getProtocol().icon(), CollectionMenuDelegate.MEDIUM_ICON_SIZE));
break;
case BookmarkCell.LARGE_BOOKMARK_SIZE:
item.setImage(IconCacheFactory.<NSImage>get().iconNamed(h.getProtocol().icon(), CollectionMenuDelegate.LARGE_ICON_SIZE));
break;
}
item.setTarget(this.id());
item.setAction(this.getDefaultAction());
item.setRepresentedObject(h.getUuid());
return item;
}
Aggregations