Ticket #2165: vitalif_skin-selection.diff

File vitalif_skin-selection.diff, 11.2 KB (added by vitalif, 10 years ago)

My version of skin selection UI... :)

  • lib/keybind.h

    commit 023aeb3da9a7be530dfc882c628caecb02736dfd
    Author: Vitaliy Filippov <vitalif@yourcmc.ru>
    Date:   Fri Feb 7 03:54:37 2014 +0400
    
        Skin selection UI
    
    old new  
    154154    CK_ConnectSmb, 
    155155    CK_PanelInfo, 
    156156    CK_Jobs, 
     157    CK_OptionsSkin, 
    157158    CK_OptionsLayout, 
    158159    CK_Link, 
    159160    CK_PanelListing, 
  • lib/skin.h

    old new  
    138138 
    139139gchar *mc_skin_get (const gchar *, const gchar *, const gchar *); 
    140140 
     141GArray *mc_skin_list (void); 
     142 
    141143#endif /* MC_SKIN_H */ 
  • lib/skin/ini-file.c

    old new  
    124124 
    125125/* --------------------------------------------------------------------------------------------- */ 
    126126 
     127static void 
     128mc_skin_get_list_from_dir (const gchar * base_dir, GArray * list) 
     129{ 
     130    unsigned int i; 
     131    char *dir_name; 
     132    DIR *dir; 
     133    gchar *name; 
     134 
     135    dir_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, NULL); 
     136    dir = opendir (dir_name); 
     137    if (dir != NULL) 
     138    { 
     139        struct dirent *de; 
     140        while ((de = readdir(dir)) != NULL) 
     141        { 
     142            if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) 
     143                continue; 
     144            if (strlen(de->d_name) > 4 && !strcmp(de->d_name + strlen(de->d_name) - 4, ".ini")) 
     145                de->d_name[strlen(de->d_name) - 4] = '\0'; 
     146            for (i = 0; i < list->len; i++) 
     147                if (!strcmp(de->d_name, g_array_index(list, gchar *, i))) 
     148                    break; 
     149            if (i < list->len) 
     150                continue; 
     151            name = g_strdup(de->d_name); 
     152            g_array_append_val(list, name); 
     153        } 
     154        closedir(dir); 
     155    } 
     156    g_free(dir_name); 
     157} 
     158 
     159/* --------------------------------------------------------------------------------------------- */ 
     160 
     161static int pstrcmp (char **a, char **b) 
     162{ 
     163    return strcmp(*a, *b); 
     164} 
     165 
     166/* --------------------------------------------------------------------------------------------- */ 
     167 
     168GArray * 
     169mc_skin_list () 
     170{ 
     171    GArray *list = g_array_new(FALSE, FALSE, sizeof(gchar *)); 
     172    /* ${XDG_DATA_HOME}/mc/skins/ */ 
     173    mc_skin_get_list_from_dir (mc_config_get_data_path (), list); 
     174    /* /etc/mc/skins/ */ 
     175    mc_skin_get_list_from_dir (mc_global.sysconfig_dir, list); 
     176    /* /usr/share/mc/skins/ */ 
     177    mc_skin_get_list_from_dir (mc_global.share_data_dir, list); 
     178    g_array_sort(list, (GCompareFunc) pstrcmp); 
     179    return list; 
     180} 
     181 
     182/* --------------------------------------------------------------------------------------------- */ 
     183 
    127184void 
    128185mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin) 
    129186{ 
  • po/ru.po

    old new  
    30653065msgid "Layout" 
    30663066msgstr "Внешний вид" 
    30673067 
     3068msgid "&Skin..." 
     3069msgstr "&Оформление..." 
     3070 
     3071msgid "Choose skin" 
     3072msgstr "Выберите оформление" 
     3073 
     3074msgid "< Default >" 
     3075msgstr "< По умолчанию >" 
     3076 
    30683077msgid "File listin&g" 
    30693078msgstr "&Список файлов" 
    30703079 
  • src/filemanager/Makefile.am

    old new  
    55        achown.c achown.h \ 
    66        boxes.c boxes.h \ 
    77        chmod.c chmod.h \ 
     8        chooseskin.c chooseskin.h \ 
    89        chown.c chown.h \ 
    910        cmd.c cmd.h \ 
    1011        command.c command.h \ 
  • new file mc-4.8.11/src/filemanager/chooseskin.c

    - +  
     1/* 
     2   User interface for skin selection. 
     3 
     4   Copyright (C) 2014 
     5   Vitaliy Filippov <vitalif at mail ru> 
     6 
     7   Written by: 
     8   Vitaliy Filippov <vitalif at mail ru> 
     9 
     10   This file is part of the Midnight Commander. 
     11 
     12   The Midnight Commander is free software: you can redistribute it 
     13   and/or modify it under the terms of the GNU General Public License as 
     14   published by the Free Software Foundation, either version 3 of the License, 
     15   or (at your option) any later version. 
     16 
     17   The Midnight Commander is distributed in the hope that it will be useful, 
     18   but WITHOUT ANY WARRANTY; without even the implied warranty of 
     19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     20   GNU General Public License for more details. 
     21 
     22   You should have received a copy of the GNU General Public License 
     23   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     24 */ 
     25 
     26/** \file 
     27 *  \brief Source: user %interface for skin %selection 
     28 *  \author Vitaliy Filippov 
     29 *  \date 2014 
     30 */ 
     31 
     32#include <config.h> 
     33 
     34#include <stdlib.h> 
     35#include <sys/types.h> 
     36 
     37#include "lib/global.h" 
     38#include "lib/widget.h"         /* Listbox */ 
     39#include "lib/skin.h" 
     40#include "midnight.h" 
     41#include "chooseskin.h" 
     42 
     43/*** global variables ****************************************************************************/ 
     44 
     45/*** file scope macro definitions ****************************************************************/ 
     46 
     47#define MAX_ENTRY_LEN 40 
     48#define LIST_LINES 14 
     49#define N_DFLT_ENTRIES 1 
     50 
     51/*** file scope type declarations ****************************************************************/ 
     52 
     53/*** file scope variables ************************************************************************/ 
     54 
     55/*** file scope functions ************************************************************************/ 
     56 
     57static int 
     58exec_skin_dialog (GArray *names, const char *current_skin) 
     59{ 
     60    int i; 
     61 
     62    Listbox *skinlist = create_listbox_window (LIST_LINES, MAX_ENTRY_LEN, 
     63                                                 _("Choose skin"), NULL); 
     64    LISTBOX_APPEND_TEXT (skinlist, 'A', _("< Default >"), NULL); 
     65 
     66    for (i = 0; i < names->len; i++) 
     67    { 
     68        LISTBOX_APPEND_TEXT (skinlist, 0, g_array_index(names, char*, i), NULL); 
     69        if (current_skin && !strcmp(g_array_index(names, char*, i), current_skin)) 
     70            listbox_select_entry (skinlist->list, i+N_DFLT_ENTRIES); 
     71    } 
     72 
     73    return run_listbox (skinlist); 
     74} 
     75 
     76/* --------------------------------------------------------------------------------------------- */ 
     77/*** public functions ****************************************************************************/ 
     78/* --------------------------------------------------------------------------------------------- */ 
     79 
     80void 
     81filemanager_skin_dialog () 
     82{ 
     83    int skin; 
     84 
     85    GArray *names = mc_skin_list (); 
     86    char *current_skin = mc_skin__default.name; 
     87    skin = exec_skin_dialog (names, current_skin); 
     88 
     89    if (skin >= 0) 
     90    { 
     91        GError *error = NULL; 
     92        dlg_colors_t midnight_colors; 
     93        mc_skin_deinit (); 
     94        if (mc_global.tty.skin) 
     95        { 
     96            g_free(mc_global.tty.skin); 
     97        } 
     98        if (skin == 0) 
     99        { 
     100            /* default skin */ 
     101            mc_global.tty.skin = g_strdup ("default"); 
     102        } 
     103        else 
     104        { 
     105            mc_global.tty.skin = g_strdup (g_array_index (names, char *, skin-N_DFLT_ENTRIES)); 
     106        } 
     107        mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, "skin", mc_global.tty.skin); 
     108        mc_skin_init (&error); 
     109        if (error != NULL) 
     110        { 
     111            message (D_ERROR, _("Warning"), "%s", error->message); 
     112            g_error_free (error); 
     113            error = NULL; 
     114        } 
     115 
     116        /* refresh panel colors */ 
     117        panel_deinit (); 
     118        panel_init (); 
     119 
     120        /* refresh global dialog colors */ 
     121        midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_"); 
     122        midnight_colors[DLG_COLOR_FOCUS] = mc_skin_color_get ("dialog", "focus"); 
     123        midnight_colors[DLG_COLOR_HOT_NORMAL] = mc_skin_color_get ("dialog", "hotnormal"); 
     124        midnight_colors[DLG_COLOR_HOT_FOCUS] = mc_skin_color_get ("dialog", "hotfocus"); 
     125        midnight_colors[DLG_COLOR_TITLE] = mc_skin_color_get ("dialog", "title"); 
     126        memmove (midnight_dlg->color, midnight_colors, sizeof (dlg_colors_t)); 
     127 
     128        /* refresh highlighting colors */ 
     129        mc_fhl_free (&mc_filehighlight); 
     130        mc_filehighlight = mc_fhl_new (TRUE); 
     131 
     132        dlg_redraw(midnight_dlg); 
     133    } 
     134 
     135    for (skin = 0; skin < names->len; skin++) 
     136        g_free (g_array_index (names, char *, skin)); 
     137    g_array_free (names, TRUE); 
     138} 
     139 
     140/* --------------------------------------------------------------------------------------------- */ 
  • new file mc-4.8.11/src/filemanager/chooseskin.h

    - +  
     1/** \file chooseskin.h 
     2 *  \brief Header: skin choose dialog for Midnight Commander 
     3 */ 
     4 
     5#ifndef MC__CHOOSESKIN_H 
     6#define MC__CHOOSESKIN_H 
     7 
     8/*** typedefs(not structures) and defined constants **********************************************/ 
     9 
     10/*** enums ***************************************************************************************/ 
     11 
     12/*** structures declarations (and typedefs of structures)*****************************************/ 
     13 
     14/*** global variables defined in .c file *********************************************************/ 
     15 
     16/*** declarations of public functions ************************************************************/ 
     17 
     18void filemanager_skin_dialog (void); 
     19 
     20/*** inline functions ****************************************************************************/ 
     21 
     22#endif /* MC__CHOOSESKIN_H */ 
  • src/filemanager/midnight.c

    old new  
    7777#include "chmod.h" 
    7878#include "chown.h" 
    7979#include "achown.h" 
     80#include "chooseskin.h" 
    8081 
    8182#ifdef USE_INTERNAL_EDIT 
    8283#include "src/editor/edit.h" 
     
    332333    GList *entries = NULL; 
    333334 
    334335    entries = g_list_prepend (entries, menu_entry_create (_("&Configuration..."), CK_Options)); 
     336    entries = g_list_prepend (entries, menu_entry_create (_("&Skin..."), CK_OptionsSkin)); 
    335337    entries = g_list_prepend (entries, menu_entry_create (_("&Layout..."), CK_OptionsLayout)); 
    336338    entries = g_list_prepend (entries, menu_entry_create (_("&Panel options..."), CK_OptionsPanel)); 
    337339    entries = 
     
    12471249        jobs_cmd (); 
    12481250        break; 
    12491251#endif 
     1252    case CK_OptionsSkin: 
     1253        filemanager_skin_dialog (); 
     1254        break; 
    12501255    case CK_OptionsLayout: 
    12511256        layout_box (); 
    12521257        break;