Skip to content

Commit a8673e0

Browse files
committed
#3357 nextclouddeck: open deck dialog when clicking deck link
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent 8a9b99f commit a8673e0

File tree

5 files changed

+56
-23
lines changed

5 files changed

+56
-23
lines changed

src/dialogs/nextclouddeckdialog.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,7 @@ void NextcloudDeckDialog::resetEditFrameControls() {
239239
_currentCard = NextcloudDeckService::Card();
240240
}
241241

242-
void NextcloudDeckDialog::on_cardItemTreeWidget_currentItemChanged(QTreeWidgetItem *current,
243-
QTreeWidgetItem *previous) {
244-
Q_UNUSED(previous)
245-
246-
// in case all items were removed
247-
if (current == nullptr) {
248-
resetEditFrameControls();
249-
return;
250-
}
251-
252-
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("deck/card/changed"));
253-
254-
int id = current->data(0, Qt::UserRole).toInt();
255-
256-
// Find the card in our hash using the ID
242+
void NextcloudDeckDialog::jumpToCard(int id) {
257243
if (_cards.contains(id)) {
258244
_currentCard = _cards[id];
259245

@@ -277,6 +263,40 @@ void NextcloudDeckDialog::on_cardItemTreeWidget_currentItemChanged(QTreeWidgetIt
277263
}
278264
}
279265

266+
void NextcloudDeckDialog::on_cardItemTreeWidget_currentItemChanged(QTreeWidgetItem *current,
267+
QTreeWidgetItem *previous) {
268+
Q_UNUSED(previous)
269+
270+
// in case all items were removed
271+
if (current == nullptr) {
272+
resetEditFrameControls();
273+
return;
274+
}
275+
276+
MetricsService::instance()->sendVisitIfEnabled(QStringLiteral("deck/card/changed"));
277+
278+
const int id = current->data(0, Qt::UserRole).toInt();
279+
280+
// Find the card in our hash using the ID
281+
jumpToCard(id);
282+
}
283+
284+
void NextcloudDeckDialog::setCardId(const int id) {
285+
if (id < 1) {
286+
return;
287+
}
288+
289+
if (ui->cardItemTreeWidget->topLevelItemCount() == 0) {
290+
reloadCardList();
291+
}
292+
293+
const auto item = Utils::Gui::getTreeWidgetItemWithUserData(ui->cardItemTreeWidget, id);
294+
295+
if (item != nullptr) {
296+
ui->cardItemTreeWidget->setCurrentItem(item);
297+
}
298+
}
299+
280300
void NextcloudDeckDialog::on_newItemEdit_textChanged(const QString &arg1) {
281301
Utils::Gui::searchForTextInTreeWidget(
282302
ui->cardItemTreeWidget, arg1,

src/dialogs/nextclouddeckdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class NextcloudDeckDialog : public MasterDialog {
2121
explicit NextcloudDeckDialog(QWidget *parent = nullptr, bool listMode = false);
2222
~NextcloudDeckDialog();
2323
void setTitle(const QString &title);
24+
void setCardId(int id);
2425

2526
private slots:
2627
void on_saveButton_clicked();
@@ -61,6 +62,7 @@ class NextcloudDeckDialog : public MasterDialog {
6162
void setupUi();
6263
void refreshUi();
6364
void resetEditFrameControls();
65+
void jumpToCard(int id);
6466
QHash<int, NextcloudDeckService::Card> _cards;
6567
NextcloudDeckService::Card _currentCard;
6668
};

src/mainwindow.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6215,7 +6215,7 @@ void MainWindow::onNotePreviewAnchorClicked(const QUrl &url) {
62156215
/*
62166216
* Handles note urls
62176217
*/
6218-
void MainWindow::openLocalUrl(QString urlString) { UrlHandler().openUrl(urlString); }
6218+
void MainWindow::openLocalUrl(QString urlString) { UrlHandler().openUrl(std::move(urlString)); }
62196219

62206220
/*
62216221
* Manually check for updates
@@ -12320,17 +12320,25 @@ bool MainWindow::nextCloudDeckCheck() {
1232012320
return true;
1232112321
}
1232212322

12323-
void MainWindow::on_actionInsert_Nextcloud_Deck_card_triggered() {
12323+
void MainWindow::on_actionInsert_Nextcloud_Deck_card_triggered() { openNextcloudDeckDialog(); }
12324+
12325+
void MainWindow::openNextcloudDeckDialog(int cardId) {
1232412326
if (!nextCloudDeckCheck()) {
1232512327
return;
1232612328
}
1232712329

1232812330
auto *dialog = new NextcloudDeckDialog(this);
12331+
qDebug() << __func__ << "cardId: " << cardId;
1232912332

12330-
QOwnNotesMarkdownTextEdit *textEdit = activeNoteTextEdit();
12331-
QString selectedText = textEdit->textCursor().selectedText();
12332-
if (!selectedText.isEmpty()) {
12333-
dialog->setTitle(selectedText);
12333+
if (cardId > 0) {
12334+
dialog->setCardId(cardId);
12335+
} else {
12336+
QOwnNotesMarkdownTextEdit *textEdit = activeNoteTextEdit();
12337+
QString selectedText = textEdit->textCursor().selectedText();
12338+
12339+
if (!selectedText.isEmpty()) {
12340+
dialog->setTitle(selectedText);
12341+
}
1233412342
}
1233512343

1233612344
dialog->exec();

src/mainwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ class MainWindow : public QMainWindow {
226226

227227
void openTodoDialog(const QString &taskUid = QString());
228228

229+
void openNextcloudDeckDialog(int cardId = -1);
230+
229231
class QOwnNotesMarkdownTextEdit *noteTextEdit();
230232

231233
void refreshNotePreview(bool force = false);
@@ -350,7 +352,7 @@ class MainWindow : public QMainWindow {
350352

351353
void on_actionShow_changelog_triggered();
352354

353-
void openLocalUrl(QString urlString);
355+
static void openLocalUrl(QString urlString);
354356

355357
void on_action_Find_text_in_note_triggered();
356358

src/utils/urlhandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ void UrlHandler::handleNextcloudDeckUrl(const QString &urlString) {
8888
qDebug() << __func__ << "cardId: " << cardId;
8989

9090
if (cardId > 0) {
91-
// TODO: Open the Nextcloud Deck dialog with the card details
91+
// Open the Nextcloud Deck dialog with the cardId
92+
MainWindow::instance()->openNextcloudDeckDialog(cardId);
9293
}
9394
}
9495
}

0 commit comments

Comments
 (0)