Search & Display

Here is a program that will allow you to search for a character, word, words, or special characters across all of your projects. For some special characters, a % sign needs to be placed in front of them because they are magic characters used by the find function. Currently you have to create the projectTable manually. Hopefully @Simeon will create a listProjects() function that will return a table of projects so the table won’t have to be updated manually. I have some of the example projects in the projectTable now. To use the program, tap the Parameters searchString area and enter what you want to search for. When you’re done, tap the Parameters search line and a list of all the “Project:Tabs” will show in the Output window. To see the code of any of the “Project:Tabs”, tap on one of them and the background will turn black indicating that it’s selected. Next you need to tap and hold the Parameters tabList area until the Paste bubble shows. Tap the Paste bubble to paste the “Project:Tab” in that area. The screen will switch to FULLSCREEN and then will show you the code for that “Project:Tab”. The name will show in red at the top of the screen and any line containing your search string will show as green. Use your finger to scroll the code up or down if it’s larger than the screen. To get back to the Parameters, just tap the icon (I don’t know what it’s called) in the upper left corner and you can select another “Project:Tab” to display. Or you can tap the searchString area and backspace to clear the string and enter another string to search. This program can also be used to quickly look at any “Project:Tab” just by doing a search for a . (period). All of the “Project:Tabs” should be listed and allow you to look at them without having to open and close the different projects. As I said, if Simeon creates a listProject() function, that will make this program easier to use.


supportedOrientations(PORTRAIT_ANY)

function setup()
    -- add your projects to the table. 
    projectTable={"Animation","Shaders","Camera","Parameters","Blend Modes","3D Lab","Spritely","Anagrams"}
    
    textMode(CORNER)
    tab1={}
    parameter.text("searchString","",clear)
    parameter.action("Search",getTab)
    parameter.text("tabList","",listTab)
end

function draw()
    background(40,40,50)
    if WIDTH<500 then
        tab1={}
        collectgarbage()
    end
    textWrapWidth(WIDTH)
    offset=0
    for z=1,#tab1 do
        w,h=textSize(tab1[z])
        offset = offset + h
        if z==1 then
            fill(255,0,0)
            text(tab1[z],250,cy+HEIGHT-offset)
        else
            fill(255)
            if string.find(tab1[z],searchString) then
                fill(0,255,0)
            end
            text(tab1[z],1,cy+HEIGHT-offset)
        end
    end
end

function clear()
    output.clear()
    tab1={}
end

function touched(t)
    cy=cy+t.deltaY
    if cy<0 then
        cy=0
    end
end

function listTab()
    if tabList~="" then
        tab1={}
        cy=0
        displayMode(FULLSCREEN)
        showKeyboard()
        hideKeyboard()
        xx=string.sub(tabList,1,string.len(tabList)-1)
        table.insert(tab1,"Project:Tab   "..xx)
        table.insert(tab1,"  ")
        show=readProjectTab(xx)
        e=1
        s=1
        while e~=nil do
            e=string.find(show,"\
",s)
            if e~=nil then
                st1=string.sub(show,s,e)
                table.insert(tab1,st1)
                s=e+1
            end
        end
        tabList=""
   end   
end

function search()
    e=1
    s=1
    while e~=nil do
        e=string.find(str,"\
",s)
        if e~=nil then
            str2=string.sub(str,s,e-1)
            if string.find(str2,searchString) then
                if tb~="" then
                    print(pro..":"..tb)
                    tb=""
                end
            end
            s=e+1
        end
    end
end

function getTab()
    output.clear()
    showKeyboard()
    hideKeyboard()
    for x,y in pairs(projectTable) do
        pro=y
        a=listProjectTabs(y)
        for x1,y1 in pairs(a) do
            tb=y1
            str=readProjectTab(y..":"..y1)
            search()
        end
    end
end 

I replaced the project table with the listProjects call, but it doesn’t work, Codea locks up and crashes!
It seems whatever I try to do, Codea locks up and crashes, it seems very buggy!

Honestly, I’d try to avoid the listProjects & listTabs calls and instead try to base your logic on the asset.documents.all list, filtering elements for ‘.codea’ project bundles. Then with each bundle, do the same with asset.documents[<project_here>].all filtering for ‘.lua’ files instead. You’d probably have better luck and avoid some crashes.