mirror of https://github.com/stella-emu/stella.git
Added basic (entire and single line only) text cut/copy and paste (partially implements #105)
This commit is contained in:
parent
e0d92192a9
commit
338116018b
|
@ -12,6 +12,11 @@
|
||||||
Release History
|
Release History
|
||||||
===========================================================================
|
===========================================================================
|
||||||
|
|
||||||
|
6.3 to 6.4 (XXXX XX, 202X)
|
||||||
|
|
||||||
|
* Added basic (entire and single line only) text cut/copy and paste
|
||||||
|
|
||||||
|
|
||||||
6.2.1 to 6.3 (October 7, 2020)
|
6.2.1 to 6.3 (October 7, 2020)
|
||||||
|
|
||||||
* Added adjustable autofire.
|
* Added adjustable autofire.
|
||||||
|
|
|
@ -1883,8 +1883,9 @@
|
||||||
<tr><td>Control + w</td><td>Remove entire word to left of cursor</td></tr>
|
<tr><td>Control + w</td><td>Remove entire word to left of cursor</td></tr>
|
||||||
<tr><td>Control + Left</td><td>Move cursor to beginning of word to the left</td></tr>
|
<tr><td>Control + Left</td><td>Move cursor to beginning of word to the left</td></tr>
|
||||||
<tr><td>Control + Right</td><td>Move cursor to beginning of word to the right</td></tr>
|
<tr><td>Control + Right</td><td>Move cursor to beginning of word to the right</td></tr>
|
||||||
<tr><td>Control + c</td><td>Copy entire line to clipboard (not complete)</td></tr>
|
<tr><td>Control + c</td><td>Copy entire line to clipboard</td></tr>
|
||||||
<tr><td>Control + v</td><td>Paste clipboard contents (not complete)</td></tr>
|
<tr><td>Control + v</td><td>Paste clipboard contents</td></tr>
|
||||||
|
<tr><td>Control + x</td><td>Cut entire line to clipboard</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</blockquote></br>
|
</blockquote></br>
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,30 @@ void EventHandlerSDL2::enableTextEvents(bool enable)
|
||||||
SDL_StopTextInput();
|
SDL_StopTextInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void EventHandlerSDL2::copyText(const string& text) const
|
||||||
|
{
|
||||||
|
SDL_SetClipboardText(text.c_str());
|
||||||
|
};
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void EventHandlerSDL2::cutText(string& text) const
|
||||||
|
{
|
||||||
|
copyText(text);
|
||||||
|
text = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
string EventHandlerSDL2::pasteText(string& text) const
|
||||||
|
{
|
||||||
|
if(SDL_HasClipboardText())
|
||||||
|
text = SDL_GetClipboardText();
|
||||||
|
else
|
||||||
|
text = "";
|
||||||
|
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EventHandlerSDL2::pollEvent()
|
void EventHandlerSDL2::pollEvent()
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,12 +38,19 @@ class EventHandlerSDL2 : public EventHandler
|
||||||
explicit EventHandlerSDL2(OSystem& osystem);
|
explicit EventHandlerSDL2(OSystem& osystem);
|
||||||
~EventHandlerSDL2() override;
|
~EventHandlerSDL2() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
Enable/disable text events (distinct from single-key events).
|
Enable/disable text events (distinct from single-key events).
|
||||||
*/
|
*/
|
||||||
void enableTextEvents(bool enable) override;
|
void enableTextEvents(bool enable) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clipboard methods.
|
||||||
|
*/
|
||||||
|
void copyText(const string& text) const override;
|
||||||
|
void cutText(string& text) const override;
|
||||||
|
string pasteText(string& text) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Collects and dispatches any pending SDL2 events.
|
Collects and dispatches any pending SDL2 events.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,12 +24,17 @@
|
||||||
#include "Debugger.hxx"
|
#include "Debugger.hxx"
|
||||||
#include "DebuggerDialog.hxx"
|
#include "DebuggerDialog.hxx"
|
||||||
#include "DebuggerParser.hxx"
|
#include "DebuggerParser.hxx"
|
||||||
|
#include "EventHandler.hxx"
|
||||||
|
|
||||||
#include "PromptWidget.hxx"
|
#include "PromptWidget.hxx"
|
||||||
#include "CartDebug.hxx"
|
#include "CartDebug.hxx"
|
||||||
|
|
||||||
#define PROMPT "> "
|
#define PROMPT "> "
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
// TODO: Github issue #361
|
// TODO: Github issue #361
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
PromptWidget::PromptWidget(GuiObject* boss, const GUI::Font& font,
|
PromptWidget::PromptWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
|
@ -673,19 +678,61 @@ void PromptWidget::textSelectAll()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
string PromptWidget::getLine()
|
||||||
|
{
|
||||||
|
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||||
|
assert(_promptEndPos >= _promptStartPos);
|
||||||
|
int len = _promptEndPos - _promptStartPos;
|
||||||
|
string text;
|
||||||
|
|
||||||
|
// Copy current line to text
|
||||||
|
for(int i = 0; i < len; i++)
|
||||||
|
text += buffer(_promptStartPos + i) & 0x7f;
|
||||||
|
|
||||||
|
return text;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PromptWidget::textCut()
|
void PromptWidget::textCut()
|
||||||
{
|
{
|
||||||
|
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||||
|
string text = getLine();
|
||||||
|
|
||||||
|
instance().eventHandler().cutText(text);
|
||||||
|
|
||||||
|
// Remove the current line
|
||||||
|
_currentPos = _promptStartPos;
|
||||||
|
killLine(1); // to end of line
|
||||||
|
_promptEndPos = _currentPos;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PromptWidget::textCopy()
|
void PromptWidget::textCopy()
|
||||||
{
|
{
|
||||||
|
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||||
|
string text = getLine();
|
||||||
|
|
||||||
|
instance().eventHandler().copyText(text);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PromptWidget::textPaste()
|
void PromptWidget::textPaste()
|
||||||
{
|
{
|
||||||
|
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||||
|
string text;
|
||||||
|
|
||||||
|
// Remove the current line
|
||||||
|
_currentPos = _promptStartPos;
|
||||||
|
killLine(1); // to end of line
|
||||||
|
|
||||||
|
instance().eventHandler().pasteText(text);
|
||||||
|
print(text);
|
||||||
|
_promptEndPos = _currentPos;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -72,6 +72,7 @@ class PromptWidget : public Widget, public CommandSender
|
||||||
|
|
||||||
// Clipboard
|
// Clipboard
|
||||||
void textSelectAll();
|
void textSelectAll();
|
||||||
|
string getLine();
|
||||||
void textCut();
|
void textCut();
|
||||||
void textCopy();
|
void textCopy();
|
||||||
void textPaste();
|
void textPaste();
|
||||||
|
|
|
@ -326,6 +326,13 @@ class EventHandler
|
||||||
*/
|
*/
|
||||||
virtual void enableTextEvents(bool enable) = 0;
|
virtual void enableTextEvents(bool enable) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clipboard methods.
|
||||||
|
*/
|
||||||
|
virtual void copyText(const string& text) const = 0;
|
||||||
|
virtual void cutText(string& text) const = 0;
|
||||||
|
virtual string pasteText(string& text) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handle changing mouse modes.
|
Handle changing mouse modes.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,11 +19,13 @@
|
||||||
#include "StellaKeys.hxx"
|
#include "StellaKeys.hxx"
|
||||||
#include "FBSurface.hxx"
|
#include "FBSurface.hxx"
|
||||||
#include "Font.hxx"
|
#include "Font.hxx"
|
||||||
|
#include "OSystem.hxx"
|
||||||
|
#include "EventHandler.hxx"
|
||||||
#include "EditableWidget.hxx"
|
#include "EditableWidget.hxx"
|
||||||
|
|
||||||
// Uncomment the following to give full-line copy/paste
|
// Uncomment the following to give full-line cut/copy/paste
|
||||||
// Note that this will be removed eventually, when we implement proper copy/paste
|
// Note that this will be removed eventually, when we implement proper cut/copy/paste
|
||||||
//#define PSEUDO_COPY_PASTE
|
#define PSEUDO_CUT_COPY_PASTE
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
|
EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
|
@ -260,7 +262,7 @@ bool EditableWidget::specialKeys(StellaKey key)
|
||||||
{
|
{
|
||||||
bool handled = true;
|
bool handled = true;
|
||||||
|
|
||||||
switch (key)
|
switch(key)
|
||||||
{
|
{
|
||||||
case KBDK_A:
|
case KBDK_A:
|
||||||
setCaretPos(0);
|
setCaretPos(0);
|
||||||
|
@ -268,7 +270,6 @@ bool EditableWidget::specialKeys(StellaKey key)
|
||||||
|
|
||||||
case KBDK_C:
|
case KBDK_C:
|
||||||
copySelectedText();
|
copySelectedText();
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_E:
|
case KBDK_E:
|
||||||
|
@ -292,7 +293,7 @@ bool EditableWidget::specialKeys(StellaKey key)
|
||||||
|
|
||||||
case KBDK_V:
|
case KBDK_V:
|
||||||
pasteSelectedText();
|
pasteSelectedText();
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_W:
|
case KBDK_W:
|
||||||
|
@ -300,6 +301,11 @@ bool EditableWidget::specialKeys(StellaKey key)
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KBDK_X:
|
||||||
|
cutSelectedText();
|
||||||
|
sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
|
break;
|
||||||
|
|
||||||
case KBDK_LEFT:
|
case KBDK_LEFT:
|
||||||
handled = moveWord(-1);
|
handled = moveWord(-1);
|
||||||
break;
|
break;
|
||||||
|
@ -445,21 +451,28 @@ bool EditableWidget::moveWord(int direction)
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void EditableWidget::cutSelectedText()
|
||||||
|
{
|
||||||
|
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||||
|
instance().eventHandler().cutText(_editString);
|
||||||
|
_caretPos = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EditableWidget::copySelectedText()
|
void EditableWidget::copySelectedText()
|
||||||
{
|
{
|
||||||
#if defined(PSEUDO_COPY_PASTE)
|
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||||
_clippedText = _editString;
|
instance().eventHandler().copyText(_editString);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EditableWidget::pasteSelectedText()
|
void EditableWidget::pasteSelectedText()
|
||||||
{
|
{
|
||||||
#if defined(PSEUDO_COPY_PASTE)
|
#if defined(PSEUDO_CUT_COPY_PASTE)
|
||||||
_editString = _clippedText;
|
instance().eventHandler().pasteText(_editString);
|
||||||
|
_caretPos = int(_editString.length());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
string EditableWidget::_clippedText = "";
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ class EditableWidget : public Widget, public CommandSender
|
||||||
bool moveWord(int direction);
|
bool moveWord(int direction);
|
||||||
|
|
||||||
// Clipboard
|
// Clipboard
|
||||||
|
void cutSelectedText();
|
||||||
void copySelectedText();
|
void copySelectedText();
|
||||||
void pasteSelectedText();
|
void pasteSelectedText();
|
||||||
|
|
||||||
|
@ -107,8 +108,6 @@ class EditableWidget : public Widget, public CommandSender
|
||||||
|
|
||||||
int _editScrollOffset{0};
|
int _editScrollOffset{0};
|
||||||
|
|
||||||
static string _clippedText;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextFilter _filter;
|
TextFilter _filter;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue