FIX: Show error when cannot create a new file.

This commit is contained in:
cobines 2011-10-30 21:21:30 +00:00
commit edba9d8663
2 changed files with 22 additions and 14 deletions

View file

@ -111,6 +111,8 @@ resourcestring
rsMsgCanNotCopyMoveItSelf = 'You can not copy/move a file "%s" to itself!';
rsMsgTabRenameCaption = 'Rename tab';
rsMsgTabRenamePrompt = 'New tab name:';
rsMsgErrCreateFileDirectoryExists = 'There already exists a directory named "%s".';
// for context menu
rsMnuActions = 'Actions';
rsMnuView = 'View';

View file

@ -2019,8 +2019,9 @@ end;
procedure TMainCommands.cm_EditNew(Param: String='');
var
sNewFile: String;
hFile: Integer = 0;
hFile: System.THandle = 0;
aFile: TFile;
Attrs: TFileAttrs;
begin
frmMain.ActiveFrame.ExecuteCommand('cm_EditNew', param);
@ -2046,21 +2047,26 @@ begin
if ExtractFilePath(sNewFile) = '' then
sNewFile:= ActiveFrame.CurrentPath + sNewFile;
if not mbFileExists(sNewFile) then
try
hFile:= mbFileCreate(sNewFile);
finally
if hFile > 0 then
FileClose(hFile);
Attrs := mbFileGetAttr(sNewFile);
if Attrs = faInvalidAttributes then
begin
hFile := mbFileCreate(sNewFile);
if hFile = feInvalidHandle then
begin
MessageDlg(rsMsgErrECreate, mbSysErrorMessage(GetLastOSError), mtWarning, [mbOK], 0);
Exit;
end;
try
ShowEditorByGlob(sNewFile);
finally
frameLeft.Reload;
frameRight.Reload;
FileClose(hFile);
ActiveFrame.FileSource.Reload(ExtractFilePath(sNewFile));
end
else if FPS_ISDIR(Attrs) then
begin
MessageDlg(rsMsgErrECreate, Format(rsMsgErrCreateFileDirectoryExists,
[ExtractFileName(sNewFile)]), mtWarning, [mbOK], 0);
Exit;
end;
ShowEditorByGlob(sNewFile);
end
else
msgWarning(rsMsgNotImplemented);