Code:
// This file is part of Subtitle Workshop
// URL: subworkshop.sf.net
// Licesne: GPL v3
// Copyright: See Subtitle Workshop's copyright information
// File Description: Save As form
unit formSaveAs;
interface
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
StdCtrls,
Dialogs,
ImgList,
ComCtrls,
IniFiles,
FastStrings,
System.ImageList,
USubTitleAPI,
Scale, // Kameleon
VideoPreview; // Kameleon
// -----------------------------------------------------------------------------
type
TfrmSaveAs = class(TForm)
chkAllFormats: TCheckBox;
lstFormats: TListView;
lblDblClick: TLabel;
dlgSave: TSaveDialog;
btnCustomFormat: TButton;
btnCancel: TButton;
ImageList: TImageList;
chkUTF8: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure chkAllFormatsClick(Sender: TObject);
procedure lstFormatsDblClick(Sender: TObject);
procedure lstFormatsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure btnCustomFormatClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormResize(Sender: TObject); //added by adenry
private
Resize_Enabled: boolean;
procedure AddCustomFormats;
procedure SetLanguage;
public
SaveTranslation: Boolean;
end;
// -----------------------------------------------------------------------------
var
frmSaveAs: TfrmSaveAs;
implementation
uses
General,
Functions,
TreeViewHandle,
Undo, //USubtitlesFunctions, USubtitleAPI, //Undo added by adenry //USubtitlesFunctions, USubtitleAPI removed by adenry
formMain,
formCustomFormats,
formOutputSettings;
{$R *.dfm}
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.SetLanguage;
var
LF: TIniFile;
CP: integer;
begin
CP := CharsetToCodePage(frmMain.Font.Charset); // Kameleon
LF := TIniFile.Create(frmMain.ActualLangFile);
try
with LF do
begin
Caption := StringToWideStringCP(ReadString('Save as', '01', 'Save as'), CP);
lblDblClick.Caption := StringToWideStringCP(ReadString('Save as', '02', 'Double-click on the output format:'), CP);
btnCustomFormat.Caption := StringToWideStringCP(ReadString('Save as', '03', 'Custom format'), CP);
chkAllFormats.Caption := StringToWideStringCP(ReadString('Save as', '04', 'All formats'), CP);
btnCancel.Caption := BTN_CANCEL;
// ------------------ //
// Set font //
// ------------------ //
Font := frmMain.Font;
end;
finally
LF.Free;
end;
end;
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.AddCustomFormats;
var
Busca: TSearchRec;
i: Integer;
A: TListItem;
begin
i := FindFirst(ExtractFilePath(Application.ExeName) + ID_CFPDIR + '\*.cfp', faAnyFile, Busca);
while i = 0 do
begin
A := lstFormats.Items.Add;
A.Caption := Copy(Busca.Name, 1, LastDelimiter('.', Busca.Name) - 1);
A.StateIndex := 1;
i := FindNext(Busca);
end;
FindClose(Busca);
end;
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.FormCreate(Sender: TObject);
var
i: Integer;
TotalFormats: Integer;
Name, Ext: string;
Item: TListItem;
Ini: TIniFile;
begin
// Kameleon
Resize_Enabled := false;
Resize_Enabled := true;
// Kameleon
//frmSaveAsExecuting := True; // removed by BDZL
frmMain.frmSaveAsExecuting := True; //added by adenry. Another option is frmMain.tmrSaveWork.Enabled:=False;
SetLanguage;
SaveTranslation := False;
TotalFormats := SubtitleApi.FormatsCount;
if TotalFormats = 0 then Exit;
lstFormats.Clear;
//added by adenry: end
Ini := TIniFile.Create(IniRoot);
try
for i := 1 to TotalFormats do
begin
SubtitleAPI.GetFormatInfo(i, Name, Ext);
if Ini.ReadBool('Formats to show', SubtitleAPI.GetFormatName(i), True) = True then
begin
Item := lstFormats.Items.Add;
Item.Caption := Name;
Item.ImageIndex := 0;
Item.StateIndex := 0;
end;
end;
if Ini.ReadBool('Formats', 'Show custom formats', False) then AddCustomFormats;
finally
Ini.Free;
end;
end;
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.chkAllFormatsClick(Sender: TObject);
var
i: Integer;
TotalFormats: Integer;
Name, Ext: string;
Item: TListItem;
Ini: TIniFile;
begin
TotalFormats := SubtitleAPI.FormatsCount;
if TotalFormats = 0 then Exit;
lstFormats.Clear;
Ini := TIniFile.Create(IniRoot);
for i := 1 to TotalFormats do
begin
SubtitleAPI.GetFormatInfo(i, Name, Ext);
if chkAllFormats.Checked then
begin
Item := lstFormats.Items.Add;
Item.Caption := Name;
Item.ImageIndex := 0;
Item.StateIndex := 0;
end else
begin
if Ini.ReadBool('Formats to show', SubtitleAPI.GetFormatName(i), True) = True then
begin
Item := lstFormats.Items.Add;
Item.Caption := Name;
Item.ImageIndex := 0;
Item.StateIndex := 0;
end;
end;
end;
if Ini.ReadBool('Formats', 'Show custom formats', False) then AddCustomFormats;
Ini.Free;
end;
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.lstFormatsDblClick(Sender: TObject);
label
SaveSubFile;
label
SaveCustFile;
var
FormatName: string;
AllExts: string;
Ext: string;
SubFile: string;
SubFormat: Integer;
// Custom formats stuff
// FormatName
// Ext
NewLineChar: string;
TimeStructure: string;
Time, Frames: Boolean;
FPS: Single;
Lines: TStrings;
i: Byte;
//Ini: TIniFile;
begin
if ChkUTF8.Checked then SubTitleAPI.Set_UTF8_File(true)
else SubTitleAPI.Set_UTF8_File(false);
chkUTF8.Checked := SubtitleAPI.Get_UTF8_File;
if lstFormats.ItemIndex = -1 then exit;
UpdateArray(SubtitleAPI.GetFormatIndex(lstFormats.Items[lstFormats.ItemIndex].Caption), SaveTranslation); //format index added by adenry
// Regular Formats (non-custom)
if lstFormats.Items[lstFormats.ItemIndex].StateIndex = 0 then
begin
SubFormat := SubtitleAPI.GetFormatIndex(lstFormats.Items[lstFormats.ItemIndex].Caption);
SubtitleAPI.GetFormatInfo(SubFormat, FormatName, AllExts);
dlgSave.Filter := FormatName + ' (' + AllExts + ')|' + AllExts;
if SaveTranslation then
SubFile := Copy(frmMain.TransFile, 1, LastDelimiter('.', frmMain.TransFile)) else
SubFile := Copy(frmMain.OrgFile, 1, LastDelimiter('.', frmMain.OrgFile) - 1);
if SubFile = '' then SubFile := lstFormats.Items[lstFormats.ItemIndex].Caption;
Ext := GetFormatExt(SubFormat);
if ExtractFileExt(SubFile) <> Ext then SubFile := SubFile + Ext;
dlgSave.FileName := SubFile;
if (dlgSave.Execute) and (dlgSave.FileName <> '') then
begin
SubFile := dlgSave.FileName;
if AnsiLowerCase(ExtractFileExt(SubFile)) <> AnsiLowerCase(Ext) then
begin
if SmartPos(ExtractFileExt(SubFile), AllExts, False) = 0 then
SubFile := SubFile + Ext;
end;
if FileExists(SubFile) then
begin
case MsgBox(Format(QuestionMsg[02], [SubFile]), BTN_YES, BTN_NO, BTN_CANCEL, MB_ICONQUESTION, frmSaveAs) of
1: goto SaveSubFile;
2:
begin
SubtitleAPI.ClearSubtitles;
Close;
exit;
end; //SubtitleAPI.ClearSubtitles added by adenry
3:
begin
SubtitleAPI.ClearSubtitles;
exit;
end; //SubtitleAPI.ClearSubtitles added by adenry
end;
end;
SaveSubFile:
//added by adenry: begin
//show Output Settings window if necessary
for i := 0 to Length(frmMain.OutputSettingsFormats) - 1 do
if FormatName = frmMain.OutputSettingsFormats[i].FormatName then
begin
if frmMain.OutputSettingsFormats[i].AlwaysShow = TRUE then
begin
frmOutputSettings := TfrmOutputSettings.Create(Application);
with frmOutputSettings do
begin
pgeFormats.ActivePage := pgeFormats.Pages[i];
pgeFormats.ActivePageIndex := i;
pnlHeading.Caption := tvFormats.Items[i].Text;
tvFormats.Visible := False;
pnlHeading.Left := tvFormats.Left;
pgeFormats.Left := tvFormats.Left; // - pgeFormats.Pages[0].Left;
//pgeFormats.Width := pgeFormats.Width + pgeFormats.Pages[0].Left;
//bvlSeparate1.Left := bvlSeparate1.Left + pgeFormats.Pages[0].Left;
//bvlSeparate1.Width := bvlSeparate1.Width - pgeFormats.Pages[0].Left;
btnOk.Left := btnOk.Left - tvFormats.Width - tvFormats.Left;
btnCancel.Left := btnCancel.Left - tvFormats.Width - tvFormats.Left;
ClientWidth := ClientWidth - tvFormats.Width - tvFormats.Left;
end;
if frmOutputSettings.ShowModal <> mrOk then
begin
SubtitleAPI.ClearSubtitles;
frmOutputSettings.Free;
//Close;
exit;
end;
frmOutputSettings.Free;
end;
break;
end;
//added by adenry: end
if SaveFile(SubFile, SubFormat, GetFPS) = False then
begin
SubtitleAPI.ClearSubtitles; //added by adenry
Close;
exit;
end;
//Save successful!
if SaveTranslation then
begin
frmMain.TransFile := SubFile;
frmMain.TransFormat := SubFormat;
frmMain.TransModified := False;
frmMain.UndoNumWhenTransSaved := UndoList.Count; //added by adenry
end else
begin
frmMain.OrgFile := SubFile;
frmMain.OrgFormat := SubFormat;
frmMain.OrgModified := False;
frmMain.UndoNumWhenOrgSaved := UndoList.Count; //added by adenry
end;
frmMain.RefreshStatusbar; //added by adenry - refresh format name in statusbar
if (frmMain.MarkingSave = 2) and (frmMain.MarkingModified) then SaveMarking(SubFile + ID_SRFEXT, SubFile); //added by adenry
SetFormCaption;
frmMain.AddToRecent(SubFile);
if FileExists(SubFile + '.ini') then DeleteFile(SubFile + '.ini'); // Kameleon
if frmMain.btnPlay.Enabled
then AddToLastChoices(SubFile, GetCurrentPos, frmMain.lstSubtitles.FocusedNode.Index, GetCurrentAudioStream, frmMain.MovieFile, LastPositions)
else AddToLastChoices(SubFile, -1, frmMain.lstSubtitles.FocusedNode.Index, GetCurrentAudioStream, '', LastPositions);
Close;
end;
end else
// Custom Format
if lstFormats.Items[lstFormats.ItemIndex].StateIndex = 1 then
begin
Lines := TStringList.Create;
try
GetCustomFormatInfo(ExtractFilePath(Application.ExeName) + ID_CFPDIR + '\' + lstFormats.Items[lstFormats.ItemIndex].Caption + '.cfp', FormatName, Ext, NewLineChar, TimeStructure, Time, Frames, FPS, Lines);
Ext := Copy(Ext, 2, Length(Ext));
if SaveTranslation then
SubFile := Copy(frmMain.TransFile, 1, LastDelimiter('.', frmMain.TransFile)) else
SubFile := Copy(frmMain.OrgFile, 1, LastDelimiter('.', frmMain.OrgFile) - 1);
if ExtractFileExt(SubFile) = '' then
SubFile := SubFile + Ext;
dlgSave.Filter := FormatName + ' (' + Ext + ')|' + Ext;
dlgSave.FileName := SubFile;
if (dlgSave.Execute) and (dlgSave.FileName <> '') then
begin
SubFile := dlgSave.FileName;
if ExtractFileExt(SubFile) = '' then
SubFile := SubFile + Ext;
if FileExists(SubFile) then
begin
case MsgBox(Format(QuestionMsg[02], [SubFile]), BTN_YES, BTN_NO, BTN_CANCEL, MB_ICONQUESTION, frmSaveAs) of
1: goto SaveCustFile;
2:
begin
SubtitleAPI.ClearSubtitles;
Close;
exit;
end; //SubtitleAPI.ClearSubtitles added by adenry
3:
begin
SubtitleAPI.ClearSubtitles;
exit;
end; //SubtitleAPI.ClearSubtitles added by adenry
end;
end;
SaveCustFile:
SaveCustomFormat(SubFile, Lines, Time, Frames, TimeStructure, FPS, NewLineChar, chkUTF8.Checked);
if FileExists(SubFile + '.ini') then DeleteFile(SubFile + '.ini'); // Kameleon
if frmMain.btnPlay.Enabled
then AddToLastChoices(SubFile, GetCurrentPos, frmMain.lstSubtitles.FocusedNode.Index, GetCurrentAudioStream, frmMain.MovieFile, LastPositions)
else AddToLastChoices(SubFile, -1, frmMain.lstSubtitles.FocusedNode.Index, GetCurrentAudioStream, '', LastPositions);
end;
finally
Lines.Clear;
end;
end;
SubtitleAPI.ClearSubtitles;
end;
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.lstFormatsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
lstFormatsDblClick(Sender);
end;
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.btnCustomFormatClick(Sender: TObject);
begin
frmCustomFormats := TfrmCustomFormats.Create(Application);
frmCustomFormats.SaveTranslation := SaveTranslation;
frmCustomFormats.ShowModal;
frmCustomFormats.Free;
end;
// -----------------------------------------------------------------------------
procedure TfrmSaveAs.FormDestroy(Sender: TObject);
var
Ini: TIniFile; //added by adenry
begin
//frmSaveAsExecuting := False; // removed by BDZL
//added by adenry: begin
Ini := TIniFile.Create(IniRoot);
if WindowState = wsMaximized then
begin
Ini.WriteBool('Save', 'Maximized', True);
end
else
begin
Ini.WriteInteger('Save', 'Left', Left);
Ini.WriteInteger('Save', 'Top', Top);
Ini.WriteInteger('Save', 'Width', Width);
Ini.WriteInteger('Save', 'Height', Height);
Ini.WriteBool('Save', 'Maximized', False);
end;
Ini.WriteBool('Save', 'UTF8', chkUTF8.Checked); // Kameleon
Ini.Free;
frmMain.frmSaveAsExecuting := False; //added by adenry. another option is frmMain.tmrSaveWork.Enabled:=True;
//added by adenry: end
end;
// -----------------------------------------------------------------------------
//added by adenry: begin
procedure TfrmSaveAs.FormResize(Sender: TObject);
begin
if Resize_Enabled then
begin
btnCustomFormat.Top := ClientHeight - 8 - btnCustomFormat.Height;
btnCancel.Top := btnCustomFormat.Top;
btnCancel.Left := ClientWidth - 8 - btnCancel.Width;
chkAllFormats.Top := btnCustomFormat.Top - 8 - chkAllFormats.Height;
chkAllFormats.Width := ClientWidth - 16;
chkUTF8.Top := chkAllFormats.Top; // Kameleon
chkUTF8.Left := btnCancel.Left; // Kameleon
lstformats.Top := lbldblClick.Top + lbldblclick.height + 5; // Kameleon
lstFormats.Width := ClientWidth - 16;
lstFormats.Height := chkAllFormats.Top - 8 - lstFormats.Top;
chkAllFormatsClick(Sender);
end;
end;
procedure TfrmSaveAs.FormShow(Sender: TObject);
var
i: integer;
MaxW, MaxH, Tmp: word;
Ini: TIniFile;
W, H, L, T: integer;
begin
MaxW := 0;
//MaxH := 0;
LstFormats.Canvas.Font.Size := font.Size;
for I := 0 to LstFormats.Items.Count - 1 do
begin
Tmp := LstFormats.Canvas.TextWidth(LstFormats.Items[I].Caption);
if Tmp > MaxW then MaxW := Tmp;
//Tmp := LstFormats.Canvas.TextHeight(LstFormats.Items[I].Caption);
//if Tmp > MaxH then MaxH := Tmp;
end;
if MaxW = 0 then MaxW := (ClientWidth div 4) - 10;
MaxW := MaxW * 13 div 10; // to give space (130%)
LstFormats.LargeImages.Width := MaxW;
//if MaxH > 0 then LstFormats.LargeImages.Height := MaxH;
Ini := TIniFile.Create(IniRoot);
W := abs(Ini.ReadInteger('Save', 'Width', Screen.Width div 2));
H := abs(Ini.ReadInteger('Save', 'Height', Screen.Height div 2));
L := abs(Ini.ReadInteger('Save', 'Left', Screen.Width div 4));
T := abs(Ini.ReadInteger('Save', 'Top', Screen.Height div 4));
SetLimitedBounds(Self, L, T, W, H);
if Ini.ReadBool('Save', 'Maximized', False)
then WindowState := wsMaximized
else WindowState := wsNormal;
chkUTF8.Checked := Ini.ReadBool('Save', 'UTF8', true);
Ini.Free;
end;
//added by adenry: end
// -----------------------------------------------------------------------------
end.
Bookmarks