How to make Notepad++ use “.txt” files as the default open file dialog filter

notepad

When I go to open files in NPP, the file types defaults to "all types (.)".

How can I make this default to ".txt"?

It may be a windows thing, since I'm sure it just uses the default windows file open dialog, but other programs (textpad, notepad) are able to default it.

Best Answer

I have just finished reviewing the NPP source code, and have some additional details if you would like to seek a solution for yourself. When you go File -> Open, the list of file extensions is loaded from the Scintilla (SciLexer.dll) file.

Now, when you go File -> Open, the void Notepad_plus::fileOpen() function is called (in the NppIO.cpp file). Initially, the All Types, *.* filter is added to the filter list, and then, the int Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg, int langType) function is called (in the same file). This function goes through the Scintilla entries I mentioned above, and adds them to the passed FileDialog's filter list. The code in FileOpen looks like this:

fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
setFileOpenSaveDlgFilters(fDlg);

You can change the default filter index. To do that, you can instead change those lines to this:

fDlg._ofn.nFilterIndex = 2L;
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
setFileOpenSaveDlgFilters(fDlg);

That should set the filter index to the second one by default.


Another easy way to quick-fix this is to modify those lines (again, in NppIO.cpp) to look like this:

fDlg.setExtFilter(TEXT("Text files"), TEXT(".txt"),
                  TEXT("All types"),  TEXT(".*"), NULL);
setFileOpenSaveDlgFilters(fDlg);

That will ensure that Text files are the first filter on the list. Do note that this will cause the .txt extension to be double-defined in the entries, but if you can live with that caveat, this should work fine.

Related Question