mirror of
https://github.com/jtheoof/swappy.git
synced 2024-08-16 18:20:45 +03:00
feat(ui): add shortcuts for undo/redo
This commit is contained in:
parent
e8d2f12ce1
commit
d7e7f2b5ff
@ -7,8 +7,8 @@ int application_run(struct swappy_state *state);
|
||||
void application_finish(struct swappy_state *state);
|
||||
|
||||
/* Glade signals */
|
||||
void keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||
struct swappy_state *state);
|
||||
void window_keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||
struct swappy_state *state);
|
||||
|
||||
void undo_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void redo_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
|
@ -2,7 +2,6 @@
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkAccelGroup" id="accel-group"/>
|
||||
<object class="GtkImage" id="edit-redo">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
@ -19,10 +18,7 @@
|
||||
<property name="resizable">False</property>
|
||||
<property name="window_position">center</property>
|
||||
<property name="show_menubar">False</property>
|
||||
<accel-groups>
|
||||
<group name="accel-group"/>
|
||||
</accel-groups>
|
||||
<signal name="key-press-event" handler="keypress_handler" swapped="no"/>
|
||||
<signal name="key-press-event" handler="window_keypress_handler" swapped="no"/>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="visible">True</property>
|
||||
@ -42,7 +38,6 @@
|
||||
<property name="image">edit-undo</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="undo_clicked_handler" swapped="no"/>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
@ -61,8 +56,8 @@
|
||||
<property name="image">edit-redo</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="redo_clicked_handler" swapped="no"/>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||
<accelerator key="y" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
@ -71,9 +66,6 @@
|
||||
<property name="non_homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<style>
|
||||
<class name="right"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -27,6 +27,9 @@ static void action_undo(struct swappy_state *state) {
|
||||
if (first) {
|
||||
state->paints = g_slist_remove_link(state->paints, first);
|
||||
state->redo_paints = g_slist_prepend(state->redo_paints, first->data);
|
||||
|
||||
render_state(state);
|
||||
update_ui(state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +39,9 @@ static void action_redo(struct swappy_state *state) {
|
||||
if (first) {
|
||||
state->redo_paints = g_slist_remove_link(state->redo_paints, first);
|
||||
state->paints = g_slist_prepend(state->paints, first->data);
|
||||
|
||||
render_state(state);
|
||||
update_ui(state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,77 +156,72 @@ void copy_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
clipboard_copy_drawing_area_to_selection(state);
|
||||
}
|
||||
|
||||
void keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||
struct swappy_state *state) {
|
||||
void window_keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||
struct swappy_state *state) {
|
||||
g_debug("keypress_handler key pressed: keyval: %d - state: %d\n",
|
||||
event->keyval, event->state);
|
||||
|
||||
switch (event->state) {
|
||||
case 0:
|
||||
switch (event->keyval) {
|
||||
case GDK_KEY_Escape:
|
||||
g_debug("keypress_handler: escape key pressed, ciao bye\n");
|
||||
gtk_main_quit();
|
||||
break;
|
||||
case GDK_KEY_b:
|
||||
switch_mode_to_brush(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->brush),
|
||||
true);
|
||||
break;
|
||||
case GDK_KEY_t:
|
||||
switch_mode_to_text(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->text),
|
||||
true);
|
||||
break;
|
||||
case GDK_KEY_r:
|
||||
switch_mode_to_rectangle(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->rectangle),
|
||||
true);
|
||||
break;
|
||||
case GDK_KEY_o:
|
||||
switch_mode_to_ellipse(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->ellipse),
|
||||
true);
|
||||
break;
|
||||
case GDK_KEY_a:
|
||||
switch_mode_to_arrow(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->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;
|
||||
case GDK_KEY_b:
|
||||
action_toggle_painting_pane(state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (event->state == 0) {
|
||||
switch (event->keyval) {
|
||||
case GDK_KEY_Escape:
|
||||
g_debug("keypress_handler: escape key pressed, ciao bye\n");
|
||||
gtk_main_quit();
|
||||
break;
|
||||
case GDK_KEY_b:
|
||||
switch_mode_to_brush(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->brush), true);
|
||||
break;
|
||||
case GDK_KEY_t:
|
||||
switch_mode_to_text(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->text), true);
|
||||
break;
|
||||
case GDK_KEY_r:
|
||||
switch_mode_to_rectangle(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->rectangle),
|
||||
true);
|
||||
break;
|
||||
case GDK_KEY_o:
|
||||
switch_mode_to_ellipse(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->ellipse),
|
||||
true);
|
||||
break;
|
||||
case GDK_KEY_a:
|
||||
switch_mode_to_arrow(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->arrow), true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (event->state & 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;
|
||||
case GDK_KEY_b:
|
||||
action_toggle_painting_pane(state);
|
||||
break;
|
||||
case GDK_KEY_z:
|
||||
action_undo(state);
|
||||
break;
|
||||
case GDK_KEY_Z:
|
||||
case GDK_KEY_y:
|
||||
action_redo(state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void undo_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
action_undo(state);
|
||||
render_state(state);
|
||||
update_ui(state);
|
||||
}
|
||||
|
||||
void redo_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
action_redo(state);
|
||||
render_state(state);
|
||||
update_ui(state);
|
||||
}
|
||||
|
||||
gboolean draw_area_handler(GtkWidget *widget, cairo_t *cr,
|
||||
|
Loading…
Reference in New Issue
Block a user