-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCFolder.cpp
180 lines (150 loc) · 3.65 KB
/
CFolder.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "CFolder.h"
#include "CFiles.h"
#include <boost/filesystem.hpp>
#include <functional>
#include "CApplication.h"
CFolder::CFolder():CIcon("images/folder.png", 3)
{
mForm = NULL;
mName = "";
mPath = "";
mFilter = "*";
}
CFolder::CFolder(std::string path, int numFrames): CIcon(path, numFrames)
{
mForm = NULL;
mName = "";
mPath = "";
mFilter = "*";
}
void CFolder::ReadFolder(std::string path, std::string ext)
{
CFiles files;
files.GetFiles(path, ext);
for (int i = 0; i < files.mFiles.size(); i++)
{
AddFile(files.mFiles[i]);
}
}
void CFolder::AddFile(std::string filename)
{
mFiles.push_back(CFile(filename, "", CFile::Type::NONE));
}
void CFolder::AddFile(std::string filename, std::string size)
{
mFiles.push_back(CFile(filename, size, CFile::Type::NONE));
}
void CFolder::AddFile(std::string filename, std::string size, CFile::Type type)
{
mFiles.push_back(CFile(filename, size, type));
}
void CFolder::AddFiles(std::vector<CFile> files)
{
ClearFiles();
for (int i = 0; i < files.size(); i++)
{
mFiles.push_back(files[i]);
}
}
void CFolder::ClearFiles()
{
mFiles.clear();
}
void CFolder::CreateFileList(bool draggable)
{
CListBoxItem* lbi;
using namespace std::placeholders;
if (mForm == NULL)
{
return;
}
mForm->ClearList();
for (int i = 0; i < mFiles.size(); i++)
{
if (mFiles[i].mType == CFile::Type::CORE)
{
lbi = mForm->AddItem(mFiles[i].mName, mFiles[i].mSize, CText::cRed, mFiles[i].mType);
}
else
{
lbi = mForm->AddItem(mFiles[i].mName, mFiles[i].mSize, CText::cBlack, mFiles[i].mType);
}
lbi->AddDoubleClickHandler(std::bind(&CFolderForm::OnListItemDoubleClick, mForm, _1));
lbi->mDraggable = draggable;
lbi->mTag = mFiles[i].mTag;
}
mForm->SizeToListbox();
}
void CFolder::AddItemDoubleClickedHandler(std::function<void(CFolderForm*, CListBoxItem*)> callback)
{
if (mForm == NULL)
{
return;
}
mForm->AddItemDoubleClickedHandler(callback);
}
CFolderForm* CFolder::CreateForm(int x, int y, int w, int h)
{
using namespace std::placeholders;
mForm = new CFolderForm(x, y, w, h);
mForm->AddItemRemovedHandler(std::bind(&CFolder::OnFolderItemRemoved, this, _1, _2));
mForm->AddFileCopiedHandler(std::bind(&CFolder::OnFolderReceiveCopy, this, _1));
return(mForm);
}
//void CFolder::OnFolderReceiveCopy(std::string fromFolderPath, std::string fromFileName)
//{
// std::string from = fromFolderPath + "/" + fromFileName;
// std::string to = this->mPath + "/" + fromFileName;
// printf("Copy %s to %s\n", from, to);
//
// CFiles::Copy(from, to);
//}
void CFolder::OnFolderReceiveCopy(std::string from)
{
bool b;
boost::filesystem::path p(from);
std::string to;
to = mPath + "/" + p.filename().string();
b = CFiles::Copy(from, to);
if (b == true)
{
if (mForm != NULL)
{
CFiles files;
std::vector<CFile> fileObjects;
files.GetFiles(mPath, mFilter);
for (int i = 0; i < files.mFiles.size(); i++)
{
CFile::Type type = CFile::MapType(mFilter);
fileObjects.push_back(CFile(files.mFiles[i], " ", type));
}
AddFiles(fileObjects);
CreateFileList(true);
}
}
}
void CFolder::OnFolderItemRemoved(CForm* form, CListBoxItem* item)
{
CFolderForm* folderForm = dynamic_cast<CFolderForm*>(form);
if (folderForm)
{
if (folderForm->mFolderPath != "NONE" && folderForm->mFolderPath != "")
{
if (strstr(folderForm->mFolderPath.c_str(), "bmos/") != NULL)
{
std::string fpath = folderForm->mFolderPath + "/" + item->mColumn1;
//printf("Delete %s\n", fpath.c_str());
CFiles::Delete(fpath);
}
}
}
for (auto it = std::begin(mFiles); it != std::end(mFiles); ++it)
{
CFile file = (*it);
if (file.mName == item->mColumn1)
{
mFiles.erase(it);
break;
}
}
}