Skip to content

Commit

Permalink
add menu item for #2955
Browse files Browse the repository at this point in the history
  • Loading branch information
hqnghi88 committed Feb 6, 2022
1 parent 648b3fb commit 0c6c8a1
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;

import msi.gama.common.preferences.GamaPreferences;
import msi.gama.common.util.FileUtils;
import msi.gama.runtime.GAMA;
import msi.gama.util.file.GenericFile;
import msi.gama.util.file.IGamaFile;
import msi.gaml.operators.Files;
import msi.gaml.types.IType;
import ummisco.gama.ui.navigator.contents.WrappedExperimentContent;
import ummisco.gama.ui.navigator.contents.WrappedSyntacticContent;

Expand All @@ -30,7 +36,7 @@ public class GamlActionProvider extends CommonActionProvider {
WrappedSyntacticContent selection;

/** The reveal action. */
SelectionListenerAction runAction, revealAction;
SelectionListenerAction runAction, revealAction, setStartupAction;

/**
* Instantiates a new gaml action provider.
Expand Down Expand Up @@ -64,6 +70,23 @@ public void run() {
};
revealAction.setId("reveal.item");
revealAction.setEnabled(true);

setStartupAction = new SelectionListenerAction("Set as startup...") {
@Override
public void run() {
String path = FileUtils.constructAbsoluteFilePath(null,
selection.getFile().getResource().getLocation().toOSString(), true);
if (path != null) {
IGamaFile file = Files.from(null, path);
GamaPreferences.Interface.CORE_DEFAULT_MODEL.setValue(null, file);
GamaPreferences.Interface.CORE_DEFAULT_MODEL.save();
GamaPreferences.Interface.CORE_DEFAULT_EXPERIMENT.set(selection.getElement().getName()).save();
}
}

};
setStartupAction.setId("startup.experiment");
setStartupAction.setEnabled(true);
}

@Override
Expand All @@ -74,6 +97,7 @@ public void fillContextMenu(final IMenuManager menu) {
menu.add(new Separator());
if (selection instanceof WrappedExperimentContent) {
menu.appendToGroup("group.copy", runAction);
menu.appendToGroup("group.copy", setStartupAction);
}
menu.appendToGroup("group.copy", revealAction);
}
Expand All @@ -92,6 +116,7 @@ public void updateActionBars() {
}
selection = (WrappedSyntacticContent) o;
runAction.selectionChanged(s);
setStartupAction.selectionChanged(s);
revealAction.selectionChanged(s);
}

Expand Down

0 comments on commit 0c6c8a1

Please sign in to comment.