Java Code Examples for com.intellij.CommonBundle

The following examples show how to use com.intellij.CommonBundle. These examples are extracted from open source projects. 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 Project: consulo   Source File: ConfirmationDialog.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean requestForConfirmation(@Nonnull VcsShowConfirmationOption option,
                                             @Nonnull Project project,
                                             @Nonnull String message,
                                             @Nonnull String title,
                                             @Nullable Icon icon,
                                             @Nullable String okActionName,
                                             @Nullable String cancelActionName) {
  if (option.getValue() == VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) return false;
  final ConfirmationDialog dialog = new ConfirmationDialog(project, message, title, icon, option, okActionName, cancelActionName);
  if (!option.isPersistent()) {
    dialog.setDoNotAskOption(null);
  }
  else {
    dialog.setDoNotShowAgainMessage(CommonBundle.message("dialog.options.do.not.ask"));
  }
  return dialog.showAndGet();
}
 
Example 2
Source Project: consulo   Source File: SingleConfigurableEditor.java    License: Apache License 2.0 6 votes vote down vote up
public ApplyAction() {
  super(CommonBundle.getApplyButtonText());
  final Runnable updateRequest = new Runnable() {
    @Override
    public void run() {
      if (!SingleConfigurableEditor.this.isShowing()) return;
      try {
        ApplyAction.this.setEnabled(myConfigurable != null && myConfigurable.isModified());
      }
      catch (IndexNotReadyException ignored) {
      }
      addUpdateRequest(this);
    }
  };

  // invokeLater necessary to make sure dialog is already shown so we calculate modality state correctly.
  SwingUtilities.invokeLater(() -> addUpdateRequest(updateRequest));
}
 
Example 3
Source Project: consulo   Source File: ProjectWizardUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean createDirectoryIfNotExists(final String promptPrefix, String directoryPath, boolean promptUser) {
  File dir = new File(directoryPath);
  if (!dir.exists()) {
    if (promptUser) {
      final int answer = Messages.showOkCancelDialog(IdeBundle.message("promot.projectwizard.directory.does.not.exist", promptPrefix,
                                                                       dir.getPath(), ApplicationNamesInfo.getInstance().getFullProductName()),
                                                     IdeBundle.message("title.directory.does.not.exist"), Messages.getQuestionIcon());
      if (answer != 0) {
        return false;
      }
    }
    try {
      VfsUtil.createDirectories(dir.getPath());
    }
    catch (IOException e) {
      Messages.showErrorDialog(IdeBundle.message("error.failed.to.create.directory", dir.getPath()), CommonBundle.getErrorTitle());
      return false;
    }
  }
  return true;
}
 
Example 4
Source Project: consulo   Source File: WholeWestSingleConfigurableEditor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
protected void doAction(ActionEvent e) {
  try {
    if (myConfigurable.isModified()) {
      myConfigurable.apply();
      myChangesWereApplied = true;
      setCancelButtonText(CommonBundle.getCloseButtonText());
    }
  }
  catch (ConfigurationException ex) {
    if (myProject != null) {
      Messages.showMessageDialog(myProject, ex.getMessage(), ex.getTitle(), Messages.getErrorIcon());
    }
    else {
      Messages.showMessageDialog(myParentComponent, ex.getMessage(), ex.getTitle(), Messages.getErrorIcon());
    }
  }
}
 
Example 5
Source Project: intellij   Source File: DescribeLibraryAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
  BlazeProjectData blazeProjectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (blazeProjectData == null) {
    return;
  }
  Library library = LibraryActionHelper.findLibraryForAction(e);
  if (library == null) {
    return;
  }
  BlazeJarLibrary blazeLibrary =
      LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
  if (blazeLibrary == null) {
    Messages.showErrorDialog(
        project, "Could not find this library in the project.", CommonBundle.getErrorTitle());
    return;
  }
  showLibraryDescription(project, blazeLibrary);
}
 
