From b1b3d8cc232d51c3a5d505acd2be052eb72300ee Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Thu, 26 Sep 2019 19:15:46 +0200 Subject: [PATCH] Added preferences for mouse button assignments --- .../mograsim/logic/model/editor/EditorUserInput.java | 10 ++-------- .../net/mograsim/logic/model/editor/ui/EditorGUI.java | 5 +++-- .../src/net/mograsim/logic/model/LogicUICanvas.java | 2 +- .../net/mograsim/logic/model/LogicUIStandaloneGUI.java | 5 +++-- .../src/net/mograsim/plugin/MainPreferencePage.java | 10 ++++++++++ .../mograsim/plugin/editors/SimulationViewEditor.java | 5 +++-- .../net/mograsim/preferences/DefaultPreferences.java | 6 ++++++ 7 files changed, 28 insertions(+), 15 deletions(-) diff --git a/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/EditorUserInput.java b/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/EditorUserInput.java index 333efcd1..154a81f4 100644 --- a/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/EditorUserInput.java +++ b/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/EditorUserInput.java @@ -4,6 +4,7 @@ import org.eclipse.swt.SWT; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; import net.mograsim.logic.model.editor.ui.EditorGUI; +import net.mograsim.preferences.Preferences; public class EditorUserInput { @@ -15,15 +16,8 @@ public class EditorUserInput gui.logicCanvas.addListener(SWT.MouseDown, e -> { Point clicked = editor.gui.logicCanvas.canvasToWorldCoords(e.x, e.y); - switch (e.button) - { - case 1: + if (e.button == Preferences.current().getInt("net.mograsim.logic.model.button.action")) editor.handleManager.click(clicked, e.stateMask); - break; - default: - // don't react - } - }); gui.logicCanvas.addMouseMoveListener(e -> diff --git a/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java b/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java index b89d587d..3dfd62e9 100644 --- a/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java +++ b/plugins/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java @@ -21,6 +21,7 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu import net.mograsim.logic.model.editor.Editor; import net.mograsim.logic.model.editor.SaveLoadManager; import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; +import net.mograsim.preferences.Preferences; public class EditorGUI { @@ -73,8 +74,8 @@ public class EditorGUI setupBottomToolBar(innerComp); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(logicCanvas); - userInput.buttonDrag = 3; - userInput.buttonZoom = 2; + userInput.buttonDrag = Preferences.current().getInt("net.mograsim.logic.model.button.drag"); + userInput.buttonZoom = Preferences.current().getInt("net.mograsim.logic.model.button.zoom"); userInput.enableUserInput(); new ZoomableCanvasOverlay(logicCanvas, null).enableScale(); } diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java index dda67538..162e0024 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUICanvas.java @@ -63,7 +63,7 @@ public class LogicUICanvas extends ZoomableCanvas private void mouseDown(Event e) { - if (e.button == 1) + if (e.button == Preferences.current().getInt("net.mograsim.logic.model.button.action")) { Point click = canvasToWorldCoords(e.x, e.y); for (ModelComponent component : model.getComponentsByName().values()) diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUIStandaloneGUI.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUIStandaloneGUI.java index 49182d66..55a96a51 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUIStandaloneGUI.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/LogicUIStandaloneGUI.java @@ -8,6 +8,7 @@ import org.eclipse.swt.widgets.Shell; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; import net.mograsim.logic.model.model.LogicModel; +import net.mograsim.preferences.Preferences; /** * Standalone simulation visualizer graphical user interface. @@ -28,8 +29,8 @@ public class LogicUIStandaloneGUI implements Runnable ui = new LogicUICanvas(shell, SWT.NONE, model); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui); - userInput.buttonDrag = 3; - userInput.buttonZoom = 2; + userInput.buttonDrag = Preferences.current().getInt("net.mograsim.logic.model.button.drag"); + userInput.buttonZoom = Preferences.current().getInt("net.mograsim.logic.model.button.zoom"); userInput.enableUserInput(); new ZoomableCanvasOverlay(ui, null).enableScale(); } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MainPreferencePage.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MainPreferencePage.java index b647a088..7bac9915 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MainPreferencePage.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/MainPreferencePage.java @@ -27,6 +27,16 @@ public class MainPreferencePage extends FieldEditorPreferencePage implements IWo addField(new BooleanFieldEditor("net.mograsim.logic.model.debug.openhlsshell", "Open the debug HLS shell", parent)); addField(new IntegerFieldEditor("net.mograsim.logic.model.debug.hlsshelldepth", "Depth of components to list in the debug HLS shell", parent)); + IntegerFieldEditor editor; + editor = new IntegerFieldEditor("net.mograsim.logic.model.button.action", "Mouse button for actions", parent); + editor.setValidRange(1, 5); + addField(editor); + editor = new IntegerFieldEditor("net.mograsim.logic.model.button.drag", "Mouse button for dragging", parent); + editor.setValidRange(1, 5); + addField(editor); + editor = new IntegerFieldEditor("net.mograsim.logic.model.button.zoom", "Mouse button for zooming", parent); + editor.setValidRange(1, 5); + addField(editor); // TODO add other preferences } } \ No newline at end of file diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java index 02fc2d98..3000d65a 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java @@ -38,6 +38,7 @@ import net.mograsim.plugin.nature.ProjectMachineContext; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.mi.ActiveInstructionPreviewContentProvider; import net.mograsim.plugin.tables.mi.InstructionTable; +import net.mograsim.preferences.Preferences; //TODO what if we open multiple editors? //TODO actually save / load register and latch states @@ -135,8 +136,8 @@ public class SimulationViewEditor extends EditorPart machine = machineOptional.get(); canvas = new LogicUICanvas(canvasParent, SWT.NONE, machine.getModel()); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(canvas); - userInput.buttonDrag = 3; - userInput.buttonZoom = 2; + userInput.buttonDrag = Preferences.current().getInt("net.mograsim.logic.model.button.drag"); + userInput.buttonZoom = Preferences.current().getInt("net.mograsim.logic.model.button.zoom"); userInput.enableUserInput(); if (zoom > 0) { diff --git a/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java index 9b867ce0..da01459a 100644 --- a/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java +++ b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/DefaultPreferences.java @@ -25,6 +25,12 @@ public class DefaultPreferences extends Preferences { case "net.mograsim.logic.model.debug.hlsshelldepth": return 0; + case "net.mograsim.logic.model.button.action": + return 1; + case "net.mograsim.logic.model.button.drag": + return 3; + case "net.mograsim.logic.model.button.zoom": + return 2; default: throw new IllegalArgumentException("Unknown int preference name: " + name); } -- 2.17.1