wxMaxima
Loading...
Searching...
No Matches
MaximaManual.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2009-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// Copyright (C) 2015 Gunter Königsmann <wxMaxima@physikbuch.de>
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 2 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20//
21// SPDX-License-Identifier: GPL-2.0+
22
30#ifndef MAXIMAMANUAL_H
31#define MAXIMAMANUAL_H
32
33#include <atomic>
34#include <thread>
35#include <mutex>
36#include <memory>
37#include <vector>
38#include <wx/dir.h>
39#include <wx/wx.h>
40#include <wx/arrstr.h>
41#include <wx/regex.h>
42#include <wx/xml/xml.h>
43#include <wx/filename.h>
44#include "precomp.h"
45#include "Configuration.h"
46#include "Compat.h"
47#include <unordered_map>
48
49/* The autocompletion logic
50
51 The wordlists for autocompletion for keywords come from several sources:
52
53 - wxMaxima::ReadLoadSymbols receive the contents of maxima's variables
54 "values" and "functions" after a package is loaded.
55 - all words that appear in the worksheet
56 - and a list of maxima's builtin commands.
57*/
59{
60public:
61 explicit MaximaManual(Configuration *configuration);
62 using HelpFileAnchors = std::unordered_map<wxString, wxString, wxStringHash>;
63 HelpFileAnchors GetHelpfileAnchors();
64 void FindMaximaHtmlDir(const wxString &docDir);
65 wxString GetHelpfileAnchorName(const wxString& keyword);
66 wxString GetHelpfileUrl_Singlepage(const wxString &keyword);
67 wxString GetHelpfileUrl_FilePerChapter(const wxString &keyword);
68 wxString GetHelpfileURL(const wxString &keyword);
70 void LoadHelpFileAnchors(const wxString &docdir, const wxString &maximaVersion);
76 void CompileHelpFileAnchors(const stop_token& stopToken,
77 const wxString &maximaHtmlDir,
78 const wxString &maximaShareDir,
79 const wxString &maximaVersion,
80 const wxString &saveName);
84 bool LoadManualAnchorsFromXML(const wxXmlDocument &xmlDocument, bool checkManualVersion = true);
88 void SaveManualAnchorsToCache(const wxString &maximaHtmlDir,
89 const wxString &maximaVersion,
90 const wxString &saveName);
91 virtual ~MaximaManual();
92private:
94 static void AnchorAliasses(HelpFileAnchors &anchors);
96 class GetHTMLFiles : public wxDirTraverser
97 {
98 public:
99 explicit GetHTMLFiles(std::vector<wxString>& files,
100 stop_token stopToken = {},
101 const wxString &prefix = wxEmptyString) :
102 m_files(files), m_stopToken(std::move(stopToken)), m_prefix(prefix) { }
103 wxDirTraverseResult OnFile(const wxString& filename) override;
104 wxDirTraverseResult OnDir(const wxString& dirname) override;
105 std::vector<wxString>& GetResult() const {return m_files;}
106 protected:
107 std::vector<wxString>& m_files;
108 stop_token m_stopToken;
109 wxString m_prefix;
110 };
111 class GetHTMLFiles_Recursive : public wxDirTraverser
112 {
113 public:
114 explicit GetHTMLFiles_Recursive(std::vector<wxString>& files,
115 stop_token stopToken = {},
116 const wxString &prefix = wxEmptyString) :
117 m_files(files), m_stopToken(std::move(stopToken)), m_prefix(prefix) { }
118 wxDirTraverseResult OnFile(const wxString& filename) override;
119 wxDirTraverseResult OnDir(const wxString& dirname) override;
120 std::vector<wxString>& GetResult() const {return m_files;}
121 protected:
122 std::vector<wxString>& m_files;
123 stop_token m_stopToken;
124 wxString m_prefix;
125 };
126
127 // m_configuration.MaximaShareDir(dir);
128
130 jthread m_helpfileanchorsThread;
135 std::atomic<bool> m_anchorsCompileInFlight{false};
136 std::mutex m_helpFileAnchorsLock;
138 Configuration *m_configuration = nullptr;
140
141 HelpFileAnchors m_helpFileURLs_singlePage;
143 HelpFileAnchors m_helpFileURLs_filePerChapter;
145 HelpFileAnchors m_helpFileAnchors;
146 wxString m_maximaHtmlDir;
147 wxString m_maximaVersion;
148};
149
150#endif // MAXIMAMANUAL_H
Small compatibility shims for older toolchains and older wxWidgets.
The configuration storage for the current worksheet.
Definition: Configuration.h:102
Definition: MaximaManual.h:59
bool LoadManualAnchorsFromCache()
Load the result from the last CompileHelpFileAnchors from the disk cache.
Definition: MaximaManual.cpp:105
void LoadHelpFileAnchors(const wxString &docdir, const wxString &maximaVersion)
Search maxima's help file for command and variable names.
Definition: MaximaManual.cpp:548
void SaveManualAnchorsToCache(const wxString &maximaHtmlDir, const wxString &maximaVersion, const wxString &saveName)
Save the list of help file anchors to the cache.
Definition: MaximaManual.cpp:327
bool LoadManualAnchorsFromXML(const wxXmlDocument &xmlDocument, bool checkManualVersion=true)
Load the help file anchors from an wxXmlDocument.
Definition: MaximaManual.cpp:398
bool LoadBuiltInManualAnchors()
Load the help file anchors from the built-in list.
Definition: MaximaManual.cpp:93
void CompileHelpFileAnchors(const stop_token &stopToken, const wxString &maximaHtmlDir, const wxString &maximaShareDir, const wxString &maximaVersion, const wxString &saveName)
Collect all keyword anchors in the help file.
Definition: MaximaManual.cpp:154
Definition: Compat.h:58
Definition: Compat.h:47