The Line.show()
method accepts show mode constant,
+ that influences the way the Line is displayed on the request.
+ This additional constant provides a new mode for opening the line
+ in a shared editor window that can be replaced by subsequent calls of
+ Line.show(SHOW_REUSE)
on Line
s from different
+ Document
. This is useful for quick source browsing without
+ cluttering the UI with too many opened editors.
+
show
+ */
+ public final static int SHOW_REUSE = 4;
+
/** Instance of null implementation of Line.Part */
static final private Line.Part nullPart = new Line.NullPart();
@@ -151,7 +160,8 @@
public abstract void show(int kind, int column);
/** Shows the line (at the first column).
- * @param kind one of {@link #SHOW_TRY_SHOW}, {@link #SHOW_SHOW}, or {@link #SHOW_GOTO}
+ * @param kind one of {@link #SHOW_TRY_SHOW}, {@link #SHOW_SHOW}, {@link #SHOW_GOTO},
+ * or {@link #SHOW_REUSE}
* @see #show(int, int)
*/
public void show(int kind) {
Index: src/org/openide/text/EditorSupportLineSet.java
===================================================================
RCS file: /shared/data/ccvs/repository/openide/text/src/org/openide/text/EditorSupportLineSet.java,v
retrieving revision 1.3
diff -u -r1.3 EditorSupportLineSet.java
--- src/org/openide/text/EditorSupportLineSet.java 23 Nov 2006 05:26:45 -0000 1.3
+++ src/org/openide/text/EditorSupportLineSet.java 7 Feb 2007 14:26:16 -0000
@@ -81,14 +81,15 @@
return;
}
- CloneableEditorSupport.Pane editor = support.openAt(pos, column);
-
- if (kind == SHOW_GOTO) {
- editor.getComponent().requestActive();
- } else if (kind == SHOW_TOFRONT) {
- editor.getComponent().toFront();
- editor.getComponent().requestActive();
+ CloneableEditorSupport.Pane editor;
+
+ if (kind == SHOW_REUSE) {
+ editor = support.openReuse(pos, column);
+ } else {
+ editor = support.openAt(pos, column);
+ if (kind == SHOW_TOFRONT) editor.getComponent().toFront();
}
+ editor.getComponent().requestActive();
}
/** This method will be used for annotation of part of the text on the line.*/
Index: src/org/openide/text/CloneableEditorSupport.java
===================================================================
RCS file: /shared/data/ccvs/repository/openide/text/src/org/openide/text/CloneableEditorSupport.java,v
retrieving revision 1.28
diff -u -r1.28 CloneableEditorSupport.java
--- src/org/openide/text/CloneableEditorSupport.java 12 Jan 2007 10:16:57 -0000 1.28
+++ src/org/openide/text/CloneableEditorSupport.java 7 Feb 2007 14:26:16 -0000
@@ -1599,6 +1599,8 @@
return false;
}
+ // source modified, remove it from tab-reusing slot
+ lastReusable.clear();
updateTitles();
return true;
@@ -1960,11 +1962,19 @@
}
}
+ private static ReferenceCloneableEditor
component. */
- private Pane openPane() {
+ private Pane openPane(boolean reuse) {
Pane ce = null;
boolean displayMsgOpened = false;
@@ -1991,8 +2001,19 @@
}
// #36601 - open moved outside getLock() synchronization
- ce.getComponent().open();
-
+ CloneableTopComponent ctc = ce.getComponent();
+ if (reuse && displayMsgOpened) {
+ CloneableTopComponent last = lastReusable.get();
+ if (last != null) {
+ replaceTc(last, ctc);
+ } else {
+ ctc.open();
+ }
+ lastReusable = new WeakReference(ctc);
+ } else {
+ ctc.open();
+ }
+
if (displayMsgOpened) {
String msg = messageOpened();
@@ -2046,7 +2067,11 @@
return null;
}
}
-
+
+ final Pane openReuse(final PositionRef pos, final int column) {
+ return openAtImpl(pos, column, true);
+ }
+
/** Forcibly create one editor component. Then set the caret
* to the given position.
* @param pos where to place the caret
@@ -2054,7 +2079,16 @@
* @since 5.2
*/
protected final Pane openAt(final PositionRef pos, final int column) {
- final Pane e = openPane();
+ return openAtImpl(pos, column,false);
+ }
+ /** Forcibly create one editor component. Then set the caret
+ * to the given position.
+ * @param pos where to place the caret
+ * @return always non-null
editor
+ * @since 5.2
+ */
+ private final Pane openAtImpl(final PositionRef pos, final int column, boolean reuse) {
+ final Pane e = openPane(reuse);
final Task t = prepareDocument();
e.ensureVisible();
class Selector implements TaskListener, Runnable {