@Override public void actionPerformed(AnActionEvent anActionEvent) { Project project = anActionEvent.getProject(); VirtualFile virtualFile = project.getBaseDir(); VirtualFile source = Utils.getSourceFile(virtualFile, null); Crowdin crowdin = new Crowdin(); String branch = Utils.getCurrentBranch(project); crowdin.exportTranslations(branch); File downloadTranslations = crowdin.downloadTranslations(source, branch); Utils.extractTranslations(downloadTranslations); if (downloadTranslations.delete()) { System.out.println("all.zip was deleted"); } else { System.out.println("all.zip wasn't deleted"); } }
@Override public void actionPerformed(final AnActionEvent event) { final Project project = event.getProject(); if (project == null) { return; } final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance() .createActionGroupPopup(TITLE, new PopupGroup(), event.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, true, event.getPlace()); JBPopupHelper.disableSpeedSearch(popup); JBPopupHelper.registerShiftActions(popup, TITLE, SHIFT_TITLE); JBPopupHelper.registerCtrlActions(popup, TITLE, CTRL_TITLE); popup.setAdText(AD_TEXT); popup.showCenteredInCurrentWindow(project); }
private void getTranslation(AnActionEvent event) { Editor mEditor = event.getData(PlatformDataKeys.EDITOR); Project project = event.getData(PlatformDataKeys.PROJECT); String basePath = project.getBasePath(); if (null == mEditor) { return; } SelectionModel model = mEditor.getSelectionModel(); String selectedText = model.getSelectedText(); if (TextUtils.isEmpty(selectedText)) { selectedText = getCurrentWords(mEditor); if (TextUtils.isEmpty(selectedText)) { return; } } String queryText = strip(addBlanks(selectedText)); new Thread(new RequestRunnable(mEditor, queryText,basePath)).start(); }
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } final AnswerPlaceholder answerPlaceholder = getAnswerPlaceholder(e); if (answerPlaceholder == null) { return; } StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project); if (studyEditor != null) { StudySubtaskUtils.refreshPlaceholder(studyEditor.getEditor(), answerPlaceholder); final StudyTaskManager taskManager = StudyTaskManager.getInstance(project); answerPlaceholder.reset(); taskManager.setStatus(answerPlaceholder, StudyStatus.Unchecked); } }
@Override public void actionPerformed(AnActionEvent e) { EduCoursesPanel panel = new EduCoursesPanel(); DialogBuilder dialogBuilder = new DialogBuilder().title("Select Course").centerPanel(panel); dialogBuilder.addOkAction().setText("Join"); panel.addCourseValidationListener(new EduCoursesPanel.CourseValidationListener() { @Override public void validationStatusChanged(boolean canStartCourse) { dialogBuilder.setOkActionEnabled(canStartCourse); } }); dialogBuilder.setOkOperation(() -> { dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE); Course course = panel.getSelectedCourse(); String location = panel.getLocationString(); EduCreateNewProjectDialog.createProject(EduPluginConfigurator.INSTANCE.forLanguage(course.getLanguageById()).getEduCourseProjectGenerator(), course, location); }); dialogBuilder.show(); }
@Override public void setSelected(AnActionEvent e, boolean state) { JGivenSettings.getInstance().setJGivenFilteringEnabled(state); if (e.getProject() == null) { return; } Set<Usage> scenarioStateUsages = usageView.getUsages().stream() .filter(u -> u instanceof ReadWriteAccessUsageInfo2UsageAdapter && scenarioStateAnnotationProvider.isJGivenScenarioState(((ReadWriteAccessUsageInfo2UsageAdapter) u).getElement())) .collect(Collectors.toSet()); if (state) { excludedUsages.stream() .filter(u -> !scenarioStateUsages.contains(u)) .forEach(usageView::appendUsage); } else { excludedUsages = usageView.getUsages().stream() .filter(scenarioStateUsages::contains) .collect(Collectors.toSet()); excludedUsages.forEach(usageView::removeUsage); } e.getProject().getMessageBus().syncPublisher(UsageFilteringRuleProvider.RULES_CHANGED).run(); }
public void actionPerformed( AnActionEvent e ) { Editor editor = ( Editor ) e.getDataContext().getData( "editor" ); SelectionModel selectionModel = editor.getSelectionModel(); if ( selectionModel != null ) { String selectedText = selectionModel.getSelectedText(); if ( selectedText != null && selectedText.trim().length() > 0 ) { Project project = ( Project ) e.getDataContext().getData( DataConstants.PROJECT ); String panelid = ( String ) project.getUserData( QuickNotes.KEY_PANELID ); QuickNotesPanel quickNotesPanel = QuickNotesManager.getInstance().getQuickNotesPanel( panelid ); if ( quickNotesPanel != null ) { FileDocumentManager manager = FileDocumentManager.getInstance(); VirtualFile virtualFile = manager.getFile( editor.getDocument() ); quickNotesPanel.addNewNote( "[File: " + virtualFile.getPath() + "]\n" + selectedText ); } } } }
@Override public void actionPerformed(AnActionEvent e) { RefmtManager refmt = RefmtManager.getInstance(); if (refmt != null) { PsiFile file = e.getData(PSI_FILE); Project project = e.getProject(); if (project != null && file != null && (file instanceof OclFile || file instanceof RmlFile)) { String format = file instanceof OclFile ? "ml" : "re"; Document document = PsiDocumentManager.getInstance(project).getDocument(file); if (document != null) { //WriteCommandAction.writeCommandAction(project).run(() -> refmt.refmt(project, format, document)); WriteCommandAction.runWriteCommandAction(project, () -> refmt.refmt(project, format, document)); // idea#143 } } } }
@Override public void actionPerformed(AnActionEvent anActionEvent) { final Project project = getEventProject(anActionEvent); if (project == null) { return; } removeOldProjectData(project); try { collectStatistics(); final AddModuleWizard wizard = getWizard(project); final ProjectBuilder projectBuilder = wizard.getProjectBuilder(); if (projectBuilder instanceof AbstractHybrisProjectImportBuilder) { ((AbstractHybrisProjectImportBuilder) projectBuilder).setRefresh(true); } projectBuilder.commit(project, null, ModulesProvider.EMPTY_MODULES_PROVIDER); } catch (ConfigurationException e) { Messages.showErrorDialog( anActionEvent.getProject(), e.getMessage(), HybrisI18NBundleUtils.message("hybris.project.import.error.unable.to.proceed") ); } }
@Override public void actionPerformed(@NotNull AnActionEvent event) { final Project project = getEventProject(event); if (project == null) { this.setStatus(event, false); return; } PsiDirectory bundleDirContext = ExtensionUtility.getExtensionDirectory(event); if (bundleDirContext == null) { return; } String className = Messages.showInputDialog(project, "New class name:", "New File", TYPO3CMSIcons.TYPO3_ICON); if (StringUtils.isBlank(className)) { return; } if (!PhpNameUtil.isValidClassName(className)) { JOptionPane.showMessageDialog(null, "Invalid class name"); return; } write(project, bundleDirContext, className); }
public void actionPerformed(AnActionEvent e) { this.project = e.getData(CommonDataKeys.PROJECT); String description = this.showInputDialog(SlackChannel.getIdDescription(), null); if (!isValidField(description)) { errorMessage(); return; } String token = this.showInputDialog(SlackChannel.getTokenDescription(), null); if (!isValidField(token)) { errorMessage(); return; } String channel = this.showInputDialog(SlackChannel.getChanneNameDescription(), ""); SlackStorage.getInstance().registerChannel(new SlackChannel(token, description, channel)); Messages.showMessageDialog(this.project, "Settings Saved.", "Information", Messages.getInformationIcon()); }
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); List<String> channelsId = SlackStorage.getInstance().getChannelsId(); if (channelsId.size() > 0) { String channelToRemove = Messages.showEditableChooseDialog( "Select the channel to remove", SlackChannel.getSettingsDescription(), SlackStorage.getSlackIcon(), channelsId.toArray(new String[channelsId.size()]), channelsId.get(0), null ); if (channelsId.contains(channelToRemove)) { SlackStorage.getInstance().removeChannelByDescription(channelToRemove); Messages.showMessageDialog(project, "Channel \"" + channelToRemove + "\" removed.", "Information", Messages.getInformationIcon()); } } }
@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); Project project = e.getProject(); if (project == null) { presentation.setEnabledAndVisible(false); return; } Course course = StudyTaskManager.getInstance(project).getCourse(); if (course == null || !course.isAdaptive()) { presentation.setEnabledAndVisible(false); return; } presentation.setEnabledAndVisible(true); }
@Override public void actionPerformed(AnActionEvent e) { cacheFile = new File(Constant.CACHE_PATH); if (!cacheFile.exists()) { cacheFile.mkdirs(); } long size = FileUtils.sizeOfDirectory(cacheFile); DialogBuilder builder = new DialogBuilder(); builder.setTitle(Constant.TITLE); builder.resizable(false); builder.setCenterPanel(new JLabel(String.format("Currently occupy storage %.2fM, " + "Clean Cache immediately?", size/1024.0/1024.0), Messages.getInformationIcon(), SwingConstants.CENTER)); builder.addOkAction().setText("Clean Now"); builder.addCancelAction().setText("Cancel"); builder.setButtonsAlignment(SwingConstants.RIGHT); if (builder.show() == 0) { clean(); } }
@Override public void actionPerformed(AnActionEvent e) { AbstractNewProjectDialog dialog = new AbstractNewProjectDialog() { @Override protected DefaultActionGroup createRootStep() { return new PyCCCreateCourseProjectStep(); } }; dialog.show(); }
/** * Tests that no further actions are taken when the editor is {@code null}. */ @Test public void testActionPerformedNullEditor() { final AnActionEvent event = mock(AnActionEvent.class); when(event.getData(CommonDataKeys.EDITOR)).thenReturn(null); dataInsertAction.actionPerformed(event); verify(event, times(1)).getData(CommonDataKeys.EDITOR); verifyNoMoreInteractions(event); }
@Override public void actionPerformed(AnActionEvent anActionEvent) { // 1. 显示CodeGroup新增dialog TemplateGroupEditDialog dialog = new TemplateGroupEditDialog(); dialog.setTitle("Create New Group"); dialog.getButtonOK().addActionListener(it -> { // 获取名称和level, 校验 String name = dialog.getNameTextField().getText(); String level = dialog.getLevelTextField().getText(); if (StringUtils.isBlank(name)) { showErrorBorder(dialog.getNameTextField(), true); return; } else { showErrorBorder(dialog.getNameTextField(), false); } if (StringUtils.isBlank(level)) { showErrorBorder(dialog.getLevelTextField(), true); return; } else { showErrorBorder(dialog.getLevelTextField(), false); } // 新增group addCodeGroup(new CodeGroup(name.trim(), Integer.valueOf(level.trim()))); dialog.setVisible(false); }); // 2. 显示dialog showDialog(dialog, 300, 150); }
@Nullable private static CommitMessageI getCommitPanel(@Nullable AnActionEvent e) { if (e == null) { return null; } Refreshable data = Refreshable.PANEL_KEY.getData(e.getDataContext()); if (data instanceof CommitMessageI) { return (CommitMessageI) data; } return VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.getDataContext()); }
@Override public final void update(AnActionEvent e) { this.dataContext = e.getDataContext(); final Presentation presentation = e.getPresentation(); final boolean enabled = isAvailable(dataContext); presentation.setVisible(enabled); presentation.setEnabled(enabled); }
@Override public void update(AnActionEvent e) { e.getPresentation().setVisible(myGeneralCommandLine != null); e.getPresentation().setEnabled(myGeneralCommandLine != null); if(displayName != null) { e.getPresentation().setText("Rerun '" + displayName + "'"); e.getPresentation().setDescription("Rerun '" + displayName + "'"); } else if(myGeneralCommandLine != null) { e.getPresentation().setText("Rerun '" + myGeneralCommandLine.getCommandLineString() + "'"); e.getPresentation().setDescription("Rerun '" + myGeneralCommandLine.getCommandLineString() + "'"); } }
@Override public void actionPerformed(@NotNull AnActionEvent e) { final Project project = e.getProject(); if (project == null) { return; } navigateToPlaceholder(project); }
@Nullable public static String getClassPath(@NotNull AnActionEvent event) { String packageName = null; PsiElement element = event.getData(LangDataKeys.PSI_ELEMENT); if (element == null) { return packageName; } if (element instanceof PsiClass) { PsiClass cls = (PsiClass) element; if (cls.getContainingClass() != null) { // 排除内部类的情况 packageName = cls.getContainingClass().getQualifiedName(); } else { packageName = cls.getQualifiedName(); } Log.debug("class => " + packageName); } else if (element instanceof PsiMethod) { PsiMethod method = (PsiMethod) element; Log.debug("method => " + method.getName() + " # " + method.getContainingClass().getQualifiedName()); packageName = method.getContainingClass().getQualifiedName(); } else if (element instanceof PsiVariable) { PsiVariable psiVariable = (PsiVariable) element; packageName = psiVariable.getType().getCanonicalText(); // 去除泛型 if (!Utils.isEmpty(packageName)) { packageName = packageName.replaceAll("<.*>", ""); } // FIXME: 2017/11/11 变量对应类是内部类会有问题 Log.debug("PsiVariable:" + psiVariable.getType().getCanonicalText()); } else { Log.debug("cls = " + element.getClass()); } return packageName; }
public static void triggerAction(final DataContext dataContext) { ApplicationManager.getApplication().invokeLater(() -> { final AnAction action = new ProjectRefreshAction(); final AnActionEvent actionEvent = AnActionEvent.createFromAnAction( action, null, ActionPlaces.UNKNOWN, dataContext ); action.actionPerformed(actionEvent); }, ModalityState.NON_MODAL); }
/** * Constructor used when we get notified by IDEA through {@link com.intellij.openapi.actionSystem.ex.AnActionListener} * * @param action action that was performed * @param event event that fired the action * @param source the source of the action */ KeyPromoterAction(AnAction action, AnActionEvent event, ActionSource source) { myMnemonic = event.getPresentation().getMnemonic(); myIdeaActionID = ActionManager.getInstance().getId(action); myDescription = event.getPresentation().getText(); mySource = source; myShortcut = KeyPromoterUtils.getKeyboardShortcutsText(myIdeaActionID); }
@Override public void actionPerformed(final AnActionEvent e) { final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext()); if (editor != null) { final SelectionModel selectionModel = editor.getSelectionModel(); final ValidateImpexHttpClient client = new ValidateImpexHttpClient(); final HybrisHttpResult hybrisHttpResult = client.validateImpex(selectionModel.getSelectedText()); ExecuteHybrisConsole.getInstance().show(hybrisHttpResult, e.getProject()); } }
@Override public void actionPerformed(AnActionEvent anActionEvent) { Project project = anActionEvent.getProject(); if (project != null) { try { initFiles(project); } catch (IOException e) { e.printStackTrace(); } if (TextUtils.isEmpty(apkPath)) { chooseAndSaveApkFile(project); } packageName = PropertiesManager.getData(project, PropertyKeys.PACKAGE_NAME); if (TextUtils.isEmpty(packageName)) { setPackageName(project); } isInnerClassEnabled = PropertiesManager.getData(project, PropertyKeys.IS_INNER_CLASS_ENABLE, Strings.TRUE); if (!TextUtils.isEmpty(apkPath) && !TextUtils.isEmpty(packageName)) { Task task = generateDependencyInjectionGraph(project); task.queue(); } } }
@Override public void actionPerformed(@NotNull AnActionEvent e) { CCState state = getState(e); if (state == null) { return; } performAnswerPlaceholderAction(state); }
@Override public boolean isSelected(AnActionEvent e) { Project project = e.getProject(); if (project == null) { return false; } return StudyTaskManager.getInstance(project).getToolWindowMode() == StudyToolWindow.StudyToolWindowMode.EDITING; }
@Override public void actionPerformed(AnActionEvent anActionEvent) { if (anActionEvent.getProject() != null) { CptUtil.getTemplateFile("javascript").ifPresent(file -> { CptUtil.openFileInEditor(anActionEvent.getProject(), file); }); } }
@Override public void update(@NotNull AnActionEvent event) { final Presentation presentation = event.getPresentation(); presentation.setEnabledAndVisible(false); final Project project = event.getData(CommonDataKeys.PROJECT); final IdeView view = event.getData(LangDataKeys.IDE_VIEW); if (project == null || view == null) { return; } if (!StudyUtils.isStudyProject(project) || !CCUtils.isCourseCreator(project)) { return; } final PsiDirectory[] directories = view.getDirectories(); if (directories.length == 0 || directories.length > 1) { return; } final PsiDirectory sourceDirectory = directories[0]; final Course course = StudyTaskManager.getInstance(project).getCourse(); if (course == null || sourceDirectory == null) { return; } if (!isAddedAsLast(sourceDirectory, project, course) && getThresholdItem(course, sourceDirectory) == null) { return; } if (CommonDataKeys.PSI_FILE.getData(event.getDataContext()) != null) { return; } presentation.setEnabledAndVisible(true); }
public void actionPerformed(AnActionEvent var1) { DataContext var2 = var1.getDataContext(); CopyProvider var3 = (CopyProvider) PlatformDataKeys.COPY_PROVIDER.getData(var2); if (var3 != null) { var3.performCopy(var2); String var4 = (String) CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); if (StringUtil.isNotEmpty(var4)) { BrowserUtil.browse("https://translate.google.com/#en/zh-CN/" + URLEncoder.encode(var4)); } } }
@Override public void update(AnActionEvent e) { Project project = e.getProject(); Presentation presentation = e.getPresentation(); if (project == null || !CCUtils.isCourseCreator(project)) { presentation.setEnabledAndVisible(false); return; } final VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(e.getDataContext()); if (virtualFiles == null || virtualFiles.length == 0) { presentation.setEnabledAndVisible(false); } }
@Nullable public AnAction getClickAction() { return new AnAction() { @Override public void actionPerformed(AnActionEvent e) { callProtractor(); } }; }
@Override public void update(AnActionEvent event) { super.update(event); setEnabledInModalContext(true); getTemplatePresentation().setEnabled(true); getTemplatePresentation().setVisible(true); }
@Override public void update(AnActionEvent e) { if (ApplicationManager.getApplication().getExtensions(EduIntelliJProjectTemplate.EP_NAME).length < 1) { e.getPresentation().setEnabledAndVisible(false); } if (!PlatformUtils.isJetBrainsProduct()) { e.getPresentation().setEnabledAndVisible(false); } }
public static void updateAction(@NotNull final AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); final Project project = e.getProject(); if (project != null) { final StudyEditor studyEditor = getSelectedStudyEditor(project); if (studyEditor != null) { presentation.setEnabledAndVisible(true); } } }
@Override public void actionPerformed(AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project != null) { new DomGenDialog(project).show(); } }
@Override public void actionPerformed(@NotNull final AnActionEvent anActionEvent) { Project project = anActionEvent.getProject(); VirtualFile virtualFile = project.getBaseDir(); String sourcesProp = Utils.getPropertyValue(PROPERTY_SOURCES, true); List<String> sourcesList = Utils.getSourcesList(sourcesProp); Crowdin crowdin = new Crowdin(); for (String src : sourcesList) { VirtualFile source = Utils.getSourceFile(virtualFile, src); String branch = Utils.getCurrentBranch(project); crowdin.uploadFile(source, branch); } }
@Override public void update(AnActionEvent event) { //在Action显示之前,根据选中文件扩展名判定是否显示此Action VirtualFile file = DataKeys.VIRTUAL_FILE.getData(event.getDataContext()); boolean show = file.isDirectory() || isYamlFile(file.getExtension()); this.getTemplatePresentation().setEnabled(show); this.getTemplatePresentation().setVisible(show); }
private static void showStepicNotification(@NotNull Project project, @NotNull NotificationType notificationType, @NotNull String failedActionName) { String text = "Log in to Stepik to " + failedActionName; Notification notification = new Notification("Stepik", "Failed to " + failedActionName, text, notificationType); notification.addAction(new AnAction("Log in") { @Override public void actionPerformed(AnActionEvent e) { EduStepicConnector.doAuthorize(() -> showOAuthDialog()); notification.expire(); } }); notification.notify(project); }