39#include <wx/xml/xml.h>
45#include <wx/filename.h>
46#include <wx/hashmap.h>
47#include "Configuration.h"
50#include <unordered_map>
62 typedef std::unordered_map <wxString, int, wxStringHash> WorksheetWords;
64 using WordList = std::vector<wxString>;
127 const wxString &maximaDir);
131 void AddWorksheetWords(WordList::const_iterator begin, WordList::const_iterator end);
153 void LoadableFiles_BackgroundTask(
stop_token stopToken, wxString sharedir, wxString demodir);
155 void BuiltinSymbols_BackgroundTask(
stop_token stopToken);
158 void UpdateLoadFiles_BackgroundTask(
stop_token stopToken, wxString partial, wxString maximaDir);
160 std::vector<wxString> m_builtInLoadFiles;
162 std::vector<wxString> m_builtInDemoFiles;
164 class GetGeneralFiles :
public wxDirTraverser
167 explicit GetGeneralFiles(std::vector<wxString>& files,
170 const wxString &prefix = wxEmptyString) :
171 m_files(files), m_lock(lock), m_stopToken(stopToken), m_prefix(prefix) {
172 for(
const auto &i : m_files)
175 wxDirTraverseResult OnFile(
const wxString& filename)
override
177 if (m_stopToken.stop_requested())
return wxDIR_STOP;
178 wxFileName newItemName(filename);
179 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"\"";
180 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
182 const std::lock_guard<std::mutex> lock(*m_lock);
183 if (m_filesHash.find(newItem) == m_filesHash.end())
185 m_files.push_back(newItem);
186 m_filesHash[newItem];
189 return wxDIR_CONTINUE;
191 wxDirTraverseResult OnDir(
const wxString& dirname)
override
193 if (m_stopToken.stop_requested())
return wxDIR_STOP;
194 wxFileName newItemName(dirname);
195 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
196 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
198 const std::lock_guard<std::mutex> lock(*m_lock);
199 if (m_filesHash.find(newItem) == m_filesHash.end())
201 m_files.push_back(newItem);
202 m_filesHash[newItem];
207 std::vector<wxString> GetResult(){
208 const std::lock_guard<std::mutex> lock(*m_lock);
213 std::vector<wxString>& m_files;
215 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
222 class GetMacFiles_includingSubdirs :
public wxDirTraverser
225 explicit GetMacFiles_includingSubdirs(std::vector<wxString>& files,
228 const wxString &prefix = wxEmptyString) :
229 m_files(files), m_lock(lock), m_stopToken(stopToken), m_prefix(prefix)
231 for(
const auto &i : m_files)
234 wxDirTraverseResult OnFile(
const wxString& filename)
override
236 if (m_stopToken.stop_requested())
return wxDIR_STOP;
238 (filename.EndsWith(
".mac"))||
239 (filename.EndsWith(
".lisp"))||
240 (filename.EndsWith(
".wxm"))
243 wxFileName newItemName(filename);
244 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
245 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
247 const std::lock_guard<std::mutex> lock(*m_lock);
248 if (m_filesHash.find(newItem) == m_filesHash.end())
250 m_files.push_back(newItem);
251 m_filesHash[newItem];
255 return wxDIR_CONTINUE;
257 wxDirTraverseResult OnDir(
const wxString& dirname)
override
259 if (m_stopToken.stop_requested())
return wxDIR_STOP;
260 if((dirname.EndsWith(
".git")) ||
261 (dirname.EndsWith(
"/share/share")) ||
262 (dirname.EndsWith(
"/src/src")) ||
263 (dirname.EndsWith(
"/doc/doc")) ||
264 (dirname.EndsWith(
"/interfaces/interfaces"))
268 return wxDIR_CONTINUE;
270 std::vector<wxString> GetResult(){
271 const std::lock_guard<std::mutex> lock(*m_lock);
276 std::vector<wxString>& m_files;
278 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
285 class GetMacFiles :
public GetMacFiles_includingSubdirs
288 explicit GetMacFiles(std::vector<wxString>& files,
291 const wxString &prefix = wxEmptyString) :
292 GetMacFiles_includingSubdirs(files, lock, stopToken, prefix){ }
293 wxDirTraverseResult OnDir(
const wxString& dirname)
override
295 if (m_stopToken.stop_requested())
return wxDIR_STOP;
296 wxFileName newItemName(dirname);
297 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
298 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
300 const std::lock_guard<std::mutex> lock(*m_lock);
301 if (m_filesHash.find(newItem) == m_filesHash.end())
303 m_files.push_back(newItem);
304 m_filesHash[newItem];
312 class GetDemoFiles_includingSubdirs :
public wxDirTraverser
315 explicit GetDemoFiles_includingSubdirs(std::vector<wxString>& files,
318 const wxString &prefix = wxEmptyString) :
319 m_files(files), m_lock(lock), m_stopToken(stopToken), m_prefix(prefix)
321 for(
const auto &i : m_files)
324 wxDirTraverseResult OnFile(
const wxString& filename)
override
326 if (m_stopToken.stop_requested())
return wxDIR_STOP;
327 if(filename.EndsWith(
".dem"))
329 wxFileName newItemName(filename);
330 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
331 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
333 const std::lock_guard<std::mutex> lock(*m_lock);
334 if (m_filesHash.find(newItem) == m_filesHash.end())
336 m_files.push_back(newItem);
337 m_filesHash[newItem];
341 return wxDIR_CONTINUE;
343 wxDirTraverseResult OnDir(
const wxString& dirname)
override
345 if (m_stopToken.stop_requested())
return wxDIR_STOP;
346 if((dirname.EndsWith(
".git")) ||
347 (dirname.EndsWith(
"/share/share")) ||
348 (dirname.EndsWith(
"/src/src")) ||
349 (dirname.EndsWith(
"/doc/doc")) ||
350 (dirname.EndsWith(
"/interfaces/interfaces"))
354 return wxDIR_CONTINUE;
356 std::vector<wxString> GetResult(){
357 const std::lock_guard<std::mutex> lock(*m_lock);
362 std::vector<wxString>& m_files;
364 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
371 class GetDemoFiles :
public GetDemoFiles_includingSubdirs
374 explicit GetDemoFiles(std::vector<wxString>& files,
377 const wxString &prefix = wxEmptyString) :
378 GetDemoFiles_includingSubdirs(files, lock, stopToken, prefix){ }
379 virtual wxDirTraverseResult OnDir(
const wxString& dirname)
override
381 if (m_stopToken.stop_requested())
return wxDIR_STOP;
382 wxFileName newItemName(dirname);
383 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
384 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
386 const std::lock_guard<std::mutex> lock(*m_lock);
387 if (m_filesHash.find(newItem) == m_filesHash.end())
389 m_files.push_back(newItem);
390 m_filesHash[newItem];
397 jthread m_addSymbols_backgroundThread;
398 jthread m_addFiles_backgroundThread;
400 std::mutex m_keywordsLock;
402 std::vector<std::vector<wxString>> m_wordList;
403 static wxRegEx m_args;
404 WorksheetWords m_worksheetWords;
407wxDECLARE_EVENT(NEW_DEMO_FILES_EVENT, wxCommandEvent);
Small C++ standard-library compatibility shims.
Definition: Autocomplete.h:61
std::vector< wxString > GetSymbolList()
Returns a list of Symbols we know.
Definition: Autocomplete.cpp:63
virtual ~AutoComplete()
The destructor of AutoComplete.
Definition: Autocomplete.cpp:284
void ClearDemofileList()
Clear the list of files demo() can be applied on.
Definition: Autocomplete.cpp:130
void UpdateFiles(autoCompletionType type, const wxString &partial, const wxString &maximaDir)
Re-scan the directory a file-name completion currently points into.
Definition: Autocomplete.cpp:482
std::vector< wxString > GetDemoFilesList()
Returns a list of demo files we know of.
Definition: Autocomplete.cpp:58
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:499
static bool CompletesFiles(autoCompletionType type)
Is this completion type one that completes file names?
Definition: Autocomplete.h:114
void AddSymbols_Backgroundtask(stop_token stopToken, wxXmlDocument xmldoc)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:175
void LoadSymbols()
Load all autocomplete symbols wxMaxima knows about by itself.
Definition: Autocomplete.cpp:292
autoCompletionType
All types of things we can autocomplete.
Definition: Autocomplete.h:68
@ tmplte
Command names.
Definition: Autocomplete.h:70
@ generalfile
loadable files
Definition: Autocomplete.h:73
@ demofile
loadable files
Definition: Autocomplete.h:72
@ numberOfTypes
Unit names.
Definition: Autocomplete.h:76
@ unit
Esc commands describing symbols.
Definition: Autocomplete.h:75
@ loadfile
Function templates.
Definition: Autocomplete.h:71
@ esccommand
general files
Definition: Autocomplete.h:74
std::vector< wxString > CompleteSymbol(wxString partial, autoCompletionType type=command)
Returns a list of possible autocompletions for the string "partial".
Definition: Autocomplete.cpp:632
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:585
void LoadBuiltinSymbols()
Makes wxMaxima know all its builtin symbols.
Definition: Autocomplete.cpp:69
void UpdateGeneralFiles(wxString partial, const wxString &maximaDir)
Assemble a list of files.
Definition: Autocomplete.cpp:540
void AddSymbols(wxString xml)
Interprets the XML autocompletable symbol list maxima can send us.
Definition: Autocomplete.cpp:135
void AddWorksheetWords(const WordList &words)
Add words to the list of words that appear in the workSheet's code cells.
Definition: Autocomplete.cpp:280
static wxString FixTemplate(wxString templ)
Basically runs a regex over templates.
Definition: Autocomplete.cpp:741
bool HasDemofile(const wxString &commandname)
Does a demo file for this command exist?
Definition: Autocomplete.cpp:120
void AddSymbols_Backgroundtask_string(stop_token stopToken, wxString xml)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:168
void AddSymbol(wxString fun, autoCompletionType type=command)
Manually add an autocompletable symbol to our symbols lists.
Definition: Autocomplete.cpp:686
void ClearWorksheetWords()
Clear the list of words that appear in the workSheet's code cells.
Definition: Autocomplete.cpp:53
The configuration storage for the current worksheet.
Definition: Configuration.h:98