Skip to content

Commit 580c2c2

Browse files
Change debugging
1 parent 2f8ab43 commit 580c2c2

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

filemanager.lua

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ treeView = nil
44
cwd = WorkingDirectory()
55
driveLetter = "C:\\"
66
isWin = (OS == "windows")
7-
debug = false
7+
8+
-- Uncomment to enable debugging
9+
function debug(log)
10+
-- messenger:AddLog(log)
11+
end
812

913
-- ToggleTree will toggle the tree view visible (create) and hide (delete).
1014
function ToggleTree()
11-
if debug == true then messenger:AddLog("***** ToggleTree() *****") end
15+
debug("***** ToggleTree() *****")
1216
if treeView == nil then
1317
OpenTree()
1418
else
@@ -18,15 +22,15 @@ end
1822

1923
-- OpenTree setup's the view
2024
function OpenTree()
21-
if debug == true then messenger:AddLog("***** OpenTree() *****") end
25+
debug("***** OpenTree() *****")
2226
CurView():VSplitIndex(NewBuffer("", "FileManager"), 0)
2327
setupOptions()
2428
refreshTree()
2529
end
2630

2731
-- setupOptions setup tree view options
2832
function setupOptions()
29-
if debug == true then messenger:AddLog("***** setupOptions() *****") end
33+
debug("***** setupOptions() *****")
3034
treeView = CurView()
3135
treeView.Width = 30
3236
treeView.LockWidth = true
@@ -45,7 +49,7 @@ end
4549

4650
-- CloseTree will close the tree plugin view and release memory.
4751
function CloseTree()
48-
if debug == true then messenger:AddLog("***** CloseTree() *****") end
52+
debug("***** CloseTree() *****")
4953
if treeView ~= nil then
5054
treeView.Buf.IsModified = false
5155
treeView:Quit(false)
@@ -55,24 +59,22 @@ end
5559

5660
-- refreshTree will remove the buffer and load contents from folder
5761
function refreshTree()
58-
if debug == true then messenger:AddLog("***** refreshTree() *****") end
59-
-- if debug == true then messenger:AddLog("Start -> ",treeView.Buf:Start()," End -> ",treeView.Buf:End()) end
62+
debug("***** refreshTree() *****")
6063
treeView.Buf:remove(treeView.Buf:Start(), treeView.Buf:End())
6164
local list = table.concat(scanDir(cwd), "\n ")
62-
if debug == true then messenger:AddLog("dir -> ",list) end
6365
treeView.Buf:Insert(Loc(0,0),list)
6466
end
6567

6668
-- returns currently selected line in treeView
6769
function getSelection()
68-
if debug == true then messenger:AddLog("***** getSelection() ---> ",treeView.Buf:Line(treeView.Cursor.Loc.Y):sub(2)) end
70+
debug("***** getSelection() ---> ",treeView.Buf:Line(treeView.Cursor.Loc.Y):sub(2))
6971
return (treeView.Buf:Line(treeView.Cursor.Loc.Y)):sub(2)
7072
end
7173

7274
-- don't use built-in view.Cursor:SelectLine() as it will copy to clipboard (in old versions of Micro)
7375
function selectLineInTree(view)
7476
if view == treeView then
75-
if debug == true then messenger:AddLog("***** selectLineInTree(view) *****") end
77+
debug("***** selectLineInTree() *****")
7678
local y = view.Cursor.Loc.Y
7779
view.Cursor.CurSelection[1] = Loc(0, y)
7880
view.Cursor.CurSelection[2] = Loc(view.Width, y)
@@ -87,15 +89,15 @@ function onCursorUp(view) selectLineInTree(view) end
8789
function onMousePress(view, event)
8890
if view == treeView then -- check view is tree as only want inputs from that view.
8991
local columns, rows = event:Position()
90-
if debug == true then messenger:AddLog("INFO: --> Mouse pressed -> columns location rows location -> ",columns,rows) end
92+
debug("INFO: --> Mouse pressed -> columns location rows location -> ",columns,rows)
9193
return false
9294
end
9395
end
9496

9597
-- disallow selecting topmost line in treeView:
9698
function preCursorUp(view)
9799
if view == treeView then
98-
if debug == true then messenger:AddLog("***** preCursor(view) *****") end
100+
debug("***** preCursor(view) *****")
99101
if view.Cursor.Loc.Y == 1 then
100102
return false
101103
end end end
@@ -133,14 +135,12 @@ end
133135
-- If it is a file then open it in a new vertical view
134136
function preInsertNewline(view)
135137
if view == treeView then
136-
if debug == true then messenger:AddLog("***** preInsertNewLine(view) *****") end
138+
debug("***** preInsertNewLine() *****")
137139
local selected = getSelection()
138140
if view.Cursor.Loc.Y == 0 then
139141
return false -- topmost line is cwd, so disallowing selecting it
140142
elseif isDir(selected) then -- if directory then reload contents of tree view
141-
if debug == true then messenger:AddLog("current working directory -> ",cwd) end
142143
cwd = JoinPaths(cwd, selected)
143-
if debug == true then messenger:AddLog("current working directory with selected directory -> ",cwd) end
144144
refreshTree()
145145
else -- open file in new vertical view
146146
local filename = JoinPaths(cwd, selected)
@@ -157,15 +157,15 @@ end
157157
-- don't prompt to save tree view
158158
function preQuit(view)
159159
if view == treeView then
160-
if debug == true then messenger:AddLog("***** preQuit(view) *****") end
160+
debug("***** preQuit() *****")
161161
view.Buf.IsModified = false
162162
end
163163
end
164164
function preQuitAll(view) treeView.Buf.IsModified = false end
165165

166166
-- scanDir will scan contents of the directory passed.
167167
function scanDir(directory)
168-
if debug == true then messenger:AddLog("***** scanDir(directory) ---> ",directory) end
168+
debug("***** scanDir(directory) ---> ",directory)
169169
local i, list, proc = 3, {}, nil
170170
list[1] = (isWin and driveLetter or "") .. cwd -- current directory working.
171171
list[2] = ".." -- used for going up a level in directory.
@@ -186,7 +186,7 @@ end
186186
-- isDir checks if the path passed is a directory.
187187
-- return true if it is a directory else false if it is not a directory.
188188
function isDir(path)
189-
if debug == true then messenger:AddLog("***** isDir(path) ---> ",path) end
189+
debug("***** isDir(path) ---> ",path)
190190
local dir, proc = false, nil
191191
if isWin then
192192
proc = io.popen('IF EXIST ' .. driveLetter .. JoinPaths(cwd, path) .. '/* (ECHO d) ELSE (ECHO -)')
@@ -197,7 +197,7 @@ function isDir(path)
197197
dir = true
198198
end
199199
proc:close()
200-
if debug == true then messenger:AddLog("is Dir Return = ",dir) end
200+
debug("***** isDir return ",dir)
201201
return dir
202202
end
203203

0 commit comments

Comments
 (0)