mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-64949 Use standard platform file chooser in 'Create patch' action invoked on patch on the shelf
This commit is contained in:
@@ -467,7 +467,7 @@ public abstract class HistoryDialog<T extends HistoryDialogModel> extends FrameW
|
||||
return;
|
||||
}
|
||||
|
||||
CreatePatchConfigurationPanel p = new CreatePatchConfigurationPanel();
|
||||
CreatePatchConfigurationPanel p = new CreatePatchConfigurationPanel(myProject);
|
||||
p.setFileName(getDefaultPatchFile());
|
||||
if (!showAsDialog(p)) return;
|
||||
myModel.createPatch(p.getFileName(), p.isReversePatch());
|
||||
|
||||
@@ -548,3 +548,4 @@ line.annotation.aspect.author=Author
|
||||
line.annotation.aspect.date=Date
|
||||
line.annotation.aspect.revision=Revision
|
||||
annotation.commit.number=Commit number
|
||||
create.patch.file.path=&Patch file:
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class CreatePatchCommitExecutor implements CommitExecutorWithHelp, Projec
|
||||
}
|
||||
|
||||
private class CreatePatchCommitSession implements CommitSession {
|
||||
private final CreatePatchConfigurationPanel myPanel = new CreatePatchConfigurationPanel();
|
||||
private final CreatePatchConfigurationPanel myPanel = new CreatePatchConfigurationPanel(myProject);
|
||||
|
||||
@Nullable
|
||||
public JComponent getAdditionalConfigurationUI() {
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="e6922"/>
|
||||
<text resource-bundle="messages/VcsBundle" key="create.patch.file.name.field"/>
|
||||
<text resource-bundle="messages/VcsBundle" key="create.patch.file.path"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="86590">
|
||||
|
||||
+26
-6
@@ -22,7 +22,17 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.patch;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.fileChooser.FileSaverDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileSaverDialog;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileWrapper;
|
||||
import com.intellij.util.Consumer;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -37,15 +47,22 @@ public class CreatePatchConfigurationPanel {
|
||||
private JLabel myErrorLabel;
|
||||
private Consumer<Boolean> myOkEnabledListener;
|
||||
|
||||
public CreatePatchConfigurationPanel() {
|
||||
public CreatePatchConfigurationPanel(final Project project) {
|
||||
myFileNameField.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setSelectedFile(new File(myFileNameField.getText()));
|
||||
if (fileChooser.showSaveDialog(myFileNameField) != JFileChooser.APPROVE_OPTION) {
|
||||
return;
|
||||
final FileSaverDialog dialog =
|
||||
FileChooserFactory.getInstance().createSaveFileDialog(
|
||||
new FileSaverDescriptor("Save patch to", ""), myPanel);
|
||||
final String path = FileUtil.toSystemIndependentName(myFileNameField.getText().trim());
|
||||
final int idx = path.lastIndexOf("/");
|
||||
VirtualFile baseDir = idx == -1 ? project.getBaseDir() :
|
||||
(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path.substring(0, idx))));
|
||||
baseDir = baseDir == null ? project.getBaseDir() : baseDir;
|
||||
final String name = idx == -1 ? path : path.substring(idx + 1);
|
||||
final VirtualFileWrapper fileWrapper = dialog.save(baseDir, name);
|
||||
if (fileWrapper != null) {
|
||||
myFileNameField.setText(fileWrapper.getFile().getPath());
|
||||
}
|
||||
myFileNameField.setText(fileChooser.getSelectedFile().getPath());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,6 +70,7 @@ public class CreatePatchConfigurationPanel {
|
||||
public void inputMethodTextChanged(final InputMethodEvent event) {
|
||||
checkName();
|
||||
}
|
||||
|
||||
public void caretPositionChanged(final InputMethodEvent event) {
|
||||
}
|
||||
});
|
||||
@@ -60,9 +78,11 @@ public class CreatePatchConfigurationPanel {
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
checkName();
|
||||
}
|
||||
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
checkName();
|
||||
}
|
||||
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
checkName();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user