Lines 61-66
Link Here
|
61 |
import java.util.WeakHashMap; |
61 |
import java.util.WeakHashMap; |
62 |
import java.util.concurrent.atomic.AtomicBoolean; |
62 |
import java.util.concurrent.atomic.AtomicBoolean; |
63 |
import java.util.concurrent.atomic.AtomicReference; |
63 |
import java.util.concurrent.atomic.AtomicReference; |
|
|
64 |
import java.util.function.Predicate; |
64 |
import java.util.logging.Level; |
65 |
import java.util.logging.Level; |
65 |
import java.util.logging.Logger; |
66 |
import java.util.logging.Logger; |
66 |
import javax.swing.AbstractAction; |
67 |
import javax.swing.AbstractAction; |
Lines 91-96
Link Here
|
91 |
import org.openide.util.Cancellable; |
92 |
import org.openide.util.Cancellable; |
92 |
import org.openide.util.Mutex; |
93 |
import org.openide.util.Mutex; |
93 |
import org.openide.util.NbBundle; |
94 |
import org.openide.util.NbBundle; |
|
|
95 |
import org.openide.util.Pair; |
94 |
import org.openide.util.Parameters; |
96 |
import org.openide.util.Parameters; |
95 |
import org.openide.util.RequestProcessor; |
97 |
import org.openide.util.RequestProcessor; |
96 |
import org.openide.util.io.ReaderInputStream; |
98 |
import org.openide.util.io.ReaderInputStream; |
Lines 112-118
Link Here
|
112 |
* Map from tab to tab display name. |
114 |
* Map from tab to tab display name. |
113 |
* @see "#43001" |
115 |
* @see "#43001" |
114 |
*/ |
116 |
*/ |
115 |
private static final Map<InputOutput,String> freeTabs = new WeakHashMap<InputOutput,String>(); |
117 |
private static final Map<InputOutput,Pair<String,Predicate<String>>> freeTabs = new WeakHashMap<>(); |
116 |
|
118 |
|
117 |
/** |
119 |
/** |
118 |
* Display names of currently active processes. |
120 |
* Display names of currently active processes. |
Lines 129-134
Link Here
|
129 |
/** used for the tab etc. */ |
131 |
/** used for the tab etc. */ |
130 |
private String displayName; |
132 |
private String displayName; |
131 |
private String suggestedDisplayName; |
133 |
private String suggestedDisplayName; |
|
|
134 |
private Boolean shouldSaveAllDocs; |
135 |
private Predicate<String> canBeReplaced = (s) -> true; |
136 |
private Predicate<String> canReplace = (s) -> true; |
132 |
private volatile Set<String> concealedProperties; |
137 |
private volatile Set<String> concealedProperties; |
133 |
|
138 |
|
134 |
/** targets may be null to indicate default target */ |
139 |
/** targets may be null to indicate default target */ |
Lines 151-158
Link Here
|
151 |
this.concealedProperties = Collections.unmodifiableSet(new HashSet<String>(concealedProperties)); |
156 |
this.concealedProperties = Collections.unmodifiableSet(new HashSet<String>(concealedProperties)); |
152 |
} |
157 |
} |
153 |
|
158 |
|
154 |
void setDisplayName(String n) { |
159 |
public void setSaveAllDocuments(boolean shouldSaveAllDocs) { |
155 |
suggestedDisplayName = n; |
160 |
this.shouldSaveAllDocs = shouldSaveAllDocs; |
|
|
161 |
} |
162 |
|
163 |
public void setDisplayName(String n) { |
164 |
this.suggestedDisplayName = n; |
165 |
} |
166 |
|
167 |
public void setTabReplaceStrategy( |
168 |
@NonNull final Predicate<String> canReplace, |
169 |
@NonNull final Predicate<String> canBeReplaced) { |
170 |
Parameters.notNull("canReplace", canReplace); //NOI18N |
171 |
Parameters.notNull("canBeReplaced", canBeReplaced); //NOI18N |
172 |
this.canReplace = canReplace; |
173 |
this.canBeReplaced = canBeReplaced; |
156 |
} |
174 |
} |
157 |
|
175 |
|
158 |
private static String getProcessDisplayName(AntProjectCookie pcookie, List<String> targetNames) { |
176 |
private static String getProcessDisplayName(AntProjectCookie pcookie, List<String> targetNames) { |
Lines 364-386
Link Here
|
364 |
// OutputWindow |
382 |
// OutputWindow |
365 |
if (AntSettings.getAutoCloseTabs()) { // #47753 |
383 |
if (AntSettings.getAutoCloseTabs()) { // #47753 |
366 |
synchronized (freeTabs) { |
384 |
synchronized (freeTabs) { |
367 |
for (Map.Entry<InputOutput,String> entry : freeTabs.entrySet()) { |
385 |
final Set<InputOutput> retained = new HashSet<>(); |
|
|
386 |
for (Map.Entry<InputOutput,Pair<String,Predicate<String>>> entry : freeTabs.entrySet()) { |
368 |
InputOutput free = entry.getKey(); |
387 |
InputOutput free = entry.getKey(); |
369 |
String freeName = entry.getValue(); |
388 |
String freeName = entry.getValue().first(); |
|
|
389 |
Predicate<String> freePredicate = entry.getValue().second(); |
370 |
if (io == null && freeName.equals(displayName)) { |
390 |
if (io == null && freeName.equals(displayName)) { |
371 |
// Reuse it. |
391 |
// Reuse it. |
372 |
io = free; |
392 |
io = free; |
373 |
io.getOut().reset(); |
393 |
io.getOut().reset(); |
374 |
// Apparently useless and just prints warning: io.getErr().reset(); |
394 |
// Apparently useless and just prints warning: io.getErr().reset(); |
375 |
// useless: io.flushReader(); |
395 |
// useless: io.flushReader(); |
376 |
} else { |
396 |
} else if (canReplace.test(freeName) && freePredicate.test(displayName)) { |
377 |
// Discard it. |
397 |
// Discard it. |
378 |
free.closeInputOutput(); |
398 |
free.closeInputOutput(); |
379 |
stopActions.remove(free); |
399 |
stopActions.remove(free); |
380 |
rerunActions.remove(free); |
400 |
rerunActions.remove(free); |
|
|
401 |
} else { |
402 |
retained.add(free); |
381 |
} |
403 |
} |
382 |
} |
404 |
} |
383 |
freeTabs.clear(); |
405 |
freeTabs.keySet().retainAll(retained); |
384 |
} |
406 |
} |
385 |
} |
407 |
} |
386 |
if (io == null) { |
408 |
if (io == null) { |
Lines 466-472
Link Here
|
466 |
} |
488 |
} |
467 |
} |
489 |
} |
468 |
|
490 |
|
469 |
if (AntSettings.getSaveAll()) { |
491 |
if (shouldSaveAllDocs != null ? shouldSaveAllDocs : AntSettings.getSaveAll()) { |
470 |
LifecycleManager.getDefault ().saveAll (); |
492 |
LifecycleManager.getDefault ().saveAll (); |
471 |
} |
493 |
} |
472 |
|
494 |
|
Lines 557-563
Link Here
|
557 |
} finally { |
579 |
} finally { |
558 |
if (io != null) { |
580 |
if (io != null) { |
559 |
synchronized (freeTabs) { |
581 |
synchronized (freeTabs) { |
560 |
freeTabs.put(io, displayName); |
582 |
freeTabs.put(io, Pair.of(displayName,canBeReplaced)); |
561 |
} |
583 |
} |
562 |
} |
584 |
} |
563 |
if (thisExec[0] != null) { |
585 |
if (thisExec[0] != null) { |