mirror of
https://github.com/jtheoof/swappy.git
synced 2024-09-11 14:55:49 +03:00
refactor(swappy): use switch instead of if in keypress cb
This commit is contained in:
parent
af0b1a11a2
commit
f8c0e005cc
@ -185,33 +185,59 @@ static void tools_menu_button_copy_clicked_handler(GtkToggleButton *source,
|
|||||||
|
|
||||||
static void keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
static void keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||||
struct swappy_state *state) {
|
struct swappy_state *state) {
|
||||||
g_debug("keypress_handler key pressed: %d\n", event->keyval);
|
g_debug("keypress_handler key pressed: keyval: %d - state: %d\n",
|
||||||
if (event->keyval == GDK_KEY_Escape) {
|
event->keyval, event->state);
|
||||||
g_debug("keypress_handler: escape key pressed, ciao bye\n");
|
|
||||||
gtk_window_close(state->window);
|
switch (event->state) {
|
||||||
} else if (event->keyval == GDK_KEY_B || event->keyval == GDK_KEY_b) {
|
case 0:
|
||||||
switch_mode_to_brush(state);
|
switch (event->keyval) {
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->brush),
|
case GDK_KEY_Escape:
|
||||||
true);
|
g_debug("keypress_handler: escape key pressed, ciao bye\n");
|
||||||
} else if (event->keyval == GDK_KEY_T || event->keyval == GDK_KEY_t) {
|
gtk_window_close(state->window);
|
||||||
switch_mode_to_text(state);
|
break;
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->text), true);
|
case GDK_KEY_b:
|
||||||
} else if (event->keyval == GDK_KEY_R || event->keyval == GDK_KEY_r) {
|
switch_mode_to_brush(state);
|
||||||
switch_mode_to_rectangle(state);
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->brush),
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->rectangle),
|
true);
|
||||||
true);
|
break;
|
||||||
} else if (event->keyval == GDK_KEY_O || event->keyval == GDK_KEY_o) {
|
case GDK_KEY_t:
|
||||||
switch_mode_to_ellipse(state);
|
switch_mode_to_text(state);
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->ellipse),
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->text),
|
||||||
true);
|
true);
|
||||||
} else if (event->keyval == GDK_KEY_A || event->keyval == GDK_KEY_a) {
|
break;
|
||||||
switch_mode_to_arrow(state);
|
case GDK_KEY_r:
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->arrow),
|
switch_mode_to_rectangle(state);
|
||||||
true);
|
gtk_toggle_button_set_active(
|
||||||
} else if (event->keyval == GDK_KEY_c && event->state & GDK_CONTROL_MASK) {
|
GTK_TOGGLE_BUTTON(state->popover->rectangle), true);
|
||||||
clipboard_copy_drawing_area_to_selection(state);
|
break;
|
||||||
} else if (event->keyval == GDK_KEY_s && event->state & GDK_CONTROL_MASK) {
|
case GDK_KEY_o:
|
||||||
action_save_area_to_file(state);
|
switch_mode_to_ellipse(state);
|
||||||
|
gtk_toggle_button_set_active(
|
||||||
|
GTK_TOGGLE_BUTTON(state->popover->ellipse), true);
|
||||||
|
break;
|
||||||
|
case GDK_KEY_a:
|
||||||
|
switch_mode_to_arrow(state);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->arrow),
|
||||||
|
true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GDK_CONTROL_MASK:
|
||||||
|
switch (event->keyval) {
|
||||||
|
case GDK_KEY_c:
|
||||||
|
clipboard_copy_drawing_area_to_selection(state);
|
||||||
|
break;
|
||||||
|
case GDK_KEY_s:
|
||||||
|
action_save_area_to_file(state);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user