Skip to content

Commit 64055c5

Browse files
Toolbar: fixes scene switcher label in multiple windows.
1 parent 845c22e commit 64055c5

File tree

9 files changed

+676
-482
lines changed

9 files changed

+676
-482
lines changed

source/v2/phasereditor/phasereditor.ide/src/phasereditor/ide/ui/HugeToolbar.java

Lines changed: 0 additions & 482 deletions
This file was deleted.

source/v2/phasereditor/phasereditor.ide/src/phasereditor/ide/ui/MyRenderFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.eclipse.e4.ui.workbench.renderers.swt.WorkbenchRendererFactory;
3030
import org.eclipse.swt.widgets.Shell;
3131

32+
import phasereditor.ide.ui.toolbar.HugeToolbar;
33+
3234
/**
3335
* @author arian
3436
*
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2015, 2019 Arian Fornaris
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a
6+
// copy of this software and associated documentation files (the
7+
// "Software"), to deal in the Software without restriction, including
8+
// without limitation the rights to use, copy, modify, merge, publish,
9+
// distribute, sublicense, and/or sell copies of the Software, and to permit
10+
// persons to whom the Software is furnished to do so, subject to the
11+
// following conditions: The above copyright notice and this permission
12+
// notice shall be included in all copies or substantial portions of the
13+
// Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
package phasereditor.ide.ui.toolbar;
23+
24+
import static phasereditor.ui.IEditorSharedImages.IMG_ALIEN_EDITOR;
25+
26+
import org.eclipse.jface.util.IPropertyChangeListener;
27+
import org.eclipse.swt.SWT;
28+
import org.eclipse.swt.events.SelectionListener;
29+
import org.eclipse.swt.layout.RowData;
30+
import org.eclipse.swt.widgets.Button;
31+
import org.eclipse.swt.widgets.Composite;
32+
33+
import phasereditor.project.core.ProjectCore;
34+
import phasereditor.ui.EditorSharedImages;
35+
import phasereditor.ui.PhaserEditorUI;
36+
37+
class AlienEditorWrapper {
38+
private Button _btn;
39+
40+
public AlienEditorWrapper(Composite parent) {
41+
_btn = new Button(parent, SWT.PUSH);
42+
_btn.setText("Editor");
43+
_btn.setToolTipText("Open this project in the configured External Editor.");
44+
_btn.setImage(EditorSharedImages.getImage(IMG_ALIEN_EDITOR));
45+
_btn.addSelectionListener(SelectionListener
46+
.widgetSelectedAdapter(e -> PhaserEditorUI.externalEditor_openProject(ProjectCore.getActiveProject())));
47+
48+
{
49+
IPropertyChangeListener listener = e -> {
50+
if (PhaserEditorUI.PREF_PROP_ALIEN_EDITOR_ENABLED.equals(e.getProperty())) {
51+
updateButton();
52+
}
53+
};
54+
PhaserEditorUI.getPreferenceStore().addPropertyChangeListener(listener);
55+
_btn.addDisposeListener(e -> PhaserEditorUI.getPreferenceStore().removePropertyChangeListener(listener));
56+
}
57+
58+
updateButton();
59+
}
60+
61+
private void updateButton() {
62+
var visible = PhaserEditorUI.externalEditor_enabled();
63+
_btn.setLayoutData(new RowData(visible ? SWT.DEFAULT : 0, visible ? SWT.DEFAULT : 0));
64+
_btn.getParent().requestLayout();
65+
}
66+
67+
public Button getButton() {
68+
return _btn;
69+
}
70+
71+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2015, 2019 Arian Fornaris
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a
6+
// copy of this software and associated documentation files (the
7+
// "Software"), to deal in the Software without restriction, including
8+
// without limitation the rights to use, copy, modify, merge, publish,
9+
// distribute, sublicense, and/or sell copies of the Software, and to permit
10+
// persons to whom the Software is furnished to do so, subject to the
11+
// following conditions: The above copyright notice and this permission
12+
// notice shall be included in all copies or substantial portions of the
13+
// Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
package phasereditor.ide.ui.toolbar;
23+
24+
import org.eclipse.core.commands.ExecutionEvent;
25+
import org.eclipse.swt.SWT;
26+
import org.eclipse.swt.events.MouseAdapter;
27+
import org.eclipse.swt.events.MouseEvent;
28+
import org.eclipse.swt.events.SelectionListener;
29+
import org.eclipse.swt.widgets.Button;
30+
import org.eclipse.swt.widgets.Composite;
31+
import org.eclipse.ui.PlatformUI;
32+
import org.eclipse.ui.commands.ICommandService;
33+
34+
import phasereditor.ide.IDEPlugin;
35+
import phasereditor.ide.ui.StartPerspective;
36+
import phasereditor.project.ui.ProjectUI;
37+
38+
class GoHomeWrapper {
39+
public GoHomeWrapper(Composite parent) {
40+
var btn = new Button(parent, SWT.PUSH);
41+
var homePersp = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(StartPerspective.ID);
42+
btn.setImage(PerspectiveSwitcherWrapper.getPerspectiveIcon(homePersp));
43+
btn.addSelectionListener(SelectionListener.widgetSelectedAdapter(
44+
e -> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPerspective(homePersp)));
45+
btn.addMouseListener(new MouseAdapter() {
46+
@Override
47+
public void mouseUp(MouseEvent e) {
48+
if (e.button == 3) {
49+
var serv = PlatformUI.getWorkbench().getService(ICommandService.class);
50+
try {
51+
serv.getCommand(ProjectUI.CMD_OPEN_PROJECT).executeWithChecks(new ExecutionEvent());
52+
} catch (Exception e1) {
53+
IDEPlugin.logError(e1);
54+
}
55+
}
56+
}
57+
});
58+
}
59+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2015, 2019 Arian Fornaris
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a
6+
// copy of this software and associated documentation files (the
7+
// "Software"), to deal in the Software without restriction, including
8+
// without limitation the rights to use, copy, modify, merge, publish,
9+
// distribute, sublicense, and/or sell copies of the Software, and to permit
10+
// persons to whom the Software is furnished to do so, subject to the
11+
// following conditions: The above copyright notice and this permission
12+
// notice shall be included in all copies or substantial portions of the
13+
// Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
package phasereditor.ide.ui.toolbar;
23+
24+
import static phasereditor.ui.PhaserEditorUI.getWorkbenchWindow;
25+
import static phasereditor.ui.PhaserEditorUI.swtRun;
26+
27+
import org.eclipse.swt.SWT;
28+
import org.eclipse.swt.events.ControlEvent;
29+
import org.eclipse.swt.events.ControlListener;
30+
import org.eclipse.swt.layout.GridData;
31+
import org.eclipse.swt.layout.GridLayout;
32+
import org.eclipse.swt.layout.RowData;
33+
import org.eclipse.swt.layout.RowLayout;
34+
import org.eclipse.swt.widgets.Composite;
35+
import org.eclipse.swt.widgets.Label;
36+
import org.eclipse.ui.IEditorPart;
37+
import org.eclipse.ui.IWorkbenchPage;
38+
import org.eclipse.ui.IWorkbenchPart;
39+
import org.eclipse.ui.IWorkbenchWindow;
40+
import org.eclipse.ui.PlatformUI;
41+
42+
import phasereditor.ui.IEditorHugeToolbar;
43+
import phasereditor.ui.ISuperWorkbenchListener;
44+
45+
public class HugeToolbar extends Composite implements ISuperWorkbenchListener {
46+
47+
private Composite _centerArea;
48+
private IEditorPart _activeEditor;
49+
private IWorkbenchWindow _window;
50+
51+
@SuppressWarnings("unused")
52+
public HugeToolbar(Composite parent) {
53+
super(parent, 0);
54+
55+
var gridLayout = new GridLayout(3, false);
56+
gridLayout.marginWidth = gridLayout.marginHeight = 0;
57+
setLayout(gridLayout);
58+
59+
parent.addControlListener(new ControlListener() {
60+
61+
@Override
62+
public void controlResized(ControlEvent e) {
63+
updateBounds();
64+
}
65+
66+
@Override
67+
public void controlMoved(ControlEvent e) {
68+
updateBounds();
69+
}
70+
});
71+
72+
var layout = new RowLayout();
73+
layout.marginWidth = layout.marginHeight = 0;
74+
layout.center = true;
75+
76+
var leftArea = new Composite(this, 0);
77+
leftArea.setLayout(layout);
78+
leftArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
79+
80+
{
81+
_centerArea = new Composite(this, 0);
82+
_centerArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
83+
_centerArea.setLayout(layout);
84+
}
85+
86+
var rightArea = new Composite(this, 0);
87+
rightArea.setLayout(layout);
88+
89+
new GoHomeWrapper(leftArea);
90+
new NewMenuWrapper(leftArea);
91+
new RunProjectWrapper(leftArea);
92+
new AlienEditorWrapper(leftArea);
93+
new QuickAccessWrapper(rightArea);
94+
95+
{
96+
var sep = new Label(rightArea, SWT.SEPARATOR);
97+
sep.setLayoutData(new RowData(SWT.DEFAULT, 15));
98+
}
99+
100+
new PerspectiveSwitcherWrapper(rightArea);
101+
102+
updateBounds();
103+
104+
// run async because the window is not finished
105+
swtRun(() -> {
106+
_window = getWorkbenchWindow(parent);
107+
108+
if (_window == null) {
109+
return;
110+
}
111+
112+
_window.addPageListener(this);
113+
pageOpened(_window.getActivePage());
114+
});
115+
116+
}
117+
118+
private void updateBounds() {
119+
var size = computeSize(SWT.DEFAULT, SWT.DEFAULT);
120+
setBounds(0, 0, getParent().getClientArea().width, size.y);
121+
}
122+
123+
private void updateWithCurrentEditor() {
124+
var editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
125+
if (editor == _activeEditor) {
126+
return;
127+
}
128+
129+
for (var c : _centerArea.getChildren()) {
130+
c.dispose();
131+
}
132+
133+
var editorToolbar = editor.getAdapter(IEditorHugeToolbar.class);
134+
if (editorToolbar != null) {
135+
editorToolbar.createContent(_centerArea);
136+
}
137+
138+
_centerArea.requestLayout();
139+
}
140+
141+
@Override
142+
public void pageOpened(IWorkbenchPage page) {
143+
page.addPartListener(this);
144+
updateWithCurrentEditor();
145+
}
146+
147+
@Override
148+
public void pageClosed(IWorkbenchPage page) {
149+
page.removePartListener(this);
150+
}
151+
152+
@Override
153+
public void partActivated(IWorkbenchPart part) {
154+
updateWithCurrentEditor();
155+
}
156+
157+
@Override
158+
public void partClosed(IWorkbenchPart part) {
159+
updateWithCurrentEditor();
160+
}
161+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2015, 2019 Arian Fornaris
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a
6+
// copy of this software and associated documentation files (the
7+
// "Software"), to deal in the Software without restriction, including
8+
// without limitation the rights to use, copy, modify, merge, publish,
9+
// distribute, sublicense, and/or sell copies of the Software, and to permit
10+
// persons to whom the Software is furnished to do so, subject to the
11+
// following conditions: The above copyright notice and this permission
12+
// notice shall be included in all copies or substantial portions of the
13+
// Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
package phasereditor.ide.ui.toolbar;
23+
24+
import org.eclipse.swt.SWT;
25+
import org.eclipse.swt.events.SelectionListener;
26+
import org.eclipse.swt.widgets.Button;
27+
import org.eclipse.swt.widgets.Composite;
28+
import org.eclipse.ui.PlatformUI;
29+
import org.eclipse.ui.actions.NewWizardDropDownAction;
30+
31+
import phasereditor.ide.ui.wizards.NewWizardLauncherDialog;
32+
33+
class NewMenuWrapper {
34+
35+
private Button _btn;
36+
37+
public NewMenuWrapper(Composite parent) {
38+
_btn = new Button(parent, SWT.PUSH);
39+
_btn.setText("New");
40+
_btn.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
41+
var dlg = new NewWizardLauncherDialog(_btn.getShell());
42+
dlg.open();
43+
}));
44+
var action = new NewWizardDropDownAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
45+
_btn.setImage(action.getImageDescriptor().createImage());
46+
}
47+
48+
public Button getButton() {
49+
return _btn;
50+
}
51+
52+
}

0 commit comments

Comments
 (0)