WoWInterface SVN Notes

[/] [branches/] [WotLK/] [Notes/] [Notes.lua] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 VincentSDSH-33016
--[[
2 VincentSDSH-33016
Notes by Vincent, Silver Hand
3 VincentSDSH-33016
Original Author: Andersen, Silvermoon
4 VincentSDSH-33016
use /notes to show the GUI
5 VincentSDSH-33016
]]--
6 VincentSDSH-33016
 
7 VincentSDSH-33016
--[[
8 VincentSDSH-33016
Table of Contents:
9 VincentSDSH-33016
A) Variables
10 VincentSDSH-33016
B) Notes Selection Functions
11 VincentSDSH-33016
C) Notes Note Functions
12 VincentSDSH-33016
D) LUA Functions
13 VincentSDSH-33016
E) UI Update Functions
14 VincentSDSH-33016
F) UI Functions
15 VincentSDSH-33016
G) Sync Functions
16 VincentSDSH-33016
H) Notes Sorting Functions
17 VincentSDSH-33016
I) General Tools Functions
18 VincentSDSH-33016
J) Dropdown UI Functions
19 VincentSDSH-33016
K) Book UI Functions
20 VincentSDSH-33016
]]--
21 VincentSDSH-33016
 
22 VincentSDSH-33016
--function p(m) Notes_Print(m) end
23 VincentSDSH-33016
--function t(m) return Notes_DataToString(m) end
24 VincentSDSH-33016
 
25 VincentSDSH-33016
------------------------------------------
26 VincentSDSH-33016
-- A) Variables
27 VincentSDSH-33016
 
28 VincentSDSH-33016
Notes_Notes = {}
29 VincentSDSH-33016
Notes_Import = {}
30 VincentSDSH-33016
 
31 VincentSDSH-33016
Notes_Selected = nil
32 VincentSDSH-33016
Notes_MultiSelect = {}
33 VincentSDSH-33016
 
34 VincentSDSH-33016
local Notes_Undo = {}
35 VincentSDSH-33016
local Notes_SelectedAtLastUpdate = nil
36 VincentSDSH-33016
local Notes_MultiSelectCountAtLastUpdate = 0
37 VincentSDSH-33016
local Notes_LoadID = nil
38 VincentSDSH-33016
local Notes_BookID = nil
39 VincentSDSH-33016
local Notes_BookPages = {}
40 VincentSDSH-33016
local Notes_BookPage = 0
41 VincentSDSH-33016
local Notes_TotalPages = 0
42 VincentSDSH-33016
local Notes_TOCPageData = {};
43 VincentSDSH-33016
 
44 VincentSDSH-33016
local Notes_LastUpdateTime = nil
45 VincentSDSH-33016
local Notes_PrintMinLength=15
46 VincentSDSH-33016
local Notes_PrintMaxLength=180
47 VincentSDSH-33016
local Notes_PrintMaxChunkLength=220
48 VincentSDSH-33016
 
49 VincentSDSH-33016
local Notes_PrintMinInterval=1
50 VincentSDSH-33016
Notes_PrintMaxInterval=12
51 VincentSDSH-33016
local Notes_PrintInterval = Notes_PrintMaxInterval
52 VincentSDSH-33016
 
53 VincentSDSH-33016
 
54 VincentSDSH-33016
local Notes_PrintCache = {}
55 VincentSDSH-33016
local Notes_CacheIndex = 1
56 VincentSDSH-33016
local Notes_Listening = {}
57 VincentSDSH-33016
local Notes_ListenStack = {}
58 VincentSDSH-33016
local Notes_ListenBook = {}
59 VincentSDSH-33016
 
60 VincentSDSH-33016
local Notes_LUASetupNote = {"LUA - Start Up","--Notes LUA Setup READ ME.\n\n--[[Notes can organize and execute multiple LUA scripts.  This setup file should help a new Notes user take advantage of Notes's LUA functionality.  Keep in mind that you must press the Run LUA button on this note when you start WoW and every time you make a change if you want to use the LUA functions defined here.  Unlock this note to modify it.\n\nEntering LUA mode: type /lua or /noteslua\nRunning LUA notes in macros: In LUA mode, any selected note will display text that you can copy and paste into a macro.  This uses the RunNote() function.]]--\n\n--[[OnEvent commands: Uncomment the following function and register some events to run OnEvent commands. ]]--\n\n\n--NotesEvents:RegisterEvent('CHAT_MSG_WHISPER')\n--Notes_OnEvent = function()\n--   doEventStuff()\n--end\n\n\n--[[OnUpdate commands: Uncomment the following function and register some events to run OnEvent commands. ]]--\n\n\n--Notes_OnUpdate = function()\n--        doUpdateStuff()\n--end\n\n"}
61 VincentSDSH-33016
 
62 VincentSDSH-33016
local Notes_TitleLen = 25
63 VincentSDSH-33016
local Notes_DescrLen = 25
64 VincentSDSH-33016
local Notes_TOCTitleLen = 30
65 VincentSDSH-33016
local Notes_ColorNormal = {1,.82,0}
66 VincentSDSH-33016
local Notes_ColorSync = {.7,1,.3}
67 VincentSDSH-33016
local Notes_ColorLocked = {.52,.52,.52}
68 VincentSDSH-33016
local Notes_ColorSyncLocked = {.4,.5,.7}
69 VincentSDSH-33016
local Notes_ColorBook = {1,.5,.1}
70 VincentSDSH-33016
local Notes_ColorBookSync = {1,.1,0}
71 VincentSDSH-33016
local Notes_ColorBookLocked = {.52,.52,.52}
72 VincentSDSH-33016
local Notes_ColorBookSyncLocked = {.6,0,.4}
73 VincentSDSH-33016
 
74 VincentSDSH-33016
Notes_IconDrag = false
75 VincentSDSH-33016
Notes_IconPos = {nil,nil}
76 VincentSDSH-33016
 
77 VincentSDSH-33016
Notes_CommMode = false
78 VincentSDSH-33016
Notes_CommSpeedMode = false
79 VincentSDSH-33016
Notes_LUAMode = false
80 VincentSDSH-33016
Notes_ExportMode = false
81 VincentSDSH-33016
Notes_ShowIcon = 1
82 VincentSDSH-33016
Notes_SelectedComm = 1
83 VincentSDSH-33016
Notes_SelectedChan = 1
84 VincentSDSH-33016
 
85 VincentSDSH-33016
Notes_ChanList = {}
86 VincentSDSH-33016
local Notes_CommModes = {
87 VincentSDSH-33016
        {"Guild",       function(msg) ChatThrottleLib:SendChatMessage("NORMAL","",msg,"GUILD") end,
88 VincentSDSH-33016
                        function() return Notes_InGuild() end,
89 VincentSDSH-33016
                        "GUILD",
90 VincentSDSH-33016
                        function() return "Guild" end,
91 VincentSDSH-33016
                        function(sender) return Notes_InGuild(sender) end},
92 VincentSDSH-33016
 
93 VincentSDSH-33016
        {"Party",       function(msg) ChatThrottleLib:SendChatMessage("NORMAL","",msg,"PARTY") end,
94 VincentSDSH-33016
                        function() return (Notes_InParty() and not Notes_InRaid()) or (Notes_InRaid() and (IsRaidLeader() or IsRaidOfficer())) end,
95 VincentSDSH-33016
                        "PARTY",
96 VincentSDSH-33016
                        function() return "Party" end,
97 VincentSDSH-33016
                        function(sender) return Notes_InParty(sender) end},
98 VincentSDSH-33016
 
99 VincentSDSH-33016
        {"Raid",        function(msg) Notes_RaidPrint(msg) end,
100 VincentSDSH-33016
                        function() return Notes_InRaid() and (IsRaidLeader() or IsRaidOfficer()) end,
101 VincentSDSH-33016
                        "RAID",
102 VincentSDSH-33016
                        function() return "Raid" end,
103 VincentSDSH-33016
                        function(sender) return Notes_InRaid(sender) end},
104 VincentSDSH-33016
 
105 VincentSDSH-33016
        {"RaidWarning", function (msg) ChatThrottleLib:SendChatMessage("NORMAL","",msg,"RAID_WARNING") end,
106 VincentSDSH-33016
                        function() return Notes_InRaid() and (IsRaidLeader() or IsRaidOfficer()) end,
107 VincentSDSH-33016
                        "RAID",
108 VincentSDSH-33016
                        function() return "RaidWarning" end,
109 VincentSDSH-33016
                        function(sender) return Notes_InRaid(sender) end},
110 VincentSDSH-33016
 
111 VincentSDSH-33016
        {"Battleground",function(msg) ChatThrottleLib:SendChatMessage("NORMAL","",msg,"BATTLEGROUND") end,
112 VincentSDSH-33016
                        function() return Notes_InBattlefield() end,
113 VincentSDSH-33016
                        "RAID",
114 VincentSDSH-33016
                        function() return "Battleground" end,
115 VincentSDSH-33016
                        function(sender) return Notes_InRaid(sender) end},
116 VincentSDSH-33016
 
117 VincentSDSH-33016
        {"Say",         function(msg) ChatThrottleLib:SendChatMessage("NORMAL","",msg,"SAY") end,
118 VincentSDSH-33016
                        function() return true end,
119 VincentSDSH-33016
                        nil,
120 VincentSDSH-33016
                        function() return "Say" end,
121 VincentSDSH-33016
                        function() return nil end},
122 VincentSDSH-33016
 
123 VincentSDSH-33016
        {"Self",        function(msg) Notes_Print(msg) end,
124 VincentSDSH-33016
                        function() UnitName("target") return true end,
125 VincentSDSH-33016
                        nil,
126 VincentSDSH-33016
                        function() return "Self" end,
127 VincentSDSH-33016
                        function() return nil end},
128 VincentSDSH-33016
 
129 VincentSDSH-33016
        {"Target",      function(msg) ChatThrottleLib:SendChatMessage("NORMAL","",msg,"WHISPER",GetDefaultLanguage("player"),UnitName("target")) end,
130 VincentSDSH-33016
                        function() return UnitName("target") and UnitIsPlayer("target") end,
131 VincentSDSH-33016
                        "WHISPER",
132 VincentSDSH-33016
                        function() return UnitName("target") end,
133 VincentSDSH-33016
                        function(tar) return Notes_InGuild(sender) or Notes_InRaid(sender) end},
134 VincentSDSH-33016
 
135 VincentSDSH-33016
        {"Whisper",     function(msg,tar) ChatThrottleLib:SendChatMessage("NORMAL","",msg,"WHISPER",GetDefaultLanguage("player"),tar) end,
136 VincentSDSH-33016
                        function() local text=NotesWhisperEditBox:GetText() return text and strlen(text)>0 end,
137 VincentSDSH-33016
                        "WHISPER",
138 VincentSDSH-33016
                        function() local text=NotesWhisperEditBox:GetText() if strlen(text)>0 then return text end end,
139 VincentSDSH-33016
                        function(sender,tar) return (Notes_InGuild(sender) or Notes_InRaid(sender)) and tar==strlower(UnitName("player")) end},
140 VincentSDSH-33016
 
141 VincentSDSH-33016
        {"Channel",     function(msg,chan)
142 VincentSDSH-33016
                        if not chan then return end
143 VincentSDSH-33016
                        local index = GetChannelName(chan)
144 VincentSDSH-33016
                        if index ~= nil and index ~= 0 then
145 VincentSDSH-33016
                                ChatThrottleLib:SendChatMessage("NORMAL","",msg,"CHANNEL",GetDefaultLanguage("player"),index)
146 VincentSDSH-33016
                        end end,
147 VincentSDSH-33016
                        function() return true end,"CHANNEL",
148 VincentSDSH-33016
                        function() if Notes_ChanList[Notes_SelectedChan] then return Notes_ChanList[Notes_SelectedChan][2] end end,
149 VincentSDSH-33016
                        function(sender,chan) return (Notes_InGuild(sender) or Notes_InParty(sender) or Notes_InRaid(sender)) and Notes_InTable(Notes_ChanList,chan,3) end}
150 VincentSDSH-33016
        }
151 VincentSDSH-33016
 
152 VincentSDSH-33016
-- Binding Variables
153 VincentSDSH-33016
BINDING_HEADER_NOTESHEADER = "Notes";
154 VincentSDSH-33016
BINDING_NAME_NOTESTOGGLE = "Toggle Notes";
155 VincentSDSH-33016
BINDING_NAME_NOTESICONTOGGLE = "Toggle Notes Map Icon";
156 VincentSDSH-33016
 
157 VincentSDSH-33016
------------------------------------------
158 VincentSDSH-33016
-- B) Notes Selection Functions
159 VincentSDSH-33016
--[[
160 VincentSDSH-33016
Notes_ToggleSelected - Register that we've selected a new note
161 VincentSDSH-33016
Notes_SortAndReselect - Wrapper for Notes_SortNotes that fixes the selection after sorting
162 VincentSDSH-33016
Notes_SortNotes - Alphabetize the notes
163 VincentSDSH-33016
]]--
164 VincentSDSH-33016
function Notes_ToggleSelected(button)
165 VincentSDSH-33016
        local dirtyflag = nil
166 VincentSDSH-33016
 
167 VincentSDSH-33016
        if button ~= nil then
168 VincentSDSH-33016
                local num = button
169 VincentSDSH-33016
                if getglobal(button) then
170 VincentSDSH-33016
                        num = tonumber(strsub(button,-1))
171 VincentSDSH-33016
                end
172 VincentSDSH-33016
                local toselect = num + FauxScrollFrame_GetOffset(NotesNoteScrollBar)
173 VincentSDSH-33016
 
174 VincentSDSH-33016
                if Notes_Selected and type(Notes_Notes[Notes_Selected]["book"])~="string" and IsShiftKeyDown() then
175 VincentSDSH-33016
                        local idx = Notes_InTable(Notes_MultiSelect,toselect)
176 VincentSDSH-33016
                        if toselect == Notes_Selected and getn(Notes_MultiSelect) > 0 then
177 VincentSDSH-33016
                                Notes_Selected = Notes_MultiSelect[getn(Notes_MultiSelect)]
178 VincentSDSH-33016
                                table.remove(Notes_MultiSelect,getn(Notes_MultiSelect))
179 VincentSDSH-33016
 
180 VincentSDSH-33016
                        elseif idx then
181 VincentSDSH-33016
                                table.remove(Notes_MultiSelect,idx)
182 VincentSDSH-33016
                                dirtyflag = true
183 VincentSDSH-33016
 
184 VincentSDSH-33016
                        else
185 VincentSDSH-33016
                                local tar = num + FauxScrollFrame_GetOffset(NotesNoteScrollBar)
186 VincentSDSH-33016
                                local start,finish
187 VincentSDSH-33016
                                if Notes_Selected <= tar then
188 VincentSDSH-33016
                                        start = Notes_Selected
189 VincentSDSH-33016
                                        finish = tar-1
190 VincentSDSH-33016
                                else
191 VincentSDSH-33016
                                        start = tar+1
192 VincentSDSH-33016
                                        finish = Notes_Selected
193 VincentSDSH-33016
                                end
194 VincentSDSH-33016
 
195 VincentSDSH-33016
                                for i=start,finish do
196 VincentSDSH-33016
                                        if not Notes_InTable(Notes_MultiSelect,i) then
197 VincentSDSH-33016
                                                table.insert(Notes_MultiSelect,i)
198 VincentSDSH-33016
                                        end
199 VincentSDSH-33016
                                end
200 VincentSDSH-33016
                                Notes_Selected = num + FauxScrollFrame_GetOffset(NotesNoteScrollBar)
201 VincentSDSH-33016
                        end
202 VincentSDSH-33016
 
203 VincentSDSH-33016
                elseif Notes_Selected and type(Notes_Notes[Notes_Selected]["book"])~="string" and IsControlKeyDown() then
204 VincentSDSH-33016
                        local idx = Notes_InTable(Notes_MultiSelect,toselect)
205 VincentSDSH-33016
                        if toselect == Notes_Selected and getn(Notes_MultiSelect) > 0 then
206 VincentSDSH-33016
                                Notes_Selected = Notes_MultiSelect[getn(Notes_MultiSelect)]
207 VincentSDSH-33016
                                table.remove(Notes_MultiSelect,getn(Notes_MultiSelect))
208 VincentSDSH-33016
 
209 VincentSDSH-33016
                        elseif idx then
210 VincentSDSH-33016
                                table.remove(Notes_MultiSelect,idx)
211 VincentSDSH-33016
                                dirtyflag = true
212 VincentSDSH-33016
 
213 VincentSDSH-33016
                        else
214 VincentSDSH-33016
                                table.insert(Notes_MultiSelect,Notes_Selected)
215 VincentSDSH-33016
                                Notes_Selected = num + FauxScrollFrame_GetOffset(NotesNoteScrollBar)
216 VincentSDSH-33016
                        end
217 VincentSDSH-33016
 
218 VincentSDSH-33016
                else
219 VincentSDSH-33016
                        Notes_MultiSelect = {}
220 VincentSDSH-33016
                        Notes_Selected = toselect
221 VincentSDSH-33016
                end
222 VincentSDSH-33016
        else
223 VincentSDSH-33016
                Notes_MultiSelect = {}
224 VincentSDSH-33016
                Notes_Selected = nil
225 VincentSDSH-33016
                Notes_LoadID = nil
226 VincentSDSH-33016
                Notes_BookID = nil
227 VincentSDSH-33016
                Notes_BookPages = {}
228 VincentSDSH-33016
                Notes_BookPage = 0
229 VincentSDSH-33016
                Notes_SelectedAtLastUpdate = nil
230 VincentSDSH-33016
        end
231 VincentSDSH-33016
 
232 VincentSDSH-33016
        Notes_LoadSelected()
233 VincentSDSH-33016
        Notes_ScrollBarUpdate(dirtyflag)
234 VincentSDSH-33016
end
235 VincentSDSH-33016
 
236 VincentSDSH-33016
function Notes_SortAndReselect(mids)
237 VincentSDSH-33016
        Notes_FixHiddenPages()
238 VincentSDSH-33016
        Notes_SortNotes()
239 VincentSDSH-33016
 
240 VincentSDSH-33016
        if mids and getn(mids) > 0 then
241 VincentSDSH-33016
                Notes_MultiSelect = {}
242 VincentSDSH-33016
                for i=1,getn(mids) do
243 VincentSDSH-33016
                        midx = Notes_GetNoteIndex(mids[i])
244 VincentSDSH-33016
                        if midx then
245 VincentSDSH-33016
                                table.insert(Notes_MultiSelect,midx)
246 VincentSDSH-33016
                        end
247 VincentSDSH-33016
                end
248 VincentSDSH-33016
        end
249 VincentSDSH-33016
 
250 VincentSDSH-33016
        Notes_Selected = Notes_GetNoteIndex(Notes_LoadID)
251 VincentSDSH-33016
 
252 VincentSDSH-33016
        if Notes_Selected and Notes_BookPage == 0 then
253 VincentSDSH-33016
                local tarscroll = (tonumber(Notes_Selected)-1)*16
254 VincentSDSH-33016
                local minscroll = (0+FauxScrollFrame_GetOffset(NotesNoteScrollBar))*16
255 VincentSDSH-33016
                local maxscroll = (4+FauxScrollFrame_GetOffset(NotesNoteScrollBar))*16
256 VincentSDSH-33016
                local offset = nil
257 VincentSDSH-33016
 
258 VincentSDSH-33016
                if tarscroll < minscroll then
259 VincentSDSH-33016
                        offset = -2
260 VincentSDSH-33016
                elseif tarscroll > maxscroll then
261 VincentSDSH-33016
                        offset = -4
262 VincentSDSH-33016
                end
263 VincentSDSH-33016
 
264 VincentSDSH-33016
                if offset then
265 VincentSDSH-33016
                        NotesNoteScrollBarScrollBar:SetValue((tonumber(Notes_Selected)+offset)*16)
266 VincentSDSH-33016
                end
267 VincentSDSH-33016
        end
268 VincentSDSH-33016
end
269 VincentSDSH-33016
 
270 VincentSDSH-33016
function Notes_SortNotes()
271 VincentSDSH-33016
        table.sort(Notes_Notes,Notes_HashNatTitleSort)
272 VincentSDSH-33016
        Notes_ScrollBarUpdate()
273 VincentSDSH-33016
end
274 VincentSDSH-33016
 
275 VincentSDSH-33016
------------------------------------------
276 VincentSDSH-33016
-- C) Notes Note Functions
277 VincentSDSH-33016
--[[
278 VincentSDSH-33016
Notes_MakeNoteID - Make a new random ID
279 VincentSDSH-33016
Notes_NewNote - Create a new note
280 VincentSDSH-33016
Notes_SaveNote - Save new data entered in the UI to the table
281 VincentSDSH-33016
Notes_CopySelected - Duplicate the selected
282 VincentSDSH-33016
Notes_LoadSelected - Load the selected note into the edit buffer
283 VincentSDSH-33016
Notes_LoadEmpty - Empty the edit buffer
284 VincentSDSH-33016
Notes_DeleteSelected - wrapper for Notes_DeleteAndRebuild
285 VincentSDSH-33016
Notes_DeleteAndRebuild - Remove a note from the table
286 VincentSDSH-33016
Notes_RevertSelected - Revert changes to the selected note to the last time the UI was shown
287 VincentSDSH-33016
Notes_PrepUndo - Populate the undo table with the correct data.
288 VincentSDSH-33016
Notes_SyncSelected - Mark the selected note as sync for syncing purposes
289 VincentSDSH-33016
Notes_LockedSelected - Lock the selected note
290 VincentSDSH-33016
Notes_CompileOrExtractSelected - Master control switch for compiling/extracting from notebooks
291 VincentSDSH-33016
Notes_CompileSelected - Compile the selected notes into a book/add notes into an existing book
292 VincentSDSH-33016
Notes_ExtractSelected - Extract a page from a book and rebuild the book's index
293 VincentSDSH-33016
]]--
294 VincentSDSH-33016
 
295 VincentSDSH-33016
function Notes_MakeNoteID()
296 VincentSDSH-33016
        return time()..random(1000)
297 VincentSDSH-33016
end
298 VincentSDSH-33016
 
299 VincentSDSH-33016
function Notes_NewNote(title,text,sync,locked,id,book,bookname,overwrite,syncoverwrite)
300 VincentSDSH-33016
        if title == nil or title == "" then title = Notes_FindNextInSequence("New Note #1") end
301 VincentSDSH-33016
        if text == nil then text = "" end
302 VincentSDSH-33016
        if id == nil then id = Notes_MakeNoteID() end
303 VincentSDSH-33016
        if sync == nil then sync = false end
304 VincentSDSH-33016
        if locked == nil then locked = false end
305 VincentSDSH-33016
        if book == nil or (type(book)~="string" and type(book)~="table") then book = false end
306 VincentSDSH-33016
        if overwrite == nil then overwrite = false end
307 VincentSDSH-33016
        if syncoverwrite == nil then syncoverwrite = false end
308 VincentSDSH-33016
 
309 VincentSDSH-33016
        local newNote = {}
310 VincentSDSH-33016
        newNote["title"] = title
311 VincentSDSH-33016
        newNote["text"] = text
312 VincentSDSH-33016
        newNote["id"] = id
313 VincentSDSH-33016
        newNote["sync"] = sync
314 VincentSDSH-33016
        newNote["locked"] = locked
315 VincentSDSH-33016
        newNote["book"] = book
316 VincentSDSH-33016
 
317 VincentSDSH-33016
        local newUndoNote = {}
318 VincentSDSH-33016
        newUndoNote["title"] = title
319 VincentSDSH-33016
        newUndoNote["text"] = text
320 VincentSDSH-33016
        newUndoNote["id"] = id
321 VincentSDSH-33016
        newUndoNote["sync"] = sync
322 VincentSDSH-33016
        newUndoNote["locked"] = locked
323 VincentSDSH-33016
        newUndoNote["book"] = book
324 VincentSDSH-33016
        newUndoNote["undo"] = false
325 VincentSDSH-33016
 
326 VincentSDSH-33016
        local oldidx = Notes_GetNoteIndex(id)
327 VincentSDSH-33016
        if oldidx then
328 VincentSDSH-33016
                if not overwrite then return 2-- Print "tried to overwrite existing note?"
329 VincentSDSH-33016
                else
330 VincentSDSH-33016
 
331 VincentSDSH-33016
                        if Notes_Notes[oldidx]["locked"] then
332 VincentSDSH-33016
                                return 2
333 VincentSDSH-33016
 
334 VincentSDSH-33016
                        elseif syncoverwrite and not Notes_Notes[oldidx]["sync"] then
335 VincentSDSH-33016
                                return 1
336 VincentSDSH-33016
 
337 VincentSDSH-33016
                        else
338 VincentSDSH-33016
                                Notes_Notes[oldidx]["title"] = newNote["title"]
339 VincentSDSH-33016
                                Notes_Notes[oldidx]["text"] = newNote["text"]
340 VincentSDSH-33016
                                Notes_Notes[oldidx]["sync"] = newNote["sync"]
341 VincentSDSH-33016
                                Notes_Notes[oldidx]["locked"] = newNote["locked"]
342 VincentSDSH-33016
                                Notes_Notes[oldidx]["book"] = newNote["book"]
343 VincentSDSH-33016
                                if Notes_Selected == oldidx then
344 VincentSDSH-33016
                                        Notes_LoadSelected()
345 VincentSDSH-33016
                                end
346 VincentSDSH-33016
                        end
347 VincentSDSH-33016
                end
348 VincentSDSH-33016
        else
349 VincentSDSH-33016
                table.insert(Notes_Notes,newNote)
350 VincentSDSH-33016
        end
351 VincentSDSH-33016
 
352 VincentSDSH-33016
        Notes_Undo[newNote["id"]] = newUndoNote
353 VincentSDSH-33016
 
354 VincentSDSH-33016
        if not overwrite then
355 VincentSDSH-33016
                Notes_Selected = Notes_GetNoteIndex(newNote["id"])
356 VincentSDSH-33016
                Notes_MultiSelect = {}
357 VincentSDSH-33016
                Notes_LoadSelected()
358 VincentSDSH-33016
        end
359 VincentSDSH-33016
 
360 VincentSDSH-33016
        local bookidx = nil
361 VincentSDSH-33016
        if type(book) == "string" then
362 VincentSDSH-33016
                bookidx = Notes_GetNoteIndex(book)
363 VincentSDSH-33016
                if not bookidx then
364 VincentSDSH-33016
                        if not bookname then bookname = Notes_FindNextInSequence("New Book #1") end
365 VincentSDSH-33016
                        Notes_NewNote(bookname,"",false,false,book,{id})
366 VincentSDSH-33016
                else
367 VincentSDSH-33016
                        table.insert(Notes_Notes[bookidx]["book"],id)
368 VincentSDSH-33016
                        Notes_MultiSelect = {}
369 VincentSDSH-33016
                        Notes_LoadSelected(bookidx)
370 VincentSDSH-33016
                end
371 VincentSDSH-33016
        end
372 VincentSDSH-33016
 
373 VincentSDSH-33016
        Notes_SortAndReselect()
374 VincentSDSH-33016
        Notes_ScrollBarUpdate()
375 VincentSDSH-33016
        return 0
376 VincentSDSH-33016
end
377 VincentSDSH-33016
 
378 VincentSDSH-33016
function Notes_SaveNote()
379 VincentSDSH-33016
        local title = NotesTitleEditBox:GetText()
380 VincentSDSH-33016
        local text = NotesTextEditBox:GetText()
381 VincentSDSH-33016
 
382 VincentSDSH-33016
        if not Notes_Selected then
383 VincentSDSH-33016
                if strlen(title) > 0 or strlen(text) > 0 then
384 VincentSDSH-33016
                        Notes_NewNote(title,text)
385 VincentSDSH-33016
                        return
386 VincentSDSH-33016
 
387 VincentSDSH-33016
                elseif strlen(title) == 0 and strlen(text) == 0 then
388 VincentSDSH-33016
                        return
389 VincentSDSH-33016
                end
390 VincentSDSH-33016
        end
391 VincentSDSH-33016
 
392 VincentSDSH-33016
        local isbook = type(Notes_Notes[Notes_Selected]["book"]) == "table"
393 VincentSDSH-33016
        local bookidx = Notes_GetNoteIndex(Notes_BookID)
394 VincentSDSH-33016
        local booklock = not isbook and bookidx and Notes_Notes[bookidx]["locked"]
395 VincentSDSH-33016
 
396 VincentSDSH-33016
        if Notes_Notes[Notes_Selected]["locked"] or booklock then
397 VincentSDSH-33016
                NotesTitleEditBox:SetText(Notes_Notes[Notes_Selected]["title"])
398 VincentSDSH-33016
 
399 VincentSDSH-33016
                if isbook then Notes_CreateIndexPage() --NotesTextEditBox:SetText(Notes_CreateIndexPage(text))
400 VincentSDSH-33016
                else NotesTextEditBox:SetText(Notes_Notes[Notes_Selected]["text"]) end
401 VincentSDSH-33016
                return
402 VincentSDSH-33016
        end
403 VincentSDSH-33016
 
404 VincentSDSH-33016
        Notes_Notes[Notes_Selected]["title"] = title
405 VincentSDSH-33016
        if isbook then Notes_CreateIndexPage() --NotesTextEditBox:SetText(Notes_CreateIndexPage(text))
406 VincentSDSH-33016
        else Notes_Notes[Notes_Selected]["text"] = text end
407 VincentSDSH-33016
 
408 VincentSDSH-33016
        if Notes_Undo[Notes_LoadID]["undo"] == false then
409 VincentSDSH-33016
           if(strlen(Notes_Undo[Notes_LoadID]["title"]) ~= strlen(Notes_Notes[Notes_Selected]["title"]) or
410 VincentSDSH-33016
            strlen(Notes_Undo[Notes_LoadID]["text"]) ~= strlen(Notes_Notes[Notes_Selected]["text"])) then
411 VincentSDSH-33016
                Notes_Undo[Notes_LoadID]["undo"] = true
412 VincentSDSH-33016
        end end
413 VincentSDSH-33016
 
414 VincentSDSH-33016
        Notes_ScrollBarUpdate()
415 VincentSDSH-33016
end
416 VincentSDSH-33016
 
417 VincentSDSH-33016
function Notes_CopySelected(idx,midx)
418 VincentSDSH-33016
        local index = Notes_Selected
419 VincentSDSH-33016
        local mindex = Notes_MultiSelect
420 VincentSDSH-33016
        if idx then index = idx end
421 VincentSDSH-33016
        if midx then mindex = midx end
422 VincentSDSH-33016
 
423 VincentSDSH-33016
        if not index or not Notes_Notes[index] then return end
424 VincentSDSH-33016
 
425 VincentSDSH-33016
        local mids = {}
426 VincentSDSH-33016
        if not idx then
427 VincentSDSH-33016
                for i=1,getn(mindex) do
428 VincentSDSH-33016
                        table.insert(mids,Notes_Notes[mindex[i]]["id"])
429 VincentSDSH-33016
                end
430 VincentSDSH-33016
        end
431 VincentSDSH-33016
 
432 VincentSDSH-33016
        if type(Notes_Notes[index]["book"]) ~= "table" then
433 VincentSDSH-33016
                local copyNote = {}
434 VincentSDSH-33016
                copyNote["title"] = Notes_FindNextInSequence(Notes_Notes[index]["title"].." Copy #1")
435 VincentSDSH-33016
                copyNote["text"] = Notes_Notes[index]["text"]
436 VincentSDSH-33016
                copyNote["id"] = Notes_MakeNoteID()
437 VincentSDSH-33016
                copyNote["sync"] = Notes_Notes[index]["sync"]
438 VincentSDSH-33016
                copyNote["locked"] = Notes_Notes[index]["locked"]
439 VincentSDSH-33016
 
440 VincentSDSH-33016
                for i=1,getn(Notes_Notes) do
441 VincentSDSH-33016
                        if Notes_Notes[i]["id"] == copyNote["id"] then
442 VincentSDSH-33016
                                return
443 VincentSDSH-33016
                        end
444 VincentSDSH-33016
                end
445 VincentSDSH-33016
 
446 VincentSDSH-33016
                table.insert(Notes_Notes,copyNote)
447 VincentSDSH-33016
 
448 VincentSDSH-33016
                Notes_Undo[copyNote["id"]] = copyNote
449 VincentSDSH-33016
                Notes_Undo[copyNote["id"]]["undo"] = false
450 VincentSDSH-33016
        end
451 VincentSDSH-33016
 
452 VincentSDSH-33016
        if not idx then
453 VincentSDSH-33016
 
454 VincentSDSH-33016
                if getn(mindex) > 0 then
455 VincentSDSH-33016
                        for i=1,getn(mindex) do
456 VincentSDSH-33016
                                Notes_CopySelected(mindex[i])
457 VincentSDSH-33016
                        end
458 VincentSDSH-33016
                end
459 VincentSDSH-33016
 
460 VincentSDSH-33016
                Notes_SortAndReselect(mids)
461 VincentSDSH-33016
                Notes_ScrollBarUpdate()
462 VincentSDSH-33016
        end
463 VincentSDSH-33016
end
464 VincentSDSH-33016
 
465 VincentSDSH-33016
function Notes_LoadSelected(idx)
466 VincentSDSH-33016
        local index = Notes_Selected
467 VincentSDSH-33016
        if idx then index = idx end
468 VincentSDSH-33016
 
469 VincentSDSH-33016
        if not index or not Notes_Notes[index] then return Notes_LoadEmpty() end
470 VincentSDSH-33016
 
471 VincentSDSH-33016
        if type(Notes_Notes[index]["book"])=="table" then
472 VincentSDSH-33016
                Notes_BookID = Notes_Notes[index]["id"]
473 VincentSDSH-33016
                Notes_BookPages = Notes_Notes[index]["book"]
474 VincentSDSH-33016
                Notes_BookPage = 0
475 VincentSDSH-33016
 
476 VincentSDSH-33016
                Notes_CreateIndexPage()
477 VincentSDSH-33016
                NotesTitleEditBox:SetText(Notes_Notes[index]["title"])
478 VincentSDSH-33016
                Notes_LoadID = Notes_Notes[index]["id"]
479 VincentSDSH-33016
        else
480 VincentSDSH-33016
                NotesTextEditBox:SetText(Notes_Notes[index]["text"])
481 VincentSDSH-33016
                NotesTitleEditBox:SetText(Notes_Notes[index]["title"])
482 VincentSDSH-33016
                Notes_LoadID = Notes_Notes[index]["id"]
483 VincentSDSH-33016
 
484 VincentSDSH-33016
                if type(Notes_Notes[index]["book"])~="string" then
485 VincentSDSH-33016
                        Notes_BookID = nil
486 VincentSDSH-33016
                        Notes_BookPage = 0
487 VincentSDSH-33016
                        Notes_BookPages = {}
488 VincentSDSH-33016
                else
489 VincentSDSH-33016
                        Notes_MultiSelect = {}
490 VincentSDSH-33016
                end
491 VincentSDSH-33016
        end
492 VincentSDSH-33016
 
493 VincentSDSH-33016
        Notes_SortAndReselect()
494 VincentSDSH-33016
        Notes_ScrollBarUpdate()
495 VincentSDSH-33016
end
496 VincentSDSH-33016
 
497 VincentSDSH-33016
function Notes_LoadEmpty()
498 VincentSDSH-33016
        Notes_MultiSelect = {}
499 VincentSDSH-33016
        Notes_Selected = nil
500 VincentSDSH-33016
        Notes_LoadID = nil
501 VincentSDSH-33016
        Notes_BookID = nil
502 VincentSDSH-33016
        Notes_BookPages = {}
503 VincentSDSH-33016
        Notes_BookPage = 0
504 VincentSDSH-33016
        Notes_SelectedAtLastUpdate = nil
505 VincentSDSH-33016
 
506 VincentSDSH-33016
        NotesTextEditBox:SetText("")
507 VincentSDSH-33016
        NotesTitleEditBox:SetText("")
508 VincentSDSH-33016
 
509 VincentSDSH-33016
        NotesTOC:Hide()
510 VincentSDSH-33016
        NotesText:Show()
511 VincentSDSH-33016
 
512 VincentSDSH-33016
        Notes_SortAndReselect()
513 VincentSDSH-33016
        Notes_ScrollBarUpdate()
514 VincentSDSH-33016
end
515 VincentSDSH-33016
 
516 VincentSDSH-33016
function Notes_RevertSelected()
517 VincentSDSH-33016
        if Notes_Selected and Notes_Undo[Notes_LoadID]["undo"] == true then
518 VincentSDSH-33016
 
519 VincentSDSH-33016
                Notes_Notes[Notes_Selected]["title"] = Notes_Undo[Notes_LoadID]["title"]
520 VincentSDSH-33016
                Notes_Notes[Notes_Selected]["text"] = Notes_Undo[Notes_LoadID]["text"]
521 VincentSDSH-33016
                Notes_Notes[Notes_Selected]["sync"] = Notes_Undo[Notes_LoadID]["sync"]
522 VincentSDSH-33016
                Notes_Notes[Notes_Selected]["locked"] = Notes_Undo[Notes_LoadID]["locked"]
523 VincentSDSH-33016
                Notes_Notes[Notes_Selected]["book"] = Notes_Undo[Notes_LoadID]["book"]
524 VincentSDSH-33016
                Notes_Undo[Notes_LoadID]["undo"] = false
525 VincentSDSH-33016
 
526 VincentSDSH-33016
                Notes_LoadSelected()
527 VincentSDSH-33016
 
528 VincentSDSH-33016
                Notes_SortAndReselect()
529 VincentSDSH-33016
                Notes_ScrollBarUpdate()
530 VincentSDSH-33016
        end
531 VincentSDSH-33016
end
532 VincentSDSH-33016
 
533 VincentSDSH-33016
function Notes_PrepUndo()
534 VincentSDSH-33016
        Notes_TotalPages = 0
535 VincentSDSH-33016
        Notes_Undo = {}
536 VincentSDSH-33016
        for i=1,getn(Notes_Notes) do
537 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]={}
538 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]["id"] = Notes_Notes[i]["id"]
539 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]["title"] = Notes_Notes[i]["title"]
540 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]["text"] = Notes_Notes[i]["text"]
541 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]["sync"] = Notes_Notes[i]["sync"]
542 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]["locked"] = Notes_Notes[i]["locked"]
543 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]["book"] = Notes_Notes[i]["book"]
544 VincentSDSH-33016
                Notes_Undo[Notes_Notes[i]["id"]]["undo"] = false
545 VincentSDSH-33016
        end
546 VincentSDSH-33016
end
547 VincentSDSH-33016
 
548 VincentSDSH-33016
function Notes_FixHiddenPages()
549 VincentSDSH-33016
        Notes_TotalPages = 0
550 VincentSDSH-33016
        for i=1,getn(Notes_Notes) do
551 VincentSDSH-33016
                if type(Notes_Notes[i]["book"]) == "string" then
552 VincentSDSH-33016
                        Notes_TotalPages = Notes_TotalPages + 1
553 VincentSDSH-33016
                end
554 VincentSDSH-33016
        end
555 VincentSDSH-33016
end
556 VincentSDSH-33016
 
557 VincentSDSH-33016
function Notes_SyncSelected(idx,midx)
558 VincentSDSH-33016
        local index = Notes_Selected
559 VincentSDSH-33016
        local mindex = Notes_MultiSelect
560 VincentSDSH-33016
        if idx then index = idx end
561 VincentSDSH-33016
        if midx then mindex = midx end
562 VincentSDSH-33016
 
563 VincentSDSH-33016
        if not index or not Notes_Notes[index] then return end
564 VincentSDSH-33016
 
565 VincentSDSH-33016
        local ispage = type(Notes_Notes[index]["book"]) == "string"
566 VincentSDSH-33016
        local bookidx = Notes_GetNoteIndex(Notes_BookID)
567 VincentSDSH-33016
        local booksync = ispage and bookidx and Notes_Notes[bookidx]["sync"]
568 VincentSDSH-33016
        local booklock = ispage and bookidx and Notes_Notes[bookidx]["locked"]
569 VincentSDSH-33016
 
570 VincentSDSH-33016
        if booksync and not Notes_Notes[index]["sync"] then
571 VincentSDSH-33016
                Notes_Notes[index]["sync"] = 1
572 VincentSDSH-33016
        else
573 VincentSDSH-33016
                Notes_Notes[index]["sync"] = NotesSyncCheckButton:GetChecked()
574 VincentSDSH-33016
        end
575 VincentSDSH-33016
 
576 VincentSDSH-33016
        if not idx then
577 VincentSDSH-33016
                if getn(mindex) > 0 then
578 VincentSDSH-33016
                        for i=1,getn(mindex) do
579 VincentSDSH-33016
                                Notes_SyncSelected(mindex[i])
580 VincentSDSH-33016
                        end
581 VincentSDSH-33016
                end
582 VincentSDSH-33016
                Notes_ScrollBarUpdate(1)
583 VincentSDSH-33016
        end
584 VincentSDSH-33016
end
585 VincentSDSH-33016
 
586 VincentSDSH-33016
function Notes_LockedSelected(idx,midx)
587 VincentSDSH-33016
        local index = Notes_Selected
588 VincentSDSH-33016
        local mindex = Notes_MultiSelect
589 VincentSDSH-33016
        if idx then index = idx end
590 VincentSDSH-33016
        if midx then mindex = midx end
591 VincentSDSH-33016
 
592 VincentSDSH-33016
        if not index or not Notes_Notes[index] then return end
593 VincentSDSH-33016
 
594 VincentSDSH-33016
        local ispage = type(Notes_Notes[index]["book"]) == "string"
595 VincentSDSH-33016
        local bookidx = Notes_GetNoteIndex(Notes_BookID)
596 VincentSDSH-33016
        local booklock = ispage and bookidx and Notes_Notes[bookidx]["locked"]
597 VincentSDSH-33016
 
598 VincentSDSH-33016
        if booklock then
599 VincentSDSH-33016
                NotesLockedCheckButton:SetChecked(1) --SetChecked(Notes_Notes[index]["locked"])
600 VincentSDSH-33016
        else
601 VincentSDSH-33016
                Notes_Notes[index]["locked"] = NotesLockedCheckButton:GetChecked()
602 VincentSDSH-33016
        end
603 VincentSDSH-33016
 
604 VincentSDSH-33016
        if not idx then
605 VincentSDSH-33016
                if not booklock and getn(mindex) > 0 then
606 VincentSDSH-33016
                        for i=1,getn(mindex) do
607 VincentSDSH-33016
                                Notes_LockedSelected(mindex[i])
608 VincentSDSH-33016
                        end
609 VincentSDSH-33016
                end
610 VincentSDSH-33016
                Notes_ScrollBarUpdate(1)
611 VincentSDSH-33016
        end
612 VincentSDSH-33016
end
613 VincentSDSH-33016
 
614 VincentSDSH-33016
function Notes_DeleteSelected(idx,midx)
615 VincentSDSH-33016
        return Notes_DeleteAndRebuild(idx,midx)
616 VincentSDSH-33016
end
617 VincentSDSH-33016
 
618 VincentSDSH-33016
function Notes_DeleteAndRebuild(idx,midx)
619 VincentSDSH-33016
        local index = Notes_Selected
620 VincentSDSH-33016
        local mindex = Notes_MultiSelect
621 VincentSDSH-33016
        if idx then index = idx end
622 VincentSDSH-33016
        if midx then mindex = midx end
623 VincentSDSH-33016
 
624 VincentSDSH-33016
        if not index or not Notes_Notes[index] then return end
625 VincentSDSH-33016
 
626 VincentSDSH-33016
        local newmid = nil
627 VincentSDSH-33016
 
628 VincentSDSH-33016
        local deletestack = {}
629 VincentSDSH-33016
        local selectstack = {}
630 VincentSDSH-33016
        local newNotes_Notes = {}
631 VincentSDSH-33016
 
632 VincentSDSH-33016
        if not Notes_Notes[index]["locked"] then
633 VincentSDSH-33016
                table.insert(selectstack,index)
634 VincentSDSH-33016
        end
635 VincentSDSH-33016
        if getn(mindex) > 0 then
636 VincentSDSH-33016
                for i=1,getn(mindex) do
637 VincentSDSH-33016
                        if not Notes_Notes[mindex[i]]["locked"] then
638 VincentSDSH-33016
                                table.insert(selectstack,mindex[i])
639 VincentSDSH-33016
                        end
640 VincentSDSH-33016
                end
641 VincentSDSH-33016
        end
642 VincentSDSH-33016
 
643 VincentSDSH-33016
        for i=1,getn(selectstack) do
644 VincentSDSH-33016
                if type(Notes_Notes[selectstack[i]]["book"])=="table" then
645 VincentSDSH-33016
                        if getn(Notes_Notes[selectstack[i]]["book"]) > 0 then
646 VincentSDSH-33016
                                for j=1,getn(Notes_Notes[selectstack[i]]["book"]) do
647 VincentSDSH-33016
                                        local pageidx = Notes_GetNoteIndex(Notes_Notes[selectstack[i]]["book"][j])
