Lines 62-68
Link Here
|
62 |
import org.netbeans.api.project.Project; |
62 |
import org.netbeans.api.project.Project; |
63 |
import org.netbeans.api.project.ProjectUtils; |
63 |
import org.netbeans.api.project.ProjectUtils; |
64 |
import org.netbeans.api.project.SourceGroup; |
64 |
import org.netbeans.api.project.SourceGroup; |
65 |
import org.netbeans.api.project.Sources; |
|
|
66 |
import org.openide.awt.Mnemonics; |
65 |
import org.openide.awt.Mnemonics; |
67 |
import org.openide.filesystems.FileObject; |
66 |
import org.openide.filesystems.FileObject; |
68 |
import org.openide.filesystems.FileUtil; |
67 |
import org.openide.filesystems.FileUtil; |
Lines 70-75
Link Here
|
70 |
import org.openide.loaders.DataObjectNotFoundException; |
69 |
import org.openide.loaders.DataObjectNotFoundException; |
71 |
import org.openide.util.ChangeSupport; |
70 |
import org.openide.util.ChangeSupport; |
72 |
import static org.netbeans.modules.project.ui.Bundle.*; |
71 |
import static org.netbeans.modules.project.ui.Bundle.*; |
|
|
72 |
import org.openide.filesystems.FileChooserBuilder; |
73 |
import org.openide.util.NbBundle.Messages; |
73 |
import org.openide.util.NbBundle.Messages; |
74 |
|
74 |
|
75 |
/** |
75 |
/** |
Lines 83-100
Link Here
|
83 |
|
83 |
|
84 |
private final ListCellRenderer CELL_RENDERER = new GroupCellRenderer(); |
84 |
private final ListCellRenderer CELL_RENDERER = new GroupCellRenderer(); |
85 |
|
85 |
|
86 |
@NonNull |
86 |
@NullAllowed |
87 |
private Project project; |
87 |
private Project project; |
88 |
private String expectedExtension; |
88 |
private String expectedExtension; |
89 |
private final ChangeSupport changeSupport = new ChangeSupport(this); |
89 |
private final ChangeSupport changeSupport = new ChangeSupport(this); |
90 |
@NonNull |
90 |
@NonNull |
91 |
private SourceGroup[] folders; |
91 |
private final SourceGroup[] folders; |
92 |
private boolean isFolder; |
92 |
private boolean isFolder; |
93 |
private boolean freeFileExtension; |
93 |
private boolean freeFileExtension; |
94 |
|
94 |
|
95 |
@SuppressWarnings("LeakingThisInConstructor") |
95 |
@SuppressWarnings("LeakingThisInConstructor") |
96 |
@Messages("LBL_SimpleTargetChooserPanel_Name=Name and Location") |
96 |
@Messages("LBL_SimpleTargetChooserPanel_Name=Name and Location") |
97 |
public SimpleTargetChooserPanelGUI( @NonNull Project project, @NonNull SourceGroup[] folders, Component bottomPanel, boolean isFolder, boolean freeFileExtension) { |
97 |
public SimpleTargetChooserPanelGUI( @NullAllowed Project project, @NonNull SourceGroup[] folders, Component bottomPanel, boolean isFolder, boolean freeFileExtension) { |
98 |
this.project = project; |
98 |
this.project = project; |
99 |
this.folders = folders.clone(); |
99 |
this.folders = folders.clone(); |
100 |
this.isFolder = isFolder; |
100 |
this.isFolder = isFolder; |
Lines 126-142
Link Here
|
126 |
"LBL_TargetChooser_FileName_Label=File &Name:", |
126 |
"LBL_TargetChooser_FileName_Label=File &Name:", |
127 |
"LBL_TargetChooser_Folder_Label=Fo&lder:", |
127 |
"LBL_TargetChooser_Folder_Label=Fo&lder:", |
128 |
"LBL_TargetChooser_CreatedFile_Label=&Created File:", |
128 |
"LBL_TargetChooser_CreatedFile_Label=&Created File:", |
129 |
"# sample folder name", "LBL_folder_name=folder" |
129 |
"# sample folder name", "LBL_folder_name=folder", |
|
|
130 |
"LBL_TargetChooser_NoProject=None" |
130 |
}) |
131 |
}) |
131 |
final void initValues(FileObject template, @NullAllowed FileObject preselectedFolder, String documentName) { |
132 |
final void initValues(FileObject template, @NullAllowed FileObject preselectedFolder, String documentName) { |
132 |
assert project != null; |
133 |
if (project != null) { |
133 |
|
134 |
projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName()); |
134 |
projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName()); |
135 |
} else { |
135 |
|
136 |
projectTextField.setText(LBL_TargetChooser_NoProject()); |
136 |
Sources sources = ProjectUtils.getSources( project ); |
|
|
137 |
|
138 |
if (folders == null) { |
139 |
folders = sources.getSourceGroups( Sources.TYPE_GENERIC ); |
140 |
} |
137 |
} |
141 |
|
138 |
|
142 |
if ( folders.length < 2 ) { |
139 |
if ( folders.length < 2 ) { |
Lines 163-168
Link Here
|
163 |
} |
160 |
} |
164 |
folderTextField.setText(getRelativeNativeName(rootFolder, preselectedFolder)); |
161 |
folderTextField.setText(getRelativeNativeName(rootFolder, preselectedFolder)); |
165 |
} |
162 |
} |
|
|
163 |
else if (project == null && preselectedFolder != null) { |
164 |
folderTextField.setText(preselectedFolder.getPath().replace('/', File.separatorChar)); |
165 |
} |
166 |
|
166 |
|
167 |
String ext = template == null ? "" : template.getExt(); // NOI18N |
167 |
String ext = template == null ? "" : template.getExt(); // NOI18N |
168 |
expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N |
168 |
expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N |
Lines 217-226
Link Here
|
217 |
|
217 |
|
218 |
String folderName = folderTextField.getText().trim(); |
218 |
String folderName = folderTextField.getText().trim(); |
219 |
|
219 |
|
220 |
if ( folderName.length() == 0 ) { |
220 |
if ( folderName.isEmpty() ) { |
|
|
221 |
if (project == null) { |
222 |
String home = System.getProperty("user.home"); |
223 |
if (home != null && new File(home).isDirectory()) { |
224 |
return home; |
225 |
} |
226 |
} |
227 |
|
221 |
return null; |
228 |
return null; |
222 |
} |
229 |
} |
223 |
else { |
230 |
else { |
|
|
231 |
if (project == null && !new File(folderName).isAbsolute()) { |
232 |
String home = System.getProperty("user.home"); |
233 |
if (home != null && new File(home).isDirectory()) { |
234 |
FileObject homeFileObject = FileUtil.toFileObject(FileUtil.normalizeFile(new File(home))); |
235 |
folderName = FileUtil.getFileDisplayName(homeFileObject) + File.separatorChar + folderName; |
236 |
} |
237 |
} |
238 |
|
224 |
return folderName.replace( File.separatorChar, '/' ); // NOI18N |
239 |
return folderName.replace( File.separatorChar, '/' ); // NOI18N |
225 |
} |
240 |
} |
226 |
} |
241 |
} |
Lines 429-447
Link Here
|
429 |
private void updateCreatedFolder() { |
444 |
private void updateCreatedFolder() { |
430 |
|
445 |
|
431 |
SourceGroup sg = (SourceGroup)locationComboBox.getSelectedItem(); |
446 |
SourceGroup sg = (SourceGroup)locationComboBox.getSelectedItem(); |
432 |
if (sg == null) { |
447 |
FileObject root = sg != null ? sg.getRootFolder() : null; |
433 |
return; |
448 |
String documentName = documentNameTextField.getText().trim(); |
|
|
449 |
String folderName = getTargetFolder(); |
450 |
if (folderName == null) { |
451 |
folderName = ""; |
434 |
} |
452 |
} |
435 |
FileObject root = sg.getRootFolder(); |
|
|
436 |
if (root == null) { |
437 |
return; |
438 |
} |
439 |
|
440 |
String folderName = folderTextField.getText().trim(); |
441 |
String documentName = documentNameTextField.getText().trim(); |
442 |
|
453 |
|
443 |
String createdFileName = FileUtil.getFileDisplayName( root ) + |
454 |
String createdFileName = (root != null ? FileUtil.getFileDisplayName( root ) : "") + |
444 |
( folderName.startsWith("/") || folderName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N |
455 |
( root == null || folderName.startsWith("/") || folderName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N |
445 |
folderName + |
456 |
folderName + |
446 |
( folderName.endsWith("/") || folderName.endsWith( File.separator ) || folderName.length() == 0 ? "" : "/" ) + // NOI18N |
457 |
( folderName.endsWith("/") || folderName.endsWith( File.separator ) || folderName.length() == 0 ? "" : "/" ) + // NOI18N |
447 |
documentName + (!freeFileExtension || documentName.indexOf('.') == -1 ? expectedExtension : ""); |
458 |
documentName + (!freeFileExtension || documentName.indexOf('.') == -1 ? expectedExtension : ""); |
Lines 456-477
Link Here
|
456 |
|
467 |
|
457 |
public @Override void actionPerformed(ActionEvent e) { |
468 |
public @Override void actionPerformed(ActionEvent e) { |
458 |
if ( browseButton == e.getSource() ) { |
469 |
if ( browseButton == e.getSource() ) { |
459 |
FileObject fo=null; |
470 |
if (project != null) { |
460 |
// Show the browse dialog |
471 |
FileObject fo; |
461 |
|
472 |
// Show the browse dialog |
462 |
SourceGroup group = (SourceGroup)locationComboBox.getSelectedItem(); |
473 |
|
463 |
if (group == null) { // #161478 |
474 |
SourceGroup group = (SourceGroup)locationComboBox.getSelectedItem(); |
464 |
return; |
475 |
if (group == null) { // #161478 |
|
|
476 |
return; |
477 |
} |
478 |
|
479 |
fo = BrowseFolders.showDialog( new SourceGroup[] { group }, |
480 |
project, |
481 |
folderTextField.getText().replace( File.separatorChar, '/' ) ); // NOI18N |
482 |
|
483 |
if ( fo != null && fo.isFolder() ) { |
484 |
String relPath = FileUtil.getRelativePath( group.getRootFolder(), fo ); |
485 |
folderTextField.setText( relPath.replace( '/', File.separatorChar ) ); // NOI18N |
486 |
} |
465 |
} |
487 |
} |
466 |
|
488 |
else { |
467 |
fo = BrowseFolders.showDialog( new SourceGroup[] { group }, |
489 |
String previousTargetFolder = getTargetFolder(); |
468 |
project, |
490 |
File targetFolder = |
469 |
folderTextField.getText().replace( File.separatorChar, '/' ) ); // NOI18N |
491 |
new FileChooserBuilder(SimpleTargetChooserPanel.class) |
470 |
|
492 |
.setDirectoriesOnly(true) |
471 |
if ( fo != null && fo.isFolder() ) { |
493 |
.setDefaultWorkingDirectory(new File(previousTargetFolder != null ? previousTargetFolder : ".")) |
472 |
String relPath = FileUtil.getRelativePath( group.getRootFolder(), fo ); |
494 |
.forceUseOfDefaultWorkingDirectory(previousTargetFolder != null) |
473 |
folderTextField.setText( relPath.replace( '/', File.separatorChar ) ); // NOI18N |
495 |
.showSaveDialog(); |
474 |
} |
496 |
|
|
|
497 |
FileObject fo = targetFolder != null ? FileUtil.toFileObject(FileUtil.normalizeFile(targetFolder)) : null; |
498 |
|
499 |
if ( fo != null && fo.isFolder() ) { |
500 |
folderTextField.setText( fo.getPath().replace( '/', File.separatorChar ) ); // NOI18N |
501 |
} |
502 |
} |
475 |
} |
503 |
} |
476 |
else if ( locationComboBox == e.getSource() ) { |
504 |
else if ( locationComboBox == e.getSource() ) { |
477 |
updateCreatedFolder(); |
505 |
updateCreatedFolder(); |