Java Code Examples for com.intellij.openapi.ui.Messages#showInputDialog()

The following examples show how to use com.intellij.openapi.ui.Messages#showInputDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionMacroManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void stopRecording(@Nullable Project project) {
  LOG.assertTrue(myIsRecording);

  if (myWidget != null) {
    myWidget.delete();
    myWidget = null;
  }

  myIsRecording = false;
  myLastActionInputEvent.clear();
  String macroName;
  do {
    macroName = Messages.showInputDialog(project, IdeBundle.message("prompt.enter.macro.name"), IdeBundle.message("title.enter.macro.name"), Messages.getQuestionIcon());
    if (macroName == null) {
      myRecordingMacro = null;
      return;
    }

    if (macroName.isEmpty()) macroName = null;
  }
  while (macroName != null && !checkCanCreateMacro(macroName));

  myLastMacro = myRecordingMacro;
  addRecordedMacroWithName(macroName);
  registerActions();
}
 
Example 2
Source File: BaseLibrariesConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Object o = getSelectedObject();
  if (o instanceof LibraryEx) {
    final LibraryEx selected = (LibraryEx)o;
    final String newName = Messages.showInputDialog("Enter library name:", "Copy Library", null, selected.getName() + "2", new NonEmptyInputValidator());
    if (newName == null) return;

    BaseLibrariesConfigurable configurable = BaseLibrariesConfigurable.this;
    final LibraryEx library = (LibraryEx)myContext.getLibrary(selected.getName(), myLevel);
    LOG.assertTrue(library != null);

    final LibrariesModifiableModel libsModel = configurable.getModelProvider().getModifiableModel();
    final Library lib = libsModel.createLibrary(newName, library.getKind());
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)libsModel.getLibraryEditor(lib).getModel();
    LibraryEditingUtil.copyLibrary(library, Collections.<String, String>emptyMap(), model);
  }
}
 
Example 3
Source File: ZipArchiveElementType.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public CompositePackagingElement<?> createComposite(CompositePackagingElement<?> parent,
                                                    @Nullable String baseName,
                                                    @Nonnull ArtifactEditorContext context) {
  final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, baseName != null ? baseName : "archive", ".zip");
  String path =
    Messages.showInputDialog(context.getProject(), "Enter archive name: ", "New Archive", null, initialValue, new FilePathValidator());
  if (path == null) {
    return null;
  }
  path = FileUtil.toSystemIndependentName(path);
  final String parentPath = PathUtil.getParentPath(path);
  final String fileName = PathUtil.getFileName(path);
  final PackagingElement<?> element = new ZipArchivePackagingElement(fileName);
  return (CompositePackagingElement<?>)PackagingElementFactory.getInstance(context.getProject()).createParentDirectories(parentPath, element);
}
 
Example 4
Source File: TinyPngExtension.java    From TinyPngPlugin with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent actionEvent) {
    Project project = actionEvent.getProject();
    String apiKey = PropertiesComponent.getInstance().getValue(TINY_PNG_API_KEY);
    if (TextUtils.isEmpty(apiKey)) {
        apiKey = Messages.showInputDialog(project, "What's your ApiKey?", "ApiKey", Messages.getQuestionIcon());
        PropertiesComponent.getInstance().setValue(TINY_PNG_API_KEY, apiKey);
    }
    VirtualFile[] selectedFiles = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(actionEvent.getDataContext());
    Tinify.setKey(apiKey);
    ProgressDialog dialog = new ProgressDialog();
    sExecutorService.submit(() -> {
        //writing to file
        int i = 1;
        successCount = 0;
        failCount = 0;
        List<VirtualFile> failFileList = new ArrayList<>();
        for (VirtualFile file : selectedFiles) {
            failFileList.addAll(processFile(dialog, i + "/" + selectedFiles.length, file));
            i++;
        }
        dialog.setLabelMsg("Success :" + successCount + " Fail :" + failCount);
        dialog.setButtonOKVisible();
    });
    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            runningFlag.set(false);
        }
    });
    dialog.setLabelMsg("processing");
    JFrame frame = WindowManager.getInstance().getFrame(project);
    dialog.setMinimumSize(new Dimension(frame.getWidth() / 4, frame.getHeight() / 4));
    dialog.setLocationRelativeTo(frame);
    dialog.pack();
    dialog.setVisible(true);
}
 
Example 5
Source File: NewBashFileAction.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@NotNull
protected final PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) {
    final MyInputValidator validator = new MyInputValidator(project, directory);
    Messages.showInputDialog(project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "", validator);

    return validator.getCreatedElements();
}
 
