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();
enableEditMode(true);
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);
commit();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -789,6 +791,7 @@ void DataGridWidget::abortEditMode()
{
if(_editMode)
{
abort();
// Undo any changes made
assert(_selectedItem >= 0);
enableEditMode(false);

View File

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

View File

@ -627,15 +627,20 @@ void Dialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
if(e == Event::NoType)
e = instance().eventHandler().eventForKey(EventMode::kMenuMode, key, mod);
// 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(!handleNavEvent(e, repeated) && _focusedWidget)
// Widget events are handled *before* the dialog events
bool handled = false;
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)
_focusedWidget->handleKeyDown(key, mod);
handled = _focusedWidget->handleKeyDown(key, mod);
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)
{
EditableWidget::setText(str, changed);
_backupString = str;
if(_changed != changed)
{
_changed = changed;
@ -106,7 +106,7 @@ void EditTextWidget::lostFocusWidget()
{
EditableWidget::lostFocusWidget();
// If we loose focus, 'commit' the user changes
_backupString = editString();
commit();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -125,5 +125,5 @@ void EditTextWidget::endEditMode()
void EditTextWidget::abortEditMode()
{
// 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;
protected:
string _backupString;
bool _changed{false};
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)
{
const string oldEditString = _editString;
_backupString = str;
// Filter input string
_editString = "";
for(char c: str)
@ -436,6 +437,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod)
break;
case Event::AbortEdit:
handled = isChanged();
abortEditMode();
sendCommand(EditableWidget::kCancelCmd, 0, _id);
break;

View File

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