Re: ESC Key

2023-01-23 Thread Daniel

On 2023-01-23 00:29, Richard Kimberly Heck wrote:

On 1/22/23 10:36, racoon wrote:

On 2023-01-22 13:44, Daniel wrote:

On 2023-01-22 10:25, Evan Langlois wrote:

Is there some way to reconfigure LyX to not have ESC cancel a dialog
or at least ask me first?  I tried to remove the keybinding for esc in
the preferences, but that didn't help.  The issue is that I use vi, so
when editing the preamble my hand just hits the esc key to save out of
habit.  All my changes are then gone without a "Hey you changed stuff!
Are you sure?"


I don't think there is a way. And I am not sure it is a common enough
case to allow for a preference or so.

But it sounds like you would be satisfied with LyX asking whether to
discard changes made to the preamble before cancelling the dialog. I
think that is generally a good idea. After all, it is like editing your
document where we also don't just let the user close the window without
asking.

Daniel


Attached is a simple patch that avoids the dialog being closed when the
Esc key is pressed. The patch presupposes the source code patch to
ticket #12577 (https://www.lyx.org/trac/ticket/12577).

As suggested above, at least additionally, there should also be a
warning when source codes where changed whether the dialog should be
closed. But that is not implemented with this patch.


Probalby the better solution is the other one you mentioned: If there 
are changes, do not close without asking first. This could be 
implemented quite generally, I suspect, though the GuiDialog class (and 
whatever one is the other one---remember we have two parallel dialog 
classes for no terribly good reason).


Riki


I guess the greatest loss is with changes in the preamble (and maybe 
local layout). So, I would restrict asking for changes in that. 
Otherwise, it might just be annoying.


The attached patch does that. However, I changed a function into a 
virtual which made me a bit uncomfortable about possible side effects 
(there are also a couple of override warnings triggered, obviously, that 
 haven't corrected either) since I am not fluent with these concepts.


The main challenge is to handle the cancel button, the window close 
button and the escape key the same way. It seems to works well as I 
implemented it. Maybe someone else could check whether it looks correct.


DanielFrom 4af7fa2c0236eaa96e361104589e59770ec34076 Mon Sep 17 00:00:00 2001
From: Daniel Ramoeller 
Date: Mon, 23 Jan 2023 11:43:56 +0100
Subject: [PATCH] Ask to discard preamble

---
 src/frontends/qt/GuiDialog.cpp   | 17 -
 src/frontends/qt/GuiDialog.h | 12 +++-
 src/frontends/qt/GuiDocument.cpp | 16 
 src/frontends/qt/GuiDocument.h   |  2 ++
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/src/frontends/qt/GuiDialog.cpp b/src/frontends/qt/GuiDialog.cpp
index 70d086c7f8..6fe8b36ce7 100644
--- a/src/frontends/qt/GuiDialog.cpp
+++ b/src/frontends/qt/GuiDialog.cpp
@@ -37,10 +37,25 @@ GuiDialog::GuiDialog(GuiView & lv, QString const & name, 
QString const & title)
 }
 
 
+void GuiDialog::keyPressEvent(QKeyEvent * event)
+{
+if (event->key() == Qt::Key_Escape) {
+   // Let the esc key trigger the close event so we can handle it 
uniformly
+close();
+return;
+}
+QDialog::keyPressEvent(event);
+}
+
+
 void GuiDialog::closeEvent(QCloseEvent * ev)
 {
+   setCloseStopped(false);
slotClose();
-   ev->accept();
+   if (closeStopped())
+   ev->ignore();
+   else
+   ev->accept();
 }
 
 
diff --git a/src/frontends/qt/GuiDialog.h b/src/frontends/qt/GuiDialog.h
index 160357dbc6..2d2af2be75 100644
--- a/src/frontends/qt/GuiDialog.h
+++ b/src/frontends/qt/GuiDialog.h
@@ -42,6 +42,9 @@ public:
QWidget * asQWidget() override { return this; }
QWidget const * asQWidget() const override { return this; }
 
+protected:
+   void keyPressEvent(QKeyEvent * event) override;
+
 public Q_SLOTS:
/** \name Buttons
 *  These methods are publicly accessible because they are invoked
@@ -58,7 +61,7 @@ public Q_SLOTS:
// AutoApply checkbox clicked
void slotAutoApply();
// Close button clicked or closed from WindowManager
-   void slotClose();
+   virtual void slotClose();
// A collectiong slot for QDialogButtonBox
void slotButtonBox(QAbstractButton *);
///
@@ -77,6 +80,9 @@ public:
// Set whether to stop the apply process
void setApplyStopped(bool stop) { apply_stopped_ = stop; };
 
+   // Set whether to stop the close process
+   void setCloseStopped(bool stop) { close_stopped_ = stop; };
+
/** \name Dialog Components
 *  Methods to access the various components making up a dialog.
 */
