diff --git a/src/vorta/assets/UI/scheduletab.ui b/src/vorta/assets/UI/scheduletab.ui
index b5814287..cfc52125 100644
--- a/src/vorta/assets/UI/scheduletab.ui
+++ b/src/vorta/assets/UI/scheduletab.ui
@@ -725,6 +725,20 @@
+ -
+
+
+ Open Pre-backup script editor
+
+
+ ...
+
+
+
+ :/icons/edit.svg:/icons/edit.svg
+
+
+
-
@@ -778,6 +792,20 @@
+ -
+
+
+ Open Post-backup script editor
+
+
+ ...
+
+
+
+ :/icons/edit.svg:/icons/edit.svg
+
+
+
-
diff --git a/src/vorta/assets/UI/scriptedit.ui b/src/vorta/assets/UI/scriptedit.ui
new file mode 100644
index 00000000..3b5ce992
--- /dev/null
+++ b/src/vorta/assets/UI/scriptedit.ui
@@ -0,0 +1,72 @@
+
+
+ ScriptEdit
+
+
+ Edit Script
+
+
+ true
+
+
+
+ 0
+
+
-
+
+
-
+
+
+ Save
+
+
+
+ -
+
+
+
+ Monospace
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Custom Pre/Post backup script:
+
+
+
+
+
+
+
+
+
+
diff --git a/src/vorta/views/schedule_tab.py b/src/vorta/views/schedule_tab.py
index 11cd2d4d..13191423 100644
--- a/src/vorta/views/schedule_tab.py
+++ b/src/vorta/views/schedule_tab.py
@@ -13,6 +13,7 @@ from vorta.i18n import get_locale
from vorta.scheduler import ScheduleStatusType
from vorta.store.models import BackupProfileMixin, EventLogModel, WifiSettingModel
from vorta.utils import choose_file_dialog, get_asset, get_sorted_wifis
+from vorta.views.script_edit_dialog import ScriptEditWindow
from vorta.views.utils import get_colored_icon
uifile = get_asset('UI/scheduletab.ui')
@@ -83,6 +84,8 @@ class ScheduleTab(ScheduleBase, ScheduleUI, BackupProfileMixin):
self.scheduleFixedTime.timeChanged.connect(self.on_scheduler_change)
self.chooseLocalPreBackupScriptButton.clicked.connect(lambda: self.choose_local_script(context="pre"))
self.chooseLocalPostBackupScriptButton.clicked.connect(lambda: self.choose_local_script(context="post"))
+ self.preBackupScriptEditorButton.clicked.connect(lambda: self.launch_script_editor(context="pre"))
+ self.postBackupScriptEditorButton.clicked.connect(lambda: self.launch_script_editor(context="post"))
# Network and shell commands events
self.meteredNetworksCheckBox.stateChanged.connect(
@@ -139,6 +142,8 @@ class ScheduleTab(ScheduleBase, ScheduleUI, BackupProfileMixin):
self.toolBox.setItemIcon(3, get_colored_icon('terminal'))
self.chooseLocalPreBackupScriptButton.setIcon(get_colored_icon('file'))
self.chooseLocalPostBackupScriptButton.setIcon(get_colored_icon('file'))
+ self.preBackupScriptEditorButton.setIcon(get_colored_icon('edit'))
+ self.postBackupScriptEditorButton.setIcon(get_colored_icon('edit'))
def populate_from_profile(self):
"""Populate current view with data from selected profile."""
@@ -261,3 +266,8 @@ class ScheduleTab(ScheduleBase, ScheduleUI, BackupProfileMixin):
self, self.tr('Choose Script'), want_folder=False, file_filter='*.sh', single_selection=True
)
dialog.open(receive)
+
+ def launch_script_editor(self, context: str) -> None:
+ edit_window = ScriptEditWindow(context, profile=self.profile())
+ edit_window.exec()
+ self.populate_from_profile() # Refresh the view after the script has been edited.
diff --git a/src/vorta/views/script_edit_dialog.py b/src/vorta/views/script_edit_dialog.py
new file mode 100644
index 00000000..bf437f7d
--- /dev/null
+++ b/src/vorta/views/script_edit_dialog.py
@@ -0,0 +1,49 @@
+from PyQt6 import QtCore, uic
+
+from vorta.store.models import BackupProfileMixin
+from vorta.utils import get_asset
+
+uifile = get_asset("UI/scriptedit.ui")
+ScriptEditUI, ScriptEditBase = uic.loadUiType(uifile)
+
+
+class ScriptEditWindow(ScriptEditUI, ScriptEditBase, BackupProfileMixin):
+ def __init__(self, context: str, profile, parent=None) -> None:
+ super().__init__(parent)
+ self.setupUi(self)
+ self.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose)
+
+ self.context = context
+ if context == "pre":
+ self.setWindowTitle(self.tr("Edit Pre-Backup Script"))
+ elif context == "post":
+ self.setWindowTitle(self.tr("Edit Post-Backup Script"))
+
+ self.profile = profile
+ self.saveScriptButton.clicked.connect(self.save_script)
+
+ # Populate data from profile
+ self.populate_from_profile()
+
+ def populate_from_profile(self):
+ """Populate the script editor with the current profile's script."""
+ profile = self.profile
+ if self.context == "pre":
+ self.scriptEdit.setPlainText(profile.pre_backup_cmd)
+ elif self.context == "post":
+ self.scriptEdit.setPlainText(profile.post_backup_cmd)
+
+ def save_profile_attr(self, attr, new_value):
+ profile = self.profile
+ setattr(profile, attr, new_value)
+ profile.save()
+
+ def save_script(self):
+ script = self.scriptEdit.toPlainText()
+ profile = self.profile
+ if self.context == "pre":
+ self.save_profile_attr("pre_backup_cmd", script)
+ elif self.context == "post":
+ self.save_profile_attr("post_backup_cmd", script)
+ profile.save()
+ self.close()