Added preferences for mouse button assignments
[Mograsim.git] / plugins / net.mograsim.logic.model / src / net / mograsim / logic / model / LogicUICanvas.java
index 15346c6..162e002 100644 (file)
@@ -27,8 +27,7 @@ import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.model.model.LogicModel;
 import net.mograsim.logic.model.model.components.ModelComponent;
 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
-import net.mograsim.logic.model.model.components.submodels.SubmodelInterface;
-import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
+import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
 import net.mograsim.preferences.Preferences;
 
 /**
@@ -38,8 +37,6 @@ import net.mograsim.preferences.Preferences;
  */
 public class LogicUICanvas extends ZoomableCanvas
 {
-       private static final boolean OPEN_DEBUG_SETHIGHLEVELSTATE_SHELL = false;
-
        private final LogicModel model;
 
        public LogicUICanvas(Composite parent, int style, LogicModel model)
@@ -60,13 +57,13 @@ public class LogicUICanvas extends ZoomableCanvas
 
                addListener(SWT.MouseDown, this::mouseDown);
 
-               if (OPEN_DEBUG_SETHIGHLEVELSTATE_SHELL)
+               if (Preferences.current().getBoolean("net.mograsim.logic.model.debug.openhlsshell"))
                        openDebugSetHighLevelStateShell(model);
        }
 
        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())
@@ -167,6 +164,7 @@ public class LogicUICanvas extends ZoomableCanvas
                get.addListener(SWT.Selection, getAction);
                stateIDText.addListener(SWT.DefaultSelection, getAction);
                debugShell.open();
+               addDisposeListener(e -> debugShell.dispose());
        }
 
        private void compsChanged(Consumer<? super ModelComponent> compAdded, Consumer<? super ModelComponent> compRemoved, ModelComponent c,
@@ -218,21 +216,24 @@ public class LogicUICanvas extends ZoomableCanvas
                recalculateQueued.set(false);
                componentsByItemIndex.clear();
                componentSelector.setItems();
-               addComponentSelectorItems(componentsByItemIndex, "", componentSelector, model);
+               addComponentSelectorItems(componentsByItemIndex, "", componentSelector, model,
+                               Preferences.current().getInt("net.mograsim.logic.model.debug.hlsshelldepth") - 1);
        }
 
        private void addComponentSelectorItems(List<ModelComponent> componentsByItemIndex, String base, Combo componentSelector,
-                       LogicModel model)
+                       LogicModel model, int depth)
        {
                model.getComponentsByName().values().stream().sorted((c1, c2) -> c1.getName().compareTo(c2.getName())).forEach(c ->
                {
-                       if (!(c instanceof ModelWireCrossPoint || c instanceof SubmodelInterface))
+                       if (!(c.getHighLevelStateHandler() instanceof DefaultHighLevelStateHandler))
                        {
                                String item = base + c.getName();
                                componentsByItemIndex.add(c);
                                componentSelector.add(item);
-                               if (c instanceof SubmodelComponent)
-                                       addComponentSelectorItems(componentsByItemIndex, item + " -> ", componentSelector, ((SubmodelComponent) c).submodel);
+                               // this causes negative numbers to result in infinite depth
+                               if (depth != 0 && c instanceof SubmodelComponent)
+                                       addComponentSelectorItems(componentsByItemIndex, item + " -> ", componentSelector, ((SubmodelComponent) c).submodel,
+                                                       depth - 1);
                        }
                });
        }