Example 6
Source Project: consulo   Source File: CreateDirectoryOrPackageHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private Boolean suggestCreatingFileInstead(String subDirName) {
  Boolean createFile = false;
  if (StringUtil.countChars(subDirName, '.') == 1 && Registry.is("ide.suggest.file.when.creating.filename.like.directory")) {
    FileType fileType = findFileTypeBoundToName(subDirName);
    if (fileType != null) {
      String message = "The name you entered looks like a file name. Do you want to create a file named " + subDirName + " instead?";
      int ec = Messages.showYesNoCancelDialog(myProject, message, "File Name Detected", "&Yes, create file", "&No, create " + (myIsDirectory ? "directory" : "packages"),
                                              CommonBundle.getCancelButtonText(), TargetAWT.to(fileType.getIcon()));
      if (ec == Messages.CANCEL) {
        createFile = null;
      }
      if (ec == Messages.YES) {
        createFile = true;
      }
    }
  }
  return createFile;
}
 
Example 7
Source Project: consulo   Source File: FilterDialog.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void doOKAction() {
  String errorMessage = null;
  if (noText(myNameField.getText())) {
    errorMessage = ToolsBundle.message("tools.filters.add.name.required.error");
  } else if (noText(myRegexpField.getText())) {
    errorMessage = ToolsBundle.message("tools.filters.add.regex.required.error");
  }

  if (errorMessage != null) {
    Messages.showMessageDialog(getContentPane(), errorMessage, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return;
  }

  try {
    checkRegexp(myRegexpField.getText());
  } catch (InvalidExpressionException e) {
    Messages.showMessageDialog(getContentPane(), e.getMessage(), ToolsBundle.message("tools.filters.add.regex.invalid.title"), Messages.getErrorIcon());
    return;
  }
  super.doOKAction();
}
 
Example 8
Source Project: intellij-haxe   Source File: HaxeRestoreReferencesDialog.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
  myList = new JBList((Object[])myNamedElements);
  myList.setCellRenderer(new FQNameCellRenderer());
  panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER);

  panel.add(new JBLabel(CodeInsightBundle.message("dialog.paste.on.import.text"), SMALL, BRIGHTER), BorderLayout.NORTH);

  final JPanel buttonPanel = new JPanel(new VerticalFlowLayout());
  final JButton okButton = new JButton(CommonBundle.getOkButtonText());
  getRootPane().setDefaultButton(okButton);
  buttonPanel.add(okButton);
  final JButton cancelButton = new JButton(CommonBundle.getCancelButtonText());
  buttonPanel.add(cancelButton);

  panel.setPreferredSize(new Dimension(500, 400));

  return panel;
}
 
Example 9
Source Project: consulo   Source File: NewProjectAction.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
protected JPanel createSouthPanel() {
  JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, SystemInfo.isMacOSLeopard ? 0 : 5, 0));

  myCancelButton = new JButton(CommonBundle.getCancelButtonText());
  myCancelButton.addActionListener(e -> doCancelAction());

  buttonsPanel.add(myCancelButton);

  myOkButton = new JButton(CommonBundle.getOkButtonText()) {
    @Override
    public boolean isDefaultButton() {
      return true;
    }
  };
  myOkButton.setEnabled(false);

  myOkButton.addActionListener(e -> doOkAction());
  buttonsPanel.add(myOkButton);

  return JBUI.Panels.simplePanel().addToRight(buttonsPanel);
}
 
Example 10
Source Project: consulo   Source File: CodeAnalysisBeforeCheckinHandler.java    License: Apache License 2.0 6 votes vote down vote up
private ReturnResult processFoundCodeSmells(final List<CodeSmellInfo> codeSmells, @Nullable CommitExecutor executor) {
  int errorCount = collectErrors(codeSmells);
  int warningCount = codeSmells.size() - errorCount;
  String commitButtonText = executor != null ? executor.getActionText() : myCheckinPanel.getCommitActionName();
  if (commitButtonText.endsWith("...")) {
    commitButtonText = commitButtonText.substring(0, commitButtonText.length()-3);
  }

  final int answer = Messages.showYesNoCancelDialog(myProject,
    VcsBundle.message("before.commit.files.contain.code.smells.edit.them.confirm.text", errorCount, warningCount),
    VcsBundle.message("code.smells.error.messages.tab.name"), VcsBundle.message("code.smells.review.button"),
    commitButtonText, CommonBundle.getCancelButtonText(), UIUtil.getWarningIcon());
  if (answer == 0) {
    CodeSmellDetector.getInstance(myProject).showCodeSmellErrors(codeSmells);
    return ReturnResult.CLOSE_WINDOW;
  }
  else if (answer == 2 || answer == -1) {
    return ReturnResult.CANCEL;
  }
  else {
    return ReturnResult.COMMIT;
  }
}
 
Example 11
Source Project: consulo   Source File: FindUsagesAction.java    License: Apache License 2.0 6 votes vote down vote up
static void chooseAmbiguousTargetAndPerform(@Nonnull final Project project, final Editor editor, @Nonnull PsiElementProcessor<PsiElement> processor) {
  if (editor == null) {
    Messages.showMessageDialog(project, FindBundle.message("find.no.usages.at.cursor.error"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
  }
  else {
    int offset = editor.getCaretModel().getOffset();
    boolean chosen = GotoDeclarationAction.chooseAmbiguousTarget(editor, offset, processor, FindBundle.message("find.usages.ambiguous.title"), null);
    if (!chosen) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
          HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
        }
      }, project.getDisposed());
    }
  }
}
 
Example 12
Source Project: consulo   Source File: MasterDetailsComponent.java    License: Apache License 2.0 6 votes vote down vote up
protected void checkApply(Set<MyNode> rootNodes, String prefix, String title) throws ConfigurationException {
  for (MyNode rootNode : rootNodes) {
    final Set<String> names = new HashSet<String>();
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      final MyNode node = (MyNode)rootNode.getChildAt(i);
      final NamedConfigurable scopeConfigurable = node.getConfigurable();
      final String name = scopeConfigurable.getDisplayName();
      if (name.trim().length() == 0) {
        selectNodeInTree(node);
        throw new ConfigurationException("Name should contain non-space characters");
      }
      if (names.contains(name)) {
        final NamedConfigurable selectedConfigurable = getSelectedConfigurable();
        if (selectedConfigurable == null || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) {
          selectNodeInTree(node);
        }
        throw new ConfigurationException(CommonBundle.message("smth.already.exist.error.message", prefix, name), title);
      }
      names.add(name);
    }
  }
}
 
Example 13
Source Project: consulo   Source File: ElementCreator.java    License: Apache License 2.0 6 votes vote down vote up
public PsiElement[] tryCreate(@Nonnull final String inputString) {
  if (inputString.length() == 0) {
    Messages.showMessageDialog(myProject, IdeBundle.message("error.name.should.be.specified"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return PsiElement.EMPTY_ARRAY;
  }

  Ref<List<SmartPsiElementPointer>> createdElements = Ref.create();
  Exception exception = executeCommand(getActionName(inputString), () -> {
    PsiElement[] psiElements = create(inputString);
    SmartPointerManager manager = SmartPointerManager.getInstance(myProject);
    createdElements.set(ContainerUtil.map(psiElements, manager::createSmartPsiElementPointer));
  });
  if (exception != null) {
    handleException(exception);
    return PsiElement.EMPTY_ARRAY;
  }

  return ContainerUtil.mapNotNull(createdElements.get(), SmartPsiElementPointer::getElement).toArray(PsiElement.EMPTY_ARRAY);
}
 
Example 14
Source Project: consulo   Source File: SafeFileOutputStream.java    License: Apache License 2.0 6 votes vote down vote up
private void restoreFromBackup(@Nullable Path backup, IOException e) throws IOException {
  if (backup == null) {
    throw new IOException(CommonBundle.message("safe.write.junk", myTarget), e);
  }

  boolean restored = true;
  try (InputStream in = Files.newInputStream(backup, BACKUP_READ); OutputStream out = Files.newOutputStream(myTarget, MAIN_WRITE)) {
    FileUtil.copy(in, out);
  }
  catch (IOException ex) {
    restored = false;
    e.addSuppressed(ex);
  }
  if (restored) {
    throw new IOException(CommonBundle.message("safe.write.restored", myTarget), e);
  }
  else {
    throw new IOException(CommonBundle.message("safe.write.junk.backup", myTarget, backup.getFileName()), e);
  }
}
 
Example 15
Source Project: consulo   Source File: PsiFileNode.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(PresentationData data) {
  PsiFile value = getValue();
  data.setPresentableText(value.getName());
  data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS));

  VirtualFile file = getVirtualFile();
  if (file != null && file.is(VFileProperty.SYMLINK)) {
    String target = file.getCanonicalPath();
    if (target == null) {
      data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
      data.setTooltip(CommonBundle.message("vfs.broken.link"));
    }
    else {
      data.setTooltip(FileUtil.toSystemDependentName(target));
    }
  }
}
 
Example 16
Source Project: consulo   Source File: DateFormatUtil.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("Duplicates")
private static String composeInSomeTimeMessage(final Period period, final int n) {
  switch (period) {
    case DAY:
      return CommonBundle.message("date.format.in.n.days", n);
    case MINUTE:
      return CommonBundle.message("date.format.in.n.minutes", n);
    case HOUR:
      return CommonBundle.message("date.format.in.n.hours", n);
    case MONTH:
      return CommonBundle.message("date.format.in.n.months", n);
    case WEEK:
      return CommonBundle.message("date.format.in.n.weeks", n);
    default:
      return CommonBundle.message("date.format.in.n.years", n);
  }
}
 
Example 17
Source Project: consulo   Source File: ToggleReadOnlyAttributeAction.java    License: Apache License 2.0 6 votes vote down vote up
public void actionPerformed(final AnActionEvent e){
  ApplicationManager.getApplication().runWriteAction(
    new Runnable(){
      public void run(){
        // Save all documents. We won't be able to save changes to the files that became read-only afterwards.
        FileDocumentManager.getInstance().saveAllDocuments();

        try {
          VirtualFile[] files=getFiles(e.getDataContext());
          for (VirtualFile file : files) {
            ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable());
          }
        }
        catch(IOException exc){
          Project project = e.getData(CommonDataKeys.PROJECT);
          Messages.showMessageDialog(
            project,
            exc.getMessage(),
            CommonBundle.getErrorTitle(),Messages.getErrorIcon()
          );
        }
      }
    }
  );
}
 
Example 18
Source Project: crud-intellij-plugin   Source File: CrudBundle.java    License: Apache License 2.0 5 votes vote down vote up
public static String message(@PropertyKey(resourceBundle = BUNDLE_NAME) String key, Object... params) {
		return CommonBundle.message(BUNDLE, key, params);
/*        if (!StringUtil.isEmptyOrSpaces(message)) {
            try {
                message = new String(message.getBytes("ISO-8859-1"), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new IllegalStateException(e.getMessage(), e);
            }
        }
        return message;*/
	}
 
Example 19
Source Project: consulo   Source File: CustomFileTypeEditor.java    License: Apache License 2.0 5 votes vote down vote up
public void applyEditorTo(AbstractFileType type) throws ConfigurationException {
  if (myFileTypeName.getText().trim().length() == 0) {
    throw new ConfigurationException(IdeBundle.message("error.name.cannot.be.empty"),
                                     CommonBundle.getErrorTitle());
  }
  else if (myFileTypeDescr.getText().trim().length() == 0) {
    myFileTypeDescr.setText(myFileTypeName.getText());
  }
  type.setName(myFileTypeName.getText());
  type.setDescription(myFileTypeDescr.getText());
  type.setSyntaxTable(getSyntaxTable());
}
 
Example 20
Source Project: consulo   Source File: ShowSettingsAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  if (SystemInfo.isMac && e.getPlace().equals(ActionPlaces.MAIN_MENU)) {
    // It's called from Preferences in App menu.
    e.getPresentation().setVisible(false);
  }
  if (e.getPlace().equals(ActionPlaces.WELCOME_SCREEN)) {
    e.getPresentation().setText(CommonBundle.settingsTitle());
  }
}
 
Example 21
Source Project: consulo   Source File: EditVariableDialog.java    License: Apache License 2.0 5 votes vote down vote up
public EditVariableDialog(Editor editor, Component parent, ArrayList<Variable> variables, List<TemplateContextType> contextTypes) {
  super(parent, true);
  myContextTypes = contextTypes;
  myVariables = variables;
  myEditor = editor;
  init();
  setTitle(CodeInsightBundle.message("templates.dialog.edit.variables.title"));
  setOKButtonText(CommonBundle.getOkButtonText());
}
 
Example 22
Source Project: consulo   Source File: ContentChooser.java    License: Apache License 2.0 5 votes vote down vote up
public ContentChooser(Project project, String title, boolean useIdeaEditor, boolean allowMultipleSelections) {
  super(project, true);
  myProject = project;
  myUseIdeaEditor = useIdeaEditor;
  myAllowMultipleSelections = allowMultipleSelections;
  myUpdateAlarm = new Alarm(getDisposable());
  mySplitter = new JBSplitter(true, 0.3f);
  mySplitter.setSplitterProportionKey(getDimensionServiceKey() + ".splitter");
  myList = new JBList(new CollectionListModel<Item>());

  setOKButtonText(CommonBundle.getOkButtonText());
  setTitle(title);

  init();
}
 
Example 23
Source Project: consulo   Source File: IOExceptionDialog.java    License: Apache License 2.0 5 votes vote down vote up
public IOExceptionDialog(String title, String errorText)  {
  super((Project)null, true);
  setTitle(title);
  setOKButtonText(CommonBundle.message("dialog.ioexception.tryagain"));

  myErrorLabel = new JTextArea();
  myErrorLabel.setText(errorText);
  myErrorLabel.setFont(UIManager.getFont("Label.font"));
  myErrorLabel.setBackground(UIManager.getColor("Label.background"));
  myErrorLabel.setForeground(UIManager.getColor("Label.foreground"));

  init();
}
 
Example 24
Source Project: consulo   Source File: DisableInspectionToolAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(file.getProject());
  InspectionProfile inspectionProfile = profileManager.getInspectionProfile();
  ModifiableModel model = inspectionProfile.getModifiableModel();
  model.disableTool(myToolId, file);
  try {
    model.commit();
  }
  catch (IOException e) {
    Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
  }
  DaemonCodeAnalyzer.getInstance(project).restart();
}
 
Example 25
Source Project: consulo   Source File: ProjectLoadingErrorsNotifierImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void fireNotifications() {
  final MultiMap<ConfigurationErrorType, ConfigurationErrorDescription> descriptionsMap = new MultiMap<ConfigurationErrorType, ConfigurationErrorDescription>();
  synchronized (myLock) {
    if (myErrors.isEmpty()) return;
    descriptionsMap.putAllValues(myErrors);
    myErrors.clear();
  }

  for (final ConfigurationErrorType type : descriptionsMap.keySet()) {
    final Collection<ConfigurationErrorDescription> descriptions = descriptionsMap.get(type);
    if (descriptions.isEmpty()) continue;

    final String invalidElements = getInvalidElementsString(type, descriptions);
    final String errorText = ProjectBundle.message("error.message.configuration.cannot.load") + " " + invalidElements + " <a href=\"\">Details...</a>";

    Notifications.Bus.notify(new Notification("Project Loading Error", "Error Loading Project", errorText, NotificationType.ERROR, new NotificationListener() {
      @Override
      public void hyperlinkUpdate(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) {
        final List<ConfigurationErrorDescription> validDescriptions = ContainerUtil.findAll(descriptions, new Condition<ConfigurationErrorDescription>() {
          @Override
          public boolean value(ConfigurationErrorDescription errorDescription) {
            return errorDescription.isValid();
          }
        });
        RemoveInvalidElementsDialog.showDialog(myProject, CommonBundle.getErrorTitle(), type, invalidElements, validDescriptions);

        notification.expire();
      }
    }), myProject);
  }

}
 
Example 26
Source Project: consulo   Source File: CreateFromTemplateDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void doOKAction() {
  String fileName = myAttrPanel.getFileName();
  if (fileName != null && fileName.length() == 0) {
    Messages.showMessageDialog(myAttrComponent, IdeBundle.message("error.please.enter.a.file.name"), CommonBundle.getErrorTitle(), Messages.getErrorIcon());
    return;
  }
  doCreate(fileName);
  if (myCreatedElement != null) {
    super.doOKAction();
  }
}
 
Example 27
Source Project: consulo   Source File: ExecutionManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean userApprovesStopForSameTypeConfigurations(Project project, String configName, int instancesCount) {
  RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
  final RunManagerConfig config = runManager.getConfig();
  if (!config.isRestartRequiresConfirmation()) return true;

  DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
    @Override
    public boolean isToBeShown() {
      return config.isRestartRequiresConfirmation();
    }

    @Override
    public void setToBeShown(boolean value, int exitCode) {
      config.setRestartRequiresConfirmation(value);
    }

    @Override
    public boolean canBeHidden() {
      return true;
    }

    @Override
    public boolean shouldSaveOptionsOnCancel() {
      return false;
    }

    @Nonnull
    @Override
    public String getDoNotShowMessage() {
      return CommonBundle.message("dialog.options.do.not.show");
    }
  };
  return Messages.showOkCancelDialog(project, ExecutionBundle.message("rerun.singleton.confirmation.message", configName, instancesCount),
                                     ExecutionBundle.message("process.is.running.dialog.title", configName), ExecutionBundle.message("rerun.confirmation.button.text"),
                                     CommonBundle.message("button.cancel"), Messages.getQuestionIcon(), option) == Messages.OK;
}
 
Example 28
@RequiredReadAction
private static void doCopy(@Nonnull CSharpTypeDeclaration typeDeclaration, @Nullable PsiDirectory defaultTargetDirectory, Project project)
{
	PsiDirectory targetDirectory;
	String newName;
	boolean openInEditor;
	VirtualFile virtualFile = PsiUtilCore.getVirtualFile(typeDeclaration);
	CopyFilesOrDirectoriesDialog dialog = new CopyFilesOrDirectoriesDialog(new PsiElement[]{typeDeclaration.getContainingFile()}, defaultTargetDirectory, project, false);
	if(dialog.showAndGet())
	{
		newName = dialog.getNewName();
		targetDirectory = dialog.getTargetDirectory();
		openInEditor = dialog.openInEditor();
	}
	else
	{
		return;
	}

	if(targetDirectory != null)
	{
		PsiManager manager = PsiManager.getInstance(project);
		try
		{
			if(virtualFile.isDirectory())
			{
				PsiFileSystemItem psiElement = manager.findDirectory(virtualFile);
				MoveFilesOrDirectoriesUtil.checkIfMoveIntoSelf(psiElement, targetDirectory);
			}
		}
		catch(IncorrectOperationException e)
		{
			CommonRefactoringUtil.showErrorHint(project, null, e.getMessage(), CommonBundle.getErrorTitle(), null);
			return;
		}

		CommandProcessor.getInstance().executeCommand(project, () -> doCopy(typeDeclaration, newName, targetDirectory, false, openInEditor), RefactoringBundle.message("copy.handler.copy.files" +
				".directories"), null);
	}
}
 
Example 29
Source Project: consulo   Source File: MultipleFileMergeDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected Action getCancelAction() {
  Action action = super.getCancelAction();
  action.putValue(Action.NAME, CommonBundle.getCloseButtonText());
  return action;
}
 
Example 30
Source Project: consulo   Source File: StatisticsManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean createStoreFolder(){
  File homeFile = new File(STORE_PATH);
  if (!homeFile.exists()){
    if (!homeFile.mkdirs()){
      Messages.showMessageDialog(
              IdeBundle.message("error.saving.statistic.failed.to.create.folder", STORE_PATH),
              CommonBundle.getErrorTitle(),
              Messages.getErrorIcon()
      );
      return false;
    }
  }
  return true;
}