Permalink
Browse files

Merge branch 'new_scratchpad' into pu

  • Loading branch information...
2 parents 9151dbb + 46aa898 commit e1a9be1133158411c1ef5506ec567725e078efdb @jakobc jakobc committed Mar 4, 2013
@@ -27,6 +27,7 @@
import com.ericsson.otp.erlang.OtpErlangPid;
import com.ericsson.otp.erlang.OtpErlangString;
import com.ericsson.otp.erlang.OtpErlangTuple;
+import com.google.common.collect.Lists;
public class BackendShell implements IBackendShell {
@@ -221,10 +222,12 @@ public void removeListener(final BackendShellListener listener) {
}
private void notifyListeners() {
+ final List<BackendShellListener> listenersCopy;
synchronized (listeners) {
- for (final BackendShellListener listener : listeners) {
- listener.changed(this);
- }
+ listenersCopy = Lists.newArrayList(listeners);
+ }
+ for (final BackendShellListener listener : listenersCopy) {
+ listener.changed(this);
}
}
@@ -250,4 +253,17 @@ public String getText() {
return res.toString();
}
+ @Override
+ public String[] getLastMessages(final int nMessages) {
+ final List<String> result = Lists.newArrayListWithCapacity(nMessages);
+ synchronized (requests) {
+ final int size = requests.size();
+ final int n = Math.min(nMessages, size);
+ for (int i = size - n; i < size; ++i) {
+ result.add(requests.get(i).getMessage());
+ }
+ }
+ return result.toArray(new String[nMessages]);
+ }
+
}
@@ -351,6 +351,10 @@ public IErlModule findModule(final IFile file) {
@Override
public IErlProject findProject(final IProject project) {
+ try {
+ open(null);
+ } catch (final ErlModelException e) {
+ }
final IErlElement e = findElement(project);
if (e == null) {
return null;
@@ -47,4 +47,6 @@
String getText();
+ public abstract String[] getLastMessages(final int nMessages);
+
}
View
@@ -553,6 +553,11 @@
name="Send to console">
</command>
<command
+ description="Send to console with result"
+ id="org.erlide.ui.actions.sendToConsoleWithResult"
+ name="Send to console">
+ </command>
+ <command
categoryId="org.eclipse.search.ui.category.search"
description="Definitions in Workspace"
id="org.erlide.ui.search.implementors.in.workspace"
@@ -860,6 +865,11 @@
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+Enter"/>
<key
+ commandId="org.erlide.ui.actions.sendToConsoleWithResult"
+ contextId="org.erlide.ui.erlangEditorScope"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+M2+Enter"/>
+ <key
commandId="org.erlide.ui.actions.show.outline"
contextId="org.erlide.ui.erlangEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
@@ -1518,22 +1528,6 @@
</wizard>
</extension>
<extension
- point="org.eclipse.ui.navigator.linkHelper">
- <linkHelper
- class="org.erlide.ui.actions.ErlangLinkHelperAction"
- id="org.erlide.ui.navigator.linkHelper">
- <selectionEnablement>
- <or>
- <adapt
- type="org.eclipse.core.resources.IFile">
- </adapt>
- </or></selectionEnablement>
- <editorInputEnablement>
- <instanceof value="org.eclipse.ui.IFileEditorInput"/>
- </editorInputEnablement>
- </linkHelper>
- </extension>
- <extension
point="org.eclipse.ui.decorators">
<decorator
adaptable="true"
@@ -50,7 +50,6 @@
import org.erlide.ui.console.actions.ConsoleTerminateAction;
import org.erlide.ui.console.actions.ShowStandardOutAction;
import org.erlide.ui.console.actions.ShowWhenContentChangesAction;
-import org.erlide.ui.internal.ErlideUIPlugin;
import org.erlide.ui.util.DisplayUtils;
/**
@@ -123,10 +122,6 @@ public void init(final IPageBookViewPage page, final IConsole console) {
// create handler and submissions for EOF
fEOFHandler = new EOFHandler();
-
- // set global ref, used by the SendToConsole action
- // FIXME global is bad, use project's page (keyed by backend?)
- ErlideUIPlugin.getDefault().setConsolePage((ErlangConsolePage) fPage);
}
@Override
@@ -152,9 +147,6 @@ public void dispose() {
fStdOut = null;
}
fConsole = null;
- if (ErlideUIPlugin.getDefault().getConsolePage() == fPage) {
- ErlideUIPlugin.getDefault().setConsolePage(null);
- }
}
/**
@@ -246,7 +238,6 @@ public void activated() {
fActivatedContext = contextService.activateContext(fContextId);
fActivatedHandler = handlerService.activateHandler(
"org.eclipse.debug.ui.commands.eof", fEOFHandler); //$NON-NLS-1$
- ErlideUIPlugin.getDefault().setConsolePage((ErlangConsolePage) fPage);
}
@Override
@@ -1,6 +1,5 @@
package org.erlide.ui.console;
-import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IProject;
@@ -14,12 +13,16 @@
import org.erlide.util.ErlLogger;
import org.erlide.util.IDisposable;
+import com.google.common.collect.Maps;
+
public class ErlConsoleManager implements IDisposable, IBackendListener {
- private final Map<IBackend, IConsole> consoles;
+ private final Map<IBackend, IErlangConsole> consoles;
+ private final Map<IErlangConsole, IErlangConsolePage> pages;
private final IConsoleManager conMan;
public ErlConsoleManager() {
- consoles = new HashMap<IBackend, IConsole>();
+ consoles = Maps.newHashMap();
+ pages = Maps.newHashMap();
final ConsolePlugin consolePlugin = ConsolePlugin.getDefault();
conMan = consolePlugin.getConsoleManager();
@@ -52,6 +55,23 @@ public void runtimeRemoved(final IBackend b) {
conMan.removeConsoles(new IConsole[] { console });
}
+ public void addPage(final IErlangConsole console,
+ final IErlangConsolePage page) {
+ pages.put(console, page);
+ }
+
+ public void removePage(final IErlangConsole console) {
+ pages.remove(console);
+ }
+
+ public IErlangConsolePage getPage(final IErlangConsole console) {
+ return pages.get(console);
+ }
+
+ public IErlangConsole getConsole(final IBackend backend) {
+ return consoles.get(backend);
+ }
+
@Override
public void dispose() {
BackendCore.getBackendManager().removeBackendListener(this);
@@ -13,18 +13,15 @@
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.IConsoleDocumentPartitioner;
import org.eclipse.ui.console.IConsoleView;
import org.eclipse.ui.console.TextConsole;
import org.eclipse.ui.part.IPageBookViewPage;
import org.erlide.backend.IBackend;
import org.erlide.runtime.shell.IBackendShell;
+import org.erlide.ui.internal.ErlideUIPlugin;
-public class ErlangConsole extends TextConsole {
+public class ErlangConsole extends TextConsole implements IErlangConsole {
private final IBackendShell shell;
protected ListenerList consoleListeners;
protected ErlangConsolePartitioner partitioner;
@@ -45,13 +42,19 @@ public ErlangConsole(final IBackend backend) {
@Override
public IPageBookViewPage createPage(final IConsoleView view) {
- return new ErlangConsolePage(view, this, backend.getRpcSite());
+ final ErlangConsolePage erlangConsolePage = new ErlangConsolePage(view,
+ this, backend.getRpcSite());
+ ErlideUIPlugin.getDefault().getErlConsoleManager()
+ .addPage(this, erlangConsolePage);
+ return erlangConsolePage;
}
+ @Override
public IBackend getBackend() {
return backend;
}
+ @Override
public IBackendShell getShell() {
return shell;
}
@@ -80,18 +83,18 @@ public void removePropertyChangeListener(
final IPropertyChangeListener listener) {
}
- public void show() {
- final IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- final String id = IConsoleConstants.ID_CONSOLE_VIEW;
- IConsoleView view;
- try {
- view = (IConsoleView) page.showView(id);
- view.display(this);
- } catch (final PartInitException e) {
- e.printStackTrace();
- }
- }
+ // public void show() {
+ // final IWorkbenchPage page = PlatformUI.getWorkbench()
+ // .getActiveWorkbenchWindow().getActivePage();
+ // final String id = IConsoleConstants.ID_CONSOLE_VIEW;
+ // IConsoleView view;
+ // try {
+ // view = (IConsoleView) page.showView(id);
+ // view.display(this);
+ // } catch (final PartInitException e) {
+ // e.printStackTrace();
+ // }
+ // }
@Override
protected IConsoleDocumentPartitioner getPartitioner() {
@@ -75,13 +75,14 @@
import org.erlide.runtime.ParserException;
import org.erlide.runtime.RuntimeHelper;
import org.erlide.runtime.shell.IBackendShell;
+import org.erlide.ui.internal.ErlideUIPlugin;
import com.ericsson.otp.erlang.OtpErlangList;
import com.ericsson.otp.erlang.OtpErlangObject;
@SuppressWarnings("restriction")
public class ErlangConsolePage extends Page implements IAdaptable,
- IPropertyChangeListener {
+ IPropertyChangeListener, IErlangConsolePage {
public static final String ID = "org.erlide.ui.views.console";
Color bgColor_Ok;
@@ -141,6 +142,7 @@ public void dispose() {
bgColor_Err.dispose();
bgColor_Ok.dispose();
}
+ ErlideUIPlugin.getDefault().getErlConsoleManager().removePage(fConsole);
super.dispose();
}
@@ -167,6 +169,7 @@ protected void sendInput() {
consoleInput.setText("");
}
+ @Override
public void input(final String data) {
final String data2 = data.trim() + "\n";
shell.input(data2);
@@ -315,7 +318,7 @@ public void documentChanged(final DocumentEvent event) {
consoleOutputViewer.revealRange(end, 0);
}
};
- fDoc.addDocumentListener(documentListener);
+ addDocumentListener(documentListener);
final String id = "#ContextMenu"; //$NON-NLS-1$
// if (getConsole().getType() != null) {
@@ -524,4 +527,16 @@ protected void updateAction(final String actionId) {
((IUpdate) action).update();
}
}
+
+ public void addDocumentListener(final IDocumentListener documentListener) {
+ fDoc.addDocumentListener(documentListener);
+ }
+
+ public void removeDocumentListener(final IDocumentListener documentListener) {
+ fDoc.removeDocumentListener(documentListener);
+ }
+
+ public IBackendShell getShell() {
+ return shell;
+ }
}
@@ -0,0 +1,13 @@
+package org.erlide.ui.console;
+
+import org.eclipse.ui.console.IConsole;
+import org.erlide.backend.IBackend;
+import org.erlide.runtime.shell.IBackendShell;
+
+public interface IErlangConsole extends IConsole {
+
+ public abstract IBackendShell getShell();
+
+ public abstract IBackend getBackend();
+
+}
@@ -0,0 +1,7 @@
+package org.erlide.ui.console;
+
+public interface IErlangConsolePage {
+
+ public abstract void input(final String data);
+
+}
Oops, something went wrong.

0 comments on commit e1a9be1

Please sign in to comment.