blob: 6aa49d0f86aba1a322d5cbbc958104e89da8486d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*******************************************************************************
* Copyright (c) 2000, 2014 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal;
import java.util.ArrayList;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
/**
* This class reads the registry for extensions that plug into 'editorActions'
* extension point.
*/
public class EditorActionBuilder extends PluginActionBuilder {
private static final String TAG_CONTRIBUTION_TYPE = "editorContribution"; //$NON-NLS-1$
/**
* The constructor.
*/
public EditorActionBuilder() {
}
@Override
protected ActionDescriptor createActionDescriptor(IConfigurationElement element) {
return new ActionDescriptor(element, ActionDescriptor.T_EDITOR);
}
@Override
protected BasicContribution createContribution() {
return new EditorContribution();
}
/**
* Reads and apply all external contributions for this editor's ID registered in
* 'editorActions' extension point.
*/
public IEditorActionBarContributor readActionExtensions(IEditorDescriptor desc) {
ExternalContributor ext = null;
readContributions(desc.getId(), TAG_CONTRIBUTION_TYPE, IWorkbenchRegistryConstants.PL_EDITOR_ACTIONS);
if (cache != null) {
ext = new ExternalContributor(cache);
cache = null;
}
return ext;
}
/**
* Helper class to collect the menus and actions defined within a contribution
* element.
*/
private static class EditorContribution extends BasicContribution {
@Override
public void dispose() {
disposeActions();
super.dispose();
}
public void editorChanged(IEditorPart editor) {
if (actions != null) {
for (int i = 0; i < actions.size(); i++) {
ActionDescriptor ad = (ActionDescriptor) actions.get(i);
EditorPluginAction action = (EditorPluginAction) ad.getAction();
action.editorChanged(editor);
}
}
}
}
/**
* Helper class that will populate the menu and toobar with the external editor
* contributions.
*/
public static class ExternalContributor implements IEditorActionBarContributor {
private ArrayList cache;
public ExternalContributor(ArrayList cache) {
this.cache = cache;
}
@Override
public void dispose() {
for (int i = 0; i < cache.size(); i++) {
((EditorContribution) cache.get(i)).dispose();
}
}
public ActionDescriptor[] getExtendedActions() {
ArrayList results = new ArrayList();
for (int i = 0; i < cache.size(); i++) {
EditorContribution ec = (EditorContribution) cache.get(i);
if (ec.actions != null) {
results.addAll(ec.actions);
}
}
return (ActionDescriptor[]) results.toArray(new ActionDescriptor[results.size()]);
}
@Override
public void init(IActionBars bars, IWorkbenchPage page) {
for (int i = 0; i < cache.size(); i++) {
((EditorContribution) cache.get(i)).contribute(bars.getMenuManager(), false, bars.getToolBarManager(),
true);
}
}
@Override
public void setActiveEditor(IEditorPart editor) {
for (int i = 0; i < cache.size(); i++) {
((EditorContribution) cache.get(i)).editorChanged(editor);
}
}
}
}
|