Numeric sort instead of string sort
Please add an option to sort numerically, where 2 comes before 10, ideally ignoring file extension (to prevent the extension from also spoiling the numeric sort).
Not sure it's a good idea to always sort this way, I will think about...
In the meantime, you can do it yourself by creating a new plugin containing something like:
import sort_tabs
from itertools import groupby
class SortTabsByNameNumericalCommand(sort_tabs.SortTabsByNameCommand):
'''Sort Tabs by file name (numerical)'''
sorting_indexes = (1, 3, 2)
def fill_list_views(self, list_views):
super(SortTabsByNameNumericalCommand, self).fill_list_views(list_views)
for item in list_views:
key = []
for digit, g in groupby(item[2], lambda x: x.isdigit()):
val = "".join(g)
if digit:
key.append(int(val))
else:
key.append(val)
item.append(key)
I did not suggest to always sort this way, but to have a preference that one could switch on or off (although I confess I most probably would have it always on).
Does the plugin in my previous comment works as you expected ?
Works like wonders. Thanks!
The code doesn't work anymore in ST3, you must use:
from SortTabs import sort_tabs
from itertools import groupby
class SortTabsByNameNumericalCommand(sort_tabs.SortTabsByNameCommand):
'''Sort Tabs by file name (numerical)'''
sorting_indexes = (1, 3, 2)
def fill_list_views(self, list_views):
super(SortTabsByNameNumericalCommand, self).fill_list_views(list_views)
for item in list_views:
key = []
for digit, g in groupby(item[2], lambda x: x.isdigit()):
val = "".join(g)
if digit:
key.append("{0:>99}".format(val))
else:
key.append(val)
item.append(key)