Browse Source

simplify check for unsaved changes

Check if last performed action does not match the last action when the
project was saved or loaded.
audio_region_bpm_change_fix
parent
commit
4b76bd69b4
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 20
      inc/actions/undo_manager.h
  2. 24
      inc/project.h
  3. 104
      src/gui/widgets/main_window.c
  4. 10
      src/project.c

20
inc/actions/undo_manager.h

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2019-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/**
* \file

24
inc/project.h

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2018-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2018-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/**
* \file
@ -304,6 +288,10 @@ typedef struct Project @@ -304,6 +288,10 @@ typedef struct Project
/** Semaphore used to block saving. */
ZixSem save_sem;
/** Used to check if the project has unsaved
* changes. */
UndoableAction * last_saved_action;
gint64 last_autosave_time;
} Project;

104
src/gui/widgets/main_window.c

@ -122,89 +122,19 @@ on_close_request ( @@ -122,89 +122,19 @@ on_close_request (
"%s: main window delete event called",
__func__);
/* temporarily pause engine */
EngineState state;
engine_wait_for_pause (
AUDIO_ENGINE, &state, Z_F_NO_FORCE);
/* get yaml for live project */
char * live_yaml =
yaml_serialize (PROJECT, &project_schema);
if (!live_yaml)
{
ui_show_error_message (
self, false,
_ ("Failed to serialize current project"));
/* restart engine */
engine_resume (AUDIO_ENGINE, &state);
/* return true to stop other handlers from
* running */
return true;
}
/* get yaml for existing project file */
char * file_yaml = project_get_existing_yaml (
PROJECT, F_NOT_BACKUP);
/* check if we have unsaved changes - simply
* check if the last performed action matches
* the last action when the project was last
* saved/loaded */
UndoableAction * last_performed_action =
undo_manager_get_last_action (UNDO_MANAGER);
/* ask for save if project has unsaved changes */
bool ret = false;
if (!string_is_equal (file_yaml, live_yaml))
if (
last_performed_action
!= PROJECT->last_saved_action)
{
bool show_diff = false;
char * diff = NULL;
/* no need, usually diff is too large so this
* is a waste of time */
#if 0
# ifndef _WOE32
/* get diff using `diff` */
const size_t max_diff_len = 400;
GError * err = NULL;
char * tmp_dir =
g_dir_make_tmp ("zrythm-diff-XXXXXX", &err);
g_return_val_if_fail (err == NULL, false);
char * tmp_live_fp =
g_build_filename (
tmp_dir, "live.yaml", NULL);
char * tmp_file_fp =
g_build_filename (
tmp_dir, "file.yaml", NULL);
err = NULL;
g_file_set_contents (
tmp_live_fp, live_yaml, -1, &err);
g_return_val_if_fail (err == NULL, false);
err = NULL;
g_file_set_contents (
tmp_file_fp, file_yaml, -1, &err);
g_return_val_if_fail (err == NULL, false);
char * diff_bin =
g_find_program_in_path ("diff");
diff = NULL;
if (diff_bin)
{
const char * argv[] = {
diff_bin, tmp_live_fp, tmp_file_fp, NULL };
diff =
system_get_cmd_output (
(char **) argv, -1, false);
g_debug ("diff: %s", diff);
g_free (diff_bin);
}
show_diff =
diff && strlen (diff) < max_diff_len;
io_remove (tmp_live_fp);
io_remove (tmp_file_fp);
io_rmdir (tmp_dir, F_NO_FORCE);
g_free (tmp_dir);
g_free (tmp_live_fp);
g_free (tmp_file_fp);
# endif
#endif
GtkWidget * dialog = gtk_dialog_new_with_buttons (
_ ("Unsaved changes"),
GTK_WINDOW (MAIN_WINDOW),
@ -220,12 +150,8 @@ on_close_request ( @@ -220,12 +150,8 @@ on_close_request (
"The project contains unsaved changes.\n"
"If you quit without saving, unsaved "
"changes will be lost.");
char label_str[4000];
sprintf (
label_str,
show_diff ? _ ("%s\n\nChanges:\n%s") : "%s%s",
label_question, show_diff ? diff : "");
GtkWidget * label = gtk_label_new (label_str);
GtkWidget * label =
gtk_label_new (label_question);
gtk_widget_set_margin_top (label, 4);
gtk_widget_set_margin_bottom (label, 4);
gtk_widget_set_visible (label, true);
@ -259,15 +185,7 @@ on_close_request ( @@ -259,15 +185,7 @@ on_close_request (
break;
}
if (diff)
g_free (diff);
} /* endif project has unsaved changes */
g_free (live_yaml);
free (file_yaml);
/* restart engine */
engine_resume (AUDIO_ENGINE, &state);
g_debug (
"%s: main window delete event returning %d",

10
src/project.c

@ -1255,6 +1255,9 @@ project_load ( @@ -1255,6 +1255,9 @@ project_load (
PROJECT, PROJECT->dir, 0, 0, F_NO_ASYNC);
}
PROJECT->last_saved_action =
undo_manager_get_last_action (UNDO_MANAGER);
engine_activate (AUDIO_ENGINE, true);
/* pause engine */
@ -1993,6 +1996,13 @@ project_save ( @@ -1993,6 +1996,13 @@ project_save (
if (ZRYTHM_TESTING)
tracklist_validate (self->tracklist);
if (!is_backup)
{
self->last_saved_action =
undo_manager_get_last_action (
self->undo_manager);
}
if (engine_paused)
{
engine_resume (AUDIO_ENGINE, &state);

Loading…
Cancel
Save