Skip to content

Commit 3c7562e

Browse files
committed
#3413 note-dialog: add "Reload" and "Jump to note" buttons
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 1547c89 commit 3c7562e

File tree

5 files changed

+579
-421
lines changed

5 files changed

+579
-421
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 25.12.7
44

5+
- Added **Reload** and **Jump to note** buttons to the Note Dialog of the
6+
`Open note in different window` context menu (for [#3413](https://github.com/pbek/QOwnNotes/issues/3413))
7+
- The **Reload** button refreshes the note from the database to show any external changes
8+
- The **Jump to note** button navigates to the note in the main window without closing the dialog
59
- Now a status message will be shown if a note cannot be written to disk
610
(for [#3412](https://github.com/pbek/QOwnNotes/issues/3412))
711

src/dialogs/notedialog.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
#include <QDebug>
77
#include <QDesktopServices>
8+
#include <QDialogButtonBox>
9+
#include <QPushButton>
810

11+
#include "mainwindow.h"
912
#include "services/settingsservice.h"
1013
#include "ui_notedialog.h"
1114
#include "utils/urlhandler.h"
@@ -21,9 +24,29 @@ NoteDialog::NoteDialog(QWidget *parent) : MasterDialog(parent), ui(new Ui::NoteD
2124
QFont font;
2225
font.fromString(Utils::Misc::previewFontString());
2326
ui->noteTextView->setFont(font);
27+
28+
// Add custom buttons to the button box
29+
QPushButton *reloadButton =
30+
ui->buttonBox->addButton(tr("Reload"), QDialogButtonBox::ActionRole);
31+
reloadButton->setIcon(
32+
QIcon::fromTheme(QStringLiteral("view-refresh"),
33+
QIcon(QStringLiteral(":/icons/breeze-qownnotes/16x16/view-refresh.svg"))));
34+
reloadButton->setToolTip(tr("Reload the note text"));
35+
36+
QPushButton *jumpToNoteButton =
37+
ui->buttonBox->addButton(tr("Jump to note"), QDialogButtonBox::ActionRole);
38+
jumpToNoteButton->setIcon(
39+
QIcon::fromTheme(QStringLiteral("go-next"),
40+
QIcon(QStringLiteral(":/icons/breeze-qownnotes/16x16/go-next.svg"))));
41+
jumpToNoteButton->setToolTip(tr("Jump to the note in the main window"));
42+
43+
// Connect the custom buttons to their slots
44+
connect(reloadButton, &QPushButton::clicked, this, &NoteDialog::onReloadButtonClicked);
45+
connect(jumpToNoteButton, &QPushButton::clicked, this, &NoteDialog::onJumpToNoteButtonClicked);
2446
}
2547

2648
void NoteDialog::setNote(Note &note) {
49+
_note = note; // Store the note for later use
2750
setWindowTitle(note.getName());
2851

2952
// show the decrypted text if possible
@@ -50,3 +73,19 @@ void NoteDialog::on_noteTextView_anchorClicked(const QUrl &url) {
5073
void NoteDialog::on_tabWidget_currentChanged(int index) {
5174
SettingsService().setValue("NoteDialog/tabWidgetIndex", index);
5275
}
76+
77+
void NoteDialog::onReloadButtonClicked() {
78+
// Refetch the note from the database
79+
if (_note.refetch()) {
80+
// Update the display with the refreshed note
81+
setNote(_note);
82+
}
83+
}
84+
85+
void NoteDialog::onJumpToNoteButtonClicked() {
86+
// Get the MainWindow instance and jump to the note
87+
MainWindow *mainWindow = MainWindow::instance();
88+
if (mainWindow) {
89+
mainWindow->setCurrentNote(_note);
90+
}
91+
}

src/dialogs/notedialog.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#ifndef NOTEDIALOG_H
22
#define NOTEDIALOG_H
33

4+
#include "entities/note.h"
45
#include "masterdialog.h"
56

67
namespace Ui {
78
class NoteDialog;
89
}
910

10-
class Note;
11-
1211
class NoteDialog : public MasterDialog {
1312
Q_OBJECT
1413

@@ -22,8 +21,13 @@ class NoteDialog : public MasterDialog {
2221

2322
void on_tabWidget_currentChanged(int index);
2423

24+
void onReloadButtonClicked();
25+
26+
void onJumpToNoteButtonClicked();
27+
2528
private:
2629
Ui::NoteDialog *ui;
30+
Note _note;
2731
};
2832

2933
#endif // NOTEDIALOG_H

src/dialogs/notedialog.ui

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
<property name="windowTitle">
1414
<string>Note</string>
1515
</property>
16-
<layout class="QHBoxLayout" name="horizontalLayout">
16+
<layout class="QVBoxLayout" name="verticalLayout_main">
17+
<property name="spacing">
18+
<number>0</number>
19+
</property>
1720
<property name="leftMargin">
1821
<number>0</number>
1922
</property>
@@ -118,6 +121,35 @@
118121
</widget>
119122
</widget>
120123
</item>
124+
<item>
125+
<layout class="QHBoxLayout" name="buttonLayout">
126+
<property name="spacing">
127+
<number>6</number>
128+
</property>
129+
<property name="leftMargin">
130+
<number>9</number>
131+
</property>
132+
<property name="topMargin">
133+
<number>6</number>
134+
</property>
135+
<property name="rightMargin">
136+
<number>9</number>
137+
</property>
138+
<property name="bottomMargin">
139+
<number>9</number>
140+
</property>
141+
<item>
142+
<widget class="QDialogButtonBox" name="buttonBox">
143+
<property name="orientation">
144+
<enum>Qt::Horizontal</enum>
145+
</property>
146+
<property name="standardButtons">
147+
<set>QDialogButtonBox::Close</set>
148+
</property>
149+
</widget>
150+
</item>
151+
</layout>
152+
</item>
121153
</layout>
122154
</widget>
123155
<customwidgets>
@@ -133,5 +165,38 @@
133165
</customwidget>
134166
</customwidgets>
135167
<resources/>
136-
<connections/>
168+
<connections>
169+
<connection>
170+
<sender>buttonBox</sender>
171+
<signal>accepted()</signal>
172+
<receiver>NoteDialog</receiver>
173+
<slot>accept()</slot>
174+
<hints>
175+
<hint type="sourcelabel">
176+
<x>248</x>
177+
<y>254</y>
178+
</hint>
179+
<hint type="destinationlabel">
180+
<x>157</x>
181+
<y>274</y>
182+
</hint>
183+
</hints>
184+
</connection>
185+
<connection>
186+
<sender>buttonBox</sender>
187+
<signal>rejected()</signal>
188+
<receiver>NoteDialog</receiver>
189+
<slot>reject()</slot>
190+
<hints>
191+
<hint type="sourcelabel">
192+
<x>316</x>
193+
<y>260</y>
194+
</hint>
195+
<hint type="destinationlabel">
196+
<x>286</x>
197+
<y>274</y>
198+
</hint>
199+
</hints>
200+
</connection>
201+
</connections>
137202
</ui>

0 commit comments

Comments
 (0)