Multi-shorcuts option now works. Default OFF, it will avoid situations where user mistakenly sets the same key for multiple actions.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1769 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2011-04-04 22:30:02 +00:00
parent 1d24885ddc
commit 860648b190
5 changed files with 87 additions and 2 deletions

View File

@ -942,7 +942,7 @@ void Button_Settings(void)
{"Safety colors:",1,&(selected_config.Safety_colors),0,1,0,Lookup_YesNo},
{"Grid XOR color:",1,&(selected_config.Grid_XOR_color),0,255,3,NULL},
{"Sync views:",1,&(selected_config.Sync_views),0,1,0,Lookup_YesNo},
{"Multi shortcuts",1,&(selected_config.Allow_multi_shortcuts),0,1,0,Lookup_YesNo},
{"",0,NULL,0,0,0,NULL},
{"",0,NULL,0,0,0,NULL},
{" --- Input ---",0,NULL,0,0,0,NULL},
@ -966,7 +966,7 @@ void Button_Settings(void)
{"Auto discontinuous:",1,&(selected_config.Auto_discontinuous),0,1,0,Lookup_YesNo},
{"Auto count colors:",1,&(selected_config.Auto_nb_used),0,1,0,Lookup_YesNo},
{"Right click colorpick:",1,&(selected_config.Right_click_colorpick),0,1,0,Lookup_YesNo},
{"",0,NULL,0,0,0,NULL},
{"Multi shortcuts:",1,&(selected_config.Allow_multi_shortcuts),0,1,0,Lookup_YesNo},
{"",0,NULL,0,0,0,NULL},
{" --- File selector ---",0,NULL,0,0,0,NULL},
@ -1152,6 +1152,11 @@ void Button_Settings(void)
Spare_fileselector_position=0;
Spare_fileselector_offset=0;
}
if(Config.Allow_multi_shortcuts && !selected_config.Allow_multi_shortcuts)
{
// User just disabled multi shortcuts: make them unique now.
Remove_duplicate_shortcuts();
}
// Copy all
Config=selected_config;

View File

@ -228,6 +228,32 @@ void Window_set_shortcut(int action_id)
shortcut_ptr[0]=backup_shortcut[0];
shortcut_ptr[1]=backup_shortcut[1];
case 2: // OK
// Replace twice by single
if (shortcut_ptr[0]==shortcut_ptr[1])
shortcut_ptr[1]=0;
// Remove all other shortcuts that use same keys
if (!Config.Allow_multi_shortcuts)
{
int n;
for (n=0; n<2; n++)
{
if (shortcut_ptr[n]!=0)
{
int i;
for(i=0; i<NB_SHORTCUTS; i++)
{
word * other_shortcut_ptr;
if (Ordering[i]==action_id)
continue;
other_shortcut_ptr=Shortcut(Ordering[i]);
if (other_shortcut_ptr[0]==shortcut_ptr[n])
other_shortcut_ptr[0]=0;
if (other_shortcut_ptr[1]==shortcut_ptr[n])
other_shortcut_ptr[1]=0;
}
}
}
}
default:
break;
}
@ -238,6 +264,41 @@ void Window_set_shortcut(int action_id)
Display_cursor();
}
///
/// Browse the complete list of shortcuts and ensure that a key only triggers
/// one of them.
void Remove_duplicate_shortcuts(void)
{
int action_1;
// This algorithm favors shortcuts that are first in the list.
// The idea is that we, coders, append new shortcuts at the end with default
// values; they should be discarded if user has chosen the key first.
for (action_1=0; action_1<NB_SHORTCUTS-1; action_1++)
{
int n;
word *shortcut_1 = Shortcut(Ordering[action_1]);
for (n=0; n<2; n++)
{
int action_2;
for (action_2=action_1+1; action_2<NB_SHORTCUTS; action_2++)
{
if (shortcut_1[n]!=0)
{
int i;
for(i=0; i<NB_SHORTCUTS; i++)
{
word *shortcut_2 = Shortcut(Ordering[action_2]);
if (shortcut_2[0]==shortcut_1[n])
shortcut_2[0]=0;
if (shortcut_2[1]==shortcut_1[n])
shortcut_2[1]=0;
}
}
}
}
}
}
///
/// Print a line with the 'help' (6x8) font.
short Print_help(short x_pos, short y_pos, const char *line, char line_type, short link_position, short link_size)

View File

@ -57,6 +57,10 @@ short Print_help(short x_pos, short y_pos, const char *line, char line_type, sho
// de type 0x100+BOUTON_* ou SPECIAL_*
const char * Keyboard_shortcut_value(word shortcut_number);
///
/// Browse the complete list of shortcuts and ensure that a key only triggers
/// one of them.
void Remove_duplicate_shortcuts(void);
#endif

View File

@ -2449,6 +2449,16 @@ static const T_Help_table helptable_settings_details[] =
HELP_TEXT ("Background color.")
HELP_TEXT ("This option is ignored when the Shade,")
HELP_TEXT ("Quick-shade, or Tiling mode is used.")
HELP_TEXT ("")
HELP_TEXT (" Multi shortcuts")
HELP_TEXT ("When this setting is disabled, and you")
HELP_TEXT ("create a shortcut with a key that is already")
HELP_TEXT ("associated to another shortcut, Grafx2 will")
HELP_TEXT ("unset the latter. If you enable this mode,")
HELP_TEXT ("Grafx2 will not make such check, so you can")
HELP_TEXT ("design shortcuts that trigger several")
HELP_TEXT ("actions at once.")
HELP_TEXT ("")
};
static const T_Help_table helptable_clear[] =

View File

@ -658,6 +658,11 @@ int Init_program(int argc,char * argv[])
temp=Load_INI(&Config);
if (temp)
Error(temp);
if(!Config.Allow_multi_shortcuts)
{
Remove_duplicate_shortcuts();
}
Compute_menu_offsets();