Skip to content

Commit bf474e1

Browse files
committed
Ticket #2165: basic version of the user-friendly skin selector.
Thanks Egmont Koblinger and Vitaliy Filippov for original patches. Signed-off-by: Andrew Borodin <[email protected]>
1 parent 25bc34a commit bf474e1

17 files changed

+272
-27
lines changed

doc/man/mc.1.in

+15-1
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,12 @@ confirm.
17711771
.PP
17721772
The
17731773
.\"LINK2"
1774+
Appearance
1775+
.\"Appearance"
1776+
command pops up a dialog from which you specify the skin.
1777+
.PP
1778+
The
1779+
.\"LINK2"
17741780
Display bits
17751781
.\"Display bits"
17761782
command pops up a dialog from which you may select which characters is your
@@ -2123,7 +2129,15 @@ to the the panel sort order: case sensitive or not.
21232129
In this dialog you configure the confirmation options for file deletion,
21242130
overwriting files, execution by pressing enter, quitting the program,
21252131
directory hotlist entries deletion and history cleanup.
2126-
and.
2132+
.\"NODE " Appearance"
2133+
.SH " Appearance"
2134+
In this dialog you can select the skin to be used.
2135+
.PP
2136+
See the
2137+
.\"LINK2"
2138+
Skins
2139+
.\"Skins"
2140+
section for technical details about the skin definition files.
21272141
.\"NODE " Display bits"
21282142
.SH " Display bits"
21292143
This is used to configure the range of visible characters on the

doc/man/ru/mc.1.in

+14
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,12 @@ mc на экране.
18821882
.PP
18831883
Пункт
18841884
.\"LINK2"
1885+
Оформление
1886+
.\"Appearance"
1887+
вызывает диалоговое окно, в котором вы можете выбрать скин.
1888+
.PP
1889+
Пункт
1890+
.\"LINK2"
18851891
Биты символов
18861892
.\"Display bits"
18871893
вызывает диалоговое окно, в котором вы указываете, в каком формате ваш
@@ -2277,6 +2283,14 @@ Commander, выделены цветом, определенным ключев
22772283
перед выходом из программы MC, перед удаленим каталога из каталогов быстрого
22782284
доступа, а также перед очисткой истории выдавался дополнительный запрос
22792285
на подтверждение.
2286+
.\"NODE " Appearance"
2287+
.SH " Оформление"
2288+
Используя это диалоговое окно, вы можете выбрать скин.
2289+
.PP
2290+
Для получения более подробной информации о скинах обратитесь к разделу
2291+
.\"LINK2"
2292+
Внешний вид\&.
2293+
.\"Skins"
22802294
.\"NODE " Display bits"
22812295
.SH " Биты символов..."
22822296
Этот пункт меню используется для задания диапазона отображаемых на

lib/keybind.c

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static name_keymap_t command_names[] = {
176176
{"Jobs", CK_Jobs},
177177
#endif
178178
{"OptionsLayout", CK_OptionsLayout},
179+
{"OptionsAppearance", CK_OptionsAppearance},
179180
{"Link", CK_Link},
180181
{"PanelListingChange", CK_PanelListingChange},
181182
{"PanelListing", CK_PanelListing},

lib/keybind.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ enum
155155
CK_PanelInfo,
156156
CK_Jobs,
157157
CK_OptionsLayout,
158+
CK_OptionsAppearance,
158159
CK_Link,
159160
CK_PanelListing,
160161
CK_ListMode,

lib/skin.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extern mc_skin_t mc_skin__default;
129129

130130
/*** declarations of public functions ************************************************************/
131131

132-
gboolean mc_skin_init (GError **);
132+
gboolean mc_skin_init (const gchar * skin_override, GError ** error);
133133
void mc_skin_deinit (void);
134134

135135
int mc_skin_color_get (const gchar *, const gchar *);
@@ -138,4 +138,6 @@ void mc_skin_lines_parse_ini_file (mc_skin_t *);
138138

139139
gchar *mc_skin_get (const gchar *, const gchar *, const gchar *);
140140

141+
GPtrArray *mc_skin_list (void);
142+
141143
#endif /* MC_SKIN_H */

lib/skin/colors.c

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ mc_skin_color_set_default_for_terminal (mc_skin_t * mc_skin)
178178
}
179179

