Skip to content

Commit 4c4e55f

Browse files
committed
dbhub: Add context menu actions to all tree views
This adds context menus and some context menu actions to all the tree views in the Remote dock. No new features are added. This just adds a new way to trigger existing features but also establishes a place for future actions for new features.
1 parent 1af8135 commit 4c4e55f

2 files changed

Lines changed: 92 additions & 10 deletions

File tree

src/RemoteDock.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,49 @@ RemoteDock::RemoteDock(MainWindow* parent)
7272
ui->treeDatabaseCommits->expandAll();
7373
});
7474

75+
// Prepare context menu for list of remote databases
76+
connect(ui->treeRemote->selectionModel(), &QItemSelectionModel::currentChanged, [this](const QModelIndex& index, const QModelIndex&) {
77+
// Only enable database actions when a database was selected
78+
bool enable = index.isValid() &&
79+
remoteModel->modelIndexToItem(index)->value(RemoteModelColumnType).toString() == "database";
80+
ui->actionCloneDatabaseDoubleClick->setEnabled(enable);
81+
});
82+
ui->treeRemote->selectionModel()->currentChanged(QModelIndex(), QModelIndex()); // Enable/disable all action initially
83+
connect(ui->actionCloneDatabaseDoubleClick, &QAction::triggered, [this]() {
84+
fetchDatabase(ui->treeRemote->currentIndex());
85+
});
86+
ui->treeRemote->addAction(ui->actionCloneDatabaseDoubleClick);
87+
7588
// Prepare context menu for list of local clones
7689
connect(ui->treeLocal->selectionModel(), &QItemSelectionModel::currentChanged, [this](const QModelIndex& index, const QModelIndex&) {
7790
// Only enable database actions when a database was selected
7891
bool enable = index.isValid() &&
7992
!index.sibling(index.row(), RemoteLocalFilesModel::ColumnFile).data().isNull();
93+
ui->actionOpenLocalDatabase->setEnabled(enable);
8094
ui->actionDeleteDatabase->setEnabled(enable);
8195
});
96+
ui->treeLocal->selectionModel()->currentChanged(QModelIndex(), QModelIndex()); // Enable/disable all action initially
97+
connect(ui->actionOpenLocalDatabase, &QAction::triggered, [this]() {
98+
openLocalFile(ui->treeLocal->currentIndex());
99+
});
82100
connect(ui->actionDeleteDatabase, &QAction::triggered, [this]() {
83101
deleteLocalDatabase(ui->treeLocal->currentIndex());
84102
});
103+
ui->treeLocal->addAction(ui->actionOpenLocalDatabase);
85104
ui->treeLocal->addAction(ui->actionDeleteDatabase);
86105

106+
// Prepare context menu for list of commits
107+
connect(ui->treeDatabaseCommits->selectionModel(), &QItemSelectionModel::currentChanged, [this](const QModelIndex& index, const QModelIndex&) {
108+
// Only enable database actions when a commit was selected
109+
bool enable = index.isValid();
110+
ui->actionFetchCommit->setEnabled(enable);
111+
});
112+
ui->treeDatabaseCommits->selectionModel()->currentChanged(QModelIndex(), QModelIndex()); // Enable/disable all action initially
113+
connect(ui->actionFetchCommit, &QAction::triggered, [this]() {
114+
fetchCommit(ui->treeDatabaseCommits->currentIndex());
115+
});
116+
ui->treeDatabaseCommits->addAction(ui->actionFetchCommit);
117+
87118
// Initial setup
88119
reloadSettings();
89120
}
@@ -213,7 +244,7 @@ void RemoteDock::enableButtons()
213244
bool logged_in = !remoteModel->currentClientCertificate().isEmpty();
214245

215246
ui->buttonPushDatabase->setEnabled(db_opened && logged_in);
216-
ui->actionCloneDatabase->setEnabled(logged_in);
247+
ui->actionCloneDatabaseLink->setEnabled(logged_in);
217248
ui->actionDatabaseOpenBrowser->setEnabled(db_opened && logged_in);
218249
ui->actionRefresh->setEnabled(logged_in);
219250
}

