private void moveToUndoStorage(final VirtualFile file) { if (myStorageForUndo == null) { try { myStorageForUndo = FileUtil.createTempDirectory("svnUndoStorage", ""); } catch (IOException e) { LOG.error(e); return; } } final File tmpFile = FileUtil.findSequentNonexistentFile(myStorageForUndo, "tmp", ""); myUndoStorageContents.add(0, new Pair<File, File>(new File(file.getPath()), tmpFile)); new File(file.getPath()).renameTo(tmpFile); }
private ShelvedBinaryFile shelveBinaryFile(final Change change) throws IOException { final ContentRevision beforeRevision = change.getBeforeRevision(); final ContentRevision afterRevision = change.getAfterRevision(); File beforeFile = beforeRevision == null ? null : beforeRevision.getFile().getIOFile(); File afterFile = afterRevision == null ? null : afterRevision.getFile().getIOFile(); String shelvedPath = null; if (afterFile != null) { String shelvedName = FileUtil.getNameWithoutExtension(afterFile.getName()); String shelvedExt = FileUtil.getExtension(afterFile.getName()); File shelvedFile = FileUtil.findSequentNonexistentFile( myFileProcessor.getBaseIODir(), shelvedName, shelvedExt); myFileProcessor.saveFile(afterRevision.getFile().getIOFile(), shelvedFile); shelvedPath = shelvedFile.getPath(); } String beforePath = ChangesUtil.getProjectRelativePath(myProject, beforeFile); String afterPath = ChangesUtil.getProjectRelativePath(myProject, afterFile); return new ShelvedBinaryFile(beforePath, afterPath, shelvedPath); }
public static File suggestPatchName( Project project, final String commitMessage, final File file, String extension) { @NonNls String defaultPath = PathUtil.suggestFileName(commitMessage); if (defaultPath.length() == 0) { defaultPath = "unnamed"; } if (defaultPath.length() > (PatchNameChecker.MAX - 10)) { defaultPath = defaultPath.substring(0, PatchNameChecker.MAX - 10); } while (true) { final File nonexistentFile = FileUtil.findSequentNonexistentFile( file, defaultPath, extension == null ? VcsConfiguration.getInstance(project).getPatchFileExtension() : extension); if (nonexistentFile.getName().length() >= PatchNameChecker.MAX) { defaultPath = defaultPath.substring(0, defaultPath.length() - 1); continue; } return nonexistentFile; } }
public LocationNameFieldsBinding( Project project, final TextFieldWithBrowseButton locationTextField, final JTextField nameTextField, String baseDir, final String browseFolderTitle) { myBaseDir = baseDir; File suggestedProjectDirectory = FileUtil.findSequentNonexistentFile(new File(baseDir), "untitled", ""); locationTextField.setText(suggestedProjectDirectory.toString()); nameTextField.setDocument(new NameFieldDocument(nameTextField, locationTextField)); mySuggestedProjectName = suggestedProjectDirectory.getName(); nameTextField.setText(mySuggestedProjectName); nameTextField.selectAll(); FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); ComponentWithBrowseButton.BrowseFolderActionListener<JTextField> listener = new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>( browseFolderTitle, "", locationTextField, project, descriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) { protected void onFileChoosen(VirtualFile chosenFile) { myBaseDir = chosenFile.getPath(); if (isProjectNameChanged(nameTextField.getText()) && !nameTextField.getText().equals(chosenFile.getName())) { myExternalModify = true; locationTextField.setText( new File(chosenFile.getPath(), nameTextField.getText()).toString()); myExternalModify = false; } else { myExternalModify = true; locationTextField.setText(chosenFile.getPath()); nameTextField.setText(chosenFile.getName()); myExternalModify = false; } } }; locationTextField.addActionListener(listener); locationTextField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { if (myExternalModify) { return; } myModifyingLocation = true; String path = locationTextField.getText().trim(); if (path.endsWith(File.separator)) { path = path.substring(0, path.length() - File.separator.length()); } int ind = path.lastIndexOf(File.separator); if (ind != -1) { String projectName = path.substring(ind + 1, path.length()); if (!nameTextField.getText().trim().isEmpty()) { myBaseDir = path.substring(0, ind); } if (!projectName.equals(nameTextField.getText())) { if (!myModifyingProjectName) { nameTextField.setText(projectName); } } } myModifyingLocation = false; } }); }