use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project intellij-community by JetBrains.
the class ApplyPatchSaveToFileExecutor method apply.
@Override
public void apply(@NotNull List<FilePatch> remaining, @NotNull MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable String fileName, @Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Save Patch to", ""), myProject);
VirtualFileWrapper targetFile = dialog.save(myProject.getBaseDir(), "TheirsChanges.patch");
if (targetFile != null) {
savePatch(patchGroupsToApply, targetFile);
}
}
use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project intellij-community by JetBrains.
the class CaptureConfigurable method createComponent.
@Nullable
@Override
public JComponent createComponent() {
myTableModel = new MyTableModel();
JBTable table = new JBTable(myTableModel);
table.setColumnSelectionAllowed(false);
TableColumnModel columnModel = table.getColumnModel();
TableUtil.setupCheckboxColumn(columnModel.getColumn(MyTableModel.ENABLED_COLUMN));
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
myTableModel.addRow();
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.removeSelectedItems(table);
}
});
decorator.setMoveUpAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsUp(table);
}
});
decorator.setMoveDownAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsDown(table);
}
});
decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() == 1;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> {
try {
int idx = myTableModel.add(c.clone());
table.getSelectionModel().setSelectionInterval(idx, idx);
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
}
});
decorator.addExtraAction(new DumbAwareActionButton("Enable Selected", "Enable Selected", PlatformIcons.SELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = true);
table.repaint();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Disable Selected", "Disable Selected", PlatformIcons.UNSELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = false);
table.repaint();
}
});
new DumbAwareAction("Toggle") {
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(table.getSelectedRowCount() == 1);
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = !c.myEnabled);
table.repaint();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), table);
decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, true) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return file.getFileType() == StdFileTypes.XML;
}
};
descriptor.setDescription("Please select a file to import.");
descriptor.setTitle("Import Capture Points");
VirtualFile[] files = FileChooser.chooseFiles(descriptor, e.getProject(), null);
if (ArrayUtil.isEmpty(files))
return;
table.getSelectionModel().clearSelection();
for (VirtualFile file : files) {
try {
Document document = JDOMUtil.loadDocument(file.getInputStream());
List<Element> children = document.getRootElement().getChildren();
children.forEach(element -> {
int idx = myTableModel.addIfNeeded(XmlSerializer.deserialize(element, CapturePoint.class));
table.getSelectionModel().addSelectionInterval(idx, idx);
});
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
}
});
decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Capture Points to File...", "", "xml"), e.getProject()).save(null, null);
if (wrapper == null)
return;
Element rootElement = new Element("capture-points");
selectedCapturePoints(table).forEach(c -> {
try {
CapturePoint clone = c.clone();
clone.myEnabled = false;
rootElement.addContent(XmlSerializer.serialize(clone));
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
try {
JDOMUtil.write(rootElement, wrapper.getFile());
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
});
BorderLayoutPanel panel = JBUI.Panels.simplePanel();
panel.addToCenter(decorator.createPanel());
myCaptureVariables = new JCheckBox(DebuggerBundle.message("label.capture.configurable.capture.variables"));
panel.addToBottom(myCaptureVariables);
return panel;
}
use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project intellij-community by JetBrains.
the class InjectionsSettingsUI method createActions.
private void createActions(ToolbarDecorator decorator) {
final Consumer<BaseInjection> consumer = injection -> addInjection(injection);
final Factory<BaseInjection> producer = (NullableFactory<BaseInjection>) () -> {
final InjInfo info = getSelectedInjection();
return info == null ? null : info.injection;
};
for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer));
final AnAction action = support.createEditAction(myProject, producer);
myEditActions.put(support.getId(), action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer) : action);
mySupports.put(support.getId(), support);
}
Collections.sort(myAddActions, (o1, o2) -> Comparing.compare(o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()));
decorator.disableUpDownActions();
decorator.setAddActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return !myAddActions.isEmpty();
}
});
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performAdd(button);
}
});
decorator.setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
boolean enabled = false;
for (InjInfo info : getSelectedInjections()) {
if (!info.bundled) {
enabled = true;
break;
}
}
return enabled;
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performRemove();
}
});
decorator.setEditActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
AnAction edit = getEditAction();
if (edit != null)
edit.update(e);
return edit != null && edit.getTemplatePresentation().isEnabled();
}
});
decorator.setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performEditAction();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
@Override
public boolean isEnabled() {
return getEditAction() != null;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final InjInfo injection = getSelectedInjection();
if (injection != null) {
addInjection(injection.injection.copy());
//performEditAction(e);
}
}
});
decorator.addExtraAction(new DumbAwareActionButton("Enable Selected Injections", "Enable Selected Injections", PlatformIcons.SELECT_ALL_ICON) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performSelectedInjectionsEnabled(true);
}
});
decorator.addExtraAction(new DumbAwareActionButton("Disable Selected Injections", "Disable Selected Injections", PlatformIcons.UNSELECT_ALL_ICON) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performSelectedInjectionsEnabled(false);
}
});
new DumbAwareAction("Toggle") {
@Override
public void update(@NotNull AnActionEvent e) {
SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myInjectionsTable);
e.getPresentation().setEnabled(supply == null || !supply.isPopupActive());
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performToggleAction();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable);
if (myInfos.length > 1) {
AnActionButton shareAction = new DumbAwareActionButton("Move to IDE Scope", null, PlatformIcons.IMPORT_ICON) {
{
addCustomUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
CfgInfo cfg = getTargetCfgInfo(getSelectedInjections());
e.getPresentation().setText(cfg == getDefaultCfgInfo() ? "Move to IDE Scope" : "Move to Project Scope");
return cfg != null;
}
});
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final List<InjInfo> injections = getSelectedInjections();
final CfgInfo cfg = getTargetCfgInfo(injections);
if (cfg == null)
return;
for (InjInfo info : injections) {
if (info.cfgInfo == cfg)
continue;
if (info.bundled)
continue;
info.cfgInfo.injectionInfos.remove(info);
cfg.addInjection(info.injection);
}
final int[] selectedRows = myInjectionsTable.getSelectedRows();
myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
TableUtil.selectRows(myInjectionsTable, selectedRows);
}
@Nullable
private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) {
CfgInfo cfg = null;
for (InjInfo info : injections) {
if (info.bundled) {
continue;
}
if (cfg == null)
cfg = info.cfgInfo;
else if (cfg != info.cfgInfo)
return info.cfgInfo;
}
if (cfg == null)
return null;
for (CfgInfo info : myInfos) {
if (info != cfg)
return info;
}
throw new AssertionError();
}
};
shareAction.setShortcut(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK)));
decorator.addExtraAction(shareAction);
}
decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
doImportAction(e.getDataContext());
updateCountLabel();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final List<BaseInjection> injections = getInjectionList(getSelectedInjections());
final VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Injections to File...", "", "xml"), myProject).save(null, null);
if (wrapper == null)
return;
final Configuration configuration = new Configuration();
configuration.setInjections(injections);
try {
JdomKt.write(configuration.getState(), wrapper.getFile().toPath());
} catch (IOException ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
@Override
public boolean isEnabled() {
return !getSelectedInjections().isEmpty();
}
});
}
use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project intellij-community by JetBrains.
the class FileChooserUtil method getFileToSelect.
@Nullable
public static VirtualFile getFileToSelect(@NotNull FileChooserDescriptor descriptor, @Nullable Project project, @Nullable VirtualFile toSelect, @Nullable VirtualFile lastPath) {
boolean chooseDir = descriptor instanceof FileSaverDescriptor;
VirtualFile result;
if (toSelect == null && lastPath == null) {
result = project == null ? null : project.getBaseDir();
} else if (toSelect != null && lastPath != null) {
if (Boolean.TRUE.equals(descriptor.getUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT))) {
result = lastPath;
} else {
result = toSelect;
}
} else if (toSelect == null) {
result = lastPath;
} else {
result = toSelect;
}
if (result != null) {
if (chooseDir && !result.isDirectory()) {
result = result.getParent();
}
} else if (SystemInfo.isUnix) {
result = VfsUtil.getUserHomeDir();
}
return result;
}
use of com.intellij.openapi.fileChooser.FileSaverDescriptor in project android by JetBrains.
the class ConvertToNinePatchAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final VirtualFile pngFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
if (!isPngFile(pngFile)) {
return;
}
FileSaverDescriptor descriptor = new FileSaverDescriptor(AndroidBundle.message("android.9patch.creator.save.title"), "", SdkConstants.EXT_PNG);
FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project) null);
VirtualFileWrapper fileWrapper = saveFileDialog.save(pngFile.getParent(), pngFile.getNameWithoutExtension().concat(SdkConstants.DOT_9PNG));
if (fileWrapper == null) {
return;
}
final File patchFile = fileWrapper.getFile();
new Task.Modal(null, "Creating 9-Patch File", false) {
private IOException myException;
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
try {
BufferedImage pngImage = ImageIO.read(VfsUtilCore.virtualToIoFile(pngFile));
BufferedImage patchImage = ImageUtils.addMargin(pngImage, 1);
ImageIO.write(patchImage, SdkConstants.EXT_PNG, patchFile);
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patchFile);
} catch (IOException e) {
myException = e;
}
}
@Override
public void onSuccess() {
if (myException != null) {
Messages.showErrorDialog(AndroidBundle.message("android.9patch.creator.error", myException.getMessage()), AndroidBundle.message("android.9patch.creator.error.title"));
}
}
}.queue();
}
Aggregations