Example 6
Source File: CreateConcernOfInPackageAction.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@NotNull
protected final PsiElement[] invokeDialog( Project project, PsiDirectory directory )
{
    MyInputValidator validator = new MyInputValidator( project, directory );
    Messages.showInputDialog( project, message( "createConcernOfInPackage.dlg.prompt" ),
                              message( "createConcernOfInPackage.dlg.title" ),
                              Messages.getQuestionIcon(), "", validator );
    return validator.getCreatedElements();
}
 
Example 7
Source File: NewVueActionBase.java    From vue-for-idea with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
protected final PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) {
    final MyInputValidator validator = new MyInputValidator(project, directory);
    Messages.showInputDialog(project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "", validator);

    final PsiElement[] elements = validator.getCreatedElements();
    return elements;
}
 
Example 8
Source File: NewBundleFileActionAbstract.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {

    final Project project = getEventProject(event);
    if(project == null) {
        this.setStatus(event, false);
        return;
    }

    PsiDirectory bundleDirContext = BundleClassGeneratorUtil.getBundleDirContext(event);
    if(bundleDirContext == null) {
        return;
    }

    final PhpClass phpClass = BundleClassGeneratorUtil.getBundleClassInDirectory(bundleDirContext);
    if(phpClass == null) {
        return;
    }

    String className = Messages.showInputDialog(project, "New class name:", "New File", Symfony2Icons.SYMFONY);
    if(StringUtils.isBlank(className)) {
        return;
    }

    if(!PhpNameUtil.isValidClassName(className)) {
        JOptionPane.showMessageDialog(null, "Invalid class name");
        return;
    }

    write(project, phpClass, className);
}
 
Example 9
Source File: SlackSettings.java    From SlackStorm with GNU General Public License v2.0 5 votes vote down vote up
protected String showInputDialog(String keyDescription, String keyDefaultValue) {
    return Messages.showInputDialog(
            this.project,
            keyDescription,
            SlackChannel.getSettingsDescription(),
            SlackStorage.getSlackIcon(),
            keyDefaultValue,
            null
    );
}
 
Example 10
Source File: SingleInspectionProfilePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ModifiableModel createNewProfile(final int initValue,
                                               ModifiableModel selectedProfile,
                                               JPanel parent,
                                               String profileName,
                                               Set<String> existingProfileNames,
                                               @Nonnull Project project) {
  profileName = Messages.showInputDialog(parent, profileName, "Create New Inspection Profile", Messages.getQuestionIcon());
  if (profileName == null) return null;
  final ProfileManager profileManager = selectedProfile.getProfileManager();
  if (existingProfileNames.contains(profileName)) {
    Messages.showErrorDialog(InspectionsBundle.message("inspection.unable.to.create.profile.message", profileName),
                             InspectionsBundle.message("inspection.unable.to.create.profile.dialog.title"));
    return null;
  }
  InspectionProfileImpl inspectionProfile = new InspectionProfileImpl(profileName, InspectionToolRegistrar.getInstance(), profileManager);
  if (initValue == -1) {
    inspectionProfile.initInspectionTools(project);
    ModifiableModel profileModifiableModel = inspectionProfile.getModifiableModel();
    final InspectionToolWrapper[] profileEntries = profileModifiableModel.getInspectionTools(null);
    for (InspectionToolWrapper toolWrapper : profileEntries) {
      profileModifiableModel.disableTool(toolWrapper.getShortName(), null, project);
    }
    profileModifiableModel.setProjectLevel(false);
    profileModifiableModel.setModified(true);
    return profileModifiableModel;
  }
  else if (initValue == 0) {
    inspectionProfile.copyFrom(selectedProfile);
    inspectionProfile.setName(profileName);
    inspectionProfile.initInspectionTools(project);
    inspectionProfile.setModified(true);
    return inspectionProfile;
  }
  return null;
}
 
Example 11
Source File: NewBlazePackageAction.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent event) {
  IdeView view = event.getData(LangDataKeys.IDE_VIEW);
  if (view == null) {
    return;
  }
  PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
  if (directory == null) {
    return;
  }
  CreateDirectoryOrPackageHandler validator =
      new CreateDirectoryOrPackageHandler(project, directory, false, ".") {
        @Override
        protected void createDirectories(String subDirName) {
          super.createDirectories(subDirName);
          PsiFileSystemItem element = getCreatedElement();
          if (element instanceof PsiDirectory) {
            createBuildFile(project, (PsiDirectory) element);
          }
        }
      };
  Messages.showInputDialog(
      project,
      "Enter new package name:",
      String.format("New %s Package", Blaze.buildSystemName(project)),
      Messages.getQuestionIcon(),
      "",
      validator);
  PsiDirectory newDir = (PsiDirectory) validator.getCreatedElement();
  if (newDir != null) {
    PsiFile buildFile = findBuildFile(project, newDir);
    if (buildFile != null) {
      view.selectElement(buildFile);
      OpenFileAction.openFile(buildFile.getViewProvider().getVirtualFile(), project);
    }
  }
}
 
