134 lines
5.7 KiB
Python
134 lines
5.7 KiB
Python
# --- FILE: gitsync_tool/logic/submodule_handler.py ---
|
|
|
|
from typing import TYPE_CHECKING, Optional, Tuple
|
|
|
|
from gitutility.async_tasks import async_workers
|
|
from gitutility.logging_setup import log_handler
|
|
from gitutility.gui.dialogs import AddSubmoduleDialog
|
|
|
|
# Forward reference for type hinting to avoid circular import
|
|
if TYPE_CHECKING:
|
|
from ..app import GitSvnSyncApp
|
|
|
|
class SubmoduleLogicHandler:
|
|
"""
|
|
Handles the application logic for submodule-related actions, acting as an
|
|
intermediary between the GUI callbacks and the asynchronous workers.
|
|
"""
|
|
|
|
def __init__(self, app: "GitSvnSyncApp"):
|
|
"""
|
|
Initializes the SubmoduleLogicHandler.
|
|
|
|
Args:
|
|
app: The main application instance.
|
|
"""
|
|
self.app = app
|
|
self.main_frame = app.main_frame
|
|
self.git_commands = app.git_commands
|
|
self.submodule_handler = app.submodule_handler # The core handler
|
|
|
|
def refresh_submodules(self):
|
|
"""Starts an async operation to refresh the list of submodules."""
|
|
func_name = "refresh_submodules"
|
|
svn_path = self.app._get_and_validate_svn_path("Refresh Submodules")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
log_handler.log_debug("Refresh Submodules skipped: Repo not ready.", func_name=func_name)
|
|
# The GUI will be cleared by the status indicator update
|
|
return
|
|
|
|
args = (self.git_commands, svn_path)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_refresh_submodules_async,
|
|
args_tuple=args,
|
|
context_dict={"context": "refresh_submodules", "status_msg": "Refreshing submodules..."},
|
|
)
|
|
|
|
def add_submodule(self):
|
|
"""Handles adding a new submodule via a dialog."""
|
|
func_name = "add_submodule"
|
|
svn_path = self.app._get_and_validate_svn_path("Add Submodule")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
self.main_frame.show_error("Action Failed", "Repository is not ready.")
|
|
return
|
|
|
|
# --- MODIFICA: Usa il nuovo dialogo personalizzato ---
|
|
dialog = AddSubmoduleDialog(self.app.master)
|
|
details = dialog.result
|
|
# ---------------------------------------------------
|
|
|
|
if not details:
|
|
self.main_frame.update_status_bar("Add submodule cancelled.")
|
|
return
|
|
|
|
submodule_url, submodule_path = details
|
|
log_handler.log_info(f"Attempting to add submodule '{submodule_url}' at path '{submodule_path}'", func_name=func_name)
|
|
|
|
args = (self.app.submodule_handler, svn_path, submodule_url, submodule_path)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_add_submodule_async,
|
|
args_tuple=args,
|
|
context_dict={"context": "add_submodule", "status_msg": f"Adding submodule '{submodule_path}'..."},
|
|
)
|
|
|
|
def sync_all_submodules(self):
|
|
"""Starts an async operation to sync all submodules."""
|
|
func_name = "sync_all_submodules"
|
|
svn_path = self.app._get_and_validate_svn_path("Sync Submodules")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
self.main_frame.show_error("Action Failed", "Repository is not ready.")
|
|
return
|
|
|
|
if not self.main_frame.ask_yes_no(
|
|
"Confirm Sync",
|
|
"This will fetch the latest changes for all submodules and commit the updates to your main repository.\n\nProceed?"
|
|
):
|
|
self.main_frame.update_status_bar("Sync cancelled.")
|
|
return
|
|
|
|
args = (self.submodule_handler, svn_path)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_sync_all_submodules_async,
|
|
args_tuple=args,
|
|
context_dict={"context": "sync_submodules", "status_msg": "Syncing all submodules..."},
|
|
)
|
|
|
|
def remove_submodule(self, submodule_path: str):
|
|
"""Handles removing a selected submodule after confirmation."""
|
|
func_name = "remove_submodule"
|
|
svn_path = self.app._get_and_validate_svn_path("Remove Submodule")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
self.main_frame.show_error("Action Failed", "Repository is not ready.")
|
|
return
|
|
|
|
if not self.main_frame.ask_yes_no(
|
|
"Confirm Removal",
|
|
f"Are you sure you want to permanently remove the submodule at '{submodule_path}'?\n\n"
|
|
"This will de-initialize the submodule, remove it from the index, and create a commit."
|
|
):
|
|
self.main_frame.update_status_bar("Removal cancelled.")
|
|
return
|
|
|
|
args = (self.submodule_handler, svn_path, submodule_path)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_remove_submodule_async,
|
|
args_tuple=args,
|
|
context_dict={"context": "remove_submodule", "status_msg": f"Removing submodule '{submodule_path}'..."},
|
|
)
|
|
|
|
def init_missing_submodules(self):
|
|
"""Starts an async operation to initialize all missing submodules."""
|
|
func_name = "init_missing_submodules"
|
|
svn_path = self.app._get_and_validate_svn_path("Initialize Submodules")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
self.main_frame.show_error("Action Failed", "Repository is not ready.")
|
|
return
|
|
|
|
args = (self.submodule_handler, svn_path)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_init_submodules_async,
|
|
args_tuple=args,
|
|
context_dict={"context": "init_submodules", "status_msg": "Initializing missing submodules..."},
|
|
)
|
|
|
|
|