View | Details | Raw Unified | Return to bug 184074 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java (-49 / +109 lines)
Lines 581-594 Link Here
581
	 *            the index of the activated page
581
	 *            the index of the activated page
582
	 */
582
	 */
583
	protected void pageChange(int newPageIndex) {
583
	protected void pageChange(int newPageIndex) {
584
		// Deactivate the nested services from the last active service locator.
584
		deactivateSite(false);
585
		if (activeServiceLocator != null) {
586
			activeServiceLocator.deactivate();
587
			activeServiceLocator = null;
588
		}
589
585
590
		setFocus();
586
		// should use
587
		// IPartService partService = (IPartService) getSite()
588
		//     .getService(IPartService.class);
589
		if (getSite().getPage().getActivePart()==this) {
590
			setFocus(newPageIndex);
591
		}
592
		
591
		IEditorPart activeEditor = getEditor(newPageIndex);
593
		IEditorPart activeEditor = getEditor(newPageIndex);
594
		
592
		IEditorActionBarContributor contributor = getEditorSite()
595
		IEditorActionBarContributor contributor = getEditorSite()
593
				.getActionBarContributor();
596
				.getActionBarContributor();
594
		if (contributor != null
597
		if (contributor != null
Lines 596-610 Link Here
596
			((MultiPageEditorActionBarContributor) contributor)
599
			((MultiPageEditorActionBarContributor) contributor)
597
					.setActivePage(activeEditor);
600
					.setActivePage(activeEditor);
598
		}
601
		}
602
		
599
		if (activeEditor != null) {
603
		if (activeEditor != null) {
600
601
			// Activate the services for the new service locator.
602
			final IServiceLocator serviceLocator = activeEditor.getEditorSite();
603
			if (serviceLocator instanceof INestable) {
604
				activeServiceLocator = (INestable) serviceLocator;
605
				activeServiceLocator.activate();
606
			}
607
608
			ISelectionProvider selectionProvider = activeEditor.getSite()
604
			ISelectionProvider selectionProvider = activeEditor.getSite()
609
					.getSelectionProvider();
605
					.getSelectionProvider();
610
			if (selectionProvider != null) {
606
			if (selectionProvider != null) {
Lines 627-632 Link Here
627
				}
623
				}
628
			}
624
			}
629
		}
625
		}
626
		
627
		activateSite();
628
	}
629
	
630
	/**
631
	 * This method can be used by implementors of
632
	 * {@link MultiPageEditorPart#createPageContainer(Composite)} to deactivate
633
	 * the active inner editor services while their header has focus. A
634
	 * deactivateSite() must have a matching call to activateSite() when
635
	 * appropriate.
636
	 * <p>
637
	 * An new inner editor will have its site activated on a
638
	 * {@link MultiPageEditorPart#pageChange(int)}.
639
	 * </p>
640
	 * <p>
641
	 * <b>Note:</b> This API is evolving in 3.4 and this might not be its final
642
	 * form.
643
	 * </p>
644
	 * 
645
	 * @param immediate
646
	 *            immediately deactivate the legacy keybinding service
647
	 * @since 3.4
648
	 * @see #activateSite()
649
	 * @see #createPageContainer(Composite)
650
	 */
