kexi
executeaction.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "executeaction.h"
00022
00023 #include <core/kexi.h>
00024 #include <core/kexiproject.h>
00025 #include <core/kexipartmanager.h>
00026 #include <core/kexipartinfo.h>
00027 #include <core/kexipart.h>
00028 #include <core/keximainwindow.h>
00029
00030 #include <klocale.h>
00031
00032 using namespace KexiMacro;
00033
00034 namespace KexiMacro {
00035 static const QString OBJECT = "object";
00036 static const QString NAME = "name";
00037 }
00038
00039 ExecuteAction::ExecuteAction()
00040 : KexiAction("execute", i18n("Execute"))
00041 {
00042 int conditions = ObjectVariable<ExecuteAction>::VisibleInNav | ObjectVariable<ExecuteAction>::Executable;
00043 KSharedPtr<KoMacro::Variable> objvar = new ObjectVariable<ExecuteAction>(this, conditions);
00044 setVariable(objvar);
00045
00046 setVariable(KSharedPtr<KoMacro::Variable>( new ObjectNameVariable<ExecuteAction>(this, objvar->variant().toString()) ));
00047 }
00048
00049 ExecuteAction::~ExecuteAction()
00050 {
00051 }
00052
00053 bool ExecuteAction::notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name)
00054 {
00055 kdDebug()<<"ExecuteAction::notifyUpdated() name="<<name<<" macroitem.action="<<(macroitem->action() ? macroitem->action()->name() : "NOACTION")<<endl;
00056 KSharedPtr<KoMacro::Variable> variable = macroitem->variable(name, false);
00057 if(! variable) {
00058 kdWarning()<<"ExecuteAction::notifyUpdated() No such variable="<<name<<" in macroitem."<<endl;
00059 return false;
00060 }
00061
00062 variable->clearChildren();
00063 if(name == OBJECT) {
00064 const QString objectvalue = macroitem->variant(OBJECT, true).toString();
00065 const QString objectname = macroitem->variant(NAME, true).toString();
00066 macroitem->variable(NAME, true)->setChildren(
00067 KoMacro::Variable::List() << KSharedPtr<KoMacro::Variable>(new ObjectNameVariable<ExecuteAction>(this, objectvalue, objectname)) );
00068 }
00069
00070 return true;
00071 }
00072
00073 void ExecuteAction::activate(KSharedPtr<KoMacro::Context> context)
00074 {
00075 if(! mainWin()->project()) {
00076 kdWarning() << "ExecuteAction::activate(KSharedPtr<KoMacro::Context>) Invalid project" << endl;
00077 return;
00078 }
00079
00080 const QString mimetype = QString("kexi/%1").arg( context->variable("object")->variant().toString() );
00081 const QString name = context->variable("name")->variant().toString();
00082
00083 KexiPart::Part* part = Kexi::partManager().partForMimeType(mimetype);
00084 if(! part) {
00085 throw KoMacro::Exception(i18n("No such mimetype \"%1\"").arg(mimetype));
00086 }
00087
00088 KexiPart::Item* item = mainWin()->project()->item(part->info(), name);
00089 if(! item) {
00090 throw KoMacro::Exception(i18n("Failed to open part \"%1\" for mimetype \"%2\"").arg(name).arg(mimetype));
00091 }
00092
00093 part->execute(item);
00094 }
00095
00096
|