@@ -122,6 +128,10 @@ private:
/// stop the apply process?
bool applyStopped() { return apply_stopped_; };
bool apply_stopped_;
+
+   /// stop the apply process?
+ 

Re: ESC Key

2023-01-22 Thread Richard Kimberly Heck

On 1/22/23 10:36, racoon wrote:

On 2023-01-22 13:44, Daniel wrote:

On 2023-01-22 10:25, Evan Langlois wrote:

Is there some way to reconfigure LyX to not have ESC cancel a dialog
or at least ask me first?  I tried to remove the keybinding for esc in
the preferences, but that didn't help.  The issue is that I use vi, so
when editing the preamble my hand just hits the esc key to save out of
habit.  All my changes are then gone without a "Hey you changed stuff!
Are you sure?"


I don't think there is a way. And I am not sure it is a common enough
case to allow for a preference or so.

But it sounds like you would be satisfied with LyX asking whether to
discard changes made to the preamble before cancelling the dialog. I
think that is generally a good idea. After all, it is like editing your
document where we also don't just let the user close the window without
asking.

Daniel


Attached is a simple patch that avoids the dialog being closed when the
Esc key is pressed. The patch presupposes the source code patch to
ticket #12577 (https://www.lyx.org/trac/ticket/12577).

As suggested above, at least additionally, there should also be a
warning when source codes where changed whether the dialog should be
closed. But that is not implemented with this patch.


Probalby the better solution is the other one you mentioned: If there 
are changes, do not close without asking first. This could be 
implemented quite generally, I suspect, though the GuiDialog class (and 
whatever one is the other one---remember we have two parallel dialog 
classes for no terribly good reason).


Riki


--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: ESC Key

2023-01-22 Thread racoon

On 2023-01-22 13:44, Daniel wrote:

On 2023-01-22 10:25, Evan Langlois wrote:

Is there some way to reconfigure LyX to not have ESC cancel a dialog
or at least ask me first?  I tried to remove the keybinding for esc in
the preferences, but that didn't help.  The issue is that I use vi, so
when editing the preamble my hand just hits the esc key to save out of
habit.  All my changes are then gone without a "Hey you changed stuff!
Are you sure?"


I don't think there is a way. And I am not sure it is a common enough
case to allow for a preference or so.

But it sounds like you would be satisfied with LyX asking whether to
discard changes made to the preamble before cancelling the dialog. I
think that is generally a good idea. After all, it is like editing your
document where we also don't just let the user close the window without
asking.

Daniel


Attached is a simple patch that avoids the dialog being closed when the
Esc key is pressed. The patch presupposes the source code patch to
ticket #12577 (https://www.lyx.org/trac/ticket/12577).

As suggested above, at least additionally, there should also be a
warning when source codes where changed whether the dialog should be
closed. But that is not implemented with this patch.

Daniel
From 80748b0a03441ca6f959d9776eef8a092aef644c Mon Sep 17 00:00:00 2001
From: Daniel Ramoeller 
Date: Sun, 22 Jan 2023 16:31:53 +0100
Subject: [PATCH 2/2] When editing source code, prevent Escape key

When editing source code, e.g. the local layout or the LaTeX preamble, pressing 
the Esc key leads to the dialog being closed. This is prevented by the patch.
---
 src/frontends/qt/GuiSourceEdit.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/frontends/qt/GuiSourceEdit.cpp 
b/src/frontends/qt/GuiSourceEdit.cpp
index 9b008a5d03..e451688752 100644
--- a/src/frontends/qt/GuiSourceEdit.cpp
+++ b/src/frontends/qt/GuiSourceEdit.cpp
@@ -300,7 +300,9 @@ void GuiSourceEdit::keyPressEvent(QKeyEvent *event)
modifyMarkerInSel("\t", REMOVE);
else if (event->key() == Qt::Key_Return)
newLineWithInheritedIndentation();
-   else
+   else if (event->key() == Qt::Key_Escape) {
+// Ignore the ESC key so that the dialog isn't closed
+   } else
// Call base class for other events
QTextEdit::keyPressEvent(event);
 }
-- 
2.24.3 (Apple Git-128)

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: ESC Key

2023-01-22 Thread Daniel

On 2023-01-22 10:25, Evan Langlois wrote:
Is there some way to reconfigure LyX to not have ESC cancel a dialog or 
at least ask me first?  I tried to remove the keybinding for esc in the 
preferences, but that didn't help.  The issue is that I use vi, so when 
editing the preamble my hand just hits the esc key to save out of 
habit.  All my changes are then gone without a "Hey you changed stuff!  
Are you sure?"


I don't think there is a way. And I am not sure it is a common enough 
case to allow for a preference or so.


But it sounds like you would be satisfied with LyX asking whether to 
discard changes made to the preamble before cancelling the dialog. I 
think that is generally a good idea. After all, it is like editing your 
document where we also don't just let the user close the window without 
asking.


Daniel


--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel