KTextEditor

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

KDE's Doxygen guidelines are available online.