Changeset View
Changeset View
Standalone View
Standalone View
addons/externaltools/katemacroexpander.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright 2019 Dominik Haumann <dhaumann@kde.org> | ||||
4 | * | ||||
5 | * This library is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Library General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 2 of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This library is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | * Library General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Library General Public License | ||||
16 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | * Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | #include "katemacroexpander.h" | ||||
21 | | ||||
22 | #include <KTextEditor/Editor> | ||||
23 | #include <KTextEditor/Application> | ||||
24 | #include <KTextEditor/Document> | ||||
25 | #include <KTextEditor/View> | ||||
26 | | ||||
27 | MacroExpander::MacroExpander(KTextEditor::View * view) | ||||
28 | : KWordMacroExpander() | ||||
29 | , m_view(view) | ||||
30 | { | ||||
31 | } | ||||
32 | | ||||
33 | bool MacroExpander::expandMacro(const QString& str, QStringList& ret) | ||||
34 | { | ||||
35 | KTextEditor::View* view = m_view; | ||||
36 | if (!view) | ||||
37 | return false; | ||||
38 | | ||||
39 | KTextEditor::Document* doc = view->document(); | ||||
40 | QUrl url = doc->url(); | ||||
41 | | ||||
42 | if (str == QStringLiteral("URL")) | ||||
43 | ret += url.url(); | ||||
44 | else if (str == QStringLiteral("directory")) // directory of current doc | ||||
45 | ret += url.toString(QUrl::RemoveScheme | QUrl::RemoveFilename); | ||||
46 | else if (str == QStringLiteral("filename")) | ||||
47 | ret += url.fileName(); | ||||
48 | else if (str == QStringLiteral("line")) // cursor line of current doc | ||||
49 | ret += QString::number(view->cursorPosition().line()); | ||||
50 | else if (str == QStringLiteral("col")) // cursor col of current doc | ||||
51 | ret += QString::number(view->cursorPosition().column()); | ||||
52 | else if (str == QStringLiteral("selection")) // selection of current doc if any | ||||
53 | ret += view->selectionText(); | ||||
54 | else if (str == QStringLiteral("text")) // text of current doc | ||||
55 | ret += doc->text(); | ||||
56 | else if (str == QStringLiteral("URLs")) { | ||||
57 | foreach (KTextEditor::Document* it, KTextEditor::Editor::instance()->application()->documents()) | ||||
58 | if (!it->url().isEmpty()) | ||||
59 | ret += it->url().url(); | ||||
60 | } else | ||||
61 | return false; | ||||
62 | | ||||
63 | return true; | ||||
64 | } | ||||
65 | | ||||
66 | // kate: space-indent on; indent-width 4; replace-tabs on; |