Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 87587 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java (-10 / +6 lines)
Lines 389-394 Link Here
389
	public void start(BundleContext context) throws Exception {
389
	public void start(BundleContext context) throws Exception {
390
		super.start(context);
390
		super.start(context);
391
		
391
		
392
		// make sure the perspective manager is created
393
		// and be the first debug event listener
394
		fPerspectiveManager = new PerspectiveManager();
395
		fPerspectiveManager.startup();		
396
		
392
		// Listen to launches to lazily create "launch processors"
397
		// Listen to launches to lazily create "launch processors"
393
		DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
398
		DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
394
        
399
        
Lines 652-662 Link Here
652
		DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
657
		DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
653
		getProcessConsoleManager().startup();
658
		getProcessConsoleManager().startup();
654
		
659
		
655
		if (fPerspectiveManager == null) {
656
			PerspectiveManager manager = getPerspectiveManager();
657
			manager.launchAdded(launch);
658
		}
659
		
660
		if (fStepFilterManager == null) {
660
		if (fStepFilterManager == null) {
661
			getStepFilterManager().launchAdded(launch);
661
			getStepFilterManager().launchAdded(launch);
662
		}
662
		}
Lines 665-679 Link Here
665
	}
665
	}
666
	
666
	
667
	/**
667
	/**
668
	 * Returns the persepective manager - instantiating it if required.
668
	 * Returns the persepective manager.
669
	 * 
669
	 * 
670
	 * @return
670
	 * @return
671
	 */
671
	 */
672
	public PerspectiveManager getPerspectiveManager() {
672
	public PerspectiveManager getPerspectiveManager() {
673
		if (fPerspectiveManager == null) {
674
			fPerspectiveManager = new PerspectiveManager();
675
			fPerspectiveManager.startup();			
676
		}
677
		return fPerspectiveManager;
673
		return fPerspectiveManager;
678
	}
674
	}
679
	
675
	
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/PerspectiveManager.java (-23 / +97 lines)
Lines 14-27 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.io.StringReader;
15
import java.io.StringReader;
16
import java.text.MessageFormat;
16
import java.text.MessageFormat;
17
import java.util.ArrayList;
17
import java.util.HashMap;
18
import java.util.HashMap;
18
import java.util.Iterator;
19
import java.util.Iterator;
20
import java.util.List;
19
import java.util.Map;
21
import java.util.Map;
20
import javax.xml.parsers.DocumentBuilder;
22
import javax.xml.parsers.DocumentBuilder;
21
import javax.xml.parsers.DocumentBuilderFactory;
23
import javax.xml.parsers.DocumentBuilderFactory;
22
import javax.xml.parsers.ParserConfigurationException;
24
import javax.xml.parsers.ParserConfigurationException;
23
import javax.xml.transform.TransformerException;
25
import javax.xml.transform.TransformerException;
24
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.jobs.Job;
25
import org.eclipse.debug.core.DebugEvent;
28
import org.eclipse.debug.core.DebugEvent;
26
import org.eclipse.debug.core.DebugPlugin;
29
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.IDebugEventSetListener;
30
import org.eclipse.debug.core.IDebugEventSetListener;
Lines 85-91 Link Here
85
	 * prompts at the same time.
88
	 * prompts at the same time.
86
	 */
89
	 */
87
	private boolean fPrompting;
90
	private boolean fPrompting;
91
	private PerspectiveSwitchLock fPerspectiveSwitchLock = new PerspectiveSwitchLock();
92
	
93
	/**
94
	 * Lock used to synchronize perspective switching with view activation.
95
	 * Clients wanting to perform an action after a perspective switch should
96
	 * schedule jobs with the perspective manager via #schedulePostSwitch(..)
97
	 */
98
	public class PerspectiveSwitchLock
99
	{
100
101
		private int fSwitch = 0;
102
		private List fJobs = new ArrayList();
88
		
103
		
104
		public synchronized void startSwitch() {
105
			fSwitch++;
106
		}
107
		
108
		public synchronized void endSwitch() {
109
			fSwitch--;
110
			if (fSwitch == 0) {
111
				Iterator jobs = fJobs.iterator();
112
				while (jobs.hasNext()) {
113
					((Job)jobs.next()).schedule();
114
				}
115
				fJobs.clear();
116
			}
117
		}
118
				
119
		public synchronized void schedulePostSwitch(Job job) {
120
			if (fSwitch > 0) {
121
				fJobs.add(job);	
122
			} else {
123
				job.schedule();
124
			}
125
		}
126
	}
