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
|
||||
===========================================================================
|
||||
|
||||
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)
|
||||
|
||||
* 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
|
||||
when exiting and re-entering a directory.
|
||||
|
||||
-Have fun!
|
||||
|
||||
|
||||
6.2.1 to 6.3 (October 7, 2020)
|
||||
|
||||
|
|
|
@ -23,10 +23,6 @@
|
|||
#include "EventHandler.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,
|
||||
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_INSERT:
|
||||
copySelectedText();
|
||||
handled = copySelectedText();
|
||||
break;
|
||||
|
||||
case KBDK_E:
|
||||
|
@ -175,7 +171,8 @@ bool EditableWidget::handleControlKeys(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_V:
|
||||
pasteSelectedText();
|
||||
handled = pasteSelectedText();
|
||||
if(handled)
|
||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||
break;
|
||||
|
||||
|
@ -185,7 +182,8 @@ bool EditableWidget::handleControlKeys(StellaKey key, StellaMod mod)
|
|||
break;
|
||||
|
||||
case KBDK_X:
|
||||
cutSelectedText();
|
||||
handled = cutSelectedText();
|
||||
if(handled)
|
||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||
break;
|
||||
|
||||
|
@ -221,12 +219,14 @@ bool EditableWidget::handleShiftKeys(StellaKey key)
|
|||
{
|
||||
case KBDK_DELETE:
|
||||
case KBDK_KP_PERIOD:
|
||||
cutSelectedText();
|
||||
handled = cutSelectedText();
|
||||
if(handled)
|
||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||
break;
|
||||
|
||||
case KBDK_INSERT:
|
||||
pasteSelectedText();
|
||||
handled = pasteSelectedText();
|
||||
if(handled)
|
||||
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||
break;
|
||||
|
||||
|
@ -662,31 +662,48 @@ bool EditableWidget::killSelectedText()
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditableWidget::cutSelectedText()
|
||||
bool EditableWidget::cutSelectedText()
|
||||
{
|
||||
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||
instance().eventHandler().copyText(selectString());
|
||||
string selected = selectString();
|
||||
|
||||
// only cut and copy if anything is selected, else keep old cut text
|
||||
if(!selected.empty())
|
||||
{
|
||||
instance().eventHandler().copyText(selected);
|
||||
killSelectedText();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EditableWidget::copySelectedText()
|
||||
bool EditableWidget::copySelectedText()
|
||||
{
|
||||
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||
instance().eventHandler().copyText(selectString());
|
||||
#endif
|
||||
string selected = selectString();
|
||||
|
||||
// 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)
|
||||
string text;
|
||||
bool selected = !selectString().empty();
|
||||
string pasted;
|
||||
|
||||
instance().eventHandler().pasteText(text);
|
||||
// retrieve the pasted text
|
||||
instance().eventHandler().pasteText(pasted);
|
||||
// remove the currently selected text
|
||||
killSelectedText();
|
||||
_editString.insert(_caretPos, text);
|
||||
_caretPos += int(text.length());
|
||||
#endif
|
||||
// insert paste text instead
|
||||
_editString.insert(_caretPos, pasted);
|
||||
// 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 selectEndPos();
|
||||
// Clipboard
|
||||
void cutSelectedText();
|
||||
void copySelectedText();
|
||||
void pasteSelectedText();
|
||||
bool cutSelectedText();
|
||||
bool copySelectedText();
|
||||
bool pasteSelectedText();
|
||||
|
||||
// Use the current TextFilter to insert a character into the
|
||||
// internal buffer
|
||||
|
|
Loading…
Reference in New Issue