Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 131 lines (99 sloc) 3.975 kb
b930f4c New fork initial commit
iamjessu authored
1 """
9e5c4da @JesusLeon A small cleanup and version fixes
authored
2 SplitScreen-Resizer v3.0.0
b930f4c New fork initial commit
iamjessu authored
3 by Jesus Leon
9d3992f Ratio is set in key bindings file.
iamjessu authored
4 https://github.com/iamjessu/sublime-SplitScreen-Resizer
b930f4c New fork initial commit
iamjessu authored
5
9e5c4da @JesusLeon A small cleanup and version fixes
authored
6
7 Contributors, THANKS!:
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
8 Artis Raugulis <artis@devart.lv>
9
9e5c4da @JesusLeon A small cleanup and version fixes
authored
10
b930f4c New fork initial commit
iamjessu authored
11 A fork of:
12
041a3d0 @JesusLeon v2.0.0 - Added autofocus capability
authored
13 SplitScreen v1.0.0
14 by Nick Fisher
15 https://github.com/spadgos/sublime-SplitScreen
16
9e5c4da @JesusLeon A small cleanup and version fixes
authored
17 Combined with:
041a3d0 @JesusLeon v2.0.0 - Added autofocus capability
authored
18
19 Split Navigation
20 by Linus Oleander
21 https://github.com/oleander/sublime-split-navigation
b930f4c New fork initial commit
iamjessu authored
22 """
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
23 import sublime, sublime_plugin
b930f4c New fork initial commit
iamjessu authored
24 import re
25
26
27 def addUp(lst):
28 out = [0.0]
29 for i in lst:
30 out.append(out[-1] + i)
31
32 return out
33
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
34 class PanelChangedCommand(sublime_plugin.EventListener):
35 last_work_group = None
36 settings = None
37 def on_activated(self, view):
9e5c4da @JesusLeon A small cleanup and version fixes
authored
38 # Load settings.
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
39 if self.settings == None:
40 self.settings = sublime.load_settings("splitscreen-resizer.sublime-settings")
41
9e5c4da @JesusLeon A small cleanup and version fixes
authored
42 # If mouse focus disabled. Exit.
43 if self.settings.get('resize_on_focus') == False:
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
44 return 0
45
7d01278 @ArtisR fixed issue when secondary window with one group spawned another group
ArtisR authored
46 # If theres only one group in current window. Do nothing.
47 if view.window().num_groups() == 1:
48 return 0
49
9e5c4da @JesusLeon A small cleanup and version fixes
authored
50 # Current active group.
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
51 current_active_group = view.window().active_group()
52
9e5c4da @JesusLeon A small cleanup and version fixes
authored
53 # Working group not changed. Do nothing.
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
54 if self.last_work_group == current_active_group:
55 return 0
56
9e5c4da @JesusLeon A small cleanup and version fixes
authored
57 # Update last work group.
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
58 self.last_work_group = current_active_group
59
9e5c4da @JesusLeon A small cleanup and version fixes
authored
60 # By default we show left side.
61 # Note the extra parameter ignore_focus_on_resize.
62 # It prevents an infinite loop. A short circuit! :O
63 args = {"side":"left", "ignore_focus_on_resize":True}
64
65 # If right side active, update args to right side version.
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
66 if(current_active_group == 1):
9e5c4da @JesusLeon A small cleanup and version fixes
authored
67 args = {"side":"right", "ignore_focus_on_resize":True}
d375304 @ArtisR added mousefoucus code and contributors notice
ArtisR authored
68
69 win = view.window()
70 win.run_command("split_screen_resizer", args)
71
b930f4c New fork initial commit
iamjessu authored
72
73 class SplitScreenResizerCommand(sublime_plugin.WindowCommand):
9e5c4da @JesusLeon A small cleanup and version fixes
authored
74 settings = None
75 def run(self, side, ignore_focus_on_resize=False):
76 # Load settings
77 if self.settings == None:
78 self.settings = sublime.load_settings("splitscreen-resizer.sublime-settings")
041a3d0 @JesusLeon v2.0.0 - Added autofocus capability
authored
79 win = self.window
80 num = win.num_groups()
81 act = win.active_group()
b930f4c New fork initial commit
iamjessu authored
82
c158720 @ArtisR fixed group spawning by keyboard, when only one group present
ArtisR authored
83 #If theres only one group in current window. Do nothing.
84 if num == 1:
85 return 0
86
b930f4c New fork initial commit
iamjessu authored
87 if side == "left":
9e5c4da @JesusLeon A small cleanup and version fixes
authored
88 ratio = self.settings.get('ratio_left')
041a3d0 @JesusLeon v2.0.0 - Added autofocus capability
authored
89 act = act - 1
9d3992f Ratio is set in key bindings file.
iamjessu authored
90
91 if side == "right":
9e5c4da @JesusLeon A small cleanup and version fixes
authored
92 ratio = self.settings.get('ratio_right')
041a3d0 @JesusLeon v2.0.0 - Added autofocus capability
authored
93 act = act + 1
94
95 # By keeping it as modulus operation we ensure that:
96 # - It continues focusing the next/previous column in case we're
97 # working with more than 2 columns.
98 # - It acts as a loop, focusing the first/last column when the
99 # last/first is reached respectively.
9e5c4da @JesusLeon A small cleanup and version fixes
authored
100 if self.settings.get('focus_on_resize') and ignore_focus_on_resize == False:
041a3d0 @JesusLeon v2.0.0 - Added autofocus capability
authored
101 win.focus_group(act % num)
b930f4c New fork initial commit
iamjessu authored
102
103
104 """
105 Keep original code in case we want to add vertical resizing.
106 """
107 parts = re.split("\\s*,\\s*", ratio)
108
109 horiz = parts[0] or "1"
110 vert = parts[1] or "1" if len(parts) > 1 else "1"
111
112 vert = map(float, re.split(":", vert))
113 horiz = map(float, re.split(":", horiz))
114 vertTotal = sum(vert)
115 horizTotal = sum(horiz)
116 vert = map((lambda x: x / vertTotal), vert)
117 horiz = map((lambda x: x / horizTotal), horiz)
118
119 cols = addUp(horiz)
120 rows = addUp(vert)
121
122 cells = []
123 for x, val1 in enumerate(horiz):
124 for y, val2 in enumerate(vert):
125 cells.append([x, y, x + 1, y + 1])
126
127 self.window.run_command('set_layout', {
128 "cols": cols,
129 "rows": rows,
130 "cells": cells
041a3d0 @JesusLeon v2.0.0 - Added autofocus capability
authored
131 })
Something went wrong with that request. Please try again.