Allow bookmark labels to be UTF-8 !

This commit is contained in:
Thomas Bernard 2019-02-01 12:53:56 +01:00
parent ad1c38e2ca
commit 9073c040c9
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 54 additions and 43 deletions

View File

@ -1175,19 +1175,41 @@ static void Display_bookmark(T_Dropdown_button * Button, int bookmark_number)
if (Config.Bookmark_directory[bookmark_number]) if (Config.Bookmark_directory[bookmark_number])
{ {
int label_size; int label_size;
// Libellé // Label
Print_in_window_limited(Button->Pos_X+3+10,Button->Pos_Y+2,Config.Bookmark_label[bookmark_number],8,MC_Black,MC_Light); #ifdef ENABLE_FILENAMES_ICONV
word label[16];
char * input = Config.Bookmark_label[bookmark_number];
size_t inbytesleft = strlen(Config.Bookmark_label[bookmark_number]);
char * output = (char *)label;
size_t outbytesleft = sizeof(label) - 2;
if (cd_utf16 != (iconv_t)-1 && iconv(cd_utf16, &input, &inbytesleft, &output, &outbytesleft) != (size_t)-1)
{
output[0] = '\0';
output[1] = '\0';
Print_in_window_limited_unicode(Button->Pos_X+3+10, Button->Pos_Y+2,
label, 8, MC_Black, MC_Light);
label_size = Unicode_strlen(label);
}
else
#endif
{
// Fallback
Print_in_window_limited(Button->Pos_X+3+10, Button->Pos_Y+2,
Config.Bookmark_label[bookmark_number],
8, MC_Black, MC_Light);
label_size = strlen(Config.Bookmark_label[bookmark_number]); label_size = strlen(Config.Bookmark_label[bookmark_number]);
}
if (label_size<8) if (label_size<8)
Window_rectangle(Button->Pos_X+3+10+label_size*8,Button->Pos_Y+2,(8-label_size)*8,8,MC_Light); Window_rectangle(Button->Pos_X+3+10+label_size*8,Button->Pos_Y+2,(8-label_size)*8,8,MC_Light);
// Menu apparait sur clic droit // the menu is activated with right clic
Button->Active_button = RIGHT_SIDE; Button->Active_button = RIGHT_SIDE;
} }
else else
{ {
// Libellé // Label
Print_in_window(Button->Pos_X+3+10,Button->Pos_Y+2,"--------",MC_Dark,MC_Light); Print_in_window(Button->Pos_X+3+10, Button->Pos_Y+2, "--------",
// Menu apparait sur clic droit ou gauche MC_Dark, MC_Light);
// the menu is activated with right or left clic
Button->Active_button = RIGHT_SIDE|LEFT_SIDE; Button->Active_button = RIGHT_SIDE|LEFT_SIDE;
} }
// item actifs // item actifs
@ -2157,34 +2179,27 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
free(Config.Bookmark_directory[clicked_button-10]); free(Config.Bookmark_directory[clicked_button-10]);
Config.Bookmark_directory[clicked_button-10] = NULL; Config.Bookmark_directory[clicked_button-10] = NULL;
Config.Bookmark_label[clicked_button-10][0] = '\0'; Config.Bookmark_label[clicked_button-10][0] = '\0';
temp=strlen(Selector->Directory); Config.Bookmark_directory[clicked_button-10] = strdup(Selector->Directory);
Config.Bookmark_directory[clicked_button-10]=malloc(temp+1);
strcpy(Config.Bookmark_directory[clicked_button-10],Selector->Directory);
directory_name = Find_last_separator(Selector->Directory); directory_name = Find_last_separator(Selector->Directory);
if (directory_name && directory_name[1] != '\0') if (directory_name && directory_name[1] != '\0')
directory_name++; directory_name++;
else else
directory_name = Selector->Directory; directory_name = Selector->Directory;
temp=strlen(directory_name); strncpy(Config.Bookmark_label[clicked_button-10], directory_name, sizeof(Config.Bookmark_label[0]) - 1);
strncpy(Config.Bookmark_label[clicked_button-10],directory_name,8); Config.Bookmark_label[clicked_button-10][sizeof(Config.Bookmark_label[0]) - 1]='\0';
if (temp>8)
{
Config.Bookmark_label[clicked_button-10][7]=ELLIPSIS_CHARACTER;
Config.Bookmark_label[clicked_button-10][8]='\0';
}
Display_bookmark(bookmark_dropdown[clicked_button-10],clicked_button-10); Display_bookmark(bookmark_dropdown[clicked_button-10],clicked_button-10);
break; break;
case 1: // Rename case 1: // Rename
if (Config.Bookmark_directory[clicked_button-10]) if (Config.Bookmark_directory[clicked_button-10])
{ {
// On enlève les "..." avant l'édition char bookmark_label[24];
char bookmark_label[8+1]; /// @todo convert label to unicode before editing
strcpy(bookmark_label, Config.Bookmark_label[clicked_button-10]); strcpy(bookmark_label, Config.Bookmark_label[clicked_button-10]);
if (bookmark_label[7]==ELLIPSIS_CHARACTER) if (Readline_ex(bookmark_dropdown[clicked_button-10]->Pos_X+3+10,
bookmark_label[7]='\0'; bookmark_dropdown[clicked_button-10]->Pos_Y+2,
if (Readline_ex(bookmark_dropdown[clicked_button-10]->Pos_X+3+10,bookmark_dropdown[clicked_button-10]->Pos_Y+2,bookmark_label,8,8,INPUT_TYPE_STRING,0)) bookmark_label, 8, sizeof(bookmark_label) - 1, INPUT_TYPE_STRING, 0))
strcpy(Config.Bookmark_label[clicked_button-10], bookmark_label); strcpy(Config.Bookmark_label[clicked_button-10], bookmark_label);
Display_bookmark(bookmark_dropdown[clicked_button-10],clicked_button-10); Display_bookmark(bookmark_dropdown[clicked_button-10],clicked_button-10);
Display_cursor(); Display_cursor();
@ -2214,13 +2229,8 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
directory_name++; directory_name++;
else else
directory_name=Selector->Directory; directory_name=Selector->Directory;
temp=strlen(directory_name); strncpy(Config.Bookmark_label[clicked_button-10], directory_name, sizeof(Config.Bookmark_label[0]) - 1);
strncpy(Config.Bookmark_label[clicked_button-10],directory_name,8); Config.Bookmark_label[clicked_button-10][sizeof(Config.Bookmark_label[0]) - 1] = '\0';
if (temp>8)
{
Config.Bookmark_label[clicked_button-10][7]=ELLIPSIS_CHARACTER;
Config.Bookmark_label[clicked_button-10][8]='\0';
}
Display_bookmark(bookmark_dropdown[clicked_button-10],clicked_button-10); Display_bookmark(bookmark_dropdown[clicked_button-10],clicked_button-10);
} }
else else

View File

@ -836,12 +836,13 @@ int Load_INI(T_Config * conf)
int size = strlen(value_label); int size = strlen(value_label);
if (size!=0) if (size!=0)
{ {
if (size>8) if (size >= sizeof(conf->Bookmark_label[0]))
{ {
value_label[7]=ELLIPSIS_CHARACTER; memcpy(conf->Bookmark_label[index], value_label, sizeof(conf->Bookmark_label[0]) - 1);
value_label[8]='\0'; conf->Bookmark_label[index][sizeof(conf->Bookmark_label[0]) - 1] = '\0';
} }
strcpy(conf->Bookmark_label[index],value_label); else
memcpy(conf->Bookmark_label[index], value_label, size + 1);
} }
} }
else else

