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 87586 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewContextListener.java (-19 / +184 lines)
Lines 80-90 Link Here
80
	public static final String ATTR_DEBUG_MODEL_ID= "debugModelId"; //$NON-NLS-1$
80
	public static final String ATTR_DEBUG_MODEL_ID= "debugModelId"; //$NON-NLS-1$
81
	public static final String ATTR_AUTO_OPEN= "autoOpen"; //$NON-NLS-1$
81
	public static final String ATTR_AUTO_OPEN= "autoOpen"; //$NON-NLS-1$
82
	public static final String ATTR_AUTO_CLOSE= "autoClose"; //$NON-NLS-1$
82
	public static final String ATTR_AUTO_CLOSE= "autoClose"; //$NON-NLS-1$
83
	/**
84
	 * Attributes used to persist which views the user has manually opened/closed
85
	 */
86
	private static final String ATTR_VIEWS_TO_NOT_OPEN = "viewsNotToOpen"; //$NON-NLS-1$
87
	private static final String ATTR_OPENED_VIEWS = "viewsNotToClose"; //$NON-NLS-1$
88
	
83
	
89
	/**
84
	/**
90
	 * The launch view that this context listener works for
85
	 * The launch view that this context listener works for
Lines 116-126 Link Here
116
	 */
111
	 */
117
	private Set viewIdsToNotOpen= new HashSet();
112
	private Set viewIdsToNotOpen= new HashSet();
118
	/**
113
	/**
119
	 * Collection of views which have been automatically opened.
114
	 * Map of views which have been automatically opened.
120
	 * Only views which are in this collection should be automatically
115
	 * Only views which are in this collection should be automatically
121
	 * closed.
116
	 * closed.
117
	 * 
118
	 * Key: current perspective id
119
	 * Value: ArrayList of view ids
122
	 */
120
	 */
123
	private Set openedViewIds= new HashSet();
121
	private Map openedViewIds= new HashMap();
122
	
124
	/**
123
	/**
125
	 * Map of ILaunch objects to the List of EnabledSubmissions that were
124
	 * Map of ILaunch objects to the List of EnabledSubmissions that were
126
	 * submitted for them.
125
	 * submitted for them.
Lines 329-335 Link Here
329
	 * opened.
328
	 * opened.
330
	 */
329
	 */
331
	private void saveOpenedViews() {
330
	private void saveOpenedViews() {
332
		saveViewCollection(LaunchViewContextListener.PREF_OPENED_VIEWS, openedViewIds);
331
		saveViewMap(LaunchViewContextListener.PREF_OPENED_VIEWS, openedViewIds);
333
	}
332
	}
334
333
335
	/**
334
	/**
Lines 354-364 Link Here
354
		}
353
		}
355
	}
354
	}
356
	
355
	
356
	
357
	/**
358
	 * Persist the view identifiers that the user has manually
359
	 * opened/closed so that we continue to not automatically
360
	 * open/close them.
361
	 * 
362
	 * key: perspective id
363
	 * value: ArrayList of view ids
364
	 * 
365
	 * The map is saved in the following format:
366
	 * key1:arrayElm(0),arrayElm(1)/key2:arrayElm(0),arrayElm(1)
367
	 * Perspective settings are delimited by "/".
368
	 * view Ids are delimited by ","
369
	 * 
370
	 * @param attribute attribute the preference key in which to store the
371
	 *  view id map
372
	 * @param map that maps a persective to a list of view ids
373
	 */
374
	public void saveViewMap(String attribute, Map map) {
375
		StringBuffer views= new StringBuffer();
376
		Iterator iter= map.keySet().iterator();
377
		while (iter.hasNext()) {
378
			String perspId = (String) iter.next();
379
			ArrayList viewIds = (ArrayList)map.get(perspId);
380
			views.append("/"); //$NON-NLS-1$
381
			views.append(perspId);
382
			if (viewIds != null && !viewIds.isEmpty())
383
			{
384
				views.append(":"); //$NON-NLS-1$
385
				Iterator viewsIter = viewIds.iterator();
386
				while (viewsIter.hasNext())
387
				{
388
					String viewId = (String)viewsIter.next();
389
					views.append(viewId);
390
					views.append(","); //$NON-NLS-1$
391
				}
392
			}
393
		}
394
		if (views.length() > 0) {
395
			IPreferenceStore preferenceStore = DebugUITools.getPreferenceStore();
396
			preferenceStore.removePropertyChangeListener(launchView);
397
			preferenceStore.setValue(attribute, views.toString());
398
			preferenceStore.addPropertyChangeListener(launchView);
399
		}
400
	}
