diff options
| author | 2015-01-30 17:00:24 -0500 | |
|---|---|---|
| committer | 2015-01-30 17:00:24 -0500 | |
| commit | e4767514ed04e6a0bddf3f4a47f5f0b09e65e0ee (patch) | |
| tree | 86cadc2137831d44fa29fd40a2964f7fb1326de4 /SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp | |
| parent | 26ddfe11c2b7fac52e5f57dcd9f5223a50b2a9a7 (diff) | |
| parent | 016003905ca0e8e459e3dc33e786beda8ec92f45 (diff) | |
Merge tag 'upstream/3.0.2'
Upstream version 3.0.2
# gpg: Signature made Fri 30 Jan 2015 05:00:11 PM EST using RSA key ID EBE9BD91
# gpg: Good signature from "Unit 193 <unit193@gmail.com>"
# gpg: aka "Unit 193 <unit193@ninthfloor.org>"
# gpg: aka "Unit 193 <unit193@ubuntu.com>"
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp | 88 |
1 files changed, 50 insertions, 38 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp b/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp index 52e1676..edafce5 100644 --- a/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp @@ -28,6 +28,7 @@ #include <QTextBlock> #include <QScrollBar> #include <QFileDialog> +#include <QtConcurrent/QtConcurrent> CFG_KEYS_DEFINE(SqlEditor) @@ -184,6 +185,7 @@ Db* SqlEditor::getDb() const void SqlEditor::setDb(Db* value) { db = value; + refreshValidObjects(); scheduleQueryParser(true); } @@ -194,34 +196,41 @@ void SqlEditor::setAutoCompletion(bool enabled) void SqlEditor::customContextMenuRequested(const QPoint &pos) { - if (objectLinksEnabled) - { - const DbObject* obj = getValidObjectForPosition(pos); - QString objName = toPlainText().mid(obj->from, (obj->to - obj->from + 1)); + if (objectLinksEnabled && handleValidObjectContextMenu(pos)) + return; - validObjContextMenu->clear(); + contextMenu->popup(mapToGlobal(pos)); +} - DbTreeItem* item = nullptr; - for (DbTreeItem::Type type : {DbTreeItem::Type::TABLE, DbTreeItem::Type::INDEX, DbTreeItem::Type::TRIGGER, DbTreeItem::Type::VIEW}) - { - item = DBTREE->getModel()->findItem(type, objName); - if (item) - break; - } +bool SqlEditor::handleValidObjectContextMenu(const QPoint& pos) +{ + const DbObject* obj = getValidObjectForPosition(pos); + if (!obj) + return false; - if (item) - { - DBTREE->setSelectedItem(item); - DBTREE->setupActionsForMenu(item, validObjContextMenu); - if (validObjContextMenu->actions().size() == 0) - return; + QString objName = toPlainText().mid(obj->from, (obj->to - obj->from + 1)); - DBTREE->updateActionStates(item); - validObjContextMenu->popup(mapToGlobal(pos)); - } - return; + validObjContextMenu->clear(); + + DbTreeItem* item = nullptr; + for (DbTreeItem::Type type : {DbTreeItem::Type::TABLE, DbTreeItem::Type::INDEX, DbTreeItem::Type::TRIGGER, DbTreeItem::Type::VIEW}) + { + item = DBTREE->getModel()->findItem(type, objName); + if (item) + break; } - contextMenu->popup(mapToGlobal(pos)); + + if (!item) + return false; + + DBTREE->setSelectedItem(item); + DBTREE->setupActionsForMenu(item, validObjContextMenu); + if (validObjContextMenu->actions().size() == 0) + return false; + + DBTREE->updateActionStates(item); + validObjContextMenu->popup(mapToGlobal(pos)); + return true; } void SqlEditor::updateUndoAction(bool enabled) @@ -487,17 +496,21 @@ void SqlEditor::refreshValidObjects() if (!db || !db->isValid()) return; - objectsInNamedDb.clear(); - - SchemaResolver resolver(db); - QSet<QString> databases = resolver.getDatabases(); - databases << "main"; - QStringList objects; - foreach (const QString& dbName, databases) + QtConcurrent::run([this]() { - objects = resolver.getAllObjects(); - objectsInNamedDb[dbName] << objects; - } + QMutexLocker lock(&objectsInNamedDbMutex); + objectsInNamedDb.clear(); + + SchemaResolver resolver(db); + QSet<QString> databases = resolver.getDatabases(); + databases << "main"; + QStringList objects; + foreach (const QString& dbName, databases) + { + objects = resolver.getAllObjects(); + objectsInNamedDb[dbName] << objects; + } + }); } Dialect SqlEditor::getDialect() @@ -707,10 +720,7 @@ void SqlEditor::indentNewLine() void SqlEditor::showSearchDialog() { if (!searchDialog) - { searchDialog = new SearchTextDialog(textLocator, this); - searchDialog->setWindowTitle(tr("Find or replace", "sql editor find/replace dialog")); - } if (searchDialog->isVisible()) searchDialog->hide(); @@ -855,6 +865,7 @@ void SqlEditor::checkForValidObjects() if (!db || !db->isValid()) return; + QMutexLocker lock(&objectsInNamedDbMutex); Dialect dialect = db->getDialect(); QList<SqliteStatement::FullObject> fullObjects; QString dbName; @@ -1022,7 +1033,7 @@ void SqlEditor::saveToFile() QFile file(fName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - notifyError(tr("Could not open file '%1'' for writing: %2").arg(fName).arg(file.errorString())); + notifyError(tr("Could not open file '%1' for writing: %2").arg(fName).arg(file.errorString())); return; } @@ -1046,7 +1057,7 @@ void SqlEditor::loadFromFile() QFile file(fName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - notifyError(tr("Could not open file '%1'' for reading: %2").arg(fName).arg(file.errorString())); + notifyError(tr("Could not open file '%1' for reading: %2").arg(fName).arg(file.errorString())); return; } @@ -1393,6 +1404,7 @@ void SqlEditor::handleValidObjectCursor(const QPoint& point) } viewport()->setCursor(isValid ? Qt::PointingHandCursor : Qt::IBeamCursor); } + bool SqlEditor::getVirtualSqlCompleteSemicolon() const { return virtualSqlCompleteSemicolon; |
