Δευτέρα, 11 Απριλίου 2016

Αναθεώρηση 209 και παράδειγμα Notepad (εκδ.1)

Η αναθεώρηση χρειάστηκε για να βελτιστοποιηθεί ο κώδικας. Το παράδειγμα είναι μεγάλο,
208 γραμμές (έχει και μερικές κενές). Μπορούμε να το γράψουμε σε ένα txt αρχείο με επέκταση gsb, και να το τρέξουμε ζητώντας να το εκτελέσει το m2000.exe Δεν ανοίγει η κονσόλα και εμφανίζεται άμεσα το παράθυρο, με τρία μενού και δυνατότητα resize. Μπορούμε να ανοίξουμε και άλλες φορές το πρόγραμμα, δηλαδή να ανοίξουμε και άλλα παράθυρα. Καθένα θα έχει ένα κείμενο. Το κείμενο αν είναι Bas, θα χρωματίζει τον κώδικα της VB6. Ο φάκελος ανοίγει μόνο για το φάκελο του χρήστη.



Αν εδώ : Open.file filename$,,"Load Text ("+typ$+") File",typ$
το αλλάξουμε έτσι: Open.file filename$,"*","Load Text ("+typ$+") File",typ$
τότε ανοίγει στο μέγιστο..(επιλέγουμε δίσκο) ή αν θέλουμε βάζουμε αυτό "c:\" για να περιορίσουμε στον C μόνο.

όπως είναι στο πρόγραμμα τώρα δεν βγαίνει ".." για να πάμε πάνω στο φάκελο Μόνο σε υποφακέλους μπορούμε να μπούμε





