aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2025-01-16 01:57:37 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2025-01-16 01:57:37 -0500
commit81a21e6ce040e7740de86340c8ea4dba30e69bc3 (patch)
tree95fc1741b907d5ba6d029a42d80092cb7c056c5e /SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp
parent3565aad630864ecdbe53fdaa501ea708555b3c7c (diff)
New upstream version 3.4.13+dfsg.upstream/3.4.13+dfsgupstream
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp b/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp
index d1f1a47..1fb57ec 100644
--- a/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/sqleditor.cpp
@@ -25,6 +25,8 @@
#include "dbtree/dbtreeview.h"
#include "common/lazytrigger.h"
#include "common/extaction.h"
+#include "db/dbsqlite3.h"
+#include "dialogs/dbdialog.h"
#include <QAction>
#include <QMenu>
#include <QTimer>
@@ -35,6 +37,7 @@
#include <QScrollBar>
#include <QFileDialog>
#include <QtConcurrent/QtConcurrent>
+#include <QMessageBox>
#include <QStyle>
CFG_KEYS_DEFINE(SqlEditor)
@@ -727,6 +730,9 @@ void SqlEditor::highlightParenthesis(QList<QTextEdit::ExtraSelection>& selection
void SqlEditor::highlightCurrentQuery(QList<QTextEdit::ExtraSelection>& selections)
{
+ if (!richFeaturesEnabled)
+ return;
+
QTextCursor cursor = textCursor();
int curPos = cursor.position();
QString contents = cursor.document()->toPlainText();
@@ -735,7 +741,7 @@ void SqlEditor::highlightCurrentQuery(QList<QTextEdit::ExtraSelection>& selectio
return;
QTextEdit::ExtraSelection selection;
- selection.format.setBackground(STYLE->extendedPalette().editorCurrentQueryBase());
+ selection.format.setBackground(Cfg::getSyntaxCurrentQueryBg());
cursor.setPosition(boundries.first);
cursor.setPosition(boundries.second, QTextCursor::KeepAnchor);
@@ -1100,7 +1106,7 @@ void SqlEditor::highlightCurrentLine(QList<QTextEdit::ExtraSelection>& selection
if (!isReadOnly() && isEnabled())
{
QTextEdit::ExtraSelection selection;
- selection.format.setBackground(STYLE->extendedPalette().editorLineBase());
+ selection.format.setBackground(Cfg::getSyntaxCurrentLineBg());
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
@@ -1197,6 +1203,24 @@ void SqlEditor::loadFromFile()
setFileDialogInitPathByFile(fName);
+ if (DbSqlite3::isDbFile(fName))
+ {
+ DbDialog dialog(DbDialog::ADD, MAINWINDOW);
+ dialog.setPath(fName);
+ dialog.setDoAutoTest(true);
+ dialog.exec();
+ return;
+ }
+
+ if (QFile(fName).size() > HUGE_QUERY_LENGTH)
+ {
+ QMessageBox::StandardButton resp = QMessageBox::question(this, tr("Open file"),
+ tr("This file is huge (over %1 MB). Are you sure you want to load it into SQL query editor?")
+ .arg(HUGE_QUERY_LENGTH / 1024 / 1024));
+ if (resp != QMessageBox::Yes)
+ return;
+ }
+
QString err;
QString sql = readFileContents(fName, &err);
if (sql.isNull() && !err.isNull())
@@ -1205,9 +1229,13 @@ void SqlEditor::loadFromFile()
return;
}
- setPlainText(sql);
-
- loadedFile = fName;
+ if (toPlainText().trimmed().isEmpty())
+ {
+ setPlainText(sql);
+ loadedFile = fName;
+ }
+ else
+ MAINWINDOW->openSqlEditor(db, sql);
}
void SqlEditor::deleteLine()
@@ -1715,10 +1743,11 @@ void SqlEditor::saveSelection()
}
void SqlEditor::restoreSelection()
-{
+{
QTextCursor cur = textCursor();
cur.setPosition(storedSelectionStart);
cur.setPosition(storedSelectionEnd, QTextCursor::KeepAnchor);
+ setTextCursor(cur);
}
QToolBar* SqlEditor::getToolBar(int toolbar) const