Skip to content

Commit

Permalink
Ticket #2165: basic version of the user-friendly skin selector.
Browse files Browse the repository at this point in the history
Thanks Egmont Koblinger and Vitaliy Filippov for original patches.

Signed-off-by: Andrew Borodin <[email protected]>
  • Loading branch information
aborodin committed Feb 11, 2014
1 parent 25bc34a commit bf474e1
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 27 deletions.
16 changes: 15 additions & 1 deletion doc/man/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,12 @@ confirm.
.PP
The
.\"LINK2"
Appearance
.\"Appearance"
command pops up a dialog from which you specify the skin.
.PP
The
.\"LINK2"
Display bits
.\"Display bits"
command pops up a dialog from which you may select which characters is your
Expand Down Expand Up @@ -2123,7 +2129,15 @@ to the the panel sort order: case sensitive or not.
In this dialog you configure the confirmation options for file deletion,
overwriting files, execution by pressing enter, quitting the program,
directory hotlist entries deletion and history cleanup.
and.
.\"NODE " Appearance"
.SH " Appearance"
In this dialog you can select the skin to be used.
.PP
See the
.\"LINK2"
Skins
.\"Skins"
section for technical details about the skin definition files.
.\"NODE " Display bits"
.SH " Display bits"
This is used to configure the range of visible characters on the
Expand Down
14 changes: 14 additions & 0 deletions doc/man/ru/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,12 @@ mc на экране.
.PP
Пункт
.\"LINK2"
Оформление
.\"Appearance"
вызывает диалоговое окно, в котором вы можете выбрать скин.
.PP
Пункт
.\"LINK2"
Биты символов
.\"Display bits"
вызывает диалоговое окно, в котором вы указываете, в каком формате ваш
Expand Down Expand Up @@ -2277,6 +2283,14 @@ Commander, выделены цветом, определенным ключев
перед выходом из программы MC, перед удаленим каталога из каталогов быстрого
доступа, а также перед очисткой истории выдавался дополнительный запрос
на подтверждение.
.\"NODE " Appearance"
.SH " Оформление"
Используя это диалоговое окно, вы можете выбрать скин.
.PP
Для получения более подробной информации о скинах обратитесь к разделу
.\"LINK2"
Внешний вид\&.
.\"Skins"
.\"NODE " Display bits"
.SH " Биты символов..."
Этот пункт меню используется для задания диапазона отображаемых на
Expand Down
1 change: 1 addition & 0 deletions lib/keybind.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ static name_keymap_t command_names[] = {
{"Jobs", CK_Jobs},
#endif
{"OptionsLayout", CK_OptionsLayout},
{"OptionsAppearance", CK_OptionsAppearance},
{"Link", CK_Link},
{"PanelListingChange", CK_PanelListingChange},
{"PanelListing", CK_PanelListing},
Expand Down
1 change: 1 addition & 0 deletions lib/keybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ enum
CK_PanelInfo,
CK_Jobs,
CK_OptionsLayout,
CK_OptionsAppearance,
CK_Link,
CK_PanelListing,
CK_ListMode,
Expand Down
4 changes: 3 additions & 1 deletion lib/skin.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ extern mc_skin_t mc_skin__default;

/*** declarations of public functions ************************************************************/

gboolean mc_skin_init (GError **);
gboolean mc_skin_init (const gchar * skin_override, GError ** error);
void mc_skin_deinit (void);

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

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

GPtrArray *mc_skin_list (void);

#endif /* MC_SKIN_H */
1 change: 1 addition & 0 deletions lib/skin/colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ mc_skin_color_set_default_for_terminal (mc_skin_t * mc_skin)
}

/* --------------------------------------------------------------------------------------------- */

