kspread

scripting.cpp
1/*
2 * This file is part of the KSpread project
3 *
4 * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
5 * Copyright (c) 2006 Isaac Clerencia <isaac@warp.es>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21#include "scripting.h"
22
23#include <tqapplication.h>
24
25#include <kdebug.h>
26#include <kgenericfactory.h>
27#include <kstandarddirs.h>
28
29#define KROSS_MAIN_EXPORT TDE_EXPORT
30#include <main/manager.h>
31#include <main/scriptguiclient.h>
32#include <main/wdgscriptsmanager.h>
33
34#include <kspread_doc.h>
35#include <kspread_view.h>
36
37typedef KGenericFactory<Scripting> KSpreadScriptingFactory;
38K_EXPORT_COMPONENT_FACTORY( kspreadscripting, KSpreadScriptingFactory( "kspreadscripting" ) )
39
40Scripting::Scripting(TQObject *parent, const char *name, const TQStringList &)
41 : KParts::Plugin(parent, name)
42{
43 setInstance(KSpreadScriptingFactory::instance());
44
45 kdDebug() << "Scripting plugin. Class: "
46 << metaObject()->className()
47 << ", Parent: "
48 << parent->metaObject()->className()
49 << "\n";
50
51 if ( parent->inherits("KSpread::View") )
52 {
53 setInstance(Scripting::instance());
54 m_view = (KSpread::View*) parent;
55 m_scriptguiclient = new Kross::Api::ScriptGUIClient( m_view, m_view );
56// m_scriptguiclient ->setXMLFile(locate("data","kspreadplugins/scripting.rc"), true);
57 kdDebug() << "Setup actions for scripting !" << endl;
58
59 setXMLFile(locate("data","kspread/kpartplugins/scripting.rc"), true);
60
61 new TDEAction(i18n("Execute Script File..."), 0, 0, m_scriptguiclient, TQ_SLOT(executeScriptFile()), actionCollection(), "executescriptfile");
62 new TDEAction(i18n("Script Manager..."), 0, 0, m_scriptguiclient, TQ_SLOT(showScriptManager()), actionCollection(), "configurescripts");
63
64 TDEAction* scriptmenuaction = m_scriptguiclient->action("installedscripts");
65 actionCollection()->insert(scriptmenuaction);
66
67 connect(m_scriptguiclient, TQ_SIGNAL(executionFinished( const Kross::Api::ScriptAction* )), this, TQ_SLOT(executionFinished(const Kross::Api::ScriptAction*)));
68
69 Kross::Api::Manager::scriptManager()->addTQObject(m_view->doc(), "KSpreadDocument");
70 Kross::Api::Manager::scriptManager()->addTQObject(m_view, "KSpreadView");
71 }
72
73}
74
75Scripting::~Scripting()
76{
77}
78
79void Scripting::executionFinished(const Kross::Api::ScriptAction*)
80{
81 TQApplication::restoreOverrideCursor();
82}
83
84#include "scripting.moc"
The View class displays a KSpread document.