OSDN Git Service

Fix an issue where items with different case are not displayed correctly in the folde...
[winmerge-jp/winmerge-jp.git] / Src / FileFilterMgr.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /**
3  *  @file FileFilterMgr.h
4  *
5  *  @brief Declaration file for FileFilterMgr
6  */ 
7 #pragma once
8
9 #include <vector>
10 #include "UnicodeString.h"
11 #include "FileFilter.h"
12
13 /**
14  * @brief Return values for many filter functions.
15  */
16 enum FILTER_RETVALUE
17 {
18         FILTER_OK = 0,  /**< Success */
19         FILTER_ERROR_FILEACCESS,  /**< File could not be opened etc. */
20         FILTER_NOTFOUND, /**< Filter not found */
21 };
22
23 /**
24  * @brief File filter manager for handling filefilters.
25  *
26  * The FileFilterMgr loads a collection of named file filters from disk,
27  * and provides lookup access by name, or array access by index, to these
28  * named filters. It also provides test functions for actually using the
29  * filters.
30  *
31  * We are using PCRE for regular expressions. Nice thing in PCRE is it supports
32  * UTF-8 unicode, unlike many other libs. For ANSI builds we use just ansi
33  * strings, and for unicode we must first convert strings to UTF-8.
34  */
35 class FileFilterMgr
36 {
37 private:
38
39 public:
40         ~FileFilterMgr();
41         // Reload filter array from specified directory (passed to CFileFind)
42         void LoadFromDirectory(const String& dir, const String& szPattern, const String& szExt);
43         // Reload an edited filter
44         int ReloadFilterFromDisk(FileFilter * pfilter);
45         int ReloadFilterFromDisk(const String& szFullPath);
46         // Load a filter from a string
47         void LoadFilterString(const String& szFilterString);
48         int AddFilter(const String& szFilterFile);
49         void RemoveFilter(const String& szFilterFile);
50
51         // access to array of filters
52         int GetFilterCount() const { return (int) m_filters.size(); }
53         String GetFilterName(int i) const;
54         String GetFilterName(const FileFilter *pFilter) const;
55         String GetFilterPath(int i) const;
56         String GetFilterDesc(int i) const;
57         String GetFilterDesc(const FileFilter *pFilter) const;
58         FileFilter * GetFilterByPath(const String& szFilterName);
59         FileFilter * GetFilterByIndex(int i);
60         String GetFullpath(FileFilter * pfilter) const;
61
62         // methods to actually use filter
63         bool TestFileNameAgainstFilter(const FileFilter * pFilter, const String& szFileName) const;
64         bool TestDirNameAgainstFilter(const FileFilter * pFilter, const String& szDirName) const;
65
66         void DeleteAllFilters();
67         void CloneFrom(const FileFilterMgr* fileFilterMgr);
68
69 // Implementation methods
70 protected:
71         // Clear the list of known filters
72         // Load a filter from a file (if syntax is valid)
73         FileFilter * LoadFilterFile(const String& szFilepath, int & errorcode);
74
75 // Implementation data
76 private:
77         std::vector<FileFilterPtr> m_filters; /*< List of filters loaded */
78 };
79
80
81 bool TestAgainstRegList(const std::vector<FileFilterElementPtr> *filterList, const String& szTest);
82 void EmptyFilterList(std::vector<FileFilterElementPtr> *filterList);
83
84 /**
85  * @brief Return name of filter.
86  *
87  * @param [in] i Index of filter.
88  * @return Name of filter in given index.
89  */
90 inline String FileFilterMgr::GetFilterName(int i) const
91 {
92         return m_filters[i]->name; 
93 }
94
95 /**
96  * @brief Return name of filter.
97  * @param [in] pFilter Filter to get name for.
98  * @return Given filter's name.
99  */
100 inline String FileFilterMgr::GetFilterName(const FileFilter *pFilter) const
101 {
102         return pFilter->name; 
103 }
104
105 /**
106  * @brief Return description of filter.
107  *
108  * @param [in] i Index of filter.
109  * @return Description of filter in given index.
110  */
111 inline String FileFilterMgr::GetFilterDesc(int i) const
112 {
113         return m_filters[i]->description; 
114 }
115
116 /**
117  * @brief Return description of filter.
118  * @param [in] pFilter Filter to get description for.
119  * @return Given filter's description.
120  */
121 inline String FileFilterMgr::GetFilterDesc(const FileFilter *pFilter) const
122 {
123         return pFilter->description;
124 }
125
126 /**
127  * @brief Return full path to filter.
128  *
129  * @param [in] i Index of filter.
130  * @return Full path of filter in given index.
131  */
132 inline String FileFilterMgr::GetFilterPath(int i) const
133 {
134         return m_filters[i]->fullpath;
135 }
136
137 /**
138  * @brief Return full path to filter.
139  *
140  * @param [in] pFilter Pointer to filter.
141  * @return Full path of filter.
142  */
143 inline String FileFilterMgr::GetFullpath(FileFilter * pfilter) const
144 {
145         return pfilter->fullpath;
146 }