-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookmark.fmlua
More file actions
251 lines (193 loc) · 5.89 KB
/
Bookmark.fmlua
File metadata and controls
251 lines (193 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
;;
;; Shell Bookmark - çàêëàäêè â ïàíåëÿõ
;; (c) Max Rusov
;; (i) Kerberos464
;; http://forum.farmanager.com/viewtopic.php?f=15&t=6137
;;
;; RCtrlShift+ÁóêâûÈëèÖèôðû - Óñòàíîâèòü çàêëàäêó
;; RCtrl+ÁóêâûÈëèÖèôðû - Ïåðåéòè ê çàêëàäêå
;; Ctrl+/ - Ìåíþ çàêëàäîê
;;
;; 123
;;
const MacroLib = "84884660-5B2F-4581-9282-96E00AE109A2"
const FarHints = "CDF48DA0-0334-4169-8453-69048DD3B51C"
macro Area="Shell" Description="Shell Bookmark: Start"
Key="RCtrl:Down" EatOnRun=0
{{
_G.BookmarkName = ""
}}
macro Area="Shell" Description="Shell Bookmark: Define"
Key="/RCtrlShift\w/"
{{
_G.BookmarkMode = true;
_G.BookmarkName = _G.BookmarkName .. mf.akey(2):sub(-1)
}}
macro Area="Shell" Description="Shell Bookmark: Go to"
Key="/RCtrl\w/"
{{
_G.BookmarkMode = false;
_G.BookmarkName = _G.BookmarkName .. mf.akey(2):sub(-1)
}}
// Åñëè ïðè íàæàòà CtrlShift è ðàíüøå îòïóñêàåòñÿ Ctrl, òî ìàêðîñ íà Ctrl:Up íå âûçûâàåòñÿ
// Ýòî çàòû÷êà, äëÿ îáõîäà ýòîé ïðîáëåìû (îøèáêà â MacrLib?)
macro Area="Shell" Description="Shell Bookmark: Finish" Priority=-1
Key="Shift:Up"
{{
#include_macro_once "BookmarkFunc"
if _G.BookmarkName and _G.BookmarkMode then
Name = _G.BookmarkName
_G.BookmarkName = nil
_G.ShellBookmarkGoto(Name, true)
end
}}
macro Area="Shell" Name="GotoBookmark" Description="Shell Bookmark: Finish" Priority=-1
Key="RCtrl:Up"
{{
#include_macro_once "BookmarkFunc"
if _G.BookmarkName then
Name = _G.BookmarkName
_G.BookmarkName = nil
_G.ShellBookmarkGoto(Name, _G.BookmarkMode)
end
}}
macro Area="Shell" Description="Shell Bookmark: Menu" Key="Ctrl/"
{{
#include_macro_once "BookmarkFunc"
_G.ShellBookmarkMenu()
}}
//-----------------------------------------------------------------------------
// Ãëîáàëüíûå ôóíêöèè
macro Name="BookmarkFunc"
{{
function ExpandEnv(Str)
return (Str:gsub("%%(.-)%%", win.GetEnv))
end
function EnumSettings(keyname)
local obj = far.CreateSettings()
local key = obj:OpenSubkey(0, keyname)
local res = key and obj:Enum(key)
obj:Free()
return res
end
function _G.ShellBookmarkGoto(Name, Define)
if not Name or (Name == "") then
return
end
local Bookmark = "Folder" .. Name; -- FolderA, FolderB, FolderC,...
local Folder = ""
if Define then
local OldFolder = mf.mload("ShellBookmark", Bookmark)
if APanel.Plugin then
Folder = APanel.Prefix
if APanel.HostFile ~= nil then
Folder = Folder .. ":" .. APanel.HostFile
end
Folder = Folder .. ":" .. APanel.Path
else
Folder = APanel.Path
end
if OldFolder ~= nil then
Replace = msgbox("Bookmark " .. Name, "Already assigned to:\n" .. OldFolder .. "\n Do you want redefine it?\n", 0x40000);
if Replace ~= 1 then
return
end
end
Folder = prompt("Bookmark " .. Name, "Assign to:", 0x10, Folder, "Shell.Bokmark");
if Folder == false then
return
end
mf.msave("ShellBookmark", Bookmark, Folder)
else
Folder = mf.mload("ShellBookmark", Bookmark)
if Folder then
-- Ðàñêðûâàåì ïåðåìåííûå ñðåäû
Folder = ExpandEnv(Folder)
if (mf.substr(Folder, 1, 1) == ":") or (mf.substr(Folder, 0, 2) == "\\\\") then
Panel.SetPath(0, Folder)
else
print(Folder)
Keys("Enter")
end
Plugin.Call(#%FarHints, "Info", "")
Plugin.Call(#%FarHints, "FontSize", 14)
-- Plugin.Call(#%FarHints, "Color", 0x0000FF)
-- Plugin.Call(#%FarHints, "FontColor", 0x00FFFF)
Plugin.Call(#%FarHints, "Info", Folder)
else
if (mf.len(Name) == 1) and (Name >= "0") and (Name <= "9") then
-- Ðàçðåøèì ðàáîòó ñòàíäàðòíûõ øîðòêàòîâ
Keys("RCtrl" .. Name)
else
mf.beep(0x10);
end
end
end
end
function _G.ShellBookmarkMenu()
while true do
Folders = EnumSettings("ShellBookmark")
Lines = ""
for i = 1, Folders.Count do
Name = Folders[i].Name
if mf.index(Name, "Folder") == 0 then
Key = mf.substr(Name, 6)
Folder = mf.mload("ShellBookmark", Name)
if Folder then
Key1 = Key
if Key1:len() < 3 then
Key1 = Key1 .. mf.substr(" ", 0, 3 - Key1:len());
end
Lines = Lines .. (Key:len() == 1 and "&" or "") .. Key1 .. " - " .. Folder .. "\n";
end
end
end
Res = Menu.Show(Lines, "Bookmarks\nIns - select", 0x10 or 0x20)
if Res == "" then
return
end
if mf.index(Res, "\n") >= 0 then
Code = Menu.Show("&Edit\n&Delete\n&Cancel", "Bookmarks", 0x8);
if Code == 0 then
return
end
while (Res ~= "") do
Pos = mf.index(Res, "\n");
if Pos >= 0 then
Str = mf.substr(Res, 0, Pos);
Res = mf.substr(Res, Pos + 1);
else
Str = Res;
Res = "";
end
Key = mf.trim(mf.replace(mf.substr(Str, 0, mf.index(Str, "-")), "&", ""));
Bookmark = "Folder" .. Key;
Folder = mf.substr(Str, mf.index(Str, "-") + 2);
if Code == 1 then
Folder = prompt("Bookmark " .. Key, "Assign to:", 0x10, Folder, "Shell.Bokmark");
if Folder == false then
return
end
mf.msave("ShellBookmark", Bookmark, Folder)
end
if Code == 2 then
mf.mdelete("ShellBookmark", Bookmark)
end
end
return
end
Folder = mf.substr(Res, mf.index(Res, "-") + 2);
if Folder then
-- Goto
Folder = ExpandEnv(Folder)
if (mf.substr(Folder, 1, 1) == ":") or (mf.substr(Folder, 0, 2) == "\\\\") then
Panel.SetPath(0, Folder)
else
print(Folder)
Keys("Enter")
end
return
end
end
end
}}