$TYPECHECK ON
$ESCAPECHARS ON
CONST dot = "." :CONST Quo$ = CHR$(39)
CONST false = 0 :CONST true = 1
CONST mtWarning = 0 :CONST mtConfirmation = 3
CONST mbYes = 1 :CONST mbNo = 2
CONST mbOK = 4 :CONST mbCancel = 8
CONST mrYes = 6 :CONST mrNo = 7
CONST mrCancel = 2 :CONST mrOK = 1
FUNCTION delMark$( s AS STRING ) AS STRING
s=REPLACESUBSTR$(s," ","")
s=REPLACESUBSTR$(s,"\t","")
delMark$=REPLACESUBSTR$(s,"*.","")
END FUNCTION
TYPE QSaveplus EXTENDS QSAVEDIALOG
Private:
saveDialogRet AS INTEGER
goOut AS INTEGER
FUNCTION item( i AS INTEGER ) AS STRING
Result = FIELD$( QSaveplus.Filter, "|", i*2 )
END FUNCTION
FUNCTION itemCount AS INTEGER
Result = TALLY(QSaveplus.Filter,"|")\2
END FUNCTION
FUNCTION extCount( i AS INTEGER ) AS INTEGER
Result = TALLY( QSaveplus.item( i ), "*." )
END FUNCTION
FUNCTION ext( t AS INTEGER, i AS INTEGER ) AS STRING
DIM e AS STRING
e = FIELD$( QSaveplus.item( t ), ";", i )
Result = delMark$( e )
END FUNCTION
FUNCTION Exten$ AS STRING
Result = QSaveplus.ext( QSaveplus.FilterIndex, 1 )
END FUNCTION
FUNCTION DirExist AS INTEGER
DIM fileDir$ AS STRING
DIM BslPos AS INTEGER
BslPos = RINSTR(QSaveplus.Filename,"\\")
fileDir$ = DELETE$(QSaveplus.Filename, BslPos+1, LEN(QSaveplus.Filename)-BslPos)
Result = DIREXISTS(fileDir$)
END FUNCTION
FUNCTION NoExten AS INTEGER
DIM FileLC$ AS STRING
DIM EachExt$ AS STRING
DIM FoundExt AS INTEGER
DIM cou AS INTEGER
FoundExt=False
FileLC$ = LCASE$(QSaveplus.FileName)
FOR cou = 1 TO QSaveplus.ExtCount( QSaveplus.FilterIndex )
EachExt$ = dot+LCASE$( QSaveplus.Ext( QSaveplus.FilterIndex, cou ) )
IF RIGHT$(FileLC$,LEN(EachExt$)) = EachExt$ THEN
FoundExt = True
EXIT FOR
END IF
NEXT
IF FoundExt = False THEN
Result = True
ELSE
Result = False
END IF
END FUNCTION
FUNCTION PlusExt AS STRING
IF RIGHT$(QSaveplus.Filename,1) = dot THEN
Result = QSaveplus.Filename+QSavePlus.Exten$
ELSE
Result = QSaveplus.Filename+dot+QSavePlus.Exten$
END IF
END FUNCTION
FUNCTION Validname AS INTEGER
IF INSTR(QSaveplus.Filename,">") <> 0 THEN
Result = False
ELSE
Result = True
END IF
END FUNCTION
SUB goOutTrue
QSavePlus.goOut = True
END SUB
SUB FileExistDlg
IF FILEEXISTS(QSaveplus.Filename) THEN
IF MESSAGEDLG(Quo$+QSaveplus.FileName+Quo$+_
" already exists.\r\nDo you want to replace it?",_
mtConfirmation, mbYes OR mbNo, 0) = mrYes THEN
QSavePlus.goOutTrue
END IF
ELSE
QSavePlus.goOutTrue
END IF
END SUB
Public:
FUNCTION Execute2 AS INTEGER
DIM mrValue AS INTEGER
QSavePlus.goOut = False
DO
QSavePlus.saveDialogRet = QSaveplus.EXECUTE
IF QSavePlus.saveDialogRet = False THEN
QSavePlus.goOutTrue
ELSE
IF QSavePlus.Validname = True THEN
IF QSavePlus.dirExist = False THEN
MESSAGEDLG(QSaveplus.Filename+_
"\r\nPath does not exist."+_
"\r\nPlease verify the correct path was given.",_
mtWarning, mbOK, 0)
QSaveplus.Filename=CURDIR$+"\\*."+QSavePlus.Exten$
ELSEIF QSavePlus.NoExten = True THEN
IF QSaveplus.FilterIndex = 1 THEN
QSavePlus.FileExistDlg
ELSE
mrValue=MESSAGEDLG(QSaveplus.FileName+_
"\r\nThere is no file extension in the file name."+_
"\r\nDo you want to add '"+QSavePlus.Exten$+"' extension automatically?",_
mtConfirmation, mbYes OR mbNo OR mbCancel, 0)
IF (mrValue = mrYes) OR (mrValue = mrNo) THEN
IF mrValue = mrYes THEN
QSaveplus.Filename = QSavePlus.PlusExt
END IF
QSavePlus.FileExistDlg
END IF
END IF
ELSE
QSavePlus.FileExistDlg
END IF
ELSE
MESSAGEDLG(QSaveplus.Filename+_
"\r\nThe above file name is invalid.",_
mtWarning, mbOK, 0)
END IF
END IF
LOOP UNTIL QSavePlus.goOut = True
Result = QSavePlus.saveDialogRet
END FUNCTION
END TYPE
DECLARE SUB formClick
CREATE form AS QFORM
CREATE R AS QRICHEDIT
Text="abc\r\n123"
END CREATE
Center
OnClick = formClick
END CREATE
CREATE saveDlg AS QSaveplus
Filter = _
"All Files (*.*)" + "|*.*|"+_
"JavaScript (*.js)" + "|*.js|"+_
"PHP (*.php3,*.php)" + "|*.php3;*.php|"+_
"Perl (*.pl,*.pm,*.cgi)" + "|*.pl;*.pm;*.cgi|"+_
"Rapid-Q BASIC (*.rq,*.bas)" + "|*.rq;*.bas|"+_
"Html (*.html,*.htm)" + "|*.html;*.htm|"+_
"Text (*.txt)" + "|*.txt|"
END CREATE
SUB formClick
IF saveDlg.Execute2 = 1 THEN
SHOWMESSAGE "Save File.. "+saveDlg.FileName
ELSE
SHOWMESSAGE "No Save"
END IF
END SUB
form.SHOWMODAL
|