/** * @param item Menu item * @return True if enabled */ @Override public boolean validateMenuItem(final NSMenuItem item) { final Selector action = item.action(); if(action.equals(Foundation.selector("paste:"))) { final List<PathPasteboard> pasteboards = PathPasteboardFactory.allPasteboards(); if(pasteboards.size() == 1) { for(PathPasteboard pasteboard : pasteboards) { if(pasteboard.size() == 1) { item.setTitle(MessageFormat.format(LocaleFactory.localizedString("Paste {0}"), pasteboard.get(0).getName())); } else { item.setTitle(MessageFormat.format(LocaleFactory.localizedString("Paste {0}"), MessageFormat.format(LocaleFactory.localizedString("{0} Files"), String.valueOf(pasteboard.size())) + ")")); } } } else { item.setTitle(LocaleFactory.localizedString("Paste")); } } return toolbarValidator.validate(action); }
@Override public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger index, boolean cancel) { final Archive archive = Archive.getKnownArchives()[index.intValue()]; item.setRepresentedObject(archive.getIdentifier()); item.setTitle(archive.getIdentifier()); item.setAction(this.getDefaultAction()); return super.menuUpdateItemAtIndex(menu, item, index, cancel); }
if(action.equals(Foundation.selector("paste:"))) { final String title = "Paste {0}"; item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title), StringUtils.EMPTY).trim()); if(this.isMounted()) { if(pasteboard.isEmpty()) { final NSArray elements = Rococoa.cast(o, NSArray.class); if(elements.count().intValue() == 1) { item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title), "\"" + elements.objectAtIndex(new NSUInteger(0)) + "\"").trim()); item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title), MessageFormat.format(LocaleFactory.localizedString("{0} Files"), String.valueOf(elements.count().intValue())) item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title), "\"" + pasteboard.get(0).getName() + "\"").trim()); item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title), MessageFormat.format(LocaleFactory.localizedString("{0} Files"), String.valueOf(pasteboard.size()))).trim()); int count = this.getSelectionCount(); if(0 == count) { item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title), StringUtils.EMPTY).trim()); item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title), "\"" + this.getSelectedPath().getName() + "\"").trim()); item.setTitle(MessageFormat.format(LocaleFactory.localizedString(title),
final List<Path> selected = this.getSelected(); if(selected.isEmpty() || this.getURLs(selected.iterator().next()).isEmpty()) { item.setTitle(LocaleFactory.localizedString("None")); item.setEnabled(false); item.setAction(null); Iterator<Path> iter = selected.iterator(); final DescriptiveUrl url = this.getURLs(iter.next()).get(index.intValue() / 2); item.setTitle(url.getHelp()); if(url.getType().equals(DescriptiveUrl.Type.provider)) { this.setShortcut(item, this.getKeyEquivalent(), this.getModifierMask());
public void downloadPathPanelDidEnd_returnCode_contextInfo(NSOpenPanel sheet, final int returncode, ID contextInfo) { switch(returncode) { case SheetCallback.DEFAULT_OPTION: final NSObject selected = sheet.filenames().lastObject(); if(selected != null) { bookmark.setDownloadFolder(LocalFactory.get(selected.toString())); } break; } final NSMenuItem item = downloadPathPopup.itemAtIndex(new NSInteger(0)); final Local folder = new DownloadDirectoryFinder().find(bookmark); item.setTitle(folder.getDisplayName()); item.setRepresentedObject(folder.getAbsolute()); item.setImage(IconCacheFactory.<NSImage>get().fileIcon(folder, 16)); downloadPathPopup.selectItem(item); downloadFolderOpenPanel = null; this.update(); }
public void downloadPathPanelDidEnd_returnCode_contextInfo(NSOpenPanel sheet, int returncode, ID contextInfo) { if(returncode == SheetCallback.DEFAULT_OPTION) { NSArray selected = sheet.filenames(); String filename; if((filename = selected.lastObject().toString()) != null) { final Local folder = LocalFactory.get(filename); preferences.setProperty("queue.download.folder", folder.getAbbreviatedPath()); preferences.setProperty("queue.download.folder.bookmark", folder.getBookmark()); } } final Local custom = LocalFactory.get(preferences.getProperty("queue.download.folder")); final NSMenuItem item = downloadPathPopup.itemAtIndex(new NSInteger(0)); item.setTitle(custom.getDisplayName()); item.setRepresentedObject(custom.getAbsolute()); item.setImage(IconCacheFactory.<NSImage>get().fileIcon(custom, 16)); downloadPathPopup.selectItem(item); downloadPathPanel = null; }
@Override public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger index, boolean cancel) { if(collection.size() == 0) { item.setTitle(LocaleFactory.localizedString("None")); item.setTarget(null); item.setAction(null); item.setImage(null); item.setEnabled(false); } else { final Host h = this.itemForIndex(index); item.setTitle(BookmarkNameProvider.toString(h)); item.setTarget(this.id()); item.setEnabled(true); item.setImage(IconCacheFactory.<NSImage>get().iconNamed(h.getProtocol().icon(), preferences.getInteger("bookmark.menu.icon.size"))); item.setTarget(this.id()); item.setAction(this.getDefaultAction()); item.setRepresentedObject(h.getUuid()); } return super.menuUpdateItemAtIndex(menu, item, index, cancel); }
@Override public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger row, boolean cancel) { if(row.intValue() == index) { item.setEnabled(true); item.setTitle(LocaleFactory.get().localize("History", "Localizable")); item.setImage(IconCacheFactory.<NSImage>get().iconNamed("history.tiff", 16)); item.setTarget(this.id()); item.setAction(Foundation.selector("historyMenuClicked:")); item.setSubmenu(historyMenu); } if(row.intValue() == index + 1) { item.setEnabled(true); item.setTitle(LocaleFactory.get().localize("Bonjour", "Main")); item.setImage(IconCacheFactory.<NSImage>get().iconNamed("rendezvous.tiff", 16)); item.setSubmenu(rendezvousMenu); } if(row.intValue() == index + 2) { menu.removeItemAtIndex(row); menu.insertItem_atIndex(this.seperator(), row); } if(row.intValue() > index + 2) { Host h = this.itemForIndex(row); item.setTitle(BookmarkNameProvider.toString(h)); item.setTarget(this.id()); item.setImage(IconCacheFactory.<NSImage>get().iconNamed(h.getProtocol().icon(), preferences.getInteger("bookmark.menu.icon.size"))); item.setAction(this.getDefaultAction()); item.setRepresentedObject(h.getUuid()); } return super.menuUpdateItemAtIndex(menu, item, row, cancel); }