|
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(); |