OSDN Git Service

Update Dutch.po (#842)
[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         String GetFullpath(FileFilter * pfilter) const;
60
61         // methods to actually use filter
62         bool TestFileNameAgainstFilter(const FileFilter * pFilter, const String& szFileName) const;
63         bool TestDirNameAgainstFilter(const FileFilter * pFilter, const String& szDirName) const;
64
65         void DeleteAllFilters();
66
67 // Implementation methods
68 protected:
69         // Clear the list of known filters
70         // Load a filter from a file (if syntax is valid)
71         FileFilter * LoadFilterFile(const String& szFilepath, int & errorcode);
72
73 // Implementation data
74 private:
75         std::vector<FileFilterPtr> m_filters; /*< List of filters loaded */
76 };
77
78
79 bool TestAgainstRegList(const std::vector<FileFilterElementPtr> *filterList, const String& szTest);
80 void EmptyFilterList(std::vector<FileFilterElementPtr> *filterList);
81
82 /**
83  * @brief Return name of filter.
84  *
85  * @param [in] i Index of filter.
86  * @return Name of filter in given index.
87  */
88 inline String FileFilterMgr::GetFilterName(int i) const
89 {
90         return m_filters[i]->name; 
91 }
92
93 /**
94  * @brief Return name of filter.
95  * @param [in] pFilter Filter to get name for.
96  * @return Given filter's name.
97  */
98 inline String FileFilterMgr::GetFilterName(const FileFilter *pFilter) const
99 {
100         return pFilter->name; 
101 }
102
103 /**
104  * @brief Return description of filter.
105  *
106  * @param [in] i Index of filter.
107  * @return Description of filter in given index.
108  */
109 inline String FileFilterMgr::GetFilterDesc(int i) const
110 {
111         return m_filters[i]->description; 
112 }
113
114 /**
115  * @brief Return description of filter.
116  * @param [in] pFilter Filter to get description for.
117  * @return Given filter's description.
118  */
119 inline String FileFilterMgr::GetFilterDesc(const FileFilter *pFilter) const
120 {
121         return pFilter->description;
122 }
123
124 /**
125  * @brief Return full path to filter.
126  *
127  * @param [in] i Index of filter.
128  * @return Full path of filter in given index.
129  */
130 inline String FileFilterMgr::GetFilterPath(int i) const
131 {
132         return m_filters[i]->fullpath;
133 }
134
135 /**
136  * @brief Return full path to filter.
137  *
138  * @param [in] pFilter Pointer to filter.
139  * @return Full path of filter.
140  */
141 inline String FileFilterMgr::GetFullpath(FileFilter * pfilter) const
142 {
143         return pfilter->fullpath;
144 }