Example 12
Source File: BackgroundTaskByVfsChangeManageDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void add(@Nonnull BackgroundTaskByVfsChangeProvider provider) {
  String name = Messages.showInputDialog(myProject, "Name", "Enter Name", UIUtil.getInformationIcon(), provider.getTemplateName(), null);
  if (name == null) {
    return;
  }

  BackgroundTaskByVfsChangeTask task = BackgroundTaskByVfsChangeManager.getInstance(myProject).createTask(provider, myVirtualFile, name);

  myBoxlist.addItem(task, task.getName(), task.isEnabled());
  // select last item - selected item
  myBoxlist.setSelectedIndex(myBoxlist.getItemsCount() - 1);
}
 
Example 13
Source File: LSPRenameHandler.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private void performDialogRename(Editor editor) {
    EditorEventManager manager = EditorEventManagerBase.forEditor(editor);
    if (manager != null) {
        String renameTo = Messages.showInputDialog(
                editor.getProject(), "Enter new name: ", "Rename", Messages.getQuestionIcon(), "",
                new NonEmptyInputValidator());
        if (renameTo != null && !renameTo.equals("")) {
            manager.rename(renameTo);
        }
    }
}
 
Example 14
Source File: SendCommandPlugin.java    From ReactNativeTools with Apache License 2.0 4 votes vote down vote up
private String showDialog(Project project) {
    return Messages.showInputDialog(project, "input command", "Send command", null);
}
 