127
	
128
	
89
	/**
129
	/**
90
	 * Called by the debug ui plug-in on startup.
130
	 * Called by the debug ui plug-in on startup.
91
	 * The perspective manager starts listening for
131
	 * The perspective manager starts listening for
Lines 131-136 Link Here
131
	 * @see ILaunchListener#launchAdded(ILaunch)
171
	 * @see ILaunchListener#launchAdded(ILaunch)
132
	 */
172
	 */
133
	public void launchAdded(ILaunch launch) {
173
	public void launchAdded(ILaunch launch) {
174
		
175
		fPerspectiveSwitchLock.startSwitch();
176
		
134
		String perspectiveId = null;
177
		String perspectiveId = null;
135
		// check event filters
178
		// check event filters
136
		try {
179
		try {
Lines 152-164 Link Here
152
		// switch
195
		// switch
153
		async(new Runnable() {
196
		async(new Runnable() {
154
			public void run() {
197
			public void run() {
155
				IWorkbenchWindow window = getWindowForPerspective(id);
198
				try
156
				if (id != null && window != null && shouldSwitchPerspectiveForLaunch(window, id)) {
199
				{
157
					switchToPerspective(window, id);
200
					IWorkbenchWindow window = getWindowForPerspective(id);
201
					if (id != null && window != null && shouldSwitchPerspectiveForLaunch(window, id)) {
202
						switchToPerspective(window, id);
203
					}
204
				}
205
				finally
206
				{
207
					fPerspectiveSwitchLock.endSwitch();
158
				}
208
				}
159
			}
209
			}
160
		});
210
		});
161
		
162
	}
211
	}
163
212
164
213
Lines 284-289 Link Here
284
	 * @param event the suspend event
333
	 * @param event the suspend event
285
	 */
334
	 */
286
	private void handleBreakpointHit(DebugEvent event) {
335
	private void handleBreakpointHit(DebugEvent event) {
336
		
337
		// Must be called here to indicate that the perspective
338
		// may be switching.
339
		// Putting this in the async UI call will cause the Perspective
340
		// Manager to turn on the lock too late.  Consequently, LaunchViewContextListener
341
		// may not know that the perspective will switch and will open view before
342
		// the perspective switch.
343
		fPerspectiveSwitchLock.startSwitch();
344
		
287
		// apply event filters
345
		// apply event filters
288
		ILaunch launch= null;
346
		ILaunch launch= null;
289
		Object source = event.getSource();
347
		Object source = event.getSource();
Lines 307-340 Link Here
307
		Runnable r = new Runnable() {
365
		Runnable r = new Runnable() {
308
			public void run() {
366
			public void run() {
309
				IWorkbenchWindow window = null;
367
				IWorkbenchWindow window = null;
368
				try{
310
				if (targetId != null) {
369
				if (targetId != null) {
311
					window = getWindowForPerspective(targetId);
312
					if (window == null) {
313
						return;
314
					}
315
					if (shouldSwitchPerspectiveForSuspend(window, targetId)) {
316
						switchToPerspective(window, targetId);
317
						// Showing the perspective can open a new window
318
						// (based on user prefs). So check again in case a
319
						// new window has been opened.
320
						window = getWindowForPerspective(targetId);
370
						window = getWindowForPerspective(targetId);
321
						if (window == null) {
371
						if (window == null) {
322
							return;
372
							return;
323
						}
373
						}
324
					}
374
						
325
					// re-open the window if minimized 
375
						if (shouldSwitchPerspectiveForSuspend(window, targetId)) {
326
					Shell shell= window.getShell();
376
							switchToPerspective(window, targetId);
327
					if (shell != null) {
377
							// Showing the perspective can open a new window
328
						if (shell.getMinimized()) {
378
							// (based on user prefs). So check again in case a
329
							shell.setMinimized(false);
379
							// new window has been opened.
380
							window = getWindowForPerspective(targetId);
381
							if (window == null) {
382
								return;
383
							}
330
						}
384
						}
331
						if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH)) {
385
						// re-open the window if minimized 
332
							shell.forceActive();
386
						Shell shell= window.getShell();
387
						if (shell != null) {
388
							if (shell.getMinimized()) {
389
								shell.setMinimized(false);
390
							}
391
							if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH)) {
392
								shell.forceActive();
393
							}
333
						}
394
						}
334
					}
395
					}
396
					if (window != null && DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_ACTIVATE_DEBUG_VIEW)) {
397
						showDebugView(window);
398
					}
335
				}
399
				}
336
				if (window != null && DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_ACTIVATE_DEBUG_VIEW)) {
400
				finally
337
					showDebugView(window);
401
				{
402
					fPerspectiveSwitchLock.endSwitch();
338
				}
403
				}
339
			}
404
			}
