1 Commits

Author SHA1 Message Date
4c25322757 Show text-event usage tooltips for colors 2026-07-06 09:06:59 -06:00
5 changed files with 153 additions and 1 deletions

View File

@@ -1695,6 +1695,117 @@ pevent_load (char *filename)
return 0;
}
static gboolean
text_event_uses_color (const char *text, int color)
{
const char *p;
if (!text || color < 0 || color > 31)
return FALSE;
for (p = text; *p; p++)
{
int value;
int digits;
if ((unsigned char) *p == 3)
p++;
else if (*p == '%' && p[1] == 'C')
p += 2;
else
continue;
if (!g_ascii_isdigit (*p))
{
p--;
continue;
}
value = *p - '0';
digits = 1;
if (g_ascii_isdigit (p[1]))
{
value = value * 10 + p[1] - '0';
digits = 2;
}
if (value == color)
return TRUE;
p += digits - 1;
if (*p == ',' && g_ascii_isdigit (p[1]))
{
p++;
value = *p - '0';
if (g_ascii_isdigit (p[1]))
{
value = value * 10 + p[1] - '0';
p++;
}
if (value == color)
return TRUE;
}
}
return FALSE;
}
char *
text_color_event_list (int color)
{
GString *events;
GString *tip;
int count = 0;
int line_len = 0;
int i;
events = g_string_new (NULL);
for (i = 0; i < NUM_XP; i++)
{
const char *name;
const char *text = pntevts_text[i] ? pntevts_text[i] : te[i].def;
int name_len;
if (!text_event_uses_color (text, color))
continue;
name = _(te[i].name);
name_len = strlen (name);
if (count)
{
if (line_len + name_len + 2 > 76)
{
g_string_append_c (events, '\n');
line_len = 0;
}
else
{
g_string_append (events, ", ");
line_len += 2;
}
}
g_string_append (events, name);
line_len += name_len;
count++;
}
if (!count)
{
g_string_free (events, TRUE);
return g_strdup (_("No text events use this color."));
}
tip = g_string_new (NULL);
g_string_append_printf (tip, _("Text events using this color (%d):"), count);
g_string_append_c (tip, '\n');
g_string_append (tip, events->str);
g_string_free (events, TRUE);
return g_string_free (tip, FALSE);
}
static void
pevent_check_all_loaded (void)
{

View File

@@ -53,6 +53,7 @@ int pevt_build_string (const char *input, char **output, int *max_arg);
int pevent_load (char *filename);
void pevent_make_pntevts (void);
int text_color_of (char *name);
char *text_color_event_list (int color);
void text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
time_t timestamp);
int text_emit_by_name (char *name, session *sess, time_t timestamp,

View File

@@ -50,7 +50,7 @@ zoitechat_gtk_deps = [
gtk_dep = dependency('gtk+-3.0', version: '>= 3.22')
zoitechat_theme_deps = [gtk_dep]
zoitechat_theme_deps = [gtk_dep, zoitechat_common_dep]
if host_machine.system() != 'windows'
appindicator_opt = get_option('appindicator')

View File

@@ -70,6 +70,13 @@ load_text_events (void)
{
}
char *
text_color_event_list (int color)
{
(void)color;
return g_strdup ("No text events use this color.");
}
gboolean
theme_get_color (ThemeSemanticToken token, GdkRGBA *color)
{

View File

@@ -38,6 +38,7 @@
#include "theme-runtime.h"
extern void load_text_events (void);
extern char *text_color_event_list (int color);
typedef struct
{
@@ -268,6 +269,15 @@ theme_preferences_manager_ui_free (gpointer data)
g_free (ui);
}
static char *
theme_preferences_color_events_tooltip (ThemeSemanticToken token)
{
if (token < THEME_TOKEN_MIRC_0 || token > THEME_TOKEN_MIRC_31)
return NULL;
return text_color_event_list (token - THEME_TOKEN_MIRC_0);
}
static void
theme_preferences_manager_update_preview (theme_color_manager_ui *ui)
{
@@ -884,6 +894,20 @@ theme_preferences_create_color_manager_dialog (GtkWindow *parent, gboolean *colo
if (theme_preferences_staged_get_color (token, &rgba))
theme_preferences_manager_row_apply (row, &rgba);
{
char *tip = theme_preferences_color_events_tooltip (token);
if (tip)
{
gtk_widget_set_tooltip_text (list_row, tip);
gtk_widget_set_tooltip_text (hbox, tip);
gtk_widget_set_tooltip_text (name, tip);
gtk_widget_set_tooltip_text (preview, tip);
gtk_widget_set_tooltip_text (button, tip);
gtk_widget_set_tooltip_text (entry, tip);
g_free (tip);
}
}
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (theme_preferences_manager_pick_cb), row);
g_object_set_data (G_OBJECT (button), "zoitechat-theme-color-manager-ui", ui);
@@ -1198,6 +1222,15 @@ theme_preferences_create_color_button (GtkWidget *table,
g_object_set_data (G_OBJECT (but), "zoitechat-color-box", box);
g_object_set_data (G_OBJECT (but), "zoitechat-theme-token", GINT_TO_POINTER (token));
g_object_set_data (G_OBJECT (but), "zoitechat-theme-color-change", color_change_flag);
{
char *tip = theme_preferences_color_events_tooltip (token);
if (tip)
{
gtk_widget_set_tooltip_text (but, tip);
gtk_widget_set_tooltip_text (box, tip);
g_free (tip);
}
}
gtk_grid_attach (GTK_GRID (table), but, col, row, 1, 1);
g_signal_connect (G_OBJECT (but), "clicked", G_CALLBACK (theme_preferences_color_cb), parent);
if (theme_preferences_staged_get_color (token, &color))