public static void copyDir( @NotNull File fromDir, @NotNull File toDir, @Nullable final FileFilter filter) throws IOException { ensureExists(toDir); if (isAncestor(fromDir, toDir, true)) { LOG.error(fromDir.getAbsolutePath() + " is ancestor of " + toDir + ". Can't copy to itself."); return; } File[] files = fromDir.listFiles(); if (files == null) throw new IOException( CommonBundle.message("exception.directory.is.invalid", fromDir.getPath())); if (!fromDir.canRead()) throw new IOException( CommonBundle.message("exception.directory.is.not.readable", fromDir.getPath())); for (File file : files) { if (filter != null && !filter.accept(file)) { continue; } if (file.isDirectory()) { copyDir(file, new File(toDir, file.getName()), filter); } else { copy(file, new File(toDir, file.getName())); } } }
public boolean execute(boolean drop, boolean isInsideStartFinishGroup) { if (!myUndoableGroup.isUndoable()) { reportCannotUndo( CommonBundle.message("cannot.undo.error.contains.nonundoable.changes.message"), myUndoableGroup.getAffectedDocuments()); return false; } Set<DocumentReference> clashing = getStackHolder().collectClashingActions(myUndoableGroup); if (!clashing.isEmpty()) { reportCannotUndo( CommonBundle.message("cannot.undo.error.other.affected.files.changed.message"), clashing); return false; } if (!isInsideStartFinishGroup && myUndoableGroup.shouldAskConfirmation(isRedo())) { if (!askUser()) return false; } else { if (restore(getBeforeState())) { setBeforeState(new EditorAndState(myEditor, myEditor.getState(FileEditorStateLevel.UNDO))); return true; } } Collection<VirtualFile> readOnlyFiles = collectReadOnlyAffectedFiles(); if (!readOnlyFiles.isEmpty()) { final Project project = myManager.getProject(); final VirtualFile[] files = VfsUtil.toVirtualFileArray(readOnlyFiles); if (project == null) { return false; } final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files); if (operationStatus.hasReadonlyFiles()) { return false; } } Collection<Document> readOnlyDocuments = collectReadOnlyDocuments(); if (!readOnlyDocuments.isEmpty()) { for (Document document : readOnlyDocuments) { document.fireReadOnlyModificationAttempt(); } return false; } getStackHolder().removeFromStacks(myUndoableGroup); if (!drop) { getReverseStackHolder().addToStacks(myUndoableGroup); } performAction(); restore(getAfterState()); return true; }
public MyDeleteAction(Condition<Object[]> availableCondition) { super( CommonBundle.message("button.delete"), CommonBundle.message("button.delete"), PlatformIcons.DELETE_ICON); registerCustomShortcutSet(CommonShortcuts.getDelete(), myTree); myCondition = availableCondition; }
public RerunAction(JComponent comp) { super( CommonBundle.message("action.rerun"), AnalysisScopeBundle.message("action.rerun.dependency"), AllIcons.Actions.RefreshUsages); registerCustomShortcutSet(CommonShortcuts.getRerun(), comp); }
private void checkForEmptyAndDuplicatedNames( MyNode rootNode, String prefix, String title, Class<? extends NamedConfigurable> configurableClass, boolean recursively) throws ConfigurationException { 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(); if (configurableClass.isInstance(scopeConfigurable)) { 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); } if (recursively) { checkForEmptyAndDuplicatedNames(node, prefix, title, configurableClass, true); } } }
@NotNull public String getReadonlyFilesMessage() { if (hasReadonlyFiles()) { StringBuilder buf = new StringBuilder(); if (myReadonlyFiles.length > 1) { for (VirtualFile file : myReadonlyFiles) { buf.append('\n'); buf.append(file.getPresentableUrl()); } return CommonBundle.message( "failed.to.make.the.following.files.writable.error.message", buf.toString()); } else { return CommonBundle.message( "failed.to.make.file.writeable.error.message", myReadonlyFiles[0].getPresentableUrl()); } } throw new RuntimeException("No readonly files"); }
@Override protected JComponent createSouthPanel() { JComponent southPanel = super.createSouthPanel(); myDoNotAskMeCheckBox = new JCheckBox(CommonBundle.message("dialog.options.do.not.show")); myDoNotAskMeCheckBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateState(); } }); return DialogWrapper.addDoNotShowCheckBox(southPanel, myDoNotAskMeCheckBox); }
@Override protected void updateImpl(PresentationData data) { PsiFile value = getValue(); data.setPresentableText(value.getName()); data.setIcon(value.getIcon(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)); } } }
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; } @NotNull @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; }
@Nullable private String getLocalizedString(String bundleName, String key) { final String baseName = bundleName != null ? bundleName : bundle == null ? ((IdeaPluginDescriptor) myPluginDescriptor).getResourceBundleBaseName() : bundle; if (baseName == null || key == null) { if (bundleName != null) { LOG.warn(implementationClass); } return null; } final ResourceBundle resourceBundle = AbstractBundle.getResourceBundle(baseName, myPluginDescriptor.getPluginClassLoader()); return CommonBundle.message(resourceBundle, key); }
public static boolean requestForConfirmation( @NotNull VcsShowConfirmationOption option, @NotNull Project project, @NotNull String message, @NotNull 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")); } dialog.show(); return dialog.isOK(); }
public EvaluationDialog(Project project, TextWithImports text) { super(project, true); myProject = project; setModal(false); setCancelButtonText(CommonBundle.message("button.close")); setOKButtonText(DebuggerBundle.message("button.evaluate")); myEvaluationPanel = new MyEvaluationPanel(myProject); myEditor = createEditor(DefaultCodeFragmentFactory.getInstance()); setDebuggerContext(getDebuggerContext()); initDialogData(text); myContextListener = new DebuggerContextListener() { public void changeEvent(DebuggerContextImpl newContext, int event) { boolean close = true; for (DebuggerSession session : DebuggerManagerEx.getInstanceEx(myProject).getSessions()) { if (!session.isStopped()) { close = false; break; } } if (close) { close(CANCEL_EXIT_CODE); } else { setDebuggerContext(newContext); } } }; DebuggerManagerEx.getInstanceEx(myProject).getContextManager().addListener(myContextListener); setHorizontalStretch(1f); setVerticalStretch(1f); }
private CloseAction() { super(CommonBundle.message("action.close"), null, AllIcons.Actions.Cancel); }
public static void ensureExists(@NotNull File dir) throws IOException { if (!dir.exists() && !dir.mkdirs()) { throw new IOException( CommonBundle.message("exception.directory.can.not.create", dir.getPath())); } }
public static String message( @PropertyKey(resourceBundle = BUNDLE_NAME) String key, Object... params) { return CommonBundle.message(BUNDLE, key, params); }
public DefaultPolicy() { super(CommonBundle.message("comparison.policy.default.name")); }
public static String message( @NonNls @PropertyKey(resourceBundle = BUNDLE) String key, Object... params) { return CommonBundle.message(FitnesseBundle.getBundle(), key, params); }
public TrimSpacePolicy() { super(CommonBundle.message("comparison.policy.trim.space.name")); }
public IgnoreSpacePolicy() { super(CommonBundle.message("comparison.policy.ignore.spaces.name")); }
/** * Translates the given message. * * @param key the key to be used for translation * @param params the parameters for the translation * @return the translated message. * @deprecated Translation isn't used consistently so this function is rather useless. */ @Deprecated public static String getTranslation( @PropertyKey(resourceBundle = BUNDLE) String key, Object... params) { return CommonBundle.message(getBundle(), key, params); }
private int extractExpectedHighlight( final Matcher matcher, final String text, final Document document, final Ref<Integer> textOffset) { document.deleteString(textOffset.get(), textOffset.get() + matcher.end() - matcher.start()); int groupIdx = 1; final String marker = matcher.group(groupIdx++); String descr = matcher.group(groupIdx++); final String typeString = matcher.group(groupIdx++); final String foregroundColor = matcher.group(groupIdx++); final String backgroundColor = matcher.group(groupIdx++); final String effectColor = matcher.group(groupIdx++); final String effectType = matcher.group(groupIdx++); final String fontType = matcher.group(groupIdx++); final String attrKey = matcher.group(groupIdx++); final String bundleMessage = matcher.group(groupIdx++); final boolean closed = matcher.group(groupIdx) != null; if (descr == null) { descr = ANY_TEXT; // no descr means any string by default } else if (descr.equals("null")) { descr = null; // explicit "null" descr } if (descr != null) { descr = descr.replaceAll( "\\\\\\\\\"", "\""); // replace: \\" to ", doesn't check symbol before sequence \\" descr = descr.replaceAll("\\\\\"", "\""); } HighlightInfoType type = WHATEVER; if (typeString != null) { try { type = getTypeByName(typeString); } catch (Exception e) { LOG.error(e); } LOG.assertTrue(type != null, "Wrong highlight type: " + typeString); } TextAttributes forcedAttributes = null; if (foregroundColor != null) { //noinspection MagicConstant forcedAttributes = new TextAttributes( Color.decode(foregroundColor), Color.decode(backgroundColor), Color.decode(effectColor), EffectType.valueOf(effectType), Integer.parseInt(fontType)); } final int rangeStart = textOffset.get(); final int toContinueFrom; if (closed) { toContinueFrom = matcher.end(); } else { int pos = matcher.end(); final Matcher closingTagMatcher = Pattern.compile("</" + marker + ">").matcher(text); while (true) { if (!closingTagMatcher.find(pos)) { LOG.error("Cannot find closing </" + marker + "> in position " + pos); } final int nextTagStart = matcher.find(pos) ? matcher.start() : text.length(); if (closingTagMatcher.start() < nextTagStart) { textOffset.set(textOffset.get() + closingTagMatcher.start() - pos); document.deleteString( textOffset.get(), textOffset.get() + closingTagMatcher.end() - closingTagMatcher.start()); toContinueFrom = closingTagMatcher.end(); break; } textOffset.set(textOffset.get() + nextTagStart - pos); pos = extractExpectedHighlight(matcher, text, document, textOffset); } } final ExpectedHighlightingSet expectedHighlightingSet = myHighlightingTypes.get(marker); if (expectedHighlightingSet.enabled) { TextAttributesKey forcedTextAttributesKey = attrKey == null ? null : TextAttributesKey.createTextAttributesKey(attrKey); HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type) .range(rangeStart, textOffset.get()) .severity(expectedHighlightingSet.severity); if (forcedAttributes != null) builder.textAttributes(forcedAttributes); if (forcedTextAttributesKey != null) builder.textAttributes(forcedTextAttributesKey); if (bundleMessage != null) { final List<String> split = StringUtil.split(bundleMessage, "|"); final ResourceBundle bundle = ResourceBundle.getBundle(split.get(0)); descr = CommonBundle.message(bundle, split.get(1), split.stream().skip(2).toArray()); } if (descr != null) { builder.description(descr); builder.unescapedToolTip(descr); } if (expectedHighlightingSet.endOfLine) builder.endOfLine(); HighlightInfo highlightInfo = builder.createUnconditionally(); expectedHighlightingSet.infos.add(highlightInfo); } return toContinueFrom; }
private static boolean userApprovesStopForIncompatibleConfigurations( Project project, String configName, List<RunContentDescriptor> runningIncompatibleDescriptors) { RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project); final RunManagerConfig config = runManager.getConfig(); if (!config.isStopIncompatibleRequiresConfirmation()) return true; DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() { @Override public boolean isToBeShown() { return config.isStopIncompatibleRequiresConfirmation(); } @Override public void setToBeShown(boolean value, int exitCode) { config.setStopIncompatibleRequiresConfirmation(value); } @Override public boolean canBeHidden() { return true; } @Override public boolean shouldSaveOptionsOnCancel() { return false; } @NotNull @Override public String getDoNotShowMessage() { return CommonBundle.message("dialog.options.do.not.show"); } }; final StringBuilder names = new StringBuilder(); for (final RunContentDescriptor descriptor : runningIncompatibleDescriptors) { String name = descriptor.getDisplayName(); if (names.length() > 0) { names.append(", "); } names.append( StringUtil.isEmpty(name) ? ExecutionBundle.message("run.configuration.no.name") : String.format("'%s'", name)); } //noinspection DialogTitleCapitalization return Messages.showOkCancelDialog( project, ExecutionBundle.message( "stop.incompatible.confirmation.message", configName, names.toString(), runningIncompatibleDescriptors.size()), ExecutionBundle.message( "incompatible.configuration.is.running.dialog.title", runningIncompatibleDescriptors.size()), ExecutionBundle.message("stop.incompatible.confirmation.button.text"), CommonBundle.message("button.cancel"), Messages.getQuestionIcon(), option) == Messages.OK; }
public CloseAction() { super( CommonBundle.message("action.close"), AnalysisScopeBundle.message("action.close.dependency.description"), AllIcons.Actions.Cancel); }
public static String message( @NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { return CommonBundle.message(getBundle(), key, params); }