1
2
3
4
5
6 import os
7
8 from libxyz.core.plugins import BasePlugin
9 from libxyz.core import UserData
10
11 from libxyz.exceptions import XYZRuntimeError
12
14 "Plugin where"
15
16 NAME = u"where"
17 AUTHOR = u"Max E. Kuznecov <syhpoon@syhpoon.name>"
18 VERSION = u"0.2"
19 BRIEF_DESCRIPTION = _(u"Save panels locations")
20 FULL_DESCRIPTION = _(u"When starting load previously saved locations")
21 NAMESPACE = u"misc"
22 MIN_XYZ_VERSION = 4
23 DOC = None
24 HOMEPAGE = "http://xyzcmd.syhpoon.name/"
25 EVENTS = None
26
37
38
39
41 """
42 Restore locations on startup.
43 File format is following:
44 /panel-1/path
45 /panel-2/path
46 <Number of tabs in panel-1>
47 <Active tab index in panel-1>
48 <Active tab selected name in panel-1>
49 panel-1 tab-1 path
50 panel-1 tab-1 selected
51 panel-1 tab-n path
52 panel-1 tab-n selected
53 <Number of tabs in panel-2>
54 <Active tab index in panel-2>
55 <Active tab selected name in panel-2>
56 panel-2 tab-1 path
57 panel-2 tab-1 selected
58 panel-2 tab-n path
59 panel-2 tab-n selected
60 """
61
62 chdir = self.xyz.pm.from_load(":sys:panel", "chdir")
63 new_tab = self.xyz.pm.from_load(":sys:panel", "new_tab")
64 select = self.xyz.pm.from_load(":sys:panel", "select")
65 switch = self.xyz.pm.from_load(":sys:panel", "switch_tab")
66
67 def restore_tabs(d, num, active):
68 i = 0
69
70 while i < num:
71 tab_path = d[i].rstrip()
72 tab_selected = d[i + 1].rstrip()
73
74 chdir(tab_path, active=active)
75 select(tab_selected, active=active)
76
77 if i < num - 2:
78 new_tab(active=active)
79
80 i += 2
81
82 return i
83
84
85
86 f = None
87
88 try:
89 f = self._ud.openfile(self._wfile, "r", "data")
90 data = [x.rstrip() for x in f.readlines()]
91 act = data[0]
92 inact = data[1]
93
94 chdir(act)
95 chdir(inact, active=False)
96
97 tabsnum = int(data[2]) * 2
98 active_tab = int(data[3])
99 selected = data[4]
100
101 data = data[5:]
102
103 restored = restore_tabs(data, tabsnum, True)
104
105 tabsnum = int(data[restored]) * 2
106 iactive_tab = int(data[restored + 1])
107 iselected = data[restored + 2]
108
109 data = data[restored + 3:]
110
111 restore_tabs(data, tabsnum, False)
112
113 switch(iactive_tab, active=False)
114 switch(active_tab)
115 select(iselected, active=False)
116 select(selected)
117 except Exception:
118 pass
119
120 if f:
121 f.close()
122
123
124
169