MODULE A {\\ notepad
Clear \\ Clear all variables/objects
Flush \\ Empty the stack
Title$="M2000 Pad"
typ$="txt"
Dir User
'Title Title$, 0
Declare NotePad Form
Declare Pad EditBox Form NotePad
Declare File1 Combobox Form NotePad
Declare Edit1 Combobox Form NotePad
Declare Help1 Combobox Form NotePad
With File1,"label","File", "listtext" As list$, "list" As list$() '
With Edit1,"label","Edit",  "Mark", Color(255,100,0)
With Help1,"label","Help",  "Mark", Color(255,100,0)
With NotePad, "Title" As Caption$, "Visible" As Visible, "TitleHeight" As tHeight, "Sizable", True
With Pad, "Text" As Pad.Text$, "ShowAlways", True,"NoColor", True
Def TitleStr$(a$)=ucase$(left$(a$,1))+mid$(a$,2)
Filename$=Dir$+"Untitled.txt"
Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad"
Method NotePad,"move", 2000, 4000, 8000, 4000
Layer NotePad {Cls #FFA000}
With File1,"MenuStyle", True, "MenuWidth", 3000 
With Edit1,"MenuStyle", True, "MenuWidth", 3000 
With Help1,"MenuStyle", True, "MenuWidth", 3000 
With File1, "MenuEnabled" As mEnable()
For This {
      mi$="MenuItem"  \\ is a temporary variable only for For This Block
      Method File1, mi$,"Open",True
      Method File1, mi$,"Save",True
      Method File1, mi$,""    \\  only  a line here
      Method File1,"MenuRadio","txt files",True,True
      Method File1,"MenuRadio","bas files",True,False
      
      Method File1, mi$,""
      Method File1, mi$,"Close",True
      Method File1, mi$,""
      Method File1, mi$,"Quit",True
      
      Method Edit1, mi$,"Cut",True
      Method Edit1, mi$,"Copy",True
      Method Edit1, mi$,"Paste",True
      
      Method Help1, mi$,"About",True
}
Document BackUp$="Write something..."
Pad.Text$=BackUp$
Function NotePad.Unload {
      Read New &Ok
      After 30 {call local File1.DblClick(8) }
      Ok=True


}
Function Notepad.Resize {
      Layer NotePad { Cls Color(255, 160, 0) ,0}
      With NotePad, "Width" As NP.Width, "Height" As NP.Height, "TitleHeight" As tHeight
      tHeight1=theight*2
      Method File1,"move", twipsX*2, tHeight,  twipsX*80, tHeight
      Method Edit1,"move", twipsX*2+twipsX*80, tHeight,  twipsX*80, tHeight
      Method Help1,"move", twipsX*2+twipsX*160, tHeight,  twipsX*80, tHeight
      If NP.height>2000 Then {
            Method Pad,"move", twipsX*2, tHeight1,  NP.Width-twipsX*5, NP.Height-tHeight1-twipsx*3
            With Pad, "NoWrap" As NoWrap
            If Not NoWrap Then Method Pad,"Resize"
      }
}
Function Edit1.DblClick {
      Read Local Edit1index
      Select Case Edit1index
      Case 0
            {
            Method Pad,"mn1sub"
            Method Pad,"Resize"
            }
      Case 1
            Method Pad,"mn2sub"
      Case 2
            {
                 Method Pad, "mn3sub"
                 Method Pad,"GetFocus"
                 Method Pad,"Resize"
           }
      End Select


}
Function Pad.PopUp {
      Read Local X, Y
      Method Pad,"PopUpMenu", "",X , Y
}
Function File1.MenuChecked {
Read New RadioIndex \\ 3 or 4
If RadioIndex =3 then {
      After 30 { local a$="."+file.type$(Filename$), b$=File.name$(Filename$)
      Filename$=File.path$(Filename$)+Left$(B$,Len(B$)-Len(a$))+".txt"
      Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad"
      typ$="txt"
      With Pad, "ColorCollection1", "","NoColor", True
      Method Pad, "Show"
      }
} else.if RadioIndex =4 then {
     After 30 { static a$="."+file.type$(Filename$), b$=File.name$(Filename$)
      Filename$=File.path$(Filename$)+Left$(B$,Len(B$)-Len(a$))+".bas"
      Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad"
      typ$="bas"
      With Pad, "ColorCollection1", "|AND|OR|XOR|NOT|CLS|DEBUG.|PRINT|DECLARE|CONST|GOTO|DO|LOOP|WHILE|WEND|WITH|REFRESH|LET|GET|SET|DOEVENTS|SELECT|CASE|FALSE|TRUE|OPTION|EXPLICIT|LIB|DIM|REDIM|PUBLIC|PRIVATE|FUNCTION|SUB|IF|THEN|ELSE|ELSEIF|END|SELECT|FOR|NEXT|TO|AS|LONG|BOOLEAN|STRING|OBJECT|EXIT|BYVAL|NEW|LEFT$(|LEFT(|RIGHT$(|RIGHT(|MID$(|MID(|UBOUND(|LBOUND(|CSTR(|CDBL(|CLNG(|STR$(|STRING$(|INSTR(|ASC(|CHR(|CHR$(|COS(|SIN(|LOG(|RGB(|REPLACE(|","NoColor", False
      Method Pad, "ReColor"
      Method Pad, "Show"
      }
}


}
Function File1.DblClick {
\\ we use functions As subs here
\\ each function and each module have a name (define a namespace)
\\ but here real module name is the File1.DblClick() host module
\\ this is done because is a Gui Event Service Function
\\ and is call with Local tag (Call Local)
      Read New File1index
      Local cont, cont2, f$, NL$={
      }
      File1index++
      \\ Because we want some jumps..we use  On Goto
      \\ on Goto need here a block
      {
      On File1index Goto Open1, Save1, ExitNow, ExitNow, ExitNow, ExitNow, Save2, ExitNow,  Unload
Exitnow:
      Exit
Open1:
      If Pad.Text$<>BackUp$ Then {
            If ask("Save Changes first?",Title$)=1 Then Goto Save1
      }
     Layer NotePad {
           Open.file filename$,,"Load Text ("+typ$+") File",typ$
     }
     Method Pad,"GetFocus"
     Read f$
     If f$<>"" Then {
           Filename$=f$
           If exist(F$) then {
           Clear BackUp$
           Load.Doc BackUp$, f$
           
           Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad"
           Pad.Text$=BackUp$
           } else Pad.text$="": Clear BackUp$
           Method Pad, "ReColor"
      }
      Exit
Save1:
      Layer NotePad {
            Save.As Filename$,,"Save Text ("+typ$+") File",typ$
      }
      if not cont2 then Method Pad,"GetFocus"
      Read f$
      If f$="" Then Exit 
      If lcase$(file.type$(f$))<>typ$ then f$=f$+"."+typ$
      If Exist(f$) Then  If Ask(NL$+"Overwrite"+NL$+f$,Title$)<>1 Then Exit
      Try ok {
        Clear BackUp$
        BackUp$=Pad.Text$
        Save.Doc BackUp$, f$
        filename$=f$
        Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad"
      }
     If ok else beep
     If not cont then Exit
Save2:
      cont=True
      If Pad.Text$<>BackUp$ Then {
            If ask("Save Changes?",Title$)=1 Then Goto Save1
      }
      Clear BackUp$
      Pad.Text$=""
      If Cont2 then {
            Method NotePad, "CloseNow"
      } Else {
            FileName$=Dir$+"Untitled."+typ$
            Caption$=TitleStr$(File.Name$(Filename$)) +" - M2000 Pad"
            Method Pad, "Resize"
      }
      Exit
Unload:
      Cont2=True : Goto Save2
      }
}
Function Help1.DblClick {
      Local A, info$
      Info$={
            This is an example
            of a notepad
            written for M2000 Environment
            use F1 to change wrap
            }
      A=Ask(info$,Title$,"","")


}
Call Local Notepad.Resize()
\\ open As modal


Method NotePad,"Show" , 1


Declare Pad Nothing
Declare NotePad Nothing 
Print "Done"


}
A: end