You've already forked lazarus-ccr
fpspreadsheet: Fix fpsctrls demo picking the correct file extension for saving.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5237 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -975,6 +975,7 @@ object MainForm: TMainForm
|
|||||||
Caption = 'Save &as ...'
|
Caption = 'Save &as ...'
|
||||||
Dialog.Title = 'AcSaveFileAs'
|
Dialog.Title = 'AcSaveFileAs'
|
||||||
Dialog.Filter = 'Excel XML spreadsheet (*.xlsx)|*.xlsx|Excel XP/2003 XML spreadsheets (*.xml)|*.xml|Excel 97-2003 spreadsheets (*.xls)|*.xls|Excel 5 spreadsheet (*.xls)|*.xls|Excel 2.1 spreadsheets (*.xls)|*.xls|LibreOffice/OpenOffice spreadsheet (*.ods)|*.ods|Comma-delimited files (*.csv)|*.csv|HTML files (*.html; *.htm)|*.html;*.htm|WikiTable (WikiMedia-Format, *.wikitable_wikimedia)|*.wikitable_wikimedia'
|
Dialog.Filter = 'Excel XML spreadsheet (*.xlsx)|*.xlsx|Excel XP/2003 XML spreadsheets (*.xml)|*.xml|Excel 97-2003 spreadsheets (*.xls)|*.xls|Excel 5 spreadsheet (*.xls)|*.xls|Excel 2.1 spreadsheets (*.xls)|*.xls|LibreOffice/OpenOffice spreadsheet (*.ods)|*.ods|Comma-delimited files (*.csv)|*.csv|HTML files (*.html; *.htm)|*.html;*.htm|WikiTable (WikiMedia-Format, *.wikitable_wikimedia)|*.wikitable_wikimedia'
|
||||||
|
Dialog.OnTypeChange = TSaveDialogTypeChange
|
||||||
Hint = 'Save spreadsheet'
|
Hint = 'Save spreadsheet'
|
||||||
ImageIndex = 45
|
ImageIndex = 45
|
||||||
BeforeExecute = AcFileSaveAsBeforeExecute
|
BeforeExecute = AcFileSaveAsBeforeExecute
|
||||||
|
@@ -381,6 +381,7 @@ type
|
|||||||
procedure HyperlinkHandler(Sender: TObject; ACaption: String;
|
procedure HyperlinkHandler(Sender: TObject; ACaption: String;
|
||||||
var AHyperlink: TsHyperlink);
|
var AHyperlink: TsHyperlink);
|
||||||
procedure InspectorTabControlChange(Sender: TObject);
|
procedure InspectorTabControlChange(Sender: TObject);
|
||||||
|
procedure TSaveDialogTypeChange(Sender: TObject);
|
||||||
procedure WorksheetGridClickHyperlink(Sender: TObject;
|
procedure WorksheetGridClickHyperlink(Sender: TObject;
|
||||||
const AHyperlink: TsHyperlink);
|
const AHyperlink: TsHyperlink);
|
||||||
procedure WorksheetGridMouseWheel(Sender: TObject; Shift: TShiftState;
|
procedure WorksheetGridMouseWheel(Sender: TObject; Shift: TShiftState;
|
||||||
@@ -468,10 +469,13 @@ end;
|
|||||||
procedure TMainForm.AcFileSaveAsAccept(Sender: TObject);
|
procedure TMainForm.AcFileSaveAsAccept(Sender: TObject);
|
||||||
var
|
var
|
||||||
fmt: TsSpreadFormatID;
|
fmt: TsSpreadFormatID;
|
||||||
|
fmts: TsSpreadFormatIDArray;
|
||||||
|
ext: String;
|
||||||
begin
|
begin
|
||||||
Screen.Cursor := crHourglass;
|
Screen.Cursor := crHourglass;
|
||||||
try
|
try
|
||||||
fmt := FSaveFormats[AcFileSaveAs.Dialog.FilterIndex-1];
|
fmt := FSaveFormats[AcFileSaveAs.Dialog.FilterIndex - 1];
|
||||||
|
ext := ExtractFileExt(ACFileSaveAs.Dialog.Filename);
|
||||||
WorkbookSource.SaveToSpreadsheetFile(UTF8ToAnsi(AcFileSaveAs.Dialog.FileName), fmt);
|
WorkbookSource.SaveToSpreadsheetFile(UTF8ToAnsi(AcFileSaveAs.Dialog.FileName), fmt);
|
||||||
UpdateCaption;
|
UpdateCaption;
|
||||||
finally
|
finally
|
||||||
@@ -480,11 +484,23 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainForm.AcFileSaveAsBeforeExecute(Sender: TObject);
|
procedure TMainForm.AcFileSaveAsBeforeExecute(Sender: TObject);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if WorkbookSource.FileName = '' then
|
if WorkbookSource.FileName = '' then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
AcFileSaveAs.Dialog.InitialDir := ExtractFileDir(WorkbookSource.FileName);
|
AcFileSaveAs.Dialog.InitialDir := ExtractFileDir(WorkbookSource.FileName);
|
||||||
AcFileSaveAs.Dialog.FileName := ExtractFileName(WorkbookSource.FileName);
|
AcFileSaveAs.Dialog.FileName := ExtractFileName(WorkbookSource.FileName);
|
||||||
|
|
||||||
|
// Pre-select the file format according to the input file
|
||||||
|
if WorkbookSource.Workbook.FileFormatID = sfidUnknown then
|
||||||
|
exit;
|
||||||
|
for i:=0 to High(FSaveformats) do
|
||||||
|
if FSaveFormats[i] = WorkbookSource.Workbook.FileFormatID then begin
|
||||||
|
AcFileSaveAs.Dialog.FilterIndex := i + 1;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainForm.AcFrozenColsExecute(Sender: TObject);
|
procedure TMainForm.AcFrozenColsExecute(Sender: TObject);
|
||||||
@@ -808,6 +824,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.TSaveDialogTypeChange(Sender: TObject);
|
||||||
|
var
|
||||||
|
ext: String;
|
||||||
|
begin
|
||||||
|
ext := GetSpreadFormatExt(FSaveFormats[AcFileSaveAs.Dialog.FilterIndex - 1]);
|
||||||
|
AcFileSaveAs.Dialog.FileName := ChangeFileExt(AcFileSaveAs.Dialog.FileName, ext);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainForm.UpdateCaption;
|
procedure TMainForm.UpdateCaption;
|
||||||
begin
|
begin
|
||||||
if WorkbookSource = nil then
|
if WorkbookSource = nil then
|
||||||
|
@@ -38,6 +38,7 @@ function GetSpreadFormats(AFileAccess: TsSpreadFileAccess;
|
|||||||
function GetSpreadFormatsFromFileName(AFileAccess: TsSpreadFileAccess; AFileName: TFileName;
|
function GetSpreadFormatsFromFileName(AFileAccess: TsSpreadFileAccess; AFileName: TFileName;
|
||||||
APriorityFormat: TsSpreadFormatID = sfidUnknown): TsSpreadFormatIDArray;
|
APriorityFormat: TsSpreadFormatID = sfidUnknown): TsSpreadFormatIDArray;
|
||||||
|
|
||||||
|
function GetSpreadFormatExt(AFormatID: TsSpreadFormatID): String;
|
||||||
function GetSpreadFormatName(AFormatID: TsSpreadFormatID): String;
|
function GetSpreadFormatName(AFormatID: TsSpreadFormatID): String;
|
||||||
function GetSpreadTechnicalName(AFormatID: TsSpreadFormatID): String;
|
function GetSpreadTechnicalName(AFormatID: TsSpreadFormatID): String;
|
||||||
|
|
||||||
@@ -535,6 +536,11 @@ begin
|
|||||||
AFileAccess, AFileName, APriorityFormat);
|
AFileAccess, AFileName, APriorityFormat);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function GetSpreadFormatExt(AFormatID: TsSpreadFormatID): String;
|
||||||
|
begin
|
||||||
|
Result := SpreadFormatRegistry.DefaultExt[AFormatID];
|
||||||
|
end;
|
||||||
|
|
||||||
function GetSpreadFormatName(AFormatID: TsSpreadFormatID): String;
|
function GetSpreadFormatName(AFormatID: TsSpreadFormatID): String;
|
||||||
begin
|
begin
|
||||||
Result := SpreadFormatRegistry.FormatName[AFormatID];
|
Result := SpreadFormatRegistry.FormatName[AFormatID];
|
||||||
|
Reference in New Issue
Block a user