From 540bdb85ed8e3ec6be957c1373216734cf1cd228 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 21 Apr 2009 11:48:13 +0300 Subject: [PATCH] Changes in SelectCodepage dialog: * Fixed change codepage of panel by hotkey * Dialog now show as centered relative to panel, not center of screen --- src/boxes.c | 2 +- src/cmd.c | 51 -------------------------------------- src/main.c | 4 +-- src/panel.h | 1 + src/screen.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++- src/selcodepage.c | 7 +++--- src/selcodepage.h | 2 +- src/wtools.c | 15 +++++++---- src/wtools.h | 2 ++ 9 files changed, 83 insertions(+), 64 deletions(-) diff --git a/src/boxes.c b/src/boxes.c index 2026ad865..bdf362b34 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -565,7 +565,7 @@ sel_charset_button (int action) { const char *cpname; char buf[64]; - new_display_codepage = select_charset (new_display_codepage, 1); + new_display_codepage = select_charset (0, 0, new_display_codepage, 1); cpname = (new_display_codepage < 0) ? _("Other 8 bit") : codepages[new_display_codepage].name; diff --git a/src/cmd.c b/src/cmd.c index 5c9559d9b..fe2dc802b 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -63,8 +63,6 @@ #include "execute.h" /* toggle_panels() */ #include "history.h" #include "strutil.h" -#include "selcodepage.h" /* do_select_codepage () */ -#include "charsets.h" /* get_codepage_id () */ #ifndef MAP_FILE @@ -1387,55 +1385,6 @@ toggle_listing_cmd (void) set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES); } -/* add "#enc:encodning" to end of path */ -/* if path end width a previous #enc:, only encoding is changed no additional - * #enc: is appended - * retun new string - */ -static char -*add_encoding_to_path (const char *path, const char *encoding) -{ - char *result; - char *semi; - char *slash; - - semi = g_strrstr (path, "#enc:"); - - if (semi != NULL) { - slash = strchr (semi, PATH_SEP); - if (slash != NULL) { - result = g_strconcat (path, "/#enc:", encoding, NULL); - } else { - *semi = 0; - result = g_strconcat (path, "/#enc:", encoding, NULL); - *semi = '#'; - } - } else { - result = g_strconcat (path, "/#enc:", encoding, NULL); - } - - return result; -} - -static void -set_panel_encoding (WPanel *panel) -{ - char *encoding = NULL; - char *cd_path; - -#ifdef HAVE_CHARSET - do_select_codepage (); - encoding = g_strdup( get_codepage_id ( source_codepage ) ); -#endif - if (encoding) { - cd_path = add_encoding_to_path (panel->cwd, encoding); - if (!do_panel_cd (MENU_PANEL, cd_path, 0)) - message (1, MSG_ERROR, _(" Cannot chdir to %s "), cd_path); - g_free (cd_path); - g_free (encoding); - } -} - void encoding_cmd (void) { diff --git a/src/main.c b/src/main.c index 3a056b69d..d847cc0ec 100644 --- a/src/main.c +++ b/src/main.c @@ -825,7 +825,7 @@ static menu_entry LeftMenu[] = { {' ', "", NULL_HOTKEY, 0}, {' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd}, {' ', "",NULL_HOTKEY, 0}, - {' ', N_("&Encoding... C-t"), 'C', encoding_cmd}, + {' ', N_("&Encoding... C-t"), NULL_HOTKEY, encoding_cmd}, #ifdef USE_NETCODE {' ', "", NULL_HOTKEY, 0}, #ifdef WITH_MCFS @@ -851,7 +851,7 @@ static menu_entry RightMenu[] = { {' ', "", NULL_HOTKEY, 0}, {' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd}, {' ', "",NULL_HOTKEY, 0}, - {' ', N_("&Encoding... C-t"), 'C', encoding_cmd}, + {' ', N_("&Encoding... C-t"), NULL_HOTKEY, encoding_cmd}, #ifdef USE_NETCODE {' ', "", NULL_HOTKEY, 0}, #ifdef WITH_MCFS diff --git a/src/panel.h b/src/panel.h index 45ba6e17a..8527e4457 100644 --- a/src/panel.h +++ b/src/panel.h @@ -89,6 +89,7 @@ extern int fast_reload; void panel_reload (WPanel *panel); void panel_set_sort_order (WPanel *panel, sortfn *sort_order); void panel_re_sort (WPanel *panel); +void set_panel_encoding (WPanel *); void update_dirty_panels (void); void panel_update_cols (Widget *widget, int frame_size); diff --git a/src/screen.c b/src/screen.c index 3983ba8fa..d741ef1dd 100644 --- a/src/screen.c +++ b/src/screen.c @@ -50,6 +50,8 @@ #include "main.h" /* the_menubar */ #include "unixcompat.h" #include "mountlist.h" /* my_statfs */ +#include "selcodepage.h" /* do_select_codepage () */ +#include "charsets.h" /* get_codepage_id () */ #include "strutil.h" #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) ) @@ -851,6 +853,36 @@ paint_panel (WPanel *panel) panel->dirty = 0; } +/* add "#enc:encodning" to end of path */ +/* if path end width a previous #enc:, only encoding is changed no additional + * #enc: is appended + * retun new string + */ +static char +*add_encoding_to_path (const char *path, const char *encoding) +{ + char *result; + char *semi; + char *slash; + + semi = g_strrstr (path, "#enc:"); + + if (semi != NULL) { + slash = strchr (semi, PATH_SEP); + if (slash != NULL) { + result = g_strconcat (path, "/#enc:", encoding, NULL); + } else { + *semi = 0; + result = g_strconcat (path, "/#enc:", encoding, NULL); + *semi = '#'; + } + } else { + result = g_strconcat (path, "/#enc:", encoding, NULL); + } + + return result; +} + /* * Repaint the contents of the panels without frames. To schedule panel * for repainting, set panel->dirty to 1. There are many reasons why @@ -2197,7 +2229,7 @@ static const panel_key_map panel_keymap [] = { { XCTRL('s'), start_search }, /* C-s like emacs */ { ALT('s'), start_search }, /* M-s not like emacs */ /* { XCTRL('t'), mark_file },*/ - { XCTRL('t'), encoding_cmd }, + { XCTRL('t'), set_panel_encoding }, { ALT('o'), chdir_other_panel }, { ALT('i'), sync_other_panel }, { ALT('l'), chdir_to_readlink }, @@ -2539,3 +2571,32 @@ panel_set_sort_order (WPanel *panel, sortfn *sort_order) } panel_re_sort (panel); } + +void +set_panel_encoding (WPanel *panel) +{ + char *encoding = NULL; + char *cd_path; +#ifdef HAVE_CHARSET + const char *errmsg; + int r; + int width = (panel->widget.x)? panel->widget.cols : panel->widget.cols * (-1); + + r = select_charset (width, 0, source_codepage, 0); + if ( r > 0 ) + source_codepage = r; + errmsg = init_translation_table (source_codepage, display_codepage); + if (errmsg) { + message (D_ERROR, MSG_ERROR, "%s", errmsg); + return; + } + encoding = g_strdup( get_codepage_id ( source_codepage ) ); +#endif + if (encoding) { + cd_path = add_encoding_to_path (panel->cwd, encoding); + if (!do_panel_cd (panel, cd_path, 0)) + message (1, MSG_ERROR, _(" Cannot chdir to %s "), cd_path); + g_free (cd_path); + g_free (encoding); + } +} diff --git a/src/selcodepage.c b/src/selcodepage.c index 0c54443c3..25b317038 100644 --- a/src/selcodepage.c +++ b/src/selcodepage.c @@ -45,13 +45,14 @@ get_hotkey (int n) } int -select_charset (int current_charset, int seldisplay) +select_charset (int delta_x, int delta_y, int current_charset, int seldisplay) { int i, menu_lines = n_codepages + 1; char buffer[255]; /* Create listbox */ - Listbox *listbox = create_listbox_window (ENTRY_LEN + 2, menu_lines, + Listbox *listbox = create_listbox_window_delta (delta_x, delta_y, + ENTRY_LEN + 2, menu_lines, _(" Choose input codepage "), "[Codepages Translation]"); @@ -95,7 +96,7 @@ do_select_codepage (void) const char *errmsg; int r; - r = select_charset (source_codepage, 0); + r = select_charset (0, 0, source_codepage, 0); if ( r > 0 ) source_codepage = r; diff --git a/src/selcodepage.h b/src/selcodepage.h index 06fbd77bd..84444befa 100644 --- a/src/selcodepage.h +++ b/src/selcodepage.h @@ -2,7 +2,7 @@ #define MC_SELCODEPAGE_H #ifdef HAVE_CHARSET -int select_charset (int current_charset, int seldisplay); +int select_charset (int delta_x, int delta_y, int current_charset, int seldisplay); int do_select_codepage (void); #endif /* HAVE_CHARSET */ diff --git a/src/wtools.c b/src/wtools.c index a619acd58..5b08ce7f5 100644 --- a/src/wtools.c +++ b/src/wtools.c @@ -41,7 +41,7 @@ Listbox * -create_listbox_window (int cols, int lines, const char *title, const char *help) +create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, const char *title, const char *help) { int xpos, ypos, len; Listbox *listbox = g_new (Listbox, 1); @@ -58,13 +58,12 @@ create_listbox_window (int cols, int lines, const char *title, const char *help) cols = len; cols = cols > COLS - 6 ? COLS - 6 : cols; - xpos = (COLS - cols) / 2; - ypos = (LINES - lines) / 2 - 2; - + xpos = (COLS - cols + delta_x) / 2; + ypos = (LINES - lines + delta_y) / 2 - 2; /* Create components */ listbox->dlg = create_dlg (ypos, xpos, lines + 6, cols + 4, dialog_colors, NULL, - help, title, DLG_CENTER | DLG_REVERSE); + help, title, DLG_REVERSE); listbox->list = listbox_new (2, 2, lines, cols, NULL); @@ -76,6 +75,12 @@ create_listbox_window (int cols, int lines, const char *title, const char *help) return listbox; } +Listbox * +create_listbox_window (int cols, int lines, const char *title, const char *help) +{ + return create_listbox_window_delta (0, 0, cols, lines, title, help); +} + /* Returns the number of the item selected */ int run_listbox (Listbox *l) { diff --git a/src/wtools.h b/src/wtools.h index e6e0e163e..ae7e8004d 100644 --- a/src/wtools.h +++ b/src/wtools.h @@ -9,6 +9,8 @@ typedef struct { } Listbox; /* Listbox utility functions */ +Listbox *create_listbox_window_delta (int delta_x, int delta_y, int cols, int lines, const char *title, const char *help); + Listbox *create_listbox_window (int cols, int lines, const char *title, const char *help); #define LISTBOX_APPEND_TEXT(l,h,t,d) \ listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)