-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule libclipboard
added at
3d2cb0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "clipboard.h" | ||
#include <libclipboard.h> | ||
|
||
Clipboard::Clipboard() | ||
{ | ||
cb = clipboard_new(nullptr); | ||
} | ||
|
||
Clipboard::~Clipboard() | ||
{ | ||
clipboard_free(cb); | ||
} | ||
|
||
void Clipboard::syncSetText(std::string_view text) | ||
{ | ||
if (cb) | ||
clipboard_set_text_ex(cb, text.data(), (int) text.size(), LCB_CLIPBOARD); | ||
} | ||
|
||
const char* Clipboard::syncGetText() | ||
{ | ||
if (cb) | ||
return clipboard_text(cb); | ||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef TURBO_CLIPBOARD_H | ||
#define TURBO_CLIPBOARD_H | ||
|
||
#include <ScintillaHeaders.h> | ||
#include <string_view> | ||
#include <cstdlib> | ||
|
||
class Clipboard { | ||
|
||
Scintilla::SelectionText selText; | ||
struct clipboard_c *cb; | ||
|
||
void syncSetText(std::string_view); | ||
const char* syncGetText(); | ||
|
||
public: | ||
|
||
Clipboard(); | ||
~Clipboard(); | ||
|
||
template <class Func> | ||
void copy(Func &&fillSel) | ||
{ | ||
fillSel(selText); | ||
syncSetText({selText.Data(), selText.Length()}); | ||
} | ||
|
||
template <class Func> | ||
void paste(Func &&fillSel) | ||
{ | ||
auto *data = syncGetText(); | ||
std::string_view text; | ||
if (data) | ||
text = data; | ||
else | ||
text = {selText.Data(), selText.Length()}; | ||
fillSel(selText, text); | ||
::free((void *) data); | ||
} | ||
|
||
}; | ||
|
||
#endif // TURBO_CLIPBOARD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters