Warning, file /frameworks/ktexteditor/src/utils/kateglobal.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org> 0003 SPDX-FileCopyrightText: 2009 Erlend Hamberg <ehamberg@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KATE_GLOBAL_H 0009 #define KATE_GLOBAL_H 0010 0011 #include <ktexteditor_export.h> 0012 0013 #include <ktexteditor/editor.h> 0014 #include <ktexteditor/view.h> 0015 0016 #include <KAboutData> 0017 #include <KSharedConfig> 0018 0019 #include <KTextEditor/Application> 0020 #include <KTextEditor/MainWindow> 0021 0022 #include <QList> 0023 #include <QPointer> 0024 0025 #include <array> 0026 #include <memory> 0027 0028 class QStringListModel; 0029 0030 class KateCmd; 0031 class KateModeManager; 0032 class KateGlobalConfig; 0033 class KateDocumentConfig; 0034 class KateViewConfig; 0035 class KateRendererConfig; 0036 namespace KTextEditor 0037 { 0038 class DocumentPrivate; 0039 } 0040 namespace KTextEditor 0041 { 0042 class ViewPrivate; 0043 class Command; 0044 } 0045 class KateScriptManager; 0046 class KDirWatch; 0047 class KateHlManager; 0048 class KateSpellCheckManager; 0049 class KateWordCompletionModel; 0050 class KateAbstractInputModeFactory; 0051 class KateKeywordCompletionModel; 0052 class KateVariableExpansionManager; 0053 0054 namespace KTextEditor 0055 { 0056 /** 0057 * KTextEditor::EditorPrivate 0058 * One instance of this class is hold alive during 0059 * a kate part session, as long as any factory, document 0060 * or view stay around, here is the place to put things 0061 * which are needed and shared by all this objects ;) 0062 */ 0063 class KTEXTEDITOR_EXPORT EditorPrivate : public KTextEditor::Editor 0064 { 0065 Q_OBJECT 0066 0067 friend class KTextEditor::Editor; 0068 0069 // unit testing support 0070 public: 0071 /** 0072 * Calling this function internally sets a flag such that unitTestMode() 0073 * returns \p true. 0074 */ 0075 static void enableUnitTestMode(); 0076 0077 /** 0078 * Returns \p true, if the unit test mode was enabled through a call of 0079 * enableUnitTestMode(), otherwise \p false. 0080 */ 0081 static bool unitTestMode(); 0082 0083 // for setDefaultEncoding 0084 friend class KateDocumentConfig; 0085 0086 private: 0087 /** 0088 * Default constructor, private, as singleton 0089 * @param staticInstance pointer to fill with content of this 0090 */ 0091 KTEXTEDITOR_NO_EXPORT 0092 explicit EditorPrivate(QPointer<KTextEditor::EditorPrivate> &staticInstance); 0093 0094 public: 0095 /** 0096 * Destructor 0097 */ 0098 ~EditorPrivate() override; 0099 0100 /** 0101 * Create a new document object 0102 * @param parent parent object 0103 * @return created KTextEditor::Document 0104 */ 0105 KTextEditor::Document *createDocument(QObject *parent) override; 0106 0107 /** 0108 * Returns a list of all documents of this editor. 0109 * @return list of all existing documents 0110 */ 0111 QList<KTextEditor::Document *> documents() override 0112 { 0113 return m_documents.keys(); 0114 } 0115 0116 /** 0117 * Set the global application object. 0118 * This will allow the editor component to access 0119 * the hosting application. 0120 * @param application application object 0121 */ 0122 void setApplication(KTextEditor::Application *application) override 0123 { 0124 // switch back to dummy application? 0125 m_application = application ? application : &m_dummyApplication; 0126 } 0127 0128 /** 0129 * Current hosting application, if any set. 0130 * @return current application object or nullptr 0131 */ 0132 KTextEditor::Application *application() const override 0133 { 0134 return m_application; 0135 } 0136 0137 /** 0138 * General Information about this editor 0139 */ 0140 public: 0141 /** 0142 * return the about data 0143 * @return about data of this editor part 0144 */ 0145 const KAboutData &aboutData() const override 0146 { 0147 return m_aboutData; 0148 } 0149 0150 /** 0151 * Configuration management 0152 */ 0153 public: 0154 /** 0155 * Shows a config dialog for the part, changes will be applied 0156 * to the editor, but not saved anywhere automagically, call 0157 * writeConfig to save them 0158 */ 0159 void configDialog(QWidget *parent) override; 0160 0161 /** 0162 * Number of available config pages 0163 * If the editor returns a number < 1, it doesn't support this 0164 * and the embedding app should use the configDialog () instead 0165 * @return number of config pages 0166 */ 0167 int configPages() const override; 0168 0169 /** 0170 * returns config page with the given number, 0171 * config pages from 0 to configPages()-1 are available 0172 * if configPages() > 0 0173 */ 0174 KTextEditor::ConfigPage *configPage(int number, QWidget *parent) override; 0175 0176 /** 0177 * Kate Part Internal stuff ;) 0178 */ 0179 public: 0180 /** 0181 * singleton accessor 0182 * @return instance of the factory 0183 */ 0184 static KTextEditor::EditorPrivate *self(); 0185 0186 /** 0187 * register document at the factory 0188 * this allows us to loop over all docs for example on config changes 0189 * @param doc document to register 0190 */ 0191 void registerDocument(KTextEditor::DocumentPrivate *doc); 0192 0193 /** 0194 * unregister document at the factory 0195 * @param doc document to register 0196 */ 0197 void deregisterDocument(KTextEditor::DocumentPrivate *doc); 0198 0199 /** 0200 * register view at the factory 0201 * this allows us to loop over all views for example on config changes 0202 * @param view view to register 0203 */ 0204 void registerView(KTextEditor::ViewPrivate *view); 0205 0206 /** 0207 * unregister view at the factory 0208 * @param view view to unregister 0209 */ 0210 void deregisterView(KTextEditor::ViewPrivate *view); 0211 0212 /** 0213 * return a list of all registered views 0214 * @return all known views 0215 */ 0216 QList<KTextEditor::ViewPrivate *> views() 0217 { 0218 return m_views.values(); 0219 } 0220 0221 /** 0222 * global dirwatch 0223 * @return dirwatch instance 0224 */ 0225 KDirWatch *dirWatch() 0226 { 0227 return m_dirWatch; 0228 } 0229 0230 /** 0231 * The global configuration of katepart, e.g. katepartrc 0232 * @return global shared access to katepartrc config 0233 */ 0234 static KSharedConfigPtr config(); 0235 0236 /** 0237 * global mode manager 0238 * used to manage the modes centrally 0239 * @return mode manager 0240 */ 0241 KateModeManager *modeManager() 0242 { 0243 return m_modeManager; 0244 } 0245 0246 /** 0247 * fallback document config 0248 * @return default config for all documents 0249 */ 0250 KateDocumentConfig *documentConfig() 0251 { 0252 return m_documentConfig; 0253 } 0254 0255 /** 0256 * fallback view config 0257 * @return default config for all views 0258 */ 0259 KateViewConfig *viewConfig() 0260 { 0261 return m_viewConfig; 0262 } 0263 0264 /** 0265 * fallback renderer config 0266 * @return default config for all renderers 0267 */ 0268 KateRendererConfig *rendererConfig() 0269 { 0270 return m_rendererConfig; 0271 } 0272 0273 /** 0274 * Global script collection 0275 */ 0276 KateScriptManager *scriptManager() 0277 { 0278 return m_scriptManager; 0279 } 0280 0281 /** 0282 * hl manager 0283 * @return hl manager 0284 */ 0285 KateHlManager *hlManager() 0286 { 0287 return m_hlManager; 0288 } 0289 0290 /** 0291 * command manager 0292 * @return command manager 0293 */ 0294 KateCmd *cmdManager() 0295 { 0296 return m_cmdManager; 0297 } 0298 0299 /** 0300 * spell check manager 0301 * @return spell check manager 0302 */ 0303 KateSpellCheckManager *spellCheckManager() 0304 { 0305 return m_spellCheckManager; 0306 } 0307 0308 /** 0309 * global instance of the simple word completion mode 0310 * @return global instance of the simple word completion mode 0311 */ 0312 KateWordCompletionModel *wordCompletionModel() 0313 { 0314 return m_wordCompletionModel; 0315 } 0316 0317 /** 0318 * Global instance of the language-aware keyword completion model 0319 * @return global instance of the keyword completion model 0320 */ 0321 KateKeywordCompletionModel *keywordCompletionModel() 0322 { 0323 return m_keywordCompletionModel; 0324 } 0325 0326 /** 0327 * query for command 0328 * @param cmd name of command to query for 0329 * @return found command or 0 0330 */ 0331 KTextEditor::Command *queryCommand(const QString &cmd) const override; 0332 0333 /** 0334 * Get a list of all registered commands. 0335 * \return list of all commands 0336 */ 0337 QList<KTextEditor::Command *> commands() const override; 0338 0339 /** 0340 * Get a list of available commandline strings. 0341 * \return commandline strings 0342 */ 0343 QStringList commandList() const override; 0344 0345 /** 0346 * Copy text to clipboard an remember it in the history 0347 * @param text text to copy to clipboard, does nothing if empty! 0348 * @param fileName fileName of the text to copy, used for highlighting 0349 */ 0350 void copyToClipboard(const QString &text, const QString &fileName); 0351 0352 /** 0353 * A clipboard entry stores the copied text and the filename of 0354 * the copied text. 0355 */ 0356 struct ClipboardEntry { 0357 /** 0358 * The copied text 0359 */ 0360 QString text; 0361 /** 0362 * The file name of the file containing the copied text, 0363 * used for syntax highlighting 0364 */ 0365 QString fileName; 0366 }; 0367 0368 friend inline bool operator==(const ClipboardEntry &lhs, const ClipboardEntry &rhs) 0369 { 0370 return lhs.text == rhs.text && lhs.fileName == rhs.fileName; 0371 } 0372 0373 /** 0374 * Clipboard history, filled with text we ever copied 0375 * to clipboard via copyToClipboard. 0376 */ 0377 const QVector<ClipboardEntry> &clipboardHistory() const 0378 { 0379 return m_clipboardHistory; 0380 } 0381 0382 /** 0383 * return a list of all registered docs 0384 * @return all known documents 0385 */ 0386 QList<KTextEditor::DocumentPrivate *> kateDocuments() 0387 { 0388 return m_documents.values(); 0389 } 0390 0391 /** 0392 * Dummy main window to be null safe. 0393 * @return dummy main window 0394 */ 0395 KTextEditor::MainWindow *dummyMainWindow() 0396 { 0397 return &m_dummyMainWindow; 0398 } 0399 0400 /** 0401 * @return list of available input mode factories 0402 */ 0403 const std::array<std::unique_ptr<KateAbstractInputModeFactory>, KTextEditor::View::ViInputMode + 1> &inputModeFactories() 0404 { 0405 return m_inputModeFactories; 0406 } 0407 0408 /** 0409 * Search pattern history shared among simple/power search instances. 0410 */ 0411 QStringListModel *searchHistoryModel(); 0412 0413 /** 0414 * Replace pattern history shared among simple/power search instances. 0415 */ 0416 QStringListModel *replaceHistoryModel(); 0417 0418 /** 0419 * Call this function to store the history models to the application config. 0420 */ 0421 void saveSearchReplaceHistoryModels(); 0422 0423 /** 0424 * Returns the variable expansion manager. 0425 */ 0426 KateVariableExpansionManager *variableExpansionManager(); 0427 0428 /** 0429 * Trigger delayed emission of config changed. 0430 */ 0431 void triggerConfigChanged(); 0432 0433 void copyToMulticursorClipboard(const QStringList &texts); 0434 0435 QStringList multicursorClipboard() const; 0436 0437 private Q_SLOTS: 0438 /** 0439 * Emit configChanged if needed. 0440 * Used to bundle emissions. 0441 */ 0442 void emitConfigChanged(); 0443 0444 Q_SIGNALS: 0445 /** 0446 * Emitted if the history of clipboard changes via copyToClipboard 0447 */ 0448 void clipboardHistoryChanged(); 0449 0450 protected: 0451 bool eventFilter(QObject *, QEvent *) override; 0452 0453 private Q_SLOTS: 0454 void updateColorPalette(); 0455 0456 private: 0457 /** 0458 * about data (authors and more) 0459 */ 0460 KAboutData m_aboutData; 0461 0462 /** 0463 * registered docs, map from general to specialized pointer 0464 */ 0465 QHash<KTextEditor::Document *, KTextEditor::DocumentPrivate *> m_documents; 0466 0467 /** 0468 * registered views 0469 */ 0470 QSet<KTextEditor::ViewPrivate *> m_views; 0471 0472 /** 0473 * global dirwatch object 0474 */ 0475 KDirWatch *m_dirWatch; 0476 0477 /** 0478 * mode manager 0479 */ 0480 KateModeManager *m_modeManager; 0481 0482 /** 0483 * global config 0484 */ 0485 KateGlobalConfig *m_globalConfig; 0486 0487 /** 0488 * fallback document config 0489 */ 0490 KateDocumentConfig *m_documentConfig; 0491 0492 /** 0493 * fallback view config 0494 */ 0495 KateViewConfig *m_viewConfig; 0496 0497 /** 0498 * fallback renderer config 0499 */ 0500 KateRendererConfig *m_rendererConfig; 0501 0502 /** 0503 * internal commands 0504 */ 0505 QList<KTextEditor::Command *> m_cmds; 0506 0507 /** 0508 * script manager 0509 */ 0510 KateScriptManager *m_scriptManager; 0511 0512 /** 0513 * hl manager 0514 */ 0515 KateHlManager *m_hlManager; 0516 0517 /** 0518 * command manager 0519 */ 0520 KateCmd *m_cmdManager; 0521 0522 /** 0523 * variable expansion manager 0524 */ 0525 KateVariableExpansionManager *m_variableExpansionManager; 0526 0527 /** 0528 * spell check manager 0529 */ 0530 KateSpellCheckManager *m_spellCheckManager; 0531 0532 /** 0533 * global instance of the simple word completion mode 0534 */ 0535 KateWordCompletionModel *m_wordCompletionModel; 0536 0537 /** 0538 * global instance of the language-specific keyword completion model 0539 */ 0540 KateKeywordCompletionModel *m_keywordCompletionModel; 0541 0542 /** 0543 * clipboard history 0544 */ 0545 QVector<ClipboardEntry> m_clipboardHistory; 0546 0547 /** 0548 * Dummy application object to be null safe 0549 */ 0550 KTextEditor::Application m_dummyApplication; 0551 0552 /** 0553 * access to application 0554 */ 0555 QPointer<KTextEditor::Application> m_application; 0556 0557 /** 0558 * Dummy main window to be null safe 0559 */ 0560 KTextEditor::MainWindow m_dummyMainWindow; 0561 0562 /** 0563 * input modes factories 0564 * for all input modes in the KTextEditor::View::InputMode we have here an entry 0565 */ 0566 std::array<std::unique_ptr<KateAbstractInputModeFactory>, KTextEditor::View::ViInputMode + 1> m_inputModeFactories; 0567 0568 /** 0569 * simple list that stores text copied 0570 * from all cursors selection 0571 * It's main purpose is providing multi-paste 0572 * support. 0573 */ 0574 QStringList m_multicursorClipboard; 0575 0576 /** 0577 * Shared history models for search & replace. 0578 */ 0579 QStringListModel *m_searchHistoryModel; 0580 QStringListModel *m_replaceHistoryModel; 0581 0582 /** 0583 * We collapse configChanged signals to avoid that e.g. 0584 * Document/View/Renderer/... updates cause X emitted signals in a row. 0585 * This bool tells if we still shall emit a signal in the delayed connected 0586 * slot. 0587 */ 0588 bool m_configWasChanged = false; 0589 }; 0590 0591 } 0592 0593 #endif