18
18
#include " SharedFilterDlg.h"
19
19
#include " TestFilterDlg.h"
20
20
#include " FileOrFolderSelect.h"
21
+ #include " UniFile.h"
21
22
22
23
using std::vector;
23
24
@@ -146,6 +147,22 @@ void FileFiltersDlg::SelectFilterByIndex(int index)
146
147
m_listFilters.EnsureVisible (index , bPartialOk);
147
148
}
148
149
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
+
149
166
/* *
150
167
* @brief Called before dialog is shown.
151
168
* @return Always TRUE.
@@ -437,14 +454,23 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
437
454
438
455
// Open-dialog asks about overwriting, so we can overwrite filter file
439
456
// 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))
441
460
{
442
461
String msg = strutils::format_string1 (
443
462
_ ( " Cannot copy filter template file to filter folder:\n %1\n\n Please make sure the folder exists and is writable." ),
444
463
templatePath);
445
464
AfxMessageBox (msg.c_str (), MB_ICONERROR);
446
465
return ;
447
466
}
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
+
448
474
EditFileFilter (s);
449
475
FileFilterMgr *pMgr = pGlobalFileFilter->GetManager ();
450
476
int retval = pMgr->AddFilter (s);
@@ -456,6 +482,7 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
456
482
m_Filters = pGlobalFileFilter->GetFileFilters (selected);
457
483
458
484
UpdateFiltersList ();
485
+ SelectFilterByFilePath (s);
459
486
}
460
487
}
461
488
}
@@ -580,6 +607,7 @@ void FileFiltersDlg::OnBnClickedFilterfileInstall()
580
607
m_Filters = pGlobalFileFilter->GetFileFilters (selected);
581
608
582
609
UpdateFiltersList ();
610
+ SelectFilterByFilePath (userPath);
583
611
}
584
612
}
585
613
}
0 commit comments