View File

@ -366,7 +366,7 @@ typedef struct
byte Auto_nb_used; ///< Boolean, true to count colors in Palette screen. byte Auto_nb_used; ///< Boolean, true to count colors in Palette screen.
byte Default_resolution; ///< Default video mode to use on startup. Index in ::Video_mode. byte Default_resolution; ///< Default video mode to use on startup. Index in ::Video_mode.
char *Bookmark_directory[NB_BOOKMARKS];///< Bookmarked directories in fileselectors: This is the full directory name. char *Bookmark_directory[NB_BOOKMARKS];///< Bookmarked directories in fileselectors: This is the full directory name.
char Bookmark_label[NB_BOOKMARKS][8+1];///< Bookmarked directories in fileselectors: This is the displayed name. char Bookmark_label[NB_BOOKMARKS][24]; ///< Bookmarked directories in fileselectors: This is the displayed name.
int Window_pos_x; ///< Last window x position (9999 if unsupportd/irrelevant for the platform) int Window_pos_x; ///< Last window x position (9999 if unsupportd/irrelevant for the platform)
int Window_pos_y; ///< Last window y position (9999 if unsupportd/irrelevant for the platform) int Window_pos_y; ///< Last window y position (9999 if unsupportd/irrelevant for the platform)
word Double_click_speed; ///< Maximum delay for double-click, in ms. word Double_click_speed; ///< Maximum delay for double-click, in ms.