Details of text_auto_copy_text:
Two clipboards exist, the so-called PRIMARY and CLIPBOARD clipboards. Xchat traditionally has copied selected text to both clipboards upon selection. Other programs copy only to the PRIMARY clipboard on selection and further to the CLIPBOARD clipboard on explicit instruction (Clicking a "Copy" dropdown menu, for instance, or using a keyboard shortcut).
When text_auto_copy_text is set to 0, xchat changes to this latter behavior. On selection, xchat copies the selected text only to the PRIMARY clipboard. The user may hit Control-Shift-C to copy text to the CLIPBOARD clipboard. Also, the Windows menu, and the Windows context submenu, adds an item, "Copy Selection", that is active when a buffer has a selection, and the user may click this item.
We chose Control-Shift-C as the keyboard shortcut for text-buffer selections because Control-C, without the Shift key, is already used for copying input-line selections.
Details of text_auto_copy_stamp:
When selecting text, xchat has examined the SHIFT key to decide whether to add timestamp to each selected line. With text_auto_copy_stamp set to 1, xchat always adds timestamp to a selected line, and does not check the SHIFT key.
Details of text_auto_copy_color:
When selecting text, xchat has examined the CONTROL key to decide whether to include color and other emphasis marks with each selected line. With text_auto_copy_color, it does this always and ignores the CONTROL key.
The bulk of the changes are in xtext.c's selection code, to test the set values and operate accordingly. The three new set value names are added to the preferences and text_auto_copy_text is defaulted to 1. The values correspond to global ints autocopy_text, autocopy_stamp, and autocopy_color. The Settings -> Preferences menu adds a section "Auto-Copy Behavior" with checkboxes for these items.
A guint32 is added to struct xtext_buffer, named clip_own_time. Functions are added to xtext.c:
common/cfgfiles.c | 4 ++ common/xchat.h | 3 + fe-gtk/fe-gtk.h | 2 - fe-gtk/maingui.c | 7 +++ fe-gtk/menu.c | 28 +++++++++++++-- fe-gtk/menu.h | 17 --------- fe-gtk/menu_id.h | 18 ++++++++++ fe-gtk/setup.c | 13 +++++++ fe-gtk/xtext.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++------ fe-gtk/xtext.h | 4 ++ 10 files changed, 163 insertions(+), 30 deletions(-)
Hunk 2: Initialized prefs.autocopy_text to 1 in load_config().
Hunk 2: In struct mymenu mymenu, changed the item for Attach/Detach, Control-I, to use GDK_i rather than GDK_I. See Hunk 4 for more.
Hunk 3: In struct mymenu mymenu, added item "_Copy Selection", with shortcut GDK_C and MENU_ID_COPY_SELECTION.
Hunk 4: In menu_create_main() at label normalitem:, changed argument 5 of the call to gtk_widget_add_accelerator(), the accel_mods argument, to be GDK_SHIFT_MASK | GDK_CONTROL_MASK if the shortcut is uppercase (GDK_C, ...), otherwise (as before) only GDK_CONTROL_MASK (GDK_i, ...). Did the case test the official way, by using g_ascii_isupper().
Hunk 5: A few lines later, added code for GDK_C that makes the widget hidden or sensitive as appropriate. It's marked hidden, with gtk_widget_hide(), if prefs.autocopy_text is TRUE. Otherwise it is shown, with gtk_widget_show(), and made sensitive or not, with gtk_widget_set_sensitive(), according to what gtk_xtext_text_is_selected() returns. This function is gone through once to produce the Menu bar and multiple times to produce the Context menu you get when you right-click on the text-buffer window.
Hunk 1: Included four more header files.
Hunk 2: In gtk_xtext_selection_render() invoked new function gtk_xtext_set_copy_selection_sensitive() to set the Windows-menu "Copy Selection" widget. I wish I could do this at the time a user drops down the Windows menu, but it seems I can't, so I do it here instead, and in several other places in xtext.c as well. See also hunks 5, 8, 9, and 10.
Hunk 3: In gtk_xtext_check_mark_stamp(), test prefs.autocopy_stamp and produce a timestamp if either it's on or the Shift key is down.
Hunk 4: This long hunk operates on gtk_xtext_set_clip_owner() and adds three new functions.
Hunk 5: In gtk_xtext_unselect(), the "Copy Selection" item is marked not sensitive.
Hunk 6: In gtk_xtext_button_release(), xtext->color_paste is marked TRUE if prefs->autocopy_color is true or if the Control key is depressed.
Hunk 7: In gtk_xtext_selection_kill(), the saved timestamp is compared with the timestamp provided at this call. If they're the same, we are being called for a selection that still exists and we shouldn't unselect. See also hunk 4.
Hunk 8: In gtk_xtext_kill_ent(), if the ent being killed is last_ent_end, mark not sensitive the "Copy Selection" item of the Windows menu.
Hunk 9: In gtk_xtext_clear(), when clearing the entire buffer, also mark not sensitive the "Copy Selection" item.
Hunk 10: In gtk_xtext_search() initialization, mark "Copy Selection" not sensitive.
Hunk 2: Added function prototypes for the three new functions described in xchat.c hunk 4.