401
	
357
	/**
402
	/**
358
	 * Load the collection of views to not open.
403
	 * Load the collection of views to not open.
359
	 */
404
	 */
360
	public void loadViewsToNotOpen() {
405
	public void loadViewsToNotOpen() {
361
		loadViewCollection(ATTR_VIEWS_TO_NOT_OPEN, viewIdsToNotOpen);
406
		loadViewCollection(LaunchViewContextListener.PREF_VIEWS_TO_NOT_OPEN, viewIdsToNotOpen);
362
	}
407
	}
363
	
408
	
364
	/**
409
	/**
Lines 366-372 Link Here
366
	 * opened.
411
	 * opened.
367
	 */
412
	 */
368
	public void loadOpenedViews() {
413
	public void loadOpenedViews() {
369
		loadViewCollection(ATTR_OPENED_VIEWS, openedViewIds);
414
		loadViewMap(LaunchViewContextListener.PREF_OPENED_VIEWS, openedViewIds);
370
	}
415
	}
371
	
416
	
372
	/**
417
	/**
Lines 393-398 Link Here
393
			endIndex= views.indexOf(',', startIndex);
438
			endIndex= views.indexOf(',', startIndex);
394
		}
439
		}
395
	}
440
	}
441
	
442
	/**
443
	 * Loads a map of view ids from the preferences keyed to
444
	 * the given attribute, and stores them in the given map
445
	 * 
446
	 * The map is saved in the following format:
447
	 * key1:arrayElm(0),arrayElm(1)/key2:arrayElm(0)+arrayElm(1)
448
	 * Perspective settings are delimited by "/".
449
	 * Key is the perspective id
450
	 * ArrayElm's are the view Ids and are delimited by ","
451
	 * 
452
	 * @param attribute the attribute of the view ids
453
	 * @param map the map to store the view ids into.
454
	 */
455
	private void loadViewMap(String attribute, Map map) {
456
		map.clear();
457
		String views = DebugUITools.getPreferenceStore().getString(attribute);
458
		
459
		if (views.startsWith("/")) //$NON-NLS-1$
460
		{
461
			// list of views ids in this format:
462
			// perspective1Id:viewIdA,viewIdB/persective2Id:viewIda,viewIdB
463
			String[] viewsStr = views.split("/"); //$NON-NLS-1$
464
			
465
			for (int i=0; i<viewsStr.length; i++)
466
			{
467
				if (viewsStr[i].length() == 0)
468
					continue;
469
				
470
				// split perpectiveId and viewId
471
	 			String[] data = viewsStr[i].split(":"); //$NON-NLS-1$
472
				
473
				// data[0] = perspective
474
				// data[1] = list of view ids delimited by ","
475
				
476
				if (data.length == 2)
477
				{
478
					String perspId = data[0];
479
					
480
					String[] viewIds = data[1].split(","); //$NON-NLS-1$
481
					ArrayList list = new ArrayList();
482
					for (int j=0; j<viewIds.length; j++)
483
					{
484
						list.add(viewIds[j]);
485
					}
486
					
487
					openedViewIds.put(perspId, list);
488
				}
489
			}
490
		}
491
	}
