Ejemplo n.º 1
0
static void
_g_paste_clipboard_select_uris (GPasteClipboard *self,
                                GPasteUrisItem  *item)
{
    g_return_if_fail (G_PASTE_IS_CLIPBOARD (self));
    g_return_if_fail (G_PASTE_IS_URIS_ITEM (item));

    GtkClipboard *real = self->priv->real;
    GtkTargetList *target_list = gtk_target_list_new (NULL, 0);

    _g_paste_clipboard_set_text (self, g_paste_item_get_value (G_PASTE_ITEM (item)));

    gtk_target_list_add_text_targets (target_list, 0);
    gtk_target_list_add_uri_targets (target_list, 0);
    gtk_target_list_add (target_list, g_paste_clipboard_copy_files_target, 0, 0);

    gint n_targets;
    GtkTargetEntry *targets = gtk_target_table_new_from_list (target_list, &n_targets);
    gtk_clipboard_set_with_owner (real,
                                  targets,
                                  n_targets,
                                  g_paste_clipboard_get_clipboard_data,
                                  g_paste_clipboard_clear_clipboard_data,
                                  g_object_ref (item));
    gtk_clipboard_store (real);

    gtk_target_table_free (targets, n_targets);
    gtk_target_list_unref (target_list);
}
Ejemplo n.º 2
0
/**
 * g_paste_clipboard_select_text:
 * @self: a GPasteClipboard instance
 * @text: the text to select
 *
 * Put the text into the GPasteClipbaord and the intern GtkClipboard
 *
 * Returns:
 */
G_PASTE_VISIBLE void
g_paste_clipboard_select_text (GPasteClipboard *self,
                               const gchar     *text)
{
    g_return_if_fail (G_PASTE_IS_CLIPBOARD (self));
    g_return_if_fail (text != NULL);

    GtkClipboard *real = self->priv->real;

    _g_paste_clipboard_set_text (self, text);
    gtk_clipboard_set_text (real, text, -1);
    gtk_clipboard_store (real);
}
Ejemplo n.º 3
0
/**
 * g_paste_clipboard_set_text:
 * @self: a GPasteClipboard instance
 *
 * Put the text from the intern GtkClipboard in the GPasteClipboard
 *
 * Returns: The new text if it was modified, or NULL
 */
G_PASTE_VISIBLE const gchar *
g_paste_clipboard_set_text (GPasteClipboard *self)
{
    g_return_val_if_fail (G_PASTE_IS_CLIPBOARD (self), NULL);

    GPasteClipboardPrivate *priv = self->priv;
    gchar *text = gtk_clipboard_wait_for_text (priv->real);

    if (!text)
        return NULL;

    GPasteSettings *settings = priv->settings;
    gchar *stripped = g_strstrip (g_strdup (text));
    gboolean trim_items = g_paste_settings_get_trim_items (settings);
    const gchar *to_add = trim_items ? stripped : text;
    const gchar *ret = NULL;
    guint length = strlen (to_add);

    if (length < g_paste_settings_get_min_text_item_size (settings) ||
        length > g_paste_settings_get_max_text_item_size (settings) ||
        strlen (stripped) == 0 ||
        (priv->text &&
            g_strcmp0 (priv->text, to_add) == 0))
                goto ignore;

    if (trim_items &&
        priv->target == GDK_SELECTION_CLIPBOARD &&
        g_strcmp0 (text, stripped) != 0)
            g_paste_clipboard_select_text (self, stripped);
    else
        _g_paste_clipboard_set_text (self, to_add);

    ret = priv->text;

ignore:
    g_free (stripped);
    g_free (text);

    return ret;
}