648 VincentSDSH-33016
                                        if pageidx then
649 VincentSDSH-33016
                                                if not Notes_Notes[pageidx]["locked"] then
650 VincentSDSH-33016
                                                        table.insert(deletestack,pageidx)
651 VincentSDSH-33016
                                                        Notes_TotalPages = Notes_TotalPages - 1
652 VincentSDSH-33016
                                                else
653 VincentSDSH-33016
                                                        Notes_Notes[pageidx]["book"] = false
654 VincentSDSH-33016
 
655 VincentSDSH-33016
                                                        if not newmid or type(newmid) == "string" then newmid = {} end
656 VincentSDSH-33016
                                                        table.insert(newmid,Notes_Notes[pageidx]["id"])
657 VincentSDSH-33016
                                                end
658 VincentSDSH-33016
                                        end
659 VincentSDSH-33016
                                end
660 VincentSDSH-33016
                        end
661 VincentSDSH-33016
                        table.insert(deletestack,selectstack[i])
662 VincentSDSH-33016
 
663 VincentSDSH-33016
                elseif type(Notes_Notes[selectstack[i]]["book"])=="string" then
664 VincentSDSH-33016
                        local curidx, newidx = Notes_ExtractSelected(selectstack[i])
665 VincentSDSH-33016
                        if newidx and not newmid then
666 VincentSDSH-33016
                                newmid = Notes_Notes[newidx]["id"]
667 VincentSDSH-33016
                        end
668 VincentSDSH-33016
                        table.insert(deletestack,curidx)
669 VincentSDSH-33016
                else
670 VincentSDSH-33016
                        table.insert(deletestack,selectstack[i])
671 VincentSDSH-33016
                end
672 VincentSDSH-33016
        end
673 VincentSDSH-33016
 
674 VincentSDSH-33016
        for i=1,getn(Notes_Notes) do
675 VincentSDSH-33016
                if not Notes_InTable(deletestack,i) then
676 VincentSDSH-33016
                        table.insert(newNotes_Notes,Notes_Notes[i])
677 VincentSDSH-33016
                end
678 VincentSDSH-33016
        end
679 VincentSDSH-33016
 
680 VincentSDSH-33016
        Notes_Notes = newNotes_Notes
681 VincentSDSH-33016
 
682 VincentSDSH-33016
        if type(newmid)=="string" then
683 VincentSDSH-33016
                local lid = Notes_GetNoteIndex(newmid)
684 VincentSDSH-33016
                if lid then
685 VincentSDSH-33016
                        Notes_LoadSelected(lid)
686 VincentSDSH-33016
                else
687 VincentSDSH-33016
                        Notes_LoadEmpty()
688 VincentSDSH-33016
                end
689 VincentSDSH-33016
 
690 VincentSDSH-33016
        elseif type(newmid)=="table" then
691 VincentSDSH-33016
 
692 VincentSDSH-33016
                Notes_LoadSelected(Notes_GetNoteIndex(newmid[1]))
693 VincentSDSH-33016
                if getn(newmid) > 1 then
694 VincentSDSH-33016
                        Notes_MultiSelect = {}
695 VincentSDSH-33016
                        for i=2,getn(newmid) do
696 VincentSDSH-33016
                                local mulidx = Notes_GetNoteIndex(newmid[i])
697 VincentSDSH-33016
                                if mulidx then table.insert(Notes_MultiSelect,mulidx) end
698 VincentSDSH-33016
                        end
699 VincentSDSH-33016
                end
700 VincentSDSH-33016
        else
701 VincentSDSH-33016
                Notes_LoadEmpty()
702 VincentSDSH-33016
        end
703 VincentSDSH-33016
        Notes_ScrollBarUpdate(1)
704 VincentSDSH-33016
end
705 VincentSDSH-33016
 
706 VincentSDSH-33016
function Notes_CompileOrExtractSelected(idx,midx)
707 VincentSDSH-33016
        local index = Notes_Selected
708 VincentSDSH-33016
        local mindex = Notes_MultiSelect
709 VincentSDSH-33016
        if idx then index = idx end
710 VincentSDSH-33016
        if midx then mindex = midx end
711 VincentSDSH-33016
 
712 VincentSDSH-33016
        if not index then return end
713 VincentSDSH-33016
 
714 VincentSDSH-33016
        local selectstack = {}
715 VincentSDSH-33016
 
716 VincentSDSH-33016
        if type(Notes_Notes[index]["book"])=="table" and getn(mindex) == 0 then
717 VincentSDSH-33016
                for i=getn(Notes_Notes[index]["book"]),1,-1 do
718 VincentSDSH-33016
                        local page = Notes_GetNoteIndex(Notes_Notes[index]["book"][i])
719 VincentSDSH-33016
                        table.insert(selectstack,Notes_Notes[page]["id"])
720 VincentSDSH-33016
                        if page then Notes_ExtractSelected(page) end
721 VincentSDSH-33016
                end
722 VincentSDSH-33016
 
723 VincentSDSH-33016
                if getn(selectstack) > 0 then
724 VincentSDSH-33016
                        if getn(selectstack) > 1 then
725 VincentSDSH-33016
                                for i=2,getn(selectstack) do
726 VincentSDSH-33016
                                        local page = Notes_GetNoteIndex(selectstack[i])
727 VincentSDSH-33016
                                        table.insert(Notes_MultiSelect,page)
728 VincentSDSH-33016
                                end
729 VincentSDSH-33016
                        end
730 VincentSDSH-33016
                        Notes_LoadSelected(Notes_GetNoteIndex(selectstack[1]))
731 VincentSDSH-33016
                end
732 VincentSDSH-33016
 
733 VincentSDSH-33016
        elseif type(Notes_Notes[index]["book"])=="string" then
734 VincentSDSH-33016
                Notes_LoadSelected(Notes_ExtractSelected())
735 VincentSDSH-33016
        else
736 VincentSDSH-33016
                Notes_CompileSelected()
737 VincentSDSH-33016
        end
738 VincentSDSH-33016
 
739 VincentSDSH-33016
 
740 VincentSDSH-33016
        Notes_SortAndReselect()
741 VincentSDSH-33016
        Notes_ScrollBarUpdate(1)
742 VincentSDSH-33016
end
743 VincentSDSH-33016
 
744 VincentSDSH-33016
function Notes_CompileSelected(idx,midx)
745 VincentSDSH-33016
        local index = Notes_Selected
746 VincentSDSH-33016
        local mindex = Notes_MultiSelect
747 VincentSDSH-33016
        if idx then index = idx end
748 VincentSDSH-33016
        if midx then mindex = midx end
749 VincentSDSH-33016
 
750 VincentSDSH-33016
        if not index then return end
751 VincentSDSH-33016
 
752 VincentSDSH-33016
        local selectstack = {}
753 VincentSDSH-33016
        local pagestack = {}
754 VincentSDSH-33016
        local idstack = {}
755 VincentSDSH-33016
 
756 VincentSDSH-33016
        local targetbook = nil
757 VincentSDSH-33016
        local deletebooks = {}
758 VincentSDSH-33016
 
759 VincentSDSH-33016
        table.insert(selectstack,index)
760 VincentSDSH-33016
        if getn(mindex) > 0 then
761 VincentSDSH-33016
                for i=1,getn(mindex) do
762 VincentSDSH-33016
                        table.insert(selectstack,mindex[i])
763 VincentSDSH-33016
                end
764 VincentSDSH-33016
        end
765 VincentSDSH-33016
 
766 VincentSDSH-33016
        table.sort(selectstack,Notes_HashNatNotesTitleSort)
767 VincentSDSH-33016
 
768 VincentSDSH-33016
        for i=1,getn(selectstack) do
769 VincentSDSH-33016
                if type(Notes_Notes[selectstack[i]]["book"])=="table" and getn(Notes_Notes[selectstack[i]]["book"]) > 0 then
770 VincentSDSH-33016
                        for j=1,getn(Notes_Notes[selectstack[i]]["book"]) do
771 VincentSDSH-33016
                                local pageidx = Notes_GetNoteIndex(Notes_Notes[selectstack[i]]["book"][j])
772 VincentSDSH-33016
                                if pageidx then
773 VincentSDSH-33016
                                        table.insert(pagestack,pageidx)
774 VincentSDSH-33016
                                        table.insert(idstack,Notes_Notes[pageidx]["id"])
775 VincentSDSH-33016
                                end
776 VincentSDSH-33016
                        end
777 VincentSDSH-33016
                        if targetbook == nil and getn(deletebooks) == 0 then
778 VincentSDSH-33016
                                targetbook = Notes_Notes[selectstack[i]]["id"]
779 VincentSDSH-33016
 
780 VincentSDSH-33016
                        else
781 VincentSDSH-33016
                                if targetbook ~= nil then
782 VincentSDSH-33016
                                        table.insert(deletebooks,targetbook)
783 VincentSDSH-33016
                                        targetbook = nil
784 VincentSDSH-33016
                                end
785 VincentSDSH-33016
                                table.insert(deletebooks,Notes_Notes[selectstack[i]]["id"])
786 VincentSDSH-33016
                        end
787 VincentSDSH-33016
 
788 VincentSDSH-33016
                elseif type(Notes_Notes[selectstack[i]]["book"])~="string" then
789 VincentSDSH-33016
                        table.insert(pagestack,selectstack[i])
790 VincentSDSH-33016
                        table.insert(idstack,Notes_Notes[selectstack[i]]["id"])
791 VincentSDSH-33016
                end
792 VincentSDSH-33016
        end
793 VincentSDSH-33016
 
794 VincentSDSH-33016
 
795 VincentSDSH-33016
        if targetbook then
796 VincentSDSH-33016
                local bookidx = Notes_GetNoteIndex(targetbook)
797 VincentSDSH-33016
                if bookidx then
798 VincentSDSH-33016
                        for i=1,getn(selectstack) do
799 VincentSDSH-33016
                                local booktype = type(Notes_Notes[selectstack[i]]["book"])
800 VincentSDSH-33016
                                Notes_Notes[selectstack[i]]["book"] = Notes_Notes[bookidx]["id"]
801 VincentSDSH-33016
                        end
802 VincentSDSH-33016
 
803 VincentSDSH-33016
                        Notes_Notes[bookidx]["book"] = idstack
804 VincentSDSH-33016
                        Notes_Selected = bookidx
805 VincentSDSH-33016
                        Notes_LoadSelected()
806 VincentSDSH-33016
                        Notes_MultiSelect = {}
807 VincentSDSH-33016
                        return
808 VincentSDSH-33016
                end
809 VincentSDSH-33016
        end
810 VincentSDSH-33016
 
811 VincentSDSH-33016
        local bookid = Notes_MakeNoteID()
812 VincentSDSH-33016
 
813 VincentSDSH-33016
        for i=1,getn(selectstack) do
814 VincentSDSH-33016
                Notes_Notes[selectstack[i]]["book"] = bookid
815 VincentSDSH-33016
        end
816 VincentSDSH-33016
 
817 VincentSDSH-33016
        Notes_MultiSelect = {}
818 VincentSDSH-33016
        if getn(deletebooks) > 0 then
819 VincentSDSH-33016
                for i=1,getn(deletebooks) do
820 VincentSDSH-33016
                        local bookidx = Notes_GetNoteIndex(deletebooks[i])
821 VincentSDSH-33016
                        if bookidx then
822 VincentSDSH-33016
                                Notes_Notes[bookidx]["book"] = false
823 VincentSDSH-33016
                                Notes_Notes[bookidx]["locked"] = false
824 VincentSDSH-33016
                                Notes_DeleteAndRebuild(bookidx)
825 VincentSDSH-33016
                        end
826 VincentSDSH-33016
                end
827 VincentSDSH-33016
        end
828 VincentSDSH-33016
        Notes_NewNote(Notes_FindNextInSequence("New Book #1"),"",false,false,bookid,idstack)
829 VincentSDSH-33016
end
830 VincentSDSH-33016
 
831 VincentSDSH-33016
function Notes_ExtractSelected(idx)
832 VincentSDSH-33016
        local index = Notes_Selected
833 VincentSDSH-33016
        if idx then index = idx end
834 VincentSDSH-33016
 
835 VincentSDSH-33016
        if not index then return end
836 VincentSDSH-33016
 
837 VincentSDSH-33016
        local loadid = Notes_LoadID
838 VincentSDSH-33016
        local bookidx = Notes_GetNoteIndex(Notes_BookID)
839 VincentSDSH-33016
        Notes_Notes[index]["book"] = false
840 VincentSDSH-33016
 
841 VincentSDSH-33016
        if bookidx then
842 VincentSDSH-33016
                local contents = {}
843 VincentSDSH-33016
                for i=1,getn(Notes_Notes[bookidx]["book"]) do
844 VincentSDSH-33016
                        if Notes_Notes[bookidx]["book"][i] ~= Notes_Notes[index]["id"] then
845 VincentSDSH-33016
                                table.insert(contents,Notes_Notes[bookidx]["book"][i])
846 VincentSDSH-33016
                        else
847 VincentSDSH-33016
                                Notes_TotalPages = Notes_TotalPages - 1
848 VincentSDSH-33016
                        end
849 VincentSDSH-33016
                end
850 VincentSDSH-33016
 
851 VincentSDSH-33016
                if getn(contents) > 0 then
852 VincentSDSH-33016
                        Notes_Notes[bookidx]["book"] = contents
853 VincentSDSH-33016
                        if Notes_BookPage > getn(contents) then
854 VincentSDSH-33016
                                Notes_BookPage = Notes_BookPage - 1
855 VincentSDSH-33016
                        end
856 VincentSDSH-33016
 
857 VincentSDSH-33016
                        return Notes_GetNoteIndex(loadid), Notes_GetNoteIndex(contents[Notes_BookPage])
858 VincentSDSH-33016
                else
859 VincentSDSH-33016
                        Notes_Notes[bookidx]["book"] = false
860 VincentSDSH-33016
                        Notes_Notes[bookidx]["locked"] = false
861 VincentSDSH-33016
                        Notes_DeleteAndRebuild(bookidx)
862 VincentSDSH-33016
                        return Notes_GetNoteIndex(loadid)
863 VincentSDSH-33016
                end
864 VincentSDSH-33016
        end
865 VincentSDSH-33016
end
866 VincentSDSH-33016
 
867 VincentSDSH-33016
------------------------------------------
868 VincentSDSH-33016
-- D) LUA Functions
869 VincentSDSH-33016
--[[
870 VincentSDSH-33016
Notes_ExecuteSelected - Execute the selected LUA script note
871 VincentSDSH-33016
RunNote - wrapper for Notes_RunNote
872 VincentSDSH-33016
Notes_RunNote - Execute a LUA script note by passing a note id
873 VincentSDSH-33016
Notes_AddLUASetupNote - Add the default LUA setup note
874 VincentSDSH-33016
]]--
875 VincentSDSH-33016
 
876 VincentSDSH-33016
function Notes_ExecuteSelected(idx)
877 VincentSDSH-33016
        local index = Notes_Selected
878 VincentSDSH-33016
        if idx then index = idx end
879 VincentSDSH-33016
 
880 VincentSDSH-33016
        if not index then return end
881 VincentSDSH-33016
 
882 VincentSDSH-33016
        RunScript(Notes_Notes[index]["text"])
883 VincentSDSH-33016
end
884 VincentSDSH-33016
 
885 VincentSDSH-33016
function RunNote(noteid)
886 VincentSDSH-33016
        return Notes_RunNote(noteid)
887 VincentSDSH-33016
end
888 VincentSDSH-33016
 
889 VincentSDSH-33016
function Notes_RunNote(noteid)
890 VincentSDSH-33016
        local idx = Notes_GetNoteIndex(tostring(noteid))
891 VincentSDSH-33016
        if idx ~= nil then Notes_ExecuteSelected(idx) else
892 VincentSDSH-33016
        Notes_ErrorPrint("Note ID ["..noteid.."] not found") end
893 VincentSDSH-33016
end
894 VincentSDSH-33016
 
895 VincentSDSH-33016
function Notes_AddLUASetupNote()
896 VincentSDSH-33016
        Notes_NewNote(Notes_LUASetupNote[1],Notes_LUASetupNote[2],false,false,"1","2","Notes LUA Book")
897 VincentSDSH-33016
end
898 VincentSDSH-33016
 
899 VincentSDSH-33016
------------------------------------------
900 VincentSDSH-33016
-- E) UI Update Functions
901 VincentSDSH-33016
--[[
902 VincentSDSH-33016
Notes_SetButtonState - Update the Button UI status
903 VincentSDSH-33016
Notes_ScrollBarUpdate - Update the graphics for the notes navigation system
904 VincentSDSH-33016
Notes_GetColor - Get the proper color for a note's title
905 VincentSDSH-33016
]]--
906 VincentSDSH-33016
 
907 VincentSDSH-33016
function Notes_SetButtonState(fullupdate)
908 VincentSDSH-33016
        if not NotesFrame:IsVisible() then return end
909 VincentSDSH-33016
 
910 VincentSDSH-33016
        if Notes_Selected and Notes_Notes[Notes_Selected] then
911 VincentSDSH-33016
                if Notes_Selected ~= Notes_SelectedAtLastUpdate or
912 VincentSDSH-33016
                   Notes_MultiSelectCountAtLastUpdate ~= getn(Notes_MultiSelect) or fullupdate then
913 VincentSDSH-33016
                        Notes_SelectedAtLastUpdate = Notes_Selected
914 VincentSDSH-33016
                        Notes_MultiSelectCountAtLastUpdate = getn(Notes_MultiSelect)
915 VincentSDSH-33016
 
916 VincentSDSH-33016
                        NotesLockedCheckButton:SetChecked(Notes_Notes[Notes_Selected]["locked"])
917 VincentSDSH-33016
                        NotesCompileButton:Enable()
918 VincentSDSH-33016
                        NotesExecuteButton:Enable()
919 VincentSDSH-33016
                        NotesSyncCheckButton:Enable()
920 VincentSDSH-33016
                        NotesSyncCheckButtonText:SetText("Sync")
921 VincentSDSH-33016
                        NotesSyncCheckButton:SetCheckedTexture("Interface/Buttons/UI-CheckBox-Check")
922 VincentSDSH-33016
                        NotesSyncCheckButton:SetChecked(Notes_Notes[Notes_Selected]["sync"])
923 VincentSDSH-33016
                        NotesLockedCheckButtonText:SetText("Locked")
924 VincentSDSH-33016
                        NotesLockedCheckButton:Enable()
925 VincentSDSH-33016
                        NotesLockedCheckButtonText:SetTextColor(Notes_ColorNormal[1],Notes_ColorNormal[2],Notes_ColorNormal[3])
926 VincentSDSH-33016
                        NotesCommSendButton:SetText("Print Note")
927 VincentSDSH-33016
                        NotesGoPageButton:SetText("Index")
928 VincentSDSH-33016
 
929 VincentSDSH-33016
                        NotesTOC:Hide()
930 VincentSDSH-33016
                        NotesText:Show()
931 VincentSDSH-33016
 
932 VincentSDSH-33016
                        local isbook = type(Notes_Notes[Notes_Selected]["book"]) == "table"
933 VincentSDSH-33016
                        local bookidx = Notes_GetNoteIndex(Notes_BookID)
934 VincentSDSH-33016
                        local booksync = not isbook and bookidx and Notes_Notes[bookidx]["sync"]
935 VincentSDSH-33016
                        local booklock = not isbook and bookidx and Notes_Notes[bookidx]["locked"]
936 VincentSDSH-33016
 
937 VincentSDSH-33016
                        local unlockcount = 0
938 VincentSDSH-33016
                        local notecount = 0
939 VincentSDSH-33016
 
940 VincentSDSH-33016
                        if not Notes_Notes[Notes_Selected]["locked"] then
941 VincentSDSH-33016
                                unlockcount = unlockcount + 1
942 VincentSDSH-33016
                        end
943 VincentSDSH-33016
                        if type(Notes_Notes[Notes_Selected]["book"]) ~= "table" then
944 VincentSDSH-33016
                                notecount = notecount + 1
945 VincentSDSH-33016
                        end
946 VincentSDSH-33016
                        for i=1,getn(Notes_MultiSelect) do
947 VincentSDSH-33016
                                if not Notes_Notes[Notes_MultiSelect[i]]["locked"] then
948 VincentSDSH-33016
                                        unlockcount = unlockcount + 1
949 VincentSDSH-33016
                                end
950 VincentSDSH-33016
                                if type(Notes_Notes[Notes_MultiSelect[i]]["book"]) ~= "table" then
951 VincentSDSH-33016
                                        notecount = notecount + 1
952 VincentSDSH-33016
                                end
953 VincentSDSH-33016
                        end
954 VincentSDSH-33016
 
955 VincentSDSH-33016
                        if isbook then
956 VincentSDSH-33016
                                Notes_BookUIToggle("show")
957 VincentSDSH-33016
                                NotesSyncCheckButton:Enable()
958 VincentSDSH-33016
                                NotesSyncCheckButtonText:SetTextColor(Notes_ColorBookSync[1],Notes_ColorBookSync[2],Notes_ColorBookSync[3])
959 VincentSDSH-33016
                                NotesLockedCheckButton:Enable()
960 VincentSDSH-33016
                                NotesReorderPageButton:Disable()
961 VincentSDSH-33016
                                NotesCurPageNumText:Show()
962 VincentSDSH-33016
                                NotesCurPageNumText:SetText(Notes_BookPage)
963 VincentSDSH-33016
                                NotesPageSlash:Show()
964 VincentSDSH-33016
                                NotesPageLabel:Show()
965 VincentSDSH-33016
                                NotesMaxPageNumText:Show()
966 VincentSDSH-33016
                                NotesMaxPageNumText:SetText(getn(Notes_Notes[bookidx]["book"]))
967 VincentSDSH-33016
                                NotesCommSendButton:SetText("Print Book")
968 VincentSDSH-33016
                                NotesGoPageButton:SetText("Go to")
969 VincentSDSH-33016
 
970 VincentSDSH-33016
                                NotesTOC:Show()
971 VincentSDSH-33016
                                NotesText:Hide()
972 VincentSDSH-33016
 
973 VincentSDSH-33016
                                NotesPrevPageButton:Disable()
974 VincentSDSH-33016
                                NotesNextPageButton:Enable()
975 VincentSDSH-33016
                                NotesPrevPageButtonText:SetTextColor(Notes_ColorLocked[1],Notes_ColorLocked[2],Notes_ColorLocked[3])
976 VincentSDSH-33016
                                NotesNextPageButtonText:SetTextColor(Notes_ColorNormal[1],Notes_ColorNormal[2],Notes_ColorNormal[3])
977 VincentSDSH-33016
 
978 VincentSDSH-33016
                                if getn(Notes_MultiSelect) > 0 then
979 VincentSDSH-33016
                                        NotesCompileButton:SetText("Compile")
980 VincentSDSH-33016
                                else
981 VincentSDSH-33016
                                        NotesCompileButton:SetText("Extract All")
982 VincentSDSH-33016
                                        if Notes_Notes[Notes_Selected]["locked"] then NotesCompileButton:Disable() end
983 VincentSDSH-33016
                                end
984 VincentSDSH-33016
                        else
985 VincentSDSH-33016
                                if not Notes_Notes[Notes_Selected]["sync"] and booksync then
986 VincentSDSH-33016
                                        NotesSyncCheckButton:SetChecked(1)
987 VincentSDSH-33016
                                        NotesSyncCheckButton:SetCheckedTexture("Interface/Buttons/UI-CheckBox-Check-Disabled")
988 VincentSDSH-33016
                                        NotesSyncCheckButtonText:SetText("Book Sync")
989 VincentSDSH-33016
                                end
990 VincentSDSH-33016
 
991 VincentSDSH-33016
                                if Notes_BookID and type(Notes_Notes[Notes_Selected]["book"]) == "string" then
992 VincentSDSH-33016
                                        Notes_BookPages = Notes_Notes[bookidx]["book"]
993 VincentSDSH-33016
 
994 VincentSDSH-33016
                                        local pages = getn(Notes_BookPages)
995 VincentSDSH-33016
                                        Notes_BookUIToggle("show")
996 VincentSDSH-33016
                                        NotesCompileButton:SetText("Extract")
997 VincentSDSH-33016
                                        NotesReorderPageButton:Enable()
998 VincentSDSH-33016
                                        NotesCurPageNumText:Show()
999 VincentSDSH-33016
                                        NotesCurPageNumText:SetText(Notes_BookPage)
1000 VincentSDSH-33016
                                        NotesPageSlash:Show()
1001 VincentSDSH-33016
                                        NotesPageLabel:Show()
1002 VincentSDSH-33016
                                        NotesMaxPageNumText:Show()
1003 VincentSDSH-33016
                                        NotesMaxPageNumText:SetText(pages)
1004 VincentSDSH-33016
 
1005 VincentSDSH-33016
                                        if Notes_BookPage <= 0 then
1006 VincentSDSH-33016
                                                NotesPrevPageButton:Disable()
1007 VincentSDSH-33016
                                                NotesNextPageButton:Enable()
1008 VincentSDSH-33016
                                                NotesPrevPageButtonText:SetTextColor(Notes_ColorLocked[1],Notes_ColorLocked[2],Notes_ColorLocked[3])
1009 VincentSDSH-33016
                                                NotesNextPageButtonText:SetTextColor(Notes_ColorNormal[1],Notes_ColorNormal[2],Notes_ColorNormal[3])
1010 VincentSDSH-33016
 
1011 VincentSDSH-33016
                                        elseif Notes_BookPage >= pages then
1012 VincentSDSH-33016
                                                NotesPrevPageButton:Enable()
1013 VincentSDSH-33016
                                                NotesNextPageButton:Disable()
1014 VincentSDSH-33016
                                                NotesPrevPageButtonText:SetTextColor(Notes_ColorNormal[1],Notes_ColorNormal[2],Notes_ColorNormal[3])
1015 VincentSDSH-33016
                                                NotesNextPageButtonText:SetTextColor(Notes_ColorLocked[1],Notes_ColorLocked[2],Notes_ColorLocked[3])
1016 VincentSDSH-33016
                                        else
1017 VincentSDSH-33016
                                                NotesPrevPageButton:Enable()
1018 VincentSDSH-33016
                                                NotesNextPageButton:Enable()
1019 VincentSDSH-33016
                                                NotesPrevPageButtonText:SetTextColor(Notes_ColorNormal[1],Notes_ColorNormal[2],Notes_ColorNormal[3])
1020 VincentSDSH-33016
                                                NotesNextPageButtonText:SetTextColor(Notes_ColorNormal[1],Notes_ColorNormal[2],Notes_ColorNormal[3])
1021 VincentSDSH-33016
                                        end
1022 VincentSDSH-33016
                                else
1023 VincentSDSH-33016
                                        Notes_BookUIToggle("hide")
1024 VincentSDSH-33016
                                        NotesCompileButton:SetText("Compile")
1025 VincentSDSH-33016
                                end
1026 VincentSDSH-33016
                        end
1027 VincentSDSH-33016
 
1028 VincentSDSH-33016
                        if notecount > 0 then NotesDuplicateButton:Enable()
1029 VincentSDSH-33016
                        else NotesDuplicateButton:Disable() end
1030 VincentSDSH-33016
 
1031 VincentSDSH-33016
                        local synccolor = Notes_ColorSync
1032 VincentSDSH-33016
                        local synclockcolor = Notes_ColorSyncLocked
1033 VincentSDSH-33016
                        if type(Notes_Notes[Notes_Selected]["book"]) == "table" then
1034 VincentSDSH-33016
                                synccolor = Notes_ColorBookSync
1035 VincentSDSH-33016
                                synclockcolor = Notes_ColorBookSyncLocked
1036 VincentSDSH-33016
                        end
1037 VincentSDSH-33016
 
1038 VincentSDSH-33016
                        if notecount > 0 then NotesDuplicateButton:Enable() end
1039 VincentSDSH-33016
 
1040 VincentSDSH-33016
                        if unlockcount == 0 or booklock then
1041 VincentSDSH-33016
                                NotesSyncCheckButtonText:SetTextColor(synclockcolor[1],synclockcolor[2],synclockcolor[3])
1042 VincentSDSH-33016
                                NotesDeleteButton:Disable()
1043 VincentSDSH-33016
                                if booklock then
1044 VincentSDSH-33016
                                        NotesLockedCheckButton:SetChecked(1)
1045 VincentSDSH-33016
                                        NotesLockedCheckButton:Disable()
1046 VincentSDSH-33016
                                        NotesLockedCheckButtonText:SetText("Book Locked")
1047 VincentSDSH-33016
                                        NotesLockedCheckButtonText:SetTextColor(Notes_ColorLocked[1],Notes_ColorLocked[2],Notes_ColorLocked[3])
1048 VincentSDSH-33016
                                end
1049 VincentSDSH-33016
                                if not Notes_Notes[Notes_Selected]["sync"] and booksync then
1050 VincentSDSH-33016
                                        NotesSyncCheckButtonText:SetText("Book Broadcast Only")
1051 VincentSDSH-33016
                                else
1052 VincentSDSH-33016
                                        NotesSyncCheckButtonText:SetText("Broadcast Only")
1053 VincentSDSH-33016
                                end
1054 VincentSDSH-33016
                        else
1055 VincentSDSH-33016
                                NotesSyncCheckButton:Enable()
1056 VincentSDSH-33016
                                NotesSyncCheckButtonText:SetTextColor(synccolor[1],synccolor[2],synccolor[3])
1057 VincentSDSH-33016
                                NotesDeleteButton:Enable()
1058 VincentSDSH-33016
                        end
1059 VincentSDSH-33016
 
1060 VincentSDSH-33016
                        if Notes_CommModes[Notes_SelectedComm][3]() then NotesCommSendButton:Enable()
1061 VincentSDSH-33016
                        else NotesCommSendButton:Disable() end
1062 VincentSDSH-33016
                end
1063 VincentSDSH-33016
        else
1064 VincentSDSH-33016
                NotesCompileButton:Disable()
1065 VincentSDSH-33016
                NotesDeleteButton:Disable()
1066 VincentSDSH-33016
                NotesDuplicateButton:Disable()
1067 VincentSDSH-33016
                NotesExecuteButton:Disable()
1068 VincentSDSH-33016
                NotesMacroEditBox:SetText("")
1069 VincentSDSH-33016
                NotesMacroEditBox:Hide()
1070 VincentSDSH-33016
                NotesPrintMacroEditBox:SetText("")
1071 VincentSDSH-33016
                NotesPrintMacroEditBox:Hide()
1072 VincentSDSH-33016
                NotesSyncCheckButton:Disable()
1073 VincentSDSH-33016
                NotesSyncCheckButton:SetChecked(false)
1074 VincentSDSH-33016
                NotesSyncCheckButtonText:SetTextColor(Notes_ColorLocked[1],Notes_ColorLocked[2],Notes_ColorLocked[3])
1075 VincentSDSH-33016
                NotesLockedCheckButton:Disable()
1076 VincentSDSH-33016
                NotesLockedCheckButton:SetChecked(false)
1077 VincentSDSH-33016
                NotesLockedCheckButtonText:SetTextColor(Notes_ColorLocked[1],Notes_ColorLocked[2],Notes_ColorLocked[3])
1078 VincentSDSH-33016
                NotesCommSendButton:Disable()
1079 VincentSDSH-33016
                NotesTOC:Hide()
1080 VincentSDSH-33016
                NotesText:Show()
1081 VincentSDSH-33016
                Notes_BookUIToggle("hide")
1082 VincentSDSH-33016
        end
1083 VincentSDSH-33016
 
1084 VincentSDSH-33016
        if getn(Notes_PrintCache) > 0 then NotesStopPrintButton:Enable()
1085 VincentSDSH-33016
        else NotesStopPrintButton:Disable() end
1086 VincentSDSH-33016
 
1087 VincentSDSH-33016
        if Notes_LoadID and Notes_Undo[Notes_LoadID] and Notes_Undo[Notes_LoadID]["undo"] == true and
1088 VincentSDSH-33016
           Notes_Selected and Notes_Notes[Notes_Selected] and not Notes_Notes[Notes_Selected]["locked"] then
1089 VincentSDSH-33016
                NotesUndoButton:Enable()
1090 VincentSDSH-33016
        else NotesUndoButton:Disable()end
1091 VincentSDSH-33016
 
1092 VincentSDSH-33016
        if fullupdate then
1093 VincentSDSH-33016
                if Notes_CommMode then
1094 VincentSDSH-33016
                        NotesCommButton:SetNormalTexture("Interface/ChatFrame/UI-ChatIcon-Chat-Down")
1095 VincentSDSH-33016
                        ShowUIPanel(NotesCommFrame)
1096 VincentSDSH-33016
 
1097 VincentSDSH-33016
                        NotesLuaFrame:ClearAllPoints()
1098 VincentSDSH-33016
                        NotesLuaFrame:SetPoint("TOP",NotesCommFrame,"BOTTOM",0,4)
1099 VincentSDSH-33016
 
1100 VincentSDSH-33016
                        UIDropDownMenu_SetSelectedValue(NotesCommDropDown, Notes_SelectedComm)
1101 VincentSDSH-33016
                        UIDropDownMenu_SetSelectedValue(NotesChanSelectDropDown, Notes_SelectedChan)
1102 VincentSDSH-33016
                        if Notes_CommModes[Notes_SelectedComm][1] == "Whisper" then
1103 VincentSDSH-33016
                                NotesWhisperEditBox:Show()
1104 VincentSDSH-33016
                        else
1105 VincentSDSH-33016
                                NotesWhisperEditBox:Hide()
1106 VincentSDSH-33016
                        end
1107 VincentSDSH-33016
 
1108 VincentSDSH-33016
                        if Notes_CommModes[Notes_SelectedComm][1] == "Channel" then
1109 VincentSDSH-33016
                                UIDropDownMenu_Initialize(NotesChanSelectDropDown, Notes_ChanSelectDropDownInitialize)
1110 VincentSDSH-33016
                                UIDropDownMenu_SetSelectedValue(NotesChanSelectDropDown, Notes_SelectedChan)
1111 VincentSDSH-33016
                                NotesChanSelectDropDown:Show()
1112 VincentSDSH-33016
                        else
1113 VincentSDSH-33016
                                NotesChanSelectDropDown:Hide()
1114 VincentSDSH-33016
                        end
1115 VincentSDSH-33016
 
1116 VincentSDSH-33016
                        if Notes_CommSpeedMode then
1117 VincentSDSH-33016
                                NotesCommSpeedCheckButton:SetChecked(1)
1118 VincentSDSH-33016
                                NotesCommFrame:SetHeight(70)
1119 VincentSDSH-33016
                                NotesCommSpeedSlider:Show()
1120 VincentSDSH-33016
                                NotesCommSpeedSlider:SetValue(Notes_PrintMaxInterval)
1121 VincentSDSH-33016
 
1122 VincentSDSH-33016
                                if Notes_PrintMaxInterval == 0 then
1123 VincentSDSH-33016
                                        NotesCommSpeedLabel:SetText("Max Delay: [Off]")
1124 VincentSDSH-33016
                                elseif Notes_PrintMaxInterval == 5 then
1125 VincentSDSH-33016
                                        NotesCommSpeedLabel:SetText("Max Delay: [Very Short]")
1126 VincentSDSH-33016
                                elseif Notes_PrintMaxInterval == 10 then
1127 VincentSDSH-33016
                                        NotesCommSpeedLabel:SetText("Max Delay: [Short]")
1128 VincentSDSH-33016
                                elseif Notes_PrintMaxInterval == 15 then
1129 VincentSDSH-33016
                                        NotesCommSpeedLabel:SetText("Max Delay: [Medium]")
1130 VincentSDSH-33016
                                elseif Notes_PrintMaxInterval == 20 then
1131 VincentSDSH-33016
                                        NotesCommSpeedLabel:SetText("Max Delay: [Long]")
1132 VincentSDSH-33016
                                elseif Notes_PrintMaxInterval == 25 then
1133 VincentSDSH-33016
                                        NotesCommSpeedLabel:SetText("Max Delay: [Very Long]")
1134 VincentSDSH-33016
                                end
1135 VincentSDSH-33016
                        else
1136 VincentSDSH-33016
                                NotesCommSpeedCheckButton:SetChecked(0)
1137 VincentSDSH-33016
                                NotesCommFrame:SetHeight(50)
1138 VincentSDSH-33016
                                NotesCommSpeedSlider:Hide()
1139 VincentSDSH-33016
                        end
1140 VincentSDSH-33016
                else
1141 VincentSDSH-33016
                        NotesCommButton:SetNormalTexture("Interface/ChatFrame/UI-ChatIcon-Chat-Up")
1142 VincentSDSH-33016
                        HideUIPanel(NotesCommFrame)
1143 VincentSDSH-33016
 
1144 VincentSDSH-33016
                        NotesLuaFrame:ClearAllPoints()
1145 VincentSDSH-33016
                        NotesLuaFrame:SetPoint("TOP",NotesCommFrame,"TOP",0,0)
1146 VincentSDSH-33016
                end
1147 VincentSDSH-33016
        end
1148 VincentSDSH-33016
 
1149 VincentSDSH-33016
        if Notes_CommMode then
1150 VincentSDSH-33016
                if Notes_Selected then
1151 VincentSDSH-33016
                        local target = Notes_CommModes[Notes_SelectedComm][5]()
1152 VincentSDSH-33016
                        local str = "/PrintNote "..Notes_Notes[Notes_Selected]["id"]
1153 VincentSDSH-33016
                        if target then str = str.." "..target end
1154 VincentSDSH-33016
                        NotesPrintMacroEditBox:SetText(str)
1155 VincentSDSH-33016
                        NotesPrintMacroEditBox:Show()
1156 VincentSDSH-33016
                end
1157 VincentSDSH-33016
        end
1158 VincentSDSH-33016
 
1159 VincentSDSH-33016
        if Notes_LUAMode then
1160 VincentSDSH-33016
                NotesLUACheckButton:SetChecked(1)
1161 VincentSDSH-33016
                ShowUIPanel(NotesLuaFrame)
1162 VincentSDSH-33016
 
1163 VincentSDSH-33016
                if Notes_GetNoteIndex("1") then NotesLUASetupButton:Disable()
1164 VincentSDSH-33016
                else NotesLUASetupButton:Enable() end
1165 VincentSDSH-33016
 
1166 VincentSDSH-33016
 
1167 VincentSDSH-33016
 
1168 VincentSDSH-33016
                if Notes_Selected then
1169 VincentSDSH-33016
                        NotesMacroEditBox:SetText("/RunNote "..Notes_Notes[Notes_Selected]["id"])
1170 VincentSDSH-33016
                        NotesMacroEditBox:Show()
1171 VincentSDSH-33016
                end
1172 VincentSDSH-33016
        else
1173 VincentSDSH-33016
                NotesLUACheckButton:SetChecked(nil)
1174 VincentSDSH-33016
                HideUIPanel(NotesLuaFrame)
1175 VincentSDSH-33016
        end
1176 VincentSDSH-33016
 
1177 VincentSDSH-33016
        if getglobal("NotesExportFrame") then
1178 VincentSDSH-33016
                if Notes_LUAMode then
1179 VincentSDSH-33016
                        NotesExportFrame:ClearAllPoints()
1180 VincentSDSH-33016
                        NotesExportFrame:SetPoint("TOP",NotesLuaFrame,"BOTTOM",0,4)
1181 VincentSDSH-33016
                else
1182 VincentSDSH-33016
                        NotesExportFrame:ClearAllPoints()
1183 VincentSDSH-33016
                        NotesExportFrame:SetPoint("TOP",NotesLuaFrame,"TOP",0,0)
1184 VincentSDSH-33016
                end
1185 VincentSDSH-33016
 
1186 VincentSDSH-33016
                if Notes_ExportMode then
1187 VincentSDSH-33016
                        NotesExportCheckButton:SetChecked(1)
1188 VincentSDSH-33016
                        ShowUIPanel(NotesExportFrame)
1189 VincentSDSH-33016
 
1190 VincentSDSH-33016
                        NotesImportButton:SetText("Import ["..getn(Notes_Import).."] Notes")
1191 VincentSDSH-33016
                        if getn(Notes_Import) == 0 then NotesImportButton:Disable()
1192 VincentSDSH-33016
                        else NotesImportButton:Enable() end
1193 VincentSDSH-33016
 
1194 VincentSDSH-33016
                        if Notes_Selected then NotesExportButton:Enable()
1195 VincentSDSH-33016
                        else NotesExportButton:Disable() end
1196 VincentSDSH-33016
                else
1197 VincentSDSH-33016
                        NotesExportCheckButton:SetChecked(nil)
1198 VincentSDSH-33016
                        NotesExportFrame:Hide()
1199 VincentSDSH-33016
                        HideUIPanel(NotesExportFrame)
1200 VincentSDSH-33016
                end
1201 VincentSDSH-33016
        end
1202 VincentSDSH-33016
 
1203 VincentSDSH-33016
        if Notes_ShowIcon then
1204 VincentSDSH-33016
                NotesIconCheckButton:SetChecked(1)
1205 VincentSDSH-33016
                ShowUIPanel(NotesIconFrame)
1206 VincentSDSH-33016
        else
1207 VincentSDSH-33016
                NotesIconCheckButton:SetChecked(nil)
1208 VincentSDSH-33016
                HideUIPanel(NotesIconFrame)
1209 VincentSDSH-33016
        end
1210 VincentSDSH-33016
end
1211 VincentSDSH-33016
 
1212 VincentSDSH-33016
function Notes_ScrollBarUpdate(fullupdate)
1213 VincentSDSH-33016
        local line -- 1 through 5 of our window to scroll
1214 VincentSDSH-33016
        local lineplusoffset -- an index into our data calculated from the scroll offset
1215 VincentSDSH-33016
 
1216 VincentSDSH-33016
        FauxScrollFrame_Update(NotesNoteScrollBar,getn(Notes_Notes)-Notes_TotalPages,5,16)
1217 VincentSDSH-33016
        for line=1,5 do
1218 VincentSDSH-33016
                lineplusoffset = line + FauxScrollFrame_GetOffset(NotesNoteScrollBar)
1219 VincentSDSH-33016
                if lineplusoffset <= getn(Notes_Notes) then
1220 VincentSDSH-33016
                        local title = Notes_Notes[lineplusoffset]["title"]
1221 VincentSDSH-33016
                        local descr = ""
1222 VincentSDSH-33016
 
1223 VincentSDSH-33016
                        if type(Notes_Notes[lineplusoffset]["book"]) == "table" then
1224 VincentSDSH-33016
                                local pages = getn(Notes_Notes[lineplusoffset]["book"])
1225 VincentSDSH-33016
                                getglobal("NotesNote"..line.."_BookIcon"):Show()
1226 VincentSDSH-33016
                                getglobal("NotesNote"..line.."_BookIcon"):SetTexture("Interface/Icons/INV_Misc_Book_0"..(mod(Notes_Notes[lineplusoffset]["id"],8)+1))
1227 VincentSDSH-33016
                                title = "     "..title
1228 VincentSDSH-33016
                                descr = pages.." Page"
1229 VincentSDSH-33016
                                if pages ~= 1 then descr = descr.."s" end
1230 VincentSDSH-33016
                        else
1231 VincentSDSH-33016
                                getglobal("NotesNote"..line.."_BookIcon"):Hide()
1232 VincentSDSH-33016
                                descr = string.gsub(gsub(Notes_Notes[lineplusoffset]["text"],"\n"," "),"%s+"," ")
1233 VincentSDSH-33016
                                local olddescr = descr
1234 VincentSDSH-33016
                                if descr ~= nil then
1235 VincentSDSH-33016
                                        descr = strsub(descr,0,Notes_DescrLen)
1236 VincentSDSH-33016
                                        if strlen(olddescr) > Notes_DescrLen then
1237 VincentSDSH-33016
                                                descr = descr.."..."
1238 VincentSDSH-33016
                                        end
1239 VincentSDSH-33016
                                end
1240 VincentSDSH-33016
                        end
1241 VincentSDSH-33016
 
1242 VincentSDSH-33016
                        local oldtitle = title
1243 VincentSDSH-33016
                        if title ~= nil then
1244 VincentSDSH-33016
                                title = strsub(title,0,Notes_TitleLen)
1245 VincentSDSH-33016
                                if strlen(oldtitle) > Notes_TitleLen then
1246 VincentSDSH-33016
                                        title = title.."..."
1247 VincentSDSH-33016
                                end
1248 VincentSDSH-33016
                        end
1249 VincentSDSH-33016
 
1250 VincentSDSH-33016
                        if Notes_Selected == lineplusoffset then
1251 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetDesaturated(0)
1252 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetAlpha(1)
1253 VincentSDSH-33016
                        elseif getn(Notes_MultiSelect) > 0 and Notes_InTable(Notes_MultiSelect,lineplusoffset) then
1254 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetDesaturated(0)
1255 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetAlpha(.4)
1256 VincentSDSH-33016
                        elseif Notes_BookID and Notes_GetNoteIndex(Notes_BookID) == lineplusoffset then
1257 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetDesaturated(1)
1258 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetAlpha(1)
1259 VincentSDSH-33016
                        else
1260 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetDesaturated(0)
1261 VincentSDSH-33016
                                getglobal("NotesNote"..line.."NTex"):SetAlpha(0)
1262 VincentSDSH-33016
                        end
1263 VincentSDSH-33016
 
1264 VincentSDSH-33016
                        if type(Notes_Notes[lineplusoffset]["book"]) == "string" then
1265 VincentSDSH-33016
                                getglobal("NotesNote"..line):Hide()
1266 VincentSDSH-33016
                        else
1267 VincentSDSH-33016
                                local textcolor = Notes_GetColor(lineplusoffset)
1268 VincentSDSH-33016
 
1269 VincentSDSH-33016
                                getglobal("NotesNote"..line.."_Text"):SetTextColor(textcolor[1],textcolor[2],textcolor[3])
1270 VincentSDSH-33016
                                getglobal("NotesNote"..line.."_Text"):SetText(title)
1271 VincentSDSH-33016
                                getglobal("NotesNote"..line.."_Description"):SetText(descr)
1272 VincentSDSH-33016
                                getglobal("NotesNote"..line):Show()
1273 VincentSDSH-33016
                        end
1274 VincentSDSH-33016
                else
1275 VincentSDSH-33016
                        getglobal("NotesNote"..line):Hide()
1276 VincentSDSH-33016
                end
1277 VincentSDSH-33016
        end
1278 VincentSDSH-33016
        Notes_SetButtonState(fullupdate)
1279 VincentSDSH-33016
end
1280 VincentSDSH-33016
 
1281 VincentSDSH-33016
function Notes_GetColor(index)
1282 VincentSDSH-33016
        if type(index) == "string" then
1283 VincentSDSH-33016
                local num = index
1284 VincentSDSH-33016
                if getglobal(index) then
1285 VincentSDSH-33016
                        num = tonumber(strsub(index,-1))
1286 VincentSDSH-33016
                        index = num + FauxScrollFrame_GetOffset(NotesNoteScrollBar)
1287 VincentSDSH-33016
                end
1288 VincentSDSH-33016
        end
1289 VincentSDSH-33016
 
1290 VincentSDSH-33016
        local color = Notes_ColorNormal
1291 VincentSDSH-33016
        if Notes_Notes[index] then
1292 VincentSDSH-33016
                if Notes_Notes[index]["sync"] then
1293 VincentSDSH-33016
                        color = Notes_ColorSync
1294 VincentSDSH-33016
                end
1295 VincentSDSH-33016
                if Notes_Notes[index]["locked"] then
1296 VincentSDSH-33016
                        color = Notes_ColorLocked
1297 VincentSDSH-33016
                end
1298 VincentSDSH-33016
                if Notes_Notes[index]["sync"] and Notes_Notes[index]["locked"] then
1299 VincentSDSH-33016
                        color = Notes_ColorSyncLocked
1300 VincentSDSH-33016
                end
1301 VincentSDSH-33016
 
1302 VincentSDSH-33016
                if type(Notes_Notes[index]["book"]) == "table" then
1303 VincentSDSH-33016
                        color = Notes_ColorBook
1304 VincentSDSH-33016
                        if Notes_Notes[index]["sync"] then
1305 VincentSDSH-33016
                                color = Notes_ColorBookSync
1306 VincentSDSH-33016
                        end
1307 VincentSDSH-33016
                        if Notes_Notes[index]["locked"] then
1308 VincentSDSH-33016
                                color = Notes_ColorBookLocked
1309 VincentSDSH-33016
                        end
1310 VincentSDSH-33016
                        if Notes_Notes[index]["sync"] and Notes_Notes[index]["locked"] then
1311 VincentSDSH-33016
                                color = Notes_ColorBookSyncLocked
1312 VincentSDSH-33016
                        end
1313 VincentSDSH-33016
                end
1314 VincentSDSH-33016
 
1315 VincentSDSH-33016
                if type(Notes_Notes[index]["book"]) == "string" then
1316 VincentSDSH-33016
                        color = Notes_ColorLocked
1317 VincentSDSH-33016
                end
1318 VincentSDSH-33016
        end
1319 VincentSDSH-33016
        return color
1320 VincentSDSH-33016
end
1321 VincentSDSH-33016
 
1322 VincentSDSH-33016
------------------------------------------
1323 VincentSDSH-33016
-- F) UI Functions
1324 VincentSDSH-33016
--[[
1325 VincentSDSH-33016
Notes_OnLoad - Register Notes with the system
1326 VincentSDSH-33016
Notes_OnUpdate - This function's body is defined dynamically
1327 VincentSDSH-33016
Notes_OnEvent - This function's body is defined dynamically
1328 VincentSDSH-33016
Notes_UIToggle - Hide or show Notes
1329 VincentSDSH-33016
Notes_HideNotes - Clear the selection when Notes is hidden
1330 VincentSDSH-33016
Notes_BookUIToggle - Hide or show the book navigation panel
1331 VincentSDSH-33016
Notes_CommUIToggle - Hide or show the communications panel
1332 VincentSDSH-33016
Notes_LUAUIToggle - Hide or show the LUA panel
1333 VincentSDSH-33016
Notes_IconDragging - Drag the minimap button
1334 VincentSDSH-33016
]]--
1335 VincentSDSH-33016
 
1336 VincentSDSH-33016
function Notes_OnLoad()
1337 VincentSDSH-33016
        SlashCmdList["NOTES"] = Notes_UIToggle
1338 VincentSDSH-33016
        SLASH_NOTES1 = "/notes"
1339 VincentSDSH-33016
        SLASH_NOTES2 = "/note"
1340 VincentSDSH-33016
 
1341 VincentSDSH-33016
        SlashCmdList["RUNNOTES"] = Notes_RunNote
1342 VincentSDSH-33016
        SLASH_RUNNOTES1 = "/runnotes"
1343 VincentSDSH-33016
        SLASH_RUNNOTES2 = "/runnote"
1344 VincentSDSH-33016
 
1345 VincentSDSH-33016
        SlashCmdList["PRINTNOTES"] = Notes_PrintNote
1346 VincentSDSH-33016
        SLASH_PRINTNOTES1 = "/printnotes"
1347 VincentSDSH-33016
        SLASH_PRINTNOTES2 = "/printnote"
1348 VincentSDSH-33016
        SLASH_PRINTNOTES3 = "/print"
1349 VincentSDSH-33016
 
1350 VincentSDSH-33016
        SlashCmdList["STOPNOTES"] = Notes_StopPrinting
1351 VincentSDSH-33016
        SLASH_STOPNOTES1 = "/stopnotes"
1352 VincentSDSH-33016
        SLASH_STOPNOTES2 = "/stopnote"
1353 VincentSDSH-33016
        SLASH_STOPNOTES3 = "/stop"
1354 VincentSDSH-33016
 
1355 VincentSDSH-33016
        SlashCmdList["NOTESICONTOGGLE"] = Notes_IconToggle
1356 VincentSDSH-33016
        SLASH_NOTESICONTOGGLE1 = "/notesicon"
1357 VincentSDSH-33016
 
1358 VincentSDSH-33016
        SlashCmdList["NOTESDEBUG"] = Notes_Debug
1359 VincentSDSH-33016
        SLASH_NOTESDEBUG1 = "/notesdebug"
1360 VincentSDSH-33016
 
1361 VincentSDSH-33016
        NotesEvents:RegisterEvent('VARIABLES_LOADED')
1362 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE')
1363 VincentSDSH-33016
        NotesEvents:RegisterEvent('RAID_ROSTER_UPDATE')
1364 VincentSDSH-33016
        NotesEvents:RegisterEvent('PLAYER_TARGET_CHANGED')
1365 VincentSDSH-33016
 
1366 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_ADDON')
1367 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_RAID')
1368 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_RAID_LEADER')
1369 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_PARTY')
1370 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_GUILD')
1371 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_WHISPER')
1372 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_CHANNEL')
1373 VincentSDSH-33016
        NotesEvents:RegisterEvent('CHAT_MSG_CHANNEL_LEAVE')
1374 VincentSDSH-33016
 
1375 VincentSDSH-33016
        Notes_Import = Notes_Export
1376 VincentSDSH-33016
end
1377 VincentSDSH-33016
 
1378 VincentSDSH-33016
function Notes_OnUpdate()
1379 VincentSDSH-33016
-- This function's body is defined dynamically
1380 VincentSDSH-33016
end
1381 VincentSDSH-33016
 
1382 VincentSDSH-33016
function Notes_OnEvent()
1383 VincentSDSH-33016
-- This function's body is defined dynamically
1384 VincentSDSH-33016
end
1385 VincentSDSH-33016
 
1386 VincentSDSH-33016
function Notes_Debug()
1387 VincentSDSH-33016
        RunScript("Notes_OnEvent = function() if arg1 == 'Notes' then Notes_Print(arg2) end end Notes_WarningPrint('Now printing sync debug info')")
1388 VincentSDSH-33016
end
1389 VincentSDSH-33016
 
1390 VincentSDSH-33016
function Notes_UIToggle(mode)
1391 VincentSDSH-33016
        if mode==nil or mode=="" then mode = "toggle" end
1392 VincentSDSH-33016
 
1393 VincentSDSH-33016
        if mode == "hide" or (mode=="toggle" and NotesFrame:IsVisible()) then
1394 VincentSDSH-33016
                Notes_HideNotes()
1395 VincentSDSH-33016
 
1396 VincentSDSH-33016
        elseif mode == "show" or mode=="toggle" then
1397 VincentSDSH-33016
                ShowUIPanel(NotesFrame)
1398 VincentSDSH-33016
                Notes_SetButtonState(1)
1399 VincentSDSH-33016
        end
1400 VincentSDSH-33016
end
1401 VincentSDSH-33016
 
1402 VincentSDSH-33016
function Notes_HideNotes()
1403 VincentSDSH-33016
        Notes_LoadEmpty()
1404 VincentSDSH-33016
        NotesFrame:Hide()
1405 VincentSDSH-33016
end
1406 VincentSDSH-33016
 
1407 VincentSDSH-33016
function Notes_BookUIToggle(mode)
1408 VincentSDSH-33016
        if mode==nil or mode=="" then mode = "toggle" end
1409 VincentSDSH-33016
 
1410 VincentSDSH-33016
        if mode == "hide" or (mode=="toggle" and NotesBookFrame:IsVisible()) then
1411 VincentSDSH-33016
                NotesBookFrame:Hide()
1412 VincentSDSH-33016
 
1413 VincentSDSH-33016
                NotesCommFrame:ClearAllPoints()
1414 VincentSDSH-33016
                NotesCommFrame:SetPoint("TOP",NotesBookFrame,"TOP",0,0)
1415 VincentSDSH-33016
 
1416 VincentSDSH-33016
        elseif mode == "show" or mode=="toggle" then
1417 VincentSDSH-33016
                NotesBookFrame:Show()
1418 VincentSDSH-33016
 
1419 VincentSDSH-33016
                NotesCommFrame:ClearAllPoints()
1420 VincentSDSH-33016
                NotesCommFrame:SetPoint("TOP",NotesBookFrame,"BOTTOM",0,4)
1421 VincentSDSH-33016
        end
1422 VincentSDSH-33016
end
1423 VincentSDSH-33016
 
1424 VincentSDSH-33016
function Notes_CommUIToggle(mode)
1425 VincentSDSH-33016
        if mode==nil or mode=="" then mode = "toggle" end
1426 VincentSDSH-33016
 
1427 VincentSDSH-33016
        if mode == "hide" or (mode=="toggle" and NotesCommFrame:IsVisible()) then
1428 VincentSDSH-33016
                Notes_CommMode = false
1429 VincentSDSH-33016
                Notes_SetButtonState(1)
1430 VincentSDSH-33016
 
1431 VincentSDSH-33016
                NotesLuaFrame:ClearAllPoints()
1432 VincentSDSH-33016
                NotesLuaFrame:SetPoint("TOP",NotesCommFrame,"TOP",0,0)
1433 VincentSDSH-33016
 
1434 VincentSDSH-33016
        elseif mode == "show" or mode=="toggle" then
1435 VincentSDSH-33016
                Notes_CommMode = true
1436 VincentSDSH-33016
                Notes_SetButtonState(1)
1437 VincentSDSH-33016
 
1438 VincentSDSH-33016
                NotesLuaFrame:ClearAllPoints()
1439 VincentSDSH-33016
                NotesLuaFrame:SetPoint("TOP",NotesCommFrame,"BOTTOM",0,4)
1440 VincentSDSH-33016
        end
1441 VincentSDSH-33016
end
1442 VincentSDSH-33016
 
1443 VincentSDSH-33016
function Notes_CommSpeedUIToggle(mode)
1444 VincentSDSH-33016
        if mode==nil or mode=="" then mode = "toggle" end
1445 VincentSDSH-33016
 
1446 VincentSDSH-33016
        if mode == "hide" or (mode=="toggle" and Notes_CommSpeedMode == true) then
1447 VincentSDSH-33016
                Notes_CommSpeedMode = false
1448 VincentSDSH-33016
                Notes_SetButtonState(1)
1449 VincentSDSH-33016
 
1450 VincentSDSH-33016
        elseif mode == "show" or mode=="toggle" then
1451 VincentSDSH-33016
                Notes_CommSpeedMode = true
1452 VincentSDSH-33016
                Notes_SetButtonState(1)
1453 VincentSDSH-33016
        end
1454 VincentSDSH-33016
end
1455 VincentSDSH-33016
 
1456 VincentSDSH-33016
 
1457 VincentSDSH-33016
function Notes_LUAUIToggle(mode)
1458 VincentSDSH-33016
        if mode==nil or mode=="" then mode = "toggle" end
1459 VincentSDSH-33016
 
1460 VincentSDSH-33016
        if mode == "hide" or (mode=="toggle" and NotesLuaFrame:IsVisible()) then
1461 VincentSDSH-33016
                Notes_LUAMode = false
1462 VincentSDSH-33016
                Notes_SetButtonState()
1463 VincentSDSH-33016
 
1464 VincentSDSH-33016
                if getglobal("NotesExportFrame") then
1465 VincentSDSH-33016
                        NotesExportFrame:ClearAllPoints()
1466 VincentSDSH-33016
                        NotesExportFrame:SetPoint("TOP",NotesLuaFrame,"TOP",0,0)
1467 VincentSDSH-33016
                end
1468 VincentSDSH-33016
 
1469 VincentSDSH-33016
        elseif mode == "show" or mode=="toggle" then
1470 VincentSDSH-33016
                Notes_LUAMode = true
1471 VincentSDSH-33016
                Notes_SetButtonState()
1472 VincentSDSH-33016
 
1473 VincentSDSH-33016
                if getglobal("NotesExportFrame") then
1474 VincentSDSH-33016
                        NotesExportFrame:ClearAllPoints()
1475 VincentSDSH-33016
                        NotesExportFrame:SetPoint("TOP",NotesLuaFrame,"BOTTOM",0,4)
1476 VincentSDSH-33016
                end
1477 VincentSDSH-33016
        end
1478 VincentSDSH-33016
end
1479 VincentSDSH-33016
 
1480 VincentSDSH-33016
function Notes_IconToggle(mode)
1481 VincentSDSH-33016
        if mode==nil or mode=="" then mode = "toggle" end
1482 VincentSDSH-33016
 
1483 VincentSDSH-33016
        if mode == "hide" or (mode=="toggle" and NotesIconFrame:IsVisible()) then
1484 VincentSDSH-33016
                Notes_ShowIcon = false
1485 VincentSDSH-33016
                Notes_SetButtonState()
1486 VincentSDSH-33016
 
1487 VincentSDSH-33016
        elseif mode == "show" or mode=="toggle" then
1488 VincentSDSH-33016
                Notes_ShowIcon = true
1489 VincentSDSH-33016
                Notes_SetButtonState()
1490 VincentSDSH-33016
        end
1491 VincentSDSH-33016
end
1492 VincentSDSH-33016
 
1493 VincentSDSH-33016
function Notes_IconMove(iconpos)
1494 VincentSDSH-33016
        if not Notes_IconDrag and not iconpos then return end
1495 VincentSDSH-33016
 
1496 VincentSDSH-33016
        local xpos,ypos
1497 VincentSDSH-33016
        if iconpos then
1498 VincentSDSH-33016
                xpos = iconpos[1]
1499 VincentSDSH-33016
                ypos = iconpos[2]
1500 VincentSDSH-33016
        end
1501 VincentSDSH-33016
 
1502 VincentSDSH-33016
        if not xpos and not ypos then
1503 VincentSDSH-33016
                xpos,ypos = GetCursorPosition()
1504 VincentSDSH-33016
                local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()
1505 VincentSDSH-33016
 
1506 VincentSDSH-33016
                xpos = xmin-xpos/Minimap:GetEffectiveScale()+70
1507 VincentSDSH-33016
                ypos = ypos/Minimap:GetEffectiveScale()-ymin-70
1508 VincentSDSH-33016
 
1509 VincentSDSH-33016
                local angle = math.deg(math.atan2(ypos,xpos)) or 0
1510 VincentSDSH-33016
 
1511 VincentSDSH-33016
                xpos = 80*cos(angle)
1512 VincentSDSH-33016
                ypos = 80*sin(angle)
1513 VincentSDSH-33016
 
1514 VincentSDSH-33016
                Notes_IconPos = {xpos,ypos}
1515 VincentSDSH-33016
        end
1516 VincentSDSH-33016
 
1517 VincentSDSH-33016
        NotesIconFrame:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-xpos,ypos-52)
1518 VincentSDSH-33016
end
1519 VincentSDSH-33016
 
1520 VincentSDSH-33016
------------------------------------------
1521 VincentSDSH-33016
-- G) Sync Functions
1522 VincentSDSH-33016
--[[
1523 VincentSDSH-33016
Notes_PrintNote - Wrapper for Notes_PrintSelected to be called from the command line
1524 VincentSDSH-33016
Notes_PrintSelected - Load a note into the print cache for later parsing
1525 VincentSDSH-33016
Notes_AddToCache - Add a message chunk in to the print cache
1526 VincentSDSH-33016
Notes_SendNote - Do the actual printing of a message chunk
1527 VincentSDSH-33016
Notes_StopPrinting - Clear the current print cache and notify other clients to stop syncing
1528 VincentSDSH-33016
Notes_ParseCache - Stagger printing from the messages in the print cache
1529 VincentSDSH-33016
Notes_ListenEvent - Listen to raid chat for synchronizing notes
1530 VincentSDSH-33016
Notes_InitChannelList - Initialize the list of channels for syncing
1531 VincentSDSH-33016
]]--
1532 VincentSDSH-33016
 
1533 VincentSDSH-33016
function Notes_PrintNote(cmd)
1534 VincentSDSH-33016
        local args = Notes_Split(cmd," ")
1535 VincentSDSH-33016
        local idx = Notes_GetNoteIndex(tostring(args[1]))
1536 VincentSDSH-33016
 
1537 VincentSDSH-33016
        if not args[2] then args[2] = "Self" end
1538 VincentSDSH-33016
 
1539 VincentSDSH-33016
        if idx ~= nil then Notes_PrintSelected(idx,nil,args[2]) else
1540 VincentSDSH-33016
        Notes_ErrorPrint("Note ID ["..args[1].."] not found") end
1541 VincentSDSH-33016
end
1542 VincentSDSH-33016
 
1543 VincentSDSH-33016
function Notes_PrintSelected(idx,midx,chatmethod)
1544 VincentSDSH-33016
        local index = Notes_Selected
1545 VincentSDSH-33016
        local mindex = Notes_MultiSelect
1546 VincentSDSH-33016
        local method = Notes_SelectedComm
1547 VincentSDSH-33016
        if idx then index = idx end
1548 VincentSDSH-33016
        if midx then mindex = midx end
1549 VincentSDSH-33016
        if chatmethod then method = chatmethod end
1550 VincentSDSH-33016
 
1551 VincentSDSH-33016
        if not index or not Notes_Notes[index] then return end
1552 VincentSDSH-33016
 
1553 VincentSDSH-33016
        local selectstack = {}
1554 VincentSDSH-33016
        local printstack = {}
1555 VincentSDSH-33016
 
1556 VincentSDSH-33016
        table.insert(selectstack,index)
1557 VincentSDSH-33016
        if getn(mindex) > 0 then
1558 VincentSDSH-33016
                for i=1,getn(mindex) do
1559 VincentSDSH-33016
                        table.insert(selectstack,mindex[i])
1560 VincentSDSH-33016
                end
1561 VincentSDSH-33016
        end
1562 VincentSDSH-33016
 
1563 VincentSDSH-33016
        for i=1,getn(selectstack) do
1564 VincentSDSH-33016
                if type(Notes_Notes[selectstack[i]]["book"])=="table" and getn(Notes_Notes[selectstack[i]]["book"]) > 0 then
1565 VincentSDSH-33016
 
1566 VincentSDSH-33016
                        table.insert(printstack,selectstack[i])
1567 VincentSDSH-33016
                        for j=1,getn(Notes_Notes[selectstack[i]]["book"]) do
1568 VincentSDSH-33016
                                local pageidx = Notes_GetNoteIndex(Notes_Notes[selectstack[i]]["book"][j])
1569 VincentSDSH-33016
                                if pageidx then table.insert(printstack,pageidx) end
1570 VincentSDSH-33016
                        end
1571 VincentSDSH-33016
 
1572 VincentSDSH-33016
                elseif type(Notes_Notes[selectstack[i]]["book"])=="string" then
1573 VincentSDSH-33016
                        table.insert(printstack,selectstack[i])
1574 VincentSDSH-33016
                else
1575 VincentSDSH-33016
                        table.insert(printstack,selectstack[i])
1576 VincentSDSH-33016
                end
1577 VincentSDSH-33016
        end
1578 VincentSDSH-33016
 
1579 VincentSDSH-33016
        local curbookid = "nil"
1580 VincentSDSH-33016
        local curbookidx = nil
1581 VincentSDSH-33016
        local booksync = false
1582 VincentSDSH-33016
        local bookpages = 0
1583 VincentSDSH-33016
        local bookpage = 0
1584 VincentSDSH-33016
 
1585 VincentSDSH-33016
        for k=1,getn(printstack) do
1586 VincentSDSH-33016
 
1587 VincentSDSH-33016
                if type(Notes_Notes[printstack[k]]["book"]) == "table" then
1588 VincentSDSH-33016
                        booksync = Notes_Notes[printstack[k]]["sync"]
