diff options
author | Tom Schindl | 2016-04-24 11:32:32 +0000 |
---|---|---|
committer | Tom Schindl | 2016-04-24 11:32:32 +0000 |
commit | 74625217cc37098de733c3e278a28a571d639be9 (patch) | |
tree | 95c5c4aa719e5bcf66144f172ea412001dddafdb | |
parent | f40299f8363dddf04eaacbb2eac7166d8a6fdf6d (diff) | |
download | org.eclipse.efxclipse-74625217cc37098de733c3e278a28a571d639be9.tar.gz org.eclipse.efxclipse-74625217cc37098de733c3e278a28a571d639be9.tar.xz org.eclipse.efxclipse-74625217cc37098de733c3e278a28a571d639be9.zip |
Bug 492316 - PerspectiveSwitcherNode should only show perspectives opened since the beginning
-rw-r--r-- | bundles/runtime/org.eclipse.fx.ui.workbench.fx/src/org/eclipse/fx/ui/workbench/fx/perspective/PerspectiveSwitcherNode.java | 88 |
1 files changed, 66 insertions, 22 deletions
diff --git a/bundles/runtime/org.eclipse.fx.ui.workbench.fx/src/org/eclipse/fx/ui/workbench/fx/perspective/PerspectiveSwitcherNode.java b/bundles/runtime/org.eclipse.fx.ui.workbench.fx/src/org/eclipse/fx/ui/workbench/fx/perspective/PerspectiveSwitcherNode.java index 9f9e77e73..c8de3af6f 100644 --- a/bundles/runtime/org.eclipse.fx.ui.workbench.fx/src/org/eclipse/fx/ui/workbench/fx/perspective/PerspectiveSwitcherNode.java +++ b/bundles/runtime/org.eclipse.fx.ui.workbench.fx/src/org/eclipse/fx/ui/workbench/fx/perspective/PerspectiveSwitcherNode.java @@ -10,6 +10,7 @@ *******************************************************************************/
package org.eclipse.fx.ui.workbench.fx.perspective;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -19,7 +20,6 @@ import javax.inject.Inject; import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MHandlerContainer;
-import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
@@ -29,8 +29,11 @@ import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.emf.common.util.URI;
import org.eclipse.fx.core.command.CommandService;
+import org.eclipse.fx.core.preferences.Preference;
+import org.eclipse.fx.core.preferences.Value;
import org.eclipse.fx.ui.services.resources.GraphicsLoader;
import org.eclipse.fx.ui.workbench.fx.EMFUri;
+import org.eclipse.jdt.annotation.Nullable;
import org.osgi.service.event.Event;
import javafx.geometry.Orientation;
@@ -47,17 +50,27 @@ public class PerspectiveSwitcherNode extends HBox { private final EPartService partService;
private final GraphicsLoader loader;
private final MPerspectiveStack stack;
- private final boolean hasDialogButton;
private static final String STYLESHEET_URL = PerspectiveSwitcherNode.class.getResource("default.css").toExternalForm(); //$NON-NLS-1$
+
+ private final Value<List<String>> lastPerspectives;
+
@Inject
- PerspectiveSwitcherNode(IEventBroker eventBroker, GraphicsLoader loader, MApplication application, MWindow window, MHandlerContainer handlerContainer, EPartService partService, EModelService modelService, CommandService commandService) {
+ PerspectiveSwitcherNode(IEventBroker eventBroker,
+ GraphicsLoader loader,
+ MApplication application,
+ MWindow window,
+ MHandlerContainer handlerContainer,
+ EPartService partService,
+ EModelService modelService,
+ CommandService commandService,
+ @Preference(key="perspectiveOrder") Value<List<String>> lastPerspectives) {
getStyleClass().add("perspective-switcher"); //$NON-NLS-1$
+ this.lastPerspectives = lastPerspectives;
this.loader = loader;
this.partService = partService;
eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT, this::handleSelectedElement);
- eventBroker.subscribe(UIEvents.UIElement.TOPIC_TOBERENDERED, this::handledRendered);
Button dialogbutton = new Button();
dialogbutton.getStyleClass().add("dialog-opener"); //$NON-NLS-1$
@@ -83,9 +96,6 @@ public class PerspectiveSwitcherNode extends HBox { Separator separator = new Separator();
separator.setOrientation(Orientation.VERTICAL);
getChildren().addAll(dialogbutton, separator);
- this.hasDialogButton = true;
- } else {
- this.hasDialogButton = false;
}
if (window.getChildren().get(0) instanceof MPerspectiveStack) {
@@ -95,11 +105,47 @@ public class PerspectiveSwitcherNode extends HBox { }
if (this.stack != null) {
- MPerspective selected = this.stack.getSelectedElement();
- getChildren().addAll(this.stack.getChildren().stream().filter(p -> p.isToBeRendered()).map(p -> new PerspectiveButton(loader, p, partService, p == selected)).collect(Collectors.toList()));
+ MPerspective tmp = this.stack.getSelectedElement();
+ if( tmp == null && ! this.stack.getChildren().isEmpty() ) {
+ tmp = this.stack.getChildren().get(0);
+ }
+ MPerspective selected = tmp;
+ @Nullable
+ List<String> value = lastPerspectives.getValue();
+ if( value != null && ! value.isEmpty() ) {
+ List<PerspectiveButton> buttonList = this.stack.getChildren().stream()
+ .filter( p -> p.isToBeRendered())
+ .filter( p -> value.contains(p.getElementId()))
+ .map( p -> new PerspectiveButton(loader,p,partService, p == selected))
+ .collect(Collectors.toList());
+ if( selected != null && ! value.contains(selected.getElementId()) ) {
+ buttonList.add(new PerspectiveButton(loader,selected,partService, true));
+ publishNewPerspectiveList(selected.getElementId());
+ }
+ getChildren().addAll(buttonList);
+ } else {
+ if( selected != null ) {
+ getChildren().add(new PerspectiveButton(loader,selected,partService,true));
+ publishNewPerspectiveList(selected.getElementId());
+ }
+ }
}
}
+ private void publishNewPerspectiveList(String newPerspective) {
+ List<String> value = this.lastPerspectives.getValue();
+ if( value == null ) {
+ value = new ArrayList<>();
+ } else {
+ value = new ArrayList<>(value);
+ }
+
+ if( ! value.contains(newPerspective) ) {
+ value.add(newPerspective);
+ }
+ this.lastPerspectives.publish(value);
+ }
+
@Override
public String getUserAgentStylesheet() {
return STYLESHEET_URL;
@@ -108,20 +154,18 @@ public class PerspectiveSwitcherNode extends HBox { private void handleSelectedElement(Event event) {
if (event.getProperty(EventTags.ELEMENT) == this.stack) {
MPerspective p = (MPerspective) event.getProperty(EventTags.NEW_VALUE);
- getChildren().stream().filter(n -> n instanceof PerspectiveButton).map(n -> (PerspectiveButton) n).forEach(b -> b.setSelected(b.perspective == p));
- }
- }
- private void handledRendered(Event event) {
- if (event.getProperty(EventTags.ELEMENT) instanceof MPerspective) {
- MPerspective p = (MPerspective) event.getProperty(EventTags.ELEMENT);
- if ((MUIElement) p.getParent() == this.stack) {
- if (p.isToBeRendered()) {
- PerspectiveButton b = new PerspectiveButton(this.loader, p, this.partService, this.stack.getSelectedElement() == p);
- List<MPerspective> visibleList = this.stack.getChildren().stream().filter(pp -> pp.isToBeRendered()).collect(Collectors.toList());
- getChildren().add(visibleList.indexOf(p) + (this.hasDialogButton ? 2 : 0), b);
- } else {
- getChildren().removeIf(b -> b instanceof PerspectiveButton && ((PerspectiveButton) b).perspective == p);
+ if( p != null ) {
+ getChildren().stream().filter(n -> n instanceof PerspectiveButton).map(n -> (PerspectiveButton) n).forEach(b -> b.setSelected(b.perspective == p));
+
+ if( ! getChildren().stream()
+ .filter(n -> n instanceof PerspectiveButton)
+ .map(n -> (PerspectiveButton) n)
+ .filter( pe -> pe.perspective == p)
+ .findFirst()
+ .isPresent() ) {
+ getChildren().add(new PerspectiveButton(this.loader, p, this.partService, true));
+ publishNewPerspectiveList(p.getElementId());
}
}
}
|