diff --git a/ResizeActiveGroup.py b/ResizeActiveGroup.py index 97254ad..457d9a8 100644 --- a/ResizeActiveGroup.py +++ b/ResizeActiveGroup.py @@ -1,9 +1,11 @@ import sublime_plugin +import time from copy import deepcopy class ResizeActiveGroup(sublime_plugin.EventListener): - + def __init__(self): + self.col_times = [] # based on the active group we calculate the cols/rows array def get_big(self, arr, activeGroup): return [arr[0], arr[1] if (activeGroup == 1) ^ (arr[1] > 0.5) else 1 - arr[1], arr[2]] @@ -27,10 +29,6 @@ def on_activated(self, view): else: newLayout["rows"] = self.get_big(oldLayout["rows"], activeGroup) - # 3 cells - elif len(oldLayout["cells"]) == 3: - pass - # 4 cells elif len(oldLayout["cells"]) == 4: # Grid: 4 @@ -48,5 +46,33 @@ def on_activated(self, view): newLayout["cols"] = self.get_big(oldLayout["cols"], activeGroup - 2) newLayout["rows"] = self.get_big(oldLayout["rows"], activeGroup - 2) + + # 3 cols/cells? not sure how it works + elif len(oldLayout["cells"]) == 3 and len(oldLayout["cols"]) == 4: + import sys + if sys.version_info[0] >= 3: + xrange = range + widths = [] + for i in xrange(len(oldLayout["cols"])-1): + widths += [oldLayout["cols"][i+1]-oldLayout["cols"][i]] + widths = sorted(widths) + w2 = [0 for i in xrange(len(widths))] + + + for i in xrange(len(oldLayout["cols"])-len(self.col_times)-1): + self.col_times += [0]; + + self.col_times[activeGroup] = time.time() + order = sorted(zip(xrange(len(self.col_times)),self.col_times), key=lambda value:value[1]) + order = [o[0] for o in order] + + for i in xrange(len(widths)): + w2[order[i]] = widths[i] + + left = 0 + for i in xrange(len(w2)): + left += w2[i] + newLayout["cols"][i+1] = left; + if oldLayout != newLayout: window.set_layout(newLayout)