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;
148 class GetGeneralFiles :
public wxDirTraverser
151 explicit GetGeneralFiles(std::vector<wxString>& files,
153 const wxString &prefix = wxEmptyString) :
154 m_files(files), m_lock(lock), m_prefix(prefix) { }
155 wxDirTraverseResult OnFile(
const wxString& filename)
override
157 wxFileName newItemName(filename);
158 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"\"";
159 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
161 const std::lock_guard<std::mutex> lock(*m_lock);
162 if(std::find(m_files.begin(), m_files.end(), newItem) == m_files.end())
163 m_files.push_back(newItem);
165 return wxDIR_CONTINUE;
167 wxDirTraverseResult OnDir(
const wxString& dirname)
override
169 wxFileName newItemName(dirname);
170 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
171 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
173 const std::lock_guard<std::mutex> lock(*m_lock);
174 if(std::find(m_files.begin(), m_files.end(), newItem) == m_files.end())
175 m_files.push_back(newItem);
179 std::vector<wxString> GetResult(){
180 const std::lock_guard<std::mutex> lock(*m_lock);
184 std::vector<wxString>& m_files;
190 class GetMacFiles_includingSubdirs :
public wxDirTraverser
193 explicit GetMacFiles_includingSubdirs(std::vector<wxString>& files,
195 const wxString &prefix = wxEmptyString) :
196 m_files(files), m_lock(lock), m_prefix(prefix) { }
197 wxDirTraverseResult OnFile(
const wxString& filename)
override
200 (filename.EndsWith(
".mac"))||
201 (filename.EndsWith(
".lisp"))||
202 (filename.EndsWith(
".wxm"))
205 wxFileName newItemName(filename);
206 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
207 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
209 const std::lock_guard<std::mutex> lock(*m_lock);
210 if(std::find(m_files.begin(), m_files.end(), newItem) == m_files.end())
211 m_files.push_back(newItem);
214 return wxDIR_CONTINUE;
216 wxDirTraverseResult OnDir(
const wxString& dirname)
override
218 if((dirname.EndsWith(
".git")) ||
219 (dirname.EndsWith(
"/share/share")) ||
220 (dirname.EndsWith(
"/src/src")) ||
221 (dirname.EndsWith(
"/doc/doc")) ||
222 (dirname.EndsWith(
"/interfaces/interfaces"))
226 return wxDIR_CONTINUE;
228 std::vector<wxString> GetResult(){
229 const std::lock_guard<std::mutex> lock(*m_lock);
233 std::vector<wxString>& m_files;
239 class GetMacFiles :
public GetMacFiles_includingSubdirs
242 explicit GetMacFiles(std::vector<wxString>& files,
244 const wxString &prefix = wxEmptyString) :
245 GetMacFiles_includingSubdirs(files, lock, prefix){ }
246 wxDirTraverseResult OnDir(
const wxString& dirname)
override
248 wxFileName newItemName(dirname);
249 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
250 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
252 const std::lock_guard<std::mutex> lock(*m_lock);
253 if(std::find(m_files.begin(), m_files.end(), newItem) == m_files.end())
254 m_files.push_back(newItem);
261 class GetDemoFiles_includingSubdirs :
public wxDirTraverser
264 explicit GetDemoFiles_includingSubdirs(std::vector<wxString>& files,
266 const wxString &prefix = wxEmptyString) :
267 m_files(files), m_lock(lock), m_prefix(prefix) { }
268 wxDirTraverseResult OnFile(
const wxString& filename)
override
270 if(filename.EndsWith(
".dem"))
272 wxFileName newItemName(filename);
273 wxString newItem =
"\"" + m_prefix + newItemName.GetName() +
"\"";
274 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
276 const std::lock_guard<std::mutex> lock(*m_lock);
277 if(std::find(m_files.begin(), m_files.end(), newItem) == m_files.end())
278 m_files.push_back(newItem);
281 return wxDIR_CONTINUE;
283 wxDirTraverseResult OnDir(
const wxString& dirname)
override
285 if((dirname.EndsWith(
".git")) ||
286 (dirname.EndsWith(
"/share/share")) ||
287 (dirname.EndsWith(
"/src/src")) ||
288 (dirname.EndsWith(
"/doc/doc")) ||
289 (dirname.EndsWith(
"/interfaces/interfaces"))
293 return wxDIR_CONTINUE;
295 std::vector<wxString> GetResult(){
296 const std::lock_guard<std::mutex> lock(*m_lock);
300 std::vector<wxString>& m_files;
306 class GetDemoFiles :
public GetDemoFiles_includingSubdirs
309 explicit GetDemoFiles(std::vector<wxString>& files,
311 const wxString &prefix = wxEmptyString) :
312 GetDemoFiles_includingSubdirs(files, lock, prefix){ }
313 virtual wxDirTraverseResult OnDir(
const wxString& dirname)
override
315 wxFileName newItemName(dirname);
316 wxString newItem =
"\"" + m_prefix + newItemName.GetFullName() +
"/\"";
317 newItem.Replace(wxFileName::GetPathSeparator(),
"/");
319 const std::lock_guard<std::mutex> lock(*m_lock);
320 if(std::find(m_files.begin(), m_files.end(), newItem) == m_files.end())
321 m_files.push_back(newItem);
327 jthread m_addSymbols_backgroundThread;
328 jthread m_addFiles_backgroundThread;
330 std::mutex m_keywordsLock;
332 std::vector<std::vector<wxString>> m_wordList;
333 static wxRegEx m_args;
334 WorksheetWords m_worksheetWords;
337wxDECLARE_EVENT(NEW_DEMO_FILES_EVENT, wxCommandEvent);
Definition: Autocomplete.h:60
std::vector< wxString > GetSymbolList()
Returns a list of Symbols we know.
Definition: Autocomplete.cpp:63
void AddSymbols_Backgroundtask(wxXmlDocument xmldoc)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:144
virtual ~AutoComplete()
The destructor of AutoComplete.
Definition: Autocomplete.cpp:220
void ClearDemofileList()
Clear the list of files demo() can be applied on.
Definition: Autocomplete.cpp:104
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:393
void LoadSymbols()
Load all autocomplete symbols wxMaxima knows about by itself.
Definition: Autocomplete.cpp:227
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:504
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:462
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:429
void AddSymbols(wxString xml)
Interprets the XML autocompletable symbol list maxima can send us.
Definition: Autocomplete.cpp:109
void AddWorksheetWords(const WordList &words)
Add words to the list of words that appear in the workSheet's code cells.
Definition: Autocomplete.cpp:216
void AddSymbols_Backgroundtask_string(wxString xml)
The real work of AddSymbols is made here and in the background.
Definition: Autocomplete.cpp:137
static wxString FixTemplate(wxString templ)
Basically runs a regex over templates.
Definition: Autocomplete.cpp:610
bool HasDemofile(const wxString &commandname)
Does a demo file for this command exist?
Definition: Autocomplete.cpp:94
void AddSymbol(wxString fun, autoCompletionType type=command)
Manually add an autocompletable symbol to our symbols lists.
Definition: Autocomplete.cpp:559
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:85