Changes in SelectCodepage dialog:

* Fixed change codepage of panel by hotkey
 * Dialog now show as centered relative to panel, not center of screen
This commit is contained in:
Slava Zanko 2009-04-21 11:48:13 +03:00
parent e19de53a06
commit 540bdb85ed
9 changed files with 83 additions and 64 deletions

View File

@ -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;

View File

@ -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)
{

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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 */

View File

@ -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)
{

View File

@ -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)