Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/robotide/controller/ctrlcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,11 @@ def _get_undo_command(self):
class SortKeywords(_ReversibleCommand):
index_difference = None

def __init__(self, case_insensitive=False):
self._case_insensitive = case_insensitive

def _execute(self, context):
index_difference = context.sort_keywords()
index_difference = context.sort_keywords(case_insensitive=self._case_insensitive)
self._undo_command = RestoreKeywordOrder(index_difference)

def _get_undo_command(self):
Expand Down
15 changes: 12 additions & 3 deletions src/robotide/controller/tablecontrollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,18 @@ def _configure_controller(self, ctrl, config):
if config:
ctrl.arguments.set_value(config)

def sort(self):
"""Sorts the keywords of the controller by name"""
keywords_sorted = sorted(self._table.keywords, key=lambda userkeyword: userkeyword.name)
def sort(self, case_insensitive=False):
"""Sorts the keywords of the controller by name

Args:
case_insensitive: If True, sort without regard to case
"""
if case_insensitive:
keywords_sorted = sorted(self._table.keywords,
key=lambda userkeyword: userkeyword.name.lower())
else:
keywords_sorted = sorted(self._table.keywords,
key=lambda userkeyword: userkeyword.name)
index_difference = self._index_difference(self._table.keywords, keywords_sorted)
self._table.keywords = keywords_sorted
return index_difference
Expand Down
8 changes: 8 additions & 0 deletions src/robotide/ui/treenodehandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
LABEL_SORT_VARIABLES = 'Sort Variables'
LABEL_SORT_TESTS = 'Sort Tests'
LABEL_SORT_KEYWORDS = 'Sort Keywords'
LABEL_SORT_KEYWORDS_CI = 'Sort Keywords (Case Insensitive)'
LABEL_NEW_SCALAR = 'New Scalar\tCtrl-Shift-V'
LABEL_NEW_LIST_VARIABLE = 'New List Variable\tCtrl-Shift-L'
LABEL_NEW_DICT_VARIABLE = 'New Dictionary Variable'
Expand Down Expand Up @@ -297,6 +298,11 @@ def on_sort_keywords(self, event):
"""Sorts the keywords inside the treenode"""
self.controller.execute(ctrlcommands.SortKeywords())

def on_sort_keywords_case_insensitive(self, event):
__ = event
"""Sorts the keywords inside the treenode (case insensitive)"""
self.controller.execute(ctrlcommands.SortKeywords(case_insensitive=True))

def on_sort_variables(self, event):
__ = event
"""Sorts the variables inside the treenode"""
Expand Down Expand Up @@ -495,6 +501,7 @@ def __init__(self, *args):
'---',
_('Sort Variables'),
_('Sort Keywords'),
_('Sort Keywords (Case Insensitive)'),
'---',
_('Exclude'),
'---',
Expand All @@ -515,6 +522,7 @@ def __init__(self, *args):
'---',
LABEL_SORT_VARIABLES,
LABEL_SORT_KEYWORDS,
LABEL_SORT_KEYWORDS_CI,
'---',
LABEL_EXCLUDE,
'---',
Expand Down
Loading