Initial commit after migrating repo and assuring the product launches
This commit is contained in:
64
src/edu/fichte/pbi/ide/Activator.java
Normal file
64
src/edu/fichte/pbi/ide/Activator.java
Normal file
@ -0,0 +1,64 @@
|
||||
package edu.fichte.pbi.ide;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class Activator extends AbstractUIPlugin {
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "edu.fichte.pbi.ide"; //$NON-NLS-1$
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public Activator() {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||
}
|
||||
}
|
50
src/edu/fichte/pbi/ide/Application.java
Normal file
50
src/edu/fichte/pbi/ide/Application.java
Normal file
@ -0,0 +1,50 @@
|
||||
package edu.fichte.pbi.ide;
|
||||
|
||||
import org.eclipse.equinox.app.IApplication;
|
||||
import org.eclipse.equinox.app.IApplicationContext;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
|
||||
/**
|
||||
* This class controls all aspects of the application's execution
|
||||
*/
|
||||
public class Application implements IApplication {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
|
||||
*/
|
||||
@Override
|
||||
public Object start(IApplicationContext context) throws Exception {
|
||||
Display display = PlatformUI.createDisplay();
|
||||
try {
|
||||
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
|
||||
if (returnCode == PlatformUI.RETURN_RESTART)
|
||||
return IApplication.EXIT_RESTART;
|
||||
else
|
||||
return IApplication.EXIT_OK;
|
||||
} finally {
|
||||
display.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.equinox.app.IApplication#stop()
|
||||
*/
|
||||
@Override
|
||||
public void stop() {
|
||||
if (!PlatformUI.isWorkbenchRunning())
|
||||
return;
|
||||
final IWorkbench workbench = PlatformUI.getWorkbench();
|
||||
final Display display = workbench.getDisplay();
|
||||
display.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!display.isDisposed())
|
||||
workbench.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
85
src/edu/fichte/pbi/ide/ApplicationActionBarAdvisor.java
Normal file
85
src/edu/fichte/pbi/ide/ApplicationActionBarAdvisor.java
Normal file
@ -0,0 +1,85 @@
|
||||
package edu.fichte.pbi.ide;
|
||||
|
||||
import org.eclipse.jface.action.GroupMarker;
|
||||
import org.eclipse.jface.action.ICoolBarManager;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IStatusLineManager;
|
||||
import org.eclipse.jface.action.StatusLineContributionItem;
|
||||
import org.eclipse.jface.action.ToolBarManager;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.actions.ActionFactory;
|
||||
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
|
||||
import org.eclipse.ui.application.ActionBarAdvisor;
|
||||
import org.eclipse.ui.application.IActionBarConfigurer;
|
||||
|
||||
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
|
||||
|
||||
public static final String MY_COLROW_TELLER = Activator.PLUGIN_ID
|
||||
+ ".colrowteller";
|
||||
private IWorkbenchAction save;
|
||||
private IWorkbenchAction saveAll;
|
||||
private IWorkbenchAction saveAs;
|
||||
|
||||
// IWorkbenchAction newFile;
|
||||
|
||||
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
|
||||
super(configurer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void makeActions(IWorkbenchWindow window) {
|
||||
save = ActionFactory.SAVE.create(window);
|
||||
saveAll = ActionFactory.SAVE_ALL.create(window);
|
||||
saveAs = ActionFactory.SAVE_AS.create(window);
|
||||
// newFile = ActionFactory.NEW.create(window);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillCoolBar(ICoolBarManager coolBar) {
|
||||
ToolBarManager toolBarManager = new ToolBarManager();
|
||||
toolBarManager.add(save);
|
||||
toolBarManager.add(saveAs);
|
||||
toolBarManager.add(saveAll);
|
||||
// toolBarManager.add(newFile);
|
||||
// for (IWizardDescriptor e : getAllWizards(WorkbenchPlugin.getDefault()
|
||||
// .getNewWizardRegistry().getRootCategory().getCategories())) {
|
||||
// System.out.println(e.toString());
|
||||
//
|
||||
// }
|
||||
// AbstractExtensionWizardRegistry wizardRegistry =
|
||||
// (AbstractExtensionWizardRegistry)WorkbenchPlugin.getDefault().getNewWizardRegistry();
|
||||
//
|
||||
// IWizardCategory[] categories =
|
||||
// WorkbenchPlugin.getDefault().getNewWizardRegistry().getRootCategory().getCategories();
|
||||
//
|
||||
// for(IWizardDescriptor wizard : getAllWizards(categories)){
|
||||
// WorkbenchWizardElement wizardElement = (WorkbenchWizardElement)
|
||||
// wizard;
|
||||
// wizardRegistry.removeExtension(wizardElement.getConfigurationElement().getDeclaringExtension(),
|
||||
// new Object[]{wizardElement});
|
||||
// }
|
||||
coolBar.add(new GroupMarker("edu.fichte.pbi.ide.toolbar"));
|
||||
coolBar.add(toolBarManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillMenuBar(IMenuManager menuBar) {
|
||||
}
|
||||
|
||||
// private IWizardDescriptor[] getAllWizards(IWizardCategory[] categories) {
|
||||
// List<IWizardDescriptor> results = new ArrayList<IWizardDescriptor>();
|
||||
// for (IWizardCategory wizardCategory : categories) {
|
||||
// results.addAll(Arrays.asList(wizardCategory.getWizards()));
|
||||
// results.addAll(Arrays.asList(getAllWizards(wizardCategory
|
||||
// .getCategories())));
|
||||
// }
|
||||
// return results.toArray(new IWizardDescriptor[0]);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void fillStatusLine(IStatusLineManager statusLine) {
|
||||
statusLine.add(new StatusLineContributionItem(MY_COLROW_TELLER, 10));
|
||||
super.fillStatusLine(statusLine);
|
||||
}
|
||||
|
||||
}
|
21
src/edu/fichte/pbi/ide/ApplicationWorkbenchAdvisor.java
Normal file
21
src/edu/fichte/pbi/ide/ApplicationWorkbenchAdvisor.java
Normal file
@ -0,0 +1,21 @@
|
||||
package edu.fichte.pbi.ide;
|
||||
|
||||
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
|
||||
import org.eclipse.ui.application.WorkbenchAdvisor;
|
||||
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
|
||||
|
||||
|
||||
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
|
||||
|
||||
private static final String PERSPECTIVE_ID = "edu.fichte.pbi.ide.perspective"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
|
||||
return new ApplicationWorkbenchWindowAdvisor(configurer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitialWindowPerspectiveId() {
|
||||
return PERSPECTIVE_ID;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package edu.fichte.pbi.ide;
|
||||
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.application.ActionBarAdvisor;
|
||||
import org.eclipse.ui.application.IActionBarConfigurer;
|
||||
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
|
||||
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
|
||||
import org.eclipse.ui.internal.WorkbenchWindow;
|
||||
|
||||
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
|
||||
private final IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
|
||||
|
||||
public ApplicationWorkbenchWindowAdvisor(
|
||||
IWorkbenchWindowConfigurer configurer) {
|
||||
super(configurer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionBarAdvisor createActionBarAdvisor(
|
||||
IActionBarConfigurer configurer) {
|
||||
return new ApplicationActionBarAdvisor(configurer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preWindowOpen() {
|
||||
Rectangle clientArea = Display.getCurrent().getClientArea();
|
||||
configurer
|
||||
.setInitialSize(new Point(clientArea.width, clientArea.height));
|
||||
configurer.setShowCoolBar(false);
|
||||
configurer.setShowStatusLine(true);
|
||||
configurer.setTitle("PBasic IDE and Interpreter");
|
||||
configurer.setShowPerspectiveBar(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postWindowOpen() {
|
||||
hideQuickAccess();
|
||||
}
|
||||
|
||||
|
||||
private void hideQuickAccess() {
|
||||
IWorkbenchWindow window = PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow();
|
||||
setQuickAccessVisible(window, false);
|
||||
|
||||
// final IHandlerService service = (IHandlerService)
|
||||
// window.getService(IHandlerService.class);
|
||||
// quickAccessHandlerActivation =
|
||||
// service.activateHandler(QUICK_ACCESS_COMMAND_ID, new
|
||||
// CustomQuickAccessHandler());
|
||||
}
|
||||
|
||||
private void setQuickAccessVisible(IWorkbenchWindow window, boolean visible) {
|
||||
if (window instanceof WorkbenchWindow) {
|
||||
MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
|
||||
|
||||
for (MTrimElement element : topTrim.getChildren()) {
|
||||
// System.out.println(element.getElementId());
|
||||
if ("SearchField".equals(element.getElementId())) {
|
||||
element.setVisible(false);
|
||||
}
|
||||
// if (QUICK_ACCESS_ELEMENT_ID.equals(element.getElementId())) {
|
||||
// element.setVisible(visible);
|
||||
// if (visible) {
|
||||
// Composite control = (Composite) element.getWidget();
|
||||
// control.getChildren()[0].addFocusListener(new
|
||||
// QuickAccessFocusListener());
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
public IWorkbenchWindowConfigurer getConfigurer(){
|
||||
return configurer;
|
||||
}
|
||||
|
||||
}
|
32
src/edu/fichte/pbi/ide/Perspective.java
Normal file
32
src/edu/fichte/pbi/ide/Perspective.java
Normal file
@ -0,0 +1,32 @@
|
||||
package edu.fichte.pbi.ide;
|
||||
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.IPerspectiveFactory;
|
||||
|
||||
import edu.fichte.pbi.ide.views.ConsoleView;
|
||||
import edu.fichte.pbi.ide.views.DebugView;
|
||||
import edu.fichte.pbi.ide.views.EEPROMView;
|
||||
import edu.fichte.pbi.ide.views.FileExplorer;
|
||||
import edu.fichte.pbi.ide.views.HelpView;
|
||||
import edu.fichte.pbi.ide.views.VariableView;
|
||||
|
||||
public class Perspective implements IPerspectiveFactory {
|
||||
|
||||
@Override
|
||||
public void createInitialLayout(IPageLayout layout) {
|
||||
String editorAreaId = layout.getEditorArea();
|
||||
layout.setEditorAreaVisible(false);
|
||||
layout.addPlaceholder(FileExplorer.ID, IPageLayout.LEFT, 0.17f, editorAreaId);
|
||||
layout.addView(HelpView.ID, IPageLayout.RIGHT, 0.7f, editorAreaId);
|
||||
layout.setFixed(true);
|
||||
layout.addPlaceholder(ConsoleView.ID, IPageLayout.BOTTOM, 0.54f,
|
||||
editorAreaId);
|
||||
layout.addPlaceholder(VariableView.ID, IPageLayout.RIGHT, 0.7f,
|
||||
ConsoleView.ID);
|
||||
layout.addPlaceholder(DebugView.ID, IPageLayout.RIGHT, 0.4f,
|
||||
VariableView.ID);
|
||||
layout.addPlaceholder(EEPROMView.ID, IPageLayout.RIGHT, 0.63f,
|
||||
editorAreaId);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.ide.editors.ConfigEditor;
|
||||
import edu.fichte.pbi.ide.editors.FileSystemFileEditorInput;
|
||||
import edu.fichte.pbi.ide.views.HelpView;
|
||||
|
||||
public class CASettingsCommandHandler implements IHandler,IHandler2{
|
||||
protected String filename = "ca.cfg";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/" + filename);
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
|
||||
if (!file.canRead()) {
|
||||
// must copy the html from the bundle .jar to the data file location
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
if (file.isFile()) {
|
||||
FileSystemFileEditorInput fileSystemFileEditorInput = new FileSystemFileEditorInput(
|
||||
file);
|
||||
try {
|
||||
window.getActivePage().openEditor(fileSystemFileEditorInput,
|
||||
ConfigEditor.ID);
|
||||
} catch (PartInitException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("something went wrong");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
}
|
88
src/edu/fichte/pbi/ide/commands/CommentCommandHandler.java
Normal file
88
src/edu/fichte/pbi/ide/commands/CommentCommandHandler.java
Normal file
@ -0,0 +1,88 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
|
||||
public class CommentCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
|
||||
if (activeEditor instanceof PBIEditor) {
|
||||
PBIEditor pbi = (PBIEditor) activeEditor;
|
||||
StyledText text = pbi.getText();
|
||||
Point selectionRange = text.getSelection();
|
||||
int from = selectionRange.x;
|
||||
int to = selectionRange.y;
|
||||
String selection = text.getText().substring(from, to);
|
||||
Scanner scanner = new Scanner(selection);
|
||||
// List<String> lines = new LinkedList<>();
|
||||
// boolean uncomment = true;
|
||||
String replacement = "";
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
String actual = scanner.nextLine();
|
||||
replacement += (actual.startsWith("'") ? "" : "'") + actual
|
||||
+ (scanner.hasNextLine() ? "\n" : "");
|
||||
// uncomment &= s.startsWith("'");
|
||||
// lines.add(s);
|
||||
}
|
||||
// for (String actual : lines) {
|
||||
// replacement += (uncomment ? actual.substring(1) : "'" + actual)
|
||||
// + "\n";
|
||||
// }
|
||||
text.setText(text.getText().replaceAll(selection, replacement));
|
||||
scanner.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() instanceof PBIEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
170
src/edu/fichte/pbi/ide/commands/ContentAssistCommandHandler.java
Normal file
170
src/edu/fichte/pbi/ide/commands/ContentAssistCommandHandler.java
Normal file
@ -0,0 +1,170 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.ide.editors.ConfigEditor;
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
import edu.fichte.pbi.ide.views.ConsoleView;
|
||||
import edu.fichte.pbi.ide.views.HelpView;
|
||||
|
||||
public class ContentAssistCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
private static Map<String, String> commands = null;
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
|
||||
if (activeEditor instanceof PBIEditor) {
|
||||
PBIEditor pbi = (PBIEditor) activeEditor;
|
||||
StyledText editor = pbi.getText();
|
||||
Point selectionRange = editor.getSelection();
|
||||
String text = editor.getText();
|
||||
int from;
|
||||
int to = selectionRange.y;
|
||||
for (from = to - 1; from > 0; from--) {
|
||||
if (text.charAt(from) == ' ')
|
||||
return null;
|
||||
if (text.charAt(from) == '\n')
|
||||
break;
|
||||
}
|
||||
try {
|
||||
String content = text.substring(from, to).trim();
|
||||
content = content.toUpperCase();
|
||||
execute: {
|
||||
boolean defined = false;
|
||||
String result = null;
|
||||
if (commands == null || ConfigEditor.hasChanged) {
|
||||
initCommands(event);
|
||||
}
|
||||
for (String cmd : commands.keySet()) {
|
||||
cmd = cmd.toUpperCase();
|
||||
if (cmd.startsWith(content) && !defined) {
|
||||
defined = true;
|
||||
result = cmd;
|
||||
} else if (cmd.startsWith(content) && defined) {
|
||||
break execute;
|
||||
}
|
||||
}
|
||||
String replacement = commands.get(result);
|
||||
if (replacement != null) {
|
||||
String left = text.substring(0, from + 1);
|
||||
String right = text.substring(from + content.length()
|
||||
+ 1);
|
||||
String newText = left + replacement + right;
|
||||
editor.setText(newText);
|
||||
to = from + replacement.length() + 1;
|
||||
editor.setSelection(new Point(to, to));
|
||||
}
|
||||
}
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void initCommands(ExecutionEvent event) {
|
||||
commands = new HashMap<>();
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/ca.cfg");
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
|
||||
if (!file.canRead()) {
|
||||
// must copy the html from the bundle .jar to the data file location
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
|
||||
Scanner scanner = null;
|
||||
try {
|
||||
scanner = new Scanner(file);
|
||||
String line;
|
||||
while (scanner.hasNextLine()) {
|
||||
line = scanner.nextLine().trim();
|
||||
if (line.startsWith("##") || line.isEmpty()) {
|
||||
continue;
|
||||
} else if (line.contains("->")) {
|
||||
String[] split = line.split("->");
|
||||
if (split.length != 2) {
|
||||
scanner.close();
|
||||
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
commands.put(split[0].trim(),
|
||||
split[1].trim().replace("/CR", "\n"));
|
||||
} else {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
} catch (FileNotFoundException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
((ConsoleView) window.getActivePage().showView(ConsoleView.ID))
|
||||
.print("[Error, content assist]Couldn't read the configuration file\n");
|
||||
} catch (PartInitException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() instanceof PBIEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
108
src/edu/fichte/pbi/ide/commands/DebugSchemeCommandHandler.java
Normal file
108
src/edu/fichte/pbi/ide/commands/DebugSchemeCommandHandler.java
Normal file
@ -0,0 +1,108 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.ide.views.ConsoleView;
|
||||
import edu.fichte.pbi.ide.views.HelpView;
|
||||
|
||||
public class DebugSchemeCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
|
||||
try {
|
||||
final ConsoleView console = (ConsoleView) window.getActivePage()
|
||||
.showView(ConsoleView.ID);
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/color.cfg");
|
||||
if (!file.canRead()) {
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
String s = "";
|
||||
Scanner scanner = new Scanner(file);
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("##") || line.isEmpty())
|
||||
continue;
|
||||
if (line.contains("console scheme")) {
|
||||
String[] split = line.split("=");
|
||||
if (split.length != 2) {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
split[1] = split[1].trim().equals("blue") ? " white"
|
||||
: split[1].trim().equals("white") ? " black"
|
||||
: split[1].trim().equals("black") ? "blue"
|
||||
: null;
|
||||
split[1] = split[1] == null ? "blue" : split[1];
|
||||
line = split[0] + "=" + split[1];
|
||||
}
|
||||
s += line + "\n";
|
||||
}
|
||||
scanner.close();
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(s.getBytes());
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
console.setScheme();
|
||||
} catch (PartInitException e) {
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
}
|
93
src/edu/fichte/pbi/ide/commands/ExportCommandHandler.java
Normal file
93
src/edu/fichte/pbi/ide/commands/ExportCommandHandler.java
Normal file
@ -0,0 +1,93 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
import edu.fichte.pbi.ide.views.ConsoleView;
|
||||
|
||||
public class ExportCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
java.util.List<Integer> deprecated = new LinkedList<Integer>();
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
if (activeEditor instanceof PBIEditor) {
|
||||
PBIEditor pbi = (PBIEditor) activeEditor;
|
||||
Scanner scanner = new Scanner(pbi.text.getText());
|
||||
String result = "";
|
||||
int curLineNr = 1;
|
||||
while (scanner.hasNextLine()) {
|
||||
String curLine = scanner.nextLine();
|
||||
if (curLine.contains("EEPROM") && curLine.contains("DEBUG")
|
||||
|| curLine.contains("BREAKPOINT")
|
||||
|| curLine.contains("ASSERT")
|
||||
|| curLine.contains("ACTIVATEINFO")
|
||||
|| curLine.contains("DEACTIVATEINFO")) {
|
||||
curLine = "'" + curLine.trim();
|
||||
} else if (curLine.contains("NEW")
|
||||
|| curLine.contains("SYSCLOCK")) {
|
||||
deprecated.add(curLineNr);
|
||||
}
|
||||
result += curLine + "\n";
|
||||
curLineNr++;
|
||||
}
|
||||
scanner.close();
|
||||
pbi.text.setText(result);
|
||||
IWorkbenchWindow window = HandlerUtil
|
||||
.getActiveWorkbenchWindow(event);
|
||||
try {
|
||||
final ConsoleView console = (ConsoleView) window
|
||||
.getActivePage().showView(ConsoleView.ID);
|
||||
for (Integer lineNr : deprecated) {
|
||||
console.print("[Warn, line " + lineNr + "]You have to remove the referenced object and all it's assignments to export");
|
||||
}
|
||||
} catch (PartInitException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() instanceof PBIEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
|
||||
}
|
60
src/edu/fichte/pbi/ide/commands/HelpCommandHandler.java
Normal file
60
src/edu/fichte/pbi/ide/commands/HelpCommandHandler.java
Normal file
@ -0,0 +1,60 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.views.HelpView;
|
||||
|
||||
public class HelpCommandHandler implements IHandler, IHandler2{
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IWorkbenchWindow window = HandlerUtil
|
||||
.getActiveWorkbenchWindow(event);
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
final HelpView help = (HelpView) window
|
||||
.getActivePage().showView(HelpView.ID);
|
||||
} catch (PartInitException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
|
||||
}
|
98
src/edu/fichte/pbi/ide/commands/IntentCommandHandler.java
Normal file
98
src/edu/fichte/pbi/ide/commands/IntentCommandHandler.java
Normal file
@ -0,0 +1,98 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
|
||||
public class IntentCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
if (activeEditor instanceof PBIEditor) {
|
||||
PBIEditor pbi = (PBIEditor) activeEditor;
|
||||
String intent = autoIntent(pbi.text.getText()); // TODO Zugriff
|
||||
// sch<63>ner machen
|
||||
pbi.text.setText(intent);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() instanceof PBIEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private static String autoIntent(String text) {
|
||||
String retVal = "";
|
||||
Scanner scanner = new Scanner(text);
|
||||
int intent = 0;
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine().trim();
|
||||
String space = "";
|
||||
if (!line.startsWith("'")) {
|
||||
intentation: {
|
||||
int endLineComment = line.lastIndexOf("'");
|
||||
if (line.substring(
|
||||
0,
|
||||
endLineComment == -1 ? line.length()
|
||||
: endLineComment).trim().endsWith(":"))
|
||||
break intentation;
|
||||
for (int i = 0; i < intent; i++)
|
||||
space += " ";
|
||||
if (line.startsWith("FOR"))
|
||||
intent += 2;
|
||||
else if (line.startsWith("NEXT"))
|
||||
intent -= 2;
|
||||
if (intent < 0)
|
||||
intent = 0;
|
||||
}
|
||||
}
|
||||
retVal += space + line + "\n";
|
||||
}
|
||||
scanner.close();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
113
src/edu/fichte/pbi/ide/commands/MonitoredRunCommandHandler.java
Normal file
113
src/edu/fichte/pbi/ide/commands/MonitoredRunCommandHandler.java
Normal file
@ -0,0 +1,113 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.HandlerEvent;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
import edu.fichte.pbi.ide.views.ConsoleView;
|
||||
import edu.fichte.pbi.ide.views.DebugView;
|
||||
import edu.fichte.pbi.ide.views.EEPROMView;
|
||||
import edu.fichte.pbi.ide.views.IRunStateListener;
|
||||
import edu.fichte.pbi.ide.views.VariableView;
|
||||
|
||||
public class MonitoredRunCommandHandler implements IHandler, IHandler2 {
|
||||
private List<IHandlerListener> listeners = new ArrayList<IHandlerListener>();
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
this.listeners.add(handlerListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private void fireEnabledStateChanged() {
|
||||
for (IHandlerListener iHandlerListener : listeners) {
|
||||
iHandlerListener.handlerChanged(new HandlerEvent(this, true, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
if (activeEditor instanceof PBIEditor) {
|
||||
PBIEditor pbi = (PBIEditor) activeEditor;
|
||||
final File file = pbi.getFile();
|
||||
IWorkbenchWindow window = HandlerUtil
|
||||
.getActiveWorkbenchWindow(event);
|
||||
final Display display = window.getShell().getDisplay();
|
||||
|
||||
try {
|
||||
// IViewPart view = window.getActivePage().findView(HelpView.ID);
|
||||
// if (view != null) {
|
||||
// window.getActivePage().hideView(view);
|
||||
// }
|
||||
final VariableView varView = (VariableView) window
|
||||
.getActivePage().showView(VariableView.ID);
|
||||
final ConsoleView console = (ConsoleView) window
|
||||
.getActivePage().showView(ConsoleView.ID);
|
||||
final EEPROMView eeprom = (EEPROMView) window.getActivePage()
|
||||
.showView(EEPROMView.ID);
|
||||
final DebugView debugView = (DebugView) window
|
||||
.getActivePage().showView(DebugView.ID);
|
||||
console.run(file, eeprom, debugView, varView,
|
||||
new IRunStateListener() {
|
||||
@Override
|
||||
public void runStateChanged(boolean isRunning) {
|
||||
RunCommandHandler.somethingIsRunning = isRunning;
|
||||
display.asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
fireEnabledStateChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (PartInitException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return RunCommandHandler.enabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
86
src/edu/fichte/pbi/ide/commands/NewFileCommandHandler.java
Normal file
86
src/edu/fichte/pbi/ide/commands/NewFileCommandHandler.java
Normal file
@ -0,0 +1,86 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.FileSystemFileEditorInput;
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
|
||||
public class NewFileCommandHandler implements IHandler {
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
|
||||
FileDialog fileDialog = new FileDialog(window.getShell(), SWT.SAVE);
|
||||
fileDialog.setFileName("new.bs1");
|
||||
fileDialog.setFilterExtensions(new String[] { "*.bs1" });
|
||||
// fileDialog.setFileName(fileInput.getName());
|
||||
// fileDialog.setFilterPath(fileInput.getFile().getParent());
|
||||
String newFile = fileDialog.open();
|
||||
File file = new File(newFile);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
FileSystemFileEditorInput fileSystemFileEditorInput = new FileSystemFileEditorInput(
|
||||
file);
|
||||
try {
|
||||
PBIEditor editor = (PBIEditor) window.getActivePage().openEditor(fileSystemFileEditorInput,
|
||||
PBIEditor.ID);
|
||||
if(editor.text.getText().isEmpty()){
|
||||
editor.text.setText("' {$STAMP BS1}");
|
||||
}
|
||||
} catch (PartInitException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// setInput(fileSystemFileEditorInput);
|
||||
// doSave(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
66
src/edu/fichte/pbi/ide/commands/OpenCommandHandler.java
Normal file
66
src/edu/fichte/pbi/ide/commands/OpenCommandHandler.java
Normal file
@ -0,0 +1,66 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.views.FileExplorer;
|
||||
|
||||
public class OpenCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
final FileExplorer fe = (FileExplorer) window.getActivePage()
|
||||
.showView(FileExplorer.ID);
|
||||
} catch (PartInitException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
111
src/edu/fichte/pbi/ide/commands/RunCommandHandler.java
Normal file
111
src/edu/fichte/pbi/ide/commands/RunCommandHandler.java
Normal file
@ -0,0 +1,111 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.HandlerEvent;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
import edu.fichte.pbi.ide.views.ConsoleView;
|
||||
import edu.fichte.pbi.ide.views.DebugView;
|
||||
import edu.fichte.pbi.ide.views.IRunStateListener;
|
||||
|
||||
public class RunCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
private List<IHandlerListener> listeners = new ArrayList<IHandlerListener>();
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
this.listeners.add(handlerListener);
|
||||
}
|
||||
|
||||
private void fireEnabledStateChanged(){
|
||||
for (IHandlerListener IHandlerListener : listeners) {
|
||||
IHandlerListener.handlerChanged(new HandlerEvent(this, true, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public static boolean somethingIsRunning = false;
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
if(somethingIsRunning) return null;
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
if (activeEditor instanceof PBIEditor) {
|
||||
PBIEditor pbi = (PBIEditor) activeEditor;
|
||||
final File file = pbi.getFile();
|
||||
IWorkbenchWindow window = HandlerUtil
|
||||
.getActiveWorkbenchWindow(event);
|
||||
final Display display = window.getShell().getDisplay();
|
||||
try {
|
||||
final ConsoleView console = (ConsoleView) window
|
||||
.getActivePage().showView(ConsoleView.ID);
|
||||
final DebugView debugView = (DebugView) window
|
||||
.getActivePage().showView(DebugView.ID);
|
||||
console.run(file,null,debugView,null, new IRunStateListener(){
|
||||
@Override
|
||||
public void runStateChanged(boolean isRunning) {
|
||||
// TODO das enabling unenabling funktioniert nicht richtig
|
||||
somethingIsRunning = isRunning;
|
||||
display.asyncExec(new Runnable(){
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
fireEnabledStateChanged();
|
||||
}});
|
||||
}
|
||||
});
|
||||
} catch (PartInitException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled();
|
||||
}
|
||||
|
||||
public static boolean enabled(){
|
||||
return (PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() instanceof PBIEditor) && !somethingIsRunning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
listeners.remove(handlerListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
|
||||
}
|
||||
|
||||
}
|
85
src/edu/fichte/pbi/ide/commands/SettingsCommandHandler.java
Normal file
85
src/edu/fichte/pbi/ide/commands/SettingsCommandHandler.java
Normal file
@ -0,0 +1,85 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.ide.editors.ConfigEditor;
|
||||
import edu.fichte.pbi.ide.editors.FileSystemFileEditorInput;
|
||||
import edu.fichte.pbi.ide.views.HelpView;
|
||||
|
||||
public class SettingsCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
protected String filename;;
|
||||
|
||||
public SettingsCommandHandler() {
|
||||
filename = "set.cfg";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/" + filename);
|
||||
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
|
||||
if (!file.canRead()) {
|
||||
// must copy the html from the bundle .jar to the data file location
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
if (file.isFile()) {
|
||||
FileSystemFileEditorInput fileSystemFileEditorInput = new FileSystemFileEditorInput(
|
||||
file);
|
||||
try {
|
||||
window.getActivePage().openEditor(fileSystemFileEditorInput,
|
||||
ConfigEditor.ID);
|
||||
} catch (PartInitException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("something went wrong");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
|
||||
}
|
||||
|
||||
}
|
86
src/edu/fichte/pbi/ide/commands/UncommentCommandHandler.java
Normal file
86
src/edu/fichte/pbi/ide/commands/UncommentCommandHandler.java
Normal file
@ -0,0 +1,86 @@
|
||||
package edu.fichte.pbi.ide.commands;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.commands.IHandler2;
|
||||
import org.eclipse.core.commands.IHandlerListener;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
|
||||
public class UncommentCommandHandler implements IHandler, IHandler2 {
|
||||
|
||||
@Override
|
||||
public void addHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
|
||||
if (activeEditor instanceof PBIEditor) {
|
||||
PBIEditor pbi = (PBIEditor) activeEditor;
|
||||
StyledText text = pbi.getText();
|
||||
Point selectionRange = text.getSelection();
|
||||
int from = selectionRange.x;
|
||||
int to = selectionRange.y;
|
||||
String selection = text.getText().substring(from, to);
|
||||
Scanner scanner = new Scanner(selection);
|
||||
// List<String> lines = new LinkedList<>();
|
||||
// boolean uncomment = true;
|
||||
String replacement = "";
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
String actual = scanner.nextLine();
|
||||
replacement += (actual.startsWith("'") ? actual.substring(1) : actual) + (scanner.hasNextLine() ? "\n" : "");
|
||||
// uncomment &= s.startsWith("'");
|
||||
// lines.add(s);
|
||||
}
|
||||
// for (String actual : lines) {
|
||||
// replacement += (uncomment ? actual.substring(1) : "'" + actual)
|
||||
// + "\n";
|
||||
// }
|
||||
text.setText(text.getText().replaceAll(selection, replacement));
|
||||
scanner.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() instanceof PBIEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHandled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHandlerListener(IHandlerListener handlerListener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
23
src/edu/fichte/pbi/ide/commonsstolen/FileUtils.java
Normal file
23
src/edu/fichte/pbi/ide/commonsstolen/FileUtils.java
Normal file
@ -0,0 +1,23 @@
|
||||
package edu.fichte.pbi.ide.commonsstolen;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static String readFileToString(File file) throws IOException {
|
||||
char[] buf = new char[10000];
|
||||
int c = 0;
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
while(-1!=(c=reader.read(buf))){
|
||||
stringWriter.write(buf,0,c);
|
||||
}
|
||||
reader.close();
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
}
|
134
src/edu/fichte/pbi/ide/editors/ConfigEditor.java
Normal file
134
src/edu/fichte/pbi/ide/editors/ConfigEditor.java
Normal file
@ -0,0 +1,134 @@
|
||||
package edu.fichte.pbi.ide.editors;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorSite;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.part.EditorPart;
|
||||
|
||||
import edu.fichte.pbi.ide.commonsstolen.FileUtils;
|
||||
|
||||
public class ConfigEditor extends EditorPart {
|
||||
|
||||
public static final String ID = "edu.fichte.pbi.ide.cfgeditor";
|
||||
public Text text;
|
||||
private IEditorInput input;
|
||||
private boolean dirty = false;
|
||||
private FileSystemFileEditorInput fileInput;
|
||||
public static boolean hasChanged = false;
|
||||
|
||||
@Override
|
||||
public void doSave(IProgressMonitor monitor) {
|
||||
String content = text.getText();
|
||||
File file = fileInput.getFile();
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(content.getBytes());
|
||||
out.close();
|
||||
beClean();
|
||||
hasChanged = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isSaveOnCloseNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IEditorSite site, IEditorInput input)
|
||||
throws PartInitException {
|
||||
this.input = input;
|
||||
setSite(site);
|
||||
setInput(input);
|
||||
setTitle(input.getName());
|
||||
}
|
||||
|
||||
private void beDirty() {
|
||||
dirty = true;
|
||||
firePropertyChange(PROP_DIRTY);
|
||||
}
|
||||
|
||||
private void beClean() {
|
||||
dirty = false;
|
||||
firePropertyChange(PROP_DIRTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty() {
|
||||
return dirty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaveAsAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setInput(IEditorInput input) {
|
||||
super.setInput(input);
|
||||
this.input = input;
|
||||
this.fileInput = (FileSystemFileEditorInput) input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
parent = new Composite(parent, 0);
|
||||
parent.setLayout(new FillLayout());
|
||||
|
||||
text = new Text(parent, SWT.MULTI | SWT.V_SCROLL);
|
||||
readFileContentToEditor();
|
||||
text.addModifyListener(new ModifyListener() {
|
||||
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e) {
|
||||
beDirty();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void readFileContentToEditor() {
|
||||
if (input instanceof FileSystemFileEditorInput) {
|
||||
fileInput = (FileSystemFileEditorInput) input;
|
||||
File file = fileInput.getFile();
|
||||
try {
|
||||
text.setText(FileUtils.readFileToString(file));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
text.setFocus();
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return fileInput.getFile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void doSaveAs() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package edu.fichte.pbi.ide.editors;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IPersistableElement;
|
||||
|
||||
public class FileSystemFileEditorInput implements IEditorInput {
|
||||
|
||||
private File file;
|
||||
|
||||
public FileSystemFileEditorInput(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public Object getAdapter(Class adapter) {
|
||||
return Platform.getAdapterManager().getAdapter(this, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDescriptor getImageDescriptor() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPersistableElement getPersistable() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTipText() {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((file == null) ? 0 : file.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
FileSystemFileEditorInput other = (FileSystemFileEditorInput) obj;
|
||||
if (file == null) {
|
||||
if (other.file != null)
|
||||
return false;
|
||||
} else if (!file.equals(other.file))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
349
src/edu/fichte/pbi/ide/editors/PBIEditor.java
Normal file
349
src/edu/fichte/pbi/ide/editors/PBIEditor.java
Normal file
@ -0,0 +1,349 @@
|
||||
package edu.fichte.pbi.ide.editors;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.action.StatusLineContributionItem;
|
||||
import org.eclipse.jface.action.StatusLineManager;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.KeyListener;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorSite;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.internal.WorkbenchWindow;
|
||||
import org.eclipse.ui.part.EditorPart;
|
||||
|
||||
import edu.fichte.pbi.ide.ApplicationActionBarAdvisor;
|
||||
import edu.fichte.pbi.ide.commonsstolen.FileUtils;
|
||||
import edu.fichte.pbi.prgm.parse.Lexer;
|
||||
import etinyplugins.commons.swt.UndoRedoImpl;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class PBIEditor extends EditorPart {
|
||||
|
||||
public static final String ID = "edu.fichte.pbi.ide.pbieditor";
|
||||
public StyledText text;
|
||||
private IEditorInput input;
|
||||
private boolean dirty = false;
|
||||
private FileSystemFileEditorInput fileInput;
|
||||
private StatusLineContributionItem statusLine;
|
||||
|
||||
@Override
|
||||
public void doSave(IProgressMonitor monitor) {
|
||||
String content = text.getText();
|
||||
File file = fileInput.getFile();
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
out.write(content.getBytes());
|
||||
out.close();
|
||||
beClean();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doSaveAs() {
|
||||
FileDialog fileDialog = new FileDialog(getSite().getShell(), SWT.SAVE);
|
||||
fileDialog.setFileName(fileInput.getName());
|
||||
fileDialog.setFilterPath(fileInput.getFile().getParent());
|
||||
String newFile = fileDialog.open();
|
||||
File file = new File(newFile);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FileSystemFileEditorInput fileSystemFileEditorInput = new FileSystemFileEditorInput(
|
||||
file);
|
||||
setInput(fileSystemFileEditorInput);
|
||||
doSave(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaveOnCloseNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IEditorSite site, IEditorInput input)
|
||||
throws PartInitException {
|
||||
this.input = input;
|
||||
setSite(site);
|
||||
setInput(input);
|
||||
setPartName(input.getName());
|
||||
}
|
||||
|
||||
private void beDirty() {
|
||||
dirty = true;
|
||||
firePropertyChange(PROP_DIRTY);
|
||||
}
|
||||
|
||||
private void beClean() {
|
||||
dirty = false;
|
||||
firePropertyChange(PROP_DIRTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty() {
|
||||
return dirty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaveAsAllowed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setInput(IEditorInput input) {
|
||||
super.setInput(input);
|
||||
this.input = input;
|
||||
this.fileInput = (FileSystemFileEditorInput) input;
|
||||
}
|
||||
|
||||
public StyledText getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
parent = new Composite(parent, 0);
|
||||
parent.setLayout(new FillLayout());
|
||||
|
||||
text = new StyledText(parent, SWT.MULTI | SWT.V_SCROLL);
|
||||
text.setAlwaysShowScrollBars(true);
|
||||
new UndoRedoImpl(text);
|
||||
|
||||
addCurrentPositionTelling();
|
||||
|
||||
readFileContentToEditor();
|
||||
text.addModifyListener(new ModifyListener() {
|
||||
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e) {
|
||||
beDirty();
|
||||
reformat();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Status Zeilenzugriff merken
|
||||
StatusLineManager statusLineManager = ((WorkbenchWindow) getSite()
|
||||
.getWorkbenchWindow()).getStatusLineManager();
|
||||
statusLine = (StatusLineContributionItem) statusLineManager
|
||||
.find(ApplicationActionBarAdvisor.MY_COLROW_TELLER);
|
||||
}
|
||||
|
||||
private void addCurrentPositionTelling() {
|
||||
text.addKeyListener(new KeyListener() {
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent arg0) {
|
||||
updatePositionDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent arg0) {
|
||||
updatePositionDisplay();
|
||||
}
|
||||
});
|
||||
|
||||
text.addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseUp(MouseEvent arg0) {
|
||||
updatePositionDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDown(MouseEvent arg0) {
|
||||
updatePositionDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDoubleClick(MouseEvent arg0) {
|
||||
updatePositionDisplay();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updatePositionDisplay() {
|
||||
int caretOffset = text.getCaretOffset();
|
||||
int lineNo = 1;
|
||||
int charNo = 1;
|
||||
String content = text.getText();
|
||||
for (int n = 0; n < caretOffset; n++) {
|
||||
char currentChar = content.charAt(n);
|
||||
if (currentChar == '\n') {
|
||||
lineNo++;
|
||||
charNo = 1;
|
||||
} else if (currentChar == '\r') {
|
||||
} else {
|
||||
charNo++;
|
||||
}
|
||||
}
|
||||
String position = lineNo + "/" + charNo;
|
||||
statusLine.setText(position);
|
||||
}
|
||||
|
||||
private void reformat() {
|
||||
// StyleRange styleRange = new StyleRange();
|
||||
// styleRange.start = 0;
|
||||
// styleRange.length = 10;
|
||||
// styleRange.fontStyle = SWT.BOLD;
|
||||
// styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
// SWT.COLOR_BLUE);
|
||||
for (StyleRange styleRange : sytaxHighlighting()) {
|
||||
text.setStyleRange(styleRange);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<StyleRange> sytaxHighlighting() {
|
||||
String text = this.text.getText();
|
||||
String tmp = "";
|
||||
List<String> knowCommands = new LinkedList<>();
|
||||
for (String cmd : Lexer.KNOWN_COMMANDS) {
|
||||
knowCommands.add(cmd);
|
||||
}
|
||||
knowCommands.add("TO");
|
||||
knowCommands.add("THEN");
|
||||
knowCommands.add("STEP");
|
||||
List<StyleRange> retVal = new LinkedList<StyleRange>();
|
||||
StyleRange allBlack = new StyleRange();
|
||||
allBlack.start = 0;
|
||||
allBlack.length = text.length();
|
||||
allBlack.foreground = Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_BLACK);
|
||||
retVal.add(allBlack);
|
||||
global: for (int i = 0; i < text.length(); i++) {
|
||||
char actual = text.charAt(i);
|
||||
if (actual == ' ' || actual == '\n' || actual == ',') {
|
||||
tmp = "";
|
||||
continue;
|
||||
}
|
||||
if (actual == '=' || actual == '/' || actual == '*'
|
||||
|| actual == '+' || actual == '-' || actual == '^'
|
||||
|| actual == '|' || actual == '&' || actual == '>'
|
||||
|| actual == '<') {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = i;
|
||||
styleRange.length = 1;
|
||||
styleRange.fontStyle = SWT.BOLD;
|
||||
styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_DARK_RED);
|
||||
retVal.add(styleRange);
|
||||
tmp = "";
|
||||
continue;
|
||||
}
|
||||
if (actual == '\'') {
|
||||
for (int k = i + 1; k < text.length(); k++) {
|
||||
if (text.charAt(k) == '\n' || k == text.length() - 1) {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = i;
|
||||
styleRange.length = k == text.length() - 1 ? k - i + 1
|
||||
: k - i;
|
||||
styleRange.foreground = Display.getCurrent()
|
||||
.getSystemColor(SWT.COLOR_DARK_GREEN);
|
||||
retVal.add(styleRange);
|
||||
tmp = "";
|
||||
i = k;
|
||||
continue global;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (actual == '\"') {
|
||||
for (int k = i + 1; k < text.length(); k++) {
|
||||
if (text.charAt(k) == '\"') {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = i;
|
||||
styleRange.length = k - i + 1;
|
||||
styleRange.foreground = Display.getCurrent()
|
||||
.getSystemColor(SWT.COLOR_DARK_YELLOW);
|
||||
retVal.add(styleRange);
|
||||
tmp = "";
|
||||
i = k;
|
||||
continue global;
|
||||
}
|
||||
}
|
||||
}
|
||||
tmp += text.charAt(i);
|
||||
for (String cmd : knowCommands) {
|
||||
if (tmp.equals(cmd)) {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = (i + 1) - cmd.length();
|
||||
styleRange.length = cmd.length();
|
||||
styleRange.fontStyle = SWT.BOLD;
|
||||
styleRange.foreground = Display.getCurrent()
|
||||
.getSystemColor(SWT.COLOR_BLUE);
|
||||
retVal.add(styleRange);
|
||||
tmp = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
char prev = (i == 0 ? ' ' : text.charAt(i - 1));
|
||||
if (((actual > 47 && actual < 58))
|
||||
&& (prev == ' ' || prev == '\n' || prev == ',' || prev == '(') || prev == '=' || prev == '/' || prev == '*'
|
||||
|| prev == '+' || prev == '-' || prev == '^'
|
||||
|| prev == '|' || prev == '&' || prev == '>'
|
||||
|| prev == '<') {
|
||||
for (int k = i; k < text.length(); k++) {
|
||||
char c = text.charAt(k);
|
||||
if (c < 48 || c > 57) {
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = i;
|
||||
styleRange.length = k - i;
|
||||
styleRange.foreground = Display.getCurrent()
|
||||
.getSystemColor(SWT.COLOR_DARK_YELLOW);
|
||||
retVal.add(styleRange);
|
||||
tmp = "";
|
||||
i = k;
|
||||
continue global;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
|
||||
}
|
||||
|
||||
private void readFileContentToEditor() {
|
||||
if (input instanceof FileSystemFileEditorInput) {
|
||||
fileInput = (FileSystemFileEditorInput) input;
|
||||
File file = fileInput.getFile();
|
||||
try {
|
||||
text.setText(FileUtils.readFileToString(file));
|
||||
reformat();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
text.setFocus();
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return fileInput.getFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
375
src/edu/fichte/pbi/ide/views/ConsoleView.java
Normal file
375
src/edu/fichte/pbi/ide/views/ConsoleView.java
Normal file
@ -0,0 +1,375 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.TraverseEvent;
|
||||
import org.eclipse.swt.events.TraverseListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.run.PluginRunner;
|
||||
import edu.fichte.pbi.run.app.IConsole;
|
||||
import edu.fichte.pbi.vm.IRunWatcher;
|
||||
import edu.fichte.pbi.vm.Settings;
|
||||
import edu.fichte.pbi.vm.storage.IEEPROMMonitor;
|
||||
|
||||
public class ConsoleView extends ViewPart implements IConsole {
|
||||
public static final String ID = "edu.fichte.pbi.ide.consoleView";
|
||||
public StyledText text;
|
||||
private StyledText inputText;
|
||||
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
parent = new Composite(parent, SWT.NULL);
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
Label debugLabel = new Label(parent, SWT.HORIZONTAL);
|
||||
debugLabel.setText("Console");
|
||||
text = new StyledText(parent, SWT.VERTICAL | SWT.HORIZONTAL | SWT.MULTI);
|
||||
text.setAlwaysShowScrollBars(false);
|
||||
text.setEditable(false);
|
||||
Label inputLabel = new Label(parent, SWT.HORIZONTAL);
|
||||
inputLabel.setText("Input");
|
||||
GridData textGridData = new GridData();
|
||||
textGridData.horizontalAlignment = GridData.FILL;
|
||||
textGridData.verticalAlignment = GridData.FILL;
|
||||
textGridData.grabExcessHorizontalSpace = true;
|
||||
textGridData.grabExcessVerticalSpace = true;
|
||||
text.setLayoutData(textGridData);
|
||||
setScheme();
|
||||
inputText = new StyledText(parent, SWT.SINGLE);
|
||||
|
||||
GridData inputTextGridData = new GridData();
|
||||
inputTextGridData.horizontalAlignment = GridData.FILL;
|
||||
inputTextGridData.verticalAlignment = GridData.FILL;
|
||||
inputText.setLayoutData(inputTextGridData);
|
||||
inputText.setEditable(false);
|
||||
inputText.addTraverseListener(new TraverseListener() {
|
||||
|
||||
@Override
|
||||
public void keyTraversed(TraverseEvent e) {
|
||||
if (e.keyCode == 13) {
|
||||
if (runnerLock != null) {
|
||||
inputText.setEditable(false);
|
||||
readlineText = inputText.getText();
|
||||
inputText.setText("");
|
||||
|
||||
String formerText = text.getText();
|
||||
// int formerLength = formerText.length();
|
||||
String textAdditionWithNewLines = "\r\n" + readlineText
|
||||
+ "\r\n";
|
||||
String newText = formerText + textAdditionWithNewLines;
|
||||
text.setText(newText);
|
||||
synchronized (runnerLock) {
|
||||
runnerLock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
createPartMenu();
|
||||
}
|
||||
|
||||
private void stopCurrentExecution() {
|
||||
if (isRunning()) {
|
||||
// runner.stop();
|
||||
runner = null;
|
||||
if (runStateListener != null) {
|
||||
runStateListener.runStateChanged(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return runner != null && runner.isAlive();
|
||||
}
|
||||
|
||||
private void createPartMenu() {
|
||||
Action stopAction = new Action("Stop") {
|
||||
@Override
|
||||
public void run() {
|
||||
// Kill the runner
|
||||
stopCurrentExecution();
|
||||
text.setText(text.getText()+"\n[STOP]");
|
||||
|
||||
//now lock the debugview => notify it to lock itself
|
||||
System.out.println("Locking Pins...");
|
||||
((DebugView) getViewSite().getPage().findView(DebugView.ID)).lockPinState();
|
||||
}
|
||||
};
|
||||
getViewSite().getActionBars().getToolBarManager().add(stopAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
|
||||
}
|
||||
|
||||
private Thread runner;
|
||||
private Object runnerLock;
|
||||
private String readlineText;
|
||||
private IRunStateListener runStateListener;
|
||||
|
||||
public void run(final File file, final IEEPROMMonitor monitor,
|
||||
final IRunWatcher runWatcher,
|
||||
final VariableView varView,
|
||||
final IRunStateListener runStateListener) {
|
||||
if (runner != null && runner.isAlive()) {
|
||||
runner.interrupt();
|
||||
}
|
||||
clearConsole();
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runStateListener.runStateChanged(true);
|
||||
PluginRunner pluginRunner = new PluginRunner();
|
||||
pluginRunner.run(file, ConsoleView.this, monitor,
|
||||
runWatcher,getSettings(), varView);
|
||||
runStateListener.runStateChanged(false);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
runStateListener.runStateChanged(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
runner = new Thread(runnable);
|
||||
int priority = Thread.currentThread().getPriority() - 2;
|
||||
priority = Math.max(Thread.MIN_PRIORITY, priority);
|
||||
runnerLock = new Object();
|
||||
((DebugView) getViewSite().getPage().findView(DebugView.ID)).unlockPinState();
|
||||
runner.setPriority(priority);
|
||||
runner.start();
|
||||
}
|
||||
|
||||
private Settings getSettings() {
|
||||
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/set.cfg");
|
||||
if (!file.canRead()) {
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
boolean emulate4Mhz = true, activateinfo = false, printInternComposition = false, nowarn = false;
|
||||
try {
|
||||
Scanner scanner = new Scanner(file);
|
||||
String line = "";
|
||||
while (scanner.hasNextLine()) {
|
||||
line = scanner.nextLine().trim();
|
||||
if (line.startsWith("##") || line.isEmpty())
|
||||
continue;
|
||||
if (line.startsWith("emulate 4Mhz")) {
|
||||
emulate4Mhz = evaluateBooleanExpression(line);
|
||||
} else if (line.startsWith("activate info")) {
|
||||
activateinfo = evaluateBooleanExpression(line);
|
||||
} else if (line.startsWith("print intern composition")) {
|
||||
printInternComposition = evaluateBooleanExpression(line);
|
||||
} else if (line.startsWith("ignore warnings")) {
|
||||
nowarn = evaluateBooleanExpression(line);
|
||||
} else {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
scanner.close();
|
||||
} catch (FileNotFoundException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
err("[Error, run configurations]Couldn't read the configuration file -> using standard cfg\n");
|
||||
}
|
||||
return new Settings(activateinfo, emulate4Mhz, printInternComposition,
|
||||
nowarn);
|
||||
}
|
||||
|
||||
public void setScheme() {
|
||||
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/color.cfg");
|
||||
if (!file.canRead()) {
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
try {
|
||||
Scanner scanner = new Scanner(file);
|
||||
String line = "";
|
||||
while (scanner.hasNextLine()) {
|
||||
line = scanner.nextLine().trim();
|
||||
if (line.startsWith("##") || line.isEmpty())
|
||||
continue;
|
||||
if (line.startsWith("console scheme")) {
|
||||
String[] split = line.split("=");
|
||||
if (split.length != 2) {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (split[1].trim().equals("blue")) {
|
||||
text.setBackground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_DARK_BLUE));
|
||||
text.setForeground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_WHITE));
|
||||
} else if (split[1].trim().equals("black")) {
|
||||
text.setBackground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_BLACK));
|
||||
text.setForeground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_WHITE));
|
||||
|
||||
} else if (split[1].trim().equals("white")) {
|
||||
text.setBackground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_WHITE));
|
||||
text.setForeground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_BLACK));
|
||||
|
||||
} else {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
} else {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
scanner.close();
|
||||
} catch (FileNotFoundException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
err("[Error, run configurations]Couldn't read the configuration file -> using standard cfg\n");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean evaluateBooleanExpression(String s) {
|
||||
String[] split = s.split("=");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return split[1].trim().equals("true");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printLn(final String line) {
|
||||
print("\n" + line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(final String s) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
text.setText(text.getText() + s);
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readLn() {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ConsoleView.this.focusOnInput();
|
||||
}
|
||||
});
|
||||
|
||||
synchronized (runnerLock) {
|
||||
try {
|
||||
runnerLock.wait();
|
||||
} catch (InterruptedException ie) {
|
||||
// do nothing here, we have been killed.
|
||||
}
|
||||
}
|
||||
return readlineText;
|
||||
}
|
||||
|
||||
protected void focusOnInput() {
|
||||
inputText.setEditable(true);
|
||||
inputText.forceFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
text.setText("");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void err(final String err) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// StyleRange styleRange = new StyleRange();
|
||||
// styleRange.start = text.getText().length();
|
||||
// styleRange.length = err.length();
|
||||
// styleRange.fontStyle = SWT.BOLD;
|
||||
// styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
// SWT.COLOR_RED);
|
||||
text.setText(text.getText() + err + "\n");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
// text.setStyleRange(styleRange);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(final String warn) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// StyleRange styleRange = new StyleRange();
|
||||
// styleRange.start = text.getText().length();
|
||||
// styleRange.length = warn.length();
|
||||
// styleRange.fontStyle = SWT.BOLD;
|
||||
// styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
// SWT.COLOR_RED);
|
||||
text.setText(text.getText() + warn + "\n");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
// text.setStyleRange(styleRange);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(final String info) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// StyleRange styleRange = new StyleRange();
|
||||
// styleRange.start = text.getText().length();
|
||||
// styleRange.length = info.length();
|
||||
// styleRange.fontStyle = SWT.BOLD;
|
||||
// styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
// SWT.COLOR_RED);
|
||||
text.setText(text.getText() + info + "\n");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
// text.setStyleRange(styleRange);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
322
src/edu/fichte/pbi/ide/views/DebugView.java
Normal file
322
src/edu/fichte/pbi/ide/views/DebugView.java
Normal file
@ -0,0 +1,322 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.swt.custom.CLabel;
|
||||
import org.eclipse.swt.custom.StackLayout;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.util.CallbackVariableListener;
|
||||
import edu.fichte.pbi.vm.IRunWatcher;
|
||||
import edu.fichte.pbi.vm.Machine;
|
||||
import edu.fichte.pbi.vm.var.IVariable;
|
||||
|
||||
public class DebugView extends ViewPart implements IRunWatcher {
|
||||
|
||||
public static String ID = "edu.fichte.pbi.ide.debugView";
|
||||
|
||||
private Machine machine;
|
||||
|
||||
//GUI elements
|
||||
private Label[] label = new Label[8];
|
||||
private CLabel[] labelInOut = new CLabel[8];
|
||||
private CLabel[] labelHighLow = new CLabel[8];
|
||||
private Button[] buttonHighLow = new Button[8];
|
||||
private Composite[] widgetPin = new Composite[8];
|
||||
private StackLayout[] stackLayout = new StackLayout[8];
|
||||
|
||||
//load icons
|
||||
private Image imageHigh = loadIcon("status_red.gif");
|
||||
private Image imageLow = loadIcon("status_black.gif");
|
||||
|
||||
private Image imageInput = loadIcon("InputArrowSmall.gif");
|
||||
private Image imageOutput = loadIcon("OutputArrowSmall.gif");
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
//create layout Parent with GridLayout
|
||||
Composite layoutParent = new Composite(parent, 0);
|
||||
layoutParent.setLayout(new GridLayout(3, true));
|
||||
|
||||
//create Labels
|
||||
Label pin = new Label(layoutParent, 0);
|
||||
pin.setText("PIN");
|
||||
Label io = new Label(layoutParent, 0);
|
||||
io.setText("I/O");
|
||||
Label hl = new Label(layoutParent, 0);
|
||||
hl.setText("High/Low");
|
||||
|
||||
for (int i = widgetPin.length - 1; i >= 0; i--) {
|
||||
//first column: Pin Label
|
||||
label[i] = new Label(layoutParent, 0);
|
||||
label[i].setText("P" + String.valueOf(i));
|
||||
|
||||
//second column: Pin direction (Input/Output)
|
||||
labelInOut[i] = new CLabel(layoutParent, 0);
|
||||
labelInOut[i].setText("Input");
|
||||
labelInOut[i].setImage(imageInput);
|
||||
//default is input, see:
|
||||
//(http://www.parallax.com/go/PBASICHelp/Content\
|
||||
///LanguageTopics/Commands/INPUT.htm -> Explanation)
|
||||
|
||||
//third column: Pin state (High/Low)
|
||||
//changes between CLabel and Button, depending on if an
|
||||
//input is accepted or not (uses StackLayout for that)
|
||||
stackLayout[i] = new StackLayout();
|
||||
//create new composite in which stackLayout is active
|
||||
widgetPin[i] = new Composite(layoutParent, 0);
|
||||
widgetPin[i].setLayout(stackLayout[i]);
|
||||
//create first "page" of stackLayout: label (if pin is output)
|
||||
labelHighLow[i] = new CLabel(widgetPin[i], 0);
|
||||
labelHighLow[i].setText("Low");
|
||||
labelHighLow[i].setImage(imageLow);
|
||||
labelHighLow[i].pack();
|
||||
//create second "page" of stackLayout: button (if pin is input)
|
||||
buttonHighLow[i] = new Button(widgetPin[i], 0);
|
||||
buttonHighLow[i].setText("Low");
|
||||
buttonHighLow[i].setImage(imageLow);
|
||||
buttonHighLow[i].pack();
|
||||
//show second "page" first as pin is initialized as input pin
|
||||
stackLayout[i].topControl = buttonHighLow[i];
|
||||
//actions listeners are defined outside of the loop
|
||||
}
|
||||
//action listeners as you are not allowed to use
|
||||
//non-final variables in an inner class
|
||||
buttonHighLow[0].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(0);
|
||||
}
|
||||
});
|
||||
buttonHighLow[1].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(1);
|
||||
}
|
||||
});
|
||||
buttonHighLow[2].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(2);
|
||||
}
|
||||
});
|
||||
buttonHighLow[3].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(3);
|
||||
}
|
||||
});
|
||||
buttonHighLow[4].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(4);
|
||||
}
|
||||
});
|
||||
buttonHighLow[5].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(5);
|
||||
}
|
||||
});
|
||||
buttonHighLow[6].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(6);
|
||||
}
|
||||
});
|
||||
buttonHighLow[7].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(7);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
|
||||
}
|
||||
|
||||
private void toggleVariable(int varNum) {
|
||||
IVariable variable = machine.parseIVariable("PIN" + varNum);
|
||||
long value = variable.getValue();
|
||||
if (value == 0) {
|
||||
value = 1;
|
||||
} else {
|
||||
value = 0;
|
||||
}
|
||||
variable.setValue(value);
|
||||
}
|
||||
|
||||
public void setMachine(Machine machine) {
|
||||
this.machine = machine;
|
||||
|
||||
IVariable[] listener = new IVariable[labelHighLow.length];
|
||||
for (int i = 0; i < labelHighLow.length; i++) {
|
||||
listener[i] = this.machine.parseIVariable("PIN" + String.valueOf(i));
|
||||
listener[i].setVariableListener(
|
||||
new CallbackVariableListener(
|
||||
new PinCommObject(labelHighLow[i], buttonHighLow[i])) {
|
||||
|
||||
@Override
|
||||
public void variableChanged(IVariable variable) {
|
||||
final long value = variable.getValue();
|
||||
final boolean[] newState = new boolean[1];
|
||||
if (value == 1) {
|
||||
newState[0] = true;
|
||||
}
|
||||
getSite().getShell().getDisplay().syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PinCommObject obj = (PinCommObject) callback;
|
||||
if (newState[0]) {
|
||||
obj.label.setText("High");
|
||||
obj.label.setImage(imageHigh);
|
||||
obj.button.setText("High");
|
||||
obj.button.setImage(imageHigh);
|
||||
} else {
|
||||
obj.label.setText("Low");
|
||||
obj.label.setImage(imageLow);
|
||||
obj.button.setText("Low");
|
||||
obj.button.setImage(imageLow);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
IVariable[] dirListener = new IVariable[labelInOut.length];
|
||||
for (int i = 0; i < labelInOut.length; i++) {
|
||||
dirListener[i] = this.machine.parseIVariable("DIR"
|
||||
+ String.valueOf(i));
|
||||
dirListener[i].setVariableListener(
|
||||
new CallbackVariableListener(
|
||||
new DirCommObject(
|
||||
labelInOut[i],
|
||||
labelHighLow[i],
|
||||
buttonHighLow[i],
|
||||
stackLayout[i],
|
||||
widgetPin[i])) {
|
||||
|
||||
@Override
|
||||
public void variableChanged(IVariable variable) {
|
||||
final long value = variable.getValue();
|
||||
final boolean[] newState = new boolean[1];
|
||||
if (value == 1) {
|
||||
newState[0] = true;
|
||||
}
|
||||
getSite().getShell().getDisplay().syncExec(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DirCommObject obj = (DirCommObject) callback;
|
||||
if (newState[0]) {
|
||||
obj.labelDir.setText("Output");
|
||||
obj.labelDir.pack();
|
||||
obj.labelDir.setImage(imageOutput);
|
||||
obj.labelState.setVisible(true);
|
||||
obj.buttonState.setVisible(false);
|
||||
obj.stackLayout.topControl = obj.labelState;
|
||||
} else {
|
||||
obj.labelDir.setText("Input");
|
||||
obj.labelDir.pack();
|
||||
obj.labelDir.setImage(imageInput);
|
||||
obj.labelState.setVisible(false);
|
||||
obj.buttonState.setVisible(true);
|
||||
obj.stackLayout.topControl = obj.buttonState;
|
||||
}
|
||||
obj.widgetPin.layout();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static Image loadIcon(String iconFilename) {
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
|
||||
File file = new File(targetRoot, "icons/" + iconFilename);
|
||||
if (!file.canRead()) {
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "icons",
|
||||
targetRoot);
|
||||
}
|
||||
return new Image(Display.getCurrent(), file.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void lockPinState() {
|
||||
for (int i = 0; i < buttonHighLow.length; i++) {
|
||||
buttonHighLow[i].setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void unlockPinState() {
|
||||
for (int i = 0; i < buttonHighLow.length; i++) {
|
||||
buttonHighLow[i].setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private class PinCommObject {
|
||||
|
||||
protected CLabel label;
|
||||
|
||||
protected Button button;
|
||||
|
||||
private PinCommObject(CLabel label, Button button) {
|
||||
this.label = label;
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
|
||||
private class DirCommObject {
|
||||
|
||||
protected CLabel labelDir;
|
||||
|
||||
protected CLabel labelState;
|
||||
|
||||
protected Button buttonState;
|
||||
|
||||
protected StackLayout stackLayout;
|
||||
|
||||
protected Composite widgetPin;
|
||||
|
||||
private DirCommObject(
|
||||
CLabel labelDir,
|
||||
CLabel labelState,
|
||||
Button buttonState,
|
||||
StackLayout stackLayout,
|
||||
Composite widgetPin) {
|
||||
this.labelDir = labelDir;
|
||||
this.labelState = labelState;
|
||||
this.buttonState = buttonState;
|
||||
this.stackLayout = stackLayout;
|
||||
this.widgetPin = widgetPin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
167
src/edu/fichte/pbi/ide/views/EEPROMView.java
Normal file
167
src/edu/fichte/pbi/ide/views/EEPROMView.java
Normal file
@ -0,0 +1,167 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
import edu.fichte.pbi.vm.storage.EEPROM;
|
||||
import edu.fichte.pbi.vm.storage.IEEPROMMonitor;
|
||||
|
||||
public class EEPROMView extends ViewPart implements IEEPROMMonitor {
|
||||
|
||||
public static final String ID = "edu.fichte.pbi.ide.eepromView";
|
||||
|
||||
private Label selected;
|
||||
private Label previous;
|
||||
|
||||
Label address;
|
||||
Label charValue;
|
||||
Label binaryValue;
|
||||
Label decimalValue;
|
||||
ArrayList<Label> allBytes = new ArrayList<Label>(EEPROM.SIZE);
|
||||
|
||||
Composite infoView;
|
||||
Composite eepromParent;
|
||||
Composite eepromViewLabelParent;
|
||||
|
||||
private Color writeAccess = new Color(Display.getCurrent(), 0, 255, 0);
|
||||
private Color highlighted = new Color(Display.getCurrent(), 255, 191, 0);
|
||||
// private Color special = new Color(Display.getCurrent(), 255, 0, 192);
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
//parent element, one element wide
|
||||
eepromParent = new Composite(parent, 0);
|
||||
eepromParent.setLayout(new GridLayout(1, false));
|
||||
|
||||
//make composite for all labels representing the eeprom
|
||||
eepromViewLabelParent = new Composite(eepromParent, 0);
|
||||
eepromViewLabelParent.setLayout(new GridLayout(16, false));
|
||||
|
||||
//create the labels, set them to zero
|
||||
allBytes.ensureCapacity(EEPROM.SIZE);
|
||||
Label newLabel;
|
||||
for (int i = 0; i < EEPROM.SIZE; i++) {
|
||||
newLabel = new Label(eepromViewLabelParent, 0);
|
||||
newLabel.setText("00");
|
||||
newLabel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseUp(MouseEvent event) {
|
||||
super.mouseUp(event);
|
||||
|
||||
if (event.getSource() instanceof Label) {
|
||||
//mark the label with color /highlighted/
|
||||
if (selected != null) {
|
||||
selected.setBackground(null);
|
||||
}
|
||||
Label label = (Label) event.getSource();
|
||||
selected = label;
|
||||
selected.setBackground(highlighted);
|
||||
|
||||
//calc details
|
||||
String pos = String.valueOf(allBytes.indexOf(label));
|
||||
int value = Integer.parseInt(label.getText(), 16);
|
||||
String ascii = String.valueOf((char) value);
|
||||
String binary = Integer.toBinaryString(value);
|
||||
String decimal = String.valueOf(value);
|
||||
|
||||
//set new values
|
||||
address.setText("Address: " + pos);
|
||||
charValue.setText("ASCII: " + ascii);
|
||||
binaryValue.setText("Binary: " + binary);
|
||||
decimalValue.setText("Decimal: " + decimal);
|
||||
|
||||
//update composite
|
||||
infoView.pack();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
allBytes.add(i, newLabel);
|
||||
}
|
||||
|
||||
//initialize infoView Composite and labels
|
||||
infoView = new Composite(eepromParent, 0);
|
||||
infoView.setLayout(new GridLayout(4, false));
|
||||
|
||||
address = new Label(infoView, 0);
|
||||
charValue = new Label(infoView, 0);
|
||||
binaryValue = new Label(infoView, 0);
|
||||
decimalValue = new Label(infoView, 0);
|
||||
|
||||
address.setText("Address: --");
|
||||
charValue.setText("ASCII: --");
|
||||
binaryValue.setText("Binary: --");
|
||||
decimalValue.setText("Decimal: --");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(final String s) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int value;
|
||||
String text;
|
||||
String tooltip;
|
||||
String[] newBytes = splitIntoParts(s, 2);
|
||||
for (int i = 0; i < EEPROM.SIZE; i++) {
|
||||
text = newBytes[i].toUpperCase();
|
||||
if (!allBytes.get(i).getText().equals(text)) {
|
||||
value = Integer.parseInt(text, 16);
|
||||
if (allBytes.get(i).equals(selected)) {
|
||||
//selected got updated, recalc details
|
||||
String ascii = String.valueOf((char) value);
|
||||
String binary = Integer.toBinaryString(value);
|
||||
String decimal = String.valueOf(value);
|
||||
|
||||
//set new values
|
||||
charValue.setText("ASCII: " + ascii);
|
||||
binaryValue.setText("Binary: " + binary);
|
||||
decimalValue.setText("Decimal: " + decimal);
|
||||
|
||||
//update composite
|
||||
infoView.pack();
|
||||
} else {
|
||||
allBytes.get(i).setBackground(writeAccess);
|
||||
}
|
||||
tooltip = "Ascii: " + String.valueOf((char) value);
|
||||
allBytes.get(i).setToolTipText(tooltip);
|
||||
}
|
||||
allBytes.get(i).setText(text);
|
||||
allBytes.get(i).pack();
|
||||
if (previous != selected) {
|
||||
previous.setBackground(null);
|
||||
}
|
||||
previous = allBytes.get(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private static String[] splitIntoParts(String string, int partSize) {
|
||||
int size = Integer.valueOf((int) string.length() / partSize);
|
||||
String[] parts = new String[size + 1];
|
||||
for (int i = 0; i <= string.length(); i+=partSize) {
|
||||
parts[(int) i/partSize] = string.substring(i, Math.min(2*size, i + partSize));
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
}
|
287
src/edu/fichte/pbi/ide/views/FileExplorer.java
Normal file
287
src/edu/fichte/pbi/ide/views/FileExplorer.java
Normal file
@ -0,0 +1,287 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.FileSystemFileEditorInput;
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
|
||||
/**
|
||||
* This sample class demonstrates how to plug-in a new workbench view. The view
|
||||
* shows data obtained from the model. The sample creates a dummy model on the
|
||||
* fly, but a real implementation would connect to the model available either in
|
||||
* this or another plug-in (e.g. the workspace). The view is connected to the
|
||||
* model using a content provider.
|
||||
* <p>
|
||||
* The view uses a label provider to define how model objects should be
|
||||
* presented in the view. Each view can present the same model objects using
|
||||
* different labels and icons, if needed. Alternatively, a single label provider
|
||||
* can be shared between views in order to ensure that objects of the same type
|
||||
* are presented in the same way everywhere.
|
||||
* <p>
|
||||
*/
|
||||
|
||||
public class FileExplorer extends ViewPart {
|
||||
|
||||
/**
|
||||
* The ID of the view as specified by the extension.
|
||||
*/
|
||||
public static final String ID = "edu.fichte.pbi.ide.views.FileExplorer";
|
||||
|
||||
private TreeViewer viewer;
|
||||
private Action doubleClickAction;
|
||||
private static final Image bs1File = AbstractUIPlugin
|
||||
.imageDescriptorFromPlugin("edu.fichte.pbi.ide",
|
||||
"icons/bs1.gif").createImage();
|
||||
|
||||
class ViewContentProvider implements IStructuredContentProvider,
|
||||
ITreeContentProvider {
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object parent) {
|
||||
if (parent.equals(getViewSite())) {
|
||||
Iterable<Path> rootDirectories = FileSystems.getDefault()
|
||||
.getRootDirectories();
|
||||
ArrayList<File> retVal = new ArrayList<File>();
|
||||
retVal.add(new File(System.getProperty("user.home")));
|
||||
|
||||
for (Path path : rootDirectories) {
|
||||
retVal.add(path.toFile());
|
||||
}
|
||||
return retVal.toArray();
|
||||
}
|
||||
return getChildren(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object child) {
|
||||
if (child instanceof File) {
|
||||
return ((File) child).getParentFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parent) {
|
||||
if (parent instanceof File) {
|
||||
File parentFile = (File) parent;
|
||||
if (parentFile.isDirectory()) {
|
||||
File[] listFiles = parentFile.listFiles();
|
||||
ArrayList<File> retVal = new ArrayList<File>();
|
||||
if (listFiles == null) {
|
||||
listFiles = new File[0];
|
||||
}
|
||||
for (File file : listFiles) {
|
||||
if (!file.isHidden()
|
||||
&& (file.getName().endsWith(".bs1") || file
|
||||
.isDirectory())) {
|
||||
retVal.add(file);
|
||||
}
|
||||
}
|
||||
return retVal.toArray(new File[retVal.size()]);
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(Object parent) {
|
||||
if (parent instanceof File) {
|
||||
File file = (File) parent;
|
||||
return file.isDirectory();
|
||||
} else if (parent instanceof Path) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ViewLabelProvider extends LabelProvider {
|
||||
|
||||
@Override
|
||||
public String getText(Object obj) {
|
||||
if (obj instanceof File) {
|
||||
File file = (File) obj;
|
||||
String name = file.getName();
|
||||
if (name.trim().length() == 0) {
|
||||
name = file.getPath();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object obj) {
|
||||
String imageKey = ISharedImages.IMG_OBJ_FOLDER;
|
||||
|
||||
if (obj instanceof File) {
|
||||
File file = (File) obj;
|
||||
if (file.isDirectory()) {
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(imageKey);
|
||||
} else if(file.isFile()){
|
||||
return bs1File;
|
||||
}
|
||||
}
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(imageKey);
|
||||
}
|
||||
}
|
||||
|
||||
class NameSorter extends ViewerSorter {
|
||||
}
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public FileExplorer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a callback that will allow us to create the viewer and initialize
|
||||
* it.
|
||||
*/
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
// drillDownAdapter = new DrillDownAdapter(viewer);
|
||||
viewer.setContentProvider(new ViewContentProvider());
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
// viewer.setSorter(new NameSorter());
|
||||
viewer.setInput(getViewSite());
|
||||
|
||||
// Create the help context id for the viewer's control
|
||||
PlatformUI
|
||||
.getWorkbench()
|
||||
.getHelpSystem()
|
||||
.setHelp(viewer.getControl(),
|
||||
"edu.fichte.pbi.ide.viewer");
|
||||
makeActions();
|
||||
hookContextMenu();
|
||||
hookDoubleClickAction();
|
||||
contributeToActionBars();
|
||||
}
|
||||
|
||||
private void hookContextMenu() {
|
||||
MenuManager menuMgr = new MenuManager("#PopupMenu");
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
@Override
|
||||
public void menuAboutToShow(IMenuManager manager) {
|
||||
FileExplorer.this.fillContextMenu(manager);
|
||||
}
|
||||
});
|
||||
Menu menu = menuMgr.createContextMenu(viewer.getControl());
|
||||
viewer.getControl().setMenu(menu);
|
||||
getSite().registerContextMenu(menuMgr, viewer);
|
||||
}
|
||||
|
||||
private void contributeToActionBars() {
|
||||
IActionBars bars = getViewSite().getActionBars();
|
||||
fillLocalPullDown(bars.getMenuManager());
|
||||
fillLocalToolBar(bars.getToolBarManager());
|
||||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
manager.add(new Separator());
|
||||
}
|
||||
|
||||
private void fillContextMenu(IMenuManager manager) {
|
||||
|
||||
// Other plug-ins can contribute there actions here
|
||||
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||
}
|
||||
|
||||
private void fillLocalToolBar(IToolBarManager manager) {
|
||||
manager.add(new Separator());
|
||||
}
|
||||
|
||||
private void makeActions() {
|
||||
|
||||
doubleClickAction = new Action() {
|
||||
@Override
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection) selection)
|
||||
.getFirstElement();
|
||||
File file = (File) obj;
|
||||
if (file.isFile() && file.getName().endsWith(".bs1")) {
|
||||
FileSystemFileEditorInput fileSystemFileEditorInput = new FileSystemFileEditorInput(
|
||||
file);
|
||||
try {
|
||||
getViewSite().getPage().openEditor(
|
||||
fileSystemFileEditorInput, PBIEditor.ID);
|
||||
} catch (PartInitException e) {
|
||||
showMessage("File " + file.getAbsolutePath()
|
||||
+ " caused an error");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void hookDoubleClickAction() {
|
||||
viewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
@Override
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
doubleClickAction.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(viewer.getControl().getShell(),
|
||||
"File Explorer", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passing the focus request to the viewer's control.
|
||||
*/
|
||||
@Override
|
||||
public void setFocus() {
|
||||
viewer.getControl().setFocus();
|
||||
}
|
||||
}
|
90
src/edu/fichte/pbi/ide/views/HelpView.java
Normal file
90
src/edu/fichte/pbi/ide/views/HelpView.java
Normal file
@ -0,0 +1,90 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.browser.Browser;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
|
||||
public class HelpView extends ViewPart {
|
||||
|
||||
public static final String ID = "edu.fichte.pbi.ide.browser";
|
||||
private Browser browser;
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
browser = new Browser(parent, SWT.NONE);
|
||||
browser.setJavascriptEnabled(true);
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File indexhtml = new File(targetRoot, "help/index.html");
|
||||
if(!indexhtml.canRead()){
|
||||
// must copy the html from the bundle .jar to the data file location
|
||||
copyPathFromBundleToFSRecursive(bundle, "help", targetRoot);
|
||||
}
|
||||
try {
|
||||
browser.setUrl(indexhtml.toURI().toURL().toExternalForm());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Action back = new Action("back") {
|
||||
@Override
|
||||
public void run() {
|
||||
browser.back();
|
||||
}
|
||||
};
|
||||
getViewSite().getActionBars().getToolBarManager().add(back);
|
||||
|
||||
// URL mainUrl = Activator.getDefault().getBundle().getEntry("help/Main.html");
|
||||
}
|
||||
|
||||
public static void copyPathFromBundleToFSRecursive(Bundle bundle, String path,
|
||||
File targetRoot) {
|
||||
Enumeration<String> entryPaths = bundle.getEntryPaths(path);
|
||||
while(entryPaths.hasMoreElements()){
|
||||
String entryPath = entryPaths.nextElement();
|
||||
if(entryPath.endsWith("/")) {
|
||||
copyPathFromBundleToFSRecursive(bundle, entryPath, targetRoot);
|
||||
} else {
|
||||
URL entry = bundle.getEntry(entryPath);
|
||||
File target = new File(targetRoot, entryPath);
|
||||
byte[] buf = new byte[10000];
|
||||
int c = 0;
|
||||
try {
|
||||
InputStream in = entry.openStream();
|
||||
target.getParentFile().mkdirs();
|
||||
target.createNewFile();
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(target));
|
||||
while(-1!=(c=in.read(buf))){
|
||||
out.write(buf, 0, c);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Passing the focus request to the viewer's control.
|
||||
*/
|
||||
@Override
|
||||
public void setFocus() {
|
||||
browser.setFocus();
|
||||
}
|
||||
}
|
6
src/edu/fichte/pbi/ide/views/IRunStateListener.java
Normal file
6
src/edu/fichte/pbi/ide/views/IRunStateListener.java
Normal file
@ -0,0 +1,6 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
public interface IRunStateListener {
|
||||
|
||||
public void runStateChanged(boolean isRunnung);
|
||||
}
|
67
src/edu/fichte/pbi/ide/views/VariableView.java
Normal file
67
src/edu/fichte/pbi/ide/views/VariableView.java
Normal file
@ -0,0 +1,67 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
import edu.fichte.pbi.util.CallbackVariableListener;
|
||||
import edu.fichte.pbi.vm.IRunWatcher;
|
||||
import edu.fichte.pbi.vm.Machine;
|
||||
import edu.fichte.pbi.vm.var.IVariable;
|
||||
|
||||
public class VariableView extends ViewPart implements IRunWatcher {
|
||||
|
||||
public static String ID = "edu.fichte.pbi.ide.variableView";
|
||||
|
||||
private Machine machine;
|
||||
|
||||
private Label[] varLabel = new Label[14];
|
||||
private Label[] varValue = new Label[14];
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
Composite layoutParent = new Composite(parent, 0);
|
||||
layoutParent.setLayout(new GridLayout(2, false));
|
||||
|
||||
for (int i = 0; i < varLabel.length; i++) {
|
||||
varLabel[i] = new Label(layoutParent, 0);
|
||||
varLabel[i].setText("B" + String.valueOf(i));
|
||||
varValue[i] = new Label(layoutParent, 0);
|
||||
varValue[i].setText("0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMachine(Machine machine) {
|
||||
this.machine = machine;
|
||||
|
||||
IVariable[] listener = new IVariable[varLabel.length];
|
||||
for (int i = 0; i < varLabel.length; i++) {
|
||||
listener[i] = this.machine.parseIVariable("B" + String.valueOf(i));
|
||||
listener[i].setVariableListener(
|
||||
new CallbackVariableListener(varValue[i]) {
|
||||
|
||||
@Override
|
||||
public void variableChanged(IVariable variable) {
|
||||
final long value = variable.getValue();
|
||||
getSite().getShell().getDisplay().syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((Label) callback).setText(String.valueOf(value));
|
||||
((Label) callback).pack();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
194
src/etinyplugins/commons/swt/UndoRedoImpl.java
Normal file
194
src/etinyplugins/commons/swt/UndoRedoImpl.java
Normal file
@ -0,0 +1,194 @@
|
||||
package etinyplugins.commons.swt;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.ExtendedModifyEvent;
|
||||
import org.eclipse.swt.custom.ExtendedModifyListener;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.KeyListener;
|
||||
|
||||
/**
|
||||
* Class copied from http://sourceforge.net/p/etinyplugins/blog/2013/02/add-undoredo-support-to-your-swt-styledtext-s/
|
||||
*
|
||||
* Adds the Undo-Redo functionality (working Ctrl+Z and Ctrl+Y) to an instance
|
||||
* of {@link StyledText}.
|
||||
*
|
||||
* @author Petr Bodnar
|
||||
* @see {@linkplain http
|
||||
* ://www.java2s.com/Code/Java/SWT-JFace-Eclipse/SWTUndoRedo.htm} -
|
||||
* inspiration for this code, though not really functioning - it mainly
|
||||
* shows which listeners to use...
|
||||
* @see {@linkplain http
|
||||
* ://stackoverflow.com/questions/7179464/swt-how-to-recreate
|
||||
* -a-default-context-menu-for-text-fields} -
|
||||
* "SWT's StyledText doesn't support Undo-Redo out-of-the-box"
|
||||
*/
|
||||
public class UndoRedoImpl implements KeyListener, ExtendedModifyListener {
|
||||
|
||||
/**
|
||||
* Encapsulation of the Undo and Redo stack(s).
|
||||
*/
|
||||
private static class UndoRedoStack<T> {
|
||||
|
||||
private Stack<T> undo;
|
||||
private Stack<T> redo;
|
||||
|
||||
public UndoRedoStack() {
|
||||
undo = new Stack<T>();
|
||||
redo = new Stack<T>();
|
||||
}
|
||||
|
||||
public void pushUndo(T delta) {
|
||||
undo.add(delta);
|
||||
}
|
||||
|
||||
public void pushRedo(T delta) {
|
||||
redo.add(delta);
|
||||
}
|
||||
|
||||
public T popUndo() {
|
||||
T res = undo.pop();
|
||||
return res;
|
||||
}
|
||||
|
||||
public T popRedo() {
|
||||
T res = redo.pop();
|
||||
return res;
|
||||
}
|
||||
|
||||
public void clearRedo() {
|
||||
redo.clear();
|
||||
}
|
||||
|
||||
public boolean hasUndo() {
|
||||
return !undo.isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasRedo() {
|
||||
return !redo.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private StyledText editor;
|
||||
|
||||
private UndoRedoStack<ExtendedModifyEvent> stack;
|
||||
|
||||
private boolean isUndo;
|
||||
|
||||
private boolean isRedo;
|
||||
|
||||
/**
|
||||
* Creates a new instance of this class. Automatically starts listening to
|
||||
* corresponding key and modify events coming from the given
|
||||
* <var>editor</var>.
|
||||
*
|
||||
* @param editor
|
||||
* the text field to which the Undo-Redo functionality should be
|
||||
* added
|
||||
*/
|
||||
public UndoRedoImpl(StyledText editor) {
|
||||
editor.addExtendedModifyListener(this);
|
||||
editor.addKeyListener(this);
|
||||
|
||||
this.editor = editor;
|
||||
stack = new UndoRedoStack<ExtendedModifyEvent>();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.
|
||||
* KeyEvent)
|
||||
*/
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// Listen to CTRL+Z for Undo, to CTRL+Y or CTRL+SHIFT+Z for Redo
|
||||
boolean isCtrl = (e.stateMask & SWT.CTRL) > 0;
|
||||
boolean isAlt = (e.stateMask & SWT.ALT) > 0;
|
||||
if (isCtrl && !isAlt) {
|
||||
boolean isShift = (e.stateMask & SWT.SHIFT) > 0;
|
||||
if (!isShift && e.keyCode == 'z') {
|
||||
undo();
|
||||
} else if (!isShift && e.keyCode == 'y' || isShift
|
||||
&& e.keyCode == 'z') {
|
||||
redo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events
|
||||
* .KeyEvent)
|
||||
*/
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a corresponding Undo or Redo step from the given event and pushes
|
||||
* it to the stack. The Redo stack is, logically, emptied if the event comes
|
||||
* from a normal user action.
|
||||
*
|
||||
* @param event
|
||||
* @see org.eclipse.swt.custom.ExtendedModifyListener#modifyText(org.eclipse.
|
||||
* swt.custom.ExtendedModifyEvent)
|
||||
*/
|
||||
@Override
|
||||
public void modifyText(ExtendedModifyEvent event) {
|
||||
if (isUndo) {
|
||||
stack.pushRedo(event);
|
||||
} else { // is Redo or a normal user action
|
||||
stack.pushUndo(event);
|
||||
if (!isRedo) {
|
||||
stack.clearRedo();
|
||||
// TODO Switch to treat consecutive characters as one event?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the Undo action. A new corresponding Redo step is automatically
|
||||
* pushed to the stack.
|
||||
*/
|
||||
private void undo() {
|
||||
if (stack.hasUndo()) {
|
||||
isUndo = true;
|
||||
revertEvent(stack.popUndo());
|
||||
isUndo = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the Redo action. A new corresponding Undo step is automatically
|
||||
* pushed to the stack.
|
||||
*/
|
||||
private void redo() {
|
||||
if (stack.hasRedo()) {
|
||||
isRedo = true;
|
||||
revertEvent(stack.popRedo());
|
||||
isRedo = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts the given modify event, in the way as the Eclipse text editor
|
||||
* does it.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
private void revertEvent(ExtendedModifyEvent event) {
|
||||
editor.replaceTextRange(event.start, event.length, event.replacedText);
|
||||
// (causes the modifyText() listener method to be called)
|
||||
|
||||
editor.setSelectionRange(event.start, event.replacedText.length());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user