* Shortcuts edit: fix "already assigned" check

rebase shortcuts logic on 'key is lower, modifiers are allowed in struct Accelerator' idea
This commit is contained in:
Garux 2019-03-07 00:50:25 +03:00
parent a1abcd8c83
commit dabcad5088
3 changed files with 20 additions and 18 deletions

View File

@ -109,7 +109,6 @@ bool accelerator_map_erase( AcceleratorMap& acceleratorMap, Accelerator accelera
}
Accelerator accelerator_for_event_key( guint keyval, guint state ){
keyval = gdk_keyval_to_upper( keyval );
if ( keyval == GDK_ISO_Left_Tab ) {
keyval = GDK_Tab;
}
@ -342,14 +341,14 @@ AcceleratorMap g_keydown_accelerators;
AcceleratorMap g_keyup_accelerators;
bool Keys_press( PressedKeys::Keys& keys, guint keyval ){
if ( keys.insert( gdk_keyval_to_upper( keyval ) ).second ) {
if ( keys.insert( gdk_keyval_to_lower( keyval ) ).second ) {
return AcceleratorMap_activate( g_keydown_accelerators, accelerator_for_event_key( keyval, 0 ) );
}
return g_keydown_accelerators.find( accelerator_for_event_key( keyval, 0 ) ) != g_keydown_accelerators.end();
}
bool Keys_release( PressedKeys::Keys& keys, guint keyval ){
if ( keys.erase( gdk_keyval_to_upper( keyval ) ) != 0 ) {
if ( keys.erase( gdk_keyval_to_lower( keyval ) ) != 0 ) {
return AcceleratorMap_activate( g_keyup_accelerators, accelerator_for_event_key( keyval, 0 ) );
}
return g_keyup_accelerators.find( accelerator_for_event_key( keyval, 0 ) ) != g_keyup_accelerators.end();

View File

@ -34,35 +34,35 @@
struct Accelerator
{
Accelerator( guint _key )
: key( gdk_keyval_to_upper( _key ) ), modifiers( ( GdkModifierType ) 0 ){
: key( gdk_keyval_to_lower( _key ) ), modifiers( ( GdkModifierType ) 0 ){
}
Accelerator( guint _key, GdkModifierType _modifiers )
: key( gdk_keyval_to_upper( _key ) ), modifiers( ( GdkModifierType )( _modifiers & ALLOWED_MODIFIERS ) ){
: key( gdk_keyval_to_lower( _key ) ), modifiers( ( GdkModifierType )( _modifiers & ALLOWED_MODIFIERS ) ){
}
Accelerator( const Accelerator &src )
: key( gdk_keyval_to_upper( src.key ) ), modifiers( ( GdkModifierType )( src.modifiers & ALLOWED_MODIFIERS ) ){
: key( src.key ), modifiers( src.modifiers ){
}
bool operator<( const Accelerator& other ) const {
guint k1 = key;
guint k2 = other.key;
int mod1 = modifiers & ALLOWED_MODIFIERS;
int mod2 = other.modifiers & ALLOWED_MODIFIERS;
int mod1 = modifiers;
int mod2 = other.modifiers;
return k1 < k2 || ( !( k2 < k1 ) && mod1 < mod2 );
}
bool operator==( const Accelerator& other ) const {
guint k1 = key;
guint k2 = other.key;
int mod1 = modifiers & ALLOWED_MODIFIERS;
int mod2 = other.modifiers & ALLOWED_MODIFIERS;
int mod1 = modifiers;
int mod2 = other.modifiers;
return k1 == k2 && mod1 == mod2;
}
Accelerator &operator=( const Accelerator& other ){
key = other.key;
modifiers = (GdkModifierType) ( other.modifiers & ALLOWED_MODIFIERS );
modifiers = other.modifiers;
return *this;
}
guint key;
GdkModifierType modifiers;
guint key; //!this only gdk_keyval_to_lower
GdkModifierType modifiers; //!this only &= ALLOWED_MODIFIERS
};
inline Accelerator accelerator_null(){

View File

@ -293,6 +293,7 @@ gboolean accelerator_window_key_press( GtkWidget *widget, GdkEventKey *event, gp
const char *commandName = g_value_get_string( &val );;
Shortcuts::iterator thisShortcutIterator = g_shortcuts.find( commandName );
if ( thisShortcutIterator == g_shortcuts.end() ) {
globalErrorStream() << "commandName " << makeQuoted( commandName ) << " not found in g_shortcuts.\n";
gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 2, false, -1 );
gtk_widget_set_sensitive( GTK_WIDGET( dialog.m_list ), true );
return true;
@ -310,7 +311,8 @@ gboolean accelerator_window_key_press( GtkWidget *widget, GdkEventKey *event, gp
GtkTreeModel *model;
public:
bool allow;
VerifyAcceleratorNotTaken( const char *name, const Accelerator &accelerator, GtkWidget *w, GtkTreeModel *m ) : commandName( name ), newAccel( accelerator ), widget( w ), model( m ), allow( true ){
VerifyAcceleratorNotTaken( const char *name, const Accelerator &accelerator, GtkWidget *w, GtkTreeModel *m ) :
commandName( name ), newAccel( accelerator ), widget( w ), model( m ), allow( true ){
}
void visit( const char* name, Accelerator& accelerator ){
if ( !strcmp( name, commandName ) ) {
@ -570,13 +572,14 @@ void visit( const char* name, Accelerator& accelerator ){
char value[1024];
if ( read_var( m_filename, "Commands", name, value ) ) {
if ( string_empty( value ) ) {
accelerator.key = 0;
accelerator.modifiers = (GdkModifierType)0;
accelerator = accelerator_null();
return;
}
gtk_accelerator_parse( value, &accelerator.key, &accelerator.modifiers );
accelerator = accelerator; // fix modifiers
guint key;
GdkModifierType modifiers;
gtk_accelerator_parse( value, &key, &modifiers );
accelerator = Accelerator( key, modifiers );
if ( accelerator.key != 0 ) {
++m_count;