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 using WorksheetWords = std::unordered_map<wxString, int, wxStringHash>;
64 using WordList = std::vector<wxString>;
127 const wxString &maximaDir);
131 void AddWorksheetWords(WordList::const_iterator begin, WordList::const_iterator end);
169 void WaitForSymbolTask();
173 void LoadableFiles_BackgroundTask(
const stop_token& stopToken,
const wxString& sharedir,
const wxString& demodir);
175 void BuiltinSymbols_BackgroundTask(
const stop_token& stopToken);
178 std::vector<wxString> m_builtInLoadFiles;
180 std::vector<wxString> m_builtInDemoFiles;
182 class GetGeneralFiles :
public wxDirTraverser
185 explicit GetGeneralFiles(std::vector<wxString>& files,
188 const wxString &prefix = wxEmptyString) :
189 m_files(files), m_lock(lock), m_stopToken(std::move(stopToken)), m_prefix(prefix) {
190 for(
const auto &i : m_files)
193 wxDirTraverseResult OnFile(
const wxString& filename)
override
195 if (m_stopToken.stop_requested())
return wxDIR_STOP;
196 wxFileName newItemName(filename);
197 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"\"";
198 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
200 const std::lock_guard<std::mutex> lock(*m_lock);
201 if (!m_filesHash.contains(newItem))
203 m_files.push_back(newItem);
204 m_filesHash[newItem];
207 return wxDIR_CONTINUE;
209 wxDirTraverseResult OnDir(
const wxString& dirname)
override
211 if (m_stopToken.stop_requested())
return wxDIR_STOP;
212 wxFileName newItemName(dirname);
213 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
214 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
216 const std::lock_guard<std::mutex> lock(*m_lock);
217 if (!m_filesHash.contains(newItem))
219 m_files.push_back(newItem);
220 m_filesHash[newItem];
225 std::vector<wxString> GetResult(){
226 const std::lock_guard<std::mutex> lock(*m_lock);
231 std::vector<wxString>& m_files;
233 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
240 class GetMacFiles_includingSubdirs :
public wxDirTraverser
243 explicit GetMacFiles_includingSubdirs(std::vector<wxString>& files,
246 const wxString &prefix = wxEmptyString) :
247 m_files(files), m_lock(lock), m_stopToken(std::move(stopToken)), m_prefix(prefix)
249 for(
const auto &i : m_files)
252 wxDirTraverseResult OnFile(
const wxString& filename)
override
254 if (m_stopToken.stop_requested())
return wxDIR_STOP;
256 (filename.EndsWith(
".mac"))||
257 (filename.EndsWith(
".lisp"))||
258 (filename.EndsWith(
".wxm"))
261 wxFileName newItemName(filename);
262 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
263 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
265 const std::lock_guard<std::mutex> lock(*m_lock);
266 if (!m_filesHash.contains(newItem))
268 m_files.push_back(newItem);
269 m_filesHash[newItem];
273 return wxDIR_CONTINUE;
275 wxDirTraverseResult OnDir(
const wxString& dirname)
override
277 if (m_stopToken.stop_requested())
return wxDIR_STOP;
278 if((dirname.EndsWith(
".git")) ||
279 (dirname.EndsWith(
"/share/share")) ||
280 (dirname.EndsWith(
"/src/src")) ||
281 (dirname.EndsWith(
"/doc/doc")) ||
282 (dirname.EndsWith(
"/interfaces/interfaces"))
286 return wxDIR_CONTINUE;
288 std::vector<wxString> GetResult(){
289 const std::lock_guard<std::mutex> lock(*m_lock);
294 std::vector<wxString>& m_files;
296 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
303 class GetMacFiles :
public GetMacFiles_includingSubdirs
306 explicit GetMacFiles(std::vector<wxString>& files,
309 const wxString &prefix = wxEmptyString) :
310 GetMacFiles_includingSubdirs(files, lock, std::move(stopToken), prefix){ }
311 wxDirTraverseResult OnDir(
const wxString& dirname)
override
313 if (m_stopToken.stop_requested())
return wxDIR_STOP;
314 wxFileName newItemName(dirname);
315 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
316 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
318 const std::lock_guard<std::mutex> lock(*m_lock);
319 if (!m_filesHash.contains(newItem))
321 m_files.push_back(newItem);
322 m_filesHash[newItem];
330 class GetDemoFiles_includingSubdirs :
public wxDirTraverser
333 explicit GetDemoFiles_includingSubdirs(std::vector<wxString>& files,
336 const wxString &prefix = wxEmptyString) :
337 m_files(files), m_lock(lock), m_stopToken(std::move(stopToken)), m_prefix(prefix)
339 for(
const auto &i : m_files)
342 wxDirTraverseResult OnFile(
const wxString& filename)
override
344 if (m_stopToken.stop_requested())
return wxDIR_STOP;
345 if(filename.EndsWith(
".dem"))
347 wxFileName newItemName(filename);
348 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
349 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
351 const std::lock_guard<std::mutex> lock(*m_lock);
352 if (!m_filesHash.contains(newItem))
354 m_files.push_back(newItem);
355 m_filesHash[newItem];
359 return wxDIR_CONTINUE;
361 wxDirTraverseResult OnDir(
const wxString& dirname)
override
363 if (m_stopToken.stop_requested())
return wxDIR_STOP;
364 if((dirname.EndsWith(
".git")) ||
365 (dirname.EndsWith(
"/share/share")) ||
366 (dirname.EndsWith(
"/src/src")) ||
367 (dirname.EndsWith(
"/doc/doc")) ||
368 (dirname.EndsWith(
"/interfaces/interfaces"))
372 return wxDIR_CONTINUE;
374 std::vector<wxString> GetResult(){
375 const std::lock_guard<std::mutex> lock(*m_lock);
380 std::vector<wxString>& m_files;
382 std::unordered_map<wxString, wxEvtHandler*, wxStringHash> m_filesHash;
389 class GetDemoFiles :
public GetDemoFiles_includingSubdirs
392 explicit GetDemoFiles(std::vector<wxString>& files,
395 const wxString &prefix = wxEmptyString) :
396 GetDemoFiles_includingSubdirs(files, lock, std::move(stopToken), prefix){ }
397 wxDirTraverseResult OnDir(
const wxString& dirname)
override
399 if (m_stopToken.stop_requested())
return wxDIR_STOP;
400 wxFileName newItemName(dirname);
401 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
402 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
404 const std::lock_guard<std::mutex> lock(*m_lock);
405 if (!m_filesHash.contains(newItem))
407 m_files.push_back(newItem);
408 m_filesHash[newItem];
415 jthread m_addSymbols_backgroundThread;
416 jthread m_addFiles_backgroundThread;
418 std::mutex m_keywordsLock;
420 std::vector<std::vector<wxString>> m_wordList;
421 static wxRegEx m_args;
422 WorksheetWords m_worksheetWords;
425wxDECLARE_EVENT(NEW_DEMO_FILES_EVENT, wxCommandEvent);
Small compatibility shims for older toolchains and older wxWidgets.
Definition: Autocomplete.h:61
std::vector< wxString > GetSymbolList()
Returns a list of Symbols we know.
Definition: Autocomplete.cpp:64
void ClearDemofileList()
Clear the list of files demo() can be applied on.
Definition: Autocomplete.cpp:131
void UpdateFiles(autoCompletionType type, const wxString &partial, const wxString &maximaDir)
Re-scan the directory a file-name completion currently points into.
Definition: Autocomplete.cpp:491
std::vector< wxString > GetDemoFilesList()
Returns a list of demo files we know of.
Definition: Autocomplete.cpp:59
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:508
static bool IsEscHexCompletion(const wxString &completion)
Is this ESC completion a code point typed as a hex number, not a name?
Definition: Autocomplete.cpp:701
static bool CompletesFiles(autoCompletionType type)
Is this completion type one that completes file names?
Definition: Autocomplete.h:114
void LoadSymbols()
Load all autocomplete symbols wxMaxima knows about by itself.
Definition: Autocomplete.cpp:299
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:641
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:594
void LoadBuiltinSymbols()
Makes wxMaxima know all its builtin symbols.
Definition: Autocomplete.cpp:70
~AutoComplete() override
The destructor of AutoComplete.
Definition: Autocomplete.cpp:291
void AddSymbols_Backgroundtask_string(const stop_token &stopToken, const wxString &xml)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:175
void UpdateGeneralFiles(wxString partial, const wxString &maximaDir)
Assemble a list of files.
Definition: Autocomplete.cpp:549
void AddSymbols(wxString xml)
Interprets the XML autocompletable symbol list maxima can send us.
Definition: Autocomplete.cpp:136
void AddWorksheetWords(const WordList &words)
Add words to the list of words that appear in the workSheet's code cells.
Definition: Autocomplete.cpp:287
static wxString EscCompletionLabel(const wxString &completion)
What the ESC popup shows for a completion: the symbol next to its name.
Definition: Autocomplete.cpp:710
static wxString FixTemplate(wxString templ)
Basically runs a regex over templates.
Definition: Autocomplete.cpp:783
bool HasDemofile(const wxString &commandname)
Does a demo file for this command exist?
Definition: Autocomplete.cpp:121
void AddSymbols_Backgroundtask(const stop_token &stopToken, const wxXmlDocument &xmldoc)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:182
void AddSymbol(wxString fun, autoCompletionType type=command)
Manually add an autocompletable symbol to our symbols lists.
Definition: Autocomplete.cpp:728
void ClearWorksheetWords()
Clear the list of words that appear in the workSheet's code cells.
Definition: Autocomplete.cpp:54
The configuration storage for the current worksheet.
Definition: Configuration.h:102