mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 16:21:01 +02:00
LCL: fix TValueListEditor LoadFromFile and SaveToFile. Issue #0036166.
git-svn-id: trunk@62043 -
This commit is contained in:
parent
1b50e06c5b
commit
8c90dbc81a
@ -6,7 +6,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
ContNrs, SysUtils, Classes, Variants,
|
ContNrs, SysUtils, Classes, Variants,
|
||||||
LazUtf8, Controls, StdCtrls, Grids, LResources, Dialogs, LCLType;
|
LazUtf8, Controls, StdCtrls, Grids, LResources, Dialogs, LCLType, Laz2_XMLCfg;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -160,7 +160,9 @@ type
|
|||||||
function GetDefaultEditor(Column: Integer): TWinControl; override;
|
function GetDefaultEditor(Column: Integer): TWinControl; override;
|
||||||
function GetRowCount: Integer;
|
function GetRowCount: Integer;
|
||||||
procedure KeyDown(var Key : Word; Shift : TShiftState); override;
|
procedure KeyDown(var Key : Word; Shift : TShiftState); override;
|
||||||
|
procedure LoadContent(cfg: TXMLConfig; Version: Integer); override;
|
||||||
procedure ResetDefaultColWidths; override;
|
procedure ResetDefaultColWidths; override;
|
||||||
|
procedure SaveContent(cfg: TXMLConfig); override;
|
||||||
procedure SetCells(ACol, ARow: Integer; const AValue: string); override;
|
procedure SetCells(ACol, ARow: Integer; const AValue: string); override;
|
||||||
procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
|
procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
|
||||||
procedure SetFixedRows(const AValue: Integer); override;
|
procedure SetFixedRows(const AValue: Integer); override;
|
||||||
@ -899,6 +901,7 @@ begin
|
|||||||
Raise EGridException.CreateFmt(rsVLEInvalidRowColOperation,['MoveColRow',' on columns']);
|
Raise EGridException.CreateFmt(rsVLEInvalidRowColOperation,['MoveColRow',' on columns']);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TValueListEditor.RestoreCurrentRow: Boolean;
|
function TValueListEditor.RestoreCurrentRow: Boolean;
|
||||||
begin
|
begin
|
||||||
//DbgOut('RestoreCurrentRow: Row=',DbgS(Row),' FLastEditedRow=',DbgS(FLastEditedRow),' SavedKey=',FRowTextOnEnter.Key,' SavedValue=',FRowTextOnEnter.Value);
|
//DbgOut('RestoreCurrentRow: Row=',DbgS(Row),' FLastEditedRow=',DbgS(FLastEditedRow),' SavedKey=',FRowTextOnEnter.Key,' SavedValue=',FRowTextOnEnter.Value);
|
||||||
@ -919,6 +922,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TValueListEditor.Sort(ACol: TVleSortCol = colKey);
|
procedure TValueListEditor.Sort(ACol: TVleSortCol = colKey);
|
||||||
begin
|
begin
|
||||||
SortColRow(True, Ord(ACol));
|
SortColRow(True, Ord(ACol));
|
||||||
@ -1283,6 +1287,47 @@ begin
|
|||||||
if RestoreCurrentRow then Key := 0;
|
if RestoreCurrentRow then Key := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TValueListEditor.LoadContent(cfg: TXMLConfig; Version: Integer);
|
||||||
|
var
|
||||||
|
ContentSaved, HasColumnTitles, AlwaysShowEditor: Boolean;
|
||||||
|
i,j,k, RC: Integer;
|
||||||
|
begin
|
||||||
|
AlwaysShowEditor := (goAlwaysShowEditor in Options);
|
||||||
|
if AlwaysShowEditor then Options := Options - [goAlwaysShowEditor];
|
||||||
|
inherited LoadContent(Cfg, Version);
|
||||||
|
if soContent in SaveOptions then
|
||||||
|
begin
|
||||||
|
ContentSaved:=Cfg.GetValue('grid/saveoptions/content', false);
|
||||||
|
if ContentSaved then
|
||||||
|
begin
|
||||||
|
HasColumnTitles := cfg.getValue('grid/content/hascolumntitles', False);
|
||||||
|
if HasColumnTitles then
|
||||||
|
DisplayOptions := DisplayOptions + [doColumnTitles]
|
||||||
|
else
|
||||||
|
DisplayOptions := DisplayOptions - [doColumnTitles];
|
||||||
|
|
||||||
|
//contrary to other grids we restore the entire saved content,
|
||||||
|
//so we add/delete rows (not columns of course) as needed.
|
||||||
|
RC := cfg.GetValue('grid/content/rowcount', 1);
|
||||||
|
if (RC < 1) then RC := 1;
|
||||||
|
if HasColumnTitles and (RC = 1) then
|
||||||
|
RC := 2;
|
||||||
|
RowCount := RC;
|
||||||
|
|
||||||
|
k:=cfg.getValue('grid/content/cells/cellcount', 0);
|
||||||
|
while k>0 do
|
||||||
|
begin
|
||||||
|
i:=cfg.GetValue('grid/content/cells/cell'+IntToStr(k)+'/column', -1);
|
||||||
|
j:=cfg.GetValue('grid/content/cells/cell'+IntTostr(k)+'/row',-1);
|
||||||
|
if IsRowIndexValid(j) and IsColumnIndexValid(i) then
|
||||||
|
Cells[i,j]:=UTF8Encode(cfg.GetValue('grid/content/cells/cell'+IntToStr(k)+'/text',''));
|
||||||
|
Dec(k);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if AlwaysShowEditor then Options := Options + [goAlwaysShowEditor];
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TValueListEditor.ResetDefaultColWidths;
|
procedure TValueListEditor.ResetDefaultColWidths;
|
||||||
begin
|
begin
|
||||||
if not AutoFillColumns then
|
if not AutoFillColumns then
|
||||||
@ -1294,6 +1339,38 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TValueListEditor.SaveContent(cfg: TXMLConfig);
|
||||||
|
var
|
||||||
|
i,j,k: Integer;
|
||||||
|
//c: PCellProps;
|
||||||
|
Value: String;
|
||||||
|
begin
|
||||||
|
inherited SaveContent(cfg);
|
||||||
|
cfg.SetValue('grid/saveoptions/content', soContent in SaveOptions);
|
||||||
|
if soContent in SaveOptions then
|
||||||
|
begin
|
||||||
|
cfg.SetValue('grid/content/hascolumntitles',(doColumnTitles in FDisplayOptions));
|
||||||
|
cfg.SetValue('grid/content/rowcount', RowCount);
|
||||||
|
// Save Cell Contents
|
||||||
|
k:=0;
|
||||||
|
For i:=0 to ColCount-1 do
|
||||||
|
For j:=0 to RowCount-1 do
|
||||||
|
begin
|
||||||
|
//fGrid.Celda is unassigned for cells other than the title row, so we neet to query GetCells here
|
||||||
|
Value := GetCells(i,j);
|
||||||
|
if (Value <> '') then
|
||||||
|
begin
|
||||||
|
Inc(k);
|
||||||
|
//Cfg.SetValue('grid/content/cells/cellcount',k);
|
||||||
|
cfg.SetValue('grid/content/cells/cell'+IntToStr(k)+'/column',i);
|
||||||
|
cfg.SetValue('grid/content/cells/cell'+IntToStr(k)+'/row',j);
|
||||||
|
cfg.SetValue('grid/content/cells/cell'+IntToStr(k)+'/text', Value);
|
||||||
|
end;
|
||||||
|
Cfg.SetValue('grid/content/cells/cellcount',k);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TValueListEditor.SetCells(ACol, ARow: Integer; const AValue: string);
|
procedure TValueListEditor.SetCells(ACol, ARow: Integer; const AValue: string);
|
||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user