diff options
author | Michael Valenta | 2002-05-10 21:13:00 +0000 |
---|---|---|
committer | Michael Valenta | 2002-05-10 21:13:00 +0000 |
commit | 7ee91957bc30af6ee11335742172498a3aa8a82a (patch) | |
tree | 57eed3adc3a2735098ee79170fe3bf4412c4a283 /bundles | |
parent | 31b2f42e5c23ee0e27e5d27d9eea3327f9ad7991 (diff) | |
download | eclipse.platform.team-7ee91957bc30af6ee11335742172498a3aa8a82a.tar.gz eclipse.platform.team-7ee91957bc30af6ee11335742172498a3aa8a82a.tar.xz eclipse.platform.team-7ee91957bc30af6ee11335742172498a3aa8a82a.zip |
Updated console to remember the output of the last few commands
even if no console window is open
Diffstat (limited to 'bundles')
-rw-r--r-- | bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java | 6 | ||||
-rw-r--r-- | bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleDocument.java | 50 |
2 files changed, 50 insertions, 6 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java index fdd9f81bc..4e5a7bcc8 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java @@ -115,7 +115,7 @@ public class Console extends ViewPart { propertyChangeListener = null; } instances.remove(this); - if (instances.isEmpty()) document.clear(); + //if (instances.isEmpty()) document.clear(); // dispose of allocated colors and fonts super.dispose(); @@ -350,8 +350,8 @@ public class Console extends ViewPart { if (getPreferenceStore().getBoolean(ICVSUIConstants.PREF_CONSOLE_AUTO_OPEN)) { findInActivePerspective(); } - if (instances.isEmpty() || document == null) return; - document.appendConsoleLine(type, line); + if (document == null) return; + document.appendConsoleLine(type, line, instances.isEmpty()); } }); } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleDocument.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleDocument.java index c4a6820ce..48c40882a 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleDocument.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleDocument.java @@ -10,15 +10,18 @@ ******************************************************************************/ package org.eclipse.team.internal.ccvs.ui; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.text.AbstractDocument; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DefaultLineTracker; import org.eclipse.jface.text.GapTextStore; -import org.eclipse.swt.widgets.Display; import org.eclipse.team.internal.ccvs.core.CVSException; import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener; +import org.eclipse.team.internal.ccvs.core.CVSStatus; public class ConsoleDocument extends AbstractDocument { public static final int COMMAND = 0; // command text @@ -64,7 +67,7 @@ public class ConsoleDocument extends AbstractDocument { /** * Appends a line of the specified type to the end of the console. */ - public void appendConsoleLine(int type, String line) { + public void appendConsoleLine(int type, String line, boolean purgeExcess) { if (lineTypes == null) { lineTypes = new int[16]; } else if (currentLine >= lineTypes.length) { @@ -75,8 +78,49 @@ public class ConsoleDocument extends AbstractDocument { lineTypes[currentLine++] = type; try { replace(getLength(), 0, line + "\n"); //$NON-NLS-1$ + if (purgeExcess && type == COMMAND) { + keepPreviousCommands(2); + } } catch (BadLocationException e) { CVSProviderPlugin.log(CVSException.wrapException(e)); } } + + /** + * Return the indicies of the lines that contain command strings + */ + private int[] getCommandLines() { + List commandLineList = new ArrayList(); + for (int i = 0; i < currentLine; i++) { + if (lineTypes[i] == COMMAND) { + commandLineList.add(new Integer(i)); + } + } + int[] commandLines = new int[commandLineList.size()]; + int i = 0; + for (Iterator iter = commandLineList.iterator(); iter.hasNext(); ) { + commandLines[i++] = ((Integer) iter.next()).intValue(); + } + return commandLines; + } + + /** + * Purge all but the output of the last N commands from the document + */ + private void keepPreviousCommands(int number) throws BadLocationException{ + // Get the index of the line and character to keep + int[] commandLines = getCommandLines(); + if (commandLines.length <= number) return; + int lineIndex = commandLines[commandLines.length - number]; + int characterIndex = getLineOffset(lineIndex); + + // Keep everything from the character to the end + set(get(characterIndex, getLength() - characterIndex)); + + // Adjust the line types + int[] oldLineTypes = lineTypes; + lineTypes = new int[oldLineTypes.length]; + System.arraycopy(oldLineTypes, lineIndex, lineTypes, 0, oldLineTypes.length - lineIndex); + currentLine -= lineIndex; + } } |