Text editor တခု ေရးၾကမယ္
New, Open, Save ၃ မ်ိဳးပါတဲ့ Text editor တခုေရးျပထားပါတယ္။ အလြယ္ကူဆံုး ျဖစ္ေအာင္ txt ဖိုင္ကို FileDirRootExternal directory မွာ ပံုေသ ထားထားပါတယ္။ Code ေတြကို နားလည္ေအာင္ ဖတ္ပါ။ ထပ္မံ ခ်ဲ႕ထြင္ၾကည့္ပါ။
================
Views Panel
================
dim f(0)
Dir=FileDirRootExternal
fname="Untitled.txt"
Setactivitytitle(fname)
AddPanel("pnlOpen",0,0,100%x,100%y,"")
AddListView("lv",0,0,100%x,100%y,"pnlOpen")
SetVisible("pnlOpen",false)
AddPanel("pnlEditor",0,0,100%x,100%y,"")
AddEditText("et",0,0,100%x,100%y,"pnlEditor")
AddMenuItem("New")
AddMenuItem("Open")
AddMenuItem("Save")
================
Events Panel
================
Sub Activity_Pause(UserClosed)
End Sub
Sub Activity_Resume
End Sub
Sub ListView_ItemClick(who, pos, value)
if StringEndsWith(value,".txt") then
str=FileReadString(Dir,value)
fname=value
SetActivityTitle(fname)
SetText("et",str)
SetVisible("pnlOpen",false)
SetVisible("pnlEditor",true)
end if
End Sub
Sub Menu_Click(Which)
select which
case "New"
SetText("et","")
fname="Untitled.txt"
SetActivityTitle(fname)
case "Open"
clear("lv")
FileListFiles(Dir,"f")
AddAll("lv","f")
SetVisible("pnlOpen",true)
SetVisible("pnlEditor",false)
case "Save"
a=inputBox("Enter File name to be saved.","Save File","OK","Cancel","")
if a=-1 then
fname=GetInput
SetActivityTitle(fname)
FileWriteString(Dir,fname,getText("et"))
ShowToast("File saved successfully",false)
end if
end select
end sub
Sub Edit_Change(Who, Old, New)
End Sub
Sub Edit_enterpressed(who)
End Sub
================
No comments:
Post a Comment