2009-09-04 18:22:49 +04:00
|
|
|
/*
|
|
|
|
Skins engine.
|
2013-07-23 02:16:20 +04:00
|
|
|
Work with colors - backward compatibility
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2024-01-01 09:46:17 +03:00
|
|
|
Copyright (C) 2009-2024
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
Written by:
|
2010-12-29 12:58:10 +03:00
|
|
|
Slava Zanko <slavazanko@gmail.com>, 2009
|
|
|
|
Egmont Koblinger <egmont@gmail.com>, 2010
|
2011-10-28 13:57:00 +04:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2012
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
2009-09-04 18:22:49 +04:00
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
2011-10-15 14:56:47 +04:00
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2009-09-04 18:22:49 +04:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-09-04 18:22:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
2010-12-29 13:29:52 +03:00
|
|
|
#include <string.h> /* strcmp() */
|
2009-09-14 17:43:03 +04:00
|
|
|
#include <sys/types.h> /* size_t */
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-10 16:14:18 +04:00
|
|
|
#include "internal.h"
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2010-11-11 14:05:34 +03:00
|
|
|
#include "lib/tty/color.h"
|
2010-01-21 16:06:15 +03:00
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
2010-04-23 11:54:25 +04:00
|
|
|
typedef struct mc_skin_colors_old_struct
|
|
|
|
{
|
2009-09-10 16:14:18 +04:00
|
|
|
const char *old_color;
|
|
|
|
const char *group;
|
|
|
|
const char *key;
|
|
|
|
} mc_skin_colors_old_t;
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
2010-12-29 13:29:52 +03:00
|
|
|
/* keep this table alphabetically sorted */
|
2010-04-22 16:09:52 +04:00
|
|
|
static const mc_skin_colors_old_t old_colors[] = {
|
2010-12-29 13:29:52 +03:00
|
|
|
{"bbarbutton", "buttonbar", "button"},
|
|
|
|
{"bbarhotkey", "buttonbar", "hotkey"},
|
|
|
|
{"commandlinemark", "core", "commandlinemark"},
|
2009-09-14 17:43:03 +04:00
|
|
|
{"dfocus", "dialog", "dfocus"},
|
|
|
|
{"dhotfocus", "dialog", "dhotfocus"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"dhotnormal", "dialog", "dhotnormal"},
|
|
|
|
{"disabled", "core", "disabled"},
|
|
|
|
{"dnormal", "dialog", "_default_"},
|
2011-10-28 13:57:00 +04:00
|
|
|
{"editbg", "editor", "editbg"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"editbold", "editor", "editbold"},
|
2011-10-28 13:57:00 +04:00
|
|
|
{"editframe", "editor", "editframe"},
|
|
|
|
{"editframeactive", "editor", "editframeactive"},
|
|
|
|
{"editframedrag", "editor", "editframedrag"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"editlinestate", "editor", "editlinestate"},
|
|
|
|
{"editmarked", "editor", "editmarked"},
|
2023-12-03 19:28:56 +03:00
|
|
|
{"editnonprintable", "editor", "editnonprintable"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"editnormal", "editor", "_default_"},
|
|
|
|
{"editwhitespace", "editor", "editwhitespace"},
|
2009-09-19 18:31:22 +04:00
|
|
|
{"errdhotfocus", "error", "errdhotfocus"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"errdhotnormal", "error", "errdhotnormal"},
|
|
|
|
{"errors", "error", "_default_"},
|
|
|
|
{"gauge", "core", "gauge"},
|
|
|
|
{"header", "core", "header"},
|
|
|
|
{"helpbold", "help", "helpbold"},
|
|
|
|
{"helpitalic", "help", "helpitalic"},
|
|
|
|
{"helplink", "help", "helplink"},
|
|
|
|
{"helpnormal", "help", "_default_"},
|
|
|
|
{"helpslink", "help", "helpslink"},
|
|
|
|
{"input", "core", "input"},
|
|
|
|
{"inputmark", "core", "inputmark"},
|
|
|
|
{"inputunchanged", "core", "inputunchanged"},
|
|
|
|
{"marked", "core", "marked"},
|
|
|
|
{"markselect", "core", "markselect"},
|
2009-09-14 17:43:03 +04:00
|
|
|
{"menuhot", "menu", "menuhot"},
|
|
|
|
{"menuhotsel", "menu", "menuhotsel"},
|
2010-02-23 14:13:23 +03:00
|
|
|
{"menuinactive", "menu", "menuinactive"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"menunormal", "menu", "_default_"},
|
|
|
|
{"menusel", "menu", "menusel"},
|
|
|
|
{"normal", "core", "_default_"},
|
2010-11-29 21:46:11 +03:00
|
|
|
{"pmenunormal", "popupmenu", "_default_"},
|
|
|
|
{"pmenusel", "popupmenu", "menusel"},
|
|
|
|
{"pmenutitle", "popupmenu", "menutitle"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"reverse", "core", "reverse"},
|
|
|
|
{"selected", "core", "selected"},
|
2010-11-11 14:05:34 +03:00
|
|
|
{"statusbar", "statusbar", "_default_"},
|
2011-02-03 15:40:38 +03:00
|
|
|
{"viewbold", "viewer", "viewbold"},
|
2015-02-18 09:31:40 +03:00
|
|
|
{"viewnormal", "viewer", "_default_"},
|
2011-02-03 15:40:38 +03:00
|
|
|
{"viewselected", "viewer", "viewselected"},
|
2010-12-29 13:29:52 +03:00
|
|
|
{"viewunderline", "viewer", "viewunderline"}
|
2009-09-10 16:14:18 +04:00
|
|
|
};
|
|
|
|
|
2010-12-29 13:29:52 +03:00
|
|
|
static const size_t num_old_colors = G_N_ELEMENTS (old_colors);
|
2009-09-10 16:14:18 +04:00
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-09-04 18:22:49 +04:00
|
|
|
/*** file scope functions ************************************************************************/
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-12-29 13:29:52 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
old_color_comparator (const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const mc_skin_colors_old_t *m1 = (const mc_skin_colors_old_t *) p1;
|
|
|
|
const mc_skin_colors_old_t *m2 = (const mc_skin_colors_old_t *) p2;
|
|
|
|
|
|
|
|
return strcmp (m1->old_color, m2->old_color);
|
|
|
|
}
|
|
|
|
|
2009-09-04 18:22:49 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-09-10 16:14:18 +04:00
|
|
|
static gboolean
|
2009-09-14 17:43:03 +04:00
|
|
|
mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2010-12-29 13:29:52 +03:00
|
|
|
const mc_skin_colors_old_t oc = { old_color, NULL, NULL };
|
|
|
|
mc_skin_colors_old_t *res;
|
|
|
|
|
|
|
|
if (old_color == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
res = (mc_skin_colors_old_t *) bsearch (&oc, old_colors, num_old_colors,
|
|
|
|
sizeof (old_colors[0]), old_color_comparator);
|
|
|
|
|
|
|
|
if (res == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (group != NULL)
|
|
|
|
*group = res->group;
|
|
|
|
if (key != NULL)
|
|
|
|
*key = res->key;
|
|
|
|
return TRUE;
|
2009-09-10 16:14:18 +04:00
|
|
|
}
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-10 16:14:18 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-10 16:14:18 +04:00
|
|
|
static void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_skin_colors_old_configure_one (mc_skin_t *mc_skin, const char *the_color_string)
|
2009-09-10 16:14:18 +04:00
|
|
|
{
|
|
|
|
gchar **colors, **orig_colors;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-10 16:14:18 +04:00
|
|
|
if (the_color_string == NULL)
|
2009-09-14 17:43:03 +04:00
|
|
|
return;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2013-08-07 13:42:42 +04:00
|
|
|
orig_colors = g_strsplit (the_color_string, ":", -1);
|
|
|
|
if (orig_colors == NULL)
|
2009-09-14 17:43:03 +04:00
|
|
|
return;
|
2009-09-10 16:14:18 +04:00
|
|
|
|
2013-08-07 13:42:42 +04:00
|
|
|
for (colors = orig_colors; *colors != NULL; colors++)
|
2010-04-23 11:54:25 +04:00
|
|
|
{
|
2011-01-23 11:20:27 +03:00
|
|
|
gchar **key_val;
|
|
|
|
const gchar *skin_group, *skin_key;
|
|
|
|
|
2010-12-29 12:58:10 +03:00
|
|
|
key_val = g_strsplit_set (*colors, "=,", 4);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2011-01-23 11:20:27 +03:00
|
|
|
if (key_val == NULL)
|
2009-09-14 17:43:03 +04:00
|
|
|
continue;
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
if (key_val[1] != NULL && mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
|
2010-04-23 11:54:25 +04:00
|
|
|
{
|
2011-01-23 11:20:27 +03:00
|
|
|
gchar *skin_val;
|
2010-04-23 11:54:25 +04:00
|
|
|
|
2011-01-23 11:20:27 +03:00
|
|
|
if (key_val[2] == NULL)
|
|
|
|
skin_val = g_strdup_printf ("%s;", key_val[1]);
|
|
|
|
else if (key_val[3] == NULL)
|
|
|
|
skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
|
|
|
|
else
|
|
|
|
skin_val = g_strdup_printf ("%s;%s;%s", key_val[1], key_val[2], key_val[3]);
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2011-01-23 11:20:27 +03:00
|
|
|
mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
|
|
|
|
g_free (skin_val);
|
|
|
|
}
|
2009-09-04 18:22:49 +04:00
|
|
|
|
2009-09-14 17:43:03 +04:00
|
|
|
g_strfreev (key_val);
|
2009-09-10 16:14:18 +04:00
|
|
|
}
|
|
|
|
g_strfreev (orig_colors);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2024-06-01 21:12:14 +03:00
|
|
|
mc_skin_colors_old_configure (mc_skin_t *mc_skin)
|
2009-09-04 18:22:49 +04:00
|
|
|
{
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.setup_color_string);
|
|
|
|
mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.term_color_string);
|
2009-09-10 16:14:18 +04:00
|
|
|
mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.command_line_colors);
|
2009-09-04 18:22:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|