# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\Projects\core-main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: tasklist.projectint/src/org/netbeans/modules/tasklist/projectint/OpenedProjectsScanningScope.java --- tasklist.projectint/src/org/netbeans/modules/tasklist/projectint/OpenedProjectsScanningScope.java Base (BASE) +++ tasklist.projectint/src/org/netbeans/modules/tasklist/projectint/OpenedProjectsScanningScope.java Locally Modified (Based On LOCAL) @@ -84,7 +84,7 @@ * @param icon */ private OpenedProjectsScanningScope( String displayName, String description, Image icon ) { - super( displayName, description, icon, true ); + super( displayName, description, icon ); Map labels = new HashMap(1); labels.put( Utils.KEY_STATUS_BAR_LABEL, NbBundle.getMessage(OpenedProjectsScanningScope.class, "LBL_OpenedProjectsStatusBar") ); //NOI18N Index: tasklist.ui/src/org/netbeans/modules/tasklist/impl/CurrentEditorScanningScope.java --- tasklist.ui/src/org/netbeans/modules/tasklist/impl/CurrentEditorScanningScope.java Base (BASE) +++ tasklist.ui/src/org/netbeans/modules/tasklist/impl/CurrentEditorScanningScope.java Locally Modified (Based On LOCAL) @@ -79,7 +79,7 @@ /** Creates a new instance of CurrentEditorScope */ public CurrentEditorScanningScope( String displayName, String description, Image icon ) { - super( displayName, description, icon ); + super( displayName, description, icon, true ); Map labels = new HashMap(1); labels.put( "StatusBarLabel", //NOI18N NbBundle.getMessage(CurrentEditorScanningScope.class, "LBL_CurrentFileStatusMessage") ); //NOI18N Index: tasklist.ui/src/org/netbeans/modules/tasklist/impl/TaskIndexer.java --- tasklist.ui/src/org/netbeans/modules/tasklist/impl/TaskIndexer.java Base (BASE) +++ tasklist.ui/src/org/netbeans/modules/tasklist/impl/TaskIndexer.java Locally Modified (Based On LOCAL) @@ -94,22 +94,15 @@ try { boolean firstScan = true; boolean isInScope = false; + boolean currentFileFound = false; IndexingSupport is = IndexingSupport.getInstance(context); for( Indexable idx : files ) { if (context.isCancelled()) { LOG.log(Level.FINE, "Indexer cancelled"); //NOI18N return; } - if( null == scanners ) { - scanners = new ArrayList( 20 ); - for( FileTaskScanner s : tm.getFileScanners() ) { - if( filter.isEnabled(s) ) { - s.notifyPrepare(); - scanners.add(s); - LOG.fine("Using FileTaskScanner: " + s); //NOI18N - } - } - } + + // get fileObject FileObject root = context.getRoot(); if( null == root ) { LOG.log(Level.FINE, "Context root not available"); @@ -120,12 +113,42 @@ LOG.log(Level.FINE, "Cannot find file [%0] under root [%1]", new Object[] {idx.getRelativePath(), root}); continue; } - if (firstScan || scope instanceof CurrentEditorScanningScope){ + + /* + * if the currentEditorScope is active we want to scan only + * current editor file. If fo isn't the file we are looking for + * we will skip it and flag the cache as dirty + */ + if (tm.isCurrentEditorScope()) { isInScope = scope.isInScope(fo); + if (isInScope) { + currentFileFound = true; + } else { + tm.makeCacheDirty(); + continue; + } + } + + //prepare file scanners + if( null == scanners ) { + scanners = new ArrayList( 20 ); + for( FileTaskScanner s : tm.getFileScanners() ) { + if( filter.isEnabled(s) ) { + s.notifyPrepare(); + scanners.add(s); + LOG.fine("Using FileTaskScanner: " + s); //NOI18N + } + } + } + + if (firstScan){ + isInScope = scope.isInScope(fo); firstScan = false; } is.removeDocuments(idx); IndexDocument doc = null; + + // scan and cache tasks for( FileTaskScanner scanner : scanners ) { List tasks = scanner.scan(fo); if( null == tasks ) @@ -143,6 +166,10 @@ } } } + // current editor file has been found, no need for further scanning and caching + if (currentFileFound) { + break; + } } } catch( IOException ioE ) { LOG.log(Level.INFO, "Error while scanning file for tasks.", ioE); Index: tasklist.ui/src/org/netbeans/modules/tasklist/impl/TaskManagerImpl.java --- tasklist.ui/src/org/netbeans/modules/tasklist/impl/TaskManagerImpl.java Base (BASE) +++ tasklist.ui/src/org/netbeans/modules/tasklist/impl/TaskManagerImpl.java Locally Modified (Based On LOCAL) @@ -53,6 +53,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -64,6 +65,7 @@ import org.netbeans.spi.tasklist.Task; import org.netbeans.spi.tasklist.TaskScanningScope; import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; import org.openide.util.Exceptions; import org.openide.util.NbPreferences; import org.openide.util.RequestProcessor; @@ -241,6 +243,10 @@ boolean isObserved() { return !Accessor.getEmptyScope().equals( getScope() ); } + + boolean isCurrentEditorScope(){ + return scope instanceof CurrentEditorScanningScope; + } public TaskScanningScope getScope() { return scope; @@ -346,7 +352,12 @@ if( getFilter().isEnabled( scanner ) ) scanner.setScope( scopeToRefresh, Accessor.createCallback( this, scanner ) ); } - startLoading(); + boolean dirtyCache = NbPreferences.forModule(TaskManagerImpl.class).getBoolean("dirtyCache", false); + if (dirtyCache && isCurrentEditorScope()) { + cacheCurrentEditorFile(); + } else { + startLoading(); + } } } } @@ -468,4 +479,24 @@ }); } } + + private void cacheCurrentEditorFile() { + try { + Iterator it = scope.iterator(); + FileObject fo; + if (it.hasNext()) { + fo = it.next(); + } else { + return; + } + ArrayList toRefresh = new ArrayList(1); + toRefresh.add(fo.getURL()); + Collection roots = QuerySupport.findRoots(fo, null, null, null); + for (FileObject root : roots) { + IndexingManager.getDefault().refreshIndex(root.getURL(), toRefresh); + } + } catch (FileStateInvalidException ex) { + getLogger().log(Level.INFO, "Error while refreshing files.", ex); + } + } }