Fixed bug: clipboard contents was lost on closing view; improved scrolling to given line when opening a document
This commit is contained in:
parent
e4855e112e
commit
5b03ad1c08
@ -67,7 +67,7 @@
|
|||||||
* But, e.g. if we have a big file, and scroll down, we do want the engine
|
* But, e.g. if we have a big file, and scroll down, we do want the engine
|
||||||
* to analyze quickly. Perhaps we want to reinstall first_update in case
|
* to analyze quickly. Perhaps we want to reinstall first_update in case
|
||||||
* of expose events or something. */
|
* of expose events or something. */
|
||||||
#define INCREMENTAL_UPDATE_PRIORITY G_PRIORITY_LOW
|
#define INCREMENTAL_UPDATE_PRIORITY GTK_TEXT_VIEW_PRIORITY_VALIDATE
|
||||||
/* Maximal amount of time allowed to spent in one cycle of background idle. */
|
/* Maximal amount of time allowed to spent in one cycle of background idle. */
|
||||||
#define INCREMENTAL_UPDATE_TIME_SLICE 30
|
#define INCREMENTAL_UPDATE_TIME_SLICE 30
|
||||||
|
|
||||||
|
@ -83,6 +83,11 @@ typedef enum {
|
|||||||
MOO_TEXT_VIEW_N_COLORS
|
MOO_TEXT_VIEW_N_COLORS
|
||||||
} MooTextViewColor;
|
} MooTextViewColor;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MooTextView *view;
|
||||||
|
char *text;
|
||||||
|
} MooTextViewClipboard;
|
||||||
|
|
||||||
struct _MooTextViewPrivate {
|
struct _MooTextViewPrivate {
|
||||||
gboolean constructed;
|
gboolean constructed;
|
||||||
|
|
||||||
@ -93,6 +98,7 @@ struct _MooTextViewPrivate {
|
|||||||
|
|
||||||
/* Clipboard */
|
/* Clipboard */
|
||||||
gboolean manage_clipboard;
|
gboolean manage_clipboard;
|
||||||
|
MooTextViewClipboard *clipboard;
|
||||||
|
|
||||||
#if !GTK_CHECK_VERSION(2,12,0)
|
#if !GTK_CHECK_VERSION(2,12,0)
|
||||||
/* Overwrite mode cursor */
|
/* Overwrite mode cursor */
|
||||||
|
@ -789,6 +789,12 @@ moo_text_view_dispose (GObject *object)
|
|||||||
GSList *l;
|
GSList *l;
|
||||||
MooTextView *view = MOO_TEXT_VIEW (object);
|
MooTextView *view = MOO_TEXT_VIEW (object);
|
||||||
|
|
||||||
|
if (view->priv->clipboard)
|
||||||
|
{
|
||||||
|
view->priv->clipboard->view = NULL;
|
||||||
|
view->priv->clipboard = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (view->priv->indenter)
|
if (view->priv->indenter)
|
||||||
{
|
{
|
||||||
g_object_unref (view->priv->indenter);
|
g_object_unref (view->priv->indenter);
|
||||||
@ -1617,7 +1623,8 @@ moo_text_view_move_cursor (gpointer view,
|
|||||||
|
|
||||||
mview = MOO_TEXT_VIEW (view);
|
mview = MOO_TEXT_VIEW (view);
|
||||||
mview->priv->move_cursor_idle =
|
mview->priv->move_cursor_idle =
|
||||||
moo_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
moo_idle_add_full (G_PRIORITY_HIGH_IDLE + 9, /* between gtktextview's first validate priority and
|
||||||
|
* GTK_PRIORITY_RESIZE */
|
||||||
(GSourceFunc) do_move_cursor,
|
(GSourceFunc) do_move_cursor,
|
||||||
g_memdup (&scroll, sizeof scroll),
|
g_memdup (&scroll, sizeof scroll),
|
||||||
g_free);
|
g_free);
|
||||||
@ -1891,33 +1898,30 @@ static void
|
|||||||
get_clipboard (G_GNUC_UNUSED GtkClipboard *clipboard,
|
get_clipboard (G_GNUC_UNUSED GtkClipboard *clipboard,
|
||||||
GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
guint info,
|
guint info,
|
||||||
gpointer view)
|
gpointer data)
|
||||||
{
|
{
|
||||||
char **contents;
|
MooTextViewClipboard *contents = data;
|
||||||
char *text;
|
|
||||||
|
|
||||||
if (info == TARGET_MOO_TEXT_VIEW)
|
if (info == TARGET_MOO_TEXT_VIEW)
|
||||||
{
|
|
||||||
moo_selection_data_set_pointer (selection_data,
|
moo_selection_data_set_pointer (selection_data,
|
||||||
gdk_atom_intern ("MOO_TEXT_VIEW", FALSE),
|
gdk_atom_intern ("MOO_TEXT_VIEW", FALSE),
|
||||||
view);
|
contents->view);
|
||||||
return;
|
else
|
||||||
}
|
gtk_selection_data_set_text (selection_data, contents->text, -1);
|
||||||
|
|
||||||
contents = g_object_get_data (view, "moo-text-view-clipboard");
|
|
||||||
g_return_if_fail (contents != NULL);
|
|
||||||
|
|
||||||
text = g_strjoinv ("", contents);
|
|
||||||
gtk_selection_data_set_text (selection_data, text, -1);
|
|
||||||
g_free (text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clear_clipboard (G_GNUC_UNUSED GtkClipboard *clipboard,
|
clear_clipboard (G_GNUC_UNUSED GtkClipboard *clipboard,
|
||||||
gpointer view)
|
gpointer data)
|
||||||
{
|
{
|
||||||
g_object_set_data (view, "moo-text-view-clipboard", NULL);
|
MooTextViewClipboard *contents = data;
|
||||||
|
|
||||||
|
if (contents->view && contents->view->priv->clipboard == contents)
|
||||||
|
contents->view->priv->clipboard = NULL;
|
||||||
|
|
||||||
|
g_free (contents->text);
|
||||||
|
moo_free (MooTextViewClipboard, contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1927,27 +1931,29 @@ moo_text_view_cut_or_copy (GtkTextView *text_view,
|
|||||||
{
|
{
|
||||||
GtkTextBuffer *buffer;
|
GtkTextBuffer *buffer;
|
||||||
GtkTextIter start, end;
|
GtkTextIter start, end;
|
||||||
char *text;
|
|
||||||
char **pieces;
|
|
||||||
GtkClipboard *clipboard;
|
GtkClipboard *clipboard;
|
||||||
|
MooTextViewClipboard *contents;
|
||||||
|
MooTextView *view = MOO_TEXT_VIEW (text_view);
|
||||||
|
|
||||||
buffer = gtk_text_view_get_buffer (text_view);
|
buffer = gtk_text_view_get_buffer (text_view);
|
||||||
|
|
||||||
if (!gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
if (!gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
text = gtk_text_buffer_get_slice (buffer, &start, &end, TRUE);
|
|
||||||
pieces = g_strsplit (text, MOO_TEXT_UNKNOWN_CHAR_S, 0);
|
|
||||||
g_object_set_data_full (G_OBJECT (text_view), "moo-text-view-clipboard",
|
|
||||||
pieces, (GDestroyNotify) g_strfreev);
|
|
||||||
g_free (text);
|
|
||||||
|
|
||||||
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
|
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (text_view),
|
||||||
GDK_SELECTION_CLIPBOARD);
|
GDK_SELECTION_CLIPBOARD);
|
||||||
|
|
||||||
if (!gtk_clipboard_set_with_owner (clipboard, targets, G_N_ELEMENTS (targets),
|
contents = moo_new0 (MooTextViewClipboard);
|
||||||
get_clipboard, clear_clipboard,
|
contents->text = gtk_text_buffer_get_slice (buffer, &start, &end, TRUE);
|
||||||
G_OBJECT (text_view)))
|
contents->view = view;
|
||||||
|
|
||||||
|
if (view->priv->clipboard)
|
||||||
|
view->priv->clipboard->view = NULL;
|
||||||
|
view->priv->clipboard = contents;
|
||||||
|
|
||||||
|
if (!gtk_clipboard_set_with_data (clipboard, targets, G_N_ELEMENTS (targets),
|
||||||
|
get_clipboard, clear_clipboard,
|
||||||
|
contents))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gtk_clipboard_set_can_store (clipboard, targets + 1,
|
gtk_clipboard_set_can_store (clipboard, targets + 1,
|
||||||
@ -1984,23 +1990,37 @@ paste_moo_text_view_content (GtkTextView *target,
|
|||||||
{
|
{
|
||||||
GtkTextBuffer *buffer;
|
GtkTextBuffer *buffer;
|
||||||
GtkTextIter start, end;
|
GtkTextIter start, end;
|
||||||
char **contents, **p;
|
MooTextViewClipboard *contents;
|
||||||
|
|
||||||
g_return_if_fail (MOO_IS_TEXT_VIEW (source));
|
g_return_if_fail (MOO_IS_TEXT_VIEW (source));
|
||||||
|
|
||||||
buffer = gtk_text_view_get_buffer (target);
|
buffer = gtk_text_view_get_buffer (target);
|
||||||
|
|
||||||
contents = g_object_get_data (G_OBJECT (source), "moo-text-view-clipboard");
|
contents = source->priv->clipboard;
|
||||||
g_return_if_fail (contents != NULL);
|
g_return_if_fail (contents != NULL);
|
||||||
|
|
||||||
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
|
||||||
gtk_text_buffer_delete (buffer, &start, &end);
|
gtk_text_buffer_delete (buffer, &start, &end);
|
||||||
|
|
||||||
for (p = contents; *p; ++p)
|
if (strstr (contents->text, MOO_TEXT_UNKNOWN_CHAR_S))
|
||||||
{
|
{
|
||||||
if (p != contents)
|
char **pieces, **p;
|
||||||
moo_text_view_insert_placeholder (MOO_TEXT_VIEW (target), &end, NULL);
|
|
||||||
gtk_text_buffer_insert (buffer, &end, *p, -1);
|
pieces = g_strsplit (contents->text, MOO_TEXT_UNKNOWN_CHAR_S, 0);
|
||||||
|
|
||||||
|
for (p = pieces; *p; ++p)
|
||||||
|
{
|
||||||
|
if (p != pieces)
|
||||||
|
moo_text_view_insert_placeholder (MOO_TEXT_VIEW (target), &end, NULL);
|
||||||
|
|
||||||
|
gtk_text_buffer_insert (buffer, &end, *p, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev (pieces);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_text_buffer_insert (buffer, &end, contents->text, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user