-/////////////////////////////////////////////////////////////////////////////
-// License (GPLv2+):
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-/////////////////////////////////////////////////////////////////////////////
+// SPDX-License-Identifier: GPL-2.0-or-later
/**
* @file FileFilterHelper.h
*
* @brief Declaration file for FileFilterHelper
*/
-// ID line follows -- this is updated by SVN
-// $Id$
-
-#ifndef _FILEFILTERHELPER_H_
-#define _FILEFILTERHELPER_H_
+#pragma once
#include <vector>
+#include <memory>
#include "UnicodeString.h"
+#include "DirItem.h"
class FileFilterMgr;
class FilterList;
/**
* @brief File extension of file filter files.
*/
-const TCHAR FileFilterExt[] = L".flt";
+const TCHAR FileFilterExt[] = _T(".flt");
/**
* @brief Helper structure for UI and management of filters.
class IDiffFilter
{
public:
- virtual BOOL includeFile(LPCTSTR szFileName) = 0;
- virtual BOOL includeDir(LPCTSTR szDirName) = 0;
- BOOL includeFile(LPCTSTR szFileName1, LPCTSTR szFileName2)
+ virtual bool includeFile(const String& szFileName) const = 0;
+ virtual bool includeDir(const String& szDirName) const = 0;
+ bool includeFile(const String& szFileName1, const String& szFileName2) const
+ {
+ if (!szFileName1.empty())
+ return includeFile(szFileName1);
+ else if (!szFileName2.empty())
+ return includeFile(szFileName2);
+ else
+ return false;
+ }
+ bool includeFile(const String& szFileName1, const String& szFileName2, const String& szFileName3) const
{
- return
- (
- (szFileName1[0] == '\0' || includeFile(szFileName1))
- && (szFileName2[0] == '\0' || includeFile(szFileName2))
- );
+ if (!szFileName1.empty())
+ return includeFile(szFileName1);
+ else if (!szFileName2.empty())
+ return includeFile(szFileName2);
+ else if (!szFileName3.empty())
+ return includeFile(szFileName3);
+ else
+ return false;
}
- BOOL includeDir(LPCTSTR szDirName1, LPCTSTR szDirName2)
+ bool includeDir(const String& szDirName1, const String& szDirName2) const
{
- return
- (
- (szDirName1[0] == '\0' || includeDir(szDirName1))
- && (szDirName2[0] == '\0' || includeDir(szDirName2))
- );
+ if (!szDirName1.empty())
+ return includeDir(szDirName1);
+ else if (!szDirName2.empty())
+ return includeDir(szDirName2);
+ else
+ return false;
+ }
+ bool includeDir(const String& szDirName1, const String& szDirName2, const String& szDirName3) const
+ {
+ if (!szDirName1.empty())
+ return includeDir(szDirName1);
+ else if (!szDirName2.empty())
+ return includeDir(szDirName2);
+ else if (!szDirName3.empty())
+ return includeDir(szDirName3);
+ else
+ return false;
}
};
String GetUserFilterPathWithCreate() const;
FileFilterMgr * GetManager() const;
- void SetFileFilterPath(LPCTSTR szFileFilterPath);
- void GetFileFilters(std::vector<FileFilterInfo> * filters, String & selected) const;
- String GetFileFilterName(LPCTSTR filterPath) const;
- String GetFileFilterPath(LPCTSTR filterName) const;
+ void SetFileFilterPath(const String& szFileFilterPath);
+ std::vector<FileFilterInfo> GetFileFilters(String & selected) const;
+ String GetFileFilterName(const String& filterPath) const;
+ String GetFileFilterPath(const String& filterName) const;
void SetUserFilterPath(const String & filterPath);
void ReloadUpdatedFilters();
void LoadAllFileFilters();
- void LoadFileFilterDirPattern(LPCTSTR szPattern);
+ void LoadFileFilterDirPattern(const String& dir, const String& szPattern);
- void UseMask(BOOL bUseMask);
- void SetMask(LPCTSTR strMask);
+ void UseMask(bool bUseMask);
+ void SetMask(const String& strMask);
- BOOL IsUsingMask() const;
+ bool IsUsingMask() const;
String GetFilterNameOrMask() const;
- BOOL SetFilter(const String &filter);
+ bool SetFilter(const String &filter);
- BOOL includeFile(LPCTSTR szFileName);
- BOOL includeDir(LPCTSTR szDirName);
+ bool includeFile(const String& szFileName) const override;
+ bool includeDir(const String& szDirName) const override;
protected:
String ParseExtensions(const String &extensions) const;
private:
- FilterList * m_pMaskFilter; /*< Filter for filemasks (*.cpp) */
+ std::unique_ptr<FilterList> m_pMaskFilter; /*< Filter for filemasks (*.cpp) */
FileFilter * m_currentFilter; /*< Currently selected filefilter */
- FileFilterMgr * m_fileFilterMgr; /*< Associated FileFilterMgr */
+ std::unique_ptr<FileFilterMgr> m_fileFilterMgr; /*< Associated FileFilterMgr */
String m_sFileFilterPath; /*< Path to current filter */
String m_sMask; /*< File mask (if defined) "*.cpp *.h" etc */
- BOOL m_bUseMask; /*< If TRUE file mask is used, filter otherwise */
+ bool m_bUseMask; /*< If `true` file mask is used, filter otherwise */
String m_sGlobalFilterPath; /*< Path for shared filters */
String m_sUserSelFilterPath; /*< Path for user's private filters */
};
-#endif // _FILEFILTERHELPER_H_
+/**
+ * @brief Return filtermanager used.
+ */
+inline FileFilterMgr * FileFilterHelper::GetManager() const
+{
+ return m_fileFilterMgr.get();
+}
+
+/**
+ * @brief Returns true if active filter is a mask.
+ */
+inline bool FileFilterHelper::IsUsingMask() const
+{
+ return m_bUseMask;
+}
+