Ticket #2165: mc-skin-selector-alpha1.patch

File mc-skin-selector-alpha1.patch, 10.3 KB (added by egmont, 6 years ago)

alpha1

  • lib/keybind.c

    diff --git a/lib/keybind.c b/lib/keybind.c
    index 9e101b3..f95cf0e 100644
    a b 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

    diff --git a/lib/keybind.h b/lib/keybind.h
    index 5bfb81b..d8ed810 100644
    a b 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

    diff --git a/lib/skin.h b/lib/skin.h
    index e67c49a..9dae7ed 100644
    a b extern mc_skin_t mc_skin__default; 
    129129 
    130130/*** declarations of public functions ************************************************************/ 
    131131 
    132 gboolean mc_skin_init (GError **); 
     132gboolean mc_skin_init (const gchar *, GError **); 
    133133void mc_skin_deinit (void); 
    134134 
    135135int mc_skin_color_get (const gchar *, const gchar *); 
  • lib/skin/common.c

    diff --git a/lib/skin/common.c b/lib/skin/common.c
    index 1737a4b..5a11542 100644
    a b mc_skin_hash_destroy_value (gpointer data) 
    6060 
    6161/* --------------------------------------------------------------------------------------------- */ 
    6262 
    63 static char * 
     63char * 
    6464mc_skin_get_default_name (void) 
    6565{ 
    6666    char *tmp_str; 
    mc_skin_get_default_name (void) 
    8080 
    8181/* --------------------------------------------------------------------------------------------- */ 
    8282 
    83 static void 
    84 mc_skin_reinit (void) 
     83void 
     84mc_skin_reinit (const gchar *skin_override) 
    8585{ 
     86    GError *error = NULL; 
    8687    mc_skin_deinit (); 
    87     mc_skin__default.name = mc_skin_get_default_name (); 
    88     mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal, 
    89                                                      g_free, mc_skin_hash_destroy_value); 
     88    tty_color_free_all_tmp (); 
     89    tty_color_free_all_non_tmp (); 
     90    mc_skin_init (skin_override, &error); 
    9091} 
    9192 
    9293/* --------------------------------------------------------------------------------------------- */ 
    mc_skin_reinit (void) 
    9495static void 
    9596mc_skin_try_to_load_default (void) 
    9697{ 
    97     mc_skin_reinit (); 
     98    mc_skin_reinit (NULL); 
    9899    g_free (mc_skin__default.name); 
    99100    mc_skin__default.name = g_strdup ("default"); 
    100101    if (!mc_skin_ini_file_load (&mc_skin__default)) 
    101102    { 
    102         mc_skin_reinit (); 
     103        mc_skin_reinit (NULL); 
    103104        mc_skin_set_hardcoded_skin (&mc_skin__default); 
    104105    } 
    105106 
    mc_skin_try_to_load_default (void) 
    110111/* --------------------------------------------------------------------------------------------- */ 
    111112 
    112113gboolean 
    113 mc_skin_init (GError ** error) 
     114mc_skin_init (const gchar *skin_override, GError ** error) 
    114115{ 
    115116    gboolean is_good_init = TRUE; 
    116117 
    117118    mc_skin__default.have_256_colors = FALSE; 
    118119 
    119     mc_skin__default.name = mc_skin_get_default_name (); 
     120    mc_skin__default.name = 
     121        skin_override != NULL ? g_strdup(skin_override) : mc_skin_get_default_name (); 
    120122 
    121123    mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal, 
    122124                                                     g_free, mc_skin_hash_destroy_value); 
  • lib/widget/dialog.c

    diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c
    index 12e899f..9338cca 100644
    a b dlg_create (gboolean modal, int y1, int x1, int lines, int cols, 
    780780 
    781781    new_d->state = DLG_CONSTRUCT; 
    782782    new_d->modal = modal; 
    783     if (colors != NULL) 
    784         memmove (new_d->color, colors, sizeof (dlg_colors_t)); 
     783    new_d->color = colors; 
    785784    new_d->help_ctx = help_ctx; 
    786785    new_d->flags = flags; 
    787786    new_d->data = NULL; 
  • lib/widget/dialog.h

    diff --git a/lib/widget/dialog.h b/lib/widget/dialog.h
    index 20cb8b7..17795bb 100644
    a b 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 */ 
  • src/filemanager/boxes.c

    diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c
    index bd15ae9..6e9438f 100644
    a b static int listing_user_hotkey = 'u'; 
    104104static unsigned long panel_listing_types_id, panel_user_format_id; 
    105105static unsigned long mini_user_status_id, mini_user_format_id; 
    106106 
     107static unsigned long skin_name_id; 
     108 
    107109#ifdef HAVE_CHARSET 
    108110static int new_display_codepage; 
    109111static unsigned long disp_bits_name_id; 
    configure_box (void) 
    516518 
    517519/* --------------------------------------------------------------------------------------------- */ 
    518520 
     521static void 
     522skin_apply (const gchar *skin_override) 
     523{ 
     524    mc_skin_reinit (skin_override); 
     525    mc_fhl_free (&mc_filehighlight); 
     526    mc_filehighlight = mc_fhl_new (TRUE); 
     527    dlg_set_default_colors (); 
     528    panel_deinit (); 
     529    panel_init (); 
     530} 
     531 
     532/* --------------------------------------------------------------------------------------------- */ 
     533 
     534static cb_ret_t 
     535skin_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) 
     536{ 
     537    return dlg_default_callback (w, sender, msg, parm, data); 
     538} 
     539 
     540/* --------------------------------------------------------------------------------------------- */ 
     541 
     542static int 
     543sel_skin_button (WButton * button, int action) 
     544{ 
     545    int result; 
     546    WListbox *skin_list; 
     547    WDialog *skin_dlg; 
     548    int lxx, lyy; 
     549    int b_pos; 
     550 
     551    lxx = (COLS - 74) / 2 + 35; 
     552    lyy = (LINES - 13) / 2; 
     553    skin_dlg = 
     554        dlg_create (TRUE, lyy, lxx, 13, 21, dialog_colors, skin_callback, NULL, 
     555                    "[skin]" /* ??? help section maybe ?? */, _("Skin"), DLG_COMPACT); 
     556 
     557    skin_list = listbox_new (1, 1, 11, 19, FALSE, NULL); 
     558    listbox_add_item (skin_list, LISTBOX_APPEND_AT_END, 0, "default", NULL); 
     559    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "dark", NULL); 
     560    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "darkfar", NULL); 
     561    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "double-lines", NULL); 
     562    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "featured", NULL); 
     563    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "gotar", NULL); 
     564    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "mc46", NULL); 
     565    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "nicedark", NULL); 
     566    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "modarin256", NULL); 
     567    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "modarin256root", NULL); 
     568    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "sand256", NULL); 
     569    listbox_add_item (skin_list, LISTBOX_APPEND_SORTED, 0, "xoria256", NULL); 
     570    listbox_select_entry (skin_list, 0); 
     571 
     572    b_pos = skin_list->pos; 
     573    add_widget (skin_dlg, skin_list); 
     574 
     575    result = dlg_run (skin_dlg); 
     576    if (result == B_ENTER /* && b_pos != skin_list->pos */) { 
     577        char *skin_name; 
     578        listbox_get_current (skin_list, &skin_name, NULL); 
     579        skin_apply (skin_name); 
     580 
     581        Widget *w; 
     582        w = dlg_find_by_id (WIDGET (button)->owner, skin_name_id); 
     583        button_set_text (BUTTON (w), g_strdup(skin_name)); 
     584    } 
     585    dlg_destroy (skin_dlg); 
     586    return 0; 
     587} 
     588 
     589/* --------------------------------------------------------------------------------------------- */ 
     590 
     591void 
     592appearance_box (void) 
     593{ 
     594    char *default_skin_name = mc_skin_get_default_name(); 
     595 
     596    quick_widget_t quick_widgets[] = { 
     597        /* *INDENT-OFF* */ 
     598        QUICK_START_COLUMNS, 
     599            QUICK_LABEL (N_("Skin:"), NULL), 
     600        QUICK_NEXT_COLUMN, 
     601            QUICK_BUTTON (default_skin_name, B_USER, sel_skin_button, &skin_name_id), 
     602        QUICK_STOP_COLUMNS, 
     603        QUICK_BUTTONS_OK_CANCEL, 
     604        QUICK_END 
     605        /* *INDENT-ON* */ 
     606    }; 
     607 
     608    quick_dialog_t qdlg = { 
     609        -1, -1, 50, 
     610        _("Appearance"), "[Appearance]", 
     611        quick_widgets, NULL, NULL 
     612    }; 
     613 
     614    if (quick_dialog (&qdlg) == B_ENTER) { 
     615        // save... 
     616    } else { 
     617        skin_apply (NULL); 
     618    } 
     619 
     620    g_free (default_skin_name); 
     621} 
     622 
     623/* --------------------------------------------------------------------------------------------- */ 
     624 
    519625void 
    520626panel_options_box (void) 
    521627{ 
  • src/filemanager/boxes.h

    diff --git a/src/filemanager/boxes.h b/src/filemanager/boxes.h
    index 08c86a3..9859a73 100644
    a b  
    1919/*** declarations of public functions ************************************************************/ 
    2020 
    2121void configure_box (void); 
     22void appearance_box (void); 
    2223void panel_options_box (void); 
    2324int panel_listing_box (WPanel * p, char **user, char **mini, int *use_msformat, int num); 
    2425const panel_field_t *sort_box (dir_sort_options_t * op, const panel_field_t * sort_field); 
  • src/filemanager/midnight.c

    diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c
    index f3ba774..987d9bd 100644
    a b create_options_menu (void) 
    337337    entries = 
    338338        g_list_prepend (entries, menu_entry_create (_("C&onfirmation..."), CK_OptionsConfirm)); 
    339339    entries = 
     340        g_list_prepend (entries, menu_entry_create (_("&Appearance..."), CK_OptionsAppearance)); 
     341    entries = 
    340342        g_list_prepend (entries, menu_entry_create (_("&Display bits..."), CK_OptionsDisplayBits)); 
    341343    entries = g_list_prepend (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys)); 
    342344#ifdef ENABLE_VFS 
    midnight_execute_cmd (Widget * sender, unsigned long command) 
    12501252    case CK_OptionsLayout: 
    12511253        layout_box (); 
    12521254        break; 
     1255    case CK_OptionsAppearance: 
     1256        appearance_box (); 
     1257        break; 
    12531258    case CK_LearnKeys: 
    12541259        learn_keys (); 
    12551260        break; 
  • src/main.c

    diff --git a/src/main.c b/src/main.c
    index f4005cc..87981f5 100644
    a b main (int argc, char *argv[]) 
    371371 
    372372    tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors); 
    373373 
    374     mc_skin_init (&error); 
     374    mc_skin_init (NULL, &error); 
    375375    if (error != NULL) 
    376376    { 
    377377        message (D_ERROR, _("Warning"), "%s", error->message);