[wiican] Extended sort changes posibilities in mapping_manager swap_mapping_order function Updated documentat
- From: J. Félix Ontañón <felixonta src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [wiican] Extended sort changes posibilities in mapping_manager swap_mapping_order function Updated documentat
- Date: Sat, 27 Nov 2010 19:02:28 +0000 (UTC)
commit 6c632cfd909105f20dd8e91a00f62ef6f6fce130
Author: J. Félix Ontañón <fontanon emergya es>
Date: Sat Nov 27 20:00:03 2010 +0100
Extended sort changes posibilities in mapping_manager swap_mapping_order function
Updated documentation of that function
doc/module_manager.rst | 9 ++++++---
wiican/mapping/manager.py | 19 ++++++++++++++-----
2 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/doc/module_manager.rst b/doc/module_manager.rst
index c03f303..d9d2623 100644
--- a/doc/module_manager.rst
+++ b/doc/module_manager.rst
@@ -113,16 +113,19 @@ Mapping options in a collection
.. method:: MappingManager.swap_mapping_order(mapping_id1, mapping_id2)
- Swap the order in the mapping collection between two mappings
+ Swaps mapping_id2 before mapping_id1
:param mapping_id1: The :class:`MappingManager` key that refers a
- :class:`Mapping` object to swap order.
+ :class:`Mapping` object to revolve around.
:type mapping_id1: string
:param mapping_id2: The other :class:`MappingManager` key that refers a
- :class:`Mapping` object to swap order.
+ :class:`Mapping` object to be swapped.
:type mapping_id2: string
+ :param after: default False, if true: it swaps mapping_id2 after mapping_id1
+ :type after: bool
+
:raises: :exc:`MappingManagerError` if no mapping found by the given
mapping_id
diff --git a/wiican/mapping/manager.py b/wiican/mapping/manager.py
index 859b7de..a93f585 100644
--- a/wiican/mapping/manager.py
+++ b/wiican/mapping/manager.py
@@ -164,8 +164,8 @@ class MappingManager(Singleton, GConfStore):
mapping.write()
return False
- def swap_mapping_order(self, mapping_id1, mapping_id2):
- """Swap the order in the mapping list between two mappings"""
+ def swap_mapping_order(self, mapping_id1, mapping_id2, after=False):
+ """Swaps mapping_id2 before mapping_id1"""
if not mapping_id1 in self.__mapping_bag:
raise MappingManagerError, _('Mapping not found:') + ' ' + mapping_id1
@@ -173,9 +173,18 @@ class MappingManager(Singleton, GConfStore):
if not mapping_id2 in self.__mapping_bag:
raise MappingManagerError, _('Mapping not found:') + ' ' + mapping_id2
- index = self.options['mapping_sort'].index(mapping_id1)
- self.options['mapping_sort'].remove(mapping_id2)
- self.options['mapping_sort'].insert(index, mapping_id2)
+ if mapping_id1 == mapping_id2: return
+
+ sort_list = copy.copy(self.options['mapping_sort'])
+ sort_list.remove(mapping_id2)
+ index = sort_list.index(mapping_id1)
+
+ if after:
+ sort_list = sort_list[0:index+1] + [mapping_id2] + sort_list[index+1:]
+ else:
+ sort_list.insert(index, mapping_id2)
+
+ self.options['mapping_sort'] = sort_list
def is_system_mapping(self, mapping_id):
"""Check if the mapping (identified by mapping_id) it's a system mapping"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]