-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmodel.hpp
More file actions
74 lines (66 loc) · 1.91 KB
/
dmodel.hpp
File metadata and controls
74 lines (66 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include <map>
#include "tags.hpp"
/// file descriptions database
class DescrDb {
public:
static const wchar_t DIZ_FILENAME[];
static const std::wstring extractFileName(const std::wstring &path) {
size_t iSeparator = path.find_last_of(L'\\');
if (iSeparator != std::wstring::npos)
return path.substr(iSeparator+1);
return path;
}
void clear() {
m_tags.clear();
m_items.clear();
m_bLoadedUtf8 = true;
}
/// get all tags
const Tags &getTags() const {
return m_tags;
}
/// get tags of a file
const Tags &getTagsByName(const std::wstring &item) {
return m_items[item].tags;
}
/// get file description
const std::wstring &getDizByName(const std::wstring &item) {
return m_items[item].text;
}
/// get text for file description column
std::wstring getColumnTextByName(const std::wstring &item);
/// sync m_tags with modified m_items
void refreshTags();
/// read descript.ion
void load(const std::wstring &filename);
/// write descript.ion
bool save(const std::wstring &filename) const;
/// add a new entry; refreshTags() must be called after adding/deleting entries
void insert(const std::wstring &filename, const Tags &fileTags);
/// delete an entry; refreshTags() must be called after adding/deleting entries
void erase(const std::wstring &filename);
/// apply changes in tags
void modify(const std::set<std::wstring> &selectedFiles,
bool bModifyText, const std::wstring &text,
const Tags &tagsToSet, const Tags &tagsToClear);
void modify(const std::set<std::wstring> &selectedFiles,
bool bModifyText, const std::wstring &text,
const Tags &newTags);
void removeTags(const std::set<std::wstring> &selectedFiles,
const Tags &tags);
private:
struct ItemData {
std::wstring text;
Tags tags;
void clear() {
text.clear();
tags.clear();
}
bool empty() const;
};
typedef std::map<std::wstring, ItemData> Items;
Tags m_tags;
Items m_items;
bool m_bLoadedUtf8;
};