396
492
397
	/* (non-Javadoc)
493
	/* (non-Javadoc)
398
	 * @see org.eclipse.ui.contexts.IContextManagerListener#contextManagerChanged(org.eclipse.ui.contexts.ContextManagerEvent)
494
	 * @see org.eclipse.ui.contexts.IContextManagerListener#contextManagerChanged(org.eclipse.ui.contexts.ContextManagerEvent)
Lines 440-458 Link Here
440
		Set viewsToShow= new HashSet();
536
		Set viewsToShow= new HashSet();
441
		Set viewsToOpen= new HashSet();
537
		Set viewsToOpen= new HashSet();
442
		computeViewActivation(contextIds, viewsToOpen, viewsToShow);
538
		computeViewActivation(contextIds, viewsToOpen, viewsToShow);
443
		fIsTrackingPartChanges= false;
539
		
540
		boolean resetTrackingPartChanges = false;
541
		if (fIsTrackingPartChanges)
542
		{
543
			// only change the flag if it is currently
544
			// tracking part changes.
545
			fIsTrackingPartChanges= false;
546
			resetTrackingPartChanges = true;
547
		}
548
		
444
		Iterator iterator= viewsToOpen.iterator();
549
		Iterator iterator= viewsToOpen.iterator();
550
		
551
		String id = page.getPerspective().getId();
552
		ArrayList views = (ArrayList)openedViewIds.get(id);
553
		if (views == null)
554
		{
555
			views = new ArrayList();
556
		}
557
		
445
		while (iterator.hasNext()) {
558
		while (iterator.hasNext()) {
446
			String viewId = (String) iterator.next();
559
			String viewId = (String) iterator.next();
447
			try {
560
			try {
448
				IViewPart view = page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE);
561
				IViewPart view = page.showView(viewId, null, IWorkbenchPage.VIEW_CREATE);
449
				openedViewIds.add(view.getViewSite().getId());
562
				if (!views.contains(viewId))
563
					views.add(viewId);
564
450
				viewsToShow.add(view);
565
				viewsToShow.add(view);
451
			} catch (PartInitException e) {
566
			} catch (PartInitException e) {
452
				DebugUIPlugin.log(e.getStatus());
567
				DebugUIPlugin.log(e.getStatus());
453
			}
568
			}
454
		}
569
		}
570
		
455
		if (!viewsToOpen.isEmpty()) {
571
		if (!viewsToOpen.isEmpty()) {
572
			openedViewIds.put(id, views);
456
			saveOpenedViews();
573
			saveOpenedViews();
457
		}
574
		}
458
		iterator= viewsToShow.iterator();
575
		iterator= viewsToShow.iterator();
Lines 480-486 Link Here
480
				page.bringToTop(view);
597
				page.bringToTop(view);
481
			}
598
			}
482
		}
599
		}
483
		loadTrackViews();
600
		
601
		// Reset if we have previously changed this setting
602
		if (resetTrackingPartChanges)
603
			loadTrackViews();
484
	}
604
	}
485
	
605
	
486
	/**
606
	/**
Lines 539-556 Link Here
539
		if (viewsToClose.isEmpty()) { 
659
		if (viewsToClose.isEmpty()) { 
540
			return;
660
			return;
541
		}
661
		}
542
		fIsTrackingPartChanges= false;
662
		
663
		// only set this to false if fIsTrackingPartChanges is true
664
		// otherwise, we may override the setting that is set
665
		// by other event handlers. e.g. in #contextEnabled(...)
666
		boolean resetTrackingPartChanges = false;
667
		if (fIsTrackingPartChanges)
668
		{
669
			fIsTrackingPartChanges= false;
670
			resetTrackingPartChanges = true;
671
		}
543
		Iterator iter= viewsToClose.iterator();
672
		Iterator iter= viewsToClose.iterator();
673
		
674
		String perspId = page.getPerspective().getId();
675
		ArrayList viewIds = (ArrayList)openedViewIds.get(perspId);
676
		
544
		while (iter.hasNext()) {
677
		while (iter.hasNext()) {
545
			String viewId= (String) iter.next();
678
			String viewId= (String) iter.next();
546
			IViewReference view = page.findViewReference(viewId);
679
			IViewReference view = page.findViewReference(viewId);
547
			if (view != null) {
680
			if (view != null) {
548
				page.hideView(view);
681
				page.hideView(view);
549
				openedViewIds.remove(viewId);
682
				if (viewIds != null && viewIds.contains(viewId))
683
				{
684
					// remove opened view from perspective
685
					viewIds.remove(viewId);
686
					openedViewIds.put(perspId, viewIds);
687
				}
550
			}
688
			}
551
		}
689
		}
552
		saveOpenedViews();
690
		saveOpenedViews();
553
		loadTrackViews();
691
		
692
		// reset if this setting is previously changed
693
		if (resetTrackingPartChanges)
694
			loadTrackViews();
554
	}
695
	}
555
	
696
	
556
	/**
697
	/**
Lines 565-570 Link Here
565
		Set viewIdsToClose= new HashSet();
706
		Set viewIdsToClose= new HashSet();
566
		Set viewIdsToKeepOpen= getViewIdsForEnabledContexts();
707
		Set viewIdsToKeepOpen= getViewIdsForEnabledContexts();
567
		Iterator contexts = contextIds.iterator();
708
		Iterator contexts = contextIds.iterator();
709
		String currentPerspId = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getPerspective().getId();
710
		ArrayList viewIds = (ArrayList)openedViewIds.get(currentPerspId);
568
		while (contexts.hasNext()) {
711
		while (contexts.hasNext()) {
569
			String contextId = (String) contexts.next();
712
			String contextId = (String) contexts.next();
570
			List list = getConfigurationElements(contextId);
713
			List list = getConfigurationElements(contextId);
Lines 575-581 Link Here
575
					continue;
718
					continue;
576
				}
719
				}
577
				String viewId = getViewId(element);
720
				String viewId = getViewId(element);
578
				if (viewId == null || !openedViewIds.contains(viewId) || viewIdsToKeepOpen.contains(viewId)) {
721
722
				if (viewId == null || viewIds == null || !viewIds.contains(viewId) || viewIdsToKeepOpen.contains(viewId)) {
579
					// Don't close views that the user has manually opened or views
723
					// Don't close views that the user has manually opened or views
580
					// which are associated with contexts that are still enabled.
724
					// which are associated with contexts that are still enabled.
581
					continue;
725
					continue;
Lines 929-942 Link Here
929
				viewIdsToNotOpen.add(id);
1073
				viewIdsToNotOpen.add(id);
930
				saveViewsToNotOpen();
1074
				saveViewsToNotOpen();
931
			}
1075
			}
932
			openedViewIds.remove(id);
1076
			
1077
			removeFromOpenedViews(id);
933
			saveOpenedViews();
1078
			saveOpenedViews();
934
		} else if (IWorkbenchPage.CHANGE_VIEW_SHOW.equals(changeId) && ref instanceof IViewReference) {
1079
		} else if (IWorkbenchPage.CHANGE_VIEW_SHOW.equals(changeId) && ref instanceof IViewReference) {
935
			String id = ((IViewReference) ref).getId();
1080
			String id = ((IViewReference) ref).getId();
936
			openedViewIds.remove(id);
1081
			removeFromOpenedViews(id);
937
			saveOpenedViews();
1082
			saveOpenedViews();
938
		}
1083
		}
939
	}
1084
	}
1085
1086
	/**
1087
	 * Givin a view id, this methods iterates through all the 
1088
	 * managed perspective and remove the view from openedViewIds
1089
	 * @param viewId
1090
	 */
1091
	private void removeFromOpenedViews(String viewId) {
1092
		Iterator keys = openedViewIds.keySet().iterator();
1093
		while (keys.hasNext())
1094
		{
1095
			String perspId = (String)keys.next();
1096
			
1097
			ArrayList views = (ArrayList)openedViewIds.get(perspId);
1098
			if (views != null && views.contains(viewId))
1099
			{
1100
				views.remove(viewId);
1101
				openedViewIds.put(perspId, views);
1102
			}
1103
		}
1104
	}
940
	
1105
	
941
	/**
1106
	/**
942
	 * Reads the preference specifying whether this view automatically
1107
	 * Reads the preference specifying whether this view automatically

Return to bug 87586