340
		};
405
		};
Lines 742-745 Link Here
742
		
807
		
743
	}
808
	}
744
	
809
	
810
	/**
811
	 * Schedules the given job after perspective switching is complete, or
812
	 * immediately if a perspective switch is not in progress.
813
	 * 
814
	 * @param job job to run after perspective switching
815
	 */
816
	public void schedulePostSwitch(Job job) {
817
		fPerspectiveSwitchLock.schedulePostSwitch(job);
818
	}
745
}
819
}
(-)ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewContextListener.java (-74 / +126 lines)
Lines 24-30 Link Here
24
import org.eclipse.core.runtime.IAdaptable;
24
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.core.runtime.IConfigurationElement;
25
import org.eclipse.core.runtime.IConfigurationElement;
26
import org.eclipse.core.runtime.IExtensionPoint;
26
import org.eclipse.core.runtime.IExtensionPoint;
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.Platform;
29
import org.eclipse.core.runtime.Platform;
30
import org.eclipse.core.runtime.Status;
28
import org.eclipse.debug.core.ILaunch;
31
import org.eclipse.debug.core.ILaunch;
29
import org.eclipse.debug.core.model.IDebugElement;
32
import org.eclipse.debug.core.model.IDebugElement;
30
import org.eclipse.debug.core.model.IDebugModelProvider;
33
import org.eclipse.debug.core.model.IDebugModelProvider;
Lines 32-37 Link Here
32
import org.eclipse.debug.core.model.IStackFrame;
35
import org.eclipse.debug.core.model.IStackFrame;
33
import org.eclipse.debug.internal.ui.DebugUIPlugin;
36
import org.eclipse.debug.internal.ui.DebugUIPlugin;
34
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
37
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
38
import org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager;
35
import org.eclipse.debug.ui.DebugUITools;
39
import org.eclipse.debug.ui.DebugUITools;
36
import org.eclipse.debug.ui.IDebugUIConstants;
40
import org.eclipse.debug.ui.IDebugUIConstants;
37
import org.eclipse.jface.preference.IPreferenceStore;
41
import org.eclipse.jface.preference.IPreferenceStore;
Lines 56-61 Link Here
56
import org.eclipse.ui.contexts.IContextManagerListener;
60
import org.eclipse.ui.contexts.IContextManagerListener;
57
import org.eclipse.ui.contexts.IWorkbenchContextSupport;
61
import org.eclipse.ui.contexts.IWorkbenchContextSupport;
58
import org.eclipse.ui.contexts.NotDefinedException;
62
import org.eclipse.ui.contexts.NotDefinedException;
63
import org.eclipse.ui.progress.UIJob;
59
64
60
/**
65
/**
61
 * A context listener which automatically opens/closes/activates views in
66
 * A context listener which automatically opens/closes/activates views in
Lines 530-616 Link Here
530
	 * @param contextId the ID of the context that has been
535
	 * @param contextId the ID of the context that has been
531
	 * 	enabled
536
	 * 	enabled
532
	 */
537
	 */
533
	public void contextEnabled(Set contextIds) {
538
	public void contextEnabled(final Set contextIds) {
534
		if (!isAutoManageViews()) {
539
		if (!isAutoManageViews()) {
535
			return;
540
			return;
536
		}
541
		}
537
		IWorkbenchPage page= getPage();
538
		// We ignore the "Debugging" context since we use it
539
		// to provide a base set of views for other context
540
		// bindings to inherit. If we don't ignore it, we'll
541
		// end up opening those views whenever a debug session
542
		// starts, which is not the desired behavior.
543
		contextIds.remove(DEBUG_CONTEXT);
544
		if (page == null || contextIds.size() == 0) {
545
			return;
546
		}
547
		Set viewsToShow= new HashSet();
548
		Set viewsToOpen= new HashSet();
549
		computeViewActivation(contextIds, viewsToOpen, viewsToShow);
550
		
551
		boolean resetTrackingPartChanges = false;
552
		if (fIsTrackingPartChanges)
553
		{
554
			// only change the flag if it is currently
555
			// tracking part changes.
556
			fIsTrackingPartChanges= false;
557
			resetTrackingPartChanges = true;
558
		}
559
		
560
		Iterator iterator= viewsToOpen.iterator();
561
		
562
		String id = page.getPerspective().getId();
563
		Set views = (Set)openedViewIds.get(id);
564
		if (views == null)
565
		{
566
			views = new HashSet();
567
		}
568
		
542
		
569
		while (iterator.hasNext()) {
543
		final UIJob openViewsJob = new UIJob("Open Context-Enabled Views") { //$NON-NLS-1$
570
			String viewId = (String) iterator.next();
544
			public IStatus runInUIThread(IProgressMonitor monitor) {
571
			try {
545
				IWorkbenchPage page =  getPage();
572
				IViewPart view = page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE);
546
				if (page == null)
573
				views.add(viewId);
547
					return Status.OK_STATUS;
574
548
				
575
				viewsToShow.add(view);
549
				// Since we run this job asynchronously on the UI Thread,
576
			} catch (PartInitException e) {
550
				// #getPerspective() may return null when this job is run
577
				DebugUIPlugin.log(e.getStatus());
551
				// when the workbench is shutting down.
552
				if (page.getPerspective() == null)
553
					return Status.OK_STATUS;
554
				
555
				// We ignore the "Debugging" context since we use it
556
				// to provide a base set of views for other context
557
				// bindings to inherit. If we don't ignore it, we'll
558
				// end up opening those views whenever a debug session
559
				// starts, which is not the desired behavior.
560
				contextIds.remove(DEBUG_CONTEXT);
561
				if (page == null || contextIds.size() == 0) {
562
					return Status.OK_STATUS;
563
				}
564
				Set viewsToShow = new HashSet();
565
				Set viewsToOpen = new HashSet();
566
				computeViewActivation(contextIds, viewsToOpen, viewsToShow);
567
568
				boolean resetTrackingPartChanges = false;
569
				if (fIsTrackingPartChanges) {
570
					// only change the flag if it is currently
571
					// tracking part changes.
572
					fIsTrackingPartChanges = false;
573
					resetTrackingPartChanges = true;
574
				}
575
576
				Iterator iterator = viewsToOpen.iterator();
577
578
				String id = page.getPerspective().getId();
579
				Set views = (Set) openedViewIds.get(id);
580
				if (views == null) {
581
					views = new HashSet();
582
				}
583
584
				while (iterator.hasNext()) {
585
					String viewId = (String) iterator.next();
586
					try {
587
						IViewPart view = page.showView(viewId, null,
588
								IWorkbenchPage.VIEW_CREATE);
589
						views.add(viewId);
590
591
						viewsToShow.add(view);
592
					} catch (PartInitException e) {
593
						DebugUIPlugin.log(e.getStatus());
594
					}
595
				}
596
597
				if (!viewsToOpen.isEmpty()) {
598
					openedViewIds.put(id, views);
599
					saveOpenedViews();
600
				}
601
				iterator = viewsToShow.iterator();
602
				while (iterator.hasNext()) {
603
					boolean activate = true;
604
					IViewPart view = (IViewPart) iterator.next();
605
					IViewPart[] stackedViews = page.getViewStack(view);
606
					if (stackedViews == null) {
607
						continue;
608
					}
609
					// For each applicable view, iterate through the view stack.
610
					// If we find that view before any other applicable views,
611
					// show it. Otherwise, don't.
612
					for (int i = 0; i < stackedViews.length; i++) {
613
						IViewPart stackedView = stackedViews[i];
614
						if (view == stackedView) {
615
							break;
616
						} else if (viewsToShow.contains(stackedView)) {
617
							// If this view is below an appropriate view, don't
618
							// show it
619
							activate = false;
620
							break;
621
						}
622
					}
623
					if (activate) {
624
						page.bringToTop(view);
625
					}
626
				}
627
628
				// Reset if we have previously changed this setting
629
				if (resetTrackingPartChanges)
630
					loadTrackViews();
631
				
632
				return Status.OK_STATUS;
578
			}
633
			}
579
		}
634
		};
580
		
635
		
581
		if (!viewsToOpen.isEmpty()) {
636
		openViewsJob.setSystem(true);
582
			openedViewIds.put(id, views);
637
583
			saveOpenedViews();
638
		final PerspectiveManager manager = DebugUIPlugin.getDefault().getPerspectiveManager();
639
		if (isBoundToViews(contextIds)) {
640
			manager.schedulePostSwitch(openViewsJob);
584
		}
641
		}
585
		iterator= viewsToShow.iterator();
642
	}
