summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Mozo/MenuEditor.py22
-rw-r--r--Mozo/util.py13
2 files changed, 18 insertions, 17 deletions
diff --git a/Mozo/MenuEditor.py b/Mozo/MenuEditor.py
index 623f3c0..7474dcd 100644
--- a/Mozo/MenuEditor.py
+++ b/Mozo/MenuEditor.py
@@ -47,7 +47,7 @@ class MenuEditor:
self.applications.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.applications.tree))
else:
self.applications.dom = xml.dom.minidom.parse(self.applications.path)
- self.__remove_whilespace_nodes(self.applications.dom)
+ util.removeWhitespaceNodes(self.applications.dom)
self.settings = Menu()
self.settings.tree = matemenu.lookup_tree('mate-settings.menu', matemenu.FLAGS_SHOW_EMPTY|matemenu.FLAGS_INCLUDE_EXCLUDED|matemenu.FLAGS_INCLUDE_NODISPLAY|matemenu.FLAGS_SHOW_ALL_SEPARATORS)
@@ -59,7 +59,7 @@ class MenuEditor:
self.settings.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.settings.tree))
else:
self.settings.dom = xml.dom.minidom.parse(self.settings.path)
- self.__remove_whilespace_nodes(self.settings.dom)
+ util.removeWhitespaceNodes(self.settings.dom)
self.save(True)
@@ -98,7 +98,7 @@ class MenuEditor:
menu.dom = xml.dom.minidom.parseString(util.getUserMenuXml(menu.tree))
else:
menu.dom = xml.dom.minidom.parse(menu.path)
- self.__remove_whilespace_nodes(menu.dom)
+ util.removeWhitespaceNodes(menu.dom)
#reset undo/redo, no way to recover from this
self.__undo, self.__redo = [], []
self.save()
@@ -132,7 +132,7 @@ class MenuEditor:
menu.dom = xml.dom.minidom.parseString(util.getUserMenuXml(menu.tree))
else:
menu.dom = xml.dom.minidom.parse(menu.path)
- self.__remove_whilespace_nodes(menu.dom)
+ util.removeWhitespaceNodes(menu.dom)
self.__redo.append(redo)
def redo(self):
@@ -156,7 +156,7 @@ class MenuEditor:
menu.dom = xml.dom.minidom.parseString(util.getUserMenuXml(menu.tree))
else:
menu.dom = xml.dom.minidom.parse(menu.path)
- self.__remove_whilespace_nodes(menu.dom)
+ util.removeWhitespaceNodes(menu.dom)
self.__undo.append(undo)
def getMenus(self, parent=None):
@@ -597,18 +597,6 @@ class MenuEditor:
if child.nodeName in name:
yield child
- def __remove_whilespace_nodes(self, node):
- remove_list = []
- for child in node.childNodes:
- if child.nodeType == xml.dom.minidom.Node.TEXT_NODE:
- child.data = child.data.strip()
- if not child.data.strip():
- remove_list.append(child)
- elif child.hasChildNodes():
- self.__remove_whilespace_nodes(child)
- for node in remove_list:
- node.parentNode.removeChild(node)
-
def __addXmlMove(self, element, old, new, dom):
if not self.__undoMoves(element, old, new, dom):
node = dom.createElement('Move')
diff --git a/Mozo/util.py b/Mozo/util.py
index cc7db83..2688c4b 100644
--- a/Mozo/util.py
+++ b/Mozo/util.py
@@ -17,6 +17,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
+import xml.dom.minidom
import matemenu
import gi
from collections import Sequence
@@ -171,3 +172,15 @@ def getIcon(item, for_properties=False):
if for_properties:
return pixbuf, path
return pixbuf
+
+def removeWhitespaceNodes(node):
+ remove_list = []
+ for child in node.childNodes:
+ if child.nodeType == xml.dom.minidom.Node.TEXT_NODE:
+ child.data = child.data.strip()
+ if not child.data.strip():
+ remove_list.append(child)
+ elif child.hasChildNodes():
+ removeWhitespaceNodes(child)
+ for node in remove_list:
+ node.parentNode.removeChild(node)