diff --git a/src/robomongo/core/Enums.h b/src/robomongo/core/Enums.h index 7b79e1571..96cbd0615 100644 --- a/src/robomongo/core/Enums.h +++ b/src/robomongo/core/Enums.h @@ -24,6 +24,13 @@ namespace Robomongo Custom = 3 }; + enum EditWindowMode + { + Modal = 0, + Modeless = 1, + Tabbed = 2 + }; + enum AutocompletionMode { AutocompleteNone = 0, diff --git a/src/robomongo/core/domain/Notifier.cpp b/src/robomongo/core/domain/Notifier.cpp index e5dab4d6a..590495660 100644 --- a/src/robomongo/core/domain/Notifier.cpp +++ b/src/robomongo/core/domain/Notifier.cpp @@ -20,6 +20,7 @@ #include "robomongo/gui/utils/DialogUtils.h" #include "robomongo/gui/GuiRegistry.h" #include "robomongo/core/EventBus.h" +#include "robomongo/core/domain/App.h" namespace Robomongo { @@ -284,14 +285,33 @@ namespace Robomongo const QString &json = QtUtils::toQString(str); - DocumentTextEditor editor(_queryInfo._info, - json, false, dynamic_cast(_observer)); + EditWindowMode editWindowMode = AppRegistry::instance().settingsManager()->editWindowMode(); + if(editWindowMode != Tabbed) { + DocumentTextEditor *editor = new DocumentTextEditor(_queryInfo._info, json); - editor.setWindowTitle("Edit Document"); - int result = editor.exec(); + editor->setWindowTitle("Edit Document"); + switch(editWindowMode) + { + case Modal: + { + int result = editor->exec(); - if (result == QDialog::Accepted) { - _shell->server()->saveDocuments(editor.bsonObj(), _queryInfo._info._ns); + if (result == QDialog::Accepted) { + _shell->server()->saveDocuments(editor->bsonObj(), _queryInfo._info._ns); + } + } + break; + case Modeless: + VERIFY(connect(editor, SIGNAL(accepted()), SLOT(documentTextEditorEditAccepted()))); + editor->show(); + break; + } + } else { + // Show in a tabbed window + openCurrentCollectionShell( + "save(\n" + + json + + ");", false); } } @@ -325,22 +345,49 @@ namespace Robomongo if (!_queryInfo._info.isValid()) return; - DocumentTextEditor editor(_queryInfo._info, - "{\n \n}", false, dynamic_cast(_observer)); + EditWindowMode editWindowMode = AppRegistry::instance().settingsManager()->editWindowMode(); - editor.setCursorPosition(1, 4); - editor.setWindowTitle("Insert Document"); + if(editWindowMode != Tabbed) { + DocumentTextEditor *editor = new DocumentTextEditor(_queryInfo._info, "{\n \n}"); - int result = editor.exec(); - if (result != QDialog::Accepted) - return; + editor->setCursorPosition(1, 4); + editor->setWindowTitle("Insert Document"); - DocumentTextEditor::ReturnType obj = editor.bsonObj(); - for (DocumentTextEditor::ReturnType::const_iterator it = obj.begin(); it != obj.end(); ++it) { - _shell->server()->insertDocument(*it, _queryInfo._info._ns); - } + switch(editWindowMode) + { + case Modal: + { + int result = editor->exec(); + if (result != QDialog::Accepted) + return; - _shell->query(0, _queryInfo); + DocumentTextEditor::ReturnType obj = editor->bsonObj(); + for (DocumentTextEditor::ReturnType::const_iterator it = obj.begin(); it != obj.end(); ++it) { + _shell->server()->insertDocument(*it, _queryInfo._info._ns); + } + + _shell->query(0, _queryInfo); + } + break; + case Modeless: + VERIFY(connect(editor, SIGNAL(accepted()), SLOT(documentTextEditorInsertAccepted()))); + editor->show(); + break; + } + } else { + // Show in a tabbed window + openCurrentCollectionShell( + "insertMany(\n" + " [\n" + " {\n" + " \"key\" : \"value\"\n" + " }\n" + " ],\n" + " {\n" + " ordered: true\n" + " }\n" + ");", false); + } } void Notifier::onCopyDocument() @@ -422,4 +469,27 @@ namespace Robomongo const QString &json = QtUtils::toQString(str); clipboard->setText(json); } + + void Notifier::documentTextEditorInsertAccepted() + { + DocumentTextEditor *editor = (DocumentTextEditor*)QObject::sender(); + DocumentTextEditor::ReturnType obj = editor->bsonObj(); + for (DocumentTextEditor::ReturnType::const_iterator it = obj.begin(); it != obj.end(); ++it) { + _shell->server()->insertDocument(*it, _queryInfo._info._ns); + } + + _shell->query(0, _queryInfo); + } + + void Notifier::openCurrentCollectionShell(const QString &script, bool execute, const CursorPosition &cursor) + { + QString query = detail::buildCollectionQuery(_queryInfo._info._ns.collectionName(), script); + AppRegistry::instance().app()->openShell(_shell->server(), query, _queryInfo._info._ns.databaseName(), execute, QtUtils::toQString(_queryInfo._info._ns.collectionName()), cursor); + } + + void Notifier::documentTextEditorEditAccepted() + { + DocumentTextEditor *editor = (DocumentTextEditor*)QObject::sender(); + _shell->server()->saveDocuments(editor->bsonObj(), _queryInfo._info._ns); + } } diff --git a/src/robomongo/core/domain/Notifier.h b/src/robomongo/core/domain/Notifier.h index 669ce2376..99dade022 100644 --- a/src/robomongo/core/domain/Notifier.h +++ b/src/robomongo/core/domain/Notifier.h @@ -3,6 +3,7 @@ #include #include "robomongo/core/domain/MongoQueryInfo.h" +#include "robomongo/core/domain/CursorPosition.h" QT_BEGIN_NAMESPACE class QAction; @@ -59,6 +60,8 @@ namespace Robomongo void onCopyJson(); void handle(InsertDocumentResponse *event); void handle(RemoveDocumentResponse *event); + void documentTextEditorInsertAccepted(); + void documentTextEditorEditAccepted(); private: QAction *_deleteDocumentAction; @@ -73,5 +76,7 @@ namespace Robomongo MongoShell *_shell; INotifierObserver *const _observer; + + void openCurrentCollectionShell(const QString &script, bool execute = true, const CursorPosition &cursor = CursorPosition()); }; } diff --git a/src/robomongo/core/settings/SettingsManager.cpp b/src/robomongo/core/settings/SettingsManager.cpp index a68b758c9..21c39f9c0 100644 --- a/src/robomongo/core/settings/SettingsManager.cpp +++ b/src/robomongo/core/settings/SettingsManager.cpp @@ -46,6 +46,7 @@ namespace Robomongo _uuidEncoding(DefaultEncoding), _timeZone(Utc), _viewMode(Robomongo::Tree), + _editWindowMode(Robomongo::Modal), _autocompletionMode(AutocompleteAll), _batchSize(50), _disableConnectionShortcuts(false), @@ -145,6 +146,14 @@ namespace Robomongo _viewMode = Custom; // Default View Mode } + // 4. Load edit window mode + if (map.contains("editWindowMode")) { + int editWindowMode = map.value("editWindowMode").toInt(); + _editWindowMode = (EditWindowMode) editWindowMode; + } else { + _editWindowMode = Modal; // Default Edit Window Mode + } + _autoExpand = map.contains("autoExpand") ? map.value("autoExpand").toBool() : true; @@ -250,28 +259,31 @@ namespace Robomongo map.insert("autoExpand", _autoExpand); map.insert("lineNumbers", _lineNumbers); - // 5. Save Autocompletion mode + // 5 Save edit window mode + map.insert("editWindowMode", _editWindowMode); + + // 6. Save Autocompletion mode map.insert("autocompletionMode", _autocompletionMode); - // 6. Save loadInitJs + // 7. Save loadInitJs map.insert("loadMongoRcJs", _loadMongoRcJs); - // 7. Save disableConnectionShortcuts + // 8. Save disableConnectionShortcuts map.insert("disableConnectionShortcuts", _disableConnectionShortcuts); - // 8. Save batchSize + // 9. Save batchSize map.insert("batchSize", _batchSize); map.insert("mongoTimeoutSec", _mongoTimeoutSec); map.insert("shellTimeoutSec", _shellTimeoutSec); - // 9. Save style + // 10. Save style map.insert("style", _currentStyle); - // 10. Save font information + // 11. Save font information map.insert("textFontFamily", _textFontFamily); map.insert("textFontPointSize", _textFontPointSize); - // 11. Save connections + // 12. Save connections QVariantList list; for (ConnectionSettingsContainerType::const_iterator it = _connections.begin(); it != _connections.end(); ++it) { diff --git a/src/robomongo/core/settings/SettingsManager.h b/src/robomongo/core/settings/SettingsManager.h index 32f002802..c3479b498 100644 --- a/src/robomongo/core/settings/SettingsManager.h +++ b/src/robomongo/core/settings/SettingsManager.h @@ -77,6 +77,9 @@ namespace Robomongo void setViewMode(ViewMode viewMode) { _viewMode = viewMode; } ViewMode viewMode() const { return _viewMode; } + void setEditWindowMode(EditWindowMode editWindowMode) { _editWindowMode = editWindowMode; } + EditWindowMode editWindowMode() const { return _editWindowMode; } + void setAutocompletionMode(AutocompletionMode mode) { _autocompletionMode = mode; } AutocompletionMode autocompletionMode() const { return _autocompletionMode; } @@ -144,6 +147,7 @@ namespace Robomongo UUIDEncoding _uuidEncoding; SupportedTimes _timeZone; ViewMode _viewMode; + EditWindowMode _editWindowMode; AutocompletionMode _autocompletionMode; bool _loadMongoRcJs; bool _autoExpand; diff --git a/src/robomongo/gui/MainWindow.cpp b/src/robomongo/gui/MainWindow.cpp index 1a6cee3cc..3249ec5e2 100644 --- a/src/robomongo/gui/MainWindow.cpp +++ b/src/robomongo/gui/MainWindow.cpp @@ -55,6 +55,12 @@ namespace Robomongo::AppRegistry::instance().settingsManager()->setViewMode(mode); Robomongo::AppRegistry::instance().settingsManager()->save(); } + + void saveEditWindowMode(Robomongo::EditWindowMode mode) + { + Robomongo::AppRegistry::instance().settingsManager()->setEditWindowMode(mode); + Robomongo::AppRegistry::instance().settingsManager()->save(); + } void saveAutoExpand(bool isExpand) { @@ -212,6 +218,30 @@ namespace Robomongo customModeAction->setChecked(viewMode == Custom); VERIFY(connect(customModeAction, SIGNAL(triggered()), this, SLOT(enterCustomMode()))); + // read edit window mode setting + EditWindowMode editWindowMode = AppRegistry::instance().settingsManager()->editWindowMode(); + + // Modal Window Action + QAction *modalWindowAction = new QAction("&Modal Window", this); + modalWindowAction->setToolTip("Show document edit in a modal window"); + modalWindowAction->setCheckable(true); + modalWindowAction->setChecked(editWindowMode == Modal); + VERIFY(connect(modalWindowAction, SIGNAL(triggered()), this, SLOT(setModalWindowMode()))); + + // Modeless Window Action + QAction *modelessWindowAction = new QAction("&Modeless Window", this); + modelessWindowAction->setToolTip("Show document edit in a modeless window"); + modelessWindowAction->setCheckable(true); + modelessWindowAction->setChecked(editWindowMode == Modeless); + VERIFY(connect(modelessWindowAction, SIGNAL(triggered()), this, SLOT(setModelessWindowMode()))); + + // Tabbed Window Action + QAction *tabbedWindowAction = new QAction("&Tabbed Window", this); + tabbedWindowAction->setToolTip("Show document edit in a tabbed window"); + tabbedWindowAction->setCheckable(true); + tabbedWindowAction->setChecked(editWindowMode == Tabbed); + VERIFY(connect(tabbedWindowAction, SIGNAL(triggered()), this, SLOT(setTabbedWindowMode()))); + // Execute action _executeAction = new QAction(this); _executeAction->setData("Execute"); @@ -265,8 +295,6 @@ namespace Robomongo defaultViewModeMenu->addAction(treeModeAction); defaultViewModeMenu->addAction(tableModeAction); defaultViewModeMenu->addAction(textModeAction); - - optionsMenu->addSeparator(); QActionGroup *modeGroup = new QActionGroup(this); modeGroup->addAction(textModeAction); @@ -274,6 +302,19 @@ namespace Robomongo modeGroup->addAction(tableModeAction); modeGroup->addAction(customModeAction); + // Edit window mode + QMenu *defaultEditWindowModeMenu = optionsMenu->addMenu("Edit Window Mode"); + defaultEditWindowModeMenu->addAction(modalWindowAction); + defaultEditWindowModeMenu->addAction(modelessWindowAction); + defaultEditWindowModeMenu->addAction(tabbedWindowAction); + + QActionGroup *editWindowModeGroup = new QActionGroup(this); + editWindowModeGroup->addAction(modalWindowAction); + editWindowModeGroup->addAction(modelessWindowAction); + editWindowModeGroup->addAction(tabbedWindowAction); + + optionsMenu->addSeparator(); + // Time Zone QAction *utcTime = new QAction(convertTimesToString(Utc), this); utcTime->setCheckable(true); @@ -760,6 +801,21 @@ namespace Robomongo widget->enterCustomMode(); } + void MainWindow::setModalWindowMode() + { + saveEditWindowMode(Modal); + } + + void MainWindow::setModelessWindowMode() + { + saveEditWindowMode(Modeless); + } + + void MainWindow::setTabbedWindowMode() + { + saveEditWindowMode(Tabbed); + } + void MainWindow::toggleAutoExpand() { QAction *send = qobject_cast(sender()); diff --git a/src/robomongo/gui/MainWindow.h b/src/robomongo/gui/MainWindow.h index 96c33496f..ccabbea73 100644 --- a/src/robomongo/gui/MainWindow.h +++ b/src/robomongo/gui/MainWindow.h @@ -36,6 +36,9 @@ namespace Robomongo void enterTreeMode(); void enterTableMode(); void enterCustomMode(); + void setModalWindowMode(); + void setModelessWindowMode(); + void setTabbedWindowMode(); void toggleAutoExpand(); void toggleAutoExec(); void toggleLineNumbers(); diff --git a/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.cpp b/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.cpp index a485941da..8b5ba5f1a 100644 --- a/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.cpp +++ b/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.cpp @@ -16,6 +16,7 @@ #include "robomongo/core/domain/MongoServer.h" #include "robomongo/core/domain/App.h" #include "robomongo/core/utils/QtUtils.h" +#include "robomongo/core/settings/SettingsManager.h" #include "robomongo/core/AppRegistry.h" #include "robomongo/core/EventBus.h" @@ -362,16 +363,46 @@ namespace Robomongo MongoServer *server = database->server(); ConnectionSettings *settings = server->connectionRecord(); - DocumentTextEditor editor(CollectionInfo(settings->getFullAddress(), database->name(), _collection->name()), "{\n \n}"); + EditWindowMode editWindowMode = AppRegistry::instance().settingsManager()->editWindowMode(); - editor.setCursorPosition(1, 4); - editor.setWindowTitle("Insert Document"); - int result = editor.exec(); + if(editWindowMode != Tabbed) { + DocumentTextEditor *editor = new DocumentTextEditor(CollectionInfo(settings->getFullAddress(), database->name(), _collection->name()), "{\n \n}"); - treeWidget()->activateWindow(); + editor->setCursorPosition(1, 4); + editor->setWindowTitle("Insert Document"); - if (result == QDialog::Accepted) { - server->insertDocuments(editor.bsonObj(), MongoNamespace(database->name(), _collection->name()) ); + switch(editWindowMode) + { + case Modal: + { + int result = editor->exec(); + + treeWidget()->activateWindow(); + + if (result == QDialog::Accepted) { + server->insertDocuments(editor->bsonObj(), MongoNamespace(database->name(), _collection->name()) ); + } + } + break; + + case Modeless: + VERIFY(connect(editor, SIGNAL(accepted()), SLOT(documentTextEditorAccepted()))); + editor->show(); + break; + } + } else { + // Show in a tabbed window + openCurrentCollectionShell( + "insertMany(\n" + " [\n" + " {\n" + " \"key\" : \"value\"\n" + " }\n" + " ],\n" + " {\n" + " ordered: true\n" + " }\n" + ");", false); } } @@ -535,4 +566,14 @@ namespace Robomongo QString query = detail::buildCollectionQuery(_collection->name(), script); AppRegistry::instance().app()->openShell(_collection->database(), query, execute, QtUtils::toQString(_collection->name()), cursor); } + + void ExplorerCollectionTreeItem::documentTextEditorAccepted() + { + MongoDatabase *database = _collection->database(); + MongoServer *server = database->server(); + ConnectionSettings *settings = server->connectionRecord(); + + DocumentTextEditor *editor = (DocumentTextEditor*)QObject::sender(); + server->insertDocuments(editor->bsonObj(), MongoNamespace(database->name(), _collection->name()) ); + } } diff --git a/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.h b/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.h index de34ef7c6..a159e9c19 100644 --- a/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.h +++ b/src/robomongo/gui/widgets/explorer/ExplorerCollectionTreeItem.h @@ -52,6 +52,7 @@ namespace Robomongo void ui_duplicateCollection(); void ui_copyToCollectionToDiffrentServer(); void ui_viewCollection(); + void documentTextEditorAccepted(); private: QString buildToolTip(MongoCollection *collection); diff --git a/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.cpp b/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.cpp index 170a23ce2..b721650da 100644 --- a/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.cpp +++ b/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.cpp @@ -10,6 +10,7 @@ #include "robomongo/gui/dialogs/CreateDatabaseDialog.h" #include "robomongo/core/settings/ConnectionSettings.h" +#include "robomongo/core/settings/SettingsManager.h" #include "robomongo/core/domain/MongoServer.h" #include "robomongo/core/domain/MongoDatabase.h" #include "robomongo/core/domain/App.h" @@ -204,21 +205,88 @@ namespace Robomongo if (!databaseItem) return; - FunctionTextEditor dlg(QtUtils::toQString(databaseItem->database()->server()->connectionRecord()->getFullAddress()), QtUtils::toQString(databaseItem->database()->name()), MongoFunction()); - dlg.setWindowTitle("Create Function"); - dlg.setCode( - "function() {\n" - " // write your code here\n" - "}"); - dlg.setCursorPosition(1, 4); - int result = dlg.exec(); - if (result != QDialog::Accepted) + EditWindowMode editWindowMode = AppRegistry::instance().settingsManager()->editWindowMode(); + if(editWindowMode != Tabbed) { + FunctionTextEditor *dlg = new FunctionTextEditor(QtUtils::toQString(databaseItem->database()->server()->connectionRecord()->getFullAddress()), QtUtils::toQString(databaseItem->database()->name()), MongoFunction()); + dlg->setWindowTitle("Create Function"); + dlg->setCode( + "function() {\n" + " // write your code here\n" + "}"); + dlg->setCursorPosition(1, 4); + + switch(editWindowMode) + { + case Modal: + { + int result = dlg->exec(); + if (result != QDialog::Accepted) + return; + + MongoFunction function = dlg->function(); + databaseItem->database()->createFunction(function); + // refresh list of functions + databaseItem->expandFunctions(); + } + break; + case Modeless: + VERIFY(connect(dlg, SIGNAL(accepted()), SLOT(functionTextEditorAddAccepted()))); + dlg->show(); + break; + } + } else { + openCurrentCollectionShell("{\n" + " _id: \"function_name\",\n" + " value : function() {\n" + " // write your code here\n" + " }\n" + "}", + "New Function", false); + } + } + + void ExplorerDatabaseCategoryTreeItem::ui_editFunction(const MongoFunction &function) + { + ExplorerDatabaseTreeItem *databaseItem = ExplorerDatabaseCategoryTreeItem::databaseItem(); + if (!databaseItem) return; - MongoFunction function = dlg.function(); - databaseItem->database()->createFunction(function); - // refresh list of functions - databaseItem->expandFunctions(); + std::string name = function.name(); + + EditWindowMode editWindowMode = AppRegistry::instance().settingsManager()->editWindowMode(); + if(editWindowMode != Tabbed) { + FunctionTextEditor *dlg = new FunctionTextEditor(QtUtils::toQString(databaseItem->database()->server()->connectionRecord()->getFullAddress()), + QtUtils::toQString(databaseItem->database()->name()), + function); + dlg->setWindowTitle("Edit Function"); + switch(editWindowMode) + { + case Modal: + { + int result = dlg->exec(); + + if (result == QDialog::Accepted) { + + MongoFunction editedFunction = dlg->function(); + databaseItem->database()->updateFunction(name, editedFunction); + + // refresh list of functions + databaseItem->database()->loadFunctions(); + } + } + break; + case Modeless: + VERIFY(connect(dlg, SIGNAL(accepted()), SLOT(functionTextEditorEditAccepted()))); + dlg->show(); + break; + } + } else { + openCurrentCollectionShell(QtUtils::toQString("{\n" + " _id: \""+name+"\",\n" + " value : " + function.code() + "" + "}"), + "Edit function", false); + } } void ExplorerDatabaseCategoryTreeItem::ui_refreshCollections() @@ -228,4 +296,38 @@ namespace Robomongo databaseItem->expandCollections(); } } + + void ExplorerDatabaseCategoryTreeItem::functionTextEditorAddAccepted() + { + ExplorerDatabaseTreeItem *databaseItem = ExplorerDatabaseCategoryTreeItem::databaseItem(); + if (!databaseItem) + return; + FunctionTextEditor *dlg = (FunctionTextEditor*)QObject::sender(); + MongoFunction function = dlg->function(); + databaseItem->database()->createFunction(function); + // refresh list of functions + databaseItem->expandFunctions(); + } + + void ExplorerDatabaseCategoryTreeItem::functionTextEditorEditAccepted() + { + ExplorerDatabaseTreeItem *databaseItem = ExplorerDatabaseCategoryTreeItem::databaseItem(); + if (!databaseItem) + return; + FunctionTextEditor *dlg = (FunctionTextEditor*)QObject::sender(); + MongoFunction editedFunction = dlg->function(); + databaseItem->database()->updateFunction(editedFunction.name(), editedFunction); + + // refresh list of functions + databaseItem->database()->loadFunctions(); + } + + void ExplorerDatabaseCategoryTreeItem::openCurrentCollectionShell(const QString &script, const QString &title, bool execute, const CursorPosition &cursor) + { + ExplorerDatabaseTreeItem *databaseItem = ExplorerDatabaseCategoryTreeItem::databaseItem(); + if (!databaseItem) + return; + QString query = "db.system.js.save(" + script + ")"; + AppRegistry::instance().app()->openShell(databaseItem->database(), query, execute, title, cursor); + } } diff --git a/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.h b/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.h index d6b1a29f8..ecc98d616 100644 --- a/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.h +++ b/src/robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.h @@ -1,6 +1,8 @@ #pragma once #include "robomongo/gui/widgets/explorer/ExplorerTreeItem.h" +#include "robomongo/core/domain/CursorPosition.h" +#include "robomongo/core/domain/MongoFunction.h" namespace Robomongo { @@ -24,6 +26,7 @@ namespace Robomongo typedef ExplorerTreeItem BaseClass; ExplorerDatabaseCategoryTreeItem(ExplorerDatabaseTreeItem *databaseItem, ExplorerDatabaseCategory category); void expand(); + void ui_editFunction(const MongoFunction &function); private Q_SLOTS: void ui_createCollection(); @@ -35,9 +38,12 @@ namespace Robomongo void ui_refreshFunctions(); void ui_viewUsers(); void ui_viewFunctions(); + void functionTextEditorAddAccepted(); + void functionTextEditorEditAccepted(); private: ExplorerDatabaseTreeItem *databaseItem() const; const ExplorerDatabaseCategory _category; + void openCurrentCollectionShell(const QString &script, const QString &title, bool execute = true, const CursorPosition &cursor = CursorPosition()); }; } diff --git a/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.cpp b/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.cpp index aa97f6f2b..1fdfd0934 100644 --- a/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.cpp +++ b/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.cpp @@ -9,8 +9,12 @@ #include "robomongo/core/domain/MongoDatabase.h" #include "robomongo/core/domain/MongoServer.h" +#include "robomongo/core/domain/App.h" #include "robomongo/core/settings/ConnectionSettings.h" +#include "robomongo/core/settings/SettingsManager.h" #include "robomongo/core/utils/QtUtils.h" +#include "robomongo/core/AppRegistry.h" +#include "robomongo/gui/widgets/explorer/ExplorerDatabaseCategoryTreeItem.h" namespace Robomongo { @@ -43,22 +47,8 @@ namespace Robomongo void ExplorerFunctionTreeItem::ui_editFunction() { - std::string name = _function.name(); - - FunctionTextEditor dlg(QtUtils::toQString(_database->server()->connectionRecord()->getFullAddress()), - QtUtils::toQString(_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(); - } + ExplorerDatabaseCategoryTreeItem *dcti = (ExplorerDatabaseCategoryTreeItem*)parent(); + dcti->ui_editFunction(_function); } void ExplorerFunctionTreeItem::ui_dropFunction() diff --git a/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.h b/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.h index 581e8300b..69d3195bd 100644 --- a/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.h +++ b/src/robomongo/gui/widgets/explorer/ExplorerFunctionTreeItem.h @@ -2,6 +2,7 @@ #include "robomongo/core/domain/MongoFunction.h" #include "robomongo/gui/widgets/explorer/ExplorerTreeItem.h" +#include "robomongo/core/domain/CursorPosition.h" namespace Robomongo { diff --git a/src/robomongo/gui/widgets/workarea/BsonTableView.cpp b/src/robomongo/gui/widgets/workarea/BsonTableView.cpp index 1d63a08bd..caa72b783 100644 --- a/src/robomongo/gui/widgets/workarea/BsonTableView.cpp +++ b/src/robomongo/gui/widgets/workarea/BsonTableView.cpp @@ -11,12 +11,13 @@ namespace Robomongo { - BsonTableView::BsonTableView(MongoShell *shell, const MongoQueryInfo &queryInfo, QWidget *parent) - :BaseClass(parent), _notifier(this, shell, queryInfo) + BsonTableView::BsonTableView(Notifier *notifier, QWidget *parent) + :BaseClass(parent) { #if defined(Q_OS_MAC) setAttribute(Qt::WA_MacShowFocusRect, false); #endif + _notifier = notifier; GuiRegistry::instance().setAlternatingColor(this); verticalHeader()->setDefaultAlignment(Qt::AlignLeft); @@ -32,7 +33,7 @@ namespace Robomongo void BsonTableView::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Delete) { - _notifier.onDeleteDocuments(); + _notifier->onDeleteDocuments(); } return BaseClass::keyPressEvent(event); } @@ -61,14 +62,14 @@ namespace Robomongo QModelIndexList indexes = selectedIndexes(); if (detail::isMultiSelection(indexes)) { QMenu menu(this); - _notifier.initMultiSelectionMenu(&menu); + _notifier->initMultiSelectionMenu(&menu); menu.exec(menuPoint); } else{ QModelIndex selectedInd = selectedIndex(); BsonTreeItem *documentItem = QtUtils::item(selectedInd); QMenu menu(this); - _notifier.initMenu(&menu, documentItem); + _notifier->initMenu(&menu, documentItem); menu.exec(menuPoint); } } diff --git a/src/robomongo/gui/widgets/workarea/BsonTableView.h b/src/robomongo/gui/widgets/workarea/BsonTableView.h index 57412170a..14d0396ab 100644 --- a/src/robomongo/gui/widgets/workarea/BsonTableView.h +++ b/src/robomongo/gui/widgets/workarea/BsonTableView.h @@ -10,7 +10,7 @@ namespace Robomongo Q_OBJECT public: typedef QTableView BaseClass; - explicit BsonTableView(MongoShell *shell, const MongoQueryInfo &queryInfo, QWidget *parent = 0); + explicit BsonTableView(Notifier *notifier, QWidget *parent = 0); virtual QModelIndex selectedIndex() const; virtual QModelIndexList selectedIndexes() const; @@ -21,6 +21,6 @@ namespace Robomongo virtual void keyPressEvent(QKeyEvent *event); private: - Notifier _notifier; + Notifier *_notifier; }; } diff --git a/src/robomongo/gui/widgets/workarea/BsonTreeView.cpp b/src/robomongo/gui/widgets/workarea/BsonTreeView.cpp index 3128aaea7..6dc837be4 100644 --- a/src/robomongo/gui/widgets/workarea/BsonTreeView.cpp +++ b/src/robomongo/gui/widgets/workarea/BsonTreeView.cpp @@ -12,12 +12,13 @@ namespace Robomongo { - BsonTreeView::BsonTreeView(MongoShell *shell, const MongoQueryInfo &queryInfo, QWidget *parent) - : BaseClass(parent), _notifier(this, shell, queryInfo) + BsonTreeView::BsonTreeView(Notifier *notifier, QWidget *parent) + : BaseClass(parent) { #if defined(Q_OS_MAC) setAttribute(Qt::WA_MacShowFocusRect, false); #endif + _notifier = notifier; GuiRegistry::instance().setAlternatingColor(this); setSelectionMode(QAbstractItemView::ExtendedSelection); setSelectionBehavior(QAbstractItemView::SelectRows); @@ -51,7 +52,7 @@ namespace Robomongo menu.addAction(_collapseRecursive); menu.addSeparator(); - _notifier.initMultiSelectionMenu(&menu); + _notifier->initMultiSelectionMenu(&menu); menu.exec(menuPoint); } else { @@ -70,7 +71,7 @@ namespace Robomongo } } - _notifier.initMenu(&menu, documentItem); + _notifier->initMenu(&menu, documentItem); menu.exec(menuPoint); } } @@ -85,12 +86,12 @@ namespace Robomongo { switch (event->key()) { case Qt::Key_Delete: - _notifier.handleDeleteCommand(); + _notifier->handleDeleteCommand(); break; case Qt::Key_Backspace: // Cmd/Ctrl + Backspace if (event->modifiers() & Qt::ControlModifier) - _notifier.handleDeleteCommand(); + _notifier->handleDeleteCommand(); break; case Qt::Key_Right: if (event->modifiers() & Qt::AltModifier) diff --git a/src/robomongo/gui/widgets/workarea/BsonTreeView.h b/src/robomongo/gui/widgets/workarea/BsonTreeView.h index 0bf50cd2b..b5f767c2c 100644 --- a/src/robomongo/gui/widgets/workarea/BsonTreeView.h +++ b/src/robomongo/gui/widgets/workarea/BsonTreeView.h @@ -14,7 +14,7 @@ namespace Robomongo public: typedef QTreeView BaseClass; - BsonTreeView(MongoShell *shell, const MongoQueryInfo &queryInfo, QWidget *parent = NULL); + BsonTreeView(Notifier *notifier, QWidget *parent = NULL); virtual QModelIndex selectedIndex() const; virtual QModelIndexList selectedIndexes() const; void expandNode(const QModelIndex &index); @@ -30,7 +30,7 @@ namespace Robomongo virtual void keyPressEvent(QKeyEvent *event); private: - Notifier _notifier; + Notifier *_notifier; QAction *_expandRecursive; QAction *_collapseRecursive; }; diff --git a/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.cpp b/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.cpp index 0eea58250..bb678056c 100644 --- a/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.cpp +++ b/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.cpp @@ -77,8 +77,13 @@ namespace Robomongo setup(secs); } + OutputItemContentWidget::~OutputItemContentWidget(){ + delete _notifier; + } + void OutputItemContentWidget::setup(double secs) - { + { + _notifier = new Notifier(this, _shell, _queryInfo); setContentsMargins(0, 0, 0, 0); _header = new OutputItemHeaderWidget(this); @@ -241,7 +246,7 @@ namespace Robomongo } if (!_isTreeModeInitialized) { - _bsonTreeview = new BsonTreeView(_shell, _queryInfo); + _bsonTreeview = new BsonTreeView(_notifier); _bsonTreeview->setModel(_mod); _stack->addWidget(_bsonTreeview); @@ -293,7 +298,7 @@ namespace Robomongo } if (!_isTableModeInitialized) { - _bsonTable = new BsonTableView(_shell, _queryInfo); + _bsonTable = new BsonTableView(_notifier); BsonTableModelProxy *modp = new BsonTableModelProxy(_bsonTable); modp->setSourceModel(_mod); _bsonTable->setModel(modp); @@ -363,4 +368,34 @@ namespace Robomongo _logText->sciScintilla()->setStyleSheet("QFrame {background-color: rgb(73, 76, 78); border: 1px solid #c7c5c4; border-radius: 0px; margin: 0px; padding: 0px;}"); return _logText; } + + QModelIndex OutputItemContentWidget::selectedIndex() const + { + QModelIndex result; + switch(_viewMode) { + case Text: return result; + case Tree: return _bsonTreeview->selectedIndex(); + case Table: return _bsonTable->selectedIndex(); + case Custom: + if(!_isCustomModeSupported) + return _bsonTreeview->selectedIndex(); + return result; + default: return _bsonTreeview->selectedIndex(); + } + } + + QModelIndexList OutputItemContentWidget::selectedIndexes() const + { + QModelIndexList result; + switch(_viewMode) { + case Text: return result; + case Tree: return _bsonTreeview->selectedIndexes(); + case Table: return _bsonTable->selectedIndexes(); + case Custom: + if(!_isCustomModeSupported) + return _bsonTreeview->selectedIndexes(); + return result; + default: return _bsonTreeview->selectedIndexes(); + } + } } diff --git a/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.h b/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.h index 4496c0fe3..caeef73c6 100644 --- a/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.h +++ b/src/robomongo/gui/widgets/workarea/OutputItemContentWidget.h @@ -5,6 +5,7 @@ #include "robomongo/core/Core.h" #include "robomongo/core/domain/MongoQueryInfo.h" #include "robomongo/core/Enums.h" +#include "robomongo/core/domain/Notifier.h" #include namespace Robomongo @@ -19,7 +20,7 @@ namespace Robomongo class OutputItemHeaderWidget; class OutputWidget; - class OutputItemContentWidget : public QWidget + class OutputItemContentWidget : public QWidget, public INotifierObserver { Q_OBJECT @@ -27,6 +28,7 @@ namespace Robomongo typedef QWidget BaseClass; OutputItemContentWidget(OutputWidget *out, ViewMode viewMode, MongoShell *shell, const QString &text, double secs, QWidget *parent = NULL); OutputItemContentWidget(OutputWidget *out, ViewMode viewMode, MongoShell *shell, const QString &type, const std::vector &documents, const MongoQueryInfo &queryInfo, double secs, QWidget *parent = NULL); + ~OutputItemContentWidget(); int _initialSkip; int _initialLimit; void update(const MongoQueryInfo &inf, const std::vector &documents); @@ -39,6 +41,9 @@ namespace Robomongo void refreshOutputItem(); void markUninitialized(); + virtual QModelIndex selectedIndex() const; + virtual QModelIndexList selectedIndexes() const; + Q_SIGNALS: void restoredSize(); void maximizedPart(); @@ -89,5 +94,6 @@ namespace Robomongo bool _isFirstPartRendered; ViewMode _viewMode; + Notifier *_notifier; }; }