NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
DirTraverser.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2017 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20
21#include "DirTraverser.hpp"
22
23
34DirTraverser::DirTraverser(wxTreeCtrl* therootNode, IconManager* theiconmanager, wxTreeItemId theid, const wxString& thepath, FileFilterType thefilespec)
35{
36 rootNode = therootNode;
37 iconManager = theiconmanager;
38 id = theid;
39 path = thepath;
40 fileSpec = thefilespec;
41 vcurrentnodes.push_back(id);
42 ncurrentdepth = 0;
43
44 // Calculate the current folder depth
45 for (size_t i = 0; i < path.length(); i++)
46 {
47 if (path[i] == '\\' || path[i] == '/')
49 }
50}
51
52
63wxDirTraverseResult DirTraverser::OnFile(const wxString& filename)
64{
65 if (filename.find('.') == std::string::npos || filename.find(".revisions") != std::string::npos)
66 return wxDIR_CONTINUE;
67
68 wxString filespec;
69 wxString extension = filename.substr(filename.rfind('.')+1).Lower();
70
71 // Determine, whether the current file matches to the
72 // selected file filter types
73 switch (fileSpec)
74 {
75 case FILE_NSCR:
76 if (filename.length() < 6 || (extension != "nscr" && extension != "nlyt" && extension != "npkp" && extension != "nhlp"))
77 return wxDIR_CONTINUE;
78
79 break;
80 case FILE_NPRC:
81 if (filename.length() < 6 || (extension != "nprc" && extension != "nlyt" && extension != "npkp" && extension != "nhlp"))
82 return wxDIR_CONTINUE;
83
84 break;
85 case FILE_NUMERE:
86 if (filename.length() < 6)
87 return wxDIR_CONTINUE;
88
89 filespec = "*.nscr;*.nprc;*.nlyt;*.ndat;*.npkp;*.nhlp;";
90
91 if (filespec.find("*."+extension+";") == std::string::npos)
92 return wxDIR_CONTINUE;
93
94 break;
95 case FILE_DATAFILES:
96 if (filename.length() < 4)
97 return wxDIR_CONTINUE;
98
99 filespec = "*.ndat;*.dat;*.xls;*.xlsx;*.ods;*.csv;*.txt;*.labx;*.ibw;*.jdx;*.jcm;*.dx;*.png;*.log;*.tex;*.pdf;*.m;*.cpp;*.cxx;*.c;*.hpp;*.hxx;*.h;*.xml;*.wav;*.diff;";
100
101 if (filespec.find("*."+extension + ";") == std::string::npos)
102 return wxDIR_CONTINUE;
103
104 break;
105 case FILE_IMAGEFILES:
106 if (filename.length() < 5)
107 return wxDIR_CONTINUE;
108
109 filespec = "*.png;*.jpg;*.jpeg;*.eps;*.svg;*.gif;*.bmp;*.tif;*.tiff;";
110
111 if (filespec.find("*."+extension+";") == std::string::npos)
112 return wxDIR_CONTINUE;
113
114 break;
115 default:
116 filespec = "*.*";
117 }
118
119 unsigned int ndepth = 0;
120
121 for (size_t i = 0; i < filename.length(); i++)
122 {
123 if (filename[i] == '/' || filename[i] == '\\')
124 ndepth++;
125 }
126
127 while (ndepth-1 < ncurrentdepth)
128 {
129 vcurrentnodes.pop_back();
131 }
132
134 data->filename = filename;
135
136 rootNode->AppendItem(vcurrentnodes.back(), filename.substr(filename.rfind('\\')+1), iconManager->GetIconIndex(extension),-1, data);
137 return wxDIR_CONTINUE;
138}
139
140
150wxDirTraverseResult DirTraverser::OnDir(const wxString& dirname)
151{
152 if (dirname.find(".revisions") != std::string::npos)
153 return wxDIR_IGNORE;
154
155 unsigned int ndepth = 0;
156
157 for (size_t i = 0; i < dirname.length(); i++)
158 {
159 if (dirname[i] == '/' || dirname[i] == '\\')
160 ndepth++;
161 }
162
163 while (ndepth < ncurrentdepth)
164 {
165 vcurrentnodes.pop_back();
167 }
168
169 if (ndepth == ncurrentdepth)
170 vcurrentnodes.pop_back();
171
172 if (ndepth > ncurrentdepth)
173 ncurrentdepth = ndepth;
174
176 data->filename = dirname;
177 data->isDir = true;
178 vcurrentnodes.push_back(rootNode->AppendItem(vcurrentnodes.back(), dirname.substr(dirname.rfind('\\')+1), iconManager->GetIconIndex("FOLDEROPEN"), -1, data));
179
180 return wxDIR_CONTINUE;
181}
182
183
184
wxTreeCtrl * rootNode
IconManager * iconManager
DirTraverser(wxTreeCtrl *therootNode, IconManager *theiconmanager, wxTreeItemId theid, const wxString &thepath, FileFilterType thefilespec)
Constuctor.
virtual wxDirTraverseResult OnDir(const wxString &dirname)
This method appends the folders found during traversing the directory to the file tree.
wxString path
unsigned int ncurrentdepth
std::vector< wxTreeItemId > vcurrentnodes
FileFilterType fileSpec
virtual wxDirTraverseResult OnFile(const wxString &filename)
This method classifies the files found during traversing the directory and appends them to the tree,...
This class provides the needed functionalities for the file tree and the symbols tree.
Definition: treedata.hpp:42
wxString filename
Definition: treedata.hpp:50
int GetIconIndex(wxString iconInfo)
FileFilterType
@ FILE_DATAFILES
@ FILE_NPRC
@ FILE_NSCR
@ FILE_NUMERE
@ FILE_IMAGEFILES