public void onCreateContextMenu( ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { final int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position; if (getItem(position) != null) { menu.setHeaderTitle(getItem(position).getText()); menu.add(0, OPEN_ITEM_ID, 0, myResource.getResource("open").getValue()); // menu.add(0, EDIT_ITEM_ID, 0, myResource.getResource("edit").getValue()); menu.add(0, DELETE_ITEM_ID, 0, myResource.getResource("delete").getValue()); } }
void setupPlaylistsContextMenu() { ContextMenu cm = playlistsContextMenu; MenuItem createOffline = menuItem( res.getString("create_offline_playlist"), () -> { createOfflinePlaylist(); }); MenuItem setAsFeatured = menuItem( res.getString("set_as_featured"), () -> { Playlist selectedPlaylist = (Playlist) playlistsView.getSelectionModel().getSelectedItem(); if (selectedPlaylist != null) { rememberedPlaylist = selectedPlaylist; Settings.rememberedPlaylistId = selectedPlaylist.getId(); infoLabel.setText( String.format(res.getString("featured_set"), selectedPlaylist.getTitle())); } }); MenuItem rename = menuItem( "(...) " + res.getString("rename_playlist"), () -> { renamePlaylist(); }); MenuItem delete = menuItem( "(-) " + res.getString("delete_playlist"), () -> { deletePlaylist(); }); cm.getItems() .addAll( createOffline, new SeparatorMenuItem(), setAsFeatured, new SeparatorMenuItem(), rename, delete); }
void setupTracksContextMenu() { ContextMenu cm = tracksContextMenu; List<MenuItem> items = cm.getItems(); items.clear(); Playlist pl = getSelectedPlaylist(); if (pl == null) { items.add( menuItem( "-> " + res.getString("add_to"), () -> { menuAddToPlaylist(); })); if (rememberedPlaylist != null) { items.add( menuItem( "-> " + String.format( res.getString("add_to_featured"), rememberedPlaylist.getTitle()), () -> { Track t = getSelectedTrack(); if (t != null) { addToPlaylist(t, rememberedPlaylist); } })); } } else { items.add( menuItem( "(+) " + res.getString("add_files"), () -> { FileChooser fileChooser = new FileChooser(); fileChooser.setInitialDirectory(new File(System.getProperty("user.dir"))); fileChooser.setTitle(String.format(res.getString("add_files_to"), pl.getTitle())); fileChooser .getExtensionFilters() .addAll(new FileChooser.ExtensionFilter("MP3", "*.mp3")); List<File> files = fileChooser.showOpenMultipleDialog(null); if (files != null) { addToPlaylist(files, pl); } })); items.add( menuItem( "(+) " + res.getString("add_folder_recursively"), () -> { DirectoryChooser dirChooser = new DirectoryChooser(); dirChooser.setTitle(String.format(res.getString("add_folder_to"), pl.getTitle())); dirChooser.setInitialDirectory(new File(System.getProperty("user.dir"))); File dir = dirChooser.showDialog(null); if (dir == null) return; Collection<File> files = FileUtils.listFiles(dir, new String[] {"mp3"}, true); addToPlaylist(new ArrayList(files), pl); })); items.add(new SeparatorMenuItem()); if (rememberedPlaylist != null) items.add( menuItem( "-> " + String.format( res.getString("add_to_featured"), rememberedPlaylist.getTitle()), () -> { Track t = getSelectedTrack(); if (t != null) addToPlaylist(t, rememberedPlaylist); })); items.add( menuItem( "-> " + res.getString("add_to"), () -> { menuAddToPlaylist(); })); items.add(new SeparatorMenuItem()); items.add( menuItem( "(...) " + res.getString("rename_track"), () -> { renameTrack(); })); items.add(new SeparatorMenuItem()); items.add( menuItem( "(-) " + res.getString("delete_track") + pl.getTitle(), () -> { deleteTrackFromPlaylist(); })); items.add( menuItem( "(-) " + res.getString("delete_dead_items"), () -> { Track t = getSelectedTrack(); if (t == null) { return; } deleteDeadFromOfflinePlaylist(pl); })); } }
public MyTab createTab() { MyTab tab = new MyTab() { @Override public ButtonType close() { if (Objects.nonNull(this.getPath())) closedPaths.add(Optional.ofNullable(current.currentTab().getPath())); ButtonType closeType = super.close(); Platform.runLater( () -> { ObservableList<Tab> tabs = controller.getTabPane().getTabs(); if (tabs.isEmpty()) { controller.newDoc(null); } }); return closeType; } }; tab.setOnCloseRequest( event -> { event.consume(); tab.close(); }); MenuItem menuItem0 = new MenuItem("Close"); menuItem0.setOnAction( actionEvent -> { tab.close(); }); MenuItem menuItem1 = new MenuItem("Close All"); menuItem1.setOnAction( actionEvent -> { ObservableList<Tab> tabs = controller.getTabPane().getTabs(); ObservableList<Tab> clonedTabs = FXCollections.observableArrayList(tabs); if (clonedTabs.size() > 0) { clonedTabs.forEach( (closedTab) -> { MyTab myTab = (MyTab) closedTab; myTab.close(); }); } }); MenuItem menuItem2 = new MenuItem("Close Others"); menuItem2.setOnAction( actionEvent -> { ObservableList<Tab> blackList = FXCollections.observableArrayList(); blackList.addAll(controller.getTabPane().getTabs()); blackList.remove(tab); blackList.forEach( t -> { MyTab closeTab = (MyTab) t; closeTab.close(); }); }); // // MenuItem menuItem3 = new MenuItem("Close Unmodified"); // menuItem3.setOnAction(actionEvent -> { // // ObservableList<Tab> clonedTabs = FXCollections.observableArrayList(); // clonedTabs.addAll(controller.getTabPane().getTabs()); // // // for (Tab clonedTab : clonedTabs) { // MyTab myTab = (MyTab) clonedTab; // if (!myTab.getTabText().contains(" *")) // threadService.runActionLater(()->{ // myTab.close(); // }); // } // }); MenuItem menuItem4 = new MenuItem("Select Next Tab"); menuItem4.setOnAction( actionEvent -> { TabPane tabPane = controller.getTabPane(); if (tabPane.getSelectionModel().isSelected(tabPane.getTabs().size() - 1)) tabPane.getSelectionModel().selectFirst(); else tabPane.getSelectionModel().selectNext(); }); MenuItem menuItem5 = new MenuItem("Select Previous Tab"); menuItem5.setOnAction( actionEvent -> { SingleSelectionModel<Tab> selectionModel = controller.getTabPane().getSelectionModel(); if (selectionModel.isSelected(0)) selectionModel.selectLast(); else selectionModel.selectPrevious(); }); MenuItem menuItem6 = new MenuItem("Reopen Closed Tab"); menuItem6.setOnAction( actionEvent -> { if (closedPaths.size() > 0) { int index = closedPaths.size() - 1; closedPaths.get(index).filter(pathResolver::isAsciidoc).ifPresent(this::addTab); closedPaths.get(index).filter(pathResolver::isMarkdown).ifPresent(this::addTab); closedPaths.get(index).filter(pathResolver::isImage).ifPresent(this::addImageTab); closedPaths.remove(index); } }); MenuItem menuItem7 = new MenuItem("Open File Location"); menuItem7.setOnAction( event -> { current .currentPath() .ifPresent( path -> { controller .getHostServices() .showDocument(path.getParent().toUri().toASCIIString()); }); }); MenuItem menuItem8 = new MenuItem("New File"); menuItem8.setOnAction(controller::newDoc); MenuItem gotoWorkdir = new MenuItem("Go to Workdir"); gotoWorkdir.setOnAction( event -> { current.currentPath().map(Path::getParent).ifPresent(directoryService::changeWorkigDir); }); ContextMenu contextMenu = new ContextMenu(); contextMenu .getItems() .addAll( menuItem0, menuItem1, menuItem2, new SeparatorMenuItem(), menuItem4, menuItem5, menuItem6, new SeparatorMenuItem(), gotoWorkdir, new SeparatorMenuItem(), menuItem7, menuItem8); tab.contextMenuProperty().setValue(contextMenu); Label label = tab.getLabel(); label.setOnMouseClicked( mouseEvent -> { if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) { tab.select(); } else if (mouseEvent.getClickCount() > 1) { controller.adjustSplitPane(); } }); return tab; }