use of com.igormaznitsa.sciareto.ui.FindUsagesPanel in project netbeans-mmd-plugin by raydac.
the class ExplorerTree method makePopupMenu.
@Nonnull
private JPopupMenu makePopupMenu(@Nonnull final NodeFileOrFolder node) {
final JPopupMenu result = new JPopupMenu();
if (!node.isLeaf()) {
final JMenu makeNew = new JMenu("New...");
JMenuItem item = new JMenuItem("Folder");
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
addChildTo(node, null);
}
});
makeNew.add(item);
item = new JMenuItem("Mind map");
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
// NOI18N
addChildTo(node, "mmd");
}
});
makeNew.add(item);
item = new JMenuItem("Text");
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
// NOI18N
addChildTo(node, "txt");
}
});
makeNew.add(item);
item = new JMenuItem("PlantUML");
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
// NOI18N
addChildTo(node, "puml");
}
});
makeNew.add(item);
result.add(makeNew);
}
if (!node.isProjectKnowledgeFolder()) {
final JMenuItem rename = new JMenuItem("Rename");
rename.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
projectTree.startEditingAtPath(node.makeTreePath());
}
});
result.add(rename);
}
if (node instanceof NodeProject) {
final JMenuItem close = new JMenuItem("Close");
close.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
if (DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(Main.getApplicationFrame(), "Close '" + node + '\'', "Do you really want close '" + node + "\'?\nIt will be just removed from the tree.")) {
сloseProject((NodeProject) node);
}
}
});
result.add(close);
final JMenuItem refresh = new JMenuItem("Reload");
refresh.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
getCurrentGroup().refreshProjectFolder((NodeProject) node, PrefUtils.isShowHiddenFilesAndFolders());
}
});
result.add(refresh);
}
final JMenuItem delete = new JMenuItem("Delete");
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
if (DialogProviderManager.getInstance().getDialogProvider().msgConfirmYesNo(null, "Delete", "Do you really want to delete \"" + node + "\"?")) {
context.deleteTreeNode(node);
}
}
});
result.add(delete);
final JMenuItem openInSystem = new JMenuItem("Open in System");
openInSystem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
final File file = node.makeFileForNode();
if (file != null && file.exists()) {
UiUtils.openInSystemViewer(file);
}
}
});
result.add(openInSystem);
if (node instanceof NodeProject) {
final NodeProject theProject = (NodeProject) node;
if (!theProject.hasKnowledgeFolder()) {
final File knowledgeFolder = new File(theProject.getFolder(), Context.KNOWLEDGE_FOLDER);
final JMenuItem addKnowledgeFolder = new JMenuItem("Create Knowledge folder");
addKnowledgeFolder.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
if (knowledgeFolder.mkdirs()) {
getCurrentGroup().refreshProjectFolder(theProject, PrefUtils.isShowHiddenFilesAndFolders());
context.focusInTree(knowledgeFolder);
} else {
// NOI18N
LOGGER.error("Can't create knowledge folder : " + knowledgeFolder);
}
}
});
result.add(addKnowledgeFolder);
}
}
final String BUILD_GRAPH_ITEM = "Build file links graph";
if (node instanceof NodeProject) {
final JMenuItem buildMindMapGraph = new JMenuItem(BUILD_GRAPH_ITEM);
buildMindMapGraph.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
context.showGraphMindMapFileLinksDialog(((NodeProject) node).getFolder(), null, true);
}
});
result.add(buildMindMapGraph);
} else if (node.isLeaf() && node.isMindMapFile()) {
final JMenuItem buildMindMapGraph = new JMenuItem(BUILD_GRAPH_ITEM);
buildMindMapGraph.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
final NodeProject project = node.findProject();
context.showGraphMindMapFileLinksDialog(project == null ? null : project.getFolder(), node.makeFileForNode(), true);
}
});
result.add(buildMindMapGraph);
}
final List<JMenuItem> optional = new ArrayList<>();
final JMenuItem menuSearchUsage = new JMenuItem("Find in maps");
menuSearchUsage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
if (context.hasUnsavedDocument() && !DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "Detected unsaved documents", "Unsaved content will not be processed!")) {
return;
}
final FindUsagesPanel panel = new FindUsagesPanel(context, node, false);
if (DialogProviderManager.getInstance().getDialogProvider().msgOkCancel(null, "Find usages in all opened projects", panel)) {
final NodeFileOrFolder selected = panel.getSelected();
panel.dispose();
if (selected != null) {
final File file = selected.makeFileForNode();
if (file != null) {
context.focusInTree(file);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
requestFocus();
}
});
}
}
} else {
panel.dispose();
}
}
});
optional.add(menuSearchUsage);
if (!node.isLeaf()) {
final JMenuItem menuSearchFilesForText = new JMenuItem("Find files for text");
menuSearchFilesForText.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final FindFilesForTextPanel panel = new FindFilesForTextPanel(context, node, JOptionPane.OK_OPTION);
if (DialogProviderManager.getInstance().getDialogProvider().msgOkCancel(null, "Find files for text in '" + node.name + '\'', panel)) {
final NodeFileOrFolder selected = panel.getSelected();
panel.dispose();
if (selected != null) {
final File file = selected.makeFileForNode();
if (file != null) {
context.focusInTree(file);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
requestFocus();
}
});
}
}
} else {
panel.dispose();
}
}
});
optional.add(menuSearchFilesForText);
}
final TabTitle editingTab = this.context.getFocusedTab();
if (editingTab != null && editingTab.getType() == EditorContentType.MINDMAP) {
final JMenuItem addIntoMap = new JMenuItem("Add File as topic");
addIntoMap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@Nonnull final ActionEvent e) {
addTreeAsTopic(context.findProjectForFile(editingTab.getAssociatedFile()), node, ((MMDEditor) editingTab.getProvider().getEditor()));
}
});
optional.add(addIntoMap);
}
if (!optional.isEmpty()) {
result.add(new JSeparator());
for (final JMenuItem i : optional) {
result.add(i);
}
}
return result;
}
Aggregations