The file doesn't get deleted (Notes app)
Posted: Sun Apr 02, 2017 11:27 pm
I followed the "Notes" lessons and everything seems to work.
Except for the "delete" option. Files don't get deleted. Please see the code below.
Could it be because of the Windows permissions? If yes, how can I make it work?
Thank you
Vlad
<><><><><><><><><><>
-- Sent to the card when it is opened
-- Make any updates to the card and do any setup before the card is shown
on preOpenCard
-- Declare any local variables
local tFilePath
-- if the "noteName" field is empty then start a new note
if the label of widget "header" is empty then
newNote
else
-- if the "noteName" field is not empty then
-- get the full path to the note file
put noteFilename() into tFilePath
-- display the contents of the note file in the "noteText" field
put url ("file:" & tFilePath) into field "noteText"
end if
end preOpenCard
--
-- newNote
-- DESCRIPTION:
-- Prepare the card for a new note
-- Empty the "noteName" and "noteText" fields
-- Display the current date in the "date" field
--
command newNote
-- Clear the "noteName" and "noteText" fields
set the label of widget "header" to empty
put empty into field "noteText"
-- Display the current date in the "date" field
put the long system date into field "date"
end newNote
--
-- saveNote
-- DESCRIPTION:
-- Saves the note out to a text file
-- If there is no content in the note nothing is saved
-- Otherwise a file is created in the notes folder,
-- The name of the file is the first 15 characters of the note text
-- After the note is saved go to the "list" card
--
command saveNote
-- Declare any local variables
local tFilePath
-- Check that there is text in the note
if field "noteText" is not empty then
-- Get the full path to the note file
put noteFilename() into tFilePath
-- Save the text to the file
put field "noteText" into url ("file:" & tFilePath)
end if
-- Go to the "list" card using a transition animation
visual effect "push" right fast
go to card "list"
end saveNote
--
-- deleteNote
-- DESCRIPTION:
-- Deletes a note by deleting the file it is saved in
-- Asks for confirmation from the user that the note is to be deleted
-- After the note is deleted go to the "list" card
--
command deleteNote
-- Declare any local variables
local tFilePath
-- Ask for confirmation from the user
answer "Do you want to delete this note?" With "Yes" and "No"
if it is "Yes" then
-- Get the full path to the note file
put noteFilename() into tFilePath
-- Delete the file the note is saved in
delete file tFilePath
end if
-- Go to the "list" card using a transition animation
visual effect "push" right fast
go to card "list"
end deleteNote
--
-- noteFilename
-- DESCRIPTION:
-- Returns the full path to the file a note is saved in
--
function noteFilename
-- Declare any local variables
local tFilePath, tFileName
-- If the "noteName" field is empty
-- then the first 15 characters of the note text are used as the name of the file
if the label of widget "header" is empty then
put character 1 to 15 of field "noteText" & ".txt" into tFileName
else
-- Otherwise the current name is used
put the label of widget "header" & ".txt" into tFileName
end if
-- Construct the full path to the file
put notesFolder() & "/" & tFileName into tFilePath
-- Return the full path
return tFilePath
end noteFilename
Except for the "delete" option. Files don't get deleted. Please see the code below.
Could it be because of the Windows permissions? If yes, how can I make it work?
Thank you
Vlad
<><><><><><><><><><>
-- Sent to the card when it is opened
-- Make any updates to the card and do any setup before the card is shown
on preOpenCard
-- Declare any local variables
local tFilePath
-- if the "noteName" field is empty then start a new note
if the label of widget "header" is empty then
newNote
else
-- if the "noteName" field is not empty then
-- get the full path to the note file
put noteFilename() into tFilePath
-- display the contents of the note file in the "noteText" field
put url ("file:" & tFilePath) into field "noteText"
end if
end preOpenCard
--
-- newNote
-- DESCRIPTION:
-- Prepare the card for a new note
-- Empty the "noteName" and "noteText" fields
-- Display the current date in the "date" field
--
command newNote
-- Clear the "noteName" and "noteText" fields
set the label of widget "header" to empty
put empty into field "noteText"
-- Display the current date in the "date" field
put the long system date into field "date"
end newNote
--
-- saveNote
-- DESCRIPTION:
-- Saves the note out to a text file
-- If there is no content in the note nothing is saved
-- Otherwise a file is created in the notes folder,
-- The name of the file is the first 15 characters of the note text
-- After the note is saved go to the "list" card
--
command saveNote
-- Declare any local variables
local tFilePath
-- Check that there is text in the note
if field "noteText" is not empty then
-- Get the full path to the note file
put noteFilename() into tFilePath
-- Save the text to the file
put field "noteText" into url ("file:" & tFilePath)
end if
-- Go to the "list" card using a transition animation
visual effect "push" right fast
go to card "list"
end saveNote
--
-- deleteNote
-- DESCRIPTION:
-- Deletes a note by deleting the file it is saved in
-- Asks for confirmation from the user that the note is to be deleted
-- After the note is deleted go to the "list" card
--
command deleteNote
-- Declare any local variables
local tFilePath
-- Ask for confirmation from the user
answer "Do you want to delete this note?" With "Yes" and "No"
if it is "Yes" then
-- Get the full path to the note file
put noteFilename() into tFilePath
-- Delete the file the note is saved in
delete file tFilePath
end if
-- Go to the "list" card using a transition animation
visual effect "push" right fast
go to card "list"
end deleteNote
--
-- noteFilename
-- DESCRIPTION:
-- Returns the full path to the file a note is saved in
--
function noteFilename
-- Declare any local variables
local tFilePath, tFileName
-- If the "noteName" field is empty
-- then the first 15 characters of the note text are used as the name of the file
if the label of widget "header" is empty then
put character 1 to 15 of field "noteText" & ".txt" into tFileName
else
-- Otherwise the current name is used
put the label of widget "header" & ".txt" into tFileName
end if
-- Construct the full path to the file
put notesFolder() & "/" & tFileName into tFilePath
-- Return the full path
return tFilePath
end noteFilename