Example 15
Source File: BxNewSectionAction.java    From bxfs with MIT License 4 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
	IdeView view
		= event.getData(LangDataKeys.IDE_VIEW);

	if (view != null) {
		Project project
			= event.getProject();

		if (project != null) {
			PsiDirectory directory
				= DirectoryChooserUtil.getOrChooseDirectory(view);

			if (directory != null) {
				CreateDirectoryOrPackageHandler validator
					= new CreateDirectoryOrPackageHandler(project, directory, true, "\\/");

				// Сообщение не нужно, так как заголовок окна и так близко. Они резонируют.
				Messages.showInputDialog(project, null, "Битрикс: Создание Нового Раздела", BitrixFramework.bxIcon, "", validator);

				PsiElement result = validator.getCreatedElement();
				if (result instanceof PsiDirectory) {
					PsiDirectory createdDir = (PsiDirectory) result;

					FileTemplateManager templateManager
						= FileTemplateManager.getInstance(project);

					FileTemplate cfgTemplate = templateManager.findInternalTemplate("Битрикс - Раздел (настройки)");
					FileTemplate idxTemplate = templateManager.findInternalTemplate("Битрикс - Раздел (титульная)");

					Properties properties
						= FileTemplateManager.getInstance(project).getDefaultProperties();

					try {
						PsiElement cfgFile = FileTemplateUtil.createFromTemplate(cfgTemplate, ".section", properties, createdDir);
						PsiElement idxFile = FileTemplateUtil.createFromTemplate(idxTemplate, "index", properties, createdDir);

						view.selectElement(idxFile);
					}
					catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
}
 
Example 16
Source File: TextBoxes.java    From patcher with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    String txt = Messages.showInputDialog(project, "What is your name?", "Input your name", Messages.getQuestionIcon());
    Messages.showMessageDialog(project, "Hello, " + txt + "!\n I am glad to see you.", "Information", Messages.getInformationIcon());
}
 
Example 17
Source File: ServiceActionUtil.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public static void buildFile(AnActionEvent event, final Project project, String templatePath) {
    String extension = (templatePath.endsWith(".yml") || templatePath.endsWith(".yaml")) ? "yml" : "xml" ;

    String fileName = Messages.showInputDialog(project, "File name (without extension)", String.format("Create %s Service", extension), Symfony2Icons.SYMFONY);
    if(fileName == null || StringUtils.isBlank(fileName)) {
        return;
    }

    FileType fileType = (templatePath.endsWith(".yml") || templatePath.endsWith(".yaml")) ? YAMLFileType.YML : XmlFileType.INSTANCE ;

    if(!fileName.endsWith("." + extension)) {
        fileName = fileName.concat("." + extension);
    }

    DataContext dataContext = event.getDataContext();
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return;
    }

    PsiDirectory[] directories = view.getDirectories();
    if(directories.length == 0) {
        return;
    }

    final PsiDirectory initialBaseDir = directories[0];
    if (initialBaseDir == null) {
        return;
    }

    if(initialBaseDir.findFile(fileName) != null) {
        Messages.showInfoMessage("File exists", "Error");
        return;
    }

    String content;
    try {
        content = StreamUtil.readText(ServiceActionUtil.class.getResourceAsStream(templatePath), "UTF-8").replace("\r\n", "\n");
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    final PsiFileFactory factory = PsiFileFactory.getInstance(project);

    String bundleName = "Acme\\DemoBundle";

    SymfonyBundleUtil symfonyBundleUtil = new SymfonyBundleUtil(project);
    SymfonyBundle symfonyBundle = symfonyBundleUtil.getContainingBundle(initialBaseDir);

    if(symfonyBundle != null) {
        bundleName = StringUtils.strip(symfonyBundle.getNamespaceName(), "\\");
    }

    String underscoreBundle = bundleName.replace("\\", ".").toLowerCase();
    if(underscoreBundle.endsWith("bundle")) {
        underscoreBundle = underscoreBundle.substring(0, underscoreBundle.length() - 6);
    }

    content = content.replace("{{ BundleName }}", bundleName).replace("{{ BundleNameUnderscore }}", underscoreBundle);

    final PsiFile file = factory.createFileFromText(fileName, fileType, content);

    ApplicationManager.getApplication().runWriteAction(() -> {
        CodeStyleManager.getInstance(project).reformat(file);
        initialBaseDir.add(file);
    });

    PsiFile psiFile = initialBaseDir.findFile(fileName);
    if(psiFile != null) {
        view.selectElement(psiFile);
    }

}
 
Example 18
Source File: AbstractCreateElementActionBase.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
protected MyInputValidator doInvokeDialog( Project project, PsiDirectory directory )
{
    MyInputValidator validator = new MyInputValidator( project, directory );
    Messages.showInputDialog( project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "", validator );
    return validator;
}
 
Example 19
Source File: SwapActionExecutor.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
protected String chooseSeparator() {
	StringBuilder sb = new StringBuilder();

	for (CaretState caretsAndSelection : caretsAndSelections) {
		int start = toOffset(caretsAndSelection.getSelectionStart());
		int end = toOffset(caretsAndSelection.getSelectionEnd());
		String selectedText = document.getText(TextRange.create(start, end));
		sb.append(selectedText);
	}

	String s = sb.toString();
	if (!s.contains(separator)) {
		if (s.contains(";")) {
			separator = ";";
		} else if (s.contains("||")) {
			separator = "||";
		} else if (s.contains("|")) {
			separator = "|";
		} else if (s.contains("/")) {
			separator = "/";
		} else if (s.contains("&&")) {
			separator = "&&";
		} else if (s.contains(".")) {
			separator = ".";
		} else if (s.contains(" ")) {
			separator = " ";
		}
	}

	String newSeparator = Messages.showInputDialog("Separator", "Split by separator and swap",
			Messages.getQuestionIcon(), separator, null);
	if (newSeparator != null) {
		if (newSeparator.equals("")) {
			newSeparator = " ";
		}
	} else {
		return null;
	}
	separator = newSeparator;
	return separator;
}
 
Example 20
Source File: ScanSourceCommentsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {

  final Project p = e.getDataContext().getData(CommonDataKeys.PROJECT);
  final String file =
    Messages.showInputDialog(p, "Enter path to the file comments will be extracted to", "Comments File Path", Messages.getQuestionIcon());

  try {
    final PrintStream stream = new PrintStream(file);
    stream.println("Comments in " + p.getName());

    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
      @Override
      public void run() {
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        ProjectRootManager.getInstance(p).getFileIndex().iterateContent(new ContentIterator() {
          @Override
          public boolean processFile(VirtualFile fileOrDir) {
            if (fileOrDir.isDirectory()) {
              indicator.setText("Extracting comments");
              indicator.setText2(fileOrDir.getPresentableUrl());
            }
            scanCommentsInFile(p, fileOrDir);
            return true;
          }
        });

        indicator.setText2("");
        int count = 1;
        for (CommentDescriptor descriptor : myComments.values()) {
          stream.println("#" + count + " ---------------------------------------------------------------");
          descriptor.print(stream);
          stream.println();
          count++;
        }

      }
    }, "Generating Comments", true, p);


    stream.close();

  }
  catch (Throwable e1) {
    LOG.error(e1);
    Messages.showErrorDialog(p, "Error writing? " + e1.getMessage(), "Problem writing");
  }
}