static void
mc_skin_color_cache_init (void)
{
Expand Down
8 changes: 6 additions & 2 deletions lib/skin/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ mc_skin_try_to_load_default (void)
/* --------------------------------------------------------------------------------------------- */

gboolean
mc_skin_init (GError ** error)
mc_skin_init (const gchar * skin_override, GError ** error)
{
gboolean is_good_init = TRUE;

mc_skin__default.have_256_colors = FALSE;

mc_skin__default.name = mc_skin_get_default_name ();
mc_skin__default.name =
skin_override != NULL ? g_strdup (skin_override) : mc_skin_get_default_name ();

mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, mc_skin_hash_destroy_value);
Expand Down Expand Up @@ -165,6 +166,9 @@ mc_skin_init (GError ** error)
void
mc_skin_deinit (void)
{
tty_color_free_all_tmp ();
tty_color_free_all_non_tmp ();

g_free (mc_skin__default.name);
mc_skin__default.name = NULL;
g_hash_table_destroy (mc_skin__default.colors);
Expand Down
70 changes: 70 additions & 0 deletions lib/skin/ini-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
*/

#include <config.h>

#include <string.h>

#include "lib/global.h" /* <glib.h> */

#include "internal.h"
#include "lib/fileloc.h"
#include "lib/util.h" /* exist_file() */
Expand All @@ -43,6 +46,57 @@

/* --------------------------------------------------------------------------------------------- */

static void
mc_skin_get_list_from_dir (const gchar * base_dir, GPtrArray * list)
{
gchar *name;
GDir *dir;

name = g_build_filename (base_dir, MC_SKINS_SUBDIR, (char *) NULL);
dir = g_dir_open (name, 0, NULL);
g_free (name);

if (dir != NULL)
{
while ((name = (gchar *) g_dir_read_name (dir)) != NULL)
{
gchar *sname;
size_t slen;
unsigned int i;

slen = strlen (name);
sname = g_strndup (name, slen);

if (slen > 4 && strcmp (sname + slen - 4, ".ini") == 0)
sname[slen - 4] = '\0';

for (i = 0; i < list->len; i++)
if (strcmp (sname, g_ptr_array_index (list, i)) == 0)
break;

if (i < list->len)
g_free (sname);
else
g_ptr_array_add (list, sname);
}

g_dir_close (dir);
}
}

/* --------------------------------------------------------------------------------------------- */

static int
string_array_comparator (gconstpointer a, gconstpointer b)
{
char *aa = *(char **) a;
char *bb = *(char **) b;

return strcmp (aa, bb);
}

/* --------------------------------------------------------------------------------------------- */

static gboolean
mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir)
{
Expand Down Expand Up @@ -75,6 +129,22 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */

GPtrArray *
mc_skin_list (void)
{
GPtrArray *list;

list = g_ptr_array_new ();
mc_skin_get_list_from_dir (mc_config_get_data_path (), list);
mc_skin_get_list_from_dir (mc_global.sysconfig_dir, list);
mc_skin_get_list_from_dir (mc_global.share_data_dir, list);
g_ptr_array_sort (list, (GCompareFunc) string_array_comparator);

return list;
}

/* --------------------------------------------------------------------------------------------- */

gboolean
mc_skin_ini_file_load (mc_skin_t * mc_skin)
{
Expand Down
10 changes: 8 additions & 2 deletions lib/widget/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
/* Color styles for normal and error dialogs */
dlg_colors_t dialog_colors;
dlg_colors_t alarm_colors;
dlg_colors_t listbox_colors;

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

new_d->state = DLG_CONSTRUCT;
new_d->modal = modal;
if (colors != NULL)
memmove (new_d->color, colors, sizeof (dlg_colors_t));
new_d->color = colors;
new_d->help_ctx = help_ctx;
new_d->flags = flags;
new_d->data = NULL;
Expand Down Expand Up @@ -823,6 +823,12 @@ dlg_set_default_colors (void)
alarm_colors[DLG_COLOR_HOT_NORMAL] = ERROR_HOT_NORMAL;
alarm_colors[DLG_COLOR_HOT_FOCUS] = ERROR_HOT_FOCUS;
alarm_colors[DLG_COLOR_TITLE] = ERROR_TITLE;

listbox_colors[DLG_COLOR_NORMAL] = PMENU_ENTRY_COLOR;
listbox_colors[DLG_COLOR_FOCUS] = PMENU_SELECTED_COLOR;
listbox_colors[DLG_COLOR_HOT_NORMAL] = PMENU_ENTRY_COLOR;
listbox_colors[DLG_COLOR_HOT_FOCUS] = PMENU_SELECTED_COLOR;
listbox_colors[DLG_COLOR_TITLE] = PMENU_TITLE_COLOR;
}

/* --------------------------------------------------------------------------------------------- */
Expand Down
3 changes: 2 additions & 1 deletion lib/widget/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct WDialog
gboolean modal; /* type of dialog: modal or not */
dlg_flags_t flags; /* User flags */
const char *help_ctx; /* Name of the help entry */
dlg_colors_t color; /* Color set. Unused in viewer and editor */
const int *color; /* Color set. Unused in viewer and editor */
char *title; /* Title of the dialog */

/* Set and received by the user */
Expand Down Expand Up @@ -111,6 +111,7 @@ struct WDialog
/* Color styles for normal and error dialogs */
extern dlg_colors_t dialog_colors;
extern dlg_colors_t alarm_colors;
extern dlg_colors_t listbox_colors;

extern GList *top_dlg;

Expand Down
8 changes: 0 additions & 8 deletions lib/widget/listbox-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ Listbox *
create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
const char *title, const char *help)
{
const dlg_colors_t listbox_colors = {
PMENU_ENTRY_COLOR,
PMENU_SELECTED_COLOR,
PMENU_ENTRY_COLOR,
PMENU_SELECTED_COLOR,
PMENU_TITLE_COLOR
};

const int space = 4;

int xpos, ypos;
Expand Down
1 change: 1 addition & 0 deletions misc/mc.default.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Unselect = kpminus
SelectInvert = kpasterisk
ScreenList = alt-prime
# OptionsLayout =
# OptionsAppearance =
# OptionsPanel =
# OptionsConfirm =
# OptionsDisplayBits =
Expand Down
1 change: 1 addition & 0 deletions misc/mc.emacs.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Unselect = kpminus
SelectInvert = kpasterisk
ScreenList = alt-prime
# OptionsLayout =
# OptionsAppearance =
# OptionsPanel =
# OptionsConfirm =
# OptionsDisplayBits =
Expand Down
Loading

0 comments on commit bf474e1

Please sign in to comment.