mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 16:49:07 +02:00
ValEdit: refactor the logic behind wether or not to hide the editor when manipulating the Strings property.
git-svn-id: trunk@43118 -
This commit is contained in:
parent
adc291a90d
commit
4c3f9378b9
@ -82,6 +82,7 @@ type
|
|||||||
FItemProps: TItemPropList;
|
FItemProps: TItemPropList;
|
||||||
function GetItemProp(const AKeyOrIndex: Variant): TItemProp;
|
function GetItemProp(const AKeyOrIndex: Variant): TItemProp;
|
||||||
procedure QuickSortStringsAndItemProps(L, R: Integer; CompareFn: TStringListSortCompare);
|
procedure QuickSortStringsAndItemProps(L, R: Integer; CompareFn: TStringListSortCompare);
|
||||||
|
function CanHideShowingEditorAtIndex(Index: Integer): Boolean;
|
||||||
protected
|
protected
|
||||||
procedure InsertItem(Index: Integer; const S: string; AObject: TObject); override;
|
procedure InsertItem(Index: Integer; const S: string; AObject: TObject); override;
|
||||||
procedure InsertItem(Index: Integer; const S: string); override;
|
procedure InsertItem(Index: Integer; const S: string); override;
|
||||||
@ -493,31 +494,12 @@ end;
|
|||||||
|
|
||||||
procedure TValueListStrings.InsertItem(Index: Integer; const S: string; AObject: TObject);
|
procedure TValueListStrings.InsertItem(Index: Integer; const S: string; AObject: TObject);
|
||||||
var
|
var
|
||||||
i: Integer;
|
MustHideShowingEditor: Boolean;
|
||||||
MustHideShowingEditor, EditorHasFocus: Boolean;
|
|
||||||
WC: TWinControl;
|
|
||||||
IndexToRow: Integer;
|
|
||||||
begin
|
begin
|
||||||
// ToDo: Check validity of key
|
// ToDo: Check validity of key
|
||||||
//debugln('TValueListStrings.InsertItem: Index=',dbgs(index),' S=',S,' AObject=',dbgs(aobject));
|
//debugln('TValueListStrings.InsertItem: Index = ',dbgs(index),' S = "',S,'" AObject = ',dbgs(aobject));
|
||||||
FGrid.InvalidateCachedRow;
|
FGrid.InvalidateCachedRow;
|
||||||
IndexToRow := Index + FGrid.FixedRows;
|
MustHideShowingEditor := CanHideShowingEditorAtIndex(Index);
|
||||||
if (FGrid.Editor is TCompositeCellEditor) then
|
|
||||||
begin
|
|
||||||
WC := TCompositeCellEditorAccess(FGrid.Editor).GetActiveControl;
|
|
||||||
if (WC is TCustomEdit) then
|
|
||||||
EditorHasFocus := TCustomEdit(WC).Focused
|
|
||||||
else
|
|
||||||
EditorHasFocus := False;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
EditorHasFocus := Assigned(FGrid.Editor) and FGrid.Editor.Focused;
|
|
||||||
MustHideShowingEditor := Assigned(FGrid.Editor) and
|
|
||||||
(goAlwaysShowEditor in FGrid.Options) and
|
|
||||||
FGrid.Editor.Visible and
|
|
||||||
(IndexToRow = FGrid.Row) and
|
|
||||||
//if editor is Focussed, we are editing a cell, so we cannot hide!
|
|
||||||
(not EditorHasFocus);
|
|
||||||
if MustHideShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
if MustHideShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
||||||
inherited InsertItem(Index, S, AObject);
|
inherited InsertItem(Index, S, AObject);
|
||||||
FItemProps.Insert(Index, TItemProp.Create(FGrid));
|
FItemProps.Insert(Index, TItemProp.Create(FGrid));
|
||||||
@ -532,29 +514,10 @@ end;
|
|||||||
|
|
||||||
procedure TValueListStrings.Put(Index: Integer; const S: String);
|
procedure TValueListStrings.Put(Index: Integer; const S: String);
|
||||||
var
|
var
|
||||||
IndexToRow: Integer;
|
MustHideShowingEditor: Boolean;
|
||||||
MustHideShowingEditor, EditorHasFocus: Boolean;
|
|
||||||
WC: TwinControl;
|
|
||||||
begin
|
begin
|
||||||
// ToDo: Check validity of key
|
// ToDo: Check validity of key
|
||||||
IndexToRow := Index + FGrid.FixedRows;
|
MustHideShowingEditor := CanHideShowingEditorAtIndex(Index);
|
||||||
if (FGrid.Editor is TCompositeCellEditor) then
|
|
||||||
begin
|
|
||||||
WC := TCompositeCellEditorAccess(FGrid.Editor).GetActiveControl;
|
|
||||||
if (WC is TCustomEdit) then
|
|
||||||
EditorHasFocus := TCustomEdit(WC).Focused
|
|
||||||
else
|
|
||||||
EditorHasFocus := False;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
EditorHasFocus := Assigned(FGrid.Editor) and FGrid.Editor.Focused;
|
|
||||||
MustHideShowingEditor := Assigned(FGrid.Editor) and
|
|
||||||
(goAlwaysShowEditor in FGrid.Options) and
|
|
||||||
FGrid.Editor.Visible and
|
|
||||||
(IndexToRow = FGrid.Row) and
|
|
||||||
//if editor is Focussed, we are editing a cell, so we cannot hide!
|
|
||||||
(not EditorHasFocus);
|
|
||||||
|
|
||||||
//debugln('TValueListStrings.Put: MustHideShowingEditor=',DbgS(MustHideShowingEditor));
|
//debugln('TValueListStrings.Put: MustHideShowingEditor=',DbgS(MustHideShowingEditor));
|
||||||
if MustHideShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
if MustHideShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
||||||
inherited Put(Index, S);
|
inherited Put(Index, S);
|
||||||
@ -640,6 +603,42 @@ begin
|
|||||||
QuickSortStringsAndItemProps(Pivot + 1, R, CompareFn);
|
QuickSortStringsAndItemProps(Pivot + 1, R, CompareFn);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TValueListStrings.CanHideShowingEditorAtIndex(Index: Integer): Boolean;
|
||||||
|
var
|
||||||
|
IndexToRow: Integer;
|
||||||
|
WC: TWinControl;
|
||||||
|
EditorHasFocus: Boolean;
|
||||||
|
begin
|
||||||
|
IndexToRow := Index + FGrid.FixedRows;
|
||||||
|
if (FGrid.Editor is TCompositeCellEditor) then
|
||||||
|
begin
|
||||||
|
WC := TCompositeCellEditorAccess(FGrid.Editor).GetActiveControl;
|
||||||
|
if (WC is TCustomEdit) then
|
||||||
|
EditorHasFocus := TCustomEdit(WC).Focused
|
||||||
|
else
|
||||||
|
EditorHasFocus := False;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
EditorHasFocus := Assigned(FGrid.Editor) and FGrid.Editor.Focused;
|
||||||
|
|
||||||
|
//debugln('CanHideShowingEditor:');
|
||||||
|
//debugln(' Assigned(FGrid.Editor) = ',DbgS(Assigned(FGrid.Editor)));
|
||||||
|
//debugln(' (goAlwaysShowEditor in FGrid.Options) = ',DbgS(goAlwaysShowEditor in FGrid.Options));
|
||||||
|
//if Assigned(FGrid.Editor) then
|
||||||
|
// debugln(' FGrid.Editor.Visible = ',DbgS(FGrid.Editor.Visible));
|
||||||
|
//debugln(' IndexToRow = ',DbgS(IndextoRow));
|
||||||
|
//debugln(' Count = ',DbgS(Count));
|
||||||
|
//debugln(' EditorHasFocus = ',DbgS(EditorHasFocus));
|
||||||
|
|
||||||
|
Result := Assigned(FGrid.Editor) and
|
||||||
|
(goAlwaysShowEditor in FGrid.Options) and
|
||||||
|
FGrid.Editor.Visible and
|
||||||
|
((IndexToRow = FGrid.Row) or (Count = 0)) and //if Count = 0 we still have an editable row
|
||||||
|
//if editor is Focussed, we are editing a cell, so we cannot hide!
|
||||||
|
(not EditorHasFocus);
|
||||||
|
//debugln('CanHideShowingEditor: Result = ',DbgS(Result));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TValueListStrings.CustomSort(Compare: TStringListSortCompare);
|
procedure TValueListStrings.CustomSort(Compare: TStringListSortCompare);
|
||||||
{
|
{
|
||||||
Re-implement it, because we need it to call our own QuickSortStringsAndItemProps
|
Re-implement it, because we need it to call our own QuickSortStringsAndItemProps
|
||||||
@ -665,7 +664,7 @@ var
|
|||||||
IsShowingEditor: Boolean;
|
IsShowingEditor: Boolean;
|
||||||
begin
|
begin
|
||||||
FGrid.InvalidateCachedRow;
|
FGrid.InvalidateCachedRow;
|
||||||
IsShowingEditor := goAlwaysShowEditor in FGrid.Options;
|
IsShowingEditor := CanHideShowingEditorAtIndex(Index);
|
||||||
if IsShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
if IsShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
||||||
inherited Delete(Index);
|
inherited Delete(Index);
|
||||||
// Delete also ItemProps
|
// Delete also ItemProps
|
||||||
@ -676,16 +675,10 @@ end;
|
|||||||
|
|
||||||
procedure TValueListStrings.Exchange(Index1, Index2: Integer);
|
procedure TValueListStrings.Exchange(Index1, Index2: Integer);
|
||||||
var
|
var
|
||||||
IndexToRow1, IndexToRow2: Integer;
|
|
||||||
MustHideShowingEditor: Boolean;
|
MustHideShowingEditor: Boolean;
|
||||||
begin
|
begin
|
||||||
FGrid.InvalidateCachedRow;
|
FGrid.InvalidateCachedRow;
|
||||||
IndexToRow1 := Index1 + FGrid.FixedRows;
|
MustHideShowingEditor := CanHideShowingEditorAtIndex(Index1) or CanHideShowingEditorAtIndex(Index2);
|
||||||
IndexToRow2 := Index2 + FGrid.FixedRows;
|
|
||||||
MustHideShowingEditor := Assigned(FGrid.Editor) and
|
|
||||||
(goAlwaysShowEditor in FGrid.Options) and
|
|
||||||
FGrid.Editor.Visible and
|
|
||||||
((IndexToRow1 = FGrid.Row) or (IndexToRow2 = FGrid.Row));
|
|
||||||
if MustHideShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
if MustHideShowingEditor then FGrid.Options := FGrid.Options - [goAlwaysShowEditor];
|
||||||
inherited Exchange(Index1, Index2);
|
inherited Exchange(Index1, Index2);
|
||||||
FItemProps.Exchange(Index1, Index2);
|
FItemProps.Exchange(Index1, Index2);
|
||||||
|
Loading…
Reference in New Issue
Block a user