-- -- SearchSelectedText.lua: A NoteCase Pro LUA script by Daniel Hertrich, http://www.hermocom.com -- -- This script's author, Daniel Hertrich, hereby waives all copyright -- and related or neighboring rights to this script, pursuant to the -- Creative Commons CC0 Universal relinquishment of rights found at -- http://creativecommons.org/publicdomain/zero/1.0/ -- -- Purpose: Create a list of nodes which contain the selected text ("search related info") -- -- Usage: Mark some text in a note, then start the script. -- -- Result: The list pane will show all notes of the current document which contain the -- text which has been selected, either in the note text or in the note title. -- -- get info on the currently active document/note nDocID = Nc_Doc_ID_GetCur() nNoteCount = Nc_Doc_NoteCount(nDocID) strCurNoteID = Nc_Note_ID_GetCur(nDocID) if strCurNoteID == "" then Nc_GUI_MessageBox("Error: No note selected in the current document. Aborting.") return end nFrom, nTo = Nc_Note_SelectionRange_Get(nDocID, strCurNoteID) if nFrom == nTo then Nc_GUI_MessageBox("No text selected --> Nothing to search for. Aborting.") return end strSearchString = Nc_Note_Content_Get (nDocID, strCurNoteID, 0, nFrom, nTo) -- Clear list and switch to list pane view Nc_App_List_Switch(1) Nc_App_List_Clear() -- Search for selected string in all document notes (titles and body) nResultCount = 0 for i=1,nNoteCount do -- get info on the note (note indexes start from 0) strNoteID = Nc_Note_ID_GetByIdx(nDocID, i-1) strNoteText = Nc_Note_Content_Get( nDocID, strNoteID,0) strNoteTitle = Nc_Note_Title_Get( nDocID, strNoteID) -- if string is found, add the note to the list pane if (string.find(strNoteText,strSearchString)) or (string.find(strNoteTitle,strSearchString)) then Nc_App_List_AddNote(strNoteID) nResultCount = nResultCount + 1 end end -- if no results have been found, display a message and go (back) to tree view if nResultCount == 0 then Nc_GUI_MessageBox("No matches found in current document.") Nc_App_List_Switch(0) end