Skip to content

Commit

Permalink
fix(ui): commit state before copying or saving
Browse files Browse the repository at this point in the history
Closes #52
  • Loading branch information
jtheoof committed Feb 16, 2021
1 parent 3db1b13 commit 46e5854
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ static void screen_coordinates_to_image_coordinates(struct swappy_state *state,
*image_y = y;
}

static void commit_state(struct swappy_state *state) {
paint_commit_temporary(state);
paint_free_list(&state->redo_paints);
render_state(state);
update_ui_undo_redo(state);
}

void on_destroy(GtkApplication *application, gpointer data) {
struct swappy_state *state = (struct swappy_state *)data;
maybe_save_output_file(state);
Expand Down Expand Up @@ -269,6 +276,8 @@ void application_finish(struct swappy_state *state) {
}

void save_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
// Commit a potential paint (e.g. text being written)
commit_state(state);
save_state_to_file_or_folder(state, NULL);
}

Expand All @@ -277,6 +286,8 @@ void clear_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
}

void copy_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
// Commit a potential paint (e.g. text being written)
commit_state(state);
clipboard_copy_drawing_area_to_selection(state);
}

Expand Down Expand Up @@ -499,10 +510,7 @@ void draw_area_button_release_handler(GtkWidget *widget, GdkEventButton *event,
case SWAPPY_PAINT_MODE_RECTANGLE:
case SWAPPY_PAINT_MODE_ELLIPSE:
case SWAPPY_PAINT_MODE_ARROW:
paint_commit_temporary(state);
paint_free_list(&state->redo_paints);
render_state(state);
update_ui_undo_redo(state);
commit_state(state);
break;
case SWAPPY_PAINT_MODE_TEXT:
if (state->temp_paint && !state->temp_paint->can_draw) {
Expand Down

0 comments on commit 46e5854

Please sign in to comment.