SynEdit: reworked mouse-actions

git-svn-id: trunk@33956 -
This commit is contained in:
martin 2011-12-04 16:53:23 +00:00
parent ce5458acf2
commit 7554ee973e
10 changed files with 525 additions and 239 deletions

View File

@ -36,6 +36,42 @@ It also allows to insert code like the begin and end of a multiline comment "(*"
<element name="TCustomSynEdit.EndUpdate">
<short>Enable updates internal data strucures, and applies all changes since BeginUpdate</short>
</element>
<element name="TCustomSynEdit.MouseOptions">
<short>Controls the behaviour of the mouse (mouse-clicks)</short>
<seealso>
<link id="#SynEdit.SynEdit.TSynEdit.Options">Options</link>
</seealso>
</element>
<element name="TCustomSynEdit.Options">
<short>General options to change the SynEdits behaviour</short>
<descr>
<p>
<u>About old/deprecated values for controlling the mouse:</u>
</p>
<p>They have been moved to <link id="#SynEdit.SynEdit.TSynEdit.MouseOptions">MouseOptions</link>
</p>
<p>If a new value is set to Options, then MouseOptions are updated only if any of them changed compared to their previous value in this property (Options), otherwise their value in MouseOptions is kept.
</p>
<p>If MouseOptions is assigned a new value, it will forward clearing any flag that it receives, but not forward setting any flags.
</p>
<p>This means:
<ul>
<li>As long as you only use Options both properties are kept in sync.</li>
<li>If you use MouseOptions instead, then you should leave the old flags in this property cleared. Which will allow you to set/change all other flags in this property, without interfering with MouseOptions.</li>
</ul>
</p>
</descr>
<seealso>
<link id="#SynEdit.SynEdit.TSynEdit.Options2">Options2</link>
<link id="#SynEdit.SynEdit.TSynEdit.MouseOptions">MouseOptions</link>
</seealso>
</element>
<element name="TCustomSynEdit.Options2">
<seealso>
<link id="#SynEdit.SynEdit.TSynEdit.Options">Options</link>
</seealso>
<short>More general options to change the SynEdits behaviour</short>
</element>
</module>
</package>
</fpdoc-descriptions>

View File

@ -15,6 +15,8 @@ resourcestring
syndsSeparator = 'Separator';
syndsLineOverview = 'Line Overview';
syndsResetMouseActions = 'Reset mouse actions';
implementation

View File

