Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/robomongo/core/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ namespace Robomongo
Custom = 3
};

enum EditWindowMode
{
Modal = 0,
Modeless = 1,
Tabbed = 2
};

enum AutocompletionMode
{
AutocompleteNone = 0,
Expand Down
106 changes: 88 additions & 18 deletions src/robomongo/core/domain/Notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -284,14 +285,33 @@ namespace Robomongo

const QString &json = QtUtils::toQString(str);

DocumentTextEditor editor(_queryInfo._info,
json, false, dynamic_cast<QWidget*>(_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);
}
}

Expand Down Expand Up @@ -325,22 +345,49 @@ namespace Robomongo
if (!_queryInfo._info.isValid())
return;

DocumentTextEditor editor(_queryInfo._info,
"{\n \n}", false, dynamic_cast<QWidget*>(_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()
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions src/robomongo/core/domain/Notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QModelIndex>

#include "robomongo/core/domain/MongoQueryInfo.h"
#include "robomongo/core/domain/CursorPosition.h"

QT_BEGIN_NAMESPACE
class QAction;
Expand Down Expand Up @@ -59,6 +60,8 @@ namespace Robomongo
void onCopyJson();
void handle(InsertDocumentResponse *event);
void handle(RemoveDocumentResponse *event);
void documentTextEditorInsertAccepted();
void documentTextEditorEditAccepted();

private:
QAction *_deleteDocumentAction;
Expand All @@ -73,5 +76,7 @@ namespace Robomongo

MongoShell *_shell;
INotifierObserver *const _observer;

void openCurrentCollectionShell(const QString &script, bool execute = true, const CursorPosition &cursor = CursorPosition());
};
}
26 changes: 19 additions & 7 deletions src/robomongo/core/settings/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Robomongo
_uuidEncoding(DefaultEncoding),
_timeZone(Utc),
_viewMode(Robomongo::Tree),
_editWindowMode(Robomongo::Modal),
_autocompletionMode(AutocompleteAll),
_batchSize(50),
_disableConnectionShortcuts(false),
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/robomongo/core/settings/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -144,6 +147,7 @@ namespace Robomongo
UUIDEncoding _uuidEncoding;
SupportedTimes _timeZone;
ViewMode _viewMode;
EditWindowMode _editWindowMode;
AutocompletionMode _autocompletionMode;
bool _loadMongoRcJs;
bool _autoExpand;
Expand Down
60 changes: 58 additions & 2 deletions src/robomongo/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -265,15 +295,26 @@ namespace Robomongo
defaultViewModeMenu->addAction(treeModeAction);
defaultViewModeMenu->addAction(tableModeAction);
defaultViewModeMenu->addAction(textModeAction);

optionsMenu->addSeparator();

QActionGroup *modeGroup = new QActionGroup(this);
modeGroup->addAction(textModeAction);
modeGroup->addAction(treeModeAction);
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);
Expand Down Expand Up @@ -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<QAction*>(sender());
Expand Down
3 changes: 3 additions & 0 deletions src/robomongo/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace Robomongo
void enterTreeMode();
void enterTableMode();
void enterCustomMode();
void setModalWindowMode();
void setModelessWindowMode();
void setTabbedWindowMode();
void toggleAutoExpand();
void toggleAutoExec();
void toggleLineNumbers();
Expand Down
Loading