package jetbrains.mps.ide.editor.actions; /*Generated by MPS */ import jetbrains.mps.workbench.action.BaseAction; import javax.swing.Icon; import com.intellij.openapi.actionSystem.AnActionEvent; import java.util.Map; import org.jetbrains.annotations.NotNull; import com.intellij.openapi.project.Project; import com.intellij.openapi.actionSystem.CommonDataKeys; import jetbrains.mps.internal.collections.runtime.MapSequence; import jetbrains.mps.nodeEditor.EditorComponent; import jetbrains.mps.ide.editor.MPSEditorDataKeys; import jetbrains.mps.nodeEditor.hintsSettings.ConceptEditorHintSettings; import jetbrains.mps.smodel.language.LanguageRegistry; import com.intellij.openapi.application.ApplicationManager; import java.util.Collections; import jetbrains.mps.internal.collections.runtime.SetSequence; import java.util.HashSet; import jetbrains.mps.nodeEditor.hintsSettings.ConceptEditorHintPreferencesPage; import com.intellij.openapi.ui.DialogWrapper; public class PushEditorHints_Action extends BaseAction { private static final Icon ICON = null; public PushEditorHints_Action() { super("Push Editor Hints", "", ICON); this.setIsAlwaysVisible(false); this.setExecuteOutsideCommand(false); } @Override public boolean isDumbAware() { return true; } @Override public boolean isApplicable(AnActionEvent event, final Map<String, Object> _params) { return true; } @Override public void doUpdate(@NotNull AnActionEvent event, final Map<String, Object> _params) { this.setEnabledState(event.getPresentation(), this.isApplicable(event, _params)); } @Override protected boolean collectActionData(AnActionEvent event, final Map<String, Object> _params) { if (!(super.collectActionData(event, _params))) { return false; } { Project p = event.getData(CommonDataKeys.PROJECT); MapSequence.fromMap(_params).put("project", p); if (p == null) { return false; } } { EditorComponent editorComponent = event.getData(MPSEditorDataKeys.EDITOR_COMPONENT); if (editorComponent != null && editorComponent.isInvalid()) { editorComponent = null; } MapSequence.fromMap(_params).put("editorComponent", editorComponent); if (editorComponent == null) { return false; } } return true; } @Override public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) { final ConceptEditorHintSettings settings = new ConceptEditorHintSettings(LanguageRegistry.getInstance().getAvailableLanguages()); ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { String[] initialEditorHints = ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent")).getUpdater().getInitialEditorHints(); settings.updateSettings((initialEditorHints == null ? Collections.<String>emptySet() : SetSequence.fromSetAndArray(new HashSet<String>(), initialEditorHints))); final ConceptEditorHintPreferencesPage page = new ConceptEditorHintPreferencesPage(settings); DialogWrapper dialog = new HintsDialog(((Project) MapSequence.fromMap(_params).get("project")), page, settings, ((EditorComponent) MapSequence.fromMap(_params).get("editorComponent"))); dialog.show(); } }); } }