Commit 9e24a5ab authored by Skylot's avatar Skylot

fix(gui): show 'copy name' action only for supported nodes

parent b587b6d6
......@@ -225,9 +225,12 @@ class TabbedPane extends JTabbedPane {
private JPopupMenu createTabPopupMenu(final ContentPanel contentPanel) {
JPopupMenu menu = new JPopupMenu();
JMenuItem copyRootClassName = new JMenuItem(NLS.str("tabs.copy_class_name"));
copyRootClassName.addActionListener(actionEvent -> copyRootClassName());
menu.add(copyRootClassName);
if (getNodeFullName() != null) {
JMenuItem copyRootClassName = new JMenuItem(NLS.str("tabs.copy_class_name"));
copyRootClassName.addActionListener(actionEvent -> copyRootClassName());
menu.add(copyRootClassName);
menu.addSeparator();
}
JMenuItem closeTab = new JMenuItem(NLS.str("tabs.close"));
closeTab.addActionListener(e -> closeCodePanel(contentPanel));
......@@ -275,15 +278,25 @@ class TabbedPane extends JTabbedPane {
}
public void copyRootClassName() {
String name = getNodeFullName();
if (name != null) {
Utils.setClipboardString(name);
}
}
@Nullable
private String getNodeFullName() {
ContentPanel selectedPanel = getSelectedCodePanel();
if (selectedPanel != null) {
JNode node = selectedPanel.getNode();
JClass jClass = node.getRootClass();
if (jClass != null) {
String name = jClass.getFullName();
Utils.setClipboardString(name);
return jClass.getFullName();
} else {
return node.getName();
}
}
return null;
}
public void loadSettings() {
......
......@@ -141,9 +141,14 @@ public class Utils {
return toLower ? Character.toLowerCase(ch) : ch;
}
public static void setClipboardString(String text){
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection(text);
clipboard.setContents(transferable, null);
public static void setClipboardString(String text) {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection(text);
clipboard.setContents(transferable, null);
LOG.debug("String '{}' copied to clipboard", text);
} catch (Exception e) {
LOG.error("Failed copy string '{}' to clipboard", text, e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment