Browse Source

wxGUI/datacatalog: Do not reload the tree after canceled or failed Delete or Rename (#789)

Now reloading is made only if Delete operation on mapset and location is not cancelled and was successful.
Rename functions are fixed so reload returns on update.
Linda Kladivova 4 years ago
parent
commit
278bbfa7d1
3 changed files with 34 additions and 25 deletions
  1. 11 9
      gui/wxpython/datacatalog/tree.py
  2. 11 10
      gui/wxpython/gis_set.py
  3. 12 6
      gui/wxpython/startup/guiutils.py

+ 11 - 9
gui/wxpython/datacatalog/tree.py

@@ -945,29 +945,31 @@ class DataCatalogTree(TreeView):
         Delete selected mapset
         """
         try:
-            delete_mapset_interactively(self,
-                                        self.selected_grassdb[0].data['name'],
-                                        self.selected_location[0].data['name'],
-                                        self.selected_mapset[0].data['name'])
+            if (delete_mapset_interactively(
+                    self,
+                    self.selected_grassdb[0].data['name'],
+                    self.selected_location[0].data['name'],
+                    self.selected_mapset[0].data['name'])):
+                self.ReloadTreeItems()
         except Exception as e:
             GError(parent=self,
                    message=_("Unable to delete mapset: %s") % e,
                    showTraceback=False)
-        self.ReloadTreeItems()
 
     def OnDeleteLocation(self, event):
         """
         Delete selected location
         """
         try:
-            delete_location_interactively(self,
-                                          self.selected_grassdb[0].data['name'],
-                                          self.selected_location[0].data['name'])
+            if (delete_location_interactively(
+                    self,
+                    self.selected_grassdb[0].data['name'],
+                    self.selected_location[0].data['name'])):
+                self.ReloadTreeItems()
         except Exception as e:
             GError(parent=self,
                    message=_("Unable to delete location: %s") % e,
                    showTraceback=False)
-        self.ReloadTreeItems()
 
     def OnDisplayLayer(self, event):
         """Display layer in current graphics view"""

+ 11 - 10
gui/wxpython/gis_set.py

@@ -606,7 +606,6 @@ class GRASSStartup(wx.Frame):
                     'name': filePath},
                 parent=self)
 
-
     # the event can be refactored out by using lambda in bind
     def OnRenameMapset(self, event):
         """Rename selected mapset
@@ -649,9 +648,10 @@ class GRASSStartup(wx.Frame):
         location = self.listOfLocations[self.lblocations.GetSelection()]
         mapset = self.listOfMapsets[self.lbmapsets.GetSelection()]
         try:
-            delete_mapset_interactively(self, self.gisdbase, location, mapset)
-            self.OnSelectLocation(None)
-            self.lbmapsets.SetSelection(0)
+            if (delete_mapset_interactively(self, self.gisdbase,
+                                            location, mapset)):
+                self.OnSelectLocation(None)
+                self.lbmapsets.SetSelection(0)
         except Exception as e:
             GError(parent=self,
                    message=_("Unable to delete mapset: %s") % e,
@@ -663,11 +663,11 @@ class GRASSStartup(wx.Frame):
         """
         location = self.listOfLocations[self.lblocations.GetSelection()]
         try:
-            delete_location_interactively(self, self.gisdbase, location)
-            self.UpdateLocations(self.gisdbase)
-            self.lblocations.SetSelection(0)
-            self.OnSelectLocation(None)
-            self.lbmapsets.SetSelection(0)
+            if (delete_location_interactively(self, self.gisdbase, location)):
+                self.UpdateLocations(self.gisdbase)
+                self.lblocations.SetSelection(0)
+                self.OnSelectLocation(None)
+                self.lbmapsets.SetSelection(0)
         except Exception as e:
             GError(parent=self,
                    message=_("Unable to delete location: %s") % e,
@@ -980,7 +980,7 @@ class GListBox(ListCtrl, listmix.ListCtrlAutoWidthMixin):
         self._LoadData(choices, disabled)
 
     def SetSelection(self, item, force=False):
-        if item !=  wx.NOT_FOUND and \
+        if item != wx.NOT_FOUND and \
                 (platform.system() != 'Windows' or force):
             # Windows -> FIXME
             self.SetItemState(
@@ -1006,6 +1006,7 @@ class StartUp(wx.App):
 
         return 1
 
+
 if __name__ == "__main__":
     if os.getenv("GISBASE") is None:
         sys.exit("Failed to start GUI, GRASS GIS is not running.")

+ 12 - 6
gui/wxpython/startup/guiutils.py

@@ -215,6 +215,7 @@ def rename_mapset_interactively(guiparent, grassdb, location, mapset):
     """
     Rename selected mapset
     """
+    newmapset = None
     if mapset == "PERMANENT":
         GMessage(
             parent=guiparent,
@@ -223,7 +224,8 @@ def rename_mapset_interactively(guiparent, grassdb, location, mapset):
                 "This mapset cannot be renamed."
             ),
         )
-        return
+        return newmapset
+
     dlg = MapsetDialog(
         parent=guiparent,
         default=mapset,
@@ -238,14 +240,13 @@ def rename_mapset_interactively(guiparent, grassdb, location, mapset):
         try:
             rename_mapset(grassdb, location, mapset, newmapset)
         except OSError as err:
+            newmapset = None
             wx.MessageBox(
                 parent=guiparent,
                 caption=_("Error"),
                 message=_("Unable to rename mapset.\n\n%s") % err,
                 style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
             )
-    else:
-        newmapset = None
     dlg.Destroy()
     return newmapset
 
@@ -267,6 +268,7 @@ def rename_location_interactively(guiparent, grassdb, location):
         try:
             rename_location(grassdb, location, newlocation)
         except OSError as err:
+            newlocation = None
             wx.MessageBox(
                 parent=guiparent,
                 caption=_("Error"),
@@ -291,7 +293,7 @@ def delete_mapset_interactively(guiparent, grassdb, location, mapset):
                 "This mapset cannot be deleted."
             ),
         )
-        return
+        return False
 
     dlg = wx.MessageDialog(
         parent=guiparent,
@@ -309,6 +311,8 @@ def delete_mapset_interactively(guiparent, grassdb, location, mapset):
     if dlg.ShowModal() == wx.ID_YES:
         try:
             delete_mapset(grassdb, location, mapset)
+            dlg.Destroy()
+            return True
         except OSError as err:
             wx.MessageBox(
                 parent=guiparent,
@@ -316,8 +320,8 @@ def delete_mapset_interactively(guiparent, grassdb, location, mapset):
                 message=_("Unable to delete mapset.\n\n%s") % err,
                 style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
             )
-
     dlg.Destroy()
+    return False
 
 
 def delete_location_interactively(guiparent, grassdb, location):
@@ -340,6 +344,8 @@ def delete_location_interactively(guiparent, grassdb, location):
     if dlg.ShowModal() == wx.ID_YES:
         try:
             delete_location(grassdb, location)
+            dlg.Destroy()
+            return True
         except OSError as err:
             wx.MessageBox(
                 parent=guiparent,
@@ -347,5 +353,5 @@ def delete_location_interactively(guiparent, grassdb, location):
                 message=_("Unable to delete location.\n\n%s") % err,
                 style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
             )
-
     dlg.Destroy()
+    return False