mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
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:
parent
e19de53a06
commit
540bdb85ed
@ -565,7 +565,7 @@ sel_charset_button (int action)
|
|||||||
{
|
{
|
||||||
const char *cpname;
|
const char *cpname;
|
||||||
char buf[64];
|
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)
|
cpname = (new_display_codepage < 0)
|
||||||
? _("Other 8 bit")
|
? _("Other 8 bit")
|
||||||
: codepages[new_display_codepage].name;
|
: codepages[new_display_codepage].name;
|
||||||
|
51
src/cmd.c
51
src/cmd.c
@ -63,8 +63,6 @@
|
|||||||
#include "execute.h" /* toggle_panels() */
|
#include "execute.h" /* toggle_panels() */
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "strutil.h"
|
#include "strutil.h"
|
||||||
#include "selcodepage.h" /* do_select_codepage () */
|
|
||||||
#include "charsets.h" /* get_codepage_id () */
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAP_FILE
|
#ifndef MAP_FILE
|
||||||
@ -1387,55 +1385,6 @@ toggle_listing_cmd (void)
|
|||||||
set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES);
|
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
|
void
|
||||||
encoding_cmd (void)
|
encoding_cmd (void)
|
||||||
{
|
{
|
||||||
|
@ -825,7 +825,7 @@ static menu_entry LeftMenu[] = {
|
|||||||
{' ', "", NULL_HOTKEY, 0},
|
{' ', "", NULL_HOTKEY, 0},
|
||||||
{' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd},
|
{' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd},
|
||||||
{' ', "",NULL_HOTKEY, 0},
|
{' ', "",NULL_HOTKEY, 0},
|
||||||
{' ', N_("&Encoding... C-t"), 'C', encoding_cmd},
|
{' ', N_("&Encoding... C-t"), NULL_HOTKEY, encoding_cmd},
|
||||||
#ifdef USE_NETCODE
|
#ifdef USE_NETCODE
|
||||||
{' ', "", NULL_HOTKEY, 0},
|
{' ', "", NULL_HOTKEY, 0},
|
||||||
#ifdef WITH_MCFS
|
#ifdef WITH_MCFS
|
||||||
@ -851,7 +851,7 @@ static menu_entry RightMenu[] = {
|
|||||||
{' ', "", NULL_HOTKEY, 0},
|
{' ', "", NULL_HOTKEY, 0},
|
||||||
{' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd},
|
{' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd},
|
||||||
{' ', "",NULL_HOTKEY, 0},
|
{' ', "",NULL_HOTKEY, 0},
|
||||||
{' ', N_("&Encoding... C-t"), 'C', encoding_cmd},
|
{' ', N_("&Encoding... C-t"), NULL_HOTKEY, encoding_cmd},
|
||||||
#ifdef USE_NETCODE
|
#ifdef USE_NETCODE
|
||||||
{' ', "", NULL_HOTKEY, 0},
|
{' ', "", NULL_HOTKEY, 0},
|
||||||
#ifdef WITH_MCFS
|
#ifdef WITH_MCFS
|
||||||
|
@ -89,6 +89,7 @@ extern int fast_reload;
|
|||||||
void panel_reload (WPanel *panel);
|
void panel_reload (WPanel *panel);
|
||||||
void panel_set_sort_order (WPanel *panel, sortfn *sort_order);
|
void panel_set_sort_order (WPanel *panel, sortfn *sort_order);
|
||||||
void panel_re_sort (WPanel *panel);
|
void panel_re_sort (WPanel *panel);
|
||||||
|
void set_panel_encoding (WPanel *);
|
||||||
|
|
||||||
void update_dirty_panels (void);
|
void update_dirty_panels (void);
|
||||||
void panel_update_cols (Widget *widget, int frame_size);
|
void panel_update_cols (Widget *widget, int frame_size);
|
||||||
|
63
src/screen.c
63
src/screen.c
@ -50,6 +50,8 @@
|
|||||||
#include "main.h" /* the_menubar */
|
#include "main.h" /* the_menubar */
|
||||||
#include "unixcompat.h"
|
#include "unixcompat.h"
|
||||||
#include "mountlist.h" /* my_statfs */
|
#include "mountlist.h" /* my_statfs */
|
||||||
|
#include "selcodepage.h" /* do_select_codepage () */
|
||||||
|
#include "charsets.h" /* get_codepage_id () */
|
||||||
#include "strutil.h"
|
#include "strutil.h"
|
||||||
|
|
||||||
#define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
|
#define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
|
||||||
@ -851,6 +853,36 @@ paint_panel (WPanel *panel)
|
|||||||
panel->dirty = 0;
|
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
|
* Repaint the contents of the panels without frames. To schedule panel
|
||||||
* for repainting, set panel->dirty to 1. There are many reasons why
|
* 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 */
|
{ XCTRL('s'), start_search }, /* C-s like emacs */
|
||||||
{ ALT('s'), start_search }, /* M-s not like emacs */
|
{ ALT('s'), start_search }, /* M-s not like emacs */
|
||||||
/* { XCTRL('t'), mark_file },*/
|
/* { XCTRL('t'), mark_file },*/
|
||||||
{ XCTRL('t'), encoding_cmd },
|
{ XCTRL('t'), set_panel_encoding },
|
||||||
{ ALT('o'), chdir_other_panel },
|
{ ALT('o'), chdir_other_panel },
|
||||||
{ ALT('i'), sync_other_panel },
|
{ ALT('i'), sync_other_panel },
|
||||||
{ ALT('l'), chdir_to_readlink },
|
{ ALT('l'), chdir_to_readlink },
|
||||||
@ -2539,3 +2571,32 @@ panel_set_sort_order (WPanel *panel, sortfn *sort_order)
|
|||||||
}
|
}
|
||||||
panel_re_sort (panel);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -45,13 +45,14 @@ get_hotkey (int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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;
|
int i, menu_lines = n_codepages + 1;
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
|
|
||||||
/* Create listbox */
|
/* 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 "),
|
_(" Choose input codepage "),
|
||||||
"[Codepages Translation]");
|
"[Codepages Translation]");
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ do_select_codepage (void)
|
|||||||
const char *errmsg;
|
const char *errmsg;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = select_charset (source_codepage, 0);
|
r = select_charset (0, 0, source_codepage, 0);
|
||||||
if ( r > 0 )
|
if ( r > 0 )
|
||||||
source_codepage = r;
|
source_codepage = r;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define MC_SELCODEPAGE_H
|
#define MC_SELCODEPAGE_H
|
||||||
|
|
||||||
#ifdef HAVE_CHARSET
|
#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);
|
int do_select_codepage (void);
|
||||||
#endif /* HAVE_CHARSET */
|
#endif /* HAVE_CHARSET */
|
||||||
|
|
||||||
|
15
src/wtools.c
15
src/wtools.c
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
|
|
||||||
Listbox *
|
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;
|
int xpos, ypos, len;
|
||||||
Listbox *listbox = g_new (Listbox, 1);
|
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 = len;
|
||||||
|
|
||||||
cols = cols > COLS - 6 ? COLS - 6 : cols;
|
cols = cols > COLS - 6 ? COLS - 6 : cols;
|
||||||
xpos = (COLS - cols) / 2;
|
xpos = (COLS - cols + delta_x) / 2;
|
||||||
ypos = (LINES - lines) / 2 - 2;
|
ypos = (LINES - lines + delta_y) / 2 - 2;
|
||||||
|
|
||||||
/* Create components */
|
/* Create components */
|
||||||
listbox->dlg =
|
listbox->dlg =
|
||||||
create_dlg (ypos, xpos, lines + 6, cols + 4, dialog_colors, NULL,
|
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);
|
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;
|
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 */
|
/* Returns the number of the item selected */
|
||||||
int run_listbox (Listbox *l)
|
int run_listbox (Listbox *l)
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,8 @@ typedef struct {
|
|||||||
} Listbox;
|
} Listbox;
|
||||||
|
|
||||||
/* Listbox utility functions */
|
/* 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);
|
Listbox *create_listbox_window (int cols, int lines, const char *title, const char *help);
|
||||||
#define LISTBOX_APPEND_TEXT(l,h,t,d) \
|
#define LISTBOX_APPEND_TEXT(l,h,t,d) \
|
||||||
listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
|
listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
|
||||||
|
Loading…
Reference in New Issue
Block a user