From 61dcc746cebfecaf65f0883bc5594b76583803bf Mon Sep 17 00:00:00 2001 From: angryziber Date: Sun, 6 Apr 2008 22:07:11 +0000 Subject: [PATCH] * Ctrl+I now inverts the selection * Ctrl+A correctly updates the status bar with number of selected elements * Scan Info now is shown on Ctrl+K git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@373 375186e5-ef17-0410-b0b6-91563547dcda --- TODO | 1 - resources/Labels.txt | 3 +- src/net/azib/ipscan/gui/MainMenu.java | 4 +- src/net/azib/ipscan/gui/ResultTable.java | 2 +- .../ipscan/gui/actions/CommandsActions.java | 20 ------- .../azib/ipscan/gui/actions/ToolsActions.java | 53 +++++++++++++++++++ 6 files changed, 59 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index c0ff63f8..a1473d1c 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,6 @@ Before 3.0: * plugin loader * export/import of settings (profiles or tie with Favorites?) * top-level exception handler for NoClassDefFoundErrors, etc -* Tools -> Select -> Invert Selection * public XSL for XMLExporter * Exporter appending functionality exposed to the user * make Display: status bar right-clickable diff --git a/resources/Labels.txt b/resources/Labels.txt index 9c206790..36f8a351 100755 --- a/resources/Labels.txt +++ b/resources/Labels.txt @@ -28,11 +28,12 @@ menu.favorites.edit=&Manage favorites... menu.tools=&Tools menu.tools.preferences=&Preferences... menu.tools.fetchers=&Fetchers... -menu.tools.select=Se&lect in list +menu.tools.select=Se&lection menu.tools.select.alive=&Alive hosts menu.tools.select.dead=&Dead hosts menu.tools.select.withPorts=With &open ports menu.tools.select.withoutPorts=Without o&pen ports +menu.tools.select.invert=Invert selection menu.tools.scanInfo=Show scan &info menu.help=&Help menu.help.gettingStarted=Getting &Started diff --git a/src/net/azib/ipscan/gui/MainMenu.java b/src/net/azib/ipscan/gui/MainMenu.java index 9f2aee88..738bb4b5 100755 --- a/src/net/azib/ipscan/gui/MainMenu.java +++ b/src/net/azib/ipscan/gui/MainMenu.java @@ -106,12 +106,14 @@ public class MainMenu implements Startable { initMenuItem(subMenu, "menu.tools.fetchers", "Ctrl+Shift+O", new Integer(SWT.MOD1 | SWT.MOD2 | (Platform.MAC_OS ? ',' : 'O')), initListener(ToolsActions.ChooseFetchers.class), true); initMenuItem(subMenu, null, null, null, null); Menu selectMenu = initMenu(subMenu, "menu.tools.select"); - initMenuItem(subMenu, "menu.tools.scanInfo", "Ctrl+I", new Integer(SWT.MOD1 | 'I'), initListener(ToolsActions.ScanInfo.class)); + initMenuItem(subMenu, "menu.tools.scanInfo", "Ctrl+K", new Integer(SWT.MOD1 | 'K'), initListener(ToolsActions.ScanInfo.class)); initMenuItem(selectMenu, "menu.tools.select.alive", null, null, initListener(ToolsActions.SelectAlive.class), true); initMenuItem(selectMenu, "menu.tools.select.dead", null, null, initListener(ToolsActions.SelectDead.class), true); initMenuItem(selectMenu, "menu.tools.select.withPorts", null, null, initListener(ToolsActions.SelectWithPorts.class), true); initMenuItem(selectMenu, "menu.tools.select.withoutPorts", null, null, initListener(ToolsActions.SelectWithoutPorts.class), true); + initMenuItem(selectMenu, null, null, null, null); + initMenuItem(selectMenu, "menu.tools.select.invert", "Ctrl+I", new Integer(SWT.MOD1 | 'I'), initListener(ToolsActions.SelectInvert.class), true); subMenu = initMenu(menu, "menu.help"); initMenuItem(subMenu, "menu.help.gettingStarted", !Platform.MAC_OS ? "F1" : null, new Integer(Platform.MAC_OS ? SWT.HELP : SWT.F1), initListener(HelpActions.GettingStarted.class)); diff --git a/src/net/azib/ipscan/gui/ResultTable.java b/src/net/azib/ipscan/gui/ResultTable.java index 4986ab88..fb01f18c 100755 --- a/src/net/azib/ipscan/gui/ResultTable.java +++ b/src/net/azib/ipscan/gui/ResultTable.java @@ -69,8 +69,8 @@ public class ResultTable extends Table implements FetcherRegistryUpdateListener addListener(SWT.Selection, selectionListener); addListener(SWT.KeyDown, new CommandsActions.Delete(this, stateMachine, selectionListener)); - addListener(SWT.KeyDown, new CommandsActions.SelectAll(this)); addListener(SWT.KeyDown, new CommandsActions.CopyIP(this)); + addListener(SWT.KeyDown, new ToolsActions.SelectAll(this, selectionListener)); // 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 cf85cba1..66511b91 100755 --- a/src/net/azib/ipscan/gui/actions/CommandsActions.java +++ b/src/net/azib/ipscan/gui/actions/CommandsActions.java @@ -107,26 +107,6 @@ public class CommandsActions { } } - /** - * This cannot be accessed from the menu, but it provides the Ctrl+A - * Select All functionality for Windows (other platforms implement this themselves) - */ - public static class SelectAll implements Listener { - private final ResultTable resultTable; - - public SelectAll(ResultTable resultTable) { - this.resultTable = resultTable; - } - - public void handleEvent(Event event) { - // Ctrl+A handler - if (event.type == SWT.KeyDown && event.keyCode == 'a' && event.stateMask == SWT.MOD1) { - resultTable.selectAll(); - event.doit = false; - } - } - } - public static final class Rescan implements Listener { private final ResultTable resultTable; private final StateMachine stateMachine; diff --git a/src/net/azib/ipscan/gui/actions/ToolsActions.java b/src/net/azib/ipscan/gui/actions/ToolsActions.java index b794f066..c14b271d 100755 --- a/src/net/azib/ipscan/gui/actions/ToolsActions.java +++ b/src/net/azib/ipscan/gui/actions/ToolsActions.java @@ -18,6 +18,7 @@ import net.azib.ipscan.gui.SelectFetchersDialog; import net.azib.ipscan.gui.StatisticsDialog; import net.azib.ipscan.gui.StatusBar; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -186,4 +187,56 @@ public class ToolsActions { return type == ResultType.ALIVE; } } + + /** + * This cannot be accessed from the menu, but it provides the Ctrl+A + * Select All functionality for Windows (other platforms implement this themselves) + */ + public static class SelectAll implements Listener { + private final ResultTable resultTable; + private final TableSelection tableSelectionListener; + + public SelectAll(ResultTable resultTable, TableSelection tableSelectionListener) { + this.resultTable = resultTable; + this.tableSelectionListener = tableSelectionListener; + } + + public void handleEvent(Event event) { + // Ctrl+A handler + if (event.type == SWT.KeyDown && event.keyCode == 'a' && event.stateMask == SWT.MOD1) { + resultTable.selectAll(); + // update selection status + event.widget = resultTable; + tableSelectionListener.handleEvent(event); + event.doit = false; + } + } + } + + public static final class SelectInvert implements Listener { + private final ResultTable resultTable; + private final TableSelection tableSelectionListener; + + public SelectInvert(ResultTable resultTable, TableSelection tableSelectionListener) { + this.resultTable = resultTable; + this.tableSelectionListener = tableSelectionListener; + } + + public void handleEvent(Event event) { + int count = resultTable.getItemCount(); + // the most naive implementation + resultTable.setRedraw(false); + for (int i = 0; i < count; i++) { + if (resultTable.isSelected(i)) + resultTable.deselect(i); + else + resultTable.select(i); + } + resultTable.setRedraw(true); + resultTable.redraw(); + event.widget = resultTable; + tableSelectionListener.handleEvent(event); + resultTable.forceFocus(); + } + } }