/** Opens the selected file in RText, if any. */ private void handleOpenFile() { File file = getSelectedFile(); if (file != null) { // We'll make sure the file exists and is a regular file // (as opposed to a directory) before attempting to open it. if (file.isFile()) { AbstractMainView mainView = plugin.getRText().getMainView(); mainView.openFile(file.getAbsolutePath(), null, true); } else if (getLastSelectedPathComponent() instanceof FileProjectEntryTreeNode) { FileProjectEntryTreeNode node = (FileProjectEntryTreeNode) getLastSelectedPathComponent(); promptForRemoval(node); } } }
/** * Prompts the user that a file does not exist, and asks whether they want to remove the tree node * for it. The node is removed (and the project updated) if the user selects "yes." * * @param node The node to prompt about and possibly remove. */ public void promptForRemoval(FileProjectEntryTreeNode node) { File file = node.getFile(); if (file.isDirectory()) { // FolderProjectEntryTreeNode extends FileProjectEntryTreeNode, // and careless callers might not realize this. return; } String msg = Messages.getString("Prompt.FileDoesntExist.Remove", node.getFile().getAbsolutePath()); RText rtext = plugin.getRText(); String title = rtext.getString("ConfDialogTitle"); int rc = JOptionPane.showConfirmDialog(rtext, msg, title, JOptionPane.YES_NO_OPTION); if (rc == JOptionPane.YES_OPTION) { model.removeNodeFromParent(node); node.entry.removeFromParent(); } }
protected void findInFilesFromSelectedDir() { File dir = getSelectedFile(); Object sel = getLastSelectedPathComponent(); if (dir != null && dir.isDirectory()) { RText rtext = plugin.getRText(); rtext.getMainView().getFindInFilesDialog().setSearchIn(dir); // Note the ActionEvent isn't actually used; we're just doing // this for completeness. ActionEvent ae = new ActionEvent(this, 0, "ignored"); rtext.getAction(RTextActionInfo.FIND_IN_FILES_ACTION).actionPerformed(ae); } else if (dir != null && !dir.exists() && sel instanceof FileProjectEntryTreeNode) { // Directory was deleted out from under us FileProjectEntryTreeNode fpetn = (FileProjectEntryTreeNode) sel; promptForRemoval(fpetn); } else { // Directory changed to a file out from under us? UIManager.getLookAndFeel().provideErrorFeedback(this); } }