aboutsummaryrefslogtreecommitdiff
path: root/src/gui/presetmanager.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/presetmanager.py')
-rw-r--r--src/gui/presetmanager.py49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/gui/presetmanager.py b/src/gui/presetmanager.py
index 79ec539..dce5333 100644
--- a/src/gui/presetmanager.py
+++ b/src/gui/presetmanager.py
@@ -197,11 +197,15 @@ class PresetManager(QtWidgets.QDialog):
def openPreset(self, presetName, compPos=None):
componentList = self.parent.window.listWidget_componentList
- selectedComponents = self.core.selectedComponents
-
index = compPos if compPos is not None else componentList.currentRow()
if index == -1:
return
+ action = OpenPreset(self, presetName, index)
+ self.parent.undoStack.push(action)
+
+ def _openPreset(self, presetName, index):
+ selectedComponents = self.core.selectedComponents
+
componentName = str(selectedComponents[index]).strip()
version = selectedComponents[index].version
dirname = os.path.join(self.presetDir, componentName, str(version))
@@ -225,16 +229,10 @@ class PresetManager(QtWidgets.QDialog):
if not ch:
return
self.deletePreset(comp, vers, name)
- self.findPresets()
- self.drawPresetList()
-
- for i, comp in enumerate(self.core.selectedComponents):
- if comp.currentPreset == name:
- self.clearPreset(i)
def deletePreset(self, comp, vers, name):
- filepath = os.path.join(self.presetDir, comp, str(vers), name)
- os.remove(filepath)
+ action = DeletePreset(self, comp, vers, name)
+ self.parent.undoStack.push(action)
def warnMessage(self, window=None):
self.parent.showMessage(
@@ -271,7 +269,6 @@ class PresetManager(QtWidgets.QDialog):
return index
def openRenamePresetDialog(self):
- # TODO: maintain consistency by changing this to call createNewPreset()
presetList = self.window.listWidget_presets
index = self.getPresetRow()
if index == -1:
@@ -294,22 +291,28 @@ class PresetManager(QtWidgets.QDialog):
path = os.path.join(
self.presetDir, comp, str(vers))
newPath = os.path.join(path, newName)
- oldPath = os.path.join(path, oldName)
if self.presetExists(newPath):
return
- if os.path.exists(newPath):
- os.remove(newPath)
- os.rename(oldPath, newPath)
- self.findPresets()
- self.drawPresetList()
- for i, comp in enumerate(self.core.selectedComponents):
- if self.core.getPresetDir(comp) == path \
- and comp.currentPreset == oldName:
- self.core.openPreset(newPath, i, newName)
- self.parent.updateComponentTitle(i, False)
- self.parent.drawPreview()
+ action = RenamePreset(self, path, oldName, newName)
+ self.parent.undoStack.push(action)
break
+ def renamePreset(self, path, oldName, newName):
+ oldPath = os.path.join(path, oldName)
+ newPath = os.path.join(path, newName)
+ if os.path.exists(newPath):
+ os.remove(newPath)
+ os.rename(oldPath, newPath)
+ self.findPresets()
+ self.drawPresetList()
+ path = os.path.dirname(newPath)
+ for i, comp in enumerate(self.core.selectedComponents):
+ if self.core.getPresetDir(comp) == path \
+ and comp.currentPreset == oldName:
+ self.core.openPreset(newPath, i, newName)
+ self.parent.updateComponentTitle(i, False)
+ self.parent.drawPreview()
+
def openImportDialog(self):
filename, _ = QtWidgets.QFileDialog.getOpenFileName(
self.window, "Import Preset File",