Commit 850a0e88 authored by Nate Graham's avatar Nate Graham
Browse files

[note] Add confirmation dialog when deleting note with real content

We've gotten feedback that it's too easy to accidentally delete a note
now. While there is an undo notification, this is still a fairly scary
thing to have happen if your accidentally-deleted note had important
content in it. Also, the notification is persistent, but only persists
for 60 seconds (plasmashell manually revokes it after that). So if you
accidentally delete a note and go to get coffee or fail to notice the
notification, the content will be lost forever.

To improve the situation here, we now show a warning dialog when you
attempt to delete a note that has user-generated content in it. If the
note is empty, or if the note's content is identical to the top
clipboard entry (as in  he case where the user created the note via
middle-click paste), then it is instead deleted immediately.

Hopefully this will be an adequate compromise between the desire to make
it easy to delete accidentally-created notes and the importance of
keeping user data safe.
parent 8f747d61
......@@ -9,6 +9,7 @@ import QtQuick 2.6
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Layouts 1.1
import QtQuick.Window 2.12
import QtQuick.Dialogs 1.3
import org.kde.draganddrop 2.0 as DragDrop
......@@ -436,7 +437,27 @@ PlasmaCore.SvgItem {
icon.color: textIconColor
icon.width: PlasmaCore.Units.iconSizes.smallMedium
icon.height: icon.width
onClicked: plasmoid.action("remove").trigger()
onClicked: {
// No need to ask for confirmation in the cases when...
// ...the note is blank
if (mainTextArea.length == 0 ||
// ...the note's content is equal to the clipboard text
// Note that we are intentionally not using
// mainTextArea.getText() because it has a method of
// converting the text to plainText that does not produce
// the same exact output of various other methods, and if
// we go out of our way to match it, we will be
// depending on an implementation detail. So we instead
// roll our own version to ensure that the conversion
// is done in the same way every time.
documentHandler.stripAndSimplify(mainTextArea.text) == documentHandler.strippedClipboardText()
) {
plasmoid.action("remove").trigger();
} else {
discardConfirmationDialogLoader.open();
}
}
Accessible.name: removeTooltip.text
QQC2.ToolTip {
id: removeTooltip
......@@ -446,6 +467,35 @@ PlasmaCore.SvgItem {
}
}
Loader {
id: discardConfirmationDialogLoader
function open() {
if (item) {
item.open();
} else {
active = true;
}
item.visible = true;
}
active: false
sourceComponent: MessageDialog {
visible: false
title: i18n("Discard this note?")
text: i18n("Are you sure you want to discard this note?")
icon: StandardIcon.Warning
standardButtons: StandardButton.Discard | StandardButton.Cancel
onDiscard: {
plasmoid.action("remove").trigger()
visible = false;
}
}
}
Component.onCompleted: {
plasmoid.setAction("change_note_color_white", i18nc("@item:inmenu", "White"));
plasmoid.setAction("change_note_color_black", i18nc("@item:inmenu", "Black"));
......
......@@ -19,6 +19,7 @@
#include <QMimeData>
#include <QTextCursor>
#include <QTextDocument>
#include <QTextDocumentFragment>
DocumentHandler::DocumentHandler()
: m_target(nullptr)
......@@ -316,3 +317,22 @@ QStringList DocumentHandler::defaultFontSizes() const
}
return sizes;
}
QString DocumentHandler::stripAndSimplify(const QString text)
{
QString myText = text;
QString plainText = QTextDocumentFragment::fromHtml(myText).toPlainText();
// Normalize all whitespace to increase the fuzziness of the match
plainText = plainText.simplified();
return plainText;
}
QString DocumentHandler::strippedClipboardText()
{
QClipboard *clipboard = QGuiApplication::clipboard();
if (!clipboard) {
return QString();
}
return stripAndSimplify(clipboard->text());
}
......@@ -88,6 +88,9 @@ public:
QString documentTitle() const;
Q_INVOKABLE QString stripAndSimplify(const QString text);
Q_INVOKABLE QString strippedClipboardText();
public Q_SLOTS:
void setBold(bool arg);
void setItalic(bool arg);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment