38#include <wx/xml/xml.h>
44#include <wx/filename.h>
45#include <wx/hashmap.h>
46#include "Configuration.h"
49#include <unordered_map>
61 typedef std::unordered_map <wxString, int, wxStringHash> WorksheetWords;
63 using WordList = std::vector<wxString>;
114 void AddWorksheetWords(WordList::const_iterator begin, WordList::const_iterator end);
136 void LoadableFiles_BackgroundTask(wxString sharedir, wxString demodir);
138 void BuiltinSymbols_BackgroundTask();
141 void UpdateLoadFiles_BackgroundTask(wxString partial, wxString maximaDir);
143 std::vector<wxString> m_builtInLoadFiles;
145 std::vector<wxString> m_builtInDemoFiles;
147 class GetGeneralFiles :
public wxDirTraverser
150 explicit GetGeneralFiles(std::vector<wxString>& files,
152 const wxString &prefix = wxEmptyString) :
153 m_files(files), m_lock(lock), m_prefix(prefix) {
154 for(
const auto &i : m_files)
157 wxDirTraverseResult OnFile(
const wxString& filename)
override
159 wxFileName newItemName(filename);
160 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"\"";
161 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
163 const std::lock_guard<std::mutex> lock(*m_lock);
164 if (m_filesHash.find(newItem) == m_filesHash.end())
166 m_files.push_back(newItem);
167 m_filesHash[newItem];
170 return wxDIR_CONTINUE;
172 wxDirTraverseResult OnDir(
const wxString& dirname)
override
174 wxFileName newItemName(dirname);
175 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
176 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
178 const std::lock_guard<std::mutex> lock(*m_lock);
179 if (m_filesHash.find(newItem) == m_filesHash.end())
181 m_files.push_back(newItem);
182 m_filesHash[newItem];
187 std::vector<wxString> GetResult(){
188 const std::lock_guard<std::mutex> lock(*m_lock);
193 std::vector<wxString>& m_files;
195 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
201 class GetMacFiles_includingSubdirs :
public wxDirTraverser
204 explicit GetMacFiles_includingSubdirs(std::vector<wxString>& files,
206 const wxString &prefix = wxEmptyString) :
207 m_files(files), m_lock(lock), m_prefix(prefix)
209 for(
const auto &i : m_files)
212 wxDirTraverseResult OnFile(
const wxString& filename)
override
215 (filename.EndsWith(
".mac"))||
216 (filename.EndsWith(
".lisp"))||
217 (filename.EndsWith(
".wxm"))
220 wxFileName newItemName(filename);
221 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
222 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
224 const std::lock_guard<std::mutex> lock(*m_lock);
225 if (m_filesHash.find(newItem) == m_filesHash.end())
227 m_files.push_back(newItem);
228 m_filesHash[newItem];
232 return wxDIR_CONTINUE;
234 wxDirTraverseResult OnDir(
const wxString& dirname)
override
236 if((dirname.EndsWith(
".git")) ||
237 (dirname.EndsWith(
"/share/share")) ||
238 (dirname.EndsWith(
"/src/src")) ||
239 (dirname.EndsWith(
"/doc/doc")) ||
240 (dirname.EndsWith(
"/interfaces/interfaces"))
244 return wxDIR_CONTINUE;
246 std::vector<wxString> GetResult(){
247 const std::lock_guard<std::mutex> lock(*m_lock);
252 std::vector<wxString>& m_files;
254 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
260 class GetMacFiles :
public GetMacFiles_includingSubdirs
263 explicit GetMacFiles(std::vector<wxString>& files,
265 const wxString &prefix = wxEmptyString) :
266 GetMacFiles_includingSubdirs(files, lock, prefix){ }
267 wxDirTraverseResult OnDir(
const wxString& dirname)
override
269 wxFileName newItemName(dirname);
270 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
271 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
273 const std::lock_guard<std::mutex> lock(*m_lock);
274 if (m_filesHash.find(newItem) == m_filesHash.end())
276 m_files.push_back(newItem);
277 m_filesHash[newItem];
285 class GetDemoFiles_includingSubdirs :
public wxDirTraverser
288 explicit GetDemoFiles_includingSubdirs(std::vector<wxString>& files,
290 const wxString &prefix = wxEmptyString) :
291 m_files(files), m_lock(lock), m_prefix(prefix)
293 for(
const auto &i : m_files)
296 wxDirTraverseResult OnFile(
const wxString& filename)
override
298 if(filename.EndsWith(
".dem"))
300 wxFileName newItemName(filename);
301 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
302 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
304 const std::lock_guard<std::mutex> lock(*m_lock);
305 if (m_filesHash.find(newItem) == m_filesHash.end())
307 m_files.push_back(newItem);
308 m_filesHash[newItem];
312 return wxDIR_CONTINUE;
314 wxDirTraverseResult OnDir(
const wxString& dirname)
override
316 if((dirname.EndsWith(
".git")) ||
317 (dirname.EndsWith(
"/share/share")) ||
318 (dirname.EndsWith(
"/src/src")) ||
319 (dirname.EndsWith(
"/doc/doc")) ||
320 (dirname.EndsWith(
"/interfaces/interfaces"))
324 return wxDIR_CONTINUE;
326 std::vector<wxString> GetResult(){
327 const std::lock_guard<std::mutex> lock(*m_lock);
332 std::vector<wxString>& m_files;
334 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
340 class GetDemoFiles :
public GetDemoFiles_includingSubdirs
343 explicit GetDemoFiles(std::vector<wxString>& files,
345 const wxString &prefix = wxEmptyString) :
346 GetDemoFiles_includingSubdirs(files, lock, prefix){ }
347 virtual wxDirTraverseResult OnDir(
const wxString& dirname)
override
349 wxFileName newItemName(dirname);
350 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
351 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
353 const std::lock_guard<std::mutex> lock(*m_lock);
354 if (m_filesHash.find(newItem) == m_filesHash.end())
356 m_files.push_back(newItem);
357 m_filesHash[newItem];
364 jthread m_addSymbols_backgroundThread;
365 jthread m_addFiles_backgroundThread;
367 std::mutex m_keywordsLock;
369 std::vector<std::vector<wxString>> m_wordList;
370 static wxRegEx m_args;
371 WorksheetWords m_worksheetWords;
374wxDECLARE_EVENT(NEW_DEMO_FILES_EVENT, wxCommandEvent);
Definition: Autocomplete.h:60
std::vector< wxString > GetSymbolList()
Returns a list of Symbols we know.
Definition: Autocomplete.cpp:62
void AddSymbols_Backgroundtask(wxXmlDocument xmldoc)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:142
virtual ~AutoComplete()
The destructor of AutoComplete.
Definition: Autocomplete.cpp:218
void ClearDemofileList()
Clear the list of files demo() can be applied on.
Definition: Autocomplete.cpp:103
std::vector< wxString > GetDemoFilesList()
Returns a list of demo files we know of.
Definition: Autocomplete.cpp:57
void UpdateDemoFiles(wxString partial, const wxString &maximaDir)
Replace the list of files in the directory the worksheet file is in to the demo files list.
Definition: Autocomplete.cpp:387
void LoadSymbols()
Load all autocomplete symbols wxMaxima knows about by itself.
Definition: Autocomplete.cpp:225
autoCompletionType
All types of things we can autocomplete.
Definition: Autocomplete.h:67
@ tmplte
Command names.
Definition: Autocomplete.h:69
@ generalfile
loadable files
Definition: Autocomplete.h:72
@ demofile
loadable files
Definition: Autocomplete.h:71
@ numberOfTypes
Unit names.
Definition: Autocomplete.h:75
@ unit
Esc commands describing symbols.
Definition: Autocomplete.h:74
@ loadfile
Function templates.
Definition: Autocomplete.h:70
@ esccommand
general files
Definition: Autocomplete.h:73
std::vector< wxString > CompleteSymbol(wxString partial, autoCompletionType type=command)
Returns a list of possible autocompletions for the string "partial".
Definition: Autocomplete.cpp:498
void UpdateLoadFiles(wxString partial, const wxString &maximaDir)
Replace the list of files in the directory the worksheet file is in to the load files list.
Definition: Autocomplete.cpp:456
void LoadBuiltinSymbols()
Makes wxMaxima know all its builtin symbols.
Definition: Autocomplete.cpp:68
void UpdateGeneralFiles(wxString partial, const wxString &maximaDir)
Assemble a list of files.
Definition: Autocomplete.cpp:423
void AddSymbols(wxString xml)
Interprets the XML autocompletable symbol list maxima can send us.
Definition: Autocomplete.cpp:108
void AddWorksheetWords(const WordList &words)
Add words to the list of words that appear in the workSheet's code cells.
Definition: Autocomplete.cpp:214
void AddSymbols_Backgroundtask_string(wxString xml)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:135
static wxString FixTemplate(wxString templ)
Basically runs a regex over templates.
Definition: Autocomplete.cpp:609
bool HasDemofile(const wxString &commandname)
Does a demo file for this command exist?
Definition: Autocomplete.cpp:93
void AddSymbol(wxString fun, autoCompletionType type=command)
Manually add an autocompletable symbol to our symbols lists.
Definition: Autocomplete.cpp:553
void ClearWorksheetWords()
Clear the list of words that appear in the workSheet's code cells.
Definition: Autocomplete.cpp:52
The configuration storage for the current worksheet.
Definition: Configuration.h:84