Index: apichanges.xml =================================================================== RCS file: /shared/data/ccvs/repository/openide/text/apichanges.xml,v retrieving revision 1.16 diff -u -r1.16 apichanges.xml --- apichanges.xml 1 Aug 2006 22:06:39 -0000 1.16 +++ apichanges.xml 7 Feb 2007 14:26:16 -0000 @@ -23,6 +23,26 @@ Text API + + + Adding Line.SHOW_REUSE constant for Line.show method + + + + + +

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 Lines from different + Document. This is useful for quick source browsing without + cluttering the UI with too many opened editors. +

+
+ + +
Index: manifest.mf =================================================================== RCS file: /shared/data/ccvs/repository/openide/text/manifest.mf,v retrieving revision 1.14 diff -u -r1.14 manifest.mf --- manifest.mf 1 Aug 2006 22:06:39 -0000 1.14 +++ manifest.mf 7 Feb 2007 14:26:16 -0000 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.text -OpenIDE-Module-Specification-Version: 6.12 +OpenIDE-Module-Specification-Version: 6.13 OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties Index: src/org/openide/text/Line.java =================================================================== RCS file: /shared/data/ccvs/repository/openide/text/src/org/openide/text/Line.java,v retrieving revision 1.4 diff -u -r1.4 Line.java --- src/org/openide/text/Line.java 13 Dec 2006 19:26:47 -0000 1.4 +++ src/org/openide/text/Line.java 7 Feb 2007 14:26:16 -0000 @@ -69,6 +69,15 @@ */ public final static int SHOW_TOFRONT = 3; + /** Takes the focus in case the editor is already opened and shows the line. + * Replaces (closes) the last editor opened using SHOW_REUSE in case + * the user haven't interacted with it much (e.g. haven't modified it). + * Opens a new editor in case there is no such reusable editor + * and marks it for editor reusal. + * @see #show(int) 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 Reference lastReusable = new WeakReference(null); + + // temporal - should be replaced by better impl in winsys + private static void replaceTc(TopComponent orig, TopComponent open) { + orig.close(); + open.open(); + } + // #18981. There could happen a thing also another class type // of CloneableTopCoponent then CloneableEditor could be in allEditors. /** Opens a CloneableEditor 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 {