586
		while (iterator.hasNext()) {
643
	
587
			boolean activate= true;
644
	/**
588
			IViewPart view = (IViewPart) iterator.next();
645
	 * @param contextIds
589
			IViewPart[] stackedViews = page.getViewStack(view);
646
	 * @return if the specified the context ids are tied
590
			if (stackedViews == null) {
647
	 * to any context-enabled views.
591
				continue;
648
	 */
592
			}
649
	private boolean isBoundToViews(Set contextIds)
593
			// For each applicable view, iterate through the view stack.
650
	{
594
			// If we find that view before any other applicable views,
651
		Set possibleViewsToShow = new HashSet();
595
			// show it. Otherwise, don't.
652
		Iterator iter = contextIds.iterator();
596
			for (int i = 0; i < stackedViews.length; i++) {
653
		while (iter.hasNext())
597
				IViewPart stackedView= stackedViews[i];
654
		{
598
				if (view == stackedView) {
655
			String contextId = (String)iter.next();
599
					break;
656
			Set viewIds = getApplicableViewIds(contextId);
600
				} else if (viewsToShow.contains(stackedView)) {
657
			possibleViewsToShow.addAll(viewIds);
601
					// If this view is below an appropriate view, don't show it
602
					activate= false;
603
					break;
604
				}
605
			}
606
			if (activate) {
607
				page.bringToTop(view);
608
			}
609
		}
658
		}
610
		
659
		
611
		// Reset if we have previously changed this setting
660
		return !possibleViewsToShow.isEmpty();		
612
		if (resetTrackingPartChanges)
613
			loadTrackViews();
614
	}
661
	}
615
	
662
	
616
	/**
663
	/**
Lines 661-667 Link Here
661
	 * @param contexts
708
	 * @param contexts
662
	 */
709
	 */
663
	public void contextsDisabled(Set contexts) {
710
	public void contextsDisabled(Set contexts) {
664
		IWorkbenchPage page= getPage();
711
		IWorkbenchPage page=  getPage();
665
		if (page == null || contexts.size() == 0 || !isAutoManageViews()) {
712
		if (page == null || contexts.size() == 0 || !isAutoManageViews()) {
666
			return;
713
			return;
667
		}
714
		}
Lines 715-721 Link Here
715
		Set viewIdsToClose= new HashSet();
762
		Set viewIdsToClose= new HashSet();
716
		Set viewIdsToKeepOpen= getViewIdsForEnabledContexts();
763
		Set viewIdsToKeepOpen= getViewIdsForEnabledContexts();
717
		Iterator contexts = contextIds.iterator();
764
		Iterator contexts = contextIds.iterator();
718
		String currentPerspId = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getPerspective().getId();
765
		IWorkbenchPage page = getPage();
766
		if (page == null)
767
			return viewIdsToClose;
768
		if (page.getPerspective() == null)
769
			return viewIdsToClose;
770
		String currentPerspId = page.getPerspective().getId();
719
		Set viewIds = (Set)openedViewIds.get(currentPerspId);
771
		Set viewIds = (Set)openedViewIds.get(currentPerspId);
720
		while (contexts.hasNext()) {
772
		while (contexts.hasNext()) {
721
			String contextId = (String) contexts.next();
773
			String contextId = (String) contexts.next();

Return to bug 87587