SynEdit: fixed SynPopUpMenu, enable/disable select all / Added SynEdit.HasText to check if non-empty

This commit is contained in:
Martin 2023-07-09 10:18:36 +02:00
parent 4adebcb03e
commit f21293c5d0
2 changed files with 17 additions and 1 deletions

View File

@ -207,6 +207,11 @@ type
);
TSynEditTextFlags = set of TSynEditTextFlag;
TSynEditHasTextFlag = (
shtIncludeVirtual // trailing spaces
);
TSynEditHasTextFlags = set of TSynEditHasTextFlag;
TSynStateFlag = (sfCaretChanged, sfHideCursor,
sfEnsureCursorPos, sfEnsureCursorPosAtResize, sfEnsureCursorPosForEditRight, sfEnsureCursorPosForEditLeft,
sfExplicitTopLine, sfExplicitLeftChar, // when doing EnsureCursorPos keep top/Left, if they where set explicitly after the caret (only applies before handle creation)
@ -946,6 +951,7 @@ type
// Text Raw (not undo-able)
procedure Clear;
procedure Append(const Value: String);
function HasText(AFlags: TSynEditHasTextFlags = []): Boolean;
property LineText: string read GetLineText write SetLineText; // textline at CaretY
property Text: string read SynGetText write SynSetText; // No uncommited (trailing/trimmable) spaces
@ -4730,6 +4736,16 @@ begin
FTheLinesView.Append(Value);
end;
function TCustomSynEdit.HasText(AFlags: TSynEditHasTextFlags): Boolean;
begin
if shtIncludeVirtual in AFlags then
Result := (FTheLinesView.Count > 1) or
( (FTheLinesView.Count = 1) and ((FTheLinesView[0] <> '')) )
else
Result := (FLines.Count > 1) or
( (FLines.Count = 1) and ((FLines[0] <> '')) );
end;
procedure TCustomSynEdit.DoBlockSelectionChanged(Sender : TObject);
begin
StatusChanged([scSelection]);

View File

@ -121,7 +121,7 @@ begin
meCopy: Items[i].Enabled := SelAvail;
mePaste: Items[i].Enabled := CanPaste;
meDelete: Items[i].Enabled := SelAvail and not ReadOnly;
meSelectAll: Items[i].Enabled := (Lines.Count > 1) or (Lines.Text <> '');
meSelectAll: Items[i].Enabled := HasText([shtIncludeVirtual]);
end;
end;
inherited;