src/RemoteDock.ui

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@
126126
<property name="floatable">
127127
<bool>false</bool>
128128
</property>
129-
<addaction name="actionCloneDatabase"/>
129+
<addaction name="actionCloneDatabaseLink"/>
130130
<addaction name="actionRefresh"/>
131131
</widget>
132132
</item>
133133
<item>
134134
<widget class="QTreeView" name="treeRemote">
135+
<property name="contextMenuPolicy">
136+
<enum>Qt::ActionsContextMenu</enum>
137+
</property>
135138
<property name="whatsThis">
136139
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;In this pane, remote databases from dbhub.io website can be added to DB Browser for SQLite. First you need an identity:&lt;/p&gt;&lt;ol style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Login to the dbhub.io website (use your GitHub credentials or whatever you want)&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Click the button to &amp;quot;Generate client certificate&amp;quot; (that's your identity). That'll give you a certificate file (save it to your local disk).&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Go to the Remote tab in DB Browser for SQLite Preferences. Click the button to add a new certificate to DB Browser for SQLite and choose the just downloaded certificate file.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Now the Remote panel shows your identity and you can add remote databases.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
137140
</property>
@@ -290,7 +293,11 @@
290293
</layout>
291294
</item>
292295
<item>
293-
<widget class="QTreeView" name="treeDatabaseCommits"/>
296+
<widget class="QTreeView" name="treeDatabaseCommits">
297+
<property name="contextMenuPolicy">
298+
<enum>Qt::ActionsContextMenu</enum>
299+
</property>
300+
</widget>
294301
</item>
295302
</layout>
296303
</widget>
@@ -398,9 +405,6 @@
398405
</item>
399406
</layout>
400407
<action name="actionDeleteDatabase">
401-
<property name="enabled">
402-
<bool>false</bool>
403-
</property>
404408
<property name="icon">
405409
<iconset resource="icons/icons.qrc">
406410
<normaloff>:/icons/close</normaloff>:/icons/close</iconset>
@@ -418,19 +422,19 @@
418422
<normaloff>:/icons/browser_open</normaloff>:/icons/browser_open</iconset>
419423
</property>
420424
<property name="text">
421-
<string>Open in web browser</string>
425+
<string>Open in Web Browser</string>
422426
</property>
423427
<property name="toolTip">
424428
<string>Open the web page for the current database in your browser</string>
425429
</property>
426430
</action>
427-
<action name="actionCloneDatabase">
431+
<action name="actionCloneDatabaseLink">
428432
<property name="icon">
429433
<iconset resource="icons/icons.qrc">
430434
<normaloff>:/icons/clone_database</normaloff>:/icons/clone_database</iconset>
431435
</property>
432436
<property name="text">
433-
<string>Clone from link</string>
437+
<string>Clone from Link</string>
434438
</property>
435439
<property name="toolTip">
436440
<string>Use this to download a remote database for local editing using a URL as provided on the web page of the database.</string>
@@ -451,6 +455,53 @@
451455
<string>F5</string>
452456
</property>
453457
</action>
458+
<action name="actionCloneDatabaseDoubleClick">
459+
<property name="icon">
460+
<iconset resource="icons/icons.qrc">
461+
<normaloff>:/icons/clone_database</normaloff>:/icons/clone_database</iconset>
462+
</property>
463+
<property name="text">
464+
<string>Clone Database</string>
465+
</property>
466+
<property name="font">
467+
<font>
468+
<weight>75</weight>
469+
<bold>true</bold>
470+
</font>
471+
</property>
472+
</action>
473+
<action name="actionOpenLocalDatabase">
474+
<property name="icon">
475+
<iconset resource="icons/icons.qrc">
476+
<normaloff>:/icons/db_open</normaloff>:/icons/db_open</iconset>
477+
</property>
478+
<property name="text">
479+
<string>Open Database</string>
480+
</property>
481+
<property name="toolTip">
482+
<string>Open the local copy of this database</string>
483+
</property>
484+
<property name="font">
485+
<font>
486+
<weight>75</weight>
487+
<bold>true</bold>
488+
</font>
489+
</property>
490+
</action>
491+
<action name="actionFetchCommit">
492+
<property name="text">
493+
<string>Check out Commit</string>
494+
</property>
495+
<property name="toolTip">
496+
<string>Download and open this specific commit</string>
497+
</property>
498+
<property name="font">
499+
<font>
500+
<weight>75</weight>
501+
<bold>true</bold>
502+
</font>
503+
</property>
504+
</action>
454505
</widget>
455506
<tabstops>
456507
<tabstop>comboUser</tabstop>
@@ -547,7 +598,7 @@
547598
</hints>
548599
</connection>
549600
<connection>
550-
<sender>actionCloneDatabase</sender>
601+
<sender>actionCloneDatabaseLink</sender>
551602
<signal>triggered()</signal>
552603
<receiver>RemoteDock</receiver>
553604
<slot>fetchDatabase()</slot>

0 commit comments

Comments
 (0)