OSDN Git Service

FileFiltersDlg:
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 17 Mar 2022 15:32:01 +0000 (00:32 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 17 Mar 2022 15:32:01 +0000 (00:32 +0900)
- 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.

Filters/FileFilter.tmpl
Src/FileFiltersDlg.cpp
Src/FileFiltersDlg.h

index cfe3ad6..7d9ff16 100644 (file)
@@ -1,5 +1,5 @@
 ## This is a directory/file filter template for WinMerge
-name: Name of filter
+name: ${name}
 desc: Longer description
 
 ## Select if filter is inclusive or exclusive
index b040929..efe9208 100644 (file)
@@ -18,6 +18,7 @@
 #include "SharedFilterDlg.h"
 #include "TestFilterDlg.h"
 #include "FileOrFolderSelect.h"
+#include "UniFile.h"
 
 using std::vector;
 
@@ -147,6 +148,22 @@ void FileFiltersDlg::SelectFilterByIndex(int index)
 }
 
 /**
+ * @brief Select filter by file path in the listview.
+ * @param [in] path file path
+ */
+void FileFiltersDlg::SelectFilterByFilePath(const String& path)
+{
+       for (size_t i = 0; i < m_Filters.size(); ++i)
+       {
+               if (m_Filters[i].fullpath == path)
+               {
+                       SelectFilterByIndex(static_cast<int>(i + 1));
+                       break;
+               }
+       }
+}
+
+/**
  * @brief Called before dialog is shown.
  * @return Always TRUE.
  */
@@ -437,7 +454,9 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
 
                // Open-dialog asks about overwriting, so we can overwrite filter file
                // user has already allowed it.
-               if (!CopyFile(templatePath.c_str(), s.c_str(), FALSE))
+               UniMemFile fileIn;
+               UniStdioFile fileOut;
+               if (!fileIn.OpenReadOnly(templatePath) || !fileOut.OpenCreate(s))
                {
                        String msg = strutils::format_string1(
                                _( "Cannot copy filter template file to filter folder:\n%1\n\nPlease make sure the folder exists and is writable."),
@@ -445,6 +464,13 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
                        AfxMessageBox(msg.c_str(), MB_ICONERROR);
                        return;
                }
+               String lines;
+               fileIn.ReadStringAll(lines);
+               strutils::replace(lines, _T("${name}"), file);
+               fileOut.WriteString(lines);
+               fileIn.Close();
+               fileOut.Close();
+
                EditFileFilter(s);
                FileFilterMgr *pMgr = pGlobalFileFilter->GetManager();
                int retval = pMgr->AddFilter(s);
@@ -456,6 +482,7 @@ void FileFiltersDlg::OnBnClickedFilterfileNewbutton()
                        m_Filters = pGlobalFileFilter->GetFileFilters(selected);
 
                        UpdateFiltersList();
+                       SelectFilterByFilePath(s);
                }
        }
 }
@@ -580,6 +607,7 @@ void FileFiltersDlg::OnBnClickedFilterfileInstall()
                        m_Filters = pGlobalFileFilter->GetFileFilters(selected);
 
                        UpdateFiltersList();
+                       SelectFilterByFilePath(userPath);
                }
        }
 }
index 5a2866a..30f231a 100644 (file)
@@ -42,6 +42,7 @@ private:
 protected:
        void InitList();
        void SelectFilterByIndex(int index);
+       void SelectFilterByFilePath(const String& path);
        void AddToGrid(int filterIndex);
        bool IsFilterItemNone(int item) const;
        void UpdateFiltersList();