• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • script
katescriptaction.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2010 Dominik Haumann <dhaumann kde org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "katescriptaction.h"
20 #include "katecommandlinescript.h"
21 #include "katescriptmanager.h"
22 #include "kateview.h"
23 #include "katedocument.h"
24 #include "kateglobal.h"
25 #include "kateviewhelpers.h"
26 #include "kactioncollection.h"
27 
28 #include <kxmlguifactory.h>
29 #include <kmenu.h>
30 #include <kdebug.h>
31 #include <klocale.h>
32 
33 //BEGIN KateScriptAction
34 KateScriptAction::KateScriptAction(const ScriptActionInfo& info, KateView* view)
35  : KAction(info.text(), view)
36  , m_view(view)
37  , m_command(info.command())
38  , m_interactive(info.interactive())
39 {
40  if (!info.icon().isEmpty()) {
41  setIcon(KIcon(info.icon()));
42  }
43 
44  if (!info.shortcut().isEmpty()) {
45  setShortcut(info.shortcut());
46  }
47 
48  connect(this, SIGNAL(triggered(bool)), this, SLOT(exec()));
49 }
50 
51 KateScriptAction::~KateScriptAction()
52 {
53 }
54 
55 void KateScriptAction::exec()
56 {
57  KateCommandLineBar* cmdLine = m_view->cmdLineBar();
58 
59  if (m_interactive) {
60  m_view->bottomViewBar()->showBarWidget(cmdLine);
61  cmdLine->setText(m_command + ' ', false);
62  } else {
63  cmdLine->execute(m_command);
64  }
65 }
66 //END KateScriptAction
67 
68 
69 //BEGIN KateScriptActionMenu
70 KateScriptActionMenu::KateScriptActionMenu(KateView *view, const QString& text)
71  : KActionMenu (KIcon("code-context"), text, view)
72  , m_view(view)
73 {
74  repopulate();
75 
76  // on script-reload signal, repopulate script menu
77  connect(KateGlobal::self()->scriptManager(), SIGNAL(reloaded()),
78  this, SLOT(repopulate()));
79 }
80 
81 KateScriptActionMenu::~KateScriptActionMenu()
82 {
83  cleanup();
84 }
85 
86 void KateScriptActionMenu::cleanup()
87 {
88  // delete menus and actions for real
89  qDeleteAll(m_menus);
90  m_menus.clear();
91 
92  qDeleteAll(m_actions);
93  m_actions.clear();
94 }
95 
96 void KateScriptActionMenu::repopulate()
97 {
98  // if the view is already hooked into the GUI, first remove it
99  // now and add it later, so that the changes we do here take effect
100  KXMLGUIFactory *viewFactory = m_view->factory();
101  if (viewFactory)
102  viewFactory->removeClient(m_view);
103 
104  // remove existing menu actions
105  cleanup();
106 
107  // now add all command line script commands
108  QVector<KateCommandLineScript*> scripts =
109  KateGlobal::self()->scriptManager()->commandLineScripts();
110 
111  QHash<QString, QMenu*> menus;
112 
113  foreach (KateCommandLineScript* script, scripts) {
114 
115  const QStringList &cmds = script->cmds();
116  foreach (const QString& cmd, cmds) {
117 
118  ScriptActionInfo info = script->actionInfo(cmd);
119  if (!info.isValid())
120  continue;
121 
122  QMenu* m = menu();
123 
124  // show in a category submenu?
125  if (!info.category().isEmpty()) {
126  m = menus[info.category()];
127  if (!m) {
128  m = menu()->addMenu(info.category());
129  menus.insert(info.category(), m);
130  m_menus.append(m);
131  }
132  }
133 
134  // create action + add to menu
135  KAction* a = new KateScriptAction(info, m_view);
136  m->addAction(a);
137  m_view->actionCollection()->addAction("tools_scripts_" + cmd, a);
138  m_actions.append(a);
139  }
140  }
141 
142  // finally add the view to the xml factory again, if it initially was there
143  if (viewFactory)
144  viewFactory->addClient(m_view);
145 }
146 
147 //END KateScriptActionMenu
148 
149 // kate: space-indent on; indent-width 2; replace-tabs on;
QList::clear
void clear()
kateview.h
QHash::insert
iterator insert(const Key &key, const T &value)
KateCommandLineScript::cmds
virtual const QStringList & cmds()
Definition: katecommandlinescript.cpp:107
KateScriptAction::~KateScriptAction
virtual ~KateScriptAction()
Definition: katescriptaction.cpp:51
KateView::bottomViewBar
KateViewBar * bottomViewBar() const
Definition: kateview.cpp:3008
KateCommandLineBar::setText
void setText(const QString &text, bool selected=true)
Definition: kateviewhelpers.cpp:839
QMenu::addAction
void addAction(QAction *action)
KateScriptActionMenu::KateScriptActionMenu
KateScriptActionMenu(KateView *view, const QString &text)
Definition: katescriptaction.cpp:70
katedocument.h
ScriptActionInfo::isValid
bool isValid() const
Definition: katecommandlinescript.h:52
ScriptActionInfo::shortcut
QString shortcut() const
Definition: katecommandlinescript.h:65
KateScriptAction::exec
void exec()
Definition: katescriptaction.cpp:55
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:465
KateCommandLineScript::actionInfo
ScriptActionInfo actionInfo(const QString &cmd)
Definition: katecommandlinescript.cpp:76
KateCommandLineScript
A specialized class for scripts that are of type KateScriptInformation::IndentationScript.
Definition: katecommandlinescript.h:80
kateviewhelpers.h
QList::append
void append(const T &value)
KateScriptActionMenu::~KateScriptActionMenu
~KateScriptActionMenu()
Definition: katescriptaction.cpp:81
QHash
KateScriptActionMenu::cleanup
void cleanup()
Definition: katescriptaction.cpp:86
kateglobal.h
katecommandlinescript.h
QString::isEmpty
bool isEmpty() const
KateView::cmdLineBar
KateCommandLineBar * cmdLineBar()
Definition: kateview.cpp:3013
QString
ScriptActionInfo::icon
QString icon() const
Definition: katecommandlinescript.h:59
KateScriptActionMenu::repopulate
void repopulate()
Definition: katescriptaction.cpp:96
QStringList
KateView
Definition: kateview.h:77
QMenu
KateCommandLineBar
Definition: kateviewhelpers.h:414
KActionMenu
KateScriptAction::KateScriptAction
KateScriptAction(const ScriptActionInfo &info, KateView *view)
Definition: katescriptaction.cpp:34
QVector< KateCommandLineScript * >
KateScriptManager::commandLineScripts
const QVector< KateCommandLineScript * > & commandLineScripts()
Get all scripts available in the command line.
Definition: katescriptmanager.h:54
KateViewBar::showBarWidget
void showBarWidget(KateViewBarWidget *barWidget)
Shows barWidget that was previously added with addBarWidget.
Definition: kateviewhelpers.cpp:2542
QMenu::addMenu
QAction * addMenu(QMenu *menu)
KAction
ScriptActionInfo::category
QString category() const
Definition: katecommandlinescript.h:61
katescriptaction.h
ScriptActionInfo
Definition: katecommandlinescript.h:47
katescriptmanager.h
KateScriptAction
KateScriptAction is an action that executes a commandline-script if triggered.
Definition: katescriptaction.h:33
KateCommandLineBar::execute
void execute(const QString &text)
Definition: kateviewhelpers.cpp:847
KateGlobal::scriptManager
KateScriptManager * scriptManager()
Global script collection.
Definition: kateglobal.h:321
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal