From da7f472864c50af85b01907ab3a3762e98b6154e Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Thu, 13 Oct 2016 12:22:54 +0200 Subject: [PATCH] Make shortcut for 'reload' dependent on currently active tab Make the reload shortcut (at the moment F5 and Ctrl+R) dependent on the currently active tab. This way it always performs some meaningful task, depending on the current context. See issue #759. --- src/Application.cpp | 2 +- src/MainWindow.cpp | 31 ++++++++++++++++++++++++++----- src/MainWindow.h | 2 +- src/MainWindow.ui | 36 +++++++++++++++++++++++++++--------- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index cf5bb011..aa332a19 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -125,7 +125,7 @@ Application::Application(int& argc, char** argv) : } } if(!sqlToExecute.isEmpty()) - m_mainWindow->browseRefresh(); + m_mainWindow->refresh(); // Jump to table if the -t/--table parameter was set if(!tableToBrowse.isEmpty()) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 40f37bce..a06fc132 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -120,8 +120,10 @@ void MainWindow::init() shortcuts.push_back(QKeySequence(tr("Ctrl+Return"))); ui->actionExecuteSql->setShortcuts(shortcuts); - QShortcut* shortcutBrowseRefresh = new QShortcut(QKeySequence("Ctrl+R"), this); - connect(shortcutBrowseRefresh, SIGNAL(activated()), ui->buttonRefresh, SLOT(click())); + QShortcut* shortcutBrowseRefreshF5 = new QShortcut(QKeySequence("F5"), this); + connect(shortcutBrowseRefreshF5, SIGNAL(activated()), this, SLOT(refresh())); + QShortcut* shortcutBrowseRefreshCtrlR = new QShortcut(QKeySequence("Ctrl+R"), this); + connect(shortcutBrowseRefreshCtrlR, SIGNAL(activated()), this, SLOT(refresh())); // Create the actions for the recently opened dbs list for(int i = 0; i < MaxRecentFiles; ++i) { @@ -693,10 +695,29 @@ void MainWindow::setRecordsetLabel() ui->labelRecordset->setText(tr("%1 - %2 of %3").arg(from).arg(to).arg(total)); } -void MainWindow::browseRefresh() +void MainWindow::refresh() { - db.updateSchema(); - populateTable(); + // What the Refresh function does depends on the currently active tab. This way the keyboard shortcuts (F5 and Ctrl+R) + // always perform some meaningful task; they just happen to be context dependent in the function they trigger. + switch(ui->mainTab->currentIndex()) + { + case StructureTab: + // Refresh the schema + db.updateSchema(); + break; + case BrowseTab: + // Refresh the schema and reload the current table + db.updateSchema(); + populateTable(); + break; + case PragmaTab: + // Do nothing + break; + case ExecuteTab: + // (Re-)Run the current SQL query + executeQuery(); + break; + } } void MainWindow::createTable() diff --git a/src/MainWindow.h b/src/MainWindow.h index 12ffc443..a463c58d 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -160,7 +160,7 @@ public slots: bool fileOpen(const QString& fileName = QString(), bool dontAddToRecentFiles = false); void logSql(const QString &sql, int msgtype); void dbState(bool dirty); - void browseRefresh(); + void refresh(); void jumpToRow(const QString& table, QString column, const QByteArray& value); void switchToBrowseDataTab(QString tableToBrowse = QString()); void populateStructure(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 3c581b8a..78774974 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -121,9 +121,6 @@ :/icons/refresh:/icons/refresh - - F5 - @@ -1696,10 +1693,7 @@ &Execute SQL - Execute SQL [F5, Ctrl+Return] - - - F5 + Execute SQL [F5, Ctrl+Return, Ctrl+R] @@ -1977,6 +1971,14 @@ Save to Remote + + + Refresh + + + F5 + + @@ -2227,7 +2229,7 @@ buttonRefresh clicked() MainWindow - browseRefresh() + refresh() 245 @@ -3023,6 +3025,22 @@ + + actionRefresh + triggered() + MainWindow + refresh() + + + -1 + -1 + + + 518 + 314 + + + fileOpen() @@ -3036,7 +3054,7 @@ navigateEnd() navigateGoto() browseFind(bool) - browseRefresh() + refresh() compact() helpWhatsThis() doubleClickTable(QModelIndex)