X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Ftables%2Fmi%2FInstructionView.java;h=0df15cdadff57fc825b32bc199766cdcc8c0f3b3;hb=cb96c0334c0b477ec692ec8d11dd65c1bbbf72a6;hp=b50dc84fab0e20256dced9190349220b4852e28c;hpb=38902818500a67f6a55973b9acbd4194f7a82838;p=Mograsim.git 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 b50dc84f..0df15cda 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 @@ -66,7 +68,8 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis viewer.highlightRow(highlighted, false); highlighted = index; viewer.highlightRow(index, true); - viewer.getTable().setTopIndex(index); + viewer.getTable().showItem(viewer.getTable().getItem(Math.min((int) memory.getDefinition().getMaximalAddress(), index + 2))); + viewer.getTable().showItem(viewer.getTable().getItem(index)); }); } @@ -75,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) @@ -94,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(); } } @@ -161,9 +167,12 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis { setSite(site); setInput(input); + if (input instanceof IFileEditorInput) { IFileEditorInput fileInput = (IFileEditorInput) input; + context = ProjectMachineContext.getMachineContextOf(fileInput.getFile().getProject()); + setPartName(fileInput.getName()); open(fileInput.getFile()); }