From 74412a52d6d5c4e19456247d8a3642ae0b0eb597 Mon Sep 17 00:00:00 2001 From: angryziber Date: Wed, 11 Jul 2007 22:30:57 +0000 Subject: [PATCH] * Ctrl+C is not a global key binding anymore, so default Ctrl+C behaviour (copy) should work in edit fields now in the MainWindow. * Enter now produces the expected behaviour when the program has just started git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@148 375186e5-ef17-0410-b0b6-91563547dcda --- resources/Labels.txt | 4 ++-- src/net/azib/ipscan/gui/MainMenu.java | 4 ++-- src/net/azib/ipscan/gui/ResultTable.java | 7 +++++-- .../azib/ipscan/gui/actions/CommandsActions.java | 14 +++++++++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/resources/Labels.txt b/resources/Labels.txt index d40ba523..f7577e57 100755 --- a/resources/Labels.txt +++ b/resources/Labels.txt @@ -21,8 +21,8 @@ menu.commands.show=Show menu.commands.open=Open menu.commands.open.edit=Edit openers... menu.favorites=Fa&vorites -menu.favorites.add=Add current... -menu.favorites.edit=Manage favorites... +menu.favorites.add=Ad&d current... +menu.favorites.edit=&Manage favorites... menu.tools=&Tools menu.tools.options=&Options... menu.tools.fetchers=Select &fetchers... diff --git a/src/net/azib/ipscan/gui/MainMenu.java b/src/net/azib/ipscan/gui/MainMenu.java index 0ebcee74..7544fc9d 100755 --- a/src/net/azib/ipscan/gui/MainMenu.java +++ b/src/net/azib/ipscan/gui/MainMenu.java @@ -110,9 +110,9 @@ public class MainMenu { initMenuItem(menu, "menu.commands.details", null, null, initListener(CommandsActions.Details.class)); initMenuItem(menu, null, null, null, null); initMenuItem(menu, "menu.commands.rescan", "Ctrl+R", new Integer(SWT.MOD1 | 'R'), initListener(CommandsActions.Rescan.class)); - initMenuItem(menu, "menu.commands.delete", "Del", null, initListener(CommandsActions.Delete.class)); + initMenuItem(menu, "menu.commands.delete", "Del", /* this is not a global key binding */ null, initListener(CommandsActions.Delete.class)); initMenuItem(menu, null, null, null, null); - initMenuItem(menu, "menu.commands.copy", "Ctrl+C", new Integer(SWT.MOD1 | 'C'), initListener(CommandsActions.CopyIP.class)); + initMenuItem(menu, "menu.commands.copy", "Ctrl+C", /* this is not a global key binding */ null, initListener(CommandsActions.CopyIP.class)); initMenuItem(menu, "menu.commands.copyDetails", null, null, initListener(CommandsActions.CopyIPDetails.class)); initMenuItem(menu, null, null, null, null); createOpenersMenu(menu); diff --git a/src/net/azib/ipscan/gui/ResultTable.java b/src/net/azib/ipscan/gui/ResultTable.java index 0a059243..80b5776f 100755 --- a/src/net/azib/ipscan/gui/ResultTable.java +++ b/src/net/azib/ipscan/gui/ResultTable.java @@ -65,16 +65,19 @@ public class ResultTable extends Table implements FetcherRegistryUpdateListener Listener detailsListener = new Listener() { CommandsActions.Details detailsListener = new CommandsActions.Details(ResultTable.this); public void handleEvent(Event e) { - if (e.type == SWT.MouseDoubleClick || e.detail == SWT.TRAVERSE_RETURN) { - detailsListener.handleEvent(e); + // activate only if something is selected + if (getSelectionIndex() >= 0 && (e.type == SWT.MouseDoubleClick || e.detail == SWT.TRAVERSE_RETURN)) { e.doit = false; + detailsListener.handleEvent(e); } } }; addListener(SWT.Traverse, detailsListener); addListener(SWT.MouseDoubleClick, detailsListener); addListener(SWT.KeyDown, new CommandsActions.Delete(this)); + addListener(SWT.KeyDown, new CommandsActions.CopyIP(this)); + // this one populates table dynamically, taking data from ScanningResultList addListener(SWT.SetData, new SetDataListener()); } diff --git a/src/net/azib/ipscan/gui/actions/CommandsActions.java b/src/net/azib/ipscan/gui/actions/CommandsActions.java index 2cac8745..4f7d6663 100755 --- a/src/net/azib/ipscan/gui/actions/CommandsActions.java +++ b/src/net/azib/ipscan/gui/actions/CommandsActions.java @@ -96,6 +96,10 @@ public class CommandsActions { } } + /** + * Copies currently selected IP to the clipboard. + * Used as both menu item listener and keydown listener. + */ public static class CopyIP implements Listener { private ResultTable resultTable; @@ -104,7 +108,15 @@ public class CommandsActions { } public void handleEvent(Event event) { - checkSelection(resultTable); + if (event.type == SWT.KeyDown) { + // if this is not Ctrl+C or nothing is selected, then simply do nothing + if ((event.keyCode != 'c' && event.stateMask != SWT.MOD1) || resultTable.getSelectionIndex() < 0) + return; + } + else { + // if selected from the menu, check selection + checkSelection(resultTable); + } Clipboard clipboard = new Clipboard(event.display); clipboard.setContents(new Object[] {resultTable.getItem(resultTable.getSelectionIndex()).getText()}, new Transfer[] {TextTransfer.getInstance()}); clipboard.dispose();