Commit a98f6f9a authored by Victor Ananjevsky's avatar Victor Ananjevsky

add content alignment in list dialog

parent cecbfc1e
......@@ -789,6 +789,12 @@ Don't use markup in tooltips even if text has a valid markup.
.TP
.B \-\-header-tips
Use header name as a fallback tooltip text.
.TP
.B \-\-column-align=\fISTRING\fP
Set alignment for columns. \fISTRING\fP must contain array of letters \fIl\fP, \fIr\fP or \fIc\fP for left, center or right alignment of column content.
.TP
.B \-\-header-align=\fISTRING\fP
Set alignment for column headers. \fISTRING\fP same as in \fB\-\-column-align\fP.
.PP
Sending FormFeed character to list clears it. This symbol may be sent as \fIecho \-e '\\f'\fP.
......
......@@ -31,6 +31,9 @@ static guint n_cols = 0;
static gulong select_hndl = 0;
static gchar *column_align = NULL;
static gchar *header_align = NULL;
static inline void
yad_list_add_row (GtkTreeStore *m, GtkTreeIter *it, gchar *row_id, gchar *par_id)
{
......@@ -441,10 +444,13 @@ add_columns ()
options.list_data.tooltip_column = i + 1;
break;
}
gtk_cell_renderer_set_alignment (renderer, col->c_align, 0.5);
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (i));
gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
gtk_tree_view_column_set_clickable (column, options.list_data.clickable);
gtk_tree_view_column_set_alignment (column, col->h_align);
if (col->type != YAD_COLUMN_CHECK && col->type != YAD_COLUMN_IMAGE)
{
......@@ -1177,14 +1183,17 @@ row_sep_func (GtkTreeModel *m, GtkTreeIter *it, gpointer data)
static inline void
parse_cols_props ()
{
GSList *c;
guint i;
/* set editable property for columns */
if (options.common_data.editable)
{
if (options.list_data.editable_cols)
{
gchar **cnum;
guint i = 0;
i = 0;
cnum = g_strsplit (options.list_data.editable_cols, ",", -1);
while (cnum[i])
......@@ -1202,7 +1211,6 @@ parse_cols_props ()
}
else
{
GSList *c;
for (c = options.list_data.columns; c; c = c->next)
{
YadColumn *col = (YadColumn *) c->data;
......@@ -1217,8 +1225,8 @@ parse_cols_props ()
if (options.list_data.wrap_cols)
{
gchar **cnum;
guint i = 0;
i = 0;
cnum = g_strsplit (options.list_data.wrap_cols, ",", -1);
while (cnum[i])
......@@ -1236,7 +1244,6 @@ parse_cols_props ()
}
else
{
GSList *c;
for (c = options.list_data.columns; c; c = c->next)
{
YadColumn *col = (YadColumn *) c->data;
......@@ -1251,8 +1258,8 @@ parse_cols_props ()
if (options.list_data.ellipsize_cols)
{
gchar **cnum;
guint i = 0;
i = 0;
cnum = g_strsplit (options.list_data.ellipsize_cols, ",", -1);
while (cnum[i])
......@@ -1270,7 +1277,6 @@ parse_cols_props ()
}
else
{
GSList *c;
for (c = options.list_data.columns; c; c = c->next)
{
YadColumn *col = (YadColumn *) c->data;
......@@ -1278,6 +1284,46 @@ parse_cols_props ()
}
}
}
/* set alignment */
i = 0;
for (c = options.list_data.columns; c; c = c->next)
{
YadColumn *col = (YadColumn *) c->data;
if (column_align)
{
switch (column_align[i])
{
case 'l':
col->c_align = 0.0;
break;
case 'r':
col->c_align = 1.0;
break;
case 'c':
col->c_align = 0.5;
break;
}
}
if (header_align)
{
switch (header_align[i])
{
case 'l':
col->h_align = 0.0;
break;
case 'r':
col->h_align = 1.0;
break;
case 'c':
col->h_align = 0.5;
break;
}
}
i++;
}
}
GtkWidget *
......@@ -1304,6 +1350,18 @@ list_create_widget (GtkWidget *dlg)
if (options.list_data.tree_mode)
row_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gtk_tree_path_free);
/* set normalized alignment array for list keaders and columns content */
if (options.list_data.col_align)
{
column_align = g_new0 (gchar, n_cols);
strncpy (column_align, options.list_data.col_align, n_cols);
}
if (options.list_data.hdr_align)
{
header_align = g_new0 (gchar, n_cols);
strncpy (header_align, options.list_data.hdr_align, n_cols);
}
parse_cols_props ();
/* create widget */
......
......@@ -512,6 +512,10 @@ static GOptionEntry list_options[] = {
N_("Don't use markup in tooltips"), NULL },
{ "header-tips", 0, 0, G_OPTION_ARG_NONE, &options.list_data.header_tips,
N_("Use column name as a header tooltip"), NULL },
{ "column-align", 0, 0, G_OPTION_ARG_STRING, &options.list_data.col_align,
N_("Set columns alignment"), N_("STRING") },
{ "header-align", 0, 0, G_OPTION_ARG_STRING, &options.list_data.hdr_align,
N_("Set headers alignment"), N_("STRING") },
{ NULL }
};
......@@ -1810,6 +1814,8 @@ yad_options_init (void)
options.list_data.add_on_top = FALSE;
options.list_data.simple_tips = FALSE;
options.list_data.header_tips = FALSE;
options.list_data.col_align = NULL;
options.list_data.hdr_align = NULL;
/* Initialize notebook data */
options.notebook_data.tabs = NULL;
......
......@@ -206,6 +206,8 @@ typedef struct {
gboolean wrap;
gboolean ellipsize;
gboolean editable;
gdouble c_align;
gdouble h_align;
} YadColumn;
typedef struct {
......@@ -402,6 +404,8 @@ typedef struct {
gboolean add_on_top;
gboolean simple_tips;
gboolean header_tips;
gchar *col_align;
gchar *hdr_align;
} YadListData;
typedef struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment