-
Notifications
You must be signed in to change notification settings - Fork 148
/
referencepanel.lua
79 lines (67 loc) · 2.69 KB
/
referencepanel.lua
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
-- Copyright 2014 Paul Kulchenko, ZeroBrane LLC; All rights reserved
local id = ID("referencepanel.referenceview")
local refpanel = "referencepanel"
local refeditor
local spec = {iscomment = {}}
return {
name = "Show Reference in a panel",
description = "Adds a panel for showing documentation based on tooltips.",
author = "Paul Kulchenko",
version = 0.2,
dependencies = "1.30",
onRegister = function(self)
local e = ide:CreateBareEditor()
refeditor = e
local w, h = 250, 250
local conf = function(pane)
pane:Dock():MinSize(w,-1):BestSize(w,-1):FloatingSize(w,h)
end
if ide:IsPanelDocked(refpanel) then
ide:AddPanelDocked(ide:GetOutputNotebook(), e, refpanel, TR("Reference"), conf)
else
ide:AddPanel(e, refpanel, TR("Reference"), conf)
end
do -- markup handling in the reference panel
-- copy some settings from the lua spec
for _, s in ipairs({'lexer', 'lexerstyleconvert'}) do
spec[s] = ide.specs.lua[s]
end
-- this allows the markup to be recognized in all token types
for i = 0, 16 do spec.iscomment[i] = true end
e:Connect(wxstc.wxEVT_STC_UPDATEUI, function(event) MarkupStyle(e,0,e:GetLineCount()) end)
end
e:SetReadOnly(true)
e:SetWrapMode(wxstc.wxSTC_WRAP_WORD)
e:SetupKeywords("lua",spec,ide:GetConfig().styles,ide:GetOutput():GetFont())
-- remove all margins
for m = 0, 4 do e:SetMarginWidth(m, 0) end
-- disable dragging to the panel
e:Connect(wxstc.wxEVT_STC_DO_DROP, function(event) event:SetDragResult(wx.wxDragNone) end)
local menu = ide:FindTopMenu("&View")
menu:InsertCheckItem(4, id, TR("Reference Window")..KSC(id))
menu:Connect(id, wx.wxEVT_COMMAND_MENU_SELECTED, function (event)
local uimgr = ide:GetUIManager()
uimgr:GetPane(refpanel):Show(not uimgr:GetPane(refpanel):IsShown())
uimgr:Update()
end)
ide:GetMainFrame():Connect(id, wx.wxEVT_UPDATE_UI, function (event)
local pane = ide:GetUIManager():GetPane(refpanel)
menu:Enable(event:GetId(), pane:IsOk()) -- disable if doesn't exist
menu:Check(event:GetId(), pane:IsOk() and pane:IsShown())
end)
end,
onUnRegister = function(self)
ide:RemoveMenuItem(id)
end,
onEditorCallTip = function(self, editor, tip, value, eval)
if not refeditor or eval then return end
-- update the reference text
refeditor:SetReadOnly(false)
refeditor:SetText(tip)
refeditor:SetReadOnly(true)
local pane = ide:GetUIManager():GetPane(refpanel)
-- if the reference tab is docked or the pane is shown,
-- then suppress the normal tooltip (`return false`)
if not pane:IsOk() or pane:IsShown() then return false end
end,
}