void KexiFormEventAction::slotTrigger()
{
    kDebug() << d->actionName << d->objectName;
    KexiProject* project = KexiMainWindowIface::global()->project();
    if (!project)
        return;
    KexiPart::Part* part = Kexi::partManager().partForClass(
                               QString("org.kexi-project.%1").arg(d->actionName));
    if (!part)
        return;
    KexiPart::Item* item = project->item(part->info(), d->objectName);
    if (!item)
        return;
    bool actionCancelled = false;
    if (d->actionOption.isEmpty()) { // backward compatibility (good defaults)
        if (part->info()->isExecuteSupported())
            part->execute(item, parent());
        else
            KexiMainWindowIface::global()->openObject(item, Kexi::DataViewMode, actionCancelled);
    } else {
//! @todo react on failure...
        if (d->actionOption == "open")
            KexiMainWindowIface::global()->openObject(item, Kexi::DataViewMode, actionCancelled);
        else if (d->actionOption == "execute")
            part->execute(item, parent());
        else if (d->actionOption == "print") {
            if (part->info()->isPrintingSupported())
                KexiMainWindowIface::global()->printItem(item);
        }
#ifndef KEXI_NO_QUICK_PRINTING
        else if (d->actionOption == "printPreview") {
            if (part->info()->isPrintingSupported())
                KexiMainWindowIface::global()->printPreviewForItem(item);
        }
        else if (d->actionOption == "pageSetup") {
            if (part->info()->isPrintingSupported())
                KexiMainWindowIface::global()->showPageSetupForItem(item);
        }
#endif
        else if (d->actionOption == "exportToCSV"
                   || d->actionOption == "copyToClipboardAsCSV") {
            if (part->info()->isDataExportSupported())
                KexiMainWindowIface::global()->executeCustomActionForObject(item, d->actionOption);
        } else if (d->actionOption == "new")
            KexiMainWindowIface::global()->newObject(part->info(), actionCancelled);
        else if (d->actionOption == "design")
            KexiMainWindowIface::global()->openObject(item, Kexi::DesignViewMode, actionCancelled);
        else if (d->actionOption == "editText")
            KexiMainWindowIface::global()->openObject(item, Kexi::TextViewMode, actionCancelled);
        else if (d->actionOption == "close") {
            tristate res = KexiMainWindowIface::global()->closeObject(item);
            if (~res)
                actionCancelled = true;
        }
    }
}
Exemplo n.º 2
0
    bool setupSchemaObject(KDbObject *object, KexiPart::Item *item,
                           KexiView::StoreNewDataOptions options) const
    {
        object->setName(item->name());
        object->setCaption(item->caption());
        object->setDescription(item->description());

        KexiProject *project = KexiMainWindowIface::global()->project();
        KexiPart::Item* existingItem = project->item(part->info(), object->name());
        if (existingItem && !(options & KexiView::OverwriteExistingData)) {
            KMessageBox::information(win,
                                     xi18n("Could not create new object.")
                                     + win->part()->i18nMessage("Object <resource>%1</resource> already exists.", win)
                                       .subs(object->name()).toString());
            return false;
        }
        return true;
    }