1589 VincentSDSH-33016
                        curbooktitle = Notes_Notes[printstack[k]]["title"]
1590 VincentSDSH-33016
                        curbookid = Notes_Notes[printstack[k]]["id"]
1591 VincentSDSH-33016
                        curbookidx = printstack[k]
1592 VincentSDSH-33016
 
1593 VincentSDSH-33016
                        if booksync then
1594 VincentSDSH-33016
                                bookpage = 0
1595 VincentSDSH-33016
                                bookpages = getn(Notes_Notes[printstack[k]]["book"],",")
1596 VincentSDSH-33016
                        end
1597 VincentSDSH-33016
                else
1598 VincentSDSH-33016
                        local note = Notes_Notes[printstack[k]]["text"]
1599 VincentSDSH-33016
                        local title = Notes_Notes[printstack[k]]["title"]
1600 VincentSDSH-33016
                        local notelength = strlen(note)
1601 VincentSDSH-33016
 
1602 VincentSDSH-33016
                        local notebits = Notes_Split(note,"\n")
1603 VincentSDSH-33016
                        local startloc = getn(Notes_PrintCache)+1
1604 VincentSDSH-33016
                        local curbooksync = false
1605 VincentSDSH-33016
 
1606 VincentSDSH-33016
                        if type(Notes_Notes[printstack[k]]["book"]) == "string" then
1607 VincentSDSH-33016
                                curbookid = Notes_Notes[printstack[k]]["book"]
1608 VincentSDSH-33016
                                curbookidx = Notes_GetNoteIndex(Notes_Notes[printstack[k]]["book"])
1609 VincentSDSH-33016
                                curbooktitle = Notes_Notes[curbookidx]["title"]
1610 VincentSDSH-33016
                                curbooksync = Notes_Notes[curbookidx]["sync"]
1611 VincentSDSH-33016
                        else
1612 VincentSDSH-33016
                                curbookid = "nil"
1613 VincentSDSH-33016
                                curbookidx = nil
1614 VincentSDSH-33016
                                curbooktitle = nil
1615 VincentSDSH-33016
                                curbooksync = nil
1616 VincentSDSH-33016
                        end
1617 VincentSDSH-33016
 
1618 VincentSDSH-33016
                        local sync = Notes_Notes[printstack[k]]["sync"] or curbooksync
1619 VincentSDSH-33016
 
1620 VincentSDSH-33016
                        if sync then
1621 VincentSDSH-33016
                                Notes_AddToCache("<NOTE::"..title.."::"..Notes_Notes[printstack[k]]["id"].."::"..notelength.."::"..Notes_DataToString(curbookid).."::"..Notes_DataToString(curbooktitle),sync,nil,method,title)
1622 VincentSDSH-33016
                                if booksync then
1623 VincentSDSH-33016
                                        if Notes_InTable(Notes_Notes[curbookidx]["book"],Notes_Notes[printstack[k]]["id"]) then
1624 VincentSDSH-33016
                                                bookpage = bookpage + 1
1625 VincentSDSH-33016
                                        else
1626 VincentSDSH-33016
                                                Notes_ErrorPrint("Added the wrong page to the queue")
1627 VincentSDSH-33016
                                                Notes_StopPrinting()
1628 VincentSDSH-33016
                                        end
1629 VincentSDSH-33016
                                end
1630 VincentSDSH-33016
                        end
1631 VincentSDSH-33016
 
1632 VincentSDSH-33016
                        for i=1,getn(notebits) do
1633 VincentSDSH-33016
                                if notebits[i] == "" then
1634 VincentSDSH-33016
                                        notebits[i] = " "
1635 VincentSDSH-33016
                                        notelength = notelength + 1
1636 VincentSDSH-33016
                                        if sync then
1637 VincentSDSH-33016
                                                Notes_AddToCache("<NOTE::"..title.."::"..Notes_Notes[printstack[k]]["id"].."::"..notelength.."::"..Notes_DataToString(curbookid).."::"..Notes_DataToString(curbooktitle),sync,startloc,method,title)
1638 VincentSDSH-33016
                                        end
1639 VincentSDSH-33016
                                end
1640 VincentSDSH-33016
 
1641 VincentSDSH-33016
                                if strlen(notebits[i]) <= Notes_PrintMaxChunkLength then
1642 VincentSDSH-33016
                                        Notes_AddToCache(notebits[i],sync,nil,method,title)
1643 VincentSDSH-33016
                                else
1644 VincentSDSH-33016
                                        local notebitswords = Notes_Split(notebits[i]," ")
1645 VincentSDSH-33016
                                        local notebitsword = ""
1646 VincentSDSH-33016
 
1647 VincentSDSH-33016
                                        for j=1,getn(notebitswords) do
1648 VincentSDSH-33016
                                                local testword = notebitsword.." "..notebitswords[j]
1649 VincentSDSH-33016
                                                if strlen(testword) < Notes_PrintMaxChunkLength then
1650 VincentSDSH-33016
                                                        notebitsword = testword
1651 VincentSDSH-33016
                                                else
1652 VincentSDSH-33016
                                                        Notes_AddToCache(notebitsword,sync,nil,method,title)
1653 VincentSDSH-33016
                                                        notebitsword = notebitswords[j]
1654 VincentSDSH-33016
 
1655 VincentSDSH-33016
                                                        notelength = notelength + 1
1656 VincentSDSH-33016
 
1657 VincentSDSH-33016
                                                        if sync then
1658 VincentSDSH-33016
                                                                Notes_AddToCache("<NOTE::"..title.."::"..Notes_Notes[printstack[k]]["id"].."::"..notelength.."::"..Notes_DataToString(curbookid).."::"..Notes_DataToString(curbooktitle),sync,startloc,method,title)
1659 VincentSDSH-33016
                                                        end
1660 VincentSDSH-33016
                                                end
1661 VincentSDSH-33016
                                        end
1662 VincentSDSH-33016
                                        Notes_AddToCache(notebitsword,sync,nil,method,title)
1663 VincentSDSH-33016
                                end
1664 VincentSDSH-33016
                        end
1665 VincentSDSH-33016
 
1666 VincentSDSH-33016
                        if sync then
1667 VincentSDSH-33016
                                Notes_AddToCache("<NOTE::END",sync,nil,method,title)
1668 VincentSDSH-33016
                        end
1669 VincentSDSH-33016
 
1670 VincentSDSH-33016
                        if booksync then
1671 VincentSDSH-33016
                                if bookpage >= bookpages then
1672 VincentSDSH-33016
                                        curbookid = "nil"
1673 VincentSDSH-33016
                                        curbookidx = nil
1674 VincentSDSH-33016
                                        curbooktitle = nil
1675 VincentSDSH-33016
                                        booksync = false
1676 VincentSDSH-33016
                                        bookpages = 0
1677 VincentSDSH-33016
                                        bookpage = 0
1678 VincentSDSH-33016
                                end
1679 VincentSDSH-33016
                        end
1680 VincentSDSH-33016
                end
1681 VincentSDSH-33016
        end
1682 VincentSDSH-33016
        Notes_SetButtonState()
1683 VincentSDSH-33016
end
1684 VincentSDSH-33016
 
1685 VincentSDSH-33016
function Notes_AddToCache(msg,sync,loc,chatmethod,title)
1686 VincentSDSH-33016
        local method = Notes_SelectedComm
1687 VincentSDSH-33016
        if not sync then sync = false end
1688 VincentSDSH-33016
        if chatmethod then method = chatmethod end
1689 VincentSDSH-33016
 
1690 VincentSDSH-33016
        local target = nil
1691 VincentSDSH-33016
        if type(method) == "string" then
1692 VincentSDSH-33016
                for i=1,getn(Notes_CommModes) do
1693 VincentSDSH-33016
                        if strlower(Notes_CommModes[i][1]) == strlower(method) then
1694 VincentSDSH-33016
                                target = method
1695 VincentSDSH-33016
                                method = i
1696 VincentSDSH-33016
                                break
1697 VincentSDSH-33016
                        end
1698 VincentSDSH-33016
                end
1699 VincentSDSH-33016
                if type(method) == "string" then
1700 VincentSDSH-33016
                        target = method
1701 VincentSDSH-33016
                        local index = GetChannelName(method)
1702 VincentSDSH-33016
                        if index ~= nil and index ~= 0 then method = 10
1703 VincentSDSH-33016
                        else method = 9 end
1704 VincentSDSH-33016
                end
1705 VincentSDSH-33016
 
1706 VincentSDSH-33016
        else
1707 VincentSDSH-33016
                if Notes_CommModes[method][1] == "Target" then
1708 VincentSDSH-33016
                        target = UnitName("target")
1709 VincentSDSH-33016
                end
1710 VincentSDSH-33016
 
1711 VincentSDSH-33016
                if Notes_CommModes[method][1] == "Whisper" then
1712 VincentSDSH-33016
                        target = NotesWhisperEditBox:GetText()
1713 VincentSDSH-33016
                end
1714 VincentSDSH-33016
 
1715 VincentSDSH-33016
                if Notes_CommModes[method][1] == "Channel" then
1716 VincentSDSH-33016
                        target = Notes_ChanList[Notes_SelectedChan][2]
1717 VincentSDSH-33016
                end
1718 VincentSDSH-33016
        end
1719 VincentSDSH-33016
 
1720 VincentSDSH-33016
        if not Notes_CommModes[method][3]() then return end
1721 VincentSDSH-33016
 
1722 VincentSDSH-33016
        if not loc then
1723 VincentSDSH-33016
                table.insert(Notes_PrintCache,{msg,method,target,sync,title})
1724 VincentSDSH-33016
        else
1725 VincentSDSH-33016
                Notes_PrintCache[loc] = {msg,method,target,sync,title}
1726 VincentSDSH-33016
        end
1727 VincentSDSH-33016
end
1728 VincentSDSH-33016
 
1729 VincentSDSH-33016
function Notes_SendNote(msg,method,target)
1730 VincentSDSH-33016
        if not method then method = 7 end       -- DEFAULT TO SELF
1731 VincentSDSH-33016
 
1732 VincentSDSH-33016
        if strsub(msg,1,7) == "<NOTE::" then
1733 VincentSDSH-33016
                msg = msg.."::"..method.."::"..Notes_DataToString(target)..">"
1734 VincentSDSH-33016
 
1735 VincentSDSH-33016
                if Notes_InGuild() then
1736 VincentSDSH-33016
                        SendAddonMessage("Notes",msg,"GUILD")
1737 VincentSDSH-33016
                end
1738 VincentSDSH-33016
                if (Notes_CommModes[method][4] ~= "RAID" or Notes_CommModes[method][4] ~= "PARTY") or
1739 VincentSDSH-33016
                   (Notes_InParty() and not Notes_InRaid()) or (Notes_InRaid() and (IsRaidLeader() or IsRaidOfficer())) then
1740 VincentSDSH-33016
                        SendAddonMessage("Notes",msg,"RAID")
1741 VincentSDSH-33016
                end
1742 VincentSDSH-33016
                if (Notes_InBattlefield()) then
1743 VincentSDSH-33016
                        SendAddonMessage("Notes",msg,"BATTLEGROUND")
1744 VincentSDSH-33016
                end
1745 VincentSDSH-33016
        else
1746 VincentSDSH-33016
                Notes_CommModes[method][2](msg,target)
1747 VincentSDSH-33016
        end
1748 VincentSDSH-33016
end
1749 VincentSDSH-33016
 
1750 VincentSDSH-33016
function Notes_StopPrinting()
1751 VincentSDSH-33016
        if Notes_PrintCache[Notes_CacheIndex][4] then
1752 VincentSDSH-33016
                Notes_SendNote("<NOTE::STOP",Notes_PrintCache[Notes_CacheIndex][2],Notes_PrintCache[Notes_CacheIndex][3])
1753 VincentSDSH-33016
        end
1754 VincentSDSH-33016
 
1755 VincentSDSH-33016
        Notes_WarningPrint("Printing halted for ["..Notes_PrintCache[Notes_CacheIndex][5].."]")
1756 VincentSDSH-33016
 
1757 VincentSDSH-33016
        Notes_PrintCache = {}
1758 VincentSDSH-33016
        Notes_CacheIndex = 1
1759 VincentSDSH-33016
        Notes_LastUpdateTime = nil
1760 VincentSDSH-33016
        Notes_PrintInterval = Notes_PrintMaxInterval
1761 VincentSDSH-33016
 
1762 VincentSDSH-33016
        Notes_SetButtonState()
1763 VincentSDSH-33016
end
1764 VincentSDSH-33016
 
1765 VincentSDSH-33016
function Notes_ParseCache()
1766 VincentSDSH-33016
        if getn(Notes_PrintCache) > 0 then
1767 VincentSDSH-33016
                if not Notes_LastUpdateTime then
1768 VincentSDSH-33016
                        Notes_LastUpdateTime = 0
1769 VincentSDSH-33016
                end
1770 VincentSDSH-33016
 
1771 VincentSDSH-33016
                local curtime = GetTime()
1772 VincentSDSH-33016
                if curtime-Notes_LastUpdateTime > Notes_PrintInterval then
1773 VincentSDSH-33016
                        if Notes_PrintCache[Notes_CacheIndex] ~= nil then
1774 VincentSDSH-33016
                                Notes_SendNote(Notes_PrintCache[Notes_CacheIndex][1],Notes_PrintCache[Notes_CacheIndex][2],Notes_PrintCache[Notes_CacheIndex][3])
1775 VincentSDSH-33016
 
1776 VincentSDSH-33016
                                if strsub(Notes_PrintCache[Notes_CacheIndex][1],1,7) == "<NOTE::" then
1777 VincentSDSH-33016
                                        Notes_PrintInterval=1
1778 VincentSDSH-33016
                                else
1779 VincentSDSH-33016
                                        Notes_PrintInterval=((Notes_PrintMaxInterval-Notes_PrintMinInterval)*
1780 VincentSDSH-33016
                                          (strlen(Notes_PrintCache[Notes_CacheIndex][1])-Notes_PrintMinLength)/
1781 VincentSDSH-33016
                                          (Notes_PrintMaxLength-Notes_PrintMinLength))+Notes_PrintMinInterval
1782 VincentSDSH-33016
                                end
1783 VincentSDSH-33016
 
1784 VincentSDSH-33016
                                if Notes_PrintInterval < Notes_PrintMinInterval then Notes_PrintInterval = Notes_PrintMinInterval end
1785 VincentSDSH-33016
                                if Notes_PrintInterval > Notes_PrintMaxInterval then Notes_PrintInterval = Notes_PrintMaxInterval end
1786 VincentSDSH-33016
 
1787 VincentSDSH-33016
                                if not Notes_PrintCache[Notes_CacheIndex+1] or
1788 VincentSDSH-33016
                                   (Notes_PrintCache[Notes_CacheIndex+1] and Notes_PrintCache[Notes_CacheIndex+1][5] and
1789 VincentSDSH-33016
                                    Notes_PrintCache[Notes_CacheIndex+1][5] ~= Notes_PrintCache[Notes_CacheIndex][5]) then
1790 VincentSDSH-33016
                                        Notes_SuccessPrint("Printing finished for ["..Notes_PrintCache[Notes_CacheIndex][5].."]")
1791 VincentSDSH-33016
                                end
1792 VincentSDSH-33016
 
1793 VincentSDSH-33016
                                Notes_CacheIndex = Notes_CacheIndex + 1
1794 VincentSDSH-33016
                                Notes_LastUpdateTime = curtime
1795 VincentSDSH-33016
                        else
1796 VincentSDSH-33016
 
1797 VincentSDSH-33016
                                Notes_PrintCache = {}
1798 VincentSDSH-33016
                                Notes_CacheIndex = 1
1799 VincentSDSH-33016
                                Notes_LastUpdateTime = nil
1800 VincentSDSH-33016
                                Notes_PrintInterval = Notes_PrintMaxInterval
1801 VincentSDSH-33016
                                Notes_SetButtonState()
1802 VincentSDSH-33016
                        end
1803 VincentSDSH-33016
                end
1804 VincentSDSH-33016
        end
1805 VincentSDSH-33016
end
1806 VincentSDSH-33016
 
1807 VincentSDSH-33016
function Notes_ListenEvent()
1808 VincentSDSH-33016
        if event == "VARIABLES_LOADED" then
1809 VincentSDSH-33016
                Notes_ChanSelectDropDownOnLoad()
1810 VincentSDSH-33016
                Notes_CommDropDownOnLoad()
1811 VincentSDSH-33016
                Notes_IconMove(Notes_IconPos)
1812 VincentSDSH-33016
                Notes_ScrollBarUpdate(1)
1813 VincentSDSH-33016
 
1814 VincentSDSH-33016
                if Notes_GetNoteIndex("1") then Notes_RunNote("1") end
1815 VincentSDSH-33016
        end
1816 VincentSDSH-33016
 
1817 VincentSDSH-33016
        if event == "CHAT_MSG_CHANNEL_NOTICE" then
1818 VincentSDSH-33016
                Notes_InitChannelList()
1819 VincentSDSH-33016
        end
1820 VincentSDSH-33016
 
1821 VincentSDSH-33016
        if (event=="PLAYER_TARGET_CHANGED" or event == "RAID_ROSTER_UPDATE") then
1822 VincentSDSH-33016
                Notes_SetButtonState(1)
1823 VincentSDSH-33016
        end
1824 VincentSDSH-33016
 
1825 VincentSDSH-33016
        if event == "CHAT_MSG_ADDON" and arg1 == "Notes" then
1826 VincentSDSH-33016
                parsebits = Notes_Split(strsub(arg2,0,-2),"::")
1827 VincentSDSH-33016
 
1828 VincentSDSH-33016
                if Notes_ListenStack[arg4] and parsebits[2] == "END" then
1829 VincentSDSH-33016
                        if tonumber(strlen(strsub(Notes_ListenStack[arg4]["text"],0,-2))) == tonumber(Notes_ListenStack[arg4]["length"]) then
1830 VincentSDSH-33016
                                local success = Notes_NewNote(Notes_ListenStack[arg4]["title"],strsub(Notes_ListenStack[arg4]["text"],0,-2),1,false,Notes_ListenStack[arg4]["id"],Notes_ListenStack[arg4]["bookid"],Notes_ListenStack[arg4]["bookname"],true,true)
1831 VincentSDSH-33016
                                if success == 0 then
1832 VincentSDSH-33016
                                        Notes_SuccessPrint("Sync successful for ["..Notes_ListenStack[arg4]["title"].."]")
1833 VincentSDSH-33016
                                end
1834 VincentSDSH-33016
 
1835 VincentSDSH-33016
                                Notes_SortAndReselect()
1836 VincentSDSH-33016
                                Notes_ScrollBarUpdate()
1837 VincentSDSH-33016
                        else
1838 VincentSDSH-33016
                                Notes_ErrorPrint("Sync failed for ["..Notes_ListenStack[arg4]["title"].."]")
1839 VincentSDSH-33016
                        end
1840 VincentSDSH-33016
                        Notes_ListenStack[arg4] = nil
1841 VincentSDSH-33016
 
1842 VincentSDSH-33016
                elseif Notes_ListenStack[arg4] and parsebits[2] == "STOP" then
1843 VincentSDSH-33016
                        Notes_ErrorPrint("Sync halted for ["..Notes_ListenStack[arg4]["title"].."] at request of "..arg4)
1844 VincentSDSH-33016
                        Notes_ListenStack[arg4] = nil
1845 VincentSDSH-33016
                else
1846 VincentSDSH-33016
                        if not Notes_ListenStack[arg4] and arg4 ~= UnitName("player") then
1847 VincentSDSH-33016
                                if not tonumber(parsebits[7]) then return end
1848 VincentSDSH-33016
 
1849 VincentSDSH-33016
                                local commtype = Notes_CommModes[tonumber(parsebits[7])][4]
1850 VincentSDSH-33016
                                local commtarget = nil
1851 VincentSDSH-33016
                                if parsebits[8] ~= "nil" then commtarget = strlower(parsebits[8]) end
1852 VincentSDSH-33016
 
1853 VincentSDSH-33016
                                if commtype and Notes_CommModes[tonumber(parsebits[7])][6](arg4,commtarget) then
1854 VincentSDSH-33016
                                        Notes_ListenStack[arg4] = {}
1855 VincentSDSH-33016
                                        Notes_ListenStack[arg4]["title"] = parsebits[2]
1856 VincentSDSH-33016
                                        Notes_ListenStack[arg4]["id"] = parsebits[3]
1857 VincentSDSH-33016
                                        Notes_ListenStack[arg4]["length"] = parsebits[4]
1858 VincentSDSH-33016
                                        if parsebits[5] ~= "nil" and parsebits[6] ~= "nil" then
1859 VincentSDSH-33016
                                                Notes_ListenStack[arg4]["bookid"] = parsebits[5]
1860 VincentSDSH-33016
                                                Notes_ListenStack[arg4]["bookname"] = parsebits[6]
1861 VincentSDSH-33016
                                        end
1862 VincentSDSH-33016
                                        Notes_ListenStack[arg4]["commtype"] = commtype
1863 VincentSDSH-33016
                                        Notes_ListenStack[arg4]["commtarget"] = commtarget
1864 VincentSDSH-33016
                                        Notes_ListenStack[arg4]["text"] = ""
1865 VincentSDSH-33016
                                end
1866 VincentSDSH-33016
                        end
1867 VincentSDSH-33016
                end
1868 VincentSDSH-33016
        end
1869 VincentSDSH-33016
 
1870 VincentSDSH-33016
        if strsub(event,1,9) == "CHAT_MSG_" and Notes_ListenStack[arg2] then
1871 VincentSDSH-33016
                local commtype = Notes_ListenStack[arg2]["commtype"]
1872 VincentSDSH-33016
                local commtarget = Notes_ListenStack[arg2]["commtarget"]
1873 VincentSDSH-33016
 
1874 VincentSDSH-33016
                local subevent = strsub(event,10)
1875 VincentSDSH-33016
                if subevent == "RAID_LEADER" then subevent = "RAID" end
1876 VincentSDSH-33016
 
1877 VincentSDSH-33016
                if commtype == subevent then
1878 VincentSDSH-33016
                        if (commtype ~= "CHANNEL" and commtype ~= "WHISPER") or
1879 VincentSDSH-33016
                           (commtype == "CHANNEL" and commtarget and commtarget == strlower(arg9)) or
1880 VincentSDSH-33016
                           (commtype == "WHISPER" and commtarget and commtarget == strlower(UnitName("player"))) then
1881 VincentSDSH-33016
                                Notes_ListenStack[arg2]["text"] = Notes_ListenStack[arg2]["text"]..arg1.."\n"
