changeset 2480:1a04140acf60

Implement undo/redo for renaming layers, fixing #1977
author Chris Cannam
date Fri, 27 Mar 2020 10:26:59 +0000
parents acd2dcecc674
children 3876063ed705
files main/MainWindow.cpp repoint-lock.json
diffstat 2 files changed, 27 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Thu Mar 26 12:11:28 2020 +0000
+++ b/main/MainWindow.cpp	Fri Mar 27 10:26:59 2020 +0000
@@ -4362,20 +4362,32 @@
 MainWindow::renameCurrentLayer()
 {
     Pane *pane = m_paneStack->getCurrentPane();
-    if (pane) {
-        Layer *layer = pane->getSelectedLayer();
-        if (layer) {
-            bool ok = false;
-            QString newName = QInputDialog::getText
-                (this, tr("Rename Layer"),
-                 tr("New name for this layer:"),
-                 QLineEdit::Normal, layer->objectName(), &ok);
-            if (ok) {
-                layer->setPresentationName(newName);
-                setupExistingLayersMenus();
-            }
-        }
-    }
+    if (!pane) return;
+    
+    Layer *layer = pane->getSelectedLayer();
+    if (!layer) return;
+    
+    bool ok = false;
+    QString newName = QInputDialog::getText
+        (this, tr("Rename Layer"),
+         tr("New name for this layer:"),
+         QLineEdit::Normal, layer->objectName(), &ok);
+    if (!ok) return;
+            
+    bool existingNameSet = layer->isPresentationNameSet();
+    QString existingName = layer->getLayerPresentationName();
+
+    CommandHistory::getInstance()->addCommand
+        (new GenericCommand
+         (tr("Rename Layer"),
+          [=]() {
+              layer->setPresentationName(newName);
+              setupExistingLayersMenus();
+          },
+          [=]() {
+              layer->setPresentationName(existingNameSet ? existingName : "");
+              setupExistingLayersMenus();
+          }));
 }
 
 void
--- a/repoint-lock.json	Thu Mar 26 12:11:28 2020 +0000
+++ b/repoint-lock.json	Fri Mar 27 10:26:59 2020 +0000
@@ -4,7 +4,7 @@
       "pin": "74c5b0bfa108"
     },
     "svcore": {
-      "pin": "a4dce53b3353"
+      "pin": "498ed1e86f92"
     },
     "svgui": {
       "pin": "e5464dc2f6cf"