Search in sources :

Example 1 with NSMutableAttributedString

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));
            }
        });
    }
}
Also used : NSInteger(org.rococoa.cocoa.foundation.NSInteger) NSMenu(ch.cyberduck.binding.application.NSMenu) NSImage(ch.cyberduck.binding.application.NSImage) Host(ch.cyberduck.core.Host) NSMutableAttributedString(ch.cyberduck.binding.foundation.NSMutableAttributedString) NSMenuItem(ch.cyberduck.binding.application.NSMenuItem)

Example 2 with NSMutableAttributedString

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;
}
Also used : NSImage(ch.cyberduck.binding.application.NSImage) NSMutableAttributedString(ch.cyberduck.binding.foundation.NSMutableAttributedString) NSMenuItem(ch.cyberduck.binding.application.NSMenuItem)

Aggregations

NSImage (ch.cyberduck.binding.application.NSImage)2 NSMenuItem (ch.cyberduck.binding.application.NSMenuItem)2 NSMutableAttributedString (ch.cyberduck.binding.foundation.NSMutableAttributedString)2 NSMenu (ch.cyberduck.binding.application.NSMenu)1 Host (ch.cyberduck.core.Host)1 NSInteger (org.rococoa.cocoa.foundation.NSInteger)1