Skip to content

Commit

Permalink
Improve new style save file dialog
Browse files Browse the repository at this point in the history
The right file extension (which correspond to document type) is selected while saving a new file in the new style save file dialog.
  • Loading branch information
donho committed Jun 3, 2020
1 parent fa51c2a commit 69ef27b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions PowerEditor/src/NppIO.cpp
Expand Up @@ -1593,7 +1593,7 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy)
int langTypeIndex = setFileOpenSaveDlgFilters(fDlg, false, buf->getLangType());
fDlg.setDefFileName(buf->getFileName());

fDlg.setExtIndex(langTypeIndex+1); // +1 for "All types"
fDlg.setExtIndex(langTypeIndex + 1); // +1 for "All types"

// Disable file autodetection before opening save dialog to prevent use-after-delete bug.
NppParameters& nppParam = NppParameters::getInstance();
Expand Down Expand Up @@ -1828,7 +1828,8 @@ bool Notepad_plus::isFileSession(const TCHAR * filename)
return false;
}

bool Notepad_plus::isFileWorkspace(const TCHAR * filename) {
bool Notepad_plus::isFileWorkspace(const TCHAR * filename)
{
// if filename matches the ext of user defined workspace file ext, then it'll be opened as a workspace
const TCHAR *definedWorkspaceExt = NppParameters::getInstance().getNppGUI()._definedWorkspaceExt.c_str();
if (*definedWorkspaceExt != '\0')
Expand Down
5 changes: 3 additions & 2 deletions PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp
Expand Up @@ -35,8 +35,7 @@

FileDialog *FileDialog::staticThis = NULL;

FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst)
: _nbCharFileExt(0), _nbExt(0), _fileExt(NULL), _extTypeIndex(-1)
FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst)
{
staticThis = this;

Expand Down Expand Up @@ -269,6 +268,8 @@ TCHAR * FileDialog::doSaveDlg()
NppParameters& params = NppParameters::getInstance();
_ofn.lpstrInitialDir = params.getWorkingDir();
_ofn.lpstrDefExt = _defExt.c_str();
if (_extTypeIndex != -1)
_ofn.nFilterIndex = _extTypeIndex + 1; // +1 for the file extension combobox index starts from 1

_ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING;

Expand Down
8 changes: 4 additions & 4 deletions PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h
Expand Up @@ -66,16 +66,16 @@ protected :
TCHAR _fileName[MAX_PATH*8];
generic_string _defExt;

TCHAR * _fileExt;
int _nbCharFileExt;
TCHAR * _fileExt = nullptr;
int _nbCharFileExt = 0;

stringVector _fileNames;

OPENFILENAME _ofn;
winVer _winVersion;

int _nbExt;
int _extTypeIndex;
int _nbExt = 0;
int _extTypeIndex = -1;
static FileDialog *staticThis;
};

0 comments on commit 69ef27b

Please sign in to comment.