180180
/* --------------------------------------------------------------------------------------------- */
181+
181182
static void
182183
mc_skin_color_cache_init (void)
183184
{

lib/skin/common.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ mc_skin_try_to_load_default (void)
110110
/* --------------------------------------------------------------------------------------------- */
111111

112112
gboolean
113-
mc_skin_init (GError ** error)
113+
mc_skin_init (const gchar * skin_override, GError ** error)
114114
{
115115
gboolean is_good_init = TRUE;
116116

117117
mc_skin__default.have_256_colors = FALSE;
118118

119-
mc_skin__default.name = mc_skin_get_default_name ();
119+
mc_skin__default.name =
120+
skin_override != NULL ? g_strdup (skin_override) : mc_skin_get_default_name ();
120121

121122
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
122123
g_free, mc_skin_hash_destroy_value);
@@ -165,6 +166,9 @@ mc_skin_init (GError ** error)
165166
void
166167
mc_skin_deinit (void)
167168
{
169+
tty_color_free_all_tmp ();
170+
tty_color_free_all_non_tmp ();
171+
168172
g_free (mc_skin__default.name);
169173
mc_skin__default.name = NULL;
170174
g_hash_table_destroy (mc_skin__default.colors);

lib/skin/ini-file.c

+70
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
*/
2626

2727
#include <config.h>
28+
2829
#include <string.h>
2930

31+
#include "lib/global.h" /* <glib.h> */
32+
3033
#include "internal.h"
3134
#include "lib/fileloc.h"
3235
#include "lib/util.h" /* exist_file() */
@@ -43,6 +46,57 @@
4346

4447
/* --------------------------------------------------------------------------------------------- */
4548

49+
static void
50+
mc_skin_get_list_from_dir (const gchar * base_dir, GPtrArray * list)
51+
{
52+
gchar *name;
53+
GDir *dir;
54+
55+
name = g_build_filename (base_dir, MC_SKINS_SUBDIR, (char *) NULL);
56+
dir = g_dir_open (name, 0, NULL);
57+
g_free (name);
58+
59+
if (dir != NULL)
60+
{
61+
while ((name = (gchar *) g_dir_read_name (dir)) != NULL)
62+
{
63+
gchar *sname;
64+
size_t slen;
65+
unsigned int i;
66+
67+
slen = strlen (name);
68+
sname = g_strndup (name, slen);
69+
70+
if (slen > 4 && strcmp (sname + slen - 4, ".ini") == 0)
71+
sname[slen - 4] = '\0';
72+
73+
for (i = 0; i < list->len; i++)
74+
if (strcmp (sname, g_ptr_array_index (list, i)) == 0)
75+
break;
76+
77+
if (i < list->len)
78+
g_free (sname);
79+
else
80+
g_ptr_array_add (list, sname);
81+
}
82+
83+
g_dir_close (dir);
84+
}
85+
}
86+
87+
/* --------------------------------------------------------------------------------------------- */
88+
89+
static int
90+
string_array_comparator (gconstpointer a, gconstpointer b)
91+
{
92+
char *aa = *(char **) a;
93+
char *bb = *(char **) b;
94+
95+
return strcmp (aa, bb);
96+
}
97+
98+
/* --------------------------------------------------------------------------------------------- */
99+
46100
static gboolean
47101
mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir)
48102
{
@@ -75,6 +129,22 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
75129
/*** public functions ****************************************************************************/
76130
/* --------------------------------------------------------------------------------------------- */
77131

132+
GPtrArray *
133+
mc_skin_list (void)
134+
{
135+
GPtrArray *list;
136+
137+
list = g_ptr_array_new ();
138+
mc_skin_get_list_from_dir (mc_config_get_data_path (), list);
139+
mc_skin_get_list_from_dir (mc_global.sysconfig_dir, list);
140+
mc_skin_get_list_from_dir (mc_global.share_data_dir, list);
141+
g_ptr_array_sort (list, (GCompareFunc) string_array_comparator);
142+
143+
return list;
144+
}
145+
146+
/* --------------------------------------------------------------------------------------------- */
147+
78148
gboolean
79149
mc_skin_ini_file_load (mc_skin_t * mc_skin)
80150
{

lib/widget/dialog.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
/* Color styles for normal and error dialogs */
5151
dlg_colors_t dialog_colors;
5252
dlg_colors_t alarm_colors;
53+
dlg_colors_t listbox_colors;
5354

5455
/* Primitive way to check if the the current dialog is our dialog */
5556
/* This is needed by async routines like load_prompt */
@@ -779,8 +780,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
779780

780781
new_d->state = DLG_CONSTRUCT;
781782
new_d->modal = modal;
782-
if (colors != NULL)
783-
memmove (new_d->color, colors, sizeof (dlg_colors_t));
783+
new_d->color = colors;
784784
new_d->help_ctx = help_ctx;
785785
new_d->flags = flags;
786786
new_d->data = NULL;
@@ -823,6 +823,12 @@ dlg_set_default_colors (void)
823823
alarm_colors[DLG_COLOR_HOT_NORMAL] = ERROR_HOT_NORMAL;
824824
alarm_colors[DLG_COLOR_HOT_FOCUS] = ERROR_HOT_FOCUS;
825825
alarm_colors[DLG_COLOR_TITLE] = ERROR_TITLE;
826+
827+
listbox_colors[DLG_COLOR_NORMAL] = PMENU_ENTRY_COLOR;
828+
listbox_colors[DLG_COLOR_FOCUS] = PMENU_SELECTED_COLOR;
829+
listbox_colors[DLG_COLOR_HOT_NORMAL] = PMENU_ENTRY_COLOR;
830+
listbox_colors[DLG_COLOR_HOT_FOCUS] = PMENU_SELECTED_COLOR;
831+
listbox_colors[DLG_COLOR_TITLE] = PMENU_TITLE_COLOR;
826832
}
827833

828834
/* --------------------------------------------------------------------------------------------- */

lib/widget/dialog.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct WDialog
8383
gboolean modal; /* type of dialog: modal or not */
8484
dlg_flags_t flags; /* User flags */
8585
const char *help_ctx; /* Name of the help entry */
86-
dlg_colors_t color; /* Color set. Unused in viewer and editor */
86+
const int *color; /* Color set. Unused in viewer and editor */
8787
char *title; /* Title of the dialog */
8888

8989
/* Set and received by the user */
@@ -111,6 +111,7 @@ struct WDialog
111111
/* Color styles for normal and error dialogs */
112112
extern dlg_colors_t dialog_colors;
113113
extern dlg_colors_t alarm_colors;
114+
extern dlg_colors_t listbox_colors;
114115

115116
extern GList *top_dlg;
116117

lib/widget/listbox-window.c

-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ Listbox *
5959
create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
6060
const char *title, const char *help)
6161
{
62-
const dlg_colors_t listbox_colors = {
63-
PMENU_ENTRY_COLOR,
64-
PMENU_SELECTED_COLOR,
65-
PMENU_ENTRY_COLOR,
66-
PMENU_SELECTED_COLOR,
67-
PMENU_TITLE_COLOR
68-
};
69-
7062
const int space = 4;
7163

7264
int xpos, ypos;

misc/mc.default.keymap

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Unselect = kpminus
3838
SelectInvert = kpasterisk
3939
ScreenList = alt-prime
4040
# OptionsLayout =
41+
# OptionsAppearance =
4142
# OptionsPanel =
4243
# OptionsConfirm =
4344
# OptionsDisplayBits =

misc/mc.emacs.keymap

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Unselect = kpminus
3838
SelectInvert = kpasterisk
3939
ScreenList = alt-prime
4040
# OptionsLayout =
41+
# OptionsAppearance =
4142
# OptionsPanel =
4243
# OptionsConfirm =
4344
# OptionsDisplayBits =

0 commit comments

Comments
 (0)