OSDN Git Service

Merge pull request #5 from WinMerge/master
[winmerge-jp/winmerge-jp.git] / Src / ProjectFile.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** 
3  * @file  ProjectFile.h
4  *
5  * @brief Declaration file ProjectFile class
6  */
7 #pragma once
8
9 #include "UnicodeString.h"
10 #include "PathContext.h"
11
12 class ProjectFileItem
13 {
14         friend class ProjectFile;
15         friend class ProjectFileHandler;
16 public:
17         ProjectFileItem();
18         bool HasLeft() const;
19         bool HasMiddle() const;
20         bool HasRight() const;
21         bool HasFilter() const;
22         bool HasSubfolders() const;
23
24         String GetLeft(bool * pReadOnly = nullptr) const;
25         bool GetLeftReadOnly() const;
26         String GetMiddle(bool * pReadOnly = nullptr) const;
27         bool GetMiddleReadOnly() const;
28         String GetRight(bool * pReadOnly = nullptr) const;
29         bool GetRightReadOnly() const;
30         String GetFilter() const;
31         int GetSubfolders() const;
32
33         void SetLeft(const String& sLeft, const bool * pReadOnly = nullptr);
34         void SetMiddle(const String& sMiddle, const bool * pReadOnly = nullptr);
35         void SetRight(const String& sRight, const bool * pReadOnly = nullptr);
36         void SetFilter(const String& sFilter);
37         void SetSubfolders(bool bSubfolder);
38
39         void GetPaths(PathContext& files, bool & bSubFolders) const;
40         void SetPaths(const PathContext& files, bool bSubFolders = false);
41
42 private:
43         PathContext m_paths;
44         bool m_bHasLeft; /**< Has left path? */
45         bool m_bHasMiddle; /**< Has middle path? */
46         bool m_bHasRight; /**< Has right path? */
47         bool m_bHasFilter; /**< Has filter? */
48         String m_filter; /**< Filter name or mask */
49         bool m_bHasSubfolders; /**< Has subfolders? */
50         int m_subfolders; /**< Are subfolders included (recursive scan) */
51         bool m_bLeftReadOnly; /**< Is left path opened as read-only */
52         bool m_bMiddleReadOnly; /**< Is middle path opened as read-only */
53         bool m_bRightReadOnly; /**< Is right path opened as read-only */
54 };
55
56 /**
57  * @brief Class for handling project files.
58  *
59  * This class loads and saves project files. Expat parser and SCEW wrapper for
60  * expat are used for XML parsing. We use UTF-8 encoding so Unicode paths are
61  * supported.
62  */
63 class ProjectFile
64 {
65 public:
66         bool Read(const String& path);
67         bool Save(const String& path) const;
68         const std::list<ProjectFileItem>& Items() const { return m_items; };
69         std::list<ProjectFileItem>& Items() { return m_items; }
70         static const String PROJECTFILE_EXT;
71 private:
72         std::list<ProjectFileItem> m_items;
73 };
74
75 /** 
76  * @brief Returns if left path is defined in project file.
77  * @return true if project file has left path.
78  */
79 inline bool ProjectFileItem::HasLeft() const
80 {
81         return m_bHasLeft;
82 }
83
84 /** 
85  * @brief Returns if middle path is defined.
86  */
87 inline bool ProjectFileItem::HasMiddle() const
88 {
89         return m_bHasMiddle;
90 }
91
92 /** 
93  * @brief Returns if right path is defined in project file.
94  * @return true if project file has right path.
95  */
96 inline bool ProjectFileItem::HasRight() const
97 {
98         return m_bHasRight;
99 }
100
101 /** 
102  * @brief Returns if filter is defined in project file.
103  * @return true if project file has filter.
104  */
105 inline bool ProjectFileItem::HasFilter() const
106 {
107         return m_bHasFilter;
108 }
109
110 /** 
111  * @brief Returns if subfolder is defined in projectfile.
112  * @return true if project file has subfolder definition.
113  */
114 inline bool ProjectFileItem::HasSubfolders() const
115 {
116         return m_bHasSubfolders;
117 }
118
119 /** 
120  * @brief Returns if left path is specified read-only.
121  * @return true if left path is read-only, false otherwise.
122  */
123 inline bool ProjectFileItem::GetLeftReadOnly() const
124 {
125         return m_bLeftReadOnly;
126 }
127
128 /** 
129  * @brief Returns if middle path is specified read-only.
130  */
131 inline bool ProjectFileItem::GetMiddleReadOnly() const
132 {
133         return m_bMiddleReadOnly;
134 }
135
136 /** 
137  * @brief Returns if right path is specified read-only.
138  * @return true if right path is read-only, false otherwise.
139  */
140 inline bool ProjectFileItem::GetRightReadOnly() const
141 {
142         return m_bRightReadOnly;
143 }
144
145 /** 
146  * @brief Returns filter.
147  * @return Filter string.
148  */
149 inline String ProjectFileItem::GetFilter() const
150 {
151         return m_filter;
152 }
153
154 /** 
155  * @brief Set filter.
156  * @param [in] sFilter New filter string to set.
157  */
158 inline void ProjectFileItem::SetFilter(const String& sFilter)
159 {
160         m_filter = sFilter;
161 }
162
163 /** 
164  * @brief Returns subfolder included -setting.
165  * @return != 0 if subfolders are included.
166  */
167 inline int ProjectFileItem::GetSubfolders() const
168 {
169         return m_subfolders;
170 }
171
172 /** 
173  * @brief set subfolder.
174  * @param [in] iSubfolder New value for subfolder inclusion.
175  */
176 inline void ProjectFileItem::SetSubfolders(bool bSubfolder)
177 {
178         m_subfolders = bSubfolder ? 1 : 0;
179 }
180
181 /** 
182  * @brief 
183  *
184  * @param [in] paths Files in project
185  * @param [in] bSubFolders If true subfolders included (recursive compare)
186  */
187 inline void ProjectFileItem::SetPaths(const PathContext& paths, bool bSubfolders)
188 {
189         m_paths = paths;
190         m_subfolders = bSubfolders;
191 }
192