Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/scripting/kexiscripting/kexiscripteditor.cpp
Show All 16 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License | ||
18 | along with this program; see the file COPYING. If not, write to | 18 | along with this program; see the file COPYING. If not, write to | ||
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
20 | * Boston, MA 02110-1301, USA. | 20 | * Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "kexiscripteditor.h" | 23 | #include "kexiscripteditor.h" | ||
24 | 24 | | |||
25 | #include <Kross/Action> | | |||
26 | | ||||
27 | /// \internal d-pointer class | 25 | /// \internal d-pointer class | ||
28 | class Q_DECL_HIDDEN KexiScriptEditor::Private | 26 | class Q_DECL_HIDDEN KexiScriptEditor::Private | ||
29 | { | 27 | { | ||
30 | public: | 28 | public: | ||
31 | Kross::Action* scriptaction; | 29 | QString scriptaction; | ||
32 | Private() : scriptaction(0) {} | 30 | Private() {} | ||
staniek: not needed `;` | |||||
33 | }; | 31 | }; | ||
34 | 32 | | |||
35 | KexiScriptEditor::KexiScriptEditor(QWidget *parent) | 33 | KexiScriptEditor::KexiScriptEditor(QWidget *parent) | ||
36 | : KexiEditor(parent) | 34 | : KexiEditor(parent) | ||
37 | , d(new Private()) | 35 | , d(new Private()) | ||
38 | { | 36 | { | ||
39 | } | 37 | } | ||
40 | 38 | | |||
41 | KexiScriptEditor::~KexiScriptEditor() | 39 | KexiScriptEditor::~KexiScriptEditor() | ||
42 | { | 40 | { | ||
43 | delete d; | 41 | delete d; | ||
44 | } | 42 | } | ||
45 | 43 | | |||
46 | bool KexiScriptEditor::isInitialized() const | 44 | bool KexiScriptEditor::isInitialized() const | ||
47 | { | 45 | { | ||
48 | return d->scriptaction != 0; | 46 | return !d->scriptaction.isEmpty(); | ||
staniek: isEmpty() is safer | |||||
49 | } | 47 | } | ||
50 | 48 | | |||
51 | void KexiScriptEditor::initialize(Kross::Action* scriptaction) | 49 | void KexiScriptEditor::initialize(const QString &scriptaction) | ||
52 | { | 50 | { | ||
53 | d->scriptaction = scriptaction; | 51 | d->scriptaction = scriptaction; | ||
54 | Q_ASSERT(d->scriptaction); | | |||
55 | 52 | | |||
56 | disconnect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged())); | 53 | disconnect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged())); | ||
57 | 54 | | |||
58 | QString code = d->scriptaction->code(); | 55 | if (d->scriptaction.isEmpty()) { | ||
59 | if (code.isEmpty()) { | | |||
60 | // If there is no code we just add some information. | 56 | // If there is no code we just add some information. | ||
61 | ///@todo remove after release | 57 | ///@todo remove after release | ||
62 | #if 0 | 58 | #if 0 | ||
63 | code = "# " + QStringList::split("\n", futureI18n( | 59 | code = "# " + QStringList::split("\n", futureI18n( | ||
64 | "This note will appear for a user in the script's source code " | 60 | "This note will appear for a user in the script's source code " | ||
65 | "as a comment. Keep every row not longer than 60 characters and use '\n.'", | 61 | "as a comment. Keep every row not longer than 60 characters and use '\n.'", | ||
66 | 62 | | |||
67 | "This is Technology Preview (BETA) version of scripting\n" | 63 | "This is Technology Preview (BETA) version of scripting\n" | ||
68 | "support in Kexi. The scripting API may change in details\n" | 64 | "support in Kexi. The scripting API may change in details\n" | ||
69 | "in the next Kexi version.\n" | 65 | "in the next Kexi version.\n" | ||
70 | "For more information and documentation see\n%1", | 66 | "For more information and documentation see\n%1", | ||
71 | "http://www.kexi-project.org/scripting/"), true).join("\n# ") + "\n"; | 67 | "http://www.kexi-project.org/scripting/"), true).join("\n# ") + "\n"; | ||
72 | #endif | 68 | #endif | ||
73 | } | 69 | } | ||
74 | KexiEditor::setText(code); | 70 | KexiEditor::setText(d->scriptaction); | ||
75 | // We assume Kross and the HighlightingInterface are using same | 71 | // We assume Kross and the HighlightingInterface are using same | ||
76 | // names for the support languages... | 72 | // names for the support languages... | ||
77 | setHighlightMode(d->scriptaction->interpreter()); | 73 | setHighlightMode("javascript"); | ||
78 | 74 | | |||
79 | clearUndoRedo(); | 75 | clearUndoRedo(); | ||
80 | KexiEditor::setDirty(false); | 76 | KexiEditor::setDirty(false); | ||
81 | connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged())); | 77 | connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged())); | ||
82 | } | 78 | } | ||
83 | 79 | | |||
84 | void KexiScriptEditor::slotTextChanged() | 80 | void KexiScriptEditor::slotTextChanged() | ||
85 | { | 81 | { | ||
86 | KexiEditor::setDirty(true); | 82 | KexiEditor::setDirty(true); | ||
87 | if (d->scriptaction) { | 83 | d->scriptaction = KexiEditor::text(); | ||
staniek: KexiEditor::text() is already QString() | |||||
88 | d->scriptaction->setCode(KexiEditor::text().toUtf8()); | | |||
89 | } | | |||
90 | } | 84 | } | ||
91 | 85 | | |||
92 | void KexiScriptEditor::setLineNo(long lineno) | 86 | void KexiScriptEditor::setLineNo(long lineno) | ||
93 | { | 87 | { | ||
94 | setCursorPosition(lineno, 0); | 88 | setCursorPosition(lineno, 0); | ||
95 | } | 89 | } | ||
96 | 90 | | |||
97 | 91 | |
not needed ;