mirror of https://github.com/MidnightCommander/mc
Merge branch '402_select_codepage'
* 402_select_codepage: Fixed source_codepage handling in editor (#402). Fixed type of variables that store result of get_codepage_id(). Fixed codepage selection (#402).
This commit is contained in:
commit
537bc71069
|
@ -281,13 +281,18 @@ edit_load_file_fast (WEdit *edit, const char *filename)
|
|||
{
|
||||
long buf, buf2;
|
||||
int file = -1;
|
||||
#ifdef HAVE_CHARSET
|
||||
const char *cp_id;
|
||||
#endif
|
||||
|
||||
edit->curs2 = edit->last_byte;
|
||||
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
|
||||
edit->utf8 = 0;
|
||||
#ifdef HAVE_CHARSET
|
||||
if ( get_codepage_id( source_codepage ) )
|
||||
edit->utf8 = str_isutf8 (get_codepage_id( source_codepage ));
|
||||
cp_id = get_codepage_id (source_codepage);
|
||||
|
||||
if (cp_id != NULL)
|
||||
edit->utf8 = str_isutf8 (cp_id);
|
||||
#endif
|
||||
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) {
|
||||
GString *errmsg = g_string_new(NULL);
|
||||
|
|
|
@ -2335,9 +2335,16 @@ void
|
|||
edit_select_codepage_cmd (WEdit *edit)
|
||||
{
|
||||
#ifdef HAVE_CHARSET
|
||||
do_select_codepage ();
|
||||
if ( get_codepage_id (source_codepage) )
|
||||
edit->utf8 = str_isutf8 (get_codepage_id (source_codepage));
|
||||
if (do_select_codepage ()) {
|
||||
const char *cp_id;
|
||||
|
||||
cp_id = get_codepage_id (source_codepage >= 0 ?
|
||||
source_codepage : display_codepage);
|
||||
|
||||
if (cp_id != NULL)
|
||||
edit->utf8 = str_isutf8 (cp_id);
|
||||
}
|
||||
|
||||
edit->force = REDRAW_COMPLETELY;
|
||||
edit_refresh_cmd (edit);
|
||||
#endif
|
||||
|
|
|
@ -126,7 +126,7 @@ static void status_string (WEdit * edit, char *s, int w)
|
|||
byte_str,
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
get_codepage_id ( source_codepage )
|
||||
source_codepage >= 0 ? get_codepage_id (source_codepage) : ""
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
|
@ -150,7 +150,7 @@ static void status_string (WEdit * edit, char *s, int w)
|
|||
byte_str,
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
get_codepage_id ( source_codepage )
|
||||
source_codepage >= 0 ? get_codepage_id (source_codepage) : ""
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include "../src/key.h" /* KEY_M_SHIFT */
|
||||
#include "../src/tty.h" /* keys */
|
||||
#include "../src/charsets.h" /* convert_from_input_c() */
|
||||
#include "../src/selcodepage.h" /* do_select_codepage() */
|
||||
#include "../src/main.h" /* display_codepage */
|
||||
#include "../src/strutil.h" /* str_isutf8 () */
|
||||
|
||||
|
|
29
src/boxes.c
29
src/boxes.c
|
@ -567,19 +567,26 @@ static WCheck *inpcheck;
|
|||
static int
|
||||
sel_charset_button (int action)
|
||||
{
|
||||
const char *cpname;
|
||||
char buf[64];
|
||||
int new_dcp;
|
||||
|
||||
(void) action;
|
||||
|
||||
new_display_codepage = select_charset (0, 0, new_display_codepage, 1);
|
||||
cpname = (new_display_codepage < 0)
|
||||
? _("Other 8 bit")
|
||||
: codepages[new_display_codepage].name;
|
||||
if ( cpname )
|
||||
utf8_display = str_isutf8 (cpname);
|
||||
/* avoid strange bug with label repainting */
|
||||
g_snprintf (buf, sizeof (buf), "%-27s", cpname);
|
||||
label_set_text (cplabel, buf);
|
||||
new_dcp = select_charset (0, 0, new_display_codepage, TRUE);
|
||||
|
||||
if (new_dcp != SELECT_CHARSET_CANCEL) {
|
||||
const char *cpname;
|
||||
char buf[BUF_TINY];
|
||||
|
||||
new_display_codepage = new_dcp;
|
||||
cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
|
||||
_("Other 8 bit") : codepages[new_display_codepage].name;
|
||||
if (cpname != NULL)
|
||||
utf8_display = str_isutf8 (cpname);
|
||||
/* avoid strange bug with label repainting */
|
||||
g_snprintf (buf, sizeof (buf), "%-27s", cpname);
|
||||
label_set_text (cplabel, buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
20
src/screen.c
20
src/screen.c
|
@ -54,7 +54,7 @@
|
|||
#include "main.h" /* the_menubar */
|
||||
#include "unixcompat.h"
|
||||
#include "mountlist.h" /* my_statfs */
|
||||
#include "selcodepage.h" /* do_select_codepage () */
|
||||
#include "selcodepage.h" /* select_charset () */
|
||||
#include "charsets.h" /* get_codepage_id () */
|
||||
#include "strutil.h"
|
||||
|
||||
|
@ -2651,13 +2651,13 @@ set_panel_encoding (WPanel *panel)
|
|||
int r;
|
||||
int width = (panel->widget.x)? panel->widget.cols : panel->widget.cols * (-1);
|
||||
|
||||
r = select_charset (width, 0, source_codepage, 0);
|
||||
r = select_charset (width, 0, source_codepage, FALSE);
|
||||
|
||||
if ( r == -2)
|
||||
return;
|
||||
if (r == SELECT_CHARSET_CANCEL)
|
||||
return; /* Cancel */
|
||||
|
||||
|
||||
if (r == -1){
|
||||
if (r == SELECT_CHARSET_NO_TRANSLATE) {
|
||||
/* No translation */
|
||||
errmsg = init_translation_table (display_codepage, display_codepage);
|
||||
cd_path = remove_encoding_from_path (panel->cwd);
|
||||
do_panel_cd (panel, cd_path, 0);
|
||||
|
@ -2672,13 +2672,13 @@ set_panel_encoding (WPanel *panel)
|
|||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
return;
|
||||
}
|
||||
encoding = g_strdup( get_codepage_id ( source_codepage ) );
|
||||
|
||||
encoding = get_codepage_id (source_codepage);
|
||||
#endif
|
||||
if (encoding) {
|
||||
if (encoding != NULL) {
|
||||
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);
|
||||
message (D_ERROR, MSG_ERROR, _(" Cannot chdir to %s "), cd_path);
|
||||
g_free (cd_path);
|
||||
g_free (encoding);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,16 +48,22 @@ get_hotkey (int n)
|
|||
return (n <= 9) ? '0' + n : 'a' + n - 10;
|
||||
}
|
||||
|
||||
/* Return value:
|
||||
* -2 (SELECT_CHARSET_CANCEL) : Cancel
|
||||
* -1 (SELECT_CHARSET_OTHER_8BIT) : "Other 8 bit" if seldisplay == TRUE
|
||||
* -1 (SELECT_CHARSET_NO_TRANSLATE) : "No translation" if seldisplay == FALSE
|
||||
* >= 0 : charset number
|
||||
*/
|
||||
int
|
||||
select_charset (int delta_x, int delta_y, int current_charset, int seldisplay)
|
||||
select_charset (int delta_x, int delta_y, int current_charset, gboolean seldisplay)
|
||||
{
|
||||
int i, menu_lines = n_codepages + 1;
|
||||
int i;
|
||||
char buffer[255];
|
||||
|
||||
/* Create listbox */
|
||||
Listbox *listbox = create_listbox_window_delta (delta_x, delta_y,
|
||||
ENTRY_LEN + 2, menu_lines,
|
||||
_(" Choose input codepage "),
|
||||
ENTRY_LEN + 2, n_codepages + 1,
|
||||
_("Choose codepage"),
|
||||
"[Codepages Translation]");
|
||||
|
||||
if (!seldisplay)
|
||||
|
@ -87,29 +93,40 @@ select_charset (int delta_x, int delta_y, int current_charset, int seldisplay)
|
|||
|
||||
i = run_listbox (listbox);
|
||||
|
||||
return (seldisplay) ? ((i >= n_codepages) ? -1 : i)
|
||||
: (i - 1);
|
||||
if (i < 0) {
|
||||
/* Cancel dialog */
|
||||
return SELECT_CHARSET_CANCEL;
|
||||
} else {
|
||||
/* some charset has been selected */
|
||||
if (seldisplay) {
|
||||
/* charset list is finished with "Other 8 bit" item */
|
||||
return (i >= n_codepages) ? SELECT_CHARSET_OTHER_8BIT : i;
|
||||
} else {
|
||||
/* charset list is began with "- < No translation >" item */
|
||||
return (i - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper functions for codepages support */
|
||||
|
||||
|
||||
int
|
||||
gboolean
|
||||
do_select_codepage (void)
|
||||
{
|
||||
const char *errmsg;
|
||||
const char *errmsg = NULL;
|
||||
int r;
|
||||
|
||||
r = select_charset (0, 0, source_codepage, 0);
|
||||
if ( r > 0 )
|
||||
source_codepage = r;
|
||||
r = select_charset (0, 0, source_codepage, FALSE);
|
||||
if (r == SELECT_CHARSET_CANCEL)
|
||||
return FALSE;
|
||||
|
||||
errmsg = init_translation_table (source_codepage, display_codepage);
|
||||
if (errmsg) {
|
||||
source_codepage = r;
|
||||
|
||||
errmsg = init_translation_table (r == SELECT_CHARSET_NO_TRANSLATE ?
|
||||
display_codepage : source_codepage,
|
||||
display_codepage);
|
||||
if (errmsg != NULL)
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
return (errmsg == NULL);
|
||||
}
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
|
|
@ -7,8 +7,24 @@
|
|||
#define MC_SELCODEPAGE_H
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
int select_charset (int delta_x, int delta_y, int current_charset, int seldisplay);
|
||||
int do_select_codepage (void);
|
||||
|
||||
#include "global.h"
|
||||
|
||||
int select_charset (int delta_x, int delta_y, int current_charset, gboolean seldisplay);
|
||||
gboolean do_select_codepage (void);
|
||||
|
||||
/* some results of select_charset() */
|
||||
#define SELECT_CHARSET_CANCEL -2
|
||||
/* select_charset() returns this value if dialog has been cenceled */
|
||||
#define SELECT_CHARSET_OTHER_8BIT -1
|
||||
/* select_charset() returns this value if seldisplay == TRUE
|
||||
* and the last item has been selected. Last item is "Other 8 bits" */
|
||||
#define SELECT_CHARSET_NO_TRANSLATE -1
|
||||
/* select_charset() returns this value if seldisplay == FALSE
|
||||
* and the 1st item has been selected. 1st item is "No translation" */
|
||||
/* In other cases select_charset() returns non-negative value
|
||||
* which is number of codepage in codepage list */
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
#endif
|
||||
#endif /* MC_SELCODEPAGE_H */
|
||||
|
|
21
src/view.c
21
src/view.c
|
@ -3466,15 +3466,17 @@ static void view_cmk_moveto_bottom (void *w, int n) {
|
|||
static void
|
||||
view_select_encoding (WView *view)
|
||||
{
|
||||
char *enc = NULL;
|
||||
GIConv conv;
|
||||
struct cache_line *line;
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
do_select_codepage ();
|
||||
enc = g_strdup( get_codepage_id ( source_codepage ) );
|
||||
#endif
|
||||
if ( enc ) {
|
||||
char *enc = NULL;
|
||||
|
||||
if (!do_select_codepage ())
|
||||
return;
|
||||
|
||||
enc = get_codepage_id (source_codepage);
|
||||
if (enc != NULL) {
|
||||
GIConv conv;
|
||||
struct cache_line *line;
|
||||
|
||||
conv = str_crt_conv_from (enc);
|
||||
if (conv != INVALID_CONV) {
|
||||
if (view->converter != str_cnv_from_term)
|
||||
|
@ -3484,9 +3486,8 @@ view_select_encoding (WView *view)
|
|||
line = view_offset_to_line (view, view->dpy_start);
|
||||
view_set_first_showed (view, line);
|
||||
}
|
||||
g_free(enc);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue