* updates
diff --git a/core/plugins/org.eclipse.dltk.console.ui/icons/elcl16/terminate.gif b/core/plugins/org.eclipse.dltk.console.ui/icons/elcl16/terminate.gif
index dc47edf..2cd9c54 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/icons/elcl16/terminate.gif
+++ b/core/plugins/org.eclipse.dltk.console.ui/icons/elcl16/terminate.gif
Binary files differ
diff --git a/core/plugins/org.eclipse.dltk.console.ui/plugin.xml b/core/plugins/org.eclipse.dltk.console.ui/plugin.xml
index 4df7612..2190266 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/plugin.xml
+++ b/core/plugins/org.eclipse.dltk.console.ui/plugin.xml
@@ -7,7 +7,7 @@
<consolePatternMatchListener
class="org.eclipse.dltk.console.ui.internal.HTTPConsolePatternMatcher"
id="org.eclipse.dltk.console.ui.hyperlinkConsolePatternMatcher"
- regex="http://([^ \\]|\\ |\\\\|\\)+">
+ regex="http://([^\s\\]|\\ |\\\\|\\)+">
<enablement>
<or>
<test
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/DLTKConsolePropertyTester.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/DLTKConsolePropertyTester.java
index ff7e18b..a1d29d2 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/DLTKConsolePropertyTester.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/DLTKConsolePropertyTester.java
@@ -13,7 +13,7 @@
public class DLTKConsolePropertyTester extends PropertyTester {
- private static final String IS_DLTK_CONSOLE_PROPERTY = "isDLTKConsole";
+ private static final String IS_DLTK_CONSOLE_PROPERTY = "isDLTKConsole"; //$NON-NLS-1$
public DLTKConsolePropertyTester() {
}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/IConsoleStyleProvider.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/IConsoleStyleProvider.java
index dd0fd76..afac60e 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/IConsoleStyleProvider.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/IConsoleStyleProvider.java
@@ -5,10 +5,10 @@
public interface IConsoleStyleProvider {
- StyleRange createPromptStyle (ScriptConsolePrompt prompt, int offset);
-
- StyleRange createUserInputStyle (String content, int offset);
-
- StyleRange createInterpreterOutputStyle (String content, int offset);
-
+ StyleRange[] createPromptStyle(ScriptConsolePrompt prompt, int offset);
+
+ StyleRange[] createUserInputStyle(String content, int offset);
+
+ StyleRange[] createInterpreterOutputStyle(String content, int offset);
+
}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsole.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsole.java
index 0e24975..4c28685 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsole.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsole.java
@@ -10,6 +10,9 @@
package org.eclipse.dltk.console.ui;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.dltk.console.IScriptInterpreter;
@@ -19,9 +22,16 @@
import org.eclipse.dltk.console.ui.internal.ScriptConsoleInput;
import org.eclipse.dltk.console.ui.internal.ScriptConsolePage;
import org.eclipse.dltk.console.ui.internal.ScriptConsoleSession;
+import org.eclipse.dltk.console.ui.internal.ScriptConsoleViewer.ConsoleDocumentListener;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.console.IConsoleDocumentPartitioner;
import org.eclipse.ui.console.IConsoleView;
import org.eclipse.ui.console.TextConsole;
@@ -49,12 +59,18 @@
private IConsoleStyleProvider styleProvider;
+ private Color colorBlack = new Color(Display.getCurrent(), new RGB(0, 0, 0));
+ private Color colorBlue = new Color(Display.getCurrent(),
+ new RGB(0, 0, 255));
+ private Color colorRed = new Color(Display.getCurrent(), new RGB(255, 0, 0));
+
protected IConsoleDocumentPartitioner getPartitioner() {
return partitioner;
}
- public ScriptConsole(String consoleName, String consoleType) {
- super(consoleName, consoleType, null, true);
+ public ScriptConsole(String consoleName, String consoleType,
+ ImageDescriptor image) {
+ super(consoleName, consoleType, image, true);
this.consoleListeners = new ListenerList(ListenerList.IDENTITY);
this.prompt = new ScriptConsolePrompt("=>", "->"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -66,6 +82,63 @@
partitioner = new ScriptConsolePartitioner();
getDocument().setDocumentPartitioner(partitioner);
partitioner.connect(getDocument());
+
+ styleProvider = new IConsoleStyleProvider() {
+
+ protected StyleRange[] createStyles(int start, String content,
+ boolean isInput, boolean isError) {
+ List rangeList = new ArrayList();
+ if ((colorBlack.isDisposed() != true)
+ && (colorRed.isDisposed() != true)
+ && (colorBlue.isDisposed() != true)) {
+ // Content has to be tokenized in order for style and
+ // hyperlinks to display correctly
+ StringTokenizer tokenizer = new StringTokenizer(content,
+ " \t\n\r\f@#=|,()[]{}<>'\"", true); //$NON-NLS-1$
+ String token;
+ int tokenStart = start;
+ while (tokenizer.hasMoreTokens() == true) {
+ token = tokenizer.nextToken();
+
+ if (isInput == true) {
+ rangeList.add(new StyleRange(tokenStart, token
+ .length(), colorBlack, null, SWT.BOLD));
+ } else {
+ if (isError == true) {
+ rangeList.add(new StyleRange(tokenStart, token
+ .length(), colorRed, null, SWT.BOLD));
+ } else {
+ rangeList.add(new StyleRange(tokenStart, token
+ .length(), colorBlue, null));
+ }
+ }
+
+ tokenStart += token.length();
+ }
+ }
+ return (StyleRange[]) rangeList
+ .toArray(new StyleRange[rangeList.size()]);
+ }
+
+ public StyleRange[] createPromptStyle(ScriptConsolePrompt prompt,
+ int offset) {
+ return createStyles(offset, prompt.toString(), true, false);
+ }
+
+ public StyleRange[] createUserInputStyle(String content, int offset) {
+ return createStyles(offset, content, true, false);
+ }
+
+ public StyleRange[] createInterpreterOutputStyle(String content,
+ int offset) {
+ return createStyles(offset, content, false, false);
+ }
+
+ };
+ }
+
+ public ScriptConsole(String consoleName, String consoleType) {
+ this(consoleName, consoleType, null);
}
public IScriptConsoleSession getSession() {
@@ -86,19 +159,19 @@
protected void setInterpreter(IScriptInterpreter interpreter) {
this.interpreter = interpreter;
-// interpreter.addInitialListenerOperation(new Runnable() {
-// public void run() {
-// Object[] listeners = consoleListeners.getListeners();
-// String output = ScriptConsole.this.interpreter
-// .getInitialOuput();
-// if (output != null) {
-// for (int i = 0; i < listeners.length; i++) {
-// ((IScriptConsoleListener) listeners[i])
-// .interpreterResponse(output);
-// }
-// }
-// }
-// });
+ // interpreter.addInitialListenerOperation(new Runnable() {
+ // public void run() {
+ // Object[] listeners = consoleListeners.getListeners();
+ // String output = ScriptConsole.this.interpreter
+ // .getInitialOuput();
+ // if (output != null) {
+ // for (int i = 0; i < listeners.length; i++) {
+ // ((IScriptConsoleListener) listeners[i])
+ // .interpreterResponse(output);
+ // }
+ // }
+ // }
+ // });
}
protected void setStyleProvider(IConsoleStyleProvider provider) {
@@ -121,6 +194,19 @@
this.hover = hover;
}
+ private ConsoleDocumentListener documentListener;
+
+ public ConsoleDocumentListener getDocumentListener() {
+ if (documentListener == null) {
+ documentListener = new ConsoleDocumentListener(this, this
+ .getPrompt(), this.getHistory());
+ documentListener.setDocument(getDocument());
+
+ }
+
+ return documentListener;
+ }
+
public IPageBookViewPage createPage(IConsoleView view) {
SourceViewerConfiguration cfg = new ScriptConsoleSourceViewerConfiguration(
processor, hover);
@@ -168,4 +254,17 @@
e.printStackTrace();
}
}
+
+ public void dispose() {
+ partitioner.clearRanges();
+
+ colorBlack.dispose();
+ colorBlue.dispose();
+ colorRed.dispose();
+
+ terminate();
+
+ super.dispose();
+ }
+
}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java
index 539de65..f57b5e2 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java
@@ -10,6 +10,7 @@
package org.eclipse.dltk.console.ui;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -23,17 +24,17 @@
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.ui.console.IConsoleDocumentPartitioner;
-public class ScriptConsolePartitioner extends FastPartitioner
- implements IConsoleDocumentPartitioner {
-
- private List ranges = new ArrayList ();
-
+public class ScriptConsolePartitioner extends FastPartitioner implements
+ IConsoleDocumentPartitioner {
+
+ private List ranges = new ArrayList();
+
private static class Constants {
public static final String MY_DOUBLE_QUOTED = "__my_double"; //$NON-NLS-1$
public static final String MY_SINGLE_QUOTED = "__my_single"; //$NON-NLS-1$
}
-
+
private static class MyPartitionScanner extends RuleBasedPartitionScanner {
public MyPartitionScanner() {
IToken myDouble = new Token(Constants.MY_DOUBLE_QUOTED);
@@ -50,57 +51,38 @@
setPredicateRules(result);
}
}
-
+
public ScriptConsolePartitioner() {
-
+
super(new MyPartitionScanner(), new String[] {
- Constants.MY_DOUBLE_QUOTED, Constants.MY_SINGLE_QUOTED });
+ Constants.MY_DOUBLE_QUOTED, Constants.MY_SINGLE_QUOTED });
}
-
- public void addRange (StyleRange r) {
- ranges.add (r);
+
+ public void addRange(StyleRange r) {
+ ranges.add(r);
+ }
+
+ public void addRanges(StyleRange[] r) {
+ ranges.addAll(Arrays.asList(r));
+ }
+
+ public void clearRanges() {
+ ranges.clear();
}
public StyleRange[] getStyleRanges(int offset, int length) {
-// int i = offset;
-//
-// int last = offset + length;
-//
-// List list = new ArrayList();
-// while (i < last) {
-// ITypedRegion region = getPartition(i);
-//
-// String type = region.getType();
-//
-// int off = region.getOffset();
-// int len = region.getLength();
-//
-// Color color = null;
-// if (type.equals(Constants.MY_DOUBLE_QUOTED)) {
-// color = new Color(null, 255, 0, 0);
-// }
-//
-// if (type.equals(Constants.MY_SINGLE_QUOTED)) {
-// color = new Color(null, 0, 255, 255);
-// }
-//
-// list.add(new StyleRange(off, len, color, null, SWT.ITALIC));
-//
-// i = off + len;
-// }
-//
-// return (StyleRange[]) list.toArray(new StyleRange[list.size()]);
- List result = new ArrayList ();
+ List result = new ArrayList();
for (Iterator iterator = ranges.iterator(); iterator.hasNext();) {
StyleRange r = (StyleRange) iterator.next();
if (r.start >= offset && r.start + r.length <= offset + length)
- result.add(r);
+ result.add((StyleRange) r.clone());
}
-
+
if (result.size() > 0)
- return (StyleRange[]) result.toArray(new StyleRange[result.size()]);
-
- return new StyleRange[]{new StyleRange(offset, length, null, null, SWT.NO)};
+ return (StyleRange[]) result.toArray(new StyleRange[result.size()]);
+
+ return new StyleRange[] { new StyleRange(offset, length, null, null,
+ SWT.NO) };
}
public boolean isReadOnly(int offset) {
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/HTTPConsoleHyperlink.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/HTTPConsoleHyperlink.java
index 652dfb7..5b23170 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/HTTPConsoleHyperlink.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/HTTPConsoleHyperlink.java
@@ -11,6 +11,7 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.text.MessageFormat;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -52,12 +53,12 @@
} catch (PartInitException e) {
IStatus status = new Status(IStatus.ERROR,
DLTKLaunchingPlugin.PLUGIN_ID,
- "Failed to open browser part for:" + uri, e);
+ MessageFormat.format(Messages.HTTPConsoleHyperlink_failedToInitializeBrowserFor, new Object[] { uri }), e);
DLTKLaunchingPlugin.getDefault().getLog().log(status);
} catch (MalformedURLException e) {
IStatus status = new Status(IStatus.ERROR,
DLTKLaunchingPlugin.PLUGIN_ID,
- "Failed to execute browser: Incorrect URI:" + uri, e);
+ MessageFormat.format(Messages.HTTPConsoleHyperlink_failedToOpenInvalidUri, new Object[] { uri }), e);
DLTKLaunchingPlugin.getDefault().getLog().log(status);
}
}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/Messages.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/Messages.java
new file mode 100644
index 0000000..07b2bff
--- /dev/null
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/Messages.java
@@ -0,0 +1,16 @@
+package org.eclipse.dltk.console.ui.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.dltk.console.ui.internal.messages"; //$NON-NLS-1$
+ public static String HTTPConsoleHyperlink_failedToInitializeBrowserFor;
+ public static String HTTPConsoleHyperlink_failedToOpenInvalidUri;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsolePage.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsolePage.java
index 65684b1..31f0ab3 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsolePage.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsolePage.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.dltk.console.ui.internal;
+import org.eclipse.core.commands.IHandler;
import org.eclipse.dltk.console.ScriptConsoleConstants;
import org.eclipse.dltk.console.ui.IConsoleStyleProvider;
import org.eclipse.dltk.console.ui.ScriptConsole;
@@ -17,6 +18,7 @@
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
@@ -27,7 +29,8 @@
import org.eclipse.ui.console.TextConsolePage;
import org.eclipse.ui.console.TextConsoleViewer;
import org.eclipse.ui.console.actions.TextViewerAction;
-
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
public class ScriptConsolePage extends TextConsolePage implements
IScriptConsoleContentHandler {
@@ -50,6 +53,7 @@
private ScriptConsoleViewer viewer;
private TextViewerAction proposalsAction;
+ private IHandler proposalsHandler;
private IConsoleStyleProvider styleProvider;
@@ -57,7 +61,14 @@
super.createActions();
proposalsAction = new ContentAssistProposalsAction(getViewer());
- proposalsAction = new ContentAssistProposalsAction(getViewer());
+ proposalsAction
+ .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
+ IHandlerService handlerService = (IHandlerService) getSite()
+ .getService(IHandlerService.class);
+ proposalsHandler = new ActionHandler(proposalsAction);
+ handlerService.activateHandler(
+ ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS,
+ proposalsHandler);
SaveConsoleSessionAction saveSessionAction = new SaveConsoleSessionAction(
(ScriptConsole) getConsole(),
@@ -80,7 +91,7 @@
toolbarManager.appendToGroup(ScriptConsoleConstants.SCRIPT_GROUP,
closeConsoleAction);
-
+
toolbarManager.appendToGroup(ScriptConsoleConstants.SCRIPT_GROUP,
saveSessionAction);
@@ -90,7 +101,7 @@
protected TextConsoleViewer createViewer(Composite parent) {
viewer = new ScriptConsoleViewer(parent, (ScriptConsole) getConsole(),
this, styleProvider);
- viewer.configure(cfg);
+ viewer.configure(cfg);
return viewer;
}
@@ -116,4 +127,11 @@
public void setStyleProviser(IConsoleStyleProvider provider) {
this.styleProvider = provider;
}
+
+ public void dispose() {
+ proposalsHandler.dispose();
+
+ super.dispose();
+ }
+
}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsoleViewer.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsoleViewer.java
index 20ece78..1d4ff64 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsoleViewer.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ScriptConsoleViewer.java
@@ -10,6 +10,9 @@
package org.eclipse.dltk.console.ui.internal;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import org.eclipse.dltk.console.ScriptConsoleHistory;
import org.eclipse.dltk.console.ScriptConsolePrompt;
@@ -39,7 +42,7 @@
public class ScriptConsoleViewer extends TextConsoleViewer implements
IScriptConsoleViewer {
- private static class ConsoleDocumentListener implements IDocumentListener {
+ public static class ConsoleDocumentListener implements IDocumentListener {
private ICommandHandler handler;
@@ -51,6 +54,12 @@
private IDocument doc;
+ private List viewerList = new ArrayList();
+
+ private void addViewer(ScriptConsoleViewer viewer) {
+ viewerList.add(viewer);
+ }
+
protected void connectListener() {
doc.addDocumentListener(this);
}
@@ -64,24 +73,22 @@
disconnectListener();
doc.set(""); //$NON-NLS-1$
appendInvitation();
- viewer.setCaretPosition(doc.getLength());
+ for (Iterator iter = viewerList.iterator(); iter.hasNext();) {
+ ((ScriptConsoleViewer) iter.next()).setCaretPosition(doc
+ .getLength());
+ }
connectListener();
} catch (BadLocationException e) {
e.printStackTrace();
}
}
- private ScriptConsoleViewer viewer;
-
- public ConsoleDocumentListener(ScriptConsoleViewer viewer,
- ICommandHandler handler, ScriptConsolePrompt prompt,
- ScriptConsoleHistory history) {
+ public ConsoleDocumentListener(ICommandHandler handler,
+ ScriptConsolePrompt prompt, ScriptConsoleHistory history) {
this.prompt = prompt;
this.handler = handler;
this.history = history;
- this.viewer = viewer;
-
this.offset = 0;
this.doc = null;
@@ -118,25 +125,33 @@
throws BadLocationException {
if (result != null) {
int start = appendText(result);
-
- if (viewer.styleProvider != null) {
- StyleRange style = viewer.styleProvider.createInterpreterOutputStyle(result, start);
- if (style != null) {
- addToPartitioner(style);
+ ScriptConsoleViewer viewer;
+
+ for (Iterator iter = viewerList.iterator(); iter.hasNext();) {
+ viewer = (ScriptConsoleViewer) iter.next();
+ if (viewer.styleProvider != null) {
+ StyleRange[] styles = viewer.styleProvider
+ .createInterpreterOutputStyle(result, start);
+ if ((styles != null) && (styles.length > 0)) {
+ addToPartitioner(viewer, styles);
+ }
}
}
-
+
history.commit();
offset = getLastLineLength();
}
appendInvitation();
}
-
- private void addToPartitioner (StyleRange style) {
- IDocumentPartitioner partitioner = viewer.getDocument().getDocumentPartitioner();
+
+ private void addToPartitioner(ScriptConsoleViewer viewer,
+ StyleRange[] styles) {
+ IDocumentPartitioner partitioner = viewer.getDocument()
+ .getDocumentPartitioner();
if (partitioner instanceof ScriptConsolePartitioner) {
- ScriptConsolePartitioner scriptConsolePartitioner = (ScriptConsolePartitioner) partitioner;
- scriptConsolePartitioner.addRange(style);
+ ScriptConsolePartitioner scriptConsolePartitioner = (ScriptConsolePartitioner) partitioner;
+ scriptConsolePartitioner.addRanges(styles);
+ viewer.getTextWidget().redraw();
}
}
@@ -154,30 +169,27 @@
int index = -1;
while ((index = text.indexOf(delim, start)) != -1) {
String cmd = text.substring(start, index);
- int offset2 = appendText(cmd);
-
- if (viewer.styleProvider != null) {
- StyleRange style = viewer.styleProvider.createUserInputStyle(cmd, offset2);
- if (style != null) {
- addToPartitioner(style);
+ appendText(cmd);
+ ScriptConsoleViewer viewer;
+
+ for (Iterator iter = viewerList.iterator(); iter.hasNext();) {
+ viewer = (ScriptConsoleViewer) iter.next();
+ if (viewer.styleProvider != null) {
+ StyleRange[] styles = viewer.styleProvider
+ .createUserInputStyle(getCommandLine(),
+ getCommandLineOffset());
+ if ((styles != null) && (styles.length > 0)) {
+ addToPartitioner(viewer, styles);
+ }
}
}
-
+
history.update(getCommandLine());
start = index + delim.length();
handleCommandLine();
}
- String cmd = text.substring(start, text.length());
- int offset2 = appendText(cmd);
-
- if (viewer.styleProvider != null) {
- StyleRange style = viewer.styleProvider.createUserInputStyle(cmd, offset2);
- if (style != null) {
- addToPartitioner(style);
- }
- }
-
+ appendText(text.substring(start, text.length()));
history.update(getCommandLine());
} catch (BadLocationException e) {
e.printStackTrace();
@@ -201,12 +213,18 @@
protected void appendInvitation() throws BadLocationException {
int start = doc.getLength();
appendText(prompt.toString());
- viewer.setCaretPosition(doc.getLength());
- viewer.revealEndOfDocument();
- if (viewer.styleProvider != null) {
- StyleRange style = viewer.styleProvider.createPromptStyle(prompt, start);
- if (style != null) {
- addToPartitioner(style);
+ ScriptConsoleViewer viewer;
+
+ for (Iterator iter = viewerList.iterator(); iter.hasNext();) {
+ viewer = (ScriptConsoleViewer) iter.next();
+ viewer.setCaretPosition(doc.getLength());
+ viewer.revealEndOfDocument();
+ if (viewer.styleProvider != null) {
+ StyleRange[] styles = viewer.styleProvider
+ .createPromptStyle(prompt, start);
+ if ((styles != null) && (styles.length > 0)) {
+ addToPartitioner(viewer, styles);
+ }
}
}
}
@@ -261,13 +279,15 @@
switch (action) {
case ST.LINE_UP:
history.prev();
- listener.setCommandLine(history.get());
+ console.getDocumentListener().setCommandLine(
+ history.get());
setCaretOffset(getDocument().getLength());
return;
case ST.LINE_DOWN:
history.next();
- listener.setCommandLine(history.get());
+ console.getDocumentListener().setCommandLine(
+ history.get());
setCaretOffset(getDocument().getLength());
return;
@@ -313,7 +333,7 @@
private ScriptConsoleHistory history;
- private ConsoleDocumentListener listener;
+ private ScriptConsole console;
private IConsoleStyleProvider styleProvider;
@@ -351,17 +371,17 @@
return new ScriptCnosoleStyledText(parent, styles);
}
- public ScriptConsoleViewer(Composite parent, ScriptConsole console,
- final IScriptConsoleContentHandler contentHandler, IConsoleStyleProvider styleProvider) {
+ public ScriptConsoleViewer(Composite parent, final ScriptConsole console,
+ final IScriptConsoleContentHandler contentHandler,
+ IConsoleStyleProvider styleProvider) {
super(parent, console);
-
+
+ this.console = console;
this.styleProvider = styleProvider;
this.history = console.getHistory();
- this.listener = new ConsoleDocumentListener(this, console, console
- .getPrompt(), console.getHistory());
- this.listener.setDocument(getDocument());
+ console.getDocumentListener().addViewer(this);
final StyledText styledText = getTextWidget();
@@ -385,12 +405,28 @@
try {
if (event.character != '\0') {
// Printable character
- if (!isCaretOnLastLine()) {
- event.doit = false;
- return;
+ // ssanders: Ensure selection is on last line
+ ConsoleDocumentListener listener = console
+ .getDocumentListener();
+ int selStart = getSelectedRange().x;
+ int selEnd = (getSelectedRange().x + getSelectedRange().y);
+ int clOffset = listener.getCommandLineOffset();
+ int clLength = listener.getCommandLineLength();
+ if (selStart < clOffset) {
+ int selLength;
+
+ if (selEnd < clOffset) {
+ selStart = (clOffset + clLength);
+ selLength = 0;
+ } else {
+ selStart = clOffset;
+ selLength = (selEnd - selStart);
+ }
+
+ setSelectedRange(selStart, selLength);
}
- if (beginLineOffset() < listener
+ if (beginLineOffset() < console.getDocumentListener()
.getLastLineReadOnlySize()) {
event.doit = false;
return;
@@ -419,13 +455,9 @@
styledText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
- // if (e.keyCode == 32 && (e.stateMask & SWT.CTRL) > 0) {
- if ((e.keyCode == 32 && (e.stateMask & SWT.CTRL) > 0)
- || (e.keyCode == 9)) {
- // System.out.println(".keyPressed()");
+ if (e.keyCode == 9) {
contentHandler.contentAssistRequired();
}
-
}
public void keyReleased(KeyEvent e) {
@@ -438,7 +470,7 @@
// IConsoleTextViewer
public String getCommandLine() {
try {
- return listener.getCommandLine();
+ return console.getDocumentListener().getCommandLine();
} catch (BadLocationException e) {
return null;
}
@@ -446,39 +478,40 @@
public int getCommandLineOffset() {
try {
- return listener.getCommandLineOffset();
+ return console.getDocumentListener().getCommandLineOffset();
} catch (BadLocationException e) {
return -1;
}
}
public void clear() {
- listener.clear();
+ console.getDocumentListener().clear();
}
public void insertText(String text) {
getTextWidget().append(text);
}
+
public boolean canDoOperation(int operation) {
- boolean canDoOperation = super.canDoOperation(operation);
+ boolean canDoOperation = super.canDoOperation(operation);
- if (canDoOperation) {
- switch (operation) {
- case CUT:
- case DELETE:
- case PASTE:
- case SHIFT_LEFT:
- case SHIFT_RIGHT:
- case PREFIX:
- case STRIP_PREFIX:
- canDoOperation = isCaretOnLastLine();
- }
- }
+ if (canDoOperation) {
+ switch (operation) {
+ case CUT:
+ case DELETE:
+ case PASTE:
+ case SHIFT_LEFT:
+ case SHIFT_RIGHT:
+ case PREFIX:
+ case STRIP_PREFIX:
+ canDoOperation = isCaretOnLastLine();
+ }
+ }
- return canDoOperation;
- }
+ return canDoOperation;
+ }
public void setStyleProvider(IConsoleStyleProvider provider) {
- this.styleProvider = provider;
+ this.styleProvider = provider;
}
}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/messages.properties b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/messages.properties
new file mode 100644
index 0000000..2ed42b1
--- /dev/null
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/messages.properties
@@ -0,0 +1,2 @@
+HTTPConsoleHyperlink_failedToInitializeBrowserFor=Failed to initialize browser for: {0}
+HTTPConsoleHyperlink_failedToOpenInvalidUri=Failed to open invalid URI: {0}