fpspreadsheet: New behavior of DEL in WorksheetGrid: deletes only content, not format. Old behavior (delete everything) is CTRL+DEL now.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6605 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-08-16 13:33:11 +00:00
parent 3767c1a2c9
commit f5e6986eb7
2 changed files with 33 additions and 5 deletions

View File

@ -398,7 +398,7 @@ type
procedure Clear; procedure Clear;
procedure DeleteCell(ACell: PCell); procedure DeleteCell(ACell: PCell);
procedure EraseCell(ACell: PCell); procedure EraseCell(ACell: PCell; AKeepFormat: Boolean = false);
function AddCell(ARow, ACol: Cardinal): PCell; function AddCell(ARow, ACol: Cardinal): PCell;
function FindCell(ARow, ACol: Cardinal): PCell; overload; function FindCell(ARow, ACol: Cardinal): PCell; overload;
@ -483,6 +483,7 @@ type
procedure SelectCell(ARow, ACol: Cardinal); procedure SelectCell(ARow, ACol: Cardinal);
procedure ClearSelection; procedure ClearSelection;
procedure DeleteSelection; procedure DeleteSelection;
procedure EraseSelection(AKeepFormat: Boolean = false);
function GetSelection: TsCellRangeArray; function GetSelection: TsCellRangeArray;
function GetSelectionAsString: String; function GetSelectionAsString: String;
function GetSelectionCount: Integer; function GetSelectionCount: Integer;
@ -2212,7 +2213,7 @@ end;
@param ACell Pointer to cell to be erased. @param ACell Pointer to cell to be erased.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.EraseCell(ACell: PCell); procedure TsWorksheet.EraseCell(ACell: PCell; AKeepFormat: Boolean = false);
var var
r, c: Cardinal; r, c: Cardinal;
begin begin
@ -2233,8 +2234,11 @@ begin
// Removes the formula if the cell has one // Removes the formula if the cell has one
DeleteFormula(ACell); DeleteFormula(ACell);
// Erase all cell content if AKeepFormat then
InitCell(nil, r, c, ACell^); ACell^.ContentType := cctEmpty
else
// Erase all cell content
InitCell(nil, r, c, ACell^);
end; end;
end; end;
@ -4481,6 +4485,27 @@ begin
ClearSelection; ClearSelection;
end; end;
{@@ ----------------------------------------------------------------------------
Erases all selected cells (erase = keep cell, but delete content)
If AKeepFormat is true the cell format is left unchanged.
-------------------------------------------------------------------------------}
procedure TsWorksheet.EraseSelection(AKeepFormat: Boolean = false);
var
i: Integer;
r, c: Cardinal;
cell: PCell;
begin
for i:=0 to High(FSelection) do
for r := FSelection[i].Row1 to FSelection[i].Row2 do
for c := FSelection[i].Col1 to FSelection[i].Col2 do
begin
cell := FindCell(r, c);
EraseCell(cell, AKeepFormat);
end;
ClearSelection;
end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Returns the list of selected cell ranges Returns the list of selected cell ranges
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}

View File

@ -4648,7 +4648,10 @@ begin
VK_F2: VK_F2:
FEnhEditMode := true; FEnhEditMode := true;
VK_DELETE: VK_DELETE:
Worksheet.DeleteSelection; if (ssCtrl in Shift) then
Worksheet.DeleteSelection
else
Worksheet.EraseSelection(true);
end; end;
inherited; inherited;