Skip to content

Commit 7df63f2

Browse files
Mtk112LKajan
authored andcommitted
Added wrapper function for checking, asking and committing changes.
Added wrapper function
1 parent e89ff4f commit 7df63f2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

arho_feature_template/plugin.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation
1717
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
1818
from arho_feature_template.utils.db_utils import get_existing_database_connection_names
19-
from arho_feature_template.utils.misc_utils import (
20-
check_layer_changes,
21-
commit_all_layer_changes,
22-
prompt_commit_changes,
23-
)
19+
from arho_feature_template.utils.misc_utils import handle_unsaved_changes
2420

2521
if TYPE_CHECKING:
2622
from qgis.gui import QgisInterface, QgsMapTool
@@ -187,7 +183,7 @@ def load_existing_land_use_plan(self) -> None:
187183
QMessageBox.critical(None, "Error", "No database connections found.")
188184
return
189185

190-
if check_layer_changes() and (not prompt_commit_changes() or not commit_all_layer_changes()):
186+
if not handle_unsaved_changes():
191187
return
192188

193189
dialog = LoadPlanDialog(None, connections)

arho_feature_template/utils/misc_utils.py

+15
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,18 @@ def commit_all_layer_changes() -> bool:
4040
all_committed = False
4141

4242
return all_committed
43+
44+
45+
def handle_unsaved_changes() -> bool:
46+
"""
47+
Wrapper function to check for unsaved changes, prompt user to commit, and commit changes if chosen.
48+
Returns:
49+
bool: True if changes are committed or no changes were found;
50+
False if user does not want to commit or if commit fails.
51+
"""
52+
if check_layer_changes():
53+
if not prompt_commit_changes():
54+
return False
55+
if not commit_all_layer_changes():
56+
return False
57+
return True

0 commit comments

Comments
 (0)