1882 VincentSDSH-33016
                        end
1883 VincentSDSH-33016
 
1884 VincentSDSH-33016
                        if tonumber(strlen(strsub(Notes_ListenStack[arg2]["text"],0,-2))) > tonumber(Notes_ListenStack[arg2]["length"]) then
1885 VincentSDSH-33016
                                Notes_ErrorPrint("Sync failed for ["..Notes_ListenStack[arg2]["title"].."]")
1886 VincentSDSH-33016
                                Notes_ListenStack[arg2] = nil
1887 VincentSDSH-33016
                        end
1888 VincentSDSH-33016
                end
1889 VincentSDSH-33016
        end
1890 VincentSDSH-33016
end
1891 VincentSDSH-33016
 
1892 VincentSDSH-33016
function Notes_InitChannelList()
1893 VincentSDSH-33016
        Notes_ChanList = {}
1894 VincentSDSH-33016
        for i=1,10 do
1895 VincentSDSH-33016
                local id, name = GetChannelName(i)
1896 VincentSDSH-33016
                if id and id ~= 0 and name ~= nil then
1897 VincentSDSH-33016
                        table.insert(Notes_ChanList,{id,name,strlower(name)})
1898 VincentSDSH-33016
                end
1899 VincentSDSH-33016
        end
1900 VincentSDSH-33016
end
1901 VincentSDSH-33016
 
1902 VincentSDSH-33016
------------------------------------------
1903 VincentSDSH-33016
-- H) Notes Sorting Functions
1904 VincentSDSH-33016
--[[
1905 VincentSDSH-33016
Notes_HashNatSort - Natural sorting for numbers that appear after the last # of the value
1906 VincentSDSH-33016
Notes_HashNatTitleSort - Natural sorting for numbers that appear after the last # of the value's title
1907 VincentSDSH-33016
Notes_FindNextInSequence - Find the next value in a sequence
1908 VincentSDSH-33016
Notes_FindLast - Reverse string search
1909 VincentSDSH-33016
]]--
1910 VincentSDSH-33016
 
1911 VincentSDSH-33016
function Notes_HashNatSort(a,b)
1912 VincentSDSH-33016
        local hashloca = Notes_FindLast(a,"#")
1913 VincentSDSH-33016
        local hashlocb = Notes_FindLast(b,"#")
1914 VincentSDSH-33016
 
1915 VincentSDSH-33016
        if not hashloca or not hashlocb then return a < b end
1916 VincentSDSH-33016
 
1917 VincentSDSH-33016
        local astr = strsub(a,0,hashloca)
1918 VincentSDSH-33016
        local bstr = strsub(b,0,hashlocb)
1919 VincentSDSH-33016
 
1920 VincentSDSH-33016
        if astr ~= bstr then return a < b end
1921 VincentSDSH-33016
 
1922 VincentSDSH-33016
        local anum = tonumber(strsub(a,hashloca+1))
1923 VincentSDSH-33016
        local bnum = tonumber(strsub(b,hashlocb+1))
1924 VincentSDSH-33016
 
1925 VincentSDSH-33016
        if not anum or not bnum then return a < b end
1926 VincentSDSH-33016
 
1927 VincentSDSH-33016
        return anum < bnum
1928 VincentSDSH-33016
end
1929 VincentSDSH-33016
 
1930 VincentSDSH-33016
function Notes_HashNatTitleSort(a,b)
1931 VincentSDSH-33016
        if type(a["book"]) == "table" and type(b["book"]) ~= "table" then return true end
1932 VincentSDSH-33016
        if not a["book"] and type(b["book"]) == "string" then return true end
1933 VincentSDSH-33016
        if type(b["book"]) == "table" and type(a["book"]) ~= "table" then return false end
1934 VincentSDSH-33016
        if not b["book"] and type(a["book"]) == "string" then return false end
1935 VincentSDSH-33016
 
1936 VincentSDSH-33016
        if a["title"] == b["title"] then return a["id"] < b["id"] end
1937 VincentSDSH-33016
 
1938 VincentSDSH-33016
        local hashloca = Notes_FindLast(a["title"],"#")
1939 VincentSDSH-33016
        local hashlocb = Notes_FindLast(b["title"],"#")
1940 VincentSDSH-33016
 
1941 VincentSDSH-33016
        if not hashloca or not hashlocb then return a["title"] < b["title"] end
1942 VincentSDSH-33016
 
1943 VincentSDSH-33016
        local astr = strsub(a["title"],0,hashloca)
1944 VincentSDSH-33016
        local bstr = strsub(b["title"],0,hashlocb)
1945 VincentSDSH-33016
 
1946 VincentSDSH-33016
        if astr ~= bstr then return a["title"] < b["title"] end
1947 VincentSDSH-33016
 
1948 VincentSDSH-33016
        local anum = tonumber(strsub(a["title"],hashloca+1))
1949 VincentSDSH-33016
        local bnum = tonumber(strsub(b["title"],hashlocb+1))
1950 VincentSDSH-33016
 
1951 VincentSDSH-33016
        if not anum or not bnum then return a["title"] < b["title"] end
1952 VincentSDSH-33016
 
1953 VincentSDSH-33016
        return anum < bnum
1954 VincentSDSH-33016
end
1955 VincentSDSH-33016
 
1956 VincentSDSH-33016
function Notes_HashNatNotesTitleSort(a,b)
1957 VincentSDSH-33016
        if type(Notes_Notes[a]["book"]) == "table" and type(Notes_Notes[b]["book"]) ~= "table" then return true end
1958 VincentSDSH-33016
        if not Notes_Notes[a]["book"] and type(Notes_Notes[b]["book"]) == "string" then return true end
1959 VincentSDSH-33016
        if type(Notes_Notes[b]["book"]) == "table" and type(Notes_Notes[a]["book"]) ~= "table" then return false end
1960 VincentSDSH-33016
        if not Notes_Notes[b]["book"] and type(Notes_Notes[a]["book"]) == "string" then return false end
1961 VincentSDSH-33016
 
1962 VincentSDSH-33016
        if Notes_Notes[a]["title"] == Notes_Notes[b]["title"] then return Notes_Notes[a]["id"] < Notes_Notes[b]["id"] end
1963 VincentSDSH-33016
 
1964 VincentSDSH-33016
        local hashloca = Notes_FindLast(Notes_Notes[a]["title"],"#")
1965 VincentSDSH-33016
        local hashlocb = Notes_FindLast(Notes_Notes[b]["title"],"#")
1966 VincentSDSH-33016
 
1967 VincentSDSH-33016
        if not hashloca or not hashlocb then return Notes_Notes[a]["title"] < Notes_Notes[b]["title"] end
1968 VincentSDSH-33016
 
1969 VincentSDSH-33016
        local astr = strsub(Notes_Notes[a]["title"],0,hashloca)
1970 VincentSDSH-33016
        local bstr = strsub(Notes_Notes[b]["title"],0,hashlocb)
1971 VincentSDSH-33016
 
1972 VincentSDSH-33016
        if astr ~= bstr then return Notes_Notes[a]["title"] < Notes_Notes[b]["title"] end
1973 VincentSDSH-33016
 
1974 VincentSDSH-33016
        local anum = tonumber(strsub(Notes_Notes[a]["title"],hashloca+1))
1975 VincentSDSH-33016
        local bnum = tonumber(strsub(Notes_Notes[b]["title"],hashlocb+1))
1976 VincentSDSH-33016
 
1977 VincentSDSH-33016
        if not anum or not bnum then return Notes_Notes[a]["title"] < Notes_Notes[b]["title"] end
1978 VincentSDSH-33016
 
1979 VincentSDSH-33016
        return anum < bnum
1980 VincentSDSH-33016
end
1981 VincentSDSH-33016
 
1982 VincentSDSH-33016
function Notes_FindNextInSequence(title) -- requires to be in the format: "TITLE #<num>"
1983 VincentSDSH-33016
        local titles = {}
1984 VincentSDSH-33016
        local hashloc = Notes_FindLast(title,"#")
1985 VincentSDSH-33016
 
1986 VincentSDSH-33016
        local prefix = strsub(title,0,hashloc)
1987 VincentSDSH-33016
        local num = tonumber(strsub(title,hashloc+1))
1988 VincentSDSH-33016
 
1989 VincentSDSH-33016
        title = prefix..num
1990 VincentSDSH-33016
 
1991 VincentSDSH-33016
        for i=1,getn(Notes_Notes) do
1992 VincentSDSH-33016
                table.insert(titles,Notes_Notes[i]["title"])
1993 VincentSDSH-33016
        end
1994 VincentSDSH-33016
        table.sort(titles,Notes_HashNatSort)
1995 VincentSDSH-33016
 
1996 VincentSDSH-33016
        for i=1,getn(titles) do
1997 VincentSDSH-33016
                if titles[i] == title then
1998 VincentSDSH-33016
                        num = num + 1
1999 VincentSDSH-33016
                        title = prefix..num
2000 VincentSDSH-33016
                end
2001 VincentSDSH-33016
        end
2002 VincentSDSH-33016
        return title
2003 VincentSDSH-33016
end
2004 VincentSDSH-33016
 
2005 VincentSDSH-33016
function Notes_FindLast(haystack,needle)
2006 VincentSDSH-33016
        local loc = string.find(haystack,needle)
2007 VincentSDSH-33016
        i=1
2008 VincentSDSH-33016
        while loc do
2009 VincentSDSH-33016
                local testloc = string.find(haystack,needle,loc+1)
2010 VincentSDSH-33016
                if testloc then loc = testloc
2011 VincentSDSH-33016
                else break end
2012 VincentSDSH-33016
        end
2013 VincentSDSH-33016
        return loc
2014 VincentSDSH-33016
end
2015 VincentSDSH-33016
 
2016 VincentSDSH-33016
------------------------------------------
2017 VincentSDSH-33016
-- I) General Tools Functions
2018 VincentSDSH-33016
--[[
2019 VincentSDSH-33016
Notes_InTable - Check to see if an item is in an array
2020 VincentSDSH-33016
Notes_Split - Split a string into an array via a delimeter
2021 VincentSDSH-33016
Notes_Join - Join an array into a string via a delimeter
2022 VincentSDSH-33016
Notes_Merge - Merge two arrays into one
2023 VincentSDSH-33016
Notes_RaidPrint - Do your best to print to raid chat
2024 VincentSDSH-33016
Notes_Print - General purpose print function.  Better than the default.
2025 VincentSDSH-33016
Notes_DataToString - Format data into a string for printing
2026 VincentSDSH-33016
Notes_StringToID - Create a number from a string
2027 VincentSDSH-33016
Notes_SuccessPrint - Print a success message
2028 VincentSDSH-33016
Notes_WarningPrint - Print a warning message
2029 VincentSDSH-33016
Notes_ErrorPrint - Print an error message
2030 VincentSDSH-33016
Notes_InParty - Am I in a party?
2031 VincentSDSH-33016
Notes_InRaid - Am I in a raid?
2032 VincentSDSH-33016
]]--
2033 VincentSDSH-33016
 
2034 VincentSDSH-33016
function Notes_InTable(haystack,needle,id,id2)
2035 VincentSDSH-33016
        for key,hay in pairs(haystack) do
2036 VincentSDSH-33016
                if id then hay = hay[id] end
2037 VincentSDSH-33016
                if id2 then hay = hay[id2] end
2038 VincentSDSH-33016
                if needle == hay then return key end
2039 VincentSDSH-33016
        end
2040 VincentSDSH-33016
        return nil
2041 VincentSDSH-33016
end
2042 VincentSDSH-33016
 
2043 VincentSDSH-33016
function Notes_GetNoteIndex(id)
2044 VincentSDSH-33016
        if id == nil then return nil end
2045 VincentSDSH-33016
        return Notes_InTable(Notes_Notes,id,"id")
2046 VincentSDSH-33016
end
2047 VincentSDSH-33016
 
2048 VincentSDSH-33016
function Notes_Split(text, delimiter)
2049 VincentSDSH-33016
        local list = {}
2050 VincentSDSH-33016
        local pos = 1
2051 VincentSDSH-33016
        if strfind("", delimiter, 1) then -- this would result in endless loops
2052 VincentSDSH-33016
                return text
2053 VincentSDSH-33016
        end
2054 VincentSDSH-33016
        while 1 do
2055 VincentSDSH-33016
                local first, last = strfind(text, delimiter, pos)
2056 VincentSDSH-33016
                if first then
2057 VincentSDSH-33016
                        tinsert(list, strsub(text, pos, first-1))
2058 VincentSDSH-33016
                        pos = last+1
2059 VincentSDSH-33016
                else
2060 VincentSDSH-33016
                        tinsert(list, strsub(text, pos))
2061 VincentSDSH-33016
                        break
2062 VincentSDSH-33016
                end
2063 VincentSDSH-33016
        end
2064 VincentSDSH-33016
        return list
2065 VincentSDSH-33016
end
2066 VincentSDSH-33016
 
2067 VincentSDSH-33016
function Notes_Join(list, delimiter)
2068 VincentSDSH-33016
        local len = getn(list)
2069 VincentSDSH-33016
        if len == 0 then return "" end
2070 VincentSDSH-33016
 
2071 VincentSDSH-33016
        local string = list[1]
2072 VincentSDSH-33016
        for i = 2, len do
2073 VincentSDSH-33016
                string = string..delimiter..list[i]
2074 VincentSDSH-33016
        end
2075 VincentSDSH-33016
        return string
2076 VincentSDSH-33016
end
2077 VincentSDSH-33016
 
2078 VincentSDSH-33016
function Notes_Merge (table1, table2, start1, start2, end1, end2)
2079 VincentSDSH-33016
        if not start1 then start1 = 1 end
2080 VincentSDSH-33016
        if not start2 then start2 = 1 end
2081 VincentSDSH-33016
        if not end1 then end1 = 10000 end
2082 VincentSDSH-33016
        if not end2 then end2 = 10000 end
2083 VincentSDSH-33016
 
2084 VincentSDSH-33016
        local mtable = {}
2085 VincentSDSH-33016
        if type(table1) == "table" then
2086 VincentSDSH-33016
                for i=max(1,start1),min(getn(table1),end1) do
2087 VincentSDSH-33016
                        table.insert(mtable,table1[i])
2088 VincentSDSH-33016
                end
2089 VincentSDSH-33016
        elseif type(table1) == "string" then
2090 VincentSDSH-33016
                table.insert(mtable,table1)
2091 VincentSDSH-33016
        end
2092 VincentSDSH-33016
 
2093 VincentSDSH-33016
        if type(table2) == "table" then
2094 VincentSDSH-33016
                for i=max(1,start2),min(getn(table2),end2) do
2095 VincentSDSH-33016
                        table.insert(mtable,table2[i])
2096 VincentSDSH-33016
                end
2097 VincentSDSH-33016
        elseif type(table2) == "string" then
2098 VincentSDSH-33016
                table.insert(mtable,table2)
2099 VincentSDSH-33016
        end
2100 VincentSDSH-33016
 
2101 VincentSDSH-33016
        return mtable
2102 VincentSDSH-33016
end
2103 VincentSDSH-33016
 
2104 VincentSDSH-33016
function Notes_RaidPrint (msg)
2105 VincentSDSH-33016
        local index = nil
2106 VincentSDSH-33016
 
2107 VincentSDSH-33016
        if Notes_InRaid() then
2108 VincentSDSH-33016
                ChatThrottleLib:SendChatMessage("NORMAL","",msg, "RAID")
2109 VincentSDSH-33016
 
2110 VincentSDSH-33016
        elseif Notes_InParty() then
2111 VincentSDSH-33016
                ChatThrottleLib:SendChatMessage("NORMAL","",msg, "PARTY")
2112 VincentSDSH-33016
        else
2113 VincentSDSH-33016
                Notes_Print(msg)
2114 VincentSDSH-33016
        end
2115 VincentSDSH-33016
end
2116 VincentSDSH-33016
 
2117 VincentSDSH-33016
function Notes_Print(msg,channel,prefix)
2118 VincentSDSH-33016
        if prefix == nil then prefix = "" end
2119 VincentSDSH-33016
 
2120 VincentSDSH-33016
        if msg == nil then
2121 VincentSDSH-33016
                Notes_ChanPrint(prefix.."nil",channel,.8,.8,.8)
2122 VincentSDSH-33016
 
2123 VincentSDSH-33016
        elseif type(msg) == "number" then
2124 VincentSDSH-33016
                Notes_ChanPrint(prefix..msg,channel,.8,.8,1)
2125 VincentSDSH-33016
 
2126 VincentSDSH-33016
        elseif type(msg) == "string" then
2127 VincentSDSH-33016
                Notes_ChanPrint(prefix..msg,channel,1,.9,.8)
2128 VincentSDSH-33016
 
2129 VincentSDSH-33016
        elseif type(msg) == "boolean" and msg==false then
2130 VincentSDSH-33016
                Notes_ChanPrint(prefix.."false",channel,1,.8,.8)
2131 VincentSDSH-33016
 
2132 VincentSDSH-33016
        elseif type(msg) == "boolean" and msg==true then
2133 VincentSDSH-33016
                Notes_ChanPrint(prefix.."true",channel,.8,1,.8)
2134 VincentSDSH-33016
 
2135 VincentSDSH-33016
        elseif type(msg) == "table" then
2136 VincentSDSH-33016
                for index,item in pairs(msg) do
2137 VincentSDSH-33016
                        if type(item) == "table" then
2138 VincentSDSH-33016
                                if getn(item) > 0 then
2139 VincentSDSH-33016
                                        Notes_ChanPrint(prefix..index.."  --TABLE--",channel)
2140 VincentSDSH-33016
                                        Notes_Print(item,channel,prefix..">  ")
2141 VincentSDSH-33016
                                end
2142 VincentSDSH-33016
                        else
2143 VincentSDSH-33016
                                Notes_Print(item,channel,prefix..index.."  ")
2144 VincentSDSH-33016
                        end
2145 VincentSDSH-33016
                end
2146 VincentSDSH-33016
        end
2147 VincentSDSH-33016
end
2148 VincentSDSH-33016
 
2149 VincentSDSH-33016
function Notes_ChanPrint(msg,chan,R,G,B)
2150 VincentSDSH-33016
        if not msg then return end
2151 VincentSDSH-33016
        if not chan then chan = "CONSOLE" end
2152 VincentSDSH-33016
 
2153 VincentSDSH-33016
        chan = strupper(chan)
2154 VincentSDSH-33016
 
2155 VincentSDSH-33016
        if chan == "RAID" then
2156 VincentSDSH-33016
                if UnitInRaid("player") then SendChatMessage(msg,"RAID",GetDefaultLanguage("player"))
2157 VincentSDSH-33016
                elseif GetPartyMember(1) then SendChatMessage(msg,"PARTY",GetDefaultLanguage("player")) end
2158 VincentSDSH-33016
 
2159 VincentSDSH-33016
        elseif chan == "PARTY" then
2160 VincentSDSH-33016
                SendChatMessage(msg,"PARTY",GetDefaultLanguage("player"))
2161 VincentSDSH-33016
 
2162 VincentSDSH-33016
        elseif chan == "GUILD" then
2163 VincentSDSH-33016
                SendChatMessage(msg,"GUILD",GetDefaultLanguage("player"))
2164 VincentSDSH-33016
 
2165 VincentSDSH-33016
        elseif chan == "OFFICER" then
2166 VincentSDSH-33016
                SendChatMessage(msg,"OFFICER",GetDefaultLanguage("player"))
2167 VincentSDSH-33016
 
2168 VincentSDSH-33016
        elseif chan == "BATTLEGROUND" or chan == "BATTLEFIELD" or chan == "BG" then
2169 VincentSDSH-33016
                SendChatMessage(msg,"BATTLEGROUND",GetDefaultLanguage("player"))
2170 VincentSDSH-33016
 
2171 VincentSDSH-33016
        elseif chan == "CONSOLE" then
2172 VincentSDSH-33016
                DEFAULT_CHAT_FRAME:AddMessage(msg,R,G,B)
2173 VincentSDSH-33016
        else
2174 VincentSDSH-33016
                local index = GetChannelName(chan)
2175 VincentSDSH-33016
                if index ~= nil and index ~= 0 then
2176 VincentSDSH-33016
                        SendChatMessage(msg,"CHANNEL",GetDefaultLanguage("player"),index)
2177 VincentSDSH-33016
                else
2178 VincentSDSH-33016
                        SendChatMessage(msg,"WHISPER",GetDefaultLanguage("player"),chan)
2179 VincentSDSH-33016
                end
2180 VincentSDSH-33016
        end
2181 VincentSDSH-33016
end
2182 VincentSDSH-33016
 
2183 VincentSDSH-33016
function Notes_DataToString(msg,prefix)
2184 VincentSDSH-33016
        local str = ""
2185 VincentSDSH-33016
 
2186 VincentSDSH-33016
        if prefix == nil then prefix = "" end
2187 VincentSDSH-33016
 
2188 VincentSDSH-33016
        if msg == nil then
2189 VincentSDSH-33016
                str = str..prefix.."nil\n"
2190 VincentSDSH-33016
 
2191 VincentSDSH-33016
        elseif type(msg) == "number" then
2192 VincentSDSH-33016
                str = str..prefix..msg.."\n"
2193 VincentSDSH-33016
 
2194 VincentSDSH-33016
        elseif type(msg) == "string" then
2195 VincentSDSH-33016
                str = str..prefix..msg.."\n"
2196 VincentSDSH-33016
 
2197 VincentSDSH-33016
        elseif type(msg) == "boolean" and msg==false then
2198 VincentSDSH-33016
                str = str..prefix.."false\n"
2199 VincentSDSH-33016
 
2200 VincentSDSH-33016
        elseif type(msg) == "boolean" and msg==true then
2201 VincentSDSH-33016
                str = str..prefix.."true\n"
2202 VincentSDSH-33016
 
2203 VincentSDSH-33016
        elseif type(msg) == "table" then
2204 VincentSDSH-33016
                for index,item in pairs(msg) do
2205 VincentSDSH-33016
                        if type(item) == "table" then
2206 VincentSDSH-33016
                                str = str..prefix..index.."  --TABLE--\n"
2207 VincentSDSH-33016
                                str = str..Notes_DataToString(item,prefix..">  ")
2208 VincentSDSH-33016
                        else
2209 VincentSDSH-33016
                                str = str..Notes_DataToString(item,prefix..index.."  \n")
2210 VincentSDSH-33016
                        end
2211 VincentSDSH-33016
                end
2212 VincentSDSH-33016
        end
2213 VincentSDSH-33016
        return strsub(str,0,-2)
2214 VincentSDSH-33016
end
2215 VincentSDSH-33016
 
2216 VincentSDSH-33016
function Notes_StringToID(msg)
2217 VincentSDSH-33016
        local id = 0
2218 VincentSDSH-33016
        for i=1,strlen(msg) do
2219 VincentSDSH-33016
                local val = strsub(msg,i,i)
2220 VincentSDSH-33016
                if tonumber(val) then id = id + tonumber(val)*i end
2221 VincentSDSH-33016
                if val=="a" or val=="A" then id = id + 1*i*10 end
2222 VincentSDSH-33016
                if val=="b" or val=="B" then id = id + 2*i*10 end
2223 VincentSDSH-33016
                if val=="c" or val=="C" then id = id + 3*i*10 end
2224 VincentSDSH-33016
                if val=="d" or val=="D" then id = id + 4*i*10 end
2225 VincentSDSH-33016
                if val=="e" or val=="E" then id = id + 5*i*10 end
2226 VincentSDSH-33016
                if val=="f" or val=="F" then id = id + 6*i*10 end
2227 VincentSDSH-33016
                if val=="g" or val=="G" then id = id + 7*i*10 end
2228 VincentSDSH-33016
                if val=="h" or val=="H" then id = id + 8*i*10 end
2229 VincentSDSH-33016
                if val=="i" or val=="I" then id = id + 9*i*10 end
2230 VincentSDSH-33016
                if val=="j" or val=="J" then id = id + 10*i*10 end
2231 VincentSDSH-33016
                if val=="k" or val=="K" then id = id + 11*i*10 end
2232 VincentSDSH-33016
                if val=="l" or val=="L" then id = id + 12*i*10 end
2233 VincentSDSH-33016
                if val=="m" or val=="M" then id = id + 13*i*10 end
2234 VincentSDSH-33016
                if val=="n" or val=="N" then id = id + 14*i*10 end
2235 VincentSDSH-33016
                if val=="o" or val=="O" then id = id + 15*i*10 end
2236 VincentSDSH-33016
                if val=="p" or val=="P" then id = id + 16*i*10 end
2237 VincentSDSH-33016
                if val=="q" or val=="Q" then id = id + 17*i*10 end
2238 VincentSDSH-33016
                if val=="r" or val=="R" then id = id + 18*i*10 end
2239 VincentSDSH-33016
                if val=="s" or val=="S" then id = id + 19*i*10 end
2240 VincentSDSH-33016
                if val=="t" or val=="T" then id = id + 20*i*10 end
2241 VincentSDSH-33016
                if val=="u" or val=="U" then id = id + 21*i*10 end
2242 VincentSDSH-33016
                if val=="v" or val=="V" then id = id + 22*i*10 end
2243 VincentSDSH-33016
                if val=="w" or val=="W" then id = id + 23*i*10 end
2244 VincentSDSH-33016
                if val=="x" or val=="X" then id = id + 24*i*10 end
2245 VincentSDSH-33016
                if val=="y" or val=="Y" then id = id + 25*i*10 end
2246 VincentSDSH-33016
                if val=="z" or val=="Z" then id = id + 26*i*10 end
2247 VincentSDSH-33016
        end
2248 VincentSDSH-33016
        return id
2249 VincentSDSH-33016
end
2250 VincentSDSH-33016
 
2251 VincentSDSH-33016
function Notes_SuccessPrint(msg)
2252 VincentSDSH-33016
        DEFAULT_CHAT_FRAME:AddMessage("<<Notes: "..msg..">>",.6,1,.3)
2253 VincentSDSH-33016
end
2254 VincentSDSH-33016
 
2255 VincentSDSH-33016
function Notes_WarningPrint(msg)
2256 VincentSDSH-33016
        DEFAULT_CHAT_FRAME:AddMessage("<<Notes Warning: "..msg..">>",1,.8,0)
2257 VincentSDSH-33016
end
2258 VincentSDSH-33016
 
2259 VincentSDSH-33016
function Notes_ErrorPrint(msg)
2260 VincentSDSH-33016
        DEFAULT_CHAT_FRAME:AddMessage("<<Notes Error: "..msg..">>",1,0,0)
2261 VincentSDSH-33016
end
2262 VincentSDSH-33016
 
2263 VincentSDSH-33016
function Notes_InParty(player)
2264 VincentSDSH-33016
        if player then
2265 VincentSDSH-33016
                player = strlower(player)
2266 VincentSDSH-33016
                for i=1,4 do
2267 VincentSDSH-33016
                        local name = UnitName("party"..i)
2268 VincentSDSH-33016
                        if name and strlower(name) == player then
2269 VincentSDSH-33016
                                return 1
2270 VincentSDSH-33016
                        end
2271 VincentSDSH-33016
                end
2272 VincentSDSH-33016
        else
2273 VincentSDSH-33016
                return GetPartyMember(1)
2274 VincentSDSH-33016
        end
2275 VincentSDSH-33016
        return nil
2276 VincentSDSH-33016
end
2277 VincentSDSH-33016
 
2278 VincentSDSH-33016
function Notes_InRaid(player)
2279 VincentSDSH-33016
        if player then
2280 VincentSDSH-33016
                player = strlower(player)
2281 VincentSDSH-33016
                for i=1,GetNumRaidMembers() do
2282 VincentSDSH-33016
                        local name = GetRaidRosterInfo(i)
2283 VincentSDSH-33016
                        if name and strlower(name) == player then
2284 VincentSDSH-33016
                                return 1
2285 VincentSDSH-33016
                        end
2286 VincentSDSH-33016
                end
2287 VincentSDSH-33016
        else
2288 VincentSDSH-33016
                return UnitInRaid("player")
2289 VincentSDSH-33016
        end
2290 VincentSDSH-33016
        return nil
2291 VincentSDSH-33016
end
2292 VincentSDSH-33016
 
2293 VincentSDSH-33016
function Notes_InGuild(player)
2294 VincentSDSH-33016
        if player then
2295 VincentSDSH-33016
                player = strlower(player)
2296 VincentSDSH-33016
                for i=1,GetNumGuildMembers() do
2297 VincentSDSH-33016
                        local name = GetGuildRosterInfo(i)
2298 VincentSDSH-33016
                        if name and strlower(name) == player then
2299 VincentSDSH-33016
                                return 1
2300 VincentSDSH-33016
                        end
2301 VincentSDSH-33016
                end
2302 VincentSDSH-33016
        else
2303 VincentSDSH-33016
                return IsInGuild()
2304 VincentSDSH-33016
        end
2305 VincentSDSH-33016
        return nil
2306 VincentSDSH-33016
end
2307 VincentSDSH-33016
 
2308 VincentSDSH-33016
function Notes_InBattlefield()
2309 VincentSDSH-33016
        for i=1,3 do
2310 VincentSDSH-33016
                if GetBattlefieldStatus(i)=="active" then
2311 VincentSDSH-33016
                        return true
2312 VincentSDSH-33016
                end
2313 VincentSDSH-33016
        end
2314 VincentSDSH-33016
end
2315 VincentSDSH-33016
 
2316 VincentSDSH-33016
------------------------------------------
2317 VincentSDSH-33016
-- J) Dropdown UI Functions
2318 VincentSDSH-33016
--[[
2319 VincentSDSH-33016
Notes_CommDropDownOnLoad - Set the width of the communications drop down and set starting value
2320 VincentSDSH-33016
Notes_CommDropDownOnClick - Set the communications method
2321 VincentSDSH-33016
Notes_CommDropDownInitialize - Prepare the communications drop down
2322 VincentSDSH-33016
Notes_ChanSelectDropDownOnLoad - Set the width of the communications channel drop down
2323 VincentSDSH-33016
Notes_ChanSelectDropDownOnClick - Set the communications channel
2324 VincentSDSH-33016
Notes_ChanSelectDropDownInitialize - Prepare the communications channel drop down
2325 VincentSDSH-33016
]]--
2326 VincentSDSH-33016
 
2327 VincentSDSH-33016
function Notes_CommDropDownOnLoad()
2328 VincentSDSH-33016
        UIDropDownMenu_Initialize(NotesCommDropDown, Notes_CommDropDownInitialize)
2329 VincentSDSH-33016
        UIDropDownMenu_SetSelectedValue(NotesCommDropDown, Notes_SelectedComm)
2330 VincentSDSH-33016
        UIDropDownMenu_SetWidth(NotesCommDropDown, 70)
2331 VincentSDSH-33016
end
2332 VincentSDSH-33016
 
2333 VincentSDSH-33016
function Notes_CommDropDownOnClick()
2334 VincentSDSH-33016
        UIDropDownMenu_SetSelectedValue(NotesCommDropDown, this.value)
2335 VincentSDSH-33016
        Notes_SelectedComm = this.value
2336 VincentSDSH-33016
        Notes_SetButtonState(1)
2337 VincentSDSH-33016
end
2338 VincentSDSH-33016
 
2339 VincentSDSH-33016
function Notes_CommDropDownInitialize()
2340 VincentSDSH-33016
        local selectedValue = UIDropDownMenu_GetSelectedValue(NotesCommDropDown)
2341 VincentSDSH-33016
 
2342 VincentSDSH-33016
        for i=1,getn(Notes_CommModes) do
2343 VincentSDSH-33016
                local info = {}
2344 VincentSDSH-33016
                info.text = Notes_CommModes[i][1]
2345 VincentSDSH-33016
                info.func = Notes_CommDropDownOnClick
2346 VincentSDSH-33016
                info.value = i
2347 VincentSDSH-33016
                info.checked = nil
2348 VincentSDSH-33016
                if ( info.value == selectedValue ) then
2349 VincentSDSH-33016
                        info.checked = 1
2350 VincentSDSH-33016
                end
2351 VincentSDSH-33016
                UIDropDownMenu_AddButton(info)
2352 VincentSDSH-33016
        end
2353 VincentSDSH-33016
end
2354 VincentSDSH-33016
 
2355 VincentSDSH-33016
function Notes_ChanSelectDropDownOnLoad()
2356 VincentSDSH-33016
        UIDropDownMenu_SetWidth(NotesChanSelectDropDown, 115)
2357 VincentSDSH-33016
end
2358 VincentSDSH-33016
 
2359 VincentSDSH-33016
function Notes_ChanSelectDropDownOnClick()
2360 VincentSDSH-33016
        UIDropDownMenu_SetSelectedValue(NotesChanSelectDropDown, this.value)
2361 VincentSDSH-33016
        Notes_SelectedChan = this.value
2362 VincentSDSH-33016
        Notes_SetButtonState(1)
2363 VincentSDSH-33016
end
2364 VincentSDSH-33016
 
2365 VincentSDSH-33016
function Notes_ChanSelectDropDownInitialize()
2366 VincentSDSH-33016
        local selectedValue = UIDropDownMenu_GetSelectedValue(NotesChanSelectDropDown)
2367 VincentSDSH-33016
 
2368 VincentSDSH-33016
        Notes_InitChannelList()
2369 VincentSDSH-33016
 
2370 VincentSDSH-33016
        for i=1,getn(Notes_ChanList) do
2371 VincentSDSH-33016
                if Notes_ChanList[i][2] ~= nil then
2372 VincentSDSH-33016
                        local info = {}
2373 VincentSDSH-33016
                        info.text = Notes_ChanList[i][1]..". "..Notes_ChanList[i][2]
2374 VincentSDSH-33016
                        info.func = Notes_ChanSelectDropDownOnClick
2375 VincentSDSH-33016
                        info.value = i
2376 VincentSDSH-33016
                        info.checked = nil
2377 VincentSDSH-33016
                        if ( info.value == selectedValue ) then
2378 VincentSDSH-33016
                                info.checked = 1
2379 VincentSDSH-33016
                        end
2380 VincentSDSH-33016
                        UIDropDownMenu_AddButton(info)
2381 VincentSDSH-33016
                end
2382 VincentSDSH-33016
        end
2383 VincentSDSH-33016
end
2384 VincentSDSH-33016
 
2385 VincentSDSH-33016
------------------------------------------
2386 VincentSDSH-33016
-- K) Book UI Functions
2387 VincentSDSH-33016
--[[
2388 VincentSDSH-33016
Notes_CreateIndexPage - Create a table of contents for a book
2389 VincentSDSH-33016
Notes_TOCScrollBarUpdate - Update the scrolling table of contents on vertical scroll
2390 VincentSDSH-33016
Notes_ToggleTOCSelected - Load the new book page from the index page
2391 VincentSDSH-33016
Notes_LoadPrevPage - Load the previous book page
2392 VincentSDSH-33016
Notes_LoadNextPage - Load the next book page
2393 VincentSDSH-33016
Notes_GoToPage - Go to some random book page
2394 VincentSDSH-33016
Notes_ReorderPage - Move the current page to your target page
2395 VincentSDSH-33016
]]--
2396 VincentSDSH-33016
function Notes_CreateIndexPage(bookid)
2397 VincentSDSH-33016
        local id = Notes_BookID
2398 VincentSDSH-33016
        if bookid then id = bookid end
2399 VincentSDSH-33016
 
2400 VincentSDSH-33016
        local index = Notes_GetNoteIndex(id)
2401 VincentSDSH-33016
        if not index then return end
2402 VincentSDSH-33016
 
2403 VincentSDSH-33016
        NotesTOCTitle_Text:SetText("["..Notes_Notes[index]["title"].."] Table of Contents")
2404 VincentSDSH-33016
 
2405 VincentSDSH-33016
        Notes_TOCPageData = {}
2406 VincentSDSH-33016
        for i=1,getn(Notes_BookPages) do
2407 VincentSDSH-33016
                local idx = Notes_GetNoteIndex(Notes_BookPages[i])
2408 VincentSDSH-33016
                if idx then
2409 VincentSDSH-33016
                        Notes_TOCPageData[i] = "Page "..i..") "
2410 VincentSDSH-33016
 
2411 VincentSDSH-33016
                        if Notes_Notes[idx]["sync"] then
2412 VincentSDSH-33016
                                Notes_TOCPageData[i] = Notes_TOCPageData[i].."[S]"
2413 VincentSDSH-33016
                        end
2414 VincentSDSH-33016
 
2415 VincentSDSH-33016
                        if Notes_Notes[idx]["locked"] then
2416 VincentSDSH-33016
                                Notes_TOCPageData[i] = Notes_TOCPageData[i].."[L]"
2417 VincentSDSH-33016
                        end
2418 VincentSDSH-33016
                        if Notes_Notes[idx]["sync"] or Notes_Notes[idx]["locked"] then
2419 VincentSDSH-33016
                                Notes_TOCPageData[i] = Notes_TOCPageData[i].." "
2420 VincentSDSH-33016
                        end
2421 VincentSDSH-33016
 
2422 VincentSDSH-33016
                        local title = Notes_Notes[idx]["title"]
2423 VincentSDSH-33016
                        local oldtitle = Notes_Notes[idx]["title"]
2424 VincentSDSH-33016
                        if title ~= nil then
2425 VincentSDSH-33016
                                title = strsub(title,0,Notes_TOCTitleLen)
2426 VincentSDSH-33016
                                if strlen(oldtitle) > Notes_TOCTitleLen then
2427 VincentSDSH-33016
                                        title = title.."..."
2428 VincentSDSH-33016
                                end
2429 VincentSDSH-33016
                        end
2430 VincentSDSH-33016
 
2431 VincentSDSH-33016
                        Notes_TOCPageData[i] = Notes_TOCPageData[i]..title
2432 VincentSDSH-33016
                end
2433 VincentSDSH-33016
        end
2434 VincentSDSH-33016
        Notes_TOCScrollBarUpdate()
2435 VincentSDSH-33016
end
2436 VincentSDSH-33016
 
2437 VincentSDSH-33016
function Notes_TOCScrollBarUpdate()
2438 VincentSDSH-33016
        local line; -- 1 through 5 of our window to scroll
2439 VincentSDSH-33016
        local lineplusoffset; -- an index into our data calculated from the scroll offset
2440 VincentSDSH-33016
 
2441 VincentSDSH-33016
        if getn(Notes_TOCPageData) == 0 then return end
2442 VincentSDSH-33016
 
2443 VincentSDSH-33016
        FauxScrollFrame_Update(NotesTOCScrollBar,getn(Notes_TOCPageData),16,16);
2444 VincentSDSH-33016
        for line=1,16 do
2445 VincentSDSH-33016
                lineplusoffset = line + FauxScrollFrame_GetOffset(NotesTOCScrollBar);
2446 VincentSDSH-33016
                if lineplusoffset <= getn(Notes_TOCPageData) then
2447 VincentSDSH-33016
                        getglobal("NotesTOC"..line.."_Text"):SetText(Notes_TOCPageData[lineplusoffset]);
2448 VincentSDSH-33016
                        getglobal("NotesTOC"..line):Show();
2449 VincentSDSH-33016
                else
2450 VincentSDSH-33016
                        getglobal("NotesTOC"..line):Hide();
2451 VincentSDSH-33016
                end
2452 VincentSDSH-33016
        end
2453 VincentSDSH-33016
end
2454 VincentSDSH-33016
 
2455 VincentSDSH-33016
function Notes_ToggleTOCSelected(button)
2456 VincentSDSH-33016
        if button ~= nil then
2457 VincentSDSH-33016
                local num = button
2458 VincentSDSH-33016
 
2459 VincentSDSH-33016
                if getglobal(button) then
2460 VincentSDSH-33016
                        for i=2,1,-1 do
2461 VincentSDSH-33016
                                num = tonumber(strsub(button,-1*i))
2462 VincentSDSH-33016
                                if num ~= nil then break end
2463 VincentSDSH-33016
                        end
2464 VincentSDSH-33016
                end
2465 VincentSDSH-33016
                local toselect = num + FauxScrollFrame_GetOffset(NotesTOCScrollBar)
2466 VincentSDSH-33016
 
2467 VincentSDSH-33016
                Notes_GoToPage(toselect)
2468 VincentSDSH-33016
        end
2469 VincentSDSH-33016
end
2470 VincentSDSH-33016
 
2471 VincentSDSH-33016
function Notes_LoadPrevPage()
2472 VincentSDSH-33016
        return Notes_GoToPage(Notes_BookPage - 1)
2473 VincentSDSH-33016
end
2474 VincentSDSH-33016
 
2475 VincentSDSH-33016
function Notes_LoadNextPage()
2476 VincentSDSH-33016
        return Notes_GoToPage(Notes_BookPage + 1)
2477 VincentSDSH-33016
end
2478 VincentSDSH-33016
 
2479 VincentSDSH-33016
function Notes_GoToPage(pagenum)
2480 VincentSDSH-33016
        if pagenum < 0 or pagenum > getn(Notes_BookPages) then
2481 VincentSDSH-33016
                Notes_ErrorPrint("Page out of range (0-"..getn(Notes_BookPages)..")")
2482 VincentSDSH-33016
                return Notes_SetButtonState(1)
2483 VincentSDSH-33016
        end
2484 VincentSDSH-33016
 
2485 VincentSDSH-33016
        Notes_MultiSelected = {}
2486 VincentSDSH-33016
 
2487 VincentSDSH-33016
        Notes_BookPage = pagenum
2488 VincentSDSH-33016
        Notes_LoadSelected(Notes_GetNoteIndex(Notes_BookPages[Notes_BookPage]))
2489 VincentSDSH-33016
        if Notes_BookPage == 0 then
2490 VincentSDSH-33016
                Notes_LoadSelected(Notes_GetNoteIndex(Notes_BookID))
2491 VincentSDSH-33016
 
2492 VincentSDSH-33016
        elseif Notes_BookPage >= 1 and Notes_BookPage <= getn(Notes_BookPages) then
2493 VincentSDSH-33016
                local idx = Notes_GetNoteIndex(Notes_BookPages[Notes_BookPage])
2494 VincentSDSH-33016
                if idx then Notes_LoadSelected(idx) end
2495 VincentSDSH-33016
        end
2496 VincentSDSH-33016
end
2497 VincentSDSH-33016
 
2498 VincentSDSH-33016
function Notes_ReorderPage(targetpage)
2499 VincentSDSH-33016
        if not Notes_BookID or not Notes_Selected or not Notes_Notes[Notes_Selected] then return end
2500 VincentSDSH-33016
        if targetpage < 1 or targetpage > getn(Notes_BookPages) then
2501 VincentSDSH-33016
                Notes_ErrorPrint("Page out of range (1-"..getn(Notes_BookPages)..")")
2502 VincentSDSH-33016
                return Notes_SetButtonState(1)
2503 VincentSDSH-33016
        end
2504 VincentSDSH-33016
 
2505 VincentSDSH-33016
        local bookidx = Notes_GetNoteIndex(Notes_BookID)
2506 VincentSDSH-33016
        if not bookidx then return end
2507 VincentSDSH-33016
 
2508 VincentSDSH-33016
        local pages = Notes_Notes[bookidx]["book"]
2509 VincentSDSH-33016
        local curid = Notes_Notes[Notes_Selected]["id"]
2510 VincentSDSH-33016
        local newpages = {}
2511 VincentSDSH-33016
        local newpage = 1
2512 VincentSDSH-33016
        local oldpage = 1
2513 VincentSDSH-33016
 
2514 VincentSDSH-33016
        if targetpage == 1 then
2515 VincentSDSH-33016
                table.insert(newpages,Notes_Notes[Notes_Selected]["id"])
2516 VincentSDSH-33016
                newpage = newpage + 1
2517 VincentSDSH-33016
        end
2518 VincentSDSH-33016
 
2519 VincentSDSH-33016
        while true do
2520 VincentSDSH-33016
                if pages[oldpage] ~= Notes_Notes[Notes_Selected]["id"] then
2521 VincentSDSH-33016
                        table.insert(newpages,pages[oldpage])
2522 VincentSDSH-33016
                        newpage = newpage + 1
2523 VincentSDSH-33016
                end
2524 VincentSDSH-33016
 
2525 VincentSDSH-33016
                if newpage == targetpage then
2526 VincentSDSH-33016
                        table.insert(newpages,Notes_Notes[Notes_Selected]["id"])
2527 VincentSDSH-33016
                        newpage = newpage + 1
2528 VincentSDSH-33016
                end
2529 VincentSDSH-33016
 
2530 VincentSDSH-33016
                oldpage = oldpage + 1
2531 VincentSDSH-33016
                if not pages[oldpage] then break end
2532 VincentSDSH-33016
        end
2533 VincentSDSH-33016
 
2534 VincentSDSH-33016
        if getn(pages) == getn(newpages) then
2535 VincentSDSH-33016
                Notes_Notes[bookidx]["book"] = newpages
2536 VincentSDSH-33016
                Notes_GoToPage(targetpage)
2537 VincentSDSH-33016
        end
2538 VincentSDSH-33016
end