mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[ion/clipboard] Use system clipboard on simulator
Add methods to interface Epsilon's clipboard with the system's when running a simulator. Note that the clipboard still uses a buffer located in the Escher::Clipboard class, as some features require a buffer to execute computations on the clipboard's content. Change-Id: I14c19615805d38735e64d481c617863db22db9bc
This commit is contained in:
committed by
Émilie Feral
parent
6ba88921b9
commit
b9c34ace3a
@@ -1,5 +1,6 @@
|
||||
#include <escher/clipboard.h>
|
||||
#include <escher/text_field.h>
|
||||
#include <ion/clipboard.h>
|
||||
#include <algorithm>
|
||||
|
||||
static Clipboard s_clipboard;
|
||||
@@ -10,9 +11,12 @@ Clipboard * Clipboard::sharedClipboard() {
|
||||
|
||||
void Clipboard::store(const char * storedText, int length) {
|
||||
strlcpy(m_textBuffer, storedText, length == -1 ? TextField::maxBufferSize() : std::min(TextField::maxBufferSize(), length + 1));
|
||||
Ion::Clipboard::write(m_textBuffer);
|
||||
}
|
||||
|
||||
const char * Clipboard::storedText() {
|
||||
Ion::Clipboard::read(m_textBuffer, TextField::maxBufferSize());
|
||||
|
||||
/* In order to allow copy/paste of empty formulas, we need to add empty
|
||||
* layouts between empty system parenthesis. This way, when the expression
|
||||
* is parsed, it is recognized as a proper formula and appears with the correct
|
||||
@@ -39,6 +43,8 @@ const char * Clipboard::storedText() {
|
||||
|
||||
void Clipboard::reset() {
|
||||
strlcpy(m_textBuffer, "", 1);
|
||||
/* As we do not want to empty the user's computer's clipboard when entering
|
||||
* exam mode, we do not reset Ion::Clipboard. */
|
||||
}
|
||||
|
||||
void Clipboard::replaceCharForPython(bool entersPythonApp) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <ion/backlight.h>
|
||||
#include <ion/battery.h>
|
||||
#include <ion/clipboard.h>
|
||||
#include <ion/console.h>
|
||||
#include <ion/display.h>
|
||||
#include <ion/events.h>
|
||||
|
||||
18
ion/include/ion/clipboard.h
Normal file
18
ion/include/ion/clipboard.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef ION_CLIPBOARD_H
|
||||
#define ION_CLIPBOARD_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Clipboard {
|
||||
|
||||
/* Write the text to the system clipboard. */
|
||||
void write(const char * text);
|
||||
|
||||
/* Fill the buffer with text from the system clipboard. */
|
||||
void read(char * buffer, size_t bufferSize);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@ ion_device_src += $(addprefix ion/src/device/shared/drivers/, \
|
||||
battery.cpp \
|
||||
base64.cpp \
|
||||
board.cpp \
|
||||
clipboard.cpp \
|
||||
console_uart.cpp:+consoleuart \
|
||||
console_dummy.cpp:-consoleuart \
|
||||
crc32.cpp \
|
||||
|
||||
11
ion/src/device/shared/drivers/clipboard.cpp
Normal file
11
ion/src/device/shared/drivers/clipboard.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <ion/clipboard.h>
|
||||
|
||||
namespace Ion {
|
||||
|
||||
/* Dummy implementation
|
||||
* On the device, the clipboard is fully handled by Escher::Clipboard. */
|
||||
|
||||
void Clipboard::write(const char * text) {}
|
||||
void Clipboard::read(char * buffer, size_t bufferSize) {}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ ion_src += $(addprefix ion/src/simulator/shared/, \
|
||||
dummy/serial_number.cpp \
|
||||
dummy/stack.cpp \
|
||||
dummy/usb.cpp \
|
||||
clipboard.cpp \
|
||||
console_stdio.cpp:-consoledisplay \
|
||||
crc32.cpp \
|
||||
display.cpp:-headless \
|
||||
|
||||
24
ion/src/simulator/shared/clipboard.cpp
Normal file
24
ion/src/simulator/shared/clipboard.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <ion/clipboard.h>
|
||||
#include <SDL.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace Ion {
|
||||
|
||||
void Clipboard::write(const char * text) {
|
||||
/* FIXME : Handle the error if need be. */
|
||||
SDL_SetClipboardText(text);
|
||||
}
|
||||
|
||||
void Clipboard::read(char * buffer, size_t bufferSize) {
|
||||
if (!SDL_HasClipboardText()) {
|
||||
buffer[0] = '\0';
|
||||
return;
|
||||
}
|
||||
char * text = SDL_GetClipboardText();
|
||||
if (text) {
|
||||
strlcpy(buffer, text, bufferSize);
|
||||
SDL_free(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user