void ExplorerTreeWidget::ui_editFunction()
{
    ExplorerFunctionTreeItem *functionItem = selectedFunctionItem();
    if (!functionItem)
        return;

    MongoFunction function= functionItem->function();
    MongoDatabase *database = functionItem->database();
    MongoServer *server = database->server();
    QString name = function.name();

    FunctionTextEditor dlg(server->connectionRecord()->getFullAddress(),
                         database->name(),
                         function);
    dlg.setWindowTitle("Edit Function");
    int result = dlg.exec();

    if (result == QDialog::Accepted) {

        MongoFunction editedFunction = dlg.function();
        database->updateFunction(name, editedFunction);

        // refresh list of functions
        database->loadFunctions();
    }
}
void ExplorerTreeWidget::ui_dropFunction()
{
    ExplorerFunctionTreeItem *functionItem = selectedFunctionItem();
    if (!functionItem)
        return;

    MongoFunction function = functionItem->function();
    MongoDatabase *database = functionItem->database();

    // Ask user
    int answer = QMessageBox::question(this,
            "Remove Function",
            QString("Remove <b>%1</b> function?").arg(function.name()),
            QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton);

    if (answer != QMessageBox::Yes)
        return;

    database->dropFunction(function.name());
    database->loadFunctions(); // refresh list of functions
}