Added aborting editing (closes #726)

This commit is contained in:
Thomas Jentzsch 2021-05-03 20:26:50 +02:00
parent 48719537ea
commit 106e9eeb89
7 changed files with 36 additions and 11 deletions

View File

@ -737,6 +737,7 @@ void DataGridWidget::startEditMode()
dialog().tooltip().hide(); dialog().tooltip().hide();
enableEditMode(true); enableEditMode(true);
setText("", true); // Erase current entry when starting editing setText("", true); // Erase current entry when starting editing
backupString() = "@@"; // dummy value to process Escape correctly key when nothing is entered
} }
} }
@ -782,6 +783,7 @@ void DataGridWidget::endEditMode()
} }
setSelectedValue(value); setSelectedValue(value);
commit();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -789,6 +791,7 @@ void DataGridWidget::abortEditMode()
{ {
if(_editMode) if(_editMode)
{ {
abort();
// Undo any changes made // Undo any changes made
assert(_selectedItem >= 0); assert(_selectedItem >= 0);
enableEditMode(false); enableEditMode(false);

View File

@ -111,6 +111,10 @@ void DebuggerDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
instance().eventHandler().enableTextEvents(false); instance().eventHandler().enableTextEvents(false);
} }
// Process widget keys first
if(_focusedWidget && _focusedWidget->handleKeyDown(key, mod))
return;
// special debugger keys first (cannot be remapped) // special debugger keys first (cannot be remapped)
if (StellaModTest::isControl(mod)) if (StellaModTest::isControl(mod))
{ {

View File

@ -627,15 +627,20 @@ void Dialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
if(e == Event::NoType) if(e == Event::NoType)
e = instance().eventHandler().eventForKey(EventMode::kMenuMode, key, mod); e = instance().eventHandler().eventForKey(EventMode::kMenuMode, key, mod);
// Unless a widget has claimed all responsibility for data, we assume // Widget events are handled *before* the dialog events
// that if an event exists for the given data, it should have priority. bool handled = false;
if(!handleNavEvent(e, repeated) && _focusedWidget)
if(_focusedWidget)
{ {
// Unless a widget has claimed all responsibility for data, we assume
// that if an event exists for the given data, it should have priority.
if(_focusedWidget->wantsRaw() || e == Event::NoType) if(_focusedWidget->wantsRaw() || e == Event::NoType)
_focusedWidget->handleKeyDown(key, mod); handled = _focusedWidget->handleKeyDown(key, mod);
else else
_focusedWidget->handleEvent(e); handled = _focusedWidget->handleEvent(e);
} }
if(!handled)
handleNavEvent(e, repeated);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -46,7 +46,7 @@ EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font,
void EditTextWidget::setText(const string& str, bool changed) void EditTextWidget::setText(const string& str, bool changed)
{ {
EditableWidget::setText(str, changed); EditableWidget::setText(str, changed);
_backupString = str;
if(_changed != changed) if(_changed != changed)
{ {
_changed = changed; _changed = changed;
@ -106,7 +106,7 @@ void EditTextWidget::lostFocusWidget()
{ {
EditableWidget::lostFocusWidget(); EditableWidget::lostFocusWidget();
// If we loose focus, 'commit' the user changes // If we loose focus, 'commit' the user changes
_backupString = editString(); commit();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -125,5 +125,5 @@ void EditTextWidget::endEditMode()
void EditTextWidget::abortEditMode() void EditTextWidget::abortEditMode()
{ {
// Editing is always enabled // Editing is always enabled
setText(_backupString); abort();
} }

View File

@ -56,7 +56,6 @@ class EditTextWidget : public EditableWidget
void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; void handleMouseDown(int x, int y, MouseButton b, int clickCount) override;
protected: protected:
string _backupString;
bool _changed{false}; bool _changed{false};
int _textOfs{0}; int _textOfs{0};

View File

@ -46,6 +46,7 @@ EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
void EditableWidget::setText(const string& str, bool changed) void EditableWidget::setText(const string& str, bool changed)
{ {
const string oldEditString = _editString; const string oldEditString = _editString;
_backupString = str;
// Filter input string // Filter input string
_editString = ""; _editString = "";
for(char c: str) for(char c: str)
@ -436,6 +437,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod)
break; break;
case Event::AbortEdit: case Event::AbortEdit:
handled = isChanged();
abortEditMode(); abortEditMode();
sendCommand(EditableWidget::kCancelCmd, 0, _id); sendCommand(EditableWidget::kCancelCmd, 0, _id);
break; break;

View File

@ -55,6 +55,7 @@ class EditableWidget : public Widget, public CommandSender
const string& getText() const { return _editString; } const string& getText() const { return _editString; }
bool isEditable() const { return _editable; } bool isEditable() const { return _editable; }
bool isChanged() { return editString() != backupString(); }
virtual void setEditable(bool editable, bool hiliteBG = false); virtual void setEditable(bool editable, bool hiliteBG = false);
bool handleText(char text) override; bool handleText(char text) override;
@ -80,8 +81,17 @@ class EditableWidget : public Widget, public CommandSender
bool wantsToolTip() const override; bool wantsToolTip() const override;
virtual void startEditMode() { setFlags(Widget::FLAG_WANTS_RAWDATA); } virtual void startEditMode() { setFlags(Widget::FLAG_WANTS_RAWDATA); }
virtual void endEditMode() { clearFlags(Widget::FLAG_WANTS_RAWDATA); } virtual void endEditMode() {
virtual void abortEditMode() { clearFlags(Widget::FLAG_WANTS_RAWDATA); } clearFlags(Widget::FLAG_WANTS_RAWDATA);
commit();
}
virtual void abortEditMode()
{
clearFlags(Widget::FLAG_WANTS_RAWDATA);
abort();
}
void commit() { _backupString = _editString; }
void abort() { setText(_backupString); }
virtual Common::Rect getEditRect() const = 0; virtual Common::Rect getEditRect() const = 0;
virtual int getCaretOffset() const; virtual int getCaretOffset() const;
@ -93,6 +103,7 @@ class EditableWidget : public Widget, public CommandSender
// This method is used internally by child classes wanting to // This method is used internally by child classes wanting to
// access/edit the internal buffer // access/edit the internal buffer
string& editString() { return _editString; } string& editString() { return _editString; }
string& backupString() { return _backupString; }
const string selectString() const; const string selectString() const;
void resetSelection() { _selectSize = 0; } void resetSelection() { _selectSize = 0; }
int scrollOffset(); int scrollOffset();
@ -125,6 +136,7 @@ class EditableWidget : public Widget, public CommandSender
bool _editable{true}; bool _editable{true};
string _editString; string _editString;
string _backupString;
int _maxLen{0}; int _maxLen{0};
unique_ptr<UndoHandler> myUndoHandler; unique_ptr<UndoHandler> myUndoHandler;