mirror of https://github.com/stella-emu/stella.git
some minor EditableWidget enhancements and code cosmetics
This commit is contained in:
parent
5fd48d8a99
commit
f550d727ce
|
@ -12,6 +12,13 @@
|
||||||
Release History
|
Release History
|
||||||
===========================================================================
|
===========================================================================
|
||||||
|
|
||||||
|
6.4 to 6.5 (December XX, 2020)
|
||||||
|
|
||||||
|
* Enhanced cut/copy/paste to allow selecting text (TODO: PromptWidget, doc)
|
||||||
|
|
||||||
|
-Have fun!
|
||||||
|
|
||||||
|
|
||||||
6.3 to 6.4 (November 2, 2020)
|
6.3 to 6.4 (November 2, 2020)
|
||||||
|
|
||||||
* Added basic (entire and single line only) text cut/copy and paste.
|
* Added basic (entire and single line only) text cut/copy and paste.
|
||||||
|
@ -42,8 +49,6 @@
|
||||||
* Fixed bug in ROM launcher, with last ROM selected not being remembered
|
* Fixed bug in ROM launcher, with last ROM selected not being remembered
|
||||||
when exiting and re-entering a directory.
|
when exiting and re-entering a directory.
|
||||||
|
|
||||||
-Have fun!
|
|
||||||
|
|
||||||
|
|
||||||
6.2.1 to 6.3 (October 7, 2020)
|
6.2.1 to 6.3 (October 7, 2020)
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,6 @@
|
||||||
#include "EventHandler.hxx"
|
#include "EventHandler.hxx"
|
||||||
#include "EditableWidget.hxx"
|
#include "EditableWidget.hxx"
|
||||||
|
|
||||||
// Uncomment the following to give full-line cut/copy/paste
|
|
||||||
// Note that this will be removed eventually, when we implement proper cut/copy/paste
|
|
||||||
#define PSEUDO_CUT_COPY_PASTE
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
|
EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
int x, int y, int w, int h, const string& str)
|
int x, int y, int w, int h, const string& str)
|
||||||
|
@ -148,7 +144,7 @@ bool EditableWidget::handleControlKeys(StellaKey key, StellaMod mod)
|
||||||
|
|
||||||
case KBDK_C:
|
case KBDK_C:
|
||||||
case KBDK_INSERT:
|
case KBDK_INSERT:
|
||||||
copySelectedText();
|
handled = copySelectedText();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_E:
|
case KBDK_E:
|
||||||
|
@ -175,7 +171,8 @@ bool EditableWidget::handleControlKeys(StellaKey key, StellaMod mod)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_V:
|
case KBDK_V:
|
||||||
pasteSelectedText();
|
handled = pasteSelectedText();
|
||||||
|
if(handled)
|
||||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -185,7 +182,8 @@ bool EditableWidget::handleControlKeys(StellaKey key, StellaMod mod)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_X:
|
case KBDK_X:
|
||||||
cutSelectedText();
|
handled = cutSelectedText();
|
||||||
|
if(handled)
|
||||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -221,12 +219,14 @@ bool EditableWidget::handleShiftKeys(StellaKey key)
|
||||||
{
|
{
|
||||||
case KBDK_DELETE:
|
case KBDK_DELETE:
|
||||||
case KBDK_KP_PERIOD:
|
case KBDK_KP_PERIOD:
|
||||||
cutSelectedText();
|
handled = cutSelectedText();
|
||||||
|
if(handled)
|
||||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_INSERT:
|
case KBDK_INSERT:
|
||||||
pasteSelectedText();
|
handled = pasteSelectedText();
|
||||||
|
if(handled)
|
||||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -662,31 +662,48 @@ bool EditableWidget::killSelectedText()
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EditableWidget::cutSelectedText()
|
bool EditableWidget::cutSelectedText()
|
||||||
{
|
{
|
||||||
#if defined(PSEUDO_CUT_COPY_PASTE)
|
string selected = selectString();
|
||||||
instance().eventHandler().copyText(selectString());
|
|
||||||
|
// only cut and copy if anything is selected, else keep old cut text
|
||||||
|
if(!selected.empty())
|
||||||
|
{
|
||||||
|
instance().eventHandler().copyText(selected);
|
||||||
killSelectedText();
|
killSelectedText();
|
||||||
#endif
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EditableWidget::copySelectedText()
|
bool EditableWidget::copySelectedText()
|
||||||
{
|
{
|
||||||
#if defined(PSEUDO_CUT_COPY_PASTE)
|
string selected = selectString();
|
||||||
instance().eventHandler().copyText(selectString());
|
|
||||||
#endif
|
// only copy if anything is selected, else keep old copied text
|
||||||
|
if(!selected.empty())
|
||||||
|
{
|
||||||
|
instance().eventHandler().copyText(selected);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EditableWidget::pasteSelectedText()
|
bool EditableWidget::pasteSelectedText()
|
||||||
{
|
{
|
||||||
#if defined(PSEUDO_CUT_COPY_PASTE)
|
bool selected = !selectString().empty();
|
||||||
string text;
|
string pasted;
|
||||||
|
|
||||||
instance().eventHandler().pasteText(text);
|
// retrieve the pasted text
|
||||||
|
instance().eventHandler().pasteText(pasted);
|
||||||
|
// remove the currently selected text
|
||||||
killSelectedText();
|
killSelectedText();
|
||||||
_editString.insert(_caretPos, text);
|
// insert paste text instead
|
||||||
_caretPos += int(text.length());
|
_editString.insert(_caretPos, pasted);
|
||||||
#endif
|
// position cursor at the end of pasted text
|
||||||
|
_caretPos += int(pasted.length());
|
||||||
|
|
||||||
|
return selected || !pasted.empty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,9 +98,9 @@ class EditableWidget : public Widget, public CommandSender
|
||||||
int selectStartPos();
|
int selectStartPos();
|
||||||
int selectEndPos();
|
int selectEndPos();
|
||||||
// Clipboard
|
// Clipboard
|
||||||
void cutSelectedText();
|
bool cutSelectedText();
|
||||||
void copySelectedText();
|
bool copySelectedText();
|
||||||
void pasteSelectedText();
|
bool pasteSelectedText();
|
||||||
|
|
||||||
// Use the current TextFilter to insert a character into the
|
// Use the current TextFilter to insert a character into the
|
||||||
// internal buffer
|
// internal buffer
|
||||||
|
|
Loading…
Reference in New Issue