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

KDE's Doxygen guidelines are available online.