Skip to content

Commit

Permalink
qownnotes/web-companion#57 web-companion: handle disable note edit an…
Browse files Browse the repository at this point in the history
…d encrypted notes editing
  • Loading branch information
pbek committed Feb 15, 2024
1 parent aa191b5 commit fa7cc51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6678,6 +6678,14 @@ void MainWindow::on_actionDecrypt_note_triggered() {
* Lets the user edit an encrypted note text in a 2nd text edit
*/
void MainWindow::on_actionEdit_encrypted_note_triggered() {
editEncryptedNote();
}

void MainWindow::editEncryptedNoteAsync() {
QTimer::singleShot(0, this, &MainWindow::editEncryptedNote);
}

void MainWindow::editEncryptedNote() {
currentNote.refetch();
if (!currentNote.hasEncryptedNoteText()) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class MainWindow : public QMainWindow {

QAction *findAction(const QString &objectName);

void editEncryptedNote();

void editEncryptedNoteAsync();

void addCustomAction(const QString &identifier, const QString &menuText,
const QString &buttonText, const QString &icon,
bool useInNoteEditContextMenu = false, bool hideButtonInToolbar = false,
Expand Down
12 changes: 12 additions & 0 deletions src/services/websocketserverservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,26 @@ int WebSocketServerService::deleteBookmark(const QJsonObject &jsonObject) {
// Remove the Markdown text in the current note
MainWindow *mainWindow = MainWindow::instance();
if (mainWindow != nullptr) {
// auto note = mainWindow->getCurrentNote();
// auto textBefore = note.hasEncryptedNoteText() && note.canDecryptNoteText()
// ? note.fetchDecryptedNoteText()
// : note.getNoteText();
auto textBefore = mainWindow->activeNoteTextEdit()->toPlainText();
auto textAfter = textBefore;
// Remove the bookmark from the note (try "\n" and without "\n")
textAfter.remove(markdown + QStringLiteral("\n"));
textAfter.remove(markdown);

if (textBefore != textAfter) {
// note.setDecryptedNoteText(textAfter);
mainWindow->allowNoteEditing();
mainWindow->activeNoteTextEdit()->setPlainText(textAfter);
noteCount++;

auto note = mainWindow->getCurrentNote();
if (note.hasEncryptedNoteText()) {
mainWindow->editEncryptedNoteAsync();
}
}
}

Expand Down

0 comments on commit fa7cc51

Please sign in to comment.