WoWInterface SVN Notes

[/] [branches/] [WotLK/] [Notes_Export/] [Notes_Export.lua] - Rev 2

Compare with Previous | Blame | View Log

function Notes_ExportUIToggle(mode)
        if mode==nil or mode=="" then mode = "toggle" end
        
        if mode == "hide" or (mode=="toggle" and NotesExportFrame:IsVisible()) then
                Notes_ExportMode = false
                Notes_SetButtonState()
                
        elseif mode == "show" or mode=="toggle" then
                Notes_ExportMode = true
                Notes_SetButtonState()
        end
end

function Notes_ImportNotes()
        local idlookup = {}
        local titlelookup = {}
        
        local startid = Notes_MakeNoteID()

        for i=1,getn(Notes_Import) do
                idlookup[Notes_Import[i]["id"]] = tostring(tonumber(Notes_Import[i]["id"]) + tonumber(math.mod(math.abs(tonumber(startid)-tonumber(Notes_Import[1]["id"])),999999)))
                titlelookup[idlookup[Notes_Import[i]["id"]]] = Notes_Import[i]["title"]
        end
        for i=1,getn(Notes_Import) do
                local bookname = nil
                Notes_Import[i]["id"] = idlookup[Notes_Import[i]["id"]]
                if type(Notes_Import[i]["book"]) == "table" then
                        local newpages = {}
                        for j=1,getn(Notes_Import[i]["book"]) do
                                if idlookup[Notes_Import[i]["book"][j]] then
                                        table.insert(newpages,idlookup[Notes_Import[i]["book"][j]])
                                end                             
                        end
                        Notes_Import[i]["book"] = newpages
                        
                elseif type(Notes_Import[i]["book"]) == "string" then
                        if idlookup[Notes_Import[i]["book"]] then
                                Notes_Import[i]["book"] = idlookup[Notes_Import[i]["book"]]
                                bookname = titlelookup[Notes_Import[i]["book"]]
                        else
                                Notes_Import[i]["book"] = false
                        end
                end
                Notes_NewNote(Notes_Import[i]["title"],Notes_Import[i]["text"],Notes_Import[i]["sync"],Notes_Import[i]["locked"],Notes_Import[i]["id"],Notes_Import[i]["book"],bookname)
        end
        
        for i=1,getn(Notes_Import) do
                if type(Notes_Import[i]["book"]) ~= "string" then
                        local idx = Notes_GetNoteIndex(Notes_Import[i]["id"])
                        if idx and idx ~= Notes_Selected then
                                table.insert(Notes_MultiSelect,idx)                             
                        end
                end
        end     
        Notes_ScrollBarUpdate() 
end

function Notes_ExportSelected(idx,midx)
        local index = Notes_Selected
        local mindex = Notes_MultiSelect
        if idx then index = idx end     
        if midx then mindex = midx end
                
        if not index or not Notes_Notes[index] then Notes_ErrorPrint("No notes selected") return end
        
        Notes_Export = {}
        
        local selectstack = {}
        local exportstack = {}
        local bookcount = 0
        
        table.insert(selectstack,index) 
        if getn(mindex) > 0 then
                for i=1,getn(mindex) do
                        table.insert(selectstack,mindex[i])
                end
        end
        
        for i=1,getn(selectstack) do
                if type(Notes_Notes[selectstack[i]]["book"])=="table" then
                        if getn(Notes_Notes[selectstack[i]]["book"]) > 0 then
                                for j=1,getn(Notes_Notes[selectstack[i]]["book"]) do
                                        local pageidx = Notes_GetNoteIndex(Notes_Notes[selectstack[i]]["book"][j])
                                        if pageidx then
                                                table.insert(exportstack,pageidx) 
                                        end
                                end
                        end
                        bookcount = bookcount + 1               
                        table.insert(exportstack,selectstack[i])                
                else
                        table.insert(exportstack,selectstack[i])        
                end
        end
                
        for i=1,getn(exportstack) do
                table.insert(Notes_Export,Notes_Notes[exportstack[i]])
        end
        Notes_SuccessPrint(getn(exportstack) - bookcount.." notes and "..bookcount.." books exported")
        Notes_SuccessPrint("You must log out or reload your UI to save the changes.")
        Notes_SuccessPrint("Move the Notes_Export.lua file in your SavedVariables directory into the Interface/AddOns/Notes directory.")        
end

Compare with Previous | Blame