mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-19 12:10:19 +00:00
Persist GTK userlist column widths
This commit is contained in:
@@ -74,6 +74,19 @@ chanlistrow;
|
||||
|
||||
#define GET_MODEL(xserv) (gtk_tree_view_get_model(GTK_TREE_VIEW(xserv->gui->chanlist_list)))
|
||||
|
||||
#define CHANLIST_COL_WIDTH_MIN_CHANNEL 60
|
||||
#define CHANLIST_COL_WIDTH_MIN_USERS 40
|
||||
#define CHANLIST_COL_WIDTH_MIN_TOPIC 60
|
||||
|
||||
static int
|
||||
chanlist_clamp_width (int width, int min_width)
|
||||
{
|
||||
if (width < min_width)
|
||||
return min_width;
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
static void
|
||||
chanlist_set_label_alignment (GtkWidget *widget)
|
||||
{
|
||||
@@ -805,6 +818,26 @@ chanlist_button_cb (GtkTreeView *tree, GdkEventButton *event, server *serv)
|
||||
static void
|
||||
chanlist_destroy_widget (GtkWidget *wid, server *serv)
|
||||
{
|
||||
GtkTreeViewColumn *column;
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (serv->gui->chanlist_list), COL_CHANNEL);
|
||||
if (column)
|
||||
prefs.hex_gui_chanlist_width_channel =
|
||||
chanlist_clamp_width (gtk_tree_view_column_get_width (column), CHANLIST_COL_WIDTH_MIN_CHANNEL);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (serv->gui->chanlist_list), COL_USERS);
|
||||
if (column)
|
||||
prefs.hex_gui_chanlist_width_users =
|
||||
chanlist_clamp_width (gtk_tree_view_column_get_width (column), CHANLIST_COL_WIDTH_MIN_USERS);
|
||||
|
||||
column = gtk_tree_view_get_column (GTK_TREE_VIEW (serv->gui->chanlist_list), COL_TOPIC);
|
||||
if (column)
|
||||
prefs.hex_gui_chanlist_width_topic =
|
||||
chanlist_clamp_width (gtk_tree_view_column_get_width (column), CHANLIST_COL_WIDTH_MIN_TOPIC);
|
||||
|
||||
if (!save_config ())
|
||||
fe_message (_("Could not save zoitechat.conf."), FE_MSG_WARN);
|
||||
|
||||
custom_list_clear ((CustomList *)GET_MODEL (serv));
|
||||
chanlist_data_free (serv);
|
||||
|
||||
@@ -944,6 +977,37 @@ chanlist_opengui (server *serv, int do_refresh)
|
||||
chanlist_add_column (view, COL_CHANNEL, 96, _("Channel"), FALSE);
|
||||
chanlist_add_column (view, COL_USERS, 50, _("Users"), TRUE);
|
||||
chanlist_add_column (view, COL_TOPIC, 50, _("Topic"), FALSE);
|
||||
|
||||
if (prefs.hex_gui_chanlist_width_channel > 0)
|
||||
{
|
||||
GtkTreeViewColumn *column = gtk_tree_view_get_column (GTK_TREE_VIEW (view), COL_CHANNEL);
|
||||
if (column)
|
||||
gtk_tree_view_column_set_fixed_width (column,
|
||||
chanlist_clamp_width (prefs.hex_gui_chanlist_width_channel, CHANLIST_COL_WIDTH_MIN_CHANNEL));
|
||||
}
|
||||
|
||||
if (prefs.hex_gui_chanlist_width_users > 0)
|
||||
{
|
||||
GtkTreeViewColumn *column = gtk_tree_view_get_column (GTK_TREE_VIEW (view), COL_USERS);
|
||||
if (column)
|
||||
{
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (column,
|
||||
chanlist_clamp_width (prefs.hex_gui_chanlist_width_users, CHANLIST_COL_WIDTH_MIN_USERS));
|
||||
gtk_tree_view_column_set_resizable (column, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.hex_gui_chanlist_width_topic > 0)
|
||||
{
|
||||
GtkTreeViewColumn *column = gtk_tree_view_get_column (GTK_TREE_VIEW (view), COL_TOPIC);
|
||||
if (column)
|
||||
{
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_fixed_width (column,
|
||||
chanlist_clamp_width (prefs.hex_gui_chanlist_width_topic, CHANLIST_COL_WIDTH_MIN_TOPIC));
|
||||
}
|
||||
}
|
||||
gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), GTK_TREE_VIEW_GRID_LINES_HORIZONTAL);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)), GTK_SELECTION_MULTIPLE);
|
||||
/* this is a speed up, but no horizontal scrollbar :( */
|
||||
|
||||
@@ -52,6 +52,29 @@ enum
|
||||
|
||||
static void userlist_store_color (GtkListStore *store, GtkTreeIter *iter, ThemeSemanticToken token, gboolean has_token);
|
||||
|
||||
static void
|
||||
userlist_column_width_notify_cb (GtkTreeViewColumn *column, GParamSpec *pspec, gpointer userdata)
|
||||
{
|
||||
(void)pspec;
|
||||
|
||||
int width = gtk_tree_view_column_get_width (column);
|
||||
int *target = (int *)userdata;
|
||||
|
||||
if (!target || width < 1 || *target == width)
|
||||
return;
|
||||
|
||||
*target = width;
|
||||
}
|
||||
|
||||
static void
|
||||
userlist_apply_saved_column_width (GtkTreeViewColumn *column, int width)
|
||||
{
|
||||
if (!column || width < 1)
|
||||
return;
|
||||
|
||||
gtk_tree_view_column_set_fixed_width (column, width);
|
||||
}
|
||||
|
||||
static void
|
||||
userlist_update_min_width (session *sess)
|
||||
{
|
||||
@@ -71,7 +94,6 @@ userlist_update_min_width (session *sess)
|
||||
scrolled_window = gtk_widget_get_parent (sess->gui->user_tree);
|
||||
if (GTK_IS_SCROLLED_WINDOW (scrolled_window))
|
||||
gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (scrolled_window), width);
|
||||
gtk_widget_set_size_request (sess->gui->user_tree, width, -1);
|
||||
gtk_widget_set_size_request (sess->gui->user_box, width, -1);
|
||||
}
|
||||
|
||||
@@ -712,6 +734,11 @@ userlist_add_columns (GtkTreeView * treeview)
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_expand (column, TRUE);
|
||||
gtk_tree_view_column_set_min_width (column, 1);
|
||||
gtk_tree_view_column_set_resizable (column, TRUE);
|
||||
userlist_apply_saved_column_width (column, prefs.hex_gui_ulist_nick_width);
|
||||
g_signal_connect (G_OBJECT (column), "notify::width",
|
||||
G_CALLBACK (userlist_column_width_notify_cb),
|
||||
&prefs.hex_gui_ulist_nick_width);
|
||||
|
||||
if (prefs.hex_gui_ulist_show_hosts)
|
||||
{
|
||||
@@ -728,6 +755,11 @@ userlist_add_columns (GtkTreeView * treeview)
|
||||
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_expand (column, TRUE);
|
||||
gtk_tree_view_column_set_min_width (column, 1);
|
||||
gtk_tree_view_column_set_resizable (column, TRUE);
|
||||
userlist_apply_saved_column_width (column, prefs.hex_gui_ulist_host_width);
|
||||
g_signal_connect (G_OBJECT (column), "notify::width",
|
||||
G_CALLBACK (userlist_column_width_notify_cb),
|
||||
&prefs.hex_gui_ulist_host_width);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,7 +886,7 @@ userlist_create (GtkWidget *box)
|
||||
treeview = gtk_tree_view_new ();
|
||||
gtk_widget_set_name (treeview, "zoitechat-userlist");
|
||||
gtk_widget_set_can_focus (treeview, TRUE);
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection
|
||||
(GTK_TREE_VIEW (treeview)),
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
|
||||
Reference in New Issue
Block a user