You've already forked lazarus-ccr
LazEdit: in ParseCommandlineFilenames ask to create a file if it does not exsist.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7257 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -201,6 +201,7 @@ type
|
|||||||
// Other main.pp constants
|
// Other main.pp constants
|
||||||
SLine, SCol, SModified, SIns, SOvr,
|
SLine, SCol, SModified, SIns, SOvr,
|
||||||
msgOpenError, msgSaveError, msgSaveAllError, msgFileIsNotText,
|
msgOpenError, msgSaveError, msgSaveAllError, msgFileIsNotText,
|
||||||
|
msgFileCreateError, msgAskCreateFile,
|
||||||
msgFileNotFound, msgModifiedSave, msgMruIndexOutOfBound,
|
msgFileNotFound, msgModifiedSave, msgMruIndexOutOfBound,
|
||||||
msgFileTypeNotForBrowser, msgFileHasNoName, msgErrorBrowser,
|
msgFileTypeNotForBrowser, msgFileHasNoName, msgErrorBrowser,
|
||||||
msgTextNotFound: string;
|
msgTextNotFound: string;
|
||||||
@ -348,6 +349,8 @@ begin
|
|||||||
msgSaveAllError := 'The following save all error has occured:'^m'%s';
|
msgSaveAllError := 'The following save all error has occured:'^m'%s';
|
||||||
msgFileIsNotText := 'The selected file '^m'%s'^m' does not seam to be a text file.';
|
msgFileIsNotText := 'The selected file '^m'%s'^m' does not seam to be a text file.';
|
||||||
msgFileNotFound := 'File not found:'^m'%s';
|
msgFileNotFound := 'File not found:'^m'%s';
|
||||||
|
msgFileCreateError := 'Error creating file: '^m'%s';
|
||||||
|
msgAskCreateFile := MsgFileNotFound + ^m^m'Create file?';
|
||||||
msgModifiedSave := 'The following file was modified:'^m'%s'^m'Should it be saved?';
|
msgModifiedSave := 'The following file was modified:'^m'%s'^m'Should it be saved?';
|
||||||
msgMruIndexOutOfBound := 'Index out of bounds [%d]'^m;
|
msgMruIndexOutOfBound := 'Index out of bounds [%d]'^m;
|
||||||
msgFileTypeNotForBrowser := 'The file type is not suited for a browser.'^m+'Continue anyway?';
|
msgFileTypeNotForBrowser := 'The file type is not suited for a browser.'^m+'Continue anyway?';
|
||||||
@ -507,6 +510,8 @@ begin
|
|||||||
msgSaveAllError := 'De volgende bestanden zijn niet opgeslagen:'^m'%s';
|
msgSaveAllError := 'De volgende bestanden zijn niet opgeslagen:'^m'%s';
|
||||||
msgFileIsNotText := 'Dit bestand lijkt geen tekstbestand te zijn'^m'%s'^m'Wilt u het toch openen?';
|
msgFileIsNotText := 'Dit bestand lijkt geen tekstbestand te zijn'^m'%s'^m'Wilt u het toch openen?';
|
||||||
msgFileNotFound := 'Bestand niet gevonden:'^m'%s';
|
msgFileNotFound := 'Bestand niet gevonden:'^m'%s';
|
||||||
|
msgFileCreateError := 'Fout bij aanmaken van bestand: '^m'%s';
|
||||||
|
msgAskCreateFile := MsgFileNotFound + ^m^m'Bestand aanmaken?';
|
||||||
msgModifiedSave := 'Bestand is gewijzigd:'^m'%s'^m'Bestand opslaan?';
|
msgModifiedSave := 'Bestand is gewijzigd:'^m'%s'^m'Bestand opslaan?';
|
||||||
msgMruIndexOutOfBound := 'Index voor recent geopende bestanden ligt buiten de grenzen [%d]'^m+
|
msgMruIndexOutOfBound := 'Index voor recent geopende bestanden ligt buiten de grenzen [%d]'^m+
|
||||||
'Dit is uiteraard een fout van de programmeur';
|
'Dit is uiteraard een fout van de programmeur';
|
||||||
|
@ -467,10 +467,12 @@ type
|
|||||||
function TryMarkSelection(const Pre, Post: String): Boolean;
|
function TryMarkSelection(const Pre, Post: String): Boolean;
|
||||||
public
|
public
|
||||||
//File procedures
|
//File procedures
|
||||||
|
function AskCreateFile(const Fn: String): Boolean;
|
||||||
function AskFileNameOpen: String;
|
function AskFileNameOpen: String;
|
||||||
function AskFileNameOpenTemplate: String;
|
function AskFileNameOpenTemplate: String;
|
||||||
function AskFileNameSave(const Fn: String; const FileType: TEditorFileType): String;
|
function AskFileNameSave(const Fn: String; const FileType: TEditorFileType): String;
|
||||||
function AskFileNameSaveTemplate: String;
|
function AskFileNameSaveTemplate: String;
|
||||||
|
function TryCreateEmptyFile(const Fn: String): Boolean;
|
||||||
function TryFileOpen(const Fn: String; const AsTemplate: Boolean = False): Boolean;
|
function TryFileOpen(const Fn: String; const AsTemplate: Boolean = False): Boolean;
|
||||||
function TryFileSave(Editor: TEditor; Fn: String): TIoResult;
|
function TryFileSave(Editor: TEditor; Fn: String): TIoResult;
|
||||||
function CloseCurrentEditor: Boolean;
|
function CloseCurrentEditor: Boolean;
|
||||||
@ -1600,9 +1602,26 @@ begin
|
|||||||
S := ExpandFileNameUtf8(S); //we want full filename here, e.g. for filename in statusbar
|
S := ExpandFileNameUtf8(S); //we want full filename here, e.g. for filename in statusbar
|
||||||
if FileExistsUtf8(S) then
|
if FileExistsUtf8(S) then
|
||||||
begin
|
begin
|
||||||
if not TryFileOpen(S) then ShowError(Format(vTranslations.msgOpenError,[S]));
|
if not TryFileOpen(S) then
|
||||||
|
ShowError(Format(vTranslations.msgOpenError,[S]))
|
||||||
|
else
|
||||||
|
Inc(Count);
|
||||||
end
|
end
|
||||||
else ShowError(Format(vTranslations.msgFileNotFound,[S]));
|
else
|
||||||
|
begin
|
||||||
|
if AskCreateFile(S) then
|
||||||
|
begin
|
||||||
|
if TryCreateEmptyFile(S) then
|
||||||
|
begin
|
||||||
|
if not TryFileOpen(S) then
|
||||||
|
ShowError(Format(vTranslations.msgOpenError,[S]))
|
||||||
|
else
|
||||||
|
Inc(Count);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ShowError(Format(vTranslations.msgFileCreateError,[S]));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
//Start with blank page if no files are specified on commandline
|
//Start with blank page if no files are specified on commandline
|
||||||
@ -1987,6 +2006,11 @@ begin
|
|||||||
else Result := False;
|
else Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLazEditMainForm.AskCreateFile(const Fn: String): Boolean;
|
||||||
|
begin
|
||||||
|
Result := MessageDlg(AppName, Format(vTranslations.msgAskCreateFile,[Fn]), mtConfirmation, [mbYes, mbNo],0) = mrYes;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -2062,6 +2086,15 @@ begin
|
|||||||
else Result := EmptyStr;
|
else Result := EmptyStr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLazEditMainForm.TryCreateEmptyFile(const Fn: String): Boolean;
|
||||||
|
var
|
||||||
|
H: THandle;
|
||||||
|
begin
|
||||||
|
H := FileCreate(Fn, fmOpenWrite);
|
||||||
|
Result := H <> feInvalidHandle; //THandle(-1)
|
||||||
|
if Result then FileClose(H);
|
||||||
|
end;
|
||||||
|
|
||||||
function TLazEditMainForm.TryFileOpen(const Fn: String; const AsTemplate: Boolean = False): Boolean;
|
function TLazEditMainForm.TryFileOpen(const Fn: String; const AsTemplate: Boolean = False): Boolean;
|
||||||
var
|
var
|
||||||
Ed: TEditor;
|
Ed: TEditor;
|
||||||
|
Reference in New Issue
Block a user