mirror of https://gitlab.com/basile.b/dexed.git
add editor command to comment the current identifier
This commit is contained in:
parent
6158dd26a2
commit
f1f2ad6b7e
|
@ -98,9 +98,13 @@ inherited CEEditorWidget: TCEEditorWidget
|
|||
Caption = '-'
|
||||
end
|
||||
object mnuedComm: TMenuItem
|
||||
Caption = 'Comment'
|
||||
Caption = 'Comment selected lines'
|
||||
OnClick = mnuedCommClick
|
||||
end
|
||||
object MenuItem6: TMenuItem
|
||||
Caption = 'Comment identifier'
|
||||
OnClick = MenuItem6Click
|
||||
end
|
||||
object mnuedInvAllNone: TMenuItem
|
||||
Caption = 'Invert version all none'
|
||||
OnClick = mnuedInvAllNoneClick
|
||||
|
|
|
@ -35,11 +35,14 @@ type
|
|||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TCEEditorWidget }
|
||||
|
||||
TCEEditorWidget = class(TCEWidget, ICEMultiDocObserver, ICEMultiDocHandler, ICEProjectObserver)
|
||||
MenuItem1: TMenuItem;
|
||||
MenuItem2: TMenuItem;
|
||||
MenuItem3: TMenuItem;
|
||||
MenuItem5: TMenuItem;
|
||||
MenuItem6: TMenuItem;
|
||||
mnuedRename: TMenuItem;
|
||||
mnuedInvAllNone: TMenuItem;
|
||||
mnuedComm: TMenuItem;
|
||||
|
@ -59,6 +62,7 @@ type
|
|||
editorStatus: TStatusBar;
|
||||
mnuEditor: TPopupMenu;
|
||||
procedure MenuItem5Click(Sender: TObject);
|
||||
procedure MenuItem6Click(Sender: TObject);
|
||||
procedure mnuedRenameClick(Sender: TObject);
|
||||
procedure mnuedInvAllNoneClick(Sender: TObject);
|
||||
procedure mnuedCommClick(Sender: TObject);
|
||||
|
@ -722,6 +726,12 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TCEEditorWidget.MenuItem6Click(Sender: TObject);
|
||||
begin
|
||||
if fDoc.isNotNil then
|
||||
fDoc.CommandProcessor(ecCommentIdentifier, '', nil);
|
||||
end;
|
||||
|
||||
procedure TCEEditorWidget.mnuedRenameClick(Sender: TObject);
|
||||
begin
|
||||
if fDoc.isNotNil then
|
||||
|
|
|
@ -247,6 +247,7 @@ const
|
|||
ecCommentSelection = ecUserFirst + 10;
|
||||
ecSwapVersionAllNone = ecUserFirst + 11;
|
||||
ecRenameIdentifier = ecUserFirst + 12;
|
||||
ecCommentIdentifier = ecUserFirst + 13;
|
||||
|
||||
var
|
||||
D2Syn: TSynD2Syn; // used as model to set the options when no editor exists.
|
||||
|
@ -735,6 +736,7 @@ begin
|
|||
AddKey(ecCommentSelection, ord('/'), [ssCtrl], 0, []);
|
||||
AddKey(ecSwapVersionAllNone, 0, [], 0, []);
|
||||
AddKey(ecRenameIdentifier, VK_F2, [ssCtrl], 0, []);
|
||||
AddKey(ecCommentIdentifier, 0, [], 0, []);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -753,6 +755,7 @@ begin
|
|||
'ecCommentSelection': begin Int := ecCommentSelection; exit(true); end;
|
||||
'ecSwapVersionAllNone': begin Int := ecSwapVersionAllNone; exit(true); end;
|
||||
'ecRenameIdentifier': begin Int := ecRenameIdentifier; exit(true); end;
|
||||
'ecCommentIdentifier': begin Int := ecCommentIdentifier; exit(true); end;
|
||||
else exit(false);
|
||||
end;
|
||||
end;
|
||||
|
@ -772,6 +775,7 @@ begin
|
|||
ecCommentSelection: begin Ident := 'ecCommentSelection'; exit(true); end;
|
||||
ecSwapVersionAllNone: begin Ident := 'ecSwapVersionAllNone'; exit(true); end;
|
||||
ecRenameIdentifier: begin Ident := 'ecRenameIdentifier'; exit(true); end;
|
||||
ecCommentIdentifier: begin Ident := 'ecCommentIdentifier'; exit(true); end;
|
||||
else exit(false);
|
||||
end;
|
||||
end;
|
||||
|
@ -908,6 +912,54 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure commentIdentifier(editor: TSynEdit);
|
||||
var
|
||||
str: string;
|
||||
comment: boolean = true;
|
||||
tkType, st: Integer;
|
||||
attrib: TSynHighlighterAttributes;
|
||||
begin
|
||||
if not editor.GetHighlighterAttriAtRowColEx(editor.CaretXY, str, tkType, st, attrib) then
|
||||
exit;
|
||||
if str.isEmpty then
|
||||
exit;
|
||||
|
||||
if (str.length > 1) and ((str[1..2] = '/*') or
|
||||
(str[str.length-1..str.length] = '*/')) then
|
||||
comment := false;
|
||||
|
||||
if comment then
|
||||
begin
|
||||
editor.BeginUndoBlock;
|
||||
editor.ExecuteCommand(ecWordLeft, '', nil);
|
||||
editor.ExecuteCommand(ecChar, '/', nil);
|
||||
editor.ExecuteCommand(ecChar, '*', nil);
|
||||
editor.ExecuteCommand(ecWordEndRight, '', nil);
|
||||
editor.ExecuteCommand(ecChar, '*', nil);
|
||||
editor.ExecuteCommand(ecChar, '/', nil);
|
||||
editor.EndUndoBlock;
|
||||
end else
|
||||
//TODO-ceditor: handle spaces between ident and comment beg end.
|
||||
begin
|
||||
editor.BeginUndoBlock;
|
||||
if str[1..2] = '/*' then
|
||||
begin
|
||||
editor.ExecuteCommand(ecWordLeft, '', nil);
|
||||
editor.ExecuteCommand(ecLeft, '', nil);
|
||||
editor.ExecuteCommand(ecLeft, '', nil);
|
||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
||||
end;
|
||||
if str[str.length-1..str.length] = '*/' then
|
||||
begin
|
||||
editor.ExecuteCommand(ecWordEndRight, '', nil);
|
||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
||||
editor.ExecuteCommand(ecDeleteChar, '', nil);
|
||||
end;
|
||||
editor.EndUndoBlock;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCESynMemo.DoOnProcessCommand(var Command: TSynEditorCommand;
|
||||
var AChar: TUTF8Char; Data: pointer);
|
||||
begin
|
||||
|
@ -943,6 +995,8 @@ begin
|
|||
invertVersionAllNone;
|
||||
ecRenameIdentifier:
|
||||
renameIdentifier;
|
||||
ecCommentIdentifier:
|
||||
commentIdentifier(self);
|
||||
end;
|
||||
if fOverrideColMode and not SelAvail then
|
||||
begin
|
||||
|
|
Loading…
Reference in New Issue