forked from TeXworks/texworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TWApp.h
323 lines (235 loc) · 8.41 KB
/
TWApp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
This is part of TeXworks, an environment for working with TeX documents
Copyright (C) 2007-2015 Jonathan Kew, Stefan Löffler, Charlie Sharpsteen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
For links to further information, or to contact the authors,
see <http://www.tug.org/texworks/>.
*/
#ifndef TWApp_H
#define TWApp_H
#include <QApplication>
#include <QList>
#include <QAction>
#include <QSettings>
#include <QClipboard>
#include <QVariant>
#include <QHash>
#include "TWUtils.h"
#include "TWScriptable.h"
#include "ConfigurableApp.h"
#include "TWScriptAPI.h"
#if defined(Q_OS_WIN)
#define PATH_LIST_SEP ';'
#define EXE ".exe"
#else
#define PATH_LIST_SEP ':'
#define EXE
#endif
#ifndef TW_BUILD_ID
#define TW_BUILD_ID unknown build
#endif
#define STRINGIFY_2(s) #s
#define STRINGIFY(s) STRINGIFY_2(s)
#define TW_BUILD_ID_STR STRINGIFY(TW_BUILD_ID)
#define DEFAULT_ENGINE_NAME "pdfLaTeX"
class QString;
class QMenu;
class QMenuBar;
// general constants used by multiple document types
const int kStatusMessageDuration = 3000;
const int kNewWindowOffset = 32;
#if defined(Q_OS_WIN) // for communication with the original instance
#if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0500
#define _WIN32_WINNT 0x0500 // for HWND_MESSAGE
#endif
#include <windows.h>
#define TW_HIDDEN_WINDOW_CLASS TEXWORKS_NAME ":MessageTarget"
#define TW_OPEN_FILE_MSG (('T' << 8) + 'W') // just a small sanity check for the receiver
#endif
class TWApp : public ConfigurableApp
{
Q_OBJECT
public:
TWApp(int &argc, char **argv);
virtual ~TWApp();
int maxRecentFiles() const;
void setMaxRecentFiles(int value);
void addToRecentFiles(const QMap<QString,QVariant>& fileProperties);
void clearRecentFiles();
void emitHighlightLineOptionChanged();
QMap<QString,QVariant> getFileProperties(const QString& path);
void setBinaryPaths(const QStringList& paths);
void setEngineList(const QList<Engine>& engines);
const QStringList getBinaryPaths(QStringList& sysEnv);
// runtime paths, including $PATH;
// also modifies passed-in sysEnv to include paths from prefs
QString findProgram(const QString& program, const QStringList& binPaths);
const QStringList getPrefsBinaryPaths(); // only paths from prefs
const QList<Engine> getEngineList();
void saveEngineList();
const Engine getNamedEngine(const QString& name);
const Engine getDefaultEngine();
void setDefaultEngine(const QString& name);
void setDefaultPaths();
void setDefaultEngineList();
QTextCodec *getDefaultCodec();
void setDefaultCodec(QTextCodec *codec);
void openUrl(const QUrl& url);
static TWApp *instance();
QString getPortableLibPath() const { return portableLibPath; }
TWScriptManager* getScriptManager() { return scriptManager; }
void notifyDictionaryListChanged() const { emit dictionaryListChanged(); }
#if defined(Q_OS_WIN)
void createMessageTarget(QWidget* aWindow);
static QString GetWindowsVersionString();
static unsigned int GetWindowsVersion();
#endif
void bringToFront();
QObject* openFile(const QString& fileName, const int pos = -1);
Q_INVOKABLE
QMap<QString, QVariant> openFileFromScript(const QString& fileName, QObject * scriptApiObj, const int pos = -1, const bool askUser = false);
Q_INVOKABLE QList<QVariant> getOpenWindows() const;
// return the version of Tw (0xMMNNPP)
Q_INVOKABLE
static int getVersion();
Q_PROPERTY(QString clipboard READ clipboardText WRITE setClipboardText)
Q_INVOKABLE QString clipboardText(QClipboard::Mode mode = QClipboard::Clipboard) const {
return clipboard()->text(mode);
}
// USE CAREFULLY
// i.e., never put new text into the clipboard without notifying the user
Q_INVOKABLE void setClipboardText(const QString& str, QClipboard::Mode mode = QClipboard::Clipboard) {
clipboard()->setText(str, mode);
}
Q_INVOKABLE void setGlobal(const QString& key, const QVariant& val);
Q_INVOKABLE void unsetGlobal(const QString& key) { m_globals.remove(key); }
Q_INVOKABLE bool hasGlobal(const QString& key) const { return m_globals.contains(key); }
Q_INVOKABLE QVariant getGlobal(const QString& key) const { return m_globals[key]; }
#if defined(Q_OS_DARWIN)
private:
// on the Mac only, we have a top-level app menu bar, including its own copy of the recent files menu
QMenuBar *menuBar;
QMenu *menuFile;
QAction *actionNew;
QAction *actionNew_from_Template;
QAction *actionOpen;
QAction *actionPreferences;
QMenu *menuRecent;
QAction *actionClear_Recent_Files;
QList<QAction*> recentFileActions;
QMenu *menuHelp;
QAction *aboutAction;
QAction *homePageAction;
QAction *mailingListAction;
#endif
public slots:
// called by documents when they load a file
void updateRecentFileActions();
// called by windows when they open/close/change name
void updateWindowMenus();
void reloadSpellchecker();
// called once when the app is first launched
void launchAction();
void activatedWindow(QWidget* theWindow);
void goToHomePage();
void writeToMailingList();
void openHelpFile(const QString& helpDirName);
void applyTranslation(const QString& locale);
void maybeQuit();
void updateScriptsList();
void showScriptsFolder();
void about();
void doResourcesDialog() const;
QObject * newFile() const;
void open();
void stackWindows();
void tileWindows();
QString getOpenFileName(QString selectedFilter = QString());
QStringList getOpenFileNames(QString selectedFilter = QString());
QString getSaveFileName(const QString& defaultName);
signals:
// emitted in response to updateRecentFileActions(); documents can listen to this if they have a recent files menu
void recentFileActionsChanged();
// emitted when the window list may have changed, so documents can update their window menu
void windowListChanged();
// emitted when the engine list is changed from Preferences, so docs can update their menus
void engineListChanged();
void scriptListChanged();
// emitted when TWUtils::getDictionaryList reloads the dictionary list;
// windows can connect to it to rebuild, e.g., a spellchecking menu
void dictionaryListChanged() const;
void syncPdf(const QString& sourceFile, int lineNo, int col, bool activatePreview);
void hideFloatersExcept(QWidget* theWindow);
void updatedTranslators();
void highlightLineOptionChanged();
private slots:
QObject * newFromTemplate() const;
void openRecentFile();
void preferences();
void changeLanguage();
void globalDestroyed(QObject * obj);
protected:
virtual bool event(QEvent *);
private:
void init();
void arrangeWindows(TWUtils::WindowArrangementFunction func);
int recentFilesLimit;
QTextCodec *defaultCodec;
QStringList *binaryPaths;
QStringList *defaultBinPaths;
QList<Engine> *engineList;
int defaultEngineIndex;
QString portableLibPath;
QList<QTranslator*> translators;
TWScriptManager *scriptManager;
QHash<QString, QVariant> m_globals;
QList<QTextCodec*> customTextCodecs;
#if defined(Q_OS_WIN)
HWND messageTargetWindow;
#endif
static TWApp *theAppInstance;
};
inline TWApp *TWApp::instance()
{
return theAppInstance;
}
class TWDocumentOpenEvent : public QEvent
{
public:
static const QEvent::Type type;
TWDocumentOpenEvent(const QString & filename, const int pos = 0) : QEvent(type), filename(filename), pos(pos) { }
QString filename;
int pos;
};
#ifdef QT_DBUS_LIB
#include <QtDBus>
#define TW_SERVICE_NAME "org.tug.texworks.application"
#define TW_APP_PATH "/org/tug/texworks/application"
#define TW_INTERFACE_NAME "org.tug.texworks.application"
class TWAdaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.tug.texworks.application") // using the #define here fails :(
private:
TWApp *app;
public:
TWAdaptor(TWApp *application)
: QDBusAbstractAdaptor(application), app(application)
{ }
public slots:
Q_NOREPLY void openFile(const QString& fileName, const int position = -1)
{ app->openFile(fileName, position); }
Q_NOREPLY void bringToFront()
{ app->bringToFront(); }
};
#endif // defined(QT_DBUS_LIB)
#endif // TWApp_H