Skip to content

Commit ce722e5

Browse files
committed
Added wrapper function for checking, asking and committing changes.
Added wrapper function
1 parent eda38d8 commit ce722e5

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

arho_feature_template/plugin.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
from arho_feature_template.qgis_plugin_tools.tools.i18n import setup_translation
1818
from arho_feature_template.qgis_plugin_tools.tools.resources import plugin_name
1919
from arho_feature_template.utils.db_utils import get_existing_database_connection_names
20-
from arho_feature_template.utils.misc_utils import (
21-
PLUGIN_PATH,
22-
check_layer_changes,
23-
commit_all_layer_changes,
24-
prompt_commit_changes,
25-
)
20+
from arho_feature_template.utils.misc_utils import PLUGIN_PATH, handle_unsaved_changes
2621

2722
if TYPE_CHECKING:
2823
from qgis.gui import QgisInterface, QgsMapTool
@@ -187,7 +182,7 @@ def load_existing_land_use_plan(self) -> None:
187182
QMessageBox.critical(None, "Error", "No database connections found.")
188183
return
189184

190-
if check_layer_changes() and (not prompt_commit_changes() or not commit_all_layer_changes()):
185+
if not handle_unsaved_changes():
191186
return
192187

193188
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)