Implement copy to clipboard shortcut

This commit is contained in:
Kovid Goyal
2016-12-01 16:24:24 +05:30
parent d832561f75
commit 991d01bb68
2 changed files with 16 additions and 0 deletions

View File

@@ -266,6 +266,15 @@ set_click_cursor(Window *self, PyObject *args) {
Py_RETURN_NONE;
}
static PyObject*
set_clipboard_string(Window *self, PyObject *args) {
char *title;
if(!PyArg_ParseTuple(args, "s", &title)) return NULL;
glfwSetClipboardString(self->window, title);
Py_RETURN_NONE;
}
static PyObject*
_set_title(Window *self, PyObject *args) {
char *title;
@@ -286,6 +295,7 @@ static PyMethodDef methods[] = {
MND(set_input_mode, METH_VARARGS),
MND(is_key_pressed, METH_VARARGS),
MND(set_click_cursor, METH_VARARGS),
MND(set_clipboard_string, METH_VARARGS),
MND(make_context_current, METH_NOARGS),
{"set_title", (PyCFunction)_set_title, METH_VARARGS, ""},
{NULL} /* Sentinel */

View File

@@ -208,6 +208,12 @@ class Window:
text = text.decode('utf-8')
self.paste(text)
def copy_to_clipboard(self):
text = self.char_grid.text_for_selection()
if text:
tm = tab_manager()
tm.queue_ui_action(tm.glfw_window.set_clipboard_string, text)
def scroll_line_up(self):
self.char_grid.scroll('line', True)
glfw_post_empty_event()