Last active
August 29, 2015 14:05
-
-
Save Marbux/961d5aa3244993e42cae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
NoteCase Pro outliner function (Lua 5.2) | |
See http://www.notecasepro.com/ | |
FUNCTION NAME: Test_Read_Only_Properties | |
v. 0.1.3 | |
PURPOSE: The Test_Read_Only_Properties function tests the document and note identified by parameters nDocID and strNoteID for the read-only property of each, then returns informative message strings for use in error messages and a boolean true if the script should terminate because either the note or document is read-only. | |
If both the document and the note are read-write the function returns an empty string and a boolean false. | |
If both the document and the note are read-only, the function returns the string, "ERROR: Both the document and note are read-only. Cannot make requested changes. Terminating script. To proceed, open the Document Properties dialog and change the Read-Only setting. Then open the Note Properties dialog and change the Read-Only setting. Execute script again." The function also returns a boolean true. | |
If the document is read-only but the note is read-write, the function returns the string, "ERROR: The document is read-only. Cannot make requested changes. Terminating script. To proceed, open the Document Properties dialog and change the Read-Only setting. Then try again." The function also returns a boolean true. | |
If the document is read-write but the note is read-only, the function returns the string, "ERROR: The note is read-only. Cannot make requested changes. Terminating script. To proceed, open the Note Properties dialog and change the Read-Only setting. Then try again." The function also returns a boolean true. | |
USAGE INSTRUCTIONS: See the commented test script following the function below. But load this function from your script using (assuming the function is in the same document): | |
-- gets this script's document ID | |
nScriptDocID = Nc_Script_DocID_Get() | |
-- loads Test_Read_Only_Properties Function | |
Nc_Script_Execute(nScriptDocID, "M5DSbhiT6x6kzVBbr6eaOw") | |
If that produces an error, either: | |
[i] this note's ID has been changed (check to see if you have two copies of this note in your script document; NoteCase Pro forces a new note ID if the note ID is already in use in the same document); or | |
[ii] this note is not located in the same document as your script. | |
RIGHTS: This function's author, Paul E. Merrell, waives all copyright and related or neighboring rights to this function, pursuant to the Creative Commons CC0 Universal relinquishment of rights found at http://creativecommons.org/publicdomain/zero/1.0/ | |
--]] | |
function Test_Read_Only_Properties(nDocID, strNoteID) | |
local nReadOnlyNote = Nc_Note_Flag_ReadOnly_Get(nDocID, strNoteID) | |
local nReadOnlyDoc = Nc_Doc_ReadOnly_Get(nDocID) | |
if nReadOnlyNote == 0 and nReadOnlyDoc == 0 then | |
strMessage = "" -- both read/write | |
bTerminate = false | |
end | |
if nReadOnlyNote == 0 and nReadOnlyDoc == 1 then | |
strMessage = "ERROR: The document is read-only. Cannot make requested change(s). Terminating script. To proceed, open the Document Properties dialog and change its read-only setting. Then try again." | |
bTerminate = true | |
end | |
if nReadOnlyNote == 1 and nReadOnlyDoc == 0 then | |
strMessage = "ERROR: The note is read-only. Cannot make requested change(s). Terminating script. To proceed, open the Note Properties dialog and change its read-only setting. Then try again." | |
bTerminate = true | |
end | |
if nReadOnlyNote == 1 and nReadOnlyDoc == 1 then | |
strMessage = "ERROR: Both the document and note are read-only. Cannot make requested change(s). Terminating script. To proceed, open the Document Properties dialog and change its read-only setting. Open the Note Properties dialog and change its read-only setting. Then execute the script again." | |
bTerminate = true | |
end | |
return strMessage, bTerminate | |
end -- function | |
---[[ tests function | |
--gets doc and note IDs | |
local nDocID = Nc_Doc_ID_GetCur() | |
local strNoteID = Nc_Note_ID_GetCur(nDocID) | |
-- declares globals needed in function | |
strMessage = nil | |
bTerminate = nil | |
-- gets this script's document ID | |
-- nScriptDocID = Nc_Script_DocID_Get() | |
-- loads Test_Read_Only_Properties Function | |
-- Nc_Script_Execute(nScriptDocID, "M5DSbhiT6x6kzVBbr6eaOw") | |
-- executes function | |
local strMessage, bTerminate = Test_Read_Only_Properties(nDocID, strNoteID) | |
-- if either doc or note are read-only | |
if bTerminate == true then | |
-- throws appropriate error message and terminates script | |
local nDisplayWidth, nDisplayHeight = Nc_Env_DisplaySize_Get(0) | |
local nDlgWidth = .35 * nDisplayWidth | |
local nDlgHeight = .30 * nDisplayHeight | |
Nc_GUI_InfoBox(strMessage, 1, "ERROR", nDlgWidth, nDlgHeight) | |
return | |
end --if bTerminate == true | |
--]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check my fork ;) https://gist.github.com/SoniEx2/1f966701a744e0352669