Skip to content

Commit 6b85d42

Browse files
committed
FileFiltersDlg:
- Embed the specified file name after "name:" in the filter file when creating a new file filter - Select the file filter added to the list view after pressing the New or Install button.
1 parent 32a2be4 commit 6b85d42

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Filters/FileFilter.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## This is a directory/file filter template for WinMerge
2-
name: Name of filter
2+
name: ${name}
33
desc: Longer description
44

55
## Select if filter is inclusive or exclusive

Src/FileFiltersDlg.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "SharedFilterDlg.h"
1919
#include "TestFilterDlg.h"
2020
#include "FileOrFolderSelect.h"
21+
#include "UniFile.h"
2122

2223
using std::vector;
2324

@@ -146,6 +147,22 @@ void FileFiltersDlg::SelectFilterByIndex(int index)
146147
m_listFilters.EnsureVisible(index, bPartialOk);
147148
}
148149

150+
/**
151+
* @brief Select filter by file path in the listview.
152+
* @param [in] path file path
153+
*/
154+
void FileFiltersDlg::SelectFilterByFilePath(const String& path)
155+
{
156+
for (size_t i = 0; i < m_Filters.size(); ++i)
157+
{
158+
if (m_Filters[i].fullpath == path)
159+
{
160+
SelectFilterByIndex(static_cast<int>(i + 1));
161+
break;
162+
}
163+
}
164+
}
165+
149166
/**
150167
* @brief Called before dialog is shown.
151168
* @return Always TRUE.
@@ -437,14 +454,23 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
437454

438455
// Open-dialog asks about overwriting, so we can overwrite filter file
439456
// user has already allowed it.
440-
if (!CopyFile(templatePath.c_str(), s.c_str(), FALSE))
457+
UniMemFile fileIn;
458+
UniStdioFile fileOut;
459+
if (!fileIn.OpenReadOnly(templatePath) || !fileOut.OpenCreate(s))
441460
{
442461
String msg = strutils::format_string1(
443462
_( "Cannot copy filter template file to filter folder:\n%1\n\nPlease make sure the folder exists and is writable."),
444463
templatePath);
445464
AfxMessageBox(msg.c_str(), MB_ICONERROR);
446465
return;
447466
}
467+
String lines;
468+
fileIn.ReadStringAll(lines);
469+
strutils::replace(lines, _T("${name}"), file);
470+
fileOut.WriteString(lines);
471+
fileIn.Close();
472+
fileOut.Close();
473+
448474
EditFileFilter(s);
449475
FileFilterMgr *pMgr = pGlobalFileFilter->GetManager();
450476
int retval = pMgr->AddFilter(s);
@@ -456,6 +482,7 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
456482
m_Filters = pGlobalFileFilter->GetFileFilters(selected);
457483

458484
UpdateFiltersList();
485+
SelectFilterByFilePath(s);
459486
}
460487
}
461488
}
@@ -580,6 +607,7 @@ void FileFiltersDlg::OnBnClickedFilterfileInstall()
580607
m_Filters = pGlobalFileFilter->GetFileFilters(selected);
581608

582609
UpdateFiltersList();
610+
SelectFilterByFilePath(userPath);
583611
}
584612
}
585613
}

Src/FileFiltersDlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class FileFiltersDlg : public CTrPropertyPage
4242
protected:
4343
void InitList();
4444
void SelectFilterByIndex(int index);
45+
void SelectFilterByFilePath(const String& path);
4546
void AddToGrid(int filterIndex);
4647
bool IsFilterItemNone(int item) const;
4748
void UpdateFiltersList();

0 commit comments

Comments
 (0)