1 /*******************************************************************************
2 * Copyright (C) 2016 Thomas Wolf <thomas.wolf@paranor.ch>.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org
.eclipse
.egit
.ui
.internal
.commit
;
13 import org
.eclipse
.jface
.action
.IAction
;
14 import org
.eclipse
.ui
.IActionBars
;
15 import org
.eclipse
.ui
.IEditorActionBarContributor
;
16 import org
.eclipse
.ui
.IEditorPart
;
17 import org
.eclipse
.ui
.SubActionBars
;
18 import org
.eclipse
.ui
.editors
.text
.TextEditorActionContributor
;
19 import org
.eclipse
.ui
.forms
.editor
.IFormPage
;
20 import org
.eclipse
.ui
.part
.MultiPageEditorActionBarContributor
;
21 import org
.eclipse
.ui
.texteditor
.ITextEditor
;
24 * An {@link IEditorActionBarContributor} for the {@link CommitEditor} that
25 * provides and properly activates and deactivates a
26 * {@link TextEditorActionContributor} for any page that is an
27 * {@link ITextEditor}.
29 public class CommitEditorActionBarContributor
30 extends MultiPageEditorActionBarContributor
{
32 private TextEditorActionContributor textActionContributor
= new TextEditorActionContributor();
34 private SubActionBars textEditorBars
;
36 private IFormPage currentPage
;
39 public void init(IActionBars bars
) {
41 textEditorBars
= new SubActionBars(bars
);
42 textActionContributor
.init(textEditorBars
);
46 public void dispose() {
47 textActionContributor
.dispose();
48 textEditorBars
.dispose();
53 public void setActivePage(IEditorPart activeEditor
) {
54 IFormPage formerPage
= currentPage
;
55 if (activeEditor
instanceof IFormPage
) {
56 currentPage
= (IFormPage
) activeEditor
;
60 if (formerPage
!= null && !formerPage
.isEditor()
61 && currentPage
!= null && !currentPage
.isEditor()) {
62 getActionBars().updateActionBars();
65 boolean isTextEditor
= currentPage
instanceof ITextEditor
;
66 if (isTextEditor
&& currentPage
== formerPage
) {
69 getTextEditorActionContributor().setActiveEditor(currentPage
);
70 updateTextEditorContributions(isTextEditor
);
71 getActionBars().updateActionBars();
74 private void updateTextEditorContributions(boolean activate
) {
75 IActionBars rootBars
= getActionBars();
76 rootBars
.clearGlobalActionHandlers();
78 textEditorBars
.activate();
79 Map
<?
, ?
> handlers
= textEditorBars
.getGlobalActionHandlers();
80 if (handlers
!= null) {
81 for (Map
.Entry
<?
, ?
> entry
: handlers
.entrySet()) {
82 Object key
= entry
.getKey();
83 Object value
= entry
.getValue();
84 if (key
instanceof String
&& value
instanceof IAction
) {
85 rootBars
.setGlobalActionHandler((String
) key
,
91 textEditorBars
.deactivate();
96 * Gets the nested contributor for {@link ITextEditor}s.
98 * @return the {@link IEditorActionBarContributor}
100 public IEditorActionBarContributor
getTextEditorActionContributor() {
101 return textActionContributor
;