651
	protected final void deactivateSite(boolean immediate) {
652
		System.err.println("deactivateSite"); //$NON-NLS-1$
653
		// Deactivate the nested services from the last active service locator.
654
		if (activeServiceLocator != null) {
655
			activeServiceLocator.deactivate();
656
			activeServiceLocator = null;
657
		}
658
659
		final int pageIndex = getActivePage();
660
		final IKeyBindingService service = getSite().getKeyBindingService();
661
		if (pageIndex < 0 || pageIndex >= getPageCount() || immediate) {
662
			// There is no selected page, so deactivate the active service.
663
			if (service instanceof INestableKeyBindingService) {
664
				final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
665
				nestableService.activateKeyBindingService(null);
666
			} else {
667
				WorkbenchPlugin
668
						.log("MultiPageEditorPart.setFocus()   Parent key binding service was not an instance of INestableKeyBindingService.  It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
669
			}
670
			return;
671
		}
672
	}
673
	
674
	/**
675
	 * This method can be used by implementors of
676
	 * {@link #createPageContainer(Composite)} to activate the active inner
677
	 * editor services when their header loses focus.
678
	 * <p>
679
	 * An new inner editor will have its site activated on a
680
	 * {@link #pageChange(int)}.
681
	 * </p>
682
	 * <p>
683
	 * <b>Note:</b> This API is evolving in 3.4 and this might not be its final
684
	 * form.
685
	 * </p>
686
	 * 
687
	 * @since 3.4
688
	 * @see #deactivateSite()
689
	 * @see #createPageContainer(Composite)
690
	 */
691
	protected final void activateSite() {
692
		System.err.println("activateSite"); //$NON-NLS-1$
693
		final IKeyBindingService service = getSite().getKeyBindingService();
694
		final int pageIndex = getActivePage();
695
		final IEditorPart editor = getEditor(pageIndex);
696
697
		if (editor != null) {
698
			// active the service for this inner editor
699
			if (service instanceof INestableKeyBindingService) {
700
				final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
701
				nestableService.activateKeyBindingService(editor
702
						.getEditorSite());
703
704
			} else {
705
				WorkbenchPlugin
706
						.log("MultiPageEditorPart.setFocus()   Parent key binding service was not an instance of INestableKeyBindingService.  It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
707
			}
708
			// Activate the services for the new service locator.
709
			final IServiceLocator serviceLocator = editor.getEditorSite();
710
			if (serviceLocator instanceof INestable) {
711
				activeServiceLocator = (INestable) serviceLocator;
712
				activeServiceLocator.activate();
713
			}
714
715
		} else {
716
			// There is no selected editor, so deactivate the active service.
717
			if (service instanceof INestableKeyBindingService) {
718
				final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
719
				nestableService.activateKeyBindingService(null);
720
			} else {
721
				WorkbenchPlugin
722
						.log("MultiPageEditorPart.setFocus()   Parent key binding service was not an instance of INestableKeyBindingService.  It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
723
			}
724
		}
630
	}
725
	}
631
726
632
	/**
727
	/**
Lines 731-776 Link Here
731
	 *            the index of the page
826
	 *            the index of the page
732
	 */
827
	 */
733
	private void setFocus(int pageIndex) {
828
	private void setFocus(int pageIndex) {
734
		final IKeyBindingService service = getSite().getKeyBindingService();
735
		if (pageIndex < 0 || pageIndex >= getPageCount()) {
736
			// There is no selected page, so deactivate the active service.
737
			if (service instanceof INestableKeyBindingService) {
738
				final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
739
				nestableService.activateKeyBindingService(null);
740
			} else {
741
				WorkbenchPlugin
742
						.log("MultiPageEditorPart.setFocus()   Parent key binding service was not an instance of INestableKeyBindingService.  It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
743
			}
744
			return;
745
		}
746
747
		final IEditorPart editor = getEditor(pageIndex);
829
		final IEditorPart editor = getEditor(pageIndex);
748
		if (editor != null) {
830
		if (editor != null) {
749
			editor.setFocus();
831
			editor.setFocus();
750
			// There is no selected page, so deactivate the active service.
751
			if (service instanceof INestableKeyBindingService) {
752
				final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
753
				if (editor != null) {
754
					nestableService.activateKeyBindingService(editor
755
							.getEditorSite());
756
				} else {
757
					nestableService.activateKeyBindingService(null);
758
				}
759
			} else {
760
				WorkbenchPlugin
761
						.log("MultiPageEditorPart.setFocus()   Parent key binding service was not an instance of INestableKeyBindingService.  It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
762
			}
763
832
764
		} else {
833
		} else {
765
			// There is no selected editor, so deactivate the active service.
766
			if (service instanceof INestableKeyBindingService) {
767
				final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;
768
				nestableService.activateKeyBindingService(null);
769
			} else {
770
				WorkbenchPlugin
771
						.log("MultiPageEditorPart.setFocus()   Parent key binding service was not an instance of INestableKeyBindingService.  It was an instance of " + service.getClass().getName() + " instead."); //$NON-NLS-1$ //$NON-NLS-2$
772
			}
773
774
			// Give the page's control focus.
834
			// Give the page's control focus.
775
			final Control control = getControl(pageIndex);
835
			final Control control = getControl(pageIndex);
776
			if (control != null) {
836
			if (control != null) {

Return to bug 184074