@ -213,15 +213,12 @@ type
//eoSpecialLineDefaultFg, //TODO disables the foreground text color override when using the OnSpecialLineColor event
// Only for compatibility, moved to TSynEditorMouseOptions
eoAltSetsColumnMode, // DEPRECATED, now in TSynEditorMouseOption
eoDragDropEditing, // DEPRECATED, now controlled vie MouseActions
// Allows you to select a block of text and drag it within the document to another location
eoRightMouseMovesCursor, // DEPRECATED, now controlled vie MouseActions
// When clicking with the right mouse for a popup menu, move the cursor to that location
eoDoubleClickSelectsLine, // DEPRECATED
// Select line on double click
eoShowCtrlMouseLinks // DEPRECATED, now controlled vie MouseActions
// Pressing Ctrl (SYNEDIT_LINK_MODIFIER) will highlight the word under the mouse cursor
// keep in one block
eoAltSetsColumnMode, //
eoDragDropEditing, // Allows you to select a block of text and drag it within the document to another location
eoRightMouseMovesCursor, // When clicking with the right mouse for a popup menu, move the cursor to that location
eoDoubleClickSelectsLine, // Select line on double click
eoShowCtrlMouseLinks // Pressing Ctrl (SYNEDIT_LINK_MODIFIER) will highlight the word under the mouse cursor
);
TSynEditorOptions = set of TSynEditorOption;
@ -237,11 +234,14 @@ type
);
TSynEditorOptions2 = set of TSynEditorOption2;
//TSynEditorMouseOption = (
// eoAltSetsColumnMode, // Holding down the Alt Key will put the selection mode into columnar format
//
//);
//TSynEditorMouseOptions = set of TSynEditorMouseOption;
TSynEditorMouseOption = SynEditMouseCmds.TSynEditorMouseOption;
//emUseMouseActions,
//emAltSetsColumnMode, // Alt modifier, triggers column mode selection
//emDragDropEditing, // Allows you to select a block of text and drag it within the document to another location
//emRightMouseMovesCursor, // When clicking with the right mouse for a popup menu, move the cursor to that location
//emDoubleClickSelectsLine, // Select line on double click
//emShowCtrlMouseLinks // Pressing Ctrl (SYNEDIT_LINK_MODIFIER) will highlight the word under the mouse cursor
TSynEditorMouseOptions = SynEditMouseCmds.TSynEditorMouseOptions;
// options for textbuffersharing
TSynEditorShareOption = (
@ -252,8 +252,7 @@ type
TSynVisibleSpecialChars = SynEditTypes.TSynVisibleSpecialChars;
const
// MouseAction related options will have no effect (as default), unless they
// are also updated in the Constructor of the MouseAction-class
// MouseAction related options MUST NOT be included here
SYNEDIT_DEFAULT_OPTIONS = [
eoAutoIndent,
eoScrollPastEol,
@ -276,6 +275,22 @@ const
eoSpacesToTabs // Converts space characters to tabs and spaces
];
SYNEDIT_OLD_MOUSE_OPTIONS = [
eoAltSetsColumnMode, //
eoDragDropEditing, // Allows you to select a block of text and drag it within the document to another location
eoRightMouseMovesCursor, // When clicking with the right mouse for a popup menu, move the cursor to that location
eoDoubleClickSelectsLine, // Select line on double click
eoShowCtrlMouseLinks // Pressing Ctrl (SYNEDIT_LINK_MODIFIER) will highlight the word under the mouse cursor
];
SYNEDIT_OLD_MOUSE_OPTIONS_MAP: array [eoAltSetsColumnMode..eoShowCtrlMouseLinks] of TSynEditorMouseOption = (
emAltSetsColumnMode, // eoAltSetsColumnMode
emDragDropEditing, // eoDragDropEditing
emRightMouseMovesCursor, // eoRightMouseMovesCursor
emDoubleClickSelectsLine, // eoDoubleClickSelectsLine
emShowCtrlMouseLinks // eoShowCtrlMouseLinks
);
SYNEDIT_DEFAULT_SHARE_OPTIONS = [
eosShareMarks
];
@ -285,6 +300,8 @@ const
eoOverwriteBlock
];
SYNEDIT_DEFAULT_MOUSE_OPTIONS = [];
SYNEDIT_DEFAULT_VISIBLESPECIALCHARS = [
vscSpace,
vscTabAtLast
@ -431,7 +448,7 @@ type
fOverwriteCaret: TSynEditCaretType;
fInsertCaret: TSynEditCaretType;
FKeyStrokes, FLastKeyStrokes: TSynEditKeyStrokes;
FMouseActions, FMouseSelActions: TSynEditMouseActions;
FMouseActions, FMouseSelActions: TSynEditMouseInternalActions;
FMouseActionSearchHandlerList: TSynEditMouseActionSearchList;
FMouseActionExecHandlerList: TSynEditMouseActionExecList;
FMarkList: TSynEditMarkList;
@ -443,8 +460,9 @@ type
fTextDrawer: TheTextDrawer;
FPaintLineColor, FPaintLineColor2: TSynSelectedColor;
fStateFlags: TSynStateFlags;
fOptions: TSynEditorOptions;
fOptions2: TSynEditorOptions2;
FOptions: TSynEditorOptions;
FOptions2: TSynEditorOptions2;
FMouseOptions: TSynEditorMouseOptions;
fStatusChanges: TSynStatusChanges;
fTSearch: TSynEditSearch;
fHookedCommandHandlers: TList;
@ -479,6 +497,8 @@ type
function GetDefSelectionMode: TSynSelectionMode;
function GetFoldState: String;
function GetModified: Boolean;
function GetMouseActions: TSynEditMouseActions;
function GetMouseSelActions: TSynEditMouseActions;
function GetPaintLockOwner: TSynEditBase;
function GetPlugin(Index: Integer): TSynEditPlugin;
function GetTextBetweenPoints(aStartPoint, aEndPoint: TPoint): String;
@ -585,6 +605,8 @@ type
procedure UpdateOptions;
procedure SetOptions2(const Value: TSynEditorOptions2);
procedure UpdateOptions2;
procedure SetMouseOptions(AValue: TSynEditorMouseOptions);
procedure UpdateMouseOptions;
procedure SetOverwriteCaret(const Value: TSynEditCaretType);
procedure SetRightEdge(Value: Integer);
procedure SetRightEdgeColor(Value: TColor);
@ -843,6 +865,7 @@ type
procedure SetUseIncrementalColor(const AValue : Boolean);
procedure SetBookMark(BookMark: Integer; X: Integer; Y: Integer);
procedure SetDefaultKeystrokes; virtual;
procedure ResetMouseActions; // set mouse-actions according to current Options / may clear them
procedure SetOptionFlag(Flag: TSynEditorOption; Value: boolean);
procedure Undo;
function GetLineState(ALine: Integer): TSynLineState;
@ -928,14 +951,16 @@ type
property Keystrokes: TSynEditKeyStrokes
read FKeystrokes write SetKeystrokes;
property MouseActions: TSynEditMouseActions
read FMouseActions write SetMouseActions;
read GetMouseActions write SetMouseActions;
property MouseSelActions: TSynEditMouseActions // Mouseactions, if mouse is over selection => fallback to normal
read FMouseSelActions write SetMouseSelActions;
read GetMouseSelActions write SetMouseSelActions;
property MaxUndo: Integer read GetMaxUndo write SetMaxUndo default 1024;
property Options: TSynEditorOptions read fOptions write SetOptions // See SYNEDIT_UNIMPLEMENTED_OPTIONS for deprecated Values
property Options: TSynEditorOptions read FOptions write SetOptions // See SYNEDIT_UNIMPLEMENTED_OPTIONS for deprecated Values
default SYNEDIT_DEFAULT_OPTIONS;
property Options2: TSynEditorOptions2 read fOptions2 write SetOptions2
property Options2: TSynEditorOptions2 read FOptions2 write SetOptions2
default SYNEDIT_DEFAULT_OPTIONS2;
property MouseOptions: TSynEditorMouseOptions read FMouseOptions write SetMouseOptions
default SYNEDIT_DEFAULT_MOUSE_OPTIONS;
property ShareOptions: TSynEditorShareOptions read FShareOptions write SetShareOptions
default SYNEDIT_DEFAULT_SHARE_OPTIONS; experimental;
property VisibleSpecialChars: TSynVisibleSpecialChars read FVisibleSpecialChars write SetVisibleSpecialChars;
@ -1065,6 +1090,7 @@ type
property MaxUndo;
property Options;
property Options2;
property MouseOptions;
property VisibleSpecialChars;
property OverwriteCaret;
property ReadOnly;
@ -1180,6 +1206,32 @@ type
function PerformUndo(Caller: TObject): Boolean; override;
end;
{ TSynEditMouseTextActions }
TSynEditMouseTextActions = class(TSynEditMouseInternalActions)
protected
procedure InitForOptions(AnOptions: TSynEditorMouseOptions); override;
end;
{ TSynEditMouseSelActions }
TSynEditMouseSelActions = class(TSynEditMouseInternalActions)
protected
procedure InitForOptions(AnOptions: TSynEditorMouseOptions); override;
end;
{ THookedCommandHandlerEntry }
THookedCommandHandlerEntry = class(TObject)
private
fEvent: THookedCommandEvent;
fData: pointer;
function Equals(AEvent: THookedCommandEvent): boolean; reintroduce;
public
constructor Create(AEvent: THookedCommandEvent; AData: pointer);
end;
{ TSynEditUndoCaret }
function TSynEditUndoCaret.IsEqualContent(AnItem: TSynEditUndoItem): Boolean;
@ -1298,17 +1350,57 @@ begin
end;
end;
{ THookedCommandHandlerEntry }
{ TSynEditMouseTextActions }
type
THookedCommandHandlerEntry = class(TObject)
private
fEvent: THookedCommandEvent;
fData: pointer;
function Equals(AEvent: THookedCommandEvent): boolean; reintroduce;
public
constructor Create(AEvent: THookedCommandEvent; AData: pointer);
procedure TSynEditMouseTextActions.InitForOptions(AnOptions: TSynEditorMouseOptions);
var
rmc: Boolean;
begin
Clear;
rmc := (emRightMouseMovesCursor in AnOptions);
//// eoRightMouseMovesCursor
//if (eoRightMouseMovesCursor in ChangedOptions) then begin
// for i := FMouseActions.Count-1 downto 0 do
// if FMouseActions[i].Button = mbRight then
// FMouseActions[i].MoveCaret := (eoRightMouseMovesCursor in fOptions);
//end;
AddCommand(emcStartSelections, True, mbLeft, ccSingle, cdDown, [], [ssShift, ssAlt], emcoSelectionStart);
AddCommand(emcStartSelections, True, mbLeft, ccSingle, cdDown, [ssShift], [ssShift, ssAlt], emcoSelectionContinue);
if (emAltSetsColumnMode in AnOptions) then begin
AddCommand(emcStartColumnSelections, True, mbLeft, ccSingle, cdDown, [ssAlt], [ssShift, ssAlt], emcoSelectionStart);
AddCommand(emcStartColumnSelections, True, mbLeft, ccSingle, cdDown, [ssShift, ssAlt], [ssShift, ssAlt], emcoSelectionContinue);
end;
if (emShowCtrlMouseLinks in AnOptions) then
AddCommand(emcMouseLink, False, mbLeft, ccSingle, cdUp, [SYNEDIT_LINK_MODIFIER], [ssShift, ssAlt, ssCtrl]);
if (emDoubleClickSelectsLine in AnOptions) then begin
AddCommand(emcSelectLine, True, mbLeft, ccDouble, cdDown, [], []);
AddCommand(emcSelectPara, True, mbLeft, ccTriple, cdDown, [], []);
end
else begin
AddCommand(emcSelectWord, True, mbLeft, ccDouble, cdDown, [], []);
AddCommand(emcSelectLine, True, mbLeft, ccTriple, cdDown, [], []);
end;
AddCommand(emcSelectPara, True, mbLeft, ccQuad, cdDown, [], []);
AddCommand(emcContextMenu, rmc, mbRight, ccSingle, cdUp, [], [], emcoSelectionCaretMoveNever);
AddCommand(emcPasteSelection, True, mbMiddle, ccSingle, cdDown, [], []);
end;
{ TSynEditMouseSelActions }
procedure TSynEditMouseSelActions.InitForOptions(AnOptions: TSynEditorMouseOptions);
begin
Clear;
//rmc := (eoRightMouseMovesCursor in AnOptions);
if (emDragDropEditing in AnOptions) then
AddCommand(emcStartDragMove, False, mbLeft, ccSingle, cdDown, [], []);
end;
{ THookedCommandHandlerEntry }
constructor THookedCommandHandlerEntry.Create(AEvent: THookedCommandEvent;
AData: pointer);
@ -1389,6 +1481,16 @@ begin
Result := TSynEditStringList(FLines).Modified;
end;
function TCustomSynEdit.GetMouseActions: TSynEditMouseActions;
begin
Result := FMouseActions.UserActions;
end;
function TCustomSynEdit.GetMouseSelActions: TSynEditMouseActions;
begin
Result := FMouseSelActions.UserActions;
end;
function TCustomSynEdit.GetPaintLockOwner: TSynEditBase;
begin
Result := TSynEditStringList(FLines).PaintLockOwner;
@ -1719,10 +1821,9 @@ begin
if assigned(Owner) and not (csLoading in Owner.ComponentState) then begin
SetDefaultKeystrokes;
end;
FMouseActions := TSynEditMouseTextActions.Create(Self);
FMouseSelActions := TSynEditMouseSelActions.Create(Self);
FMouseActions.ResetDefaults;
FMouseSelActions.ResetDefaults;
FMouseActionSearchHandlerList := TSynEditMouseActionSearchList.Create;
FMouseActionExecHandlerList := TSynEditMouseActionExecList.Create;
@ -1744,11 +1845,13 @@ begin
fTSearch := TSynEditSearch.Create;
FOptions := SYNEDIT_DEFAULT_OPTIONS;
FOptions2 := SYNEDIT_DEFAULT_OPTIONS2;
FMouseOptions := SYNEDIT_DEFAULT_MOUSE_OPTIONS;
FShareOptions := SYNEDIT_DEFAULT_SHARE_OPTIONS;
FVisibleSpecialChars := SYNEDIT_DEFAULT_VISIBLESPECIALCHARS;
fMarkupSpecialChar.VisibleSpecialChars := SYNEDIT_DEFAULT_VISIBLESPECIALCHARS;
UpdateOptions;
UpdateOptions2;
UpdateMouseOptions;
fScrollTimer := TTimer.Create(Self);
fScrollTimer.Enabled := False;
fScrollTimer.Interval := 100;
@ -2513,6 +2616,8 @@ begin
// Gutter
if not Result then
Result := FLeftGutter.DoHandleMouseAction(AnAction, AnInfo);
if not Result then
Result := FRightGutter.DoHandleMouseAction(AnAction, AnInfo);
if Result then begin
if (not AnInfo.CaretDone) and AnAction.MoveCaret then
@ -2674,9 +2779,9 @@ begin
//(x < ClientWidth - TextRightPixelOffset - ScrollBarWidth) and
IsPointInSelection(FInternalCaret.LineBytePos)
then
if DoHandleMouseAction(FMouseSelActions, Info) then
if DoHandleMouseAction(FMouseSelActions.GetActionsForOptions(FMouseOptions), Info) then
exit;
DoHandleMouseAction(FMouseActions, Info);
DoHandleMouseAction(FMouseActions.GetActionsForOptions(FMouseOptions), Info);
finally
if Info.IgnoreUpClick then
include(fStateFlags, sfIgnoreUpClick);
@ -5284,18 +5389,12 @@ end;
procedure TCustomSynEdit.SetMouseActions(const AValue: TSynEditMouseActions);
begin
if AValue = nil then
FMouseActions.Clear
else
FMouseActions.Assign(AValue);
FMouseActions.UserActions := AValue;
end;
procedure TCustomSynEdit.SetMouseSelActions(const AValue: TSynEditMouseActions);
begin
if AValue = nil then
FMouseSelActions.Clear
else
FMouseSelActions.Assign(AValue);
FMouseSelActions.UserActions := AValue;
end;
procedure TCustomSynEdit.SetPaintLockOwner(const AValue: TSynEditBase);
@ -6027,6 +6126,17 @@ begin
FKeystrokes.ResetDefaults;
end;
procedure TCustomSynEdit.ResetMouseActions;
var
i: Integer;
begin
FMouseActions.Options := FMouseOptions;
FMouseActions.ResetUserActions;
FMouseSelActions.Options := FMouseOptions;
FMouseSelActions.ResetUserActions;
end;
procedure TCustomSynEdit.CommandProcessor(Command: TSynEditorCommand;
AChar: TUTF8Char;
Data: pointer);
@ -7293,12 +7403,17 @@ procedure TCustomSynEdit.SetOptions(Value: TSynEditorOptions);
var
ChangedOptions: TSynEditorOptions;
i: Integer;
m: TSynEditorOption;
MOpt: TSynEditorMouseOptions;
f: Boolean;
begin
Value := Value - SYNEDIT_UNIMPLEMENTED_OPTIONS;
if (Value <> fOptions) then begin
ChangedOptions:=(fOptions-Value)+(Value-fOptions);
fOptions := Value;
if (Value = FOptions) then exit;
ChangedOptions:=(FOptions-Value)+(Value-FOptions);
FOptions := Value;
UpdateOptions;
if not (eoScrollPastEol in Options) then
LeftChar := LeftChar;
if (eoScrollPastEol in Options) or (eoScrollPastEof in Options) then begin
@ -7314,75 +7429,25 @@ begin
Invalidate;
fMarkupSpecialChar.Enabled := (eoShowSpecialChars in fOptions);
(* Deal with deprecated values
(* Deal with deprecated Mouse values
Those are all controlled by mouse-actions.
As long as the default mouse actions are set, the below will act as normal
*)
// eoShowCtrlMouseLinks
if (eoShowCtrlMouseLinks in ChangedOptions) then begin
if (eoShowCtrlMouseLinks in fOptions) then begin
try
FMouseActions.AddCommand(emcMouseLink, False, mbLeft, ccSingle, cdUp, [SYNEDIT_LINK_MODIFIER], [ssShift, ssAlt, ssCtrl]);
except
end;
end else begin
for i := FMouseActions.Count-1 downto 0 do
if FMouseActions[i].Command = emcMouseLink then
FMouseActions.Delete(i);
end;
if assigned(fMarkupCtrlMouse) then
fMarkupCtrlMouse.UpdateCtrlMouse;
UpdateCursor;
end;
// eoDragDropEditing
if (eoDragDropEditing in ChangedOptions) then begin
if (eoDragDropEditing in fOptions) then begin
try
FMouseSelActions.AddCommand(emcStartDragMove, False, mbLeft, ccSingle, cdDown, [], []);
except
end;
end else begin
for i := FMouseActions.Count-1 downto 0 do
if FMouseActions[i].Command = emcStartDragMove then
FMouseActions.Delete(i);
end;
end;
// eoRightMouseMovesCursor
if (eoRightMouseMovesCursor in ChangedOptions) then begin
for i := FMouseActions.Count-1 downto 0 do
if FMouseActions[i].Button = mbRight then
FMouseActions[i].MoveCaret := (eoRightMouseMovesCursor in fOptions);
end;
// eoDoubleClickSelectsLine
if (eoDoubleClickSelectsLine in ChangedOptions) then begin
for i := FMouseActions.Count-1 downto 0 do
if (FMouseActions[i].Button = mbLeft) and
(FMouseActions[i].ClickCount = ccDouble) and
(FMouseActions[i].IsMatchingShiftState([])) and
( (FMouseActions[i].Command = emcSelectWord) or
(FMouseActions[i].Command = emcSelectLine) )
then begin
if (eoDoubleClickSelectsLine in fOptions)
then FMouseActions[i].Command := emcSelectLine
else FMouseActions[i].Command := emcSelectWord;
end
end;
// eoAltSetsColumnMode
if (eoAltSetsColumnMode in ChangedOptions) then begin
if (eoAltSetsColumnMode in fOptions) then begin
try
FMouseActions.AddCommand(emcStartColumnSelections, True, mbLeft, ccSingle, cdDown, [ssAlt], [ssShift, ssAlt], emcoSelectionStart);
FMouseActions.AddCommand(emcStartColumnSelections, True, mbLeft, ccSingle, cdDown, [ssShift, ssAlt], [ssShift, ssAlt], emcoSelectionContinue);
except
end;
end else begin
for i := FMouseActions.Count-1 downto 0 do
if FMouseActions[i].Command = emcStartColumnSelections then
FMouseActions.Delete(i);
end;
end;
MOpt := FMouseOptions;
f := False;
for m := low(SYNEDIT_OLD_MOUSE_OPTIONS_MAP) to high(SYNEDIT_OLD_MOUSE_OPTIONS_MAP) do
if (m in SYNEDIT_OLD_MOUSE_OPTIONS) and (m in ChangedOptions) then begin
f := True;
if (m in FOptions)
then MOpt := MOpt + [SYNEDIT_OLD_MOUSE_OPTIONS_MAP[m]]
else MOpt := MOpt - [SYNEDIT_OLD_MOUSE_OPTIONS_MAP[m]];
end;
if f then
MouseOptions := MOpt;
FOptions := Value; // undo changes applied by MouseOptions
end;
procedure TCustomSynEdit.UpdateOptions;
@ -7415,6 +7480,37 @@ begin
FCaret.SkipTabs := (eoCaretSkipTab in fOptions2);
end;
procedure TCustomSynEdit.SetMouseOptions(AValue: TSynEditorMouseOptions);
var
ChangedOptions: TSynEditorMouseOptions;
m: TSynEditorOption;
f: Boolean;
begin
if FMouseOptions = AValue then Exit;
ChangedOptions := (FMouseOptions-AValue)+(AValue-FMouseOptions);
FMouseOptions := AValue;
// changes take effect when MouseActions are accessed
for m := low(SYNEDIT_OLD_MOUSE_OPTIONS_MAP) to high(SYNEDIT_OLD_MOUSE_OPTIONS_MAP) do
if (m in SYNEDIT_OLD_MOUSE_OPTIONS) and
(SYNEDIT_OLD_MOUSE_OPTIONS_MAP[m] in ChangedOptions) and
not(SYNEDIT_OLD_MOUSE_OPTIONS_MAP[m] in FMouseOptions)
then
FOptions := FOptions - [m];
if (emShowCtrlMouseLinks in ChangedOptions) then begin
if assigned(fMarkupCtrlMouse) then
fMarkupCtrlMouse.UpdateCtrlMouse;
UpdateCursor;
end;
end;
procedure TCustomSynEdit.UpdateMouseOptions;
begin
//
end;
procedure TCustomSynEdit.SetOptionFlag(Flag: TSynEditorOption; Value: boolean);
begin
if (Value <> (Flag in fOptions)) then begin

View File

@ -43,7 +43,7 @@ uses
SynHighlighterPython, SynHighlighterVB, SynHighlighterAny, SynHighlighterDiff,
SynHighlighterBat, SynHighlighterIni,
SynPropertyEditObjectList, SynDesignStringConstants,
LazarusPackageIntf, LResources, PropEdits;
LazarusPackageIntf, LResources, PropEdits, ComponentEditors;
procedure Register;
@ -234,6 +234,8 @@ begin
RegisterClasses([TSynGutterPartList, TSynGutterSeparator, TSynGutterCodeFolding,
TSynGutterLineNumber, TSynGutterChanges, TSynGutterMarks]);
RegisterComponentEditor(TCustomSynEdit, TSynEditComponentEditor);
// property editor, with filter for deprecated values
RegisterPropertyEditor(TypeInfo(TSynEditorOptions), nil,
'', TSynEdOptionsPropertyEditor);

View File

@ -40,6 +40,16 @@ uses
type
TSynEditorMouseOption = (
emUseMouseActions,
emAltSetsColumnMode, // Alt modifier, triggers column mode selection
emDragDropEditing, // Allows you to select a block of text and drag it within the document to another location
emRightMouseMovesCursor, // When clicking with the right mouse for a popup menu, move the cursor to that location
emDoubleClickSelectsLine, // Select line on double click
emShowCtrlMouseLinks // Pressing Ctrl (SYNEDIT_LINK_MODIFIER) will highlight the word under the mouse cursor
);
TSynEditorMouseOptions = set of TSynEditorMouseOption;
TSynEditorMouseCommand = type word;
TSynEditorMouseCommandOpt = type word;
TSynMAClickCount = (ccSingle, ccDouble, ccTriple, ccQuad, ccAny);
@ -136,19 +146,26 @@ type
write SetItem; default;
end;
{ TSynEditMouseTextActions }
{ TSynEditMouseInternalActions }
TSynEditMouseTextActions = class(TSynEditMouseActions)
TSynEditMouseInternalActions = class(TSynEditMouseActions)
private
FOptions, FInternOptions: TSynEditorMouseOptions;
FUserActions: TSynEditMouseActions;
procedure SetOptions(AValue: TSynEditorMouseOptions);
procedure SetUserActions(AValue: TSynEditMouseActions);
protected
procedure InitForOptions(AnOptions: TSynEditorMouseOptions); virtual;
public
constructor Create(AOwner: TPersistent);
destructor Destroy; override;
procedure ResetDefaults; override;
procedure ResetUserActions;
function GetActionsForOptions(AnOptions: TSynEditorMouseOptions): TSynEditMouseActions;
property Options: TSynEditorMouseOptions read FOptions write SetOptions;
property UserActions: TSynEditMouseActions read FUserActions write SetUserActions;
end;
{ TSynEditSelMouseActions }
TSynEditMouseSelActions = class(TSynEditMouseActions)
public
procedure ResetDefaults; override;
end;
TSynEditMouseActionHandler = function(AnActionList: TSynEditMouseActions;
AnInfo: TSynEditMouseActionInfo): Boolean of object;
@ -333,6 +350,73 @@ begin
Result := IdentToInt(Ident, SynMouseCmd, SynMouseCommandNames);
end;
{ TSynEditMouseInternalActions }
procedure TSynEditMouseInternalActions.SetOptions(AValue: TSynEditorMouseOptions);
begin
FOptions := AValue;
if emUseMouseActions in FOptions then exit;
AValue := AValue - [emUseMouseActions];
if (FInternOptions = AValue) and (Count > 0) then exit;
FInternOptions := AValue;
InitForOptions(FInternOptions);
end;
procedure TSynEditMouseInternalActions.SetUserActions(AValue: TSynEditMouseActions);
begin
if AValue =nil then
FUserActions.Clear
else
FUserActions.Assign(AValue);
end;
procedure TSynEditMouseInternalActions.InitForOptions(AnOptions: TSynEditorMouseOptions);
begin
Clear;
end;
constructor TSynEditMouseInternalActions.Create(AOwner: TPersistent);
begin
FOptions := [];
FUserActions := TSynEditMouseActions.Create(AOwner);
inherited Create(AOwner);
end;
destructor TSynEditMouseInternalActions.Destroy;
begin
FreeAndNil(FUserActions);
inherited Destroy;
end;
procedure TSynEditMouseInternalActions.ResetDefaults;
begin
InitForOptions(FOptions);
end;
procedure TSynEditMouseInternalActions.ResetUserActions;
begin
if emUseMouseActions in FOptions then begin
if (FInternOptions <> FOptions - [emUseMouseActions]) or (Count = 0) then begin
FInternOptions := FOptions - [emUseMouseActions];
InitForOptions(FInternOptions);
end;
FUserActions.Assign(Self);
end
else begin
FUserActions.Clear;
end;
end;
function TSynEditMouseInternalActions.GetActionsForOptions(AnOptions: TSynEditorMouseOptions): TSynEditMouseActions;
begin
Options := AnOptions;
if emUseMouseActions in FOptions then
Result := FUserActions
else
Result := Self;
end;
{ TSynEditMouseAction }
procedure TSynEditMouseAction.SetButton(const AValue: TMouseButton);
@ -690,34 +774,6 @@ begin
end;
end;
{ TSynEditSelMouseActions }
procedure TSynEditMouseSelActions.ResetDefaults;
begin
Clear;
AddCommand(emcStartDragMove, False, mbLeft, ccSingle, cdDown, [], []);
end;
{ TSynEditMouseTextActions }
procedure TSynEditMouseTextActions.ResetDefaults;
begin
Clear;
AddCommand(emcStartSelections, True, mbLeft, ccSingle, cdDown, [], [ssShift, ssAlt], emcoSelectionStart);
AddCommand(emcStartSelections, True, mbLeft, ccSingle, cdDown, [ssShift], [ssShift, ssAlt], emcoSelectionContinue);
AddCommand(emcStartColumnSelections, True, mbLeft, ccSingle, cdDown, [ssAlt], [ssShift, ssAlt], emcoSelectionStart);
AddCommand(emcStartColumnSelections, True, mbLeft, ccSingle, cdDown, [ssShift, ssAlt], [ssShift, ssAlt], emcoSelectionContinue);
AddCommand(emcContextMenu, False, mbRight, ccSingle, cdUp, [], [], emcoSelectionCaretMoveNever);
AddCommand(emcSelectWord, True, mbLeft, ccDouble, cdDown, [], []);
AddCommand(emcSelectLine, True, mbLeft, ccTriple, cdDown, [], []);
AddCommand(emcSelectPara, True, mbLeft, ccQuad, cdDown, [], []);
AddCommand(emcPasteSelection, True, mbMiddle, ccSingle, cdDown, [], []);
AddCommand(emcMouseLink, False, mbLeft, ccSingle, cdUp, [SYNEDIT_LINK_MODIFIER], [ssShift, ssAlt, ssCtrl]);
end;
{ TSynEditMouseActionSearchList }
function TSynEditMouseActionSearchList.CallSearchHandlers(var AnInfo: TSynEditMouseActionInfo;

View File

@ -27,6 +27,7 @@ type
mark: TSynEditMark); override;
function CreatePartList: TSynGutterPartListBase; override;
procedure CreateDefaultGutterParts; virtual;
function CreateMouseActions: TSynEditMouseInternalActions; override;
public
constructor Create(AOwner : TSynEditBase; ASide: TSynGutterSide;
ATextDrawer: TheTextDrawer);
@ -37,7 +38,7 @@ type
procedure MouseMove(Shift: TShiftState; X, Y: Integer);
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean;
HandleActionProc: TSynEditMouseActionHandler): Boolean; override;
function DoHandleMouseAction(AnAction: TSynEditMouseAction;
var AnInfo: TSynEditMouseActionInfo): Boolean;
procedure DoOnGutterClick(X, Y: integer);
@ -85,9 +86,9 @@ type
{ TSynEditMouseActionsGutter }
TSynEditMouseActionsGutter = class(TSynEditMouseActions)
public
procedure ResetDefaults; override;
TSynEditMouseActionsGutter = class(TSynEditMouseInternalActions)
protected
procedure InitForOptions(AnOptions: TSynEditorMouseOptions); override;
end;
@ -101,10 +102,6 @@ constructor TSynGutter.Create(AOwner: TSynEditBase; ASide: TSynGutterSide;
ATextDrawer: TheTextDrawer);
begin
inherited;
FMouseActions := TSynEditMouseActionsGutter.Create(self);
FMouseActions.ResetDefaults;
if not(csLoading in AOwner.ComponentState) then
CreateDefaultGutterParts;
end;
@ -113,7 +110,6 @@ destructor TSynGutter.Destroy;
begin
OnChange := nil;
OnResize := nil;
FreeAndNil(FMouseActions);
inherited Destroy;
end;
@ -135,6 +131,11 @@ begin
Name := 'SynGutterCodeFolding1';
end;
function TSynGutter.CreateMouseActions: TSynEditMouseInternalActions;
begin
Result := TSynEditMouseActionsGutter.Create(self);
end;
function TSynGutter.PixelToPartIndex(X: Integer): Integer;
begin
Result := 0;
@ -247,7 +248,7 @@ begin
MouseDownPart := PixelToPartIndex(AnInfo.MouseX);
Result := Parts[MouseDownPart].MaybeHandleMouseAction(AnInfo, HandleActionProc);
if not Result then
Result := HandleActionProc(MouseActions, AnInfo);
Result := inherited MaybeHandleMouseAction(AnInfo, HandleActionProc);
end;
function TSynGutter.DoHandleMouseAction(AnAction: TSynEditMouseAction;
@ -361,11 +362,15 @@ end;
{ TSynEditMouseActionsGutter }
procedure TSynEditMouseActionsGutter.ResetDefaults;
procedure TSynEditMouseActionsGutter.InitForOptions(AnOptions: TSynEditorMouseOptions);
var
rmc: Boolean;
begin
Clear;
rmc := (emRightMouseMovesCursor in AnOptions);
AddCommand(emcOnMainGutterClick, False, mbLeft, ccAny, cdDown, [], []);
AddCommand(emcContextMenu, False, mbRight, ccSingle, cdUp, [], []);
AddCommand(emcContextMenu, rmc, mbRight, ccSingle, cdUp, [], []);
end;
end.

View File

@ -37,7 +37,9 @@ type
FNeedOnChange, FNeedOnResize: Boolean;
FOnResize: TNotifyEvent;
FOnChange: TNotifyEvent;
FMouseActions: TSynEditMouseInternalActions;
function GetMouseActions: TSynEditMouseActions;
procedure SetAutoSize(const AValue: boolean);
procedure SetColor(const Value: TColor);
procedure SetGutterParts(const AValue: TSynGutterPartListBase);
@ -47,7 +49,6 @@ type
procedure SetVisible(const AValue: boolean);
procedure SetWidth(Value: integer);
protected
FMouseActions: TSynEditMouseActions;
procedure DoAutoSize;
procedure SetChildBounds;
procedure DoChange(Sender: TObject);
@ -59,12 +60,15 @@ type
procedure RegisterNewGutterPartList(APartList: TSynGutterPartListBase);
function PartCount: integer;
function CreatePartList: TSynGutterPartListBase; virtual; abstract;
function CreateMouseActions: TSynEditMouseInternalActions; virtual;
procedure Clear;
public
constructor Create(AOwner : TSynEditBase; ASide: TSynGutterSide; ATextDrawer: TheTextDrawer);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure RecalcBounds;
function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean; virtual;
property Left: Integer read FLeft;
property Top: Integer read FTop;
property Height:Integer read FHeight;
@ -86,7 +90,7 @@ type
property TextDrawer: TheTextDrawer read FTextDrawer;
property Color: TColor read FColor write SetColor default clBtnFace;
property MouseActions: TSynEditMouseActions
read FMouseActions write SetMouseActions;
read GetMouseActions write SetMouseActions;
end;
{ TSynGutterPartListBase }
@ -145,12 +149,14 @@ type
FCursor: TCursor;
FOnChange: TNotifyEvent;
FOnGutterClick: TGutterClickEvent;
FMouseActions: TSynEditMouseInternalActions;
function GetFoldView: TSynEditFoldedView;
function GetGutterParts: TSynGutterPartListBase;
function GetMouseActions: TSynEditMouseActions;
procedure SetMarkupInfo(const AValue: TSynSelectedColor);
procedure SetMouseActions(const AValue: TSynEditMouseActions);
protected
FMouseActions: TSynEditMouseActions;
function CreateMouseActions: TSynEditMouseInternalActions; virtual;
function PreferedWidth: Integer; virtual;
procedure SetBounds(ALeft, ATop, AHeight: Integer);
procedure DoAutoSize;
@ -194,7 +200,7 @@ type
property Width: integer read FWidth write SetWidth default 10;
property Visible: boolean read FVisible write SetVisible default True;
property MouseActions: TSynEditMouseActions
read FMouseActions write SetMouseActions;
read GetMouseActions write SetMouseActions;
end;
@ -210,6 +216,7 @@ begin
FSide := ASide;
FSynEdit := AOwner;
CreatePartList;
FMouseActions := CreateMouseActions;
FInDoChange := False;
FChangeLock := 0;
@ -227,6 +234,7 @@ begin
FOnChange := nil;
FOnResize := nil;
FreeAndNil(FGutterPartList);
FreeAndNil(FMouseActions);
inherited Destroy;
end;
@ -284,6 +292,12 @@ begin
end;
end;
function TSynGutterBase.MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean;
begin
Result := HandleActionProc(FMouseActions.GetActionsForOptions(TCustomSynEdit(SynEdit).MouseOptions), AnInfo);
end;
procedure TSynGutterBase.SetColor(const Value: TColor);
begin
if FColor <> Value then
@ -301,6 +315,11 @@ begin
DoAutoSize;
end;
function TSynGutterBase.GetMouseActions: TSynEditMouseActions;
begin
Result := FMouseActions.UserActions;
end;
procedure TSynGutterBase.SetGutterParts(const AValue: TSynGutterPartListBase);
begin
FGutterPartList.Assign(AValue);
@ -317,10 +336,7 @@ end;
procedure TSynGutterBase.SetMouseActions(const AValue: TSynEditMouseActions);
begin
if AValue = nil then
FMouseActions.Clear
else
FMouseActions.Assign(AValue);
FMouseActions.UserActions := AValue;
end;
procedure TSynGutterBase.SetRightOffset(const AValue: integer);
@ -385,6 +401,11 @@ begin
Result := 0;
end;
function TSynGutterBase.CreateMouseActions: TSynEditMouseInternalActions;
begin
Result := TSynEditMouseInternalActions.Create(Self);
end;
procedure TSynGutterBase.DoChange(Sender: TObject);
begin
if FInDoChange then exit;
@ -465,6 +486,11 @@ begin
Result := TSynGutterPartListBase(Owner);
end;
function TSynGutterPartBase.GetMouseActions: TSynEditMouseActions;
begin
Result := FMouseActions.UserActions;
end;
function TSynGutterPartBase.GetFoldView: TSynEditFoldedView;
begin
Result := TSynEditFoldedView(FoldedTextBuffer);
@ -477,10 +503,7 @@ end;
procedure TSynGutterPartBase.SetMouseActions(const AValue: TSynEditMouseActions);
begin
if AValue = nil then
FMouseActions.Clear
else
FMouseActions.Assign(AValue);
FMouseActions.UserActions := AValue;
end;
function TSynGutterPartBase.PreferedWidth: Integer;
@ -539,6 +562,11 @@ begin
FOnChange(Self);
end;
function TSynGutterPartBase.CreateMouseActions: TSynEditMouseInternalActions;
begin
Result := TSynEditMouseInternalActions.Create(Self);
end;
constructor TSynGutterPartBase.Create(AOwner: TComponent);
begin
FMarkupInfo := TSynSelectedColor.Create;
@ -547,6 +575,8 @@ begin
FMarkupInfo.FrameColor := clNone;
FMarkupInfo.OnChange := {$IFDEF FPC}@{$ENDIF}DoChange;
FMouseActions := CreateMouseActions;
FVisible := True;
FAutoSize := True;
Inherited Create(AOwner); // Todo: Lock the DoChange from RegisterItem, and call DoChange at the end (after/in autosize)
@ -569,6 +599,7 @@ end;
destructor TSynGutterPartBase.Destroy;
begin
inherited Destroy;
FreeAndNil(FMouseActions);
FreeAndNil(FMarkupInfo);
end;
@ -609,9 +640,7 @@ end;
function TSynGutterPartBase.MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo;
HandleActionProc: TSynEditMouseActionHandler): Boolean;
begin
Result := False;
if assigned(FMouseActions) then
Result := HandleActionProc(MouseActions, AnInfo);
Result := HandleActionProc(FMouseActions.GetActionsForOptions(TCustomSynEdit(SynEdit).MouseOptions), AnInfo);
end;
function TSynGutterPartBase.DoHandleMouseAction(AnAction: TSynEditMouseAction;

View File

@ -34,27 +34,27 @@ type
{ TSynEditMouseActionsGutterFold }
TSynEditMouseActionsGutterFold = class(TSynEditMouseActions)
public
procedure ResetDefaults; override;
TSynEditMouseActionsGutterFold = class(TSynEditMouseInternalActions)
protected
procedure InitForOptions(AnOptions: TSynEditorMouseOptions); override;
end;
// Line with [-] => ALL nodes expanded
{ TSynEditMouseActionsGutterFoldExpanded }
TSynEditMouseActionsGutterFoldExpanded = class(TSynEditMouseActions)
public
procedure ResetDefaults; override;
TSynEditMouseActionsGutterFoldExpanded = class(TSynEditMouseInternalActions)
protected
procedure InitForOptions(AnOptions: TSynEditorMouseOptions); override;
end;
// Line with [+] => at LEAST ONE node collapsed
{ TSynEditMouseActionsGutterFoldCollapsed }
TSynEditMouseActionsGutterFoldCollapsed = class(TSynEditMouseActions)
public
procedure ResetDefaults; override;
TSynEditMouseActionsGutterFoldCollapsed = class(TSynEditMouseInternalActions)
protected
procedure InitForOptions(AnOptions: TSynEditorMouseOptions); override;
end;
TDrawNodeSymbolOptions = set of (nsoSubtype, nsoLostHl, nsoBlockSel);
@ -63,13 +63,15 @@ type
TSynGutterCodeFolding = class(TSynGutterPartBase)
private
FMouseActionsCollapsed: TSynEditMouseActions;
FMouseActionsExpanded: TSynEditMouseActions;
FMouseActionsCollapsed: TSynEditMouseInternalActions;
FMouseActionsExpanded: TSynEditMouseInternalActions;
FPopUp: TPopupMenu;
FMenuInf: Array of TFoldViewNodeInfo;
FIsFoldHidePreviousLine: Boolean;
FPopUpImageList: TImageList;
FReversePopMenuOrder: Boolean;
function GetMouseActionsCollapsed: TSynEditMouseActions;
function GetMouseActionsExpanded: TSynEditMouseActions;
procedure SetMouseActionsCollapsed(const AValue: TSynEditMouseActions);
procedure SetMouseActionsExpanded(const AValue: TSynEditMouseActions);
function FoldTypeForLine(AScreenLine: Integer): TSynEditFoldLineCapability;
@ -83,6 +85,7 @@ type
function PreferedWidth: Integer; override;
procedure CreatePopUpMenuEntries(var APopUp: TPopupMenu; ALine: Integer); virtual;
procedure PopClicked(Sender: TObject);
function CreateMouseActions: TSynEditMouseInternalActions; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -97,9 +100,9 @@ type
published
property MarkupInfo;
property MouseActionsExpanded: TSynEditMouseActions
read FMouseActionsExpanded write SetMouseActionsExpanded;
read GetMouseActionsExpanded write SetMouseActionsExpanded;
property MouseActionsCollapsed: TSynEditMouseActions
read FMouseActionsCollapsed write SetMouseActionsCollapsed;
read GetMouseActionsCollapsed write SetMouseActionsCollapsed;
property ReversePopMenuOrder: Boolean
read FReversePopMenuOrder write FReversePopMenuOrder default True;
end;
@ -116,18 +119,22 @@ var
procedure TSynGutterCodeFolding.SetMouseActionsCollapsed(const AValue: TSynEditMouseActions);
begin
if AValue = nil then
FMouseActionsCollapsed.Clear
else
FMouseActionsCollapsed.Assign(AValue);
FMouseActionsCollapsed.UserActions := AValue;
end;
function TSynGutterCodeFolding.GetMouseActionsCollapsed: TSynEditMouseActions;
begin
Result := FMouseActionsCollapsed.UserActions;
end;
function TSynGutterCodeFolding.GetMouseActionsExpanded: TSynEditMouseActions;
begin
Result := FMouseActionsExpanded.UserActions;
end;
procedure TSynGutterCodeFolding.SetMouseActionsExpanded(const AValue: TSynEditMouseActions);
begin
if AValue = nil then
FMouseActionsExpanded.Clear
else
FMouseActionsExpanded.Assign(AValue);
FMouseActionsExpanded.UserActions := AValue;
end;
function TSynGutterCodeFolding.FoldTypeForLine(AScreenLine: Integer): TSynEditFoldLineCapability;
@ -312,12 +319,8 @@ end;
constructor TSynGutterCodeFolding.Create(AOwner: TComponent);
begin
FReversePopMenuOrder := true;
FMouseActions := TSynEditMouseActionsGutterFold.Create(self);
FMouseActionsExpanded := TSynEditMouseActionsGutterFoldExpanded.Create(self);
FMouseActionsCollapsed := TSynEditMouseActionsGutterFoldCollapsed.Create(self);
FMouseActions.ResetDefaults;
FMouseActionsCollapsed.ResetDefaults;
FMouseActionsExpanded.ResetDefaults;
inherited Create(AOwner);
@ -328,7 +331,6 @@ end;
destructor TSynGutterCodeFolding.Destroy;
begin
FreeAndNil(FMouseActions);
FreeAndNil(FMouseActionsCollapsed);
FreeAndNil(FMouseActionsExpanded);
FreeAndNil(FPopUp);
@ -354,6 +356,11 @@ begin
end;
end;
function TSynGutterCodeFolding.CreateMouseActions: TSynEditMouseInternalActions;
begin
Result := TSynEditMouseActionsGutterFold.Create(self);
end;
procedure TSynGutterCodeFolding.DoOnGutterClick(X, Y : integer);
begin
// Do Nothing
@ -368,13 +375,13 @@ begin
tmp := FoldTypeForLine(FoldView.TextIndexToScreenLine(AnInfo.NewCaret.LinePos-1));
case tmp of
cfCollapsedFold, cfCollapsedHide:
Result := HandleActionProc(MouseActionsCollapsed, AnInfo);
Result := HandleActionProc(FMouseActionsCollapsed.GetActionsForOptions(TCustomSynEdit(SynEdit).MouseOptions), AnInfo);
cfFoldStart, cfHideStart:
Result := HandleActionProc(MouseActionsExpanded, AnInfo);
Result := HandleActionProc(FMouseActionsExpanded.GetActionsForOptions(TCustomSynEdit(SynEdit).MouseOptions), AnInfo);
end;
if not Result then
Result := HandleActionProc(MouseActions, AnInfo);
Result := inherited MaybeHandleMouseAction(AnInfo, HandleActionProc);
end;
function TSynGutterCodeFolding.DoHandleMouseAction(AnAction: TSynEditMouseAction;
@ -692,18 +699,24 @@ end;
{ TSynEditMouseActionsGutterFold }
procedure TSynEditMouseActionsGutterFold.ResetDefaults;
procedure TSynEditMouseActionsGutterFold.InitForOptions(AnOptions: TSynEditorMouseOptions);
var
rmc: Boolean;
begin
Clear;
AddCommand(emcCodeFoldContextMenu, False, mbRight, ccSingle, cdUp, [], []);
rmc := (emRightMouseMovesCursor in AnOptions);
AddCommand(emcNone, False, mbLeft, ccAny, cdDown, [], []);
AddCommand(emcCodeFoldCollaps, False, mbMiddle, ccAny, cdDown, [], [ssShift], emcoCodeFoldCollapsOne);
AddCommand(emcCodeFoldCollaps, False, mbMiddle, ccAny, cdDown, [ssShift], [ssShift], emcoCodeFoldCollapsAll);
AddCommand(emcNone, False, mbLeft, ccAny, cdDown, [], []);
AddCommand(emcCodeFoldContextMenu, rmc, mbRight, ccSingle, cdUp, [], []);
end;
{ TSynEditMouseActionsGutterFoldExpanded }
procedure TSynEditMouseActionsGutterFoldExpanded.ResetDefaults;
procedure TSynEditMouseActionsGutterFoldExpanded.InitForOptions(AnOptions: TSynEditorMouseOptions);
begin
Clear;
AddCommand(emcCodeFoldCollaps, False, mbLeft, ccAny, cdDown, [], [], emcoCodeFoldCollapsOne);
@ -711,13 +724,14 @@ end;
{ TSynEditMouseActionsGutterFoldCollapsed }
procedure TSynEditMouseActionsGutterFoldCollapsed.ResetDefaults;
procedure TSynEditMouseActionsGutterFoldCollapsed.InitForOptions(AnOptions: TSynEditorMouseOptions);
begin
Clear;
AddCommand(emcCodeFoldExpand, False, mbLeft, ccAny, cdDown, [ssCtrl], [ssCtrl], emcoCodeFoldExpandOne);
AddCommand(emcCodeFoldExpand, False, mbLeft, ccAny, cdDown, [], [ssCtrl], emcoCodeFoldExpandAll);
end;
finalization
FreeAndNil(GlobalPopUpImageList);

View File

@ -10,7 +10,7 @@ uses
type
TSynEditMouseActionsLineNum = class(TSynEditMouseActions)
TSynEditMouseActionsLineNum = class(TSynEditMouseInternalActions)
public // empty by default
end;
@ -38,6 +38,7 @@ type
procedure BufferChanged(Sender: TObject);
procedure FontChanged(Sender: TObject);
procedure SetAutoSize(const AValue : boolean); override;
function CreateMouseActions: TSynEditMouseInternalActions; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -62,9 +63,6 @@ uses
constructor TSynGutterLineNumber.Create(AOwner: TComponent);
begin
FMouseActions := TSynEditMouseActionsLineNum.Create(self);
FMouseActions.ResetDefaults;
FDigitCount := 2;
FAutoSizeDigitCount := FDigitCount;
FShowOnlyLineNumbersMultiplesOf := 1;
@ -87,7 +85,6 @@ destructor TSynGutterLineNumber.Destroy;
begin
TSynEditStringList(TextBuffer).RemoveHanlders(self);
FTextDrawer.UnRegisterOnFontChangeHandler({$IFDEF FPC}@{$ENDIF}FontChanged);
FreeAndNil(FMouseActions);
inherited Destroy;
end;
@ -214,6 +211,11 @@ begin
if AValue then LineCountChanged(nil, 0, 0);
end;
function TSynGutterLineNumber.CreateMouseActions: TSynEditMouseInternalActions;
begin
Result := TSynEditMouseActionsLineNum.Create(self);
end;
procedure TSynGutterLineNumber.Paint(Canvas : TCanvas; AClip : TRect; FirstLine, LastLine : integer);
var
i, iLine: integer;

View File

@ -24,8 +24,8 @@ interface
uses
Classes, SysUtils, LCLProc,
SynEdit, SynGutterBase, SynEditMiscClasses, SynEditMouseCmds,
PropEdits, PropEditUtils, Forms, StdCtrls, ComCtrls, Dialogs,
SynEdit, SynGutterBase, SynEditMiscClasses, SynEditMouseCmds, SynDesignStringConstants,
PropEdits, PropEditUtils, Forms, StdCtrls, ComCtrls, Dialogs, ComponentEditors,
ObjInspStrConsts, Controls, IDEImagesIntf, typinfo, FormEditingIntf;
type
@ -110,7 +110,17 @@ type
procedure SetValue(const NewValue: ansistring); override;
end;
{ TSynEditComponentEditor }
TSynEditComponentEditor = class(TDefaultComponentEditor)
public
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
end;
procedure RegisterGutterPartClass(AClass: TSynGutterPartBaseClass; AName: String);
implementation
{$R *.lfm}
@ -126,6 +136,40 @@ begin
KnownSynGutterPartClasses.AddObject(AName, TObject(Pointer(AClass)));
end;
{ TSynEditComponentEditor }
function TSynEditComponentEditor.GetVerbCount: Integer;
begin
Result := inherited GetVerbCount;
Result := Result + 1;
end;
function TSynEditComponentEditor.GetVerb(Index: Integer): string;
begin
case Index - (inherited GetVerbCount) of
0: Result := syndsResetMouseActions;
else
Result := inherited GetVerb(Index);
end;
end;
procedure TSynEditComponentEditor.ExecuteVerb(Index: Integer);
var
Hook: TPropertyEditorHook;
begin
case Index - (inherited GetVerbCount) of
0: begin
if (Component <> nil) and (Component is TCustomSynEdit) then
TCustomSynEdit(Component).ResetMouseActions;
Modified;
GetHook(Hook);
if Assigned(Hook) then Hook.Modified(Self);
end;
else
inherited GetVerb(Index);
end;
end;
{ TSynEdOptionsPropertyEditor }
procedure TSynEdOptionsPropertyEditor.GetProperties(Proc: TGetPropEditProc);