Skip to content

Commit

Permalink
ui: disable actions when adding text is not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Nov 23, 2023
1 parent bf9cef8 commit 952a368
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# QOwnNotes Changelog

## 23.11.3
- if the current note is encrypted, read-only or the doesn't exist any more now
some menu actions are also disabled to prevent writing to the note text edit
(for [#2904](https://github.com/pbek/QOwnNotes/issues/2904))
- a PPA for Ubuntu 24.04 (Noble Numbat) was added

## 23.11.2
Expand Down
22 changes: 15 additions & 7 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3825,6 +3825,18 @@ void MainWindow::updateCurrentNoteTextHash() {
.toHex());
}

void MainWindow::updateActionUiEnabled() {
const bool allowEditing = !ui->noteTextEdit->isReadOnly();

setMenuEnabled(ui->menuEditNote, allowEditing);
setMenuEnabled(ui->menuInsert, allowEditing);
setMenuEnabled(ui->menuFormat, allowEditing);
ui->actionPaste_image->setEnabled(allowEditing);
ui->actionReplace_in_current_note->setEnabled(allowEditing);
ui->actionAutocomplete->setEnabled(allowEditing);
ui->actionSplit_note_at_cursor_position->setEnabled(allowEditing);
}

/**
* Sets the note text edit to readonly if the note does not exist or the
* note file is not writable or the note is encrypted
Expand All @@ -3837,6 +3849,9 @@ void MainWindow::updateNoteTextEditReadOnly() {
ui->noteTextEdit->setReadOnly(true);
}

// Also update the other UI elements
updateActionUiEnabled();

ui->noteTextEdit->setTextInteractionFlags(ui->noteTextEdit->textInteractionFlags() |
Qt::TextSelectableByKeyboard);
}
Expand Down Expand Up @@ -10842,14 +10857,7 @@ void MainWindow::on_actionAllow_note_editing_triggered(bool checked) {
settings.setValue(QStringLiteral("allowNoteEditing"), checked);

updateNoteTextEditReadOnly();
setMenuEnabled(ui->menuEditNote, checked);
setMenuEnabled(ui->menuInsert, checked);
setMenuEnabled(ui->menuFormat, checked);
setMenuEnabled(ui->menuEncryption, checked);
ui->actionPaste_image->setEnabled(checked);
ui->actionReplace_in_current_note->setEnabled(checked);
ui->actionAutocomplete->setEnabled(checked);
ui->actionSplit_note_at_cursor_position->setEnabled(checked);
_readOnlyButton->setHidden(checked);

ui->actionAllow_note_editing->setText(checked ? tr("Disallow all note editing")
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -1100,4 +1100,5 @@ class MainWindow : public QMainWindow {
void updateJumpToActionsAvailability();
int getNoteTabIndex(int noteId) const;
bool startAutoReadOnlyModeIfEnabled();
void updateActionUiEnabled();
};

0 comments on commit 952a368

Please sign in to comment.