| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2009 Erlend Hamberg <ehamberg@gmail.com> |
| 3 | SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef KATEVI_APP_COMMANDS_H |
| 9 | #define KATEVI_APP_COMMANDS_H |
| 10 | |
| 11 | #include <KTextEditor/Command> |
| 12 | #include <QObject> |
| 13 | #include <QRegularExpression> |
| 14 | |
| 15 | namespace KTextEditor |
| 16 | { |
| 17 | class MainWindow; |
| 18 | } |
| 19 | |
| 20 | namespace KateVi |
| 21 | { |
| 22 | class AppCommands : public KTextEditor::Command |
| 23 | { |
| 24 | AppCommands(); |
| 25 | static AppCommands *m_instance; |
| 26 | |
| 27 | public: |
| 28 | ~AppCommands() override; |
| 29 | bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range::invalid()) override; |
| 30 | bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override; |
| 31 | |
| 32 | static AppCommands *self() |
| 33 | { |
| 34 | if (m_instance == nullptr) { |
| 35 | m_instance = new AppCommands(); |
| 36 | } |
| 37 | return m_instance; |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | /** |
| 42 | * @returns a view in the given \p window that does not share a split |
| 43 | * view with the given \p view. If such view could not be found, then |
| 44 | * nullptr is returned. |
| 45 | */ |
| 46 | static KTextEditor::View *findViewInDifferentSplitView(KTextEditor::MainWindow *window, KTextEditor::View *view); |
| 47 | |
| 48 | private: |
| 49 | void closeCurrentDocument(); |
| 50 | void closeDocuments(const QList<KTextEditor::Document *> &documents); |
| 51 | void closeCurrentView(); |
| 52 | void closeCurrentSplitView(); |
| 53 | void closeOtherSplitViews(); |
| 54 | void quit(); |
| 55 | |
| 56 | private: |
| 57 | const QRegularExpression re_write; |
| 58 | const QRegularExpression re_close; |
| 59 | const QRegularExpression re_quit; |
| 60 | const QRegularExpression re_exit; |
| 61 | const QRegularExpression re_edit; |
| 62 | const QRegularExpression re_tabedit; |
| 63 | const QRegularExpression re_new; |
| 64 | const QRegularExpression re_split; |
| 65 | const QRegularExpression re_vsplit; |
| 66 | const QRegularExpression re_vclose; |
| 67 | const QRegularExpression re_only; |
| 68 | }; |
| 69 | |
| 70 | class BufferCommands : public KTextEditor::Command |
| 71 | { |
| 72 | BufferCommands(); |
| 73 | static BufferCommands *m_instance; |
| 74 | |
| 75 | public: |
| 76 | ~BufferCommands() override; |
| 77 | bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range::invalid()) override; |
| 78 | bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override; |
| 79 | |
| 80 | static BufferCommands *self() |
| 81 | { |
| 82 | if (m_instance == nullptr) { |
| 83 | m_instance = new BufferCommands(); |
| 84 | } |
| 85 | return m_instance; |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | void switchDocument(KTextEditor::View *, const QString &doc); |
| 90 | void prevBuffer(KTextEditor::View *); |
| 91 | void nextBuffer(KTextEditor::View *); |
| 92 | void firstBuffer(KTextEditor::View *); |
| 93 | void lastBuffer(KTextEditor::View *); |
| 94 | void prevTab(KTextEditor::View *); |
| 95 | void nextTab(KTextEditor::View *); |
| 96 | void firstTab(KTextEditor::View *); |
| 97 | void lastTab(KTextEditor::View *); |
| 98 | |
| 99 | static void activateDocument(KTextEditor::View *, KTextEditor::Document *); |
| 100 | static QList<KTextEditor::Document *> documents(); |
| 101 | }; |
| 102 | } |
| 103 | |
| 104 | #endif /* KATEVI_APP_COMMANDS_H */ |
| 105 | |