private void SaveSelectedFilename(string filename) { if (m_openMode && m_folderMode) { char pathSep = FilePath.GetPathSeparator(PathFormat.Unix); if (filename[0] == pathSep) { if (!filename.EndsWith(pathSep.ToString())) { filename += pathSep; } m_selectedFile.Assign(filename, PathFormat.Unix); } else { m_selectedFile.Assign(m_currentPath); m_selectedFile.AppendDir(filename); } m_currentPath.Assign(m_selectedFile); } else { m_selectedFile.Assign(m_currentPath.GetPath(), filename, PathFormat.Unix); } this.DialogResult = DialogResult.OK; }
private void ItemActivated() { string userFilename = txtFilename.Text; FilePath fp = new FilePath(); bool isFile = (m_currentDirListing.dirNames.IndexOf(userFilename) == -1); // the item name isn't a directory if (isFile) { // if we're trying to save a file and the filter isn't "All files (*.*) if (!m_openMode && (m_currentFilterIndex != m_filterAllFilesIndex)) { fp.FullName = userFilename; string ext = fp.Extension; if (ext == "") { // retrieves the appropriate set of extensions for the // selected filter and uses the first one as the default extension fp.Extension = m_fileExtensionList[m_currentFilterIndex][0]; userFilename = fp.FullName; } } int fileResult = m_currentDirListing.fileNames.IndexOf(userFilename); // and it's not a file either if (fileResult == -1) { // trying to open a non-existent file if (m_openMode) { string errorMessage = "\"" + userFilename + "\" was not found. Please enter or select a valid file name."; MessageBox.Show(errorMessage, "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // trying to save a file and it's a new file else { SaveSelectedFilename(userFilename); } } else { // filename found, open it if (m_openMode) { SaveSelectedFilename(userFilename); } // file already exists - confirm overwrite else { string confirmMessage = userFilename + " already exists. Do you want to replace it?"; DialogResult dr = MessageBox.Show(confirmMessage, "Overwrite File?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { SaveSelectedFilename(userFilename); } else { return; } } } } else { // call ShowDirectory with the new directory // m_currentPath gets overwritten in ShowDirectory iff the call succeeds FilePath tempDirName = new FilePath(m_currentPath); tempDirName.AppendDir(userFilename); if (!ShowDirectory(tempDirName.GetPath(PathReturnType.NoSeparator, PathFormat.Unix), false, false)) { // TODO update error message // at the moment, this will only fail if we get an exception, which is handled internally //string errorMessage = "The directory listing failed. Please run in circles, scream and shout."; //MessageBox.Show(errorMessage); } } txtFilename.Text = ""; }