Skip to content

Commit

Permalink
complement for item of #2955
Browse files Browse the repository at this point in the history
  • Loading branch information
hqnghi88 committed Feb 7, 2022
1 parent 0c6c8a1 commit 6d3331b
Showing 1 changed file with 32 additions and 4 deletions.
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.actions.SelectionListenerAction;
import org.eclipse.ui.navigator.CommonActionProvider;
Expand Down Expand Up @@ -72,15 +73,42 @@ public void run() {
revealAction.setEnabled(true);

setStartupAction = new SelectionListenerAction("Set as startup...") {

@Override
protected boolean updateSelection(IStructuredSelection selection) {
if (!super.updateSelection(selection)) return false;
setText("Set as startup...");
if (GamaPreferences.Interface.CORE_STARTUP_MODEL.getValue() && selection.getFirstElement() instanceof WrappedSyntacticContent) {
String path = FileUtils.constructAbsoluteFilePath(null,
((WrappedSyntacticContent) selection.getFirstElement()).getFile().getResource()
.getLocation().toOSString(),
true);
if (path != null) {
IGamaFile file_old = GamaPreferences.Interface.CORE_DEFAULT_MODEL.getValue();
if (file_old != null && file_old.exists(null) && file_old.getOriginalPath().equals(path)) {
setText("UnSet as startup...");
}
}
}
return true;
}

@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();

IGamaFile file_old = GamaPreferences.Interface.CORE_DEFAULT_MODEL.getValue();
if (GamaPreferences.Interface.CORE_STARTUP_MODEL.getValue() && file_old != null && file_old.exists(null) && file_old.getOriginalPath().equals(path)) {
GamaPreferences.Interface.CORE_STARTUP_MODEL.set(false).save();
}else {
GamaPreferences.Interface.CORE_STARTUP_MODEL.set(true).save();
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();
}
}
}

Expand Down

0 comments on commit 6d3331b

Please sign in to comment.