What is the actual problem here? Is it that the order of tabs can't be set by the user and isn't restored?
If so thats the problem to fix by making the tabs draggable like the edit pane tabs and to save and restore the order on shutdown and restart. Not apply some sorting which may/may not suit any individual user.