X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMainMachineLaunchConfigTab.java;h=fbbe2640f249bcea52cb4a05ef9829afbdfc8100;hb=b5d55c59d7069171bd928e4a945d9185ee4bc2b0;hp=3072c8aa48dcae40d02af972139f0407b1de517c;hpb=18a120638da6387fbc895f30c64fb570b8d51cae;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java index 3072c8aa..fbbe2640 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java @@ -37,12 +37,14 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; import net.mograsim.plugin.nature.MograsimNature; import net.mograsim.plugin.util.FileExtensionViewerFilter; import net.mograsim.plugin.util.ImageDescriptorWithMargins; +import net.mograsim.plugin.util.ProjectViewerFilter; //a big part of this class is stolen from org.eclipse.jdt.debug.ui public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { private Text projSelText; private Text mpmFileSelText; + private Text mpromFileSelText; private Text initialRAMFileSelText; @Override @@ -54,10 +56,12 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab innerParent.setLayout(new GridLayout(3, false)); - this.projSelText = addResourceSelector(innerParent, "&Project:", this::chooseMograsimProject); + this.projSelText = addResourceSelector(innerParent, "P&roject:", this::chooseMograsimProject); this.mpmFileSelText = addResourceSelector(innerParent, "&MPM:", this::chooseMPMFile); + this.mpromFileSelText = addResourceSelector(innerParent, "M&PROM:", this::chooseMPROMFile); + this.initialRAMFileSelText = addResourceSelector(innerParent, "Initial &RAM (optional):", this::chooseInitialRAMFile); } @@ -96,12 +100,13 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab private String chooseMograsimProject() { + // TODO this seems very ugly, especially hardcoded width/height WorkbenchLabelProvider renderer = new WorkbenchLabelProvider() { @Override protected ImageDescriptor decorateImage(ImageDescriptor input, Object element) { - return new ImageDescriptorWithMargins(input, new Point(22, 16)); + return new ImageDescriptorWithMargins(input, new Point(20, 16)); } }; ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), renderer); @@ -115,40 +120,28 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab private String chooseMPMFile() { - WorkbenchLabelProvider renderer = new WorkbenchLabelProvider() - { - @Override - protected ImageDescriptor decorateImage(ImageDescriptor input, Object element) - { - return new ImageDescriptorWithMargins(input, new Point(22, 16)); - } - }; - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), renderer, new WorkbenchContentProvider()); - dialog.setTitle("MPM Selection"); - dialog.setMessage("Select a MPM file"); - dialog.setInput(getSelectedProject()); - dialog.addFilter(new FileExtensionViewerFilter("mpm")); + return chooseFile("MPM", "mpm"); + } - if (dialog.open() == Window.OK) - return ((IResource) dialog.getResult()[0]).getProjectRelativePath().toPortableString(); - return null; + private String chooseMPROMFile() + { + return chooseFile("MPROM", "mprom"); } private String chooseInitialRAMFile() { - WorkbenchLabelProvider renderer = new WorkbenchLabelProvider() - { - @Override - protected ImageDescriptor decorateImage(ImageDescriptor input, Object element) - { - return new ImageDescriptorWithMargins(input, new Point(22, 16)); - } - }; - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), renderer, new WorkbenchContentProvider()); - dialog.setTitle("Initial RAM Selection"); - dialog.setMessage("Select a RAM file"); - dialog.setInput(getSelectedProject()); - dialog.addFilter(new FileExtensionViewerFilter("mem")); + return chooseFile("Initial RAM", "mem"); + } + + private String chooseFile(String type, String fileext) + { + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), + new WorkbenchContentProvider()); + dialog.setTitle(type + " Selection"); + dialog.setMessage("Select a ." + fileext + " file"); + dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); + dialog.addFilter(new FileExtensionViewerFilter(fileext)); + dialog.addFilter(new ProjectViewerFilter(getSelectedProject())); if (dialog.open() == Window.OK) return ((IResource) dialog.getResult()[0]).getProjectRelativePath().toPortableString(); @@ -190,6 +183,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { projSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.PROJECT_ATTR, "")); mpmFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.MPM_FILE_ATTR, "")); + mpromFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.MPROM_FILE_ATTR, "")); initialRAMFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.INITIAL_RAM_FILE_ATTR, "")); } @@ -211,6 +205,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { String projName = projSelText.getText().trim(); String mpmFileName = mpmFileSelText.getText().trim(); + String mpromFileName = mpromFileSelText.getText().trim(); String initialRAMFileName = initialRAMFileSelText.getText().trim(); Set associatedResources = new HashSet<>(); @@ -228,6 +223,10 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab if (mpmFile != null && mpmFile.exists() && mpmFile.getType() == IResource.FILE) associatedResources.add(mpmFile); + IResource mpromFile = project.findMember(mpromFileName); + if (mpromFile != null && mpromFile.exists() && mpromFile.getType() == IResource.FILE) + associatedResources.add(mpromFile); + IResource ramFile = project.findMember(initialRAMFileName); if (ramFile != null && ramFile.exists() && ramFile.getType() == IResource.FILE) associatedResources.add(ramFile); @@ -241,6 +240,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab configuration.setMappedResources(associatedResources.toArray(IResource[]::new)); configuration.setAttribute(MachineLaunchConfigType.PROJECT_ATTR, projName); configuration.setAttribute(MachineLaunchConfigType.MPM_FILE_ATTR, mpmFileName); + configuration.setAttribute(MachineLaunchConfigType.MPROM_FILE_ATTR, mpromFileName); configuration.setAttribute(MachineLaunchConfigType.INITIAL_RAM_FILE_ATTR, initialRAMFileName); } @@ -282,6 +282,16 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab if (mpmResource.getType() != IResource.FILE) return setErrorAndReturnFalse("MPM file {0} is not a file", mpmFileName); + String mpromFileName = mpromFileSelText.getText().trim(); + if (mpromFileName.length() > 0) + { + IResource mpromResource = project.findMember(mpromFileName); + if (mpromResource == null || !mpromResource.exists()) + return setErrorAndReturnFalse("MPROM file {0} does not exist", mpromFileName); + if (mpromResource.getType() != IResource.FILE) + return setErrorAndReturnFalse("MPROM file {0} is not a file", mpromFileName); + } + String initialRAMFileName = initialRAMFileSelText.getText().trim(); if (initialRAMFileName.length() > 0) { @@ -304,6 +314,6 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab @Override public String getName() { - return "testlaunchconfigtabname"; + return "Main"; } } \ No newline at end of file