Advertisement
BugFix

Untitled

Feb 2nd, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.85 KB | None | 0 0
  1. -- TIME_STAMP   2014-02-02 18:39:30   v 0.1
  2.  
  3. --[[
  4.  
  5.            In Startup.lua
  6.            "dofile('path\\MySideBar.lua')"
  7.  
  8. ]]
  9.  
  10.  
  11.  
  12. require "gui"
  13.  
  14. FileSwitch =  EventClass:new(Common)
  15. FileOpen   =  EventClass:new(Common)
  16. FileSave   =  EventClass:new(Common)
  17.  
  18. local IsCommentOrString = function(iPos)
  19.     if ('1 2 7'):find(tostring(editor.StyleAt[iPos])) then
  20.         return true
  21.     else
  22.         return false
  23.     end
  24. end
  25.  
  26. local current_path
  27.  
  28. -- Sidebar als eigenes Window?
  29. local win = tonumber(props['sidebar.win']) == 1
  30.  
  31. local tab_index, tabLast_index = 0, 0
  32.  
  33. local panel_width = tonumber(props['sidebar.width']) or 230
  34. local win_height = tonumber(props['position.height']) or 600
  35. local sidebar_position = props['sidebar.position']=='left' and 'left' or 'right'
  36.  
  37. -- Funktionen alphabetisch oder nach Auftreten sortieren
  38. local func_sort = props['sidebar.func.sort'] == 'alpha' and 'alpha' or 'order'
  39. local func_call_height = props['sidebar.func.call.height'] or win_height/250
  40. local func_marked_height = props['sidebar.func.marked.height'] or win_height/250
  41.  
  42.  
  43. -- Tab2 erstellen
  44. local tab0 = gui.panel(panel_width)
  45.  
  46. -- Listview Funktionen >> Positionen Aufrufe (markierte Funktion)
  47. local list_func3 = gui.list(true)
  48. list_func3:add_column("Markierter Aufruf - Positionen", 600)
  49. tab0:add(list_func3, "bottom", func_marked_height)
  50. list_func3:on_double_click(function()
  51.     local sel_item = list_func3:get_selected_item()
  52.     if sel_item == -1 then return end
  53.     -- Gehe zu Position "sel_item"
  54.     end)
  55.  
  56. -- Listview Funktionen >> Aufrufe
  57. local list_func2 = gui.list(true)
  58. list_func2:add_column("#", 30)
  59. list_func2:add_column("Aufrufe", 600)
  60. list_func2:on_select(function()
  61.     local sel_item = list_func2:get_selected_item()
  62.     if sel_item == -1 then return end
  63.     -- "list_func3" leeren
  64.     -- Für Eintrag in "list_func3" Positionen eintragen
  65.     end)
  66. tab0:add(list_func2, "bottom", func_call_height)
  67.  
  68. -- Listview Funktionen >> Deklarationen
  69. local list_func = gui.list(true)
  70. list_func:add_column("Deklarationen", 600)
  71. list_func:on_double_click(function()
  72.     local sel_item = list_func:get_selected_item()
  73.     if sel_item == -1 then return end
  74.     -- "sel_item" ist Funktion
  75.     -- Gehe zu Position der Deklaration
  76.     end)
  77. tab0:client(list_func)
  78.  
  79.  
  80. -- Tab2 erstellen
  81. local tab1 = gui.panel(panel_width)
  82.  
  83. -- Textfeld
  84. local memo_path = gui.memo()
  85. tab1:add(memo_path, "top", 22)
  86.  
  87. -- Listview
  88. local list_dir = gui.list(false,false)
  89. tab1:client(list_dir)
  90.  
  91.  
  92. -- Parent Window erstellen (eigenständiges Wnd od. Panel)
  93. local win_parent
  94.  
  95. if win then
  96.     win_parent = gui.window "Side Bar"
  97.     win_parent:size(panel_width + 24, 600)
  98.     win_parent:on_close(function() props['sidebar.show']=0 end)
  99. else
  100.     win_parent = gui.panel(panel_width)
  101. --~     gui.set_panel(win_parent, sidebar_position)
  102. end
  103.  
  104. -- Tabbar erstellen und Tabs zuordnen
  105. local tabs = gui.tabbar(win_parent)
  106. tabs:add_tab("Funktionen", tab0)
  107. tabs:add_tab("Dateien", tab1)
  108. tabs:on_select(function(idx) tab_index = idx end )
  109.  
  110. win_parent:client(tab1)
  111. win_parent:client(tab0)
  112.  
  113. -------------------------------------------------------------------------------
  114. local GetFuncsFromBuffer = function(func_sort)
  115.     if props['FileExt']:upper() ~= 'AU3' then return end
  116.     local n, tfuncsDeclared, tFuncsCall, tFuncsCallOut = 0, {}, {}, {}
  117.  
  118.     -- Declarations: { [pos] = FuncName }
  119.     for iStart, sFunc in editor:GetText():gmatch('[Ff][Uu][Nn][Cc]%s+()([%w_]+)%s*%b()') do
  120.         if not IsCommentOrString(iStart) then tFuncsDeclared[iStart] = sFunc end
  121.     end
  122.  
  123.     -- Calls
  124.     for iStart, sFunc in editor:GetText():gmatch('()([%w_]+)%s*%b()') do
  125.         if (not IsCommentOrString(iStart)) and
  126.            (not tFuncsDeclared[iStart]) and
  127.            (not (props['au3.keywords.keywords']):find(sFunc:lower())) then
  128.            tFuncsCall[iStart] = sFunc
  129.            n = n +1
  130.         end
  131.     end
  132.  
  133.     -- New table for calls with content: [function name] = { count occurences, { table positions }}
  134.     if n > 0 then
  135.         for k, v in pairs(tFuncCall) do
  136.             if not tFuncsCallOut[v] then
  137.                 tFuncsCallOut[v] = {1, {k}}
  138.             else
  139.                 local count, tPos = tFuncsCallOut[v][1], tFuncsCallOut[v][2]
  140.                 count = count +1
  141.                 table.insert(tPos, k)
  142.                 tFuncsCallOut[v][1] = count
  143.                 tFuncsCallOut[v][2] = tPos
  144.             end
  145.         end
  146.     end
  147.     return tfuncsDeclared, tFuncsCallOut
  148. end
  149.  
  150.  
  151. -- T E S T -- (Skript uber Hotkey aus au3-Skript heraus aufrufen)
  152. --~ tD, tC = GetFuncsFromBuffer()
  153. -- print('DEKLARATIONEN')
  154. -- for k, v in pairs(tD) do print(k,v) end
  155. --~ tD = SortTable(tD)
  156. --~ print('DEKLARATIONEN - SORTIERT')
  157. --~ for k = 1, #tD do print(tD[k][1], tD[k][2]) end
  158. ----------------------------------------------------------------------------------------------
  159. --~     if func_sort == 'order' then
  160. --~         -- Deklarierte Funktionen nach Position sortieren:
  161. --~         local SortTable = function()
  162. --~             local tSort = {}
  163. --~             for k, v in pairs(tFuncsDeclared) do tSort[#tSort+1] = k end
  164. --~             table.sort(tSort)
  165. --~             for k = 1, #tSort do 
  166. --~                 tFDeclaredSorted[k] = {tSort[k], tFuncsDeclared[tSort[k]]}
  167. --~             end
  168. --~             --if #tFDeclaredSorted > 0 then for k = 1, #tFDeclaredSorted do print(tFDeclaredSorted[k][1], tFDeclaredSorted[k][2]) end end
  169. --~         end
  170. --~     else
  171.  
  172.         -- Aufgerufene Funktionen nach Namen sortieren
  173. --~         local tSort = {}
  174. --~         for f, t in pairs(tC) do tSort[#tSort+1] = f end
  175. --~         table.sort(tSort)
  176.  
  177. --~         print('\nAUFRUFE - SORTIERT')
  178. --~         for k = 1, #tSort do 
  179. --~             local s, t = tSort[k], tC[tSort[k]]
  180. --~             local count, tpos = t[1], t[2]
  181. --~             table.sort(tpos)
  182. --~             s = s..'['..count..']\t'
  183. --~             for _, v in pairs(tpos) do s = s..v..'\t' end
  184. --~             print(s) 
  185. --~         end
  186.  
  187.  
  188.  
  189.  
  190. ----------------------------------------------------------------------------------------------
  191.  
  192. -------------------------------------------------------------------------------
  193. -- Events
  194. local line_count
  195.  
  196. function OnSwitch()
  197. --~     line_count = editor.LineCount
  198.     if tab0:bounds() then -- visible FileMan
  199.         local path = props['FileDir']
  200.         if path == '' then return end
  201.         current_path = path:gsub('\\$','')..'\\'
  202. --~         FileMan_ListFILL()
  203.     elseif tab1:bounds() then -- visible Funk/Bmk
  204. --~         Functions_GetNames()
  205. --~         Functions_ListFILL()
  206. --~         Bookmarks_ListFILL()
  207. --~     elseif tab2:bounds() then -- visible Abbrev
  208. --~         Abbreviations_ListFILL()
  209.     end
  210.     gui.pass_focus()
  211. end
  212.  
  213. function FileSwitch:OnSwitchFile()
  214.     OnSwitch()
  215. end
  216.  
  217. function FileOpen:OnOpen()
  218.     OnSwitch()
  219. end
  220.  
  221. function FileSave:OnSave()
  222.     OnSwitch()
  223. end
  224.  
  225. tabs:on_select(function(ind)
  226.     tab_index=ind
  227.     OnSwitch()
  228. end)
  229.  
  230.  
  231. local SideBar_Show, SideBar_Hide
  232. if win then
  233.     SideBar_Show = function()
  234.             win_parent:show()
  235.             props['sidebar.show']=1
  236.             OnSwitch()
  237.     end
  238.     SideBar_Hide = function()
  239.             win_parent:hide()
  240.             props['sidebar.show']=0
  241.     end
  242. else
  243.     SideBar_Show = function()
  244.             gui.set_panel(win_parent, sidebar_position)
  245.             props['sidebar.show']=1
  246.             OnSwitch()
  247.     end
  248.     SideBar_Hide = function()
  249.             gui.set_panel()
  250.             props['sidebar.show']=0
  251.     end
  252. end
  253.  
  254. SideBar_Show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement