From 483260f11f03502b20d470c416366844f1199927 Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 23 Jul 2009 20:35:13 +0000 Subject: Editor: - if encoding must be changed to UTF-8 create a backup copy of the old file - show error/info dialog if file saving failed/succeeded git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1911 b956fd51-792f-4845-bead-9b4dfca2ff2c --- unicode/src/screens/UScreenEditSub.pas | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'unicode/src') diff --git a/unicode/src/screens/UScreenEditSub.pas b/unicode/src/screens/UScreenEditSub.pas index 56d11124..00e62c16 100644 --- a/unicode/src/screens/UScreenEditSub.pas +++ b/unicode/src/screens/UScreenEditSub.pas @@ -139,13 +139,26 @@ uses procedure OnSaveEncodingError(Value: boolean; Data: Pointer); var SResult: TSaveSongResult; + FilePath: IPath; + Success: boolean; begin + Success := false; if (Value) then begin CurrentSong.Encoding := encUTF8; - SResult := SaveSong(CurrentSong, Lines[0], CurrentSong.Path.Append(CurrentSong.FileName), + FilePath := CurrentSong.Path.Append(CurrentSong.FileName); + // create backup file + FilePath.CopyFile(Path(FilePath.ToUTF8 + '.ansi.bak'), false); + // store in UTF-8 encoding + SResult := SaveSong(CurrentSong, Lines[0], FilePath, boolean(Data)); + Success := (SResult = ssrOK); end; + + if (Success) then + ScreenPopupInfo.ShowPopup(Language.Translate('INFO_FILE_SAVED')) + else + ScreenPopupError.ShowPopup(Language.Translate('ERROR_SAVE_FILE_FAILED')); end; // Method for input parsing. If false is returned, GetNextWindow @@ -182,10 +195,18 @@ begin // Save Song SResult := SaveSong(CurrentSong, Lines[0], CurrentSong.Path.Append(CurrentSong.FileName), (SDL_ModState = KMOD_LSHIFT)); - if (SResult = ssrEncodingError) then + if (SResult = ssrOK) then + begin + ScreenPopupInfo.ShowPopup(Language.Translate('INFO_FILE_SAVED')); + end + else if (SResult = ssrEncodingError) then begin ScreenPopupCheck.ShowPopup(Language.Translate('ENCODING_ERROR_ASK_FOR_UTF8'), OnSaveEncodingError, Pointer(SDL_ModState = KMOD_LSHIFT), true); + end + else + begin + ScreenPopupError.ShowPopup(Language.Translate('ERROR_SAVE_FILE_FAILED')); end; Exit; end; -- cgit v1.2.3