- dialog.m_waiting_for_key = false;
-
- // 7. find the name of the accelerator
- GValue val;
- memset( &val, 0, sizeof( val ) );
- gtk_tree_model_get_value( GTK_TREE_MODEL( dialog.m_model ), &dialog.m_command_iter, 0, &val );
- const char *commandName = g_value_get_string( &val );;
- Shortcuts::iterator thisShortcutIterator = g_shortcuts.find( commandName );
- if ( thisShortcutIterator == g_shortcuts.end() ) {
- 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;
- }
-
- // 8. build an Accelerator
- Accelerator newAccel( event->keyval, (GdkModifierType) event->state );
-
- // 8. verify the key is still free, show a dialog to ask what to do if not
- class VerifyAcceleratorNotTaken : public CommandVisitor
- {
- const char *commandName;
- const Accelerator &newAccel;
- GtkWidget *widget;
- 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 ){
- }
- void visit( const char* name, Accelerator& accelerator ){
- if ( !strcmp( name, commandName ) ) {
- return;
- }
- if ( !allow ) {
- return;
- }
- if ( accelerator.key == 0 ) {
- return;
- }
- if ( accelerator == newAccel ) {
- StringOutputStream msg;
- msg << "The command " << name << " is already assigned to the key " << accelerator << ".\n\n"
- << "Do you want to unassign " << name << " first?";
- EMessageBoxReturn r = gtk_MessageBox( widget, msg.c_str(), "Key already used", eMB_YESNOCANCEL );
- if ( r == eIDYES ) {
- // clear the ACTUAL accelerator too!
- disconnect_accelerator( name );
- // delete the modifier
- accelerator = accelerator_null();
- // empty the cell of the key binds dialog
- GtkTreeIter i;
- if ( gtk_tree_model_get_iter_first( GTK_TREE_MODEL( model ), &i ) ) {
- for (;; )
- {
- GValue val;
- memset( &val, 0, sizeof( val ) );
- gtk_tree_model_get_value( GTK_TREE_MODEL( model ), &i, 0, &val );
- const char *thisName = g_value_get_string( &val );;
- if ( !strcmp( thisName, name ) ) {
- gtk_list_store_set( GTK_LIST_STORE( model ), &i, 1, "", -1 );
- }
- g_value_unset( &val );
- if ( !gtk_tree_model_iter_next( GTK_TREE_MODEL( model ), &i ) ) {
- break;
- }
- }
- }
- }
- else if ( r == eIDCANCEL ) {
- // aborted
- allow = false;
- }
- }
- }
- } verify_visitor( commandName, newAccel, widget, dialog.m_model );
- GlobalShortcuts_foreach( verify_visitor );
-
- 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 );
-
- if ( verify_visitor.allow ) {
- // clear the ACTUAL accelerator first
- disconnect_accelerator( commandName );
-
- thisShortcutIterator->second.first = newAccel;
-
- // write into the cell
- StringOutputStream modifiers;
- modifiers << newAccel;
- gtk_list_store_set( GTK_LIST_STORE( dialog.m_model ), &dialog.m_command_iter, 1, modifiers.c_str(), -1 );
-
- // set the ACTUAL accelerator too!
- connect_accelerator( commandName );
- }
-
- g_value_unset( &val );
-
- dialog.m_model = NULL;
-
- return true;
+ dialog.m_waiting_for_key = false;
+
+ // 7. find the name of the accelerator
+ GValue val;
+ memset(&val, 0, sizeof(val));
+ gtk_tree_model_get_value(dialog.m_model, &dialog.m_command_iter, 0, &val);
+ const char *commandName = g_value_get_string(&val);;
+ Shortcuts::iterator thisShortcutIterator = g_shortcuts.find(commandName);
+ if (thisShortcutIterator == g_shortcuts.end()) {
+ gtk_list_store_set(ui::ListStore::from(dialog.m_model), &dialog.m_command_iter, 2, false, -1);
+ gtk_widget_set_sensitive(dialog.m_list, true);
+ return true;
+ }
+
+ // 8. build an Accelerator
+ Accelerator newAccel(event->keyval, (GdkModifierType) event->state);
+
+ // 8. verify the key is still free, show a dialog to ask what to do if not
+ class VerifyAcceleratorNotTaken : public CommandVisitor {
+ const char *commandName;
+ const Accelerator &newAccel;
+ ui::Widget widget;
+ ui::TreeModel model;
+ public:
+ bool allow;
+
+ VerifyAcceleratorNotTaken(const char *name, const Accelerator &accelerator, ui::Widget w, ui::TreeModel m)
+ : commandName(name), newAccel(accelerator), widget(w), model(m), allow(true)
+ {
+ }
+
+ void visit(const char *name, Accelerator &accelerator)
+ {
+ if (!strcmp(name, commandName)) {
+ return;
+ }
+ if (!allow) {
+ return;
+ }
+ if (accelerator.key == 0) {
+ return;
+ }
+ if (accelerator == newAccel) {
+ StringOutputStream msg;
+ msg << "The command " << name << " is already assigned to the key " << accelerator << ".\n\n"
+ << "Do you want to unassign " << name << " first?";
+ auto r = ui::alert(widget.window(), msg.c_str(), "Key already used", ui::alert_type::YESNOCANCEL);
+ if (r == ui::alert_response::YES) {
+ // clear the ACTUAL accelerator too!
+ disconnect_accelerator(name);
+ // delete the modifier
+ accelerator = accelerator_null();
+ // empty the cell of the key binds dialog
+ GtkTreeIter i;
+ if (gtk_tree_model_get_iter_first(model, &i)) {
+ for (;;) {
+ GValue val;
+ memset(&val, 0, sizeof(val));
+ gtk_tree_model_get_value(model, &i, 0, &val);
+ const char *thisName = g_value_get_string(&val);;
+ if (!strcmp(thisName, name)) {
+ gtk_list_store_set(ui::ListStore::from(model), &i, 1, "", -1);
+ }
+ g_value_unset(&val);
+ if (!gtk_tree_model_iter_next(model, &i)) {
+ break;
+ }
+ }
+ }
+ } else if (r == ui::alert_response::CANCEL) {
+ // aborted
+ allow = false;
+ }
+ }
+ }
+ } verify_visitor(commandName, newAccel, widget, dialog.m_model);
+ GlobalShortcuts_foreach(verify_visitor);
+
+ gtk_list_store_set(ui::ListStore::from(dialog.m_model), &dialog.m_command_iter, 2, false, -1);
+ gtk_widget_set_sensitive(dialog.m_list, true);
+
+ if (verify_visitor.allow) {
+ // clear the ACTUAL accelerator first
+ disconnect_accelerator(commandName);
+
+ thisShortcutIterator->second.first = newAccel;
+
+ // write into the cell
+ StringOutputStream modifiers;
+ modifiers << newAccel;
+ gtk_list_store_set(ui::ListStore::from(dialog.m_model), &dialog.m_command_iter, 1, modifiers.c_str(), -1);
+
+ // set the ACTUAL accelerator too!
+ connect_accelerator(commandName);
+ }
+
+ g_value_unset(&val);
+
+ dialog.m_model = ui::TreeModel(ui::null);
+
+ return true;