diff pwfile.c @ 13:cf81eb0c2d5a

Warn before quitting if there are unsaved changes If there are unsaved changes emit a warning when the quit command is used. Only quit if the quit command is used twice with no other command in between. Add a new Quit command which immediatly quits pwm without a warning.
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Mon, 07 Aug 2017 16:59:47 +0200
parents 17fb30016e64
children efef93e54c5f
line wrap: on
line diff
--- a/pwfile.c	Thu Aug 03 10:22:07 2017 +0200
+++ b/pwfile.c	Mon Aug 07 16:59:47 2017 +0200
@@ -213,6 +213,8 @@
 
 	free(pws3_record_list);
 
+	ctx->unsaved_changes = 0;
+
 	return (0);
 }
 
@@ -448,6 +450,8 @@
 	}
 	free(tmpfilename);
 
+	ctx->unsaved_changes = !!retval;
+
 	return (retval);
 }
 
@@ -818,6 +822,8 @@
 	memcpy(entry->uuid, uuid, sizeof (entry->uuid));
 	RB_INSERT(record_id_tree, ctx->record_id_tree, entry);
 
+	ctx->unsaved_changes = 1;
+
 	return (0);
 }
 
@@ -834,6 +840,8 @@
 
 	update_record(pws3_file_get_record(ctx->file, uuid), record);
 
+	ctx->unsaved_changes = 1;
+
 	return (0);
 }
 
@@ -854,6 +862,8 @@
 	    &(struct record_id_entry){ .id = id });
 	free(RB_REMOVE(record_id_tree, ctx->record_id_tree, entry));
 
+	ctx->unsaved_changes = 1;
+
 	return (0);
 }
 
@@ -886,6 +896,8 @@
 	}
 	pws3_file_insert_empty_group(ctx->file, empty_group_field);
 
+	ctx->unsaved_changes = 1;
+
 	return (0);
 }
 
@@ -900,6 +912,8 @@
 	}
 	pws3_field_destroy(empty_group_field);
 
+	ctx->unsaved_changes = 1;
+
 	return (0);
 }