From 6afa196302d15c2a7d6492c577a57a91c3cb85a4 Mon Sep 17 00:00:00 2001 From: Fabian Stemmler Date: Sun, 22 Sep 2019 19:32:52 +0200 Subject: [PATCH] Switched Instruction View to project associated MachineContext --- .../plugin/tables/mi/InstructionView.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java index 37aab638..af7e2113 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java @@ -23,7 +23,8 @@ import net.mograsim.machine.mi.MicroInstructionMemory; import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener; import net.mograsim.machine.mi.MicroInstructionMemoryParseException; import net.mograsim.machine.mi.MicroInstructionMemoryParser; -import net.mograsim.plugin.MachineContext; +import net.mograsim.plugin.nature.MachineContext; +import net.mograsim.plugin.nature.ProjectMachineContext; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.LazyTableViewer; import net.mograsim.plugin.tables.RadixSelector; @@ -35,6 +36,7 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis private boolean dirty = false; private MicroInstructionMemory memory; private InstructionTable table; + private MachineContext context; @SuppressWarnings("unused") @Override @@ -76,7 +78,7 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis Button activationButton = new Button(parent, SWT.PUSH); activationButton.setText("Set Active"); activationButton.addListener(SWT.Selection, - e -> MachineContext.getInstance().getMachine().getMicroInstructionMemory().bind(memory)); + e -> context.getActiveMachine().ifPresent(m -> m.getMicroInstructionMemory().bind(memory))); } public void bindMicroInstructionMemory(MicroInstructionMemory memory) @@ -95,11 +97,14 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis { try { - bindMicroInstructionMemory(MicroInstructionMemoryParser.parseMemory( - MachineContext.getInstance().getMachine().getDefinition().getMicroInstructionMemoryDefinition(), file.getContents())); + bindMicroInstructionMemory(MicroInstructionMemoryParser.parseMemory(context.getMachineDefinition() + .orElseThrow(() -> new MicroInstructionMemoryParseException("No MachineDefinition assigned!")) + .getMicroInstructionMemoryDefinition(), file.getContents())); } catch (IOException | MicroInstructionMemoryParseException | CoreException e) { + + // TODO: Proper handling via IProgressMonitor e.printStackTrace(); } } @@ -162,9 +167,11 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis { setSite(site); setInput(input); + if (input instanceof IFileEditorInput) { IFileEditorInput fileInput = (IFileEditorInput) input; + context = ProjectMachineContext.getMachineContextOf(fileInput.getFile()); setPartName(fileInput.getName()); open(fileInput.getFile()); } -- 2.17.1