KTextEditor

kateglobal.h
1/*
2 SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org>
3 SPDX-FileCopyrightText: 2009 Erlend Hamberg <ehamberg@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KATE_GLOBAL_H
9#define KATE_GLOBAL_H
10
11#include <ktexteditor_export.h>
12
13#include <ktexteditor/editor.h>
14#include <ktexteditor/view.h>
15
16#include <KAboutData>
17#include <KSharedConfig>
18
19#include <KTextEditor/Application>
20#include <KTextEditor/MainWindow>
21
22#include <QList>
23#include <QPointer>
24
25#include <array>
26#include <memory>
27
29class QTextToSpeech;
30
31class KateCmd;
32class KateModeManager;
33class KateGlobalConfig;
34class KateDocumentConfig;
35class KateViewConfig;
36class KateRendererConfig;
37namespace KTextEditor
38{
39class DocumentPrivate;
40}
41namespace KTextEditor
42{
43class ViewPrivate;
44class Command;
45}
47class KDirWatch;
48class KateHlManager;
49class KateSpellCheckManager;
50class KateWordCompletionModel;
51class KateAbstractInputModeFactory;
54
55namespace KTextEditor
56{
57/**
58 * KTextEditor::EditorPrivate
59 * One instance of this class is hold alive during
60 * a kate part session, as long as any factory, document
61 * or view stay around, here is the place to put things
62 * which are needed and shared by all this objects ;)
63 */
64class KTEXTEDITOR_EXPORT EditorPrivate final : public KTextEditor::Editor
65{
66 Q_OBJECT
67
68 friend class KTextEditor::Editor;
69
70public:
71 // for setDefaultEncoding
72 friend class KateDocumentConfig;
73
74private:
75 /**
76 * Default constructor, private, as singleton
77 * @param staticInstance pointer to fill with content of this
78 */
79 KTEXTEDITOR_NO_EXPORT
81
82public:
83 /**
84 * Destructor
85 */
86 ~EditorPrivate() override;
87
88 /**
89 * Create a new document object
90 * @param parent parent object
91 * @return created KTextEditor::Document
92 */
93 KTextEditor::Document *createDocument(QObject *parent) override;
94
95 /**
96 * Returns a list of all documents of this editor.
97 * @return list of all existing documents
98 */
100 {
101 return m_documents;
102 }
103
104 /**
105 * Set the global application object.
106 * This will allow the editor component to access
107 * the hosting application.
108 * @param application application object
109 */
110 void setApplication(KTextEditor::Application *application) override
111 {
112 // switch back to dummy application?
113 m_application = application ? application : &m_dummyApplication;
114 }
115
116 /**
117 * Current hosting application, if any set.
118 * @return current application object or nullptr
119 */
121 {
122 return m_application;
123 }
124
125 /**
126 * General Information about this editor
127 */
128public:
129 /**
130 * return the about data
131 * @return about data of this editor part
132 */
133 const KAboutData &aboutData() const override
134 {
135 return m_aboutData;
136 }
137
138 /**
139 * Configuration management
140 */
141public:
142 /**
143 * Shows a config dialog for the part, changes will be applied
144 * to the editor, but not saved anywhere automagically, call
145 * writeConfig to save them
146 */
147 void configDialog(QWidget *parent) override;
148
149 /**
150 * Number of available config pages
151 * If the editor returns a number < 1, it doesn't support this
152 * and the embedding app should use the configDialog () instead
153 * @return number of config pages
154 */
155 int configPages() const override;
156
157 /**
158 * returns config page with the given number,
159 * config pages from 0 to configPages()-1 are available
160 * if configPages() > 0
161 */
162 KTextEditor::ConfigPage *configPage(int number, QWidget *parent) override;
163
164 /**
165 * Kate Part Internal stuff ;)
166 */
167public:
168 /**
169 * singleton accessor
170 * @return instance of the factory
171 */
172 static KTextEditor::EditorPrivate *self();
173
174 /**
175 * register document at the factory
176 * this allows us to loop over all docs for example on config changes
177 * @param doc document to register
178 */
179 void registerDocument(KTextEditor::DocumentPrivate *doc);
180
181 /**
182 * unregister document at the factory
183 * @param doc document to register
184 */
185 void deregisterDocument(KTextEditor::DocumentPrivate *doc);
186
187 /**
188 * register view at the factory
189 * this allows us to loop over all views for example on config changes
190 * @param view view to register
191 */
192 void registerView(KTextEditor::ViewPrivate *view);
193
194 /**
195 * unregister view at the factory
196 * @param view view to unregister
197 */
198 void deregisterView(KTextEditor::ViewPrivate *view);
199
200 /**
201 * return a list of all registered views
202 * @return all known views
203 */
204 const std::vector<KTextEditor::ViewPrivate *> &views()
205 {
206 return m_views;
207 }
208
209 /**
210 * global dirwatch
211 * @return dirwatch instance
212 */
214 {
215 return m_dirWatch;
216 }
217
218 /**
219 * The global configuration of katepart, e.g. katepartrc
220 * @return global shared access to katepartrc config
221 */
222 static KSharedConfigPtr config();
223
224 /**
225 * global mode manager
226 * used to manage the modes centrally
227 * @return mode manager
228 */
229 KateModeManager *modeManager()
230 {
231 return m_modeManager;
232 }
233
234 /**
235 * fallback document config
236 * @return default config for all documents
237 */
238 KateDocumentConfig *documentConfig()
239 {
240 return m_documentConfig;
241 }
242
243 /**
244 * fallback view config
245 * @return default config for all views
246 */
247 KateViewConfig *viewConfig()
248 {
249 return m_viewConfig;
250 }
251
252 /**
253 * fallback renderer config
254 * @return default config for all renderers
255 */
256 KateRendererConfig *rendererConfig()
257 {
258 return m_rendererConfig;
259 }
260
261 /**
262 * Global script collection
263 */
265 {
266 return m_scriptManager;
267 }
268
269 /**
270 * hl manager
271 * @return hl manager
272 */
273 KateHlManager *hlManager()
274 {
275 return m_hlManager;
276 }
277
278 /**
279 * command manager
280 * @return command manager
281 */
282 KateCmd *cmdManager()
283 {
284 return m_cmdManager;
285 }
286
287 /**
288 * spell check manager
289 * @return spell check manager
290 */
291 KateSpellCheckManager *spellCheckManager()
292 {
293 return m_spellCheckManager;
294 }
295
296 /**
297 * global instance of the simple word completion mode
298 * @return global instance of the simple word completion mode
299 */
300 KateWordCompletionModel *wordCompletionModel()
301 {
302 return m_wordCompletionModel;
303 }
304
305 /**
306 * Global instance of the language-aware keyword completion model
307 * @return global instance of the keyword completion model
308 */
310 {
311 return m_keywordCompletionModel;
312 }
313
314 /**
315 * query for command
316 * @param cmd name of command to query for
317 * @return found command or 0
318 */
319 KTextEditor::Command *queryCommand(const QString &cmd) const override;
320
321 /**
322 * Get a list of all registered commands.
323 * \return list of all commands
324 */
325 QList<KTextEditor::Command *> commands() const override;
326
327 /**
328 * Get a list of available commandline strings.
329 * \return commandline strings
330 */
331 QStringList commandList() const override;
332
333 /**
334 * Copy text to clipboard an remember it in the history
335 * @param text text to copy to clipboard, does nothing if empty!
336 * @param fileName fileName of the text to copy, used for highlighting
337 */
338 void copyToClipboard(const QString &text, const QString &fileName);
339
340 /**
341 * A clipboard entry stores the copied text and the filename of
342 * the copied text.
343 */
345 /**
346 * The copied text
347 */
349 /**
350 * The file name of the file containing the copied text,
351 * used for syntax highlighting
352 */
354 };
355
356 friend inline bool operator==(const ClipboardEntry &lhs, const ClipboardEntry &rhs)
357 {
358 return lhs.text == rhs.text && lhs.fileName == rhs.fileName;
359 }
360
361 /**
362 * Clipboard history, filled with text we ever copied
363 * to clipboard via copyToClipboard.
364 */
366 {
367 return m_clipboardHistory;
368 }
369
370 /**
371 * Dummy main window to be null safe.
372 * @return dummy main window
373 */
375 {
376 return &m_dummyMainWindow;
377 }
378
379 /**
380 * @return list of available input mode factories
381 */
382 const std::array<std::unique_ptr<KateAbstractInputModeFactory>, KTextEditor::View::ViInputMode + 1> &inputModeFactories()
383 {
384 return m_inputModeFactories;
385 }
386
387 /**
388 * Search pattern history shared among simple/power search instances.
389 */
390 QStringListModel *searchHistoryModel();
391
392 /**
393 * Replace pattern history shared among simple/power search instances.
394 */
395 QStringListModel *replaceHistoryModel();
396
397 /**
398 * Call this function to store the history models to the application config.
399 */
400 void saveSearchReplaceHistoryModels();
401
402 /**
403 * Returns the variable expansion manager.
404 */
405 KateVariableExpansionManager *variableExpansionManager();
406
407 /**
408 * Trigger delayed emission of config changed.
409 */
410 void triggerConfigChanged();
411
412 void copyToMulticursorClipboard(const QStringList &texts);
413
414 QStringList multicursorClipboard() const;
415
416 /**
417 * text to speech engine to be use by the view actions, constructed on demand.
418 * @param view the view that want to use it
419 */
420 QTextToSpeech *speechEngine(KTextEditor::ViewPrivate *view);
421
422private Q_SLOTS:
423 /**
424 * Emit configChanged if needed.
425 * Used to bundle emissions.
426 */
427 void emitConfigChanged();
428
429 /**
430 * Was the view that started the current speak output destroyed?
431 */
432 void speechEngineUserDestoyed();
433
434 /**
435 * Speech error occured.
436 * @param view view to signal error to
437 * @param errorString error to show
438 */
439 void speechError(KTextEditor::ViewPrivate *view, const QString &errorString);
440
441Q_SIGNALS:
442 /**
443 * Emitted if the history of clipboard changes via copyToClipboard
444 */
446
447protected:
448 bool eventFilter(QObject *, QEvent *) override;
449
450private Q_SLOTS:
451 void updateColorPalette();
452
453private:
454 /**
455 * about data (authors and more)
456 */
457 KAboutData m_aboutData;
458
459 /**
460 * registered docs, map from general to specialized pointer
461 */
463
464 /**
465 * registered views
466 */
467 std::vector<KTextEditor::ViewPrivate *> m_views;
468
469 /**
470 * global dirwatch object
471 */
472 KDirWatch *m_dirWatch;
473
474 /**
475 * mode manager
476 */
477 KateModeManager *m_modeManager;
478
479 /**
480 * global config
481 */
482 KateGlobalConfig *m_globalConfig;
483
484 /**
485 * fallback document config
486 */
487 KateDocumentConfig *m_documentConfig;
488
489 /**
490 * fallback view config
491 */
492 KateViewConfig *m_viewConfig;
493
494 /**
495 * fallback renderer config
496 */
497 KateRendererConfig *m_rendererConfig;
498
499 /**
500 * internal commands
501 */
502 std::array<KTextEditor::Command *, 6> m_cmds;
503
504 /**
505 * script manager
506 */
507 KateScriptManager *m_scriptManager;
508
509 /**
510 * hl manager
511 */
512 KateHlManager *m_hlManager;
513
514 /**
515 * command manager
516 */
517 KateCmd *m_cmdManager;
518
519 /**
520 * variable expansion manager
521 */
522 KateVariableExpansionManager *m_variableExpansionManager;
523
524 /**
525 * spell check manager
526 */
527 KateSpellCheckManager *m_spellCheckManager;
528
529 /**
530 * global instance of the simple word completion mode
531 */
532 KateWordCompletionModel *m_wordCompletionModel;
533
534 /**
535 * global instance of the language-specific keyword completion model
536 */
537 KateKeywordCompletionModel *m_keywordCompletionModel;
538
539 /**
540 * clipboard history
541 */
542 QList<ClipboardEntry> m_clipboardHistory;
543
544 /**
545 * Dummy application object to be null safe
546 */
547 KTextEditor::Application m_dummyApplication;
548
549 /**
550 * access to application
551 */
553
554 /**
555 * Dummy main window to be null safe
556 */
557 KTextEditor::MainWindow m_dummyMainWindow;
558
559 /**
560 * input modes factories
561 * for all input modes in the KTextEditor::View::InputMode we have here an entry
562 */
563 std::array<std::unique_ptr<KateAbstractInputModeFactory>, KTextEditor::View::ViInputMode + 1> m_inputModeFactories;
564
565 /**
566 * simple list that stores text copied
567 * from all cursors selection
568 * It's main purpose is providing multi-paste
569 * support.
570 */
571 QStringList m_multicursorClipboard;
572
573 /**
574 * Shared history models for search & replace.
575 */
576 QStringListModel *m_searchHistoryModel;
577 QStringListModel *m_replaceHistoryModel;
578
579 /**
580 * We collapse configChanged signals to avoid that e.g.
581 * Document/View/Renderer/... updates cause X emitted signals in a row.
582 * This bool tells if we still shall emit a signal in the delayed connected
583 * slot.
584 */
585 bool m_configWasChanged = false;
586
587 /**
588 * text to speech engine to be use by the view actions, constructed on demand
589 */
590 QTextToSpeech *m_speechEngine = nullptr;
591
592 /**
593 * view that triggered last speech action
594 * used to show error messages and to stop output on view destruction
595 */
596 QPointer<KTextEditor::ViewPrivate> m_speechEngineLastUser;
597};
598
599}
600
601#endif
This class allows the application that embeds the KTextEditor component to allow it access to applica...
Definition application.h:44
An Editor command line command.
Config page interface for the Editor and Plugins.
Definition configpage.h:44
Backend of KTextEditor::Document related public KTextEditor interfaces.
A KParts derived class representing a text document.
Definition document.h:284
KTextEditor::EditorPrivate One instance of this class is hold alive during a kate part session,...
Definition kateglobal.h:65
KateCmd * cmdManager()
command manager
Definition kateglobal.h:282
KateKeywordCompletionModel * keywordCompletionModel()
Global instance of the language-aware keyword completion model.
Definition kateglobal.h:309
KateModeManager * modeManager()
global mode manager used to manage the modes centrally
Definition kateglobal.h:229
KTextEditor::Application * application() const override
Current hosting application, if any set.
Definition kateglobal.h:120
const std::vector< KTextEditor::ViewPrivate * > & views()
return a list of all registered views
Definition kateglobal.h:204
const KAboutData & aboutData() const override
General Information about this editor.
Definition kateglobal.h:133
KateScriptManager * scriptManager()
Global script collection.
Definition kateglobal.h:264
const QList< ClipboardEntry > & clipboardHistory() const
Clipboard history, filled with text we ever copied to clipboard via copyToClipboard.
Definition kateglobal.h:365
KDirWatch * dirWatch()
global dirwatch
Definition kateglobal.h:213
KateSpellCheckManager * spellCheckManager()
spell check manager
Definition kateglobal.h:291
const std::array< std::unique_ptr< KateAbstractInputModeFactory >, KTextEditor::View::ViInputMode+1 > & inputModeFactories()
Definition kateglobal.h:382
KTextEditor::MainWindow * dummyMainWindow()
Dummy main window to be null safe.
Definition kateglobal.h:374
KateWordCompletionModel * wordCompletionModel()
global instance of the simple word completion mode
Definition kateglobal.h:300
KateViewConfig * viewConfig()
fallback view config
Definition kateglobal.h:247
void clipboardHistoryChanged()
Emitted if the history of clipboard changes via copyToClipboard.
KateHlManager * hlManager()
hl manager
Definition kateglobal.h:273
QList< KTextEditor::Document * > documents() override
Returns a list of all documents of this editor.
Definition kateglobal.h:99
void setApplication(KTextEditor::Application *application) override
Set the global application object.
Definition kateglobal.h:110
KateDocumentConfig * documentConfig()
fallback document config
Definition kateglobal.h:238
KateRendererConfig * rendererConfig()
fallback renderer config
Definition kateglobal.h:256
Accessor interface for the KTextEditor framework.
Definition editor.h:91
This class allows the application that embeds the KTextEditor component to allow it to access parts o...
Definition mainwindow.h:47
@ ViInputMode
Vi mode.
Definition view.h:288
Highlighting-file based keyword completion for the editor.
Manage the scripts on disks – find them and query them.
Manager class for variable expansion.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
A clipboard entry stores the copied text and the filename of the copied text.
Definition kateglobal.h:344
QString fileName
The file name of the file containing the copied text, used for syntax highlighting.
Definition kateglobal.h:353
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.