OSDN Git Service

7f0011c39ce9718536f3938a5a253af0cf30e01c
[ring-lang-081/ring.git] / applications / rnote / source / rnotetreeviewevents.ring
1 # The Ring Notepad Application (RNote)
2 # Author : Mahmoud Fayed <msfclipper@yahoo.com>
3
4 class RNoteTreeViewEvents
5
6         func CheckSaveBeforeChange
7                 if cActiveFileName = NULL return ok
8                 SaveSettings()
9
10         func ChangeFile
11                 CheckSaveBeforeChange() # To ask to saving a file
12                 SaveCurrentFolder()
13                 oItem = tree1.currentindex()
14                 if ofile.isdir(oItem)
15                         return
16                 ok
17                 # Save the old file 
18                         cOldActiveFileName = cActiveFileName
19                 # Open Form Designer File 
20                 lActivateFormDesigner = False
21                 if right(ofile.filepath(oItem),6) = ".rform"
22                         StatusMessage("Open the form file...")
23                         if ofile.filepath(oItem) != cFormFile 
24                                 cFormFile = ofile.filepath(oItem)
25                                 FormDesigner().OpenFile(ofile.filepath(oItem))
26                         ok
27                         StatusMessage("Ready!")
28                         oDockFormDesigner.raise()
29                         cSourceFile = substr(cFormFile,".rform","Controller.ring")
30                         if fexists(FileNameEncoding(cSourceFile))
31                                 cActiveFileName = cSourceFile
32                         else 
33                                 return 
34                         ok
35                         lActivateFormDesigner = True
36                 else 
37                         cActiveFileName = ofile.filepath(oItem)
38                 ok
39                 # We get nLine before using textedit1.settext() to get the value before aFilesLines update
40                         nLine =  aFilesLines[cActiveFileName]
41                 try 
42                         textedit1.setPlaintext(read(FileNameEncoding(cActiveFileName)))
43                 catch 
44                         msginfo("Sorry","Can't open the file " + cActiveFileName)
45                         cActiveFileName = cOldActiveFileName
46                         return 
47                 end 
48                 textedit1.setfocus(0)
49                 CursorPositionChanged()
50                 SetActiveFileName()
51                 if nLine != NULL
52                         gotoline(nLine)
53                 ok
54                 AutoComplete()
55                 lAsktoSave = False
56                 cTextHash  = sha256(textedit1.toplaintext())
57                 oDockFunctionsList.setWindowTitle("Functions (Loading...)")
58                 oDockClassesList.setWindowTitle("Classes (Loading...)")
59                 DisplayFunctionsList()
60                 DisplayClassesList()
61                 if lActivateFormDesigner
62                         oDockFormDesigner.raise()
63                 else 
64                         oDockSourceCode.raise()
65                         tree1.setFocus(0)
66                 ok
67                 StatusMessage("Ready!")