mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 00:19:22 +02:00
MG: added Un-/Comment Selection
git-svn-id: trunk@1845 -
This commit is contained in:
parent
ef21f8a534
commit
9edfb60be4
@ -71,6 +71,8 @@ procedure SaveRect(XMLConfig: TXMLConfig; const Path:string; var ARect:TRect);
|
|||||||
// miscellaneous
|
// miscellaneous
|
||||||
procedure FreeThenNil(var Obj: TObject);
|
procedure FreeThenNil(var Obj: TObject);
|
||||||
function TabsToSpaces(const s: string; TabWidth: integer): string;
|
function TabsToSpaces(const s: string; TabWidth: integer): string;
|
||||||
|
function CommentLines(const s: string): string;
|
||||||
|
function UncommentLines(const s: string): string;
|
||||||
procedure TranslateResourceStrings(const BaseDirectory, CustomLang: string);
|
procedure TranslateResourceStrings(const BaseDirectory, CustomLang: string);
|
||||||
function NameToValidIdentifier(const s: string): string;
|
function NameToValidIdentifier(const s: string): string;
|
||||||
|
|
||||||
@ -746,4 +748,99 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{-------------------------------------------------------------------------------
|
||||||
|
function CommentLines(const s: string): string;
|
||||||
|
|
||||||
|
Comment every line with a Delphicomment //
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
function CommentLines(const s: string): string;
|
||||||
|
var
|
||||||
|
CurPos: integer;
|
||||||
|
Dest: string;
|
||||||
|
|
||||||
|
procedure FindLineEnd;
|
||||||
|
begin
|
||||||
|
while (CurPos<=length(Dest))
|
||||||
|
and (not (Dest[CurPos] in [#10,#13])) do
|
||||||
|
inc(CurPos);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure CommentLine;
|
||||||
|
begin
|
||||||
|
Dest:=LeftStr(Dest,CurPos-1)+'//'+RightStr(Dest,length(Dest)-CurPos+1);
|
||||||
|
FindLineEnd;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Dest:=s;
|
||||||
|
CurPos:=1;
|
||||||
|
// find code start in line
|
||||||
|
while (CurPos<=length(Dest)) do begin
|
||||||
|
case Dest[CurPos] of
|
||||||
|
|
||||||
|
' ',#9:
|
||||||
|
// skip space
|
||||||
|
inc(CurPos);
|
||||||
|
|
||||||
|
#10,#13:
|
||||||
|
// line end found -> skip
|
||||||
|
inc(CurPos);
|
||||||
|
|
||||||
|
else
|
||||||
|
// code start found
|
||||||
|
CommentLine;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result:=Dest;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{-------------------------------------------------------------------------------
|
||||||
|
function CommentLines(const s: string): string;
|
||||||
|
|
||||||
|
Uncomment every line with a Delphicomment //
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
function UncommentLines(const s: string): string;
|
||||||
|
var
|
||||||
|
CurPos: integer;
|
||||||
|
Dest: string;
|
||||||
|
|
||||||
|
procedure FindLineEnd;
|
||||||
|
begin
|
||||||
|
while (CurPos<=length(Dest))
|
||||||
|
and (not (Dest[CurPos] in [#10,#13])) do
|
||||||
|
inc(CurPos);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure UncommentLine;
|
||||||
|
begin
|
||||||
|
Dest:=LeftStr(Dest,CurPos-1)+RightStr(Dest,length(Dest)-CurPos-1);
|
||||||
|
FindLineEnd;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Dest:=s;
|
||||||
|
CurPos:=1;
|
||||||
|
// find Delphi comment line
|
||||||
|
while (CurPos<=length(Dest)) do begin
|
||||||
|
case Dest[CurPos] of
|
||||||
|
|
||||||
|
' ',#9:
|
||||||
|
// skip space
|
||||||
|
inc(CurPos);
|
||||||
|
|
||||||
|
#10,#13:
|
||||||
|
// line end found -> skip
|
||||||
|
inc(CurPos);
|
||||||
|
|
||||||
|
else
|
||||||
|
// code start found
|
||||||
|
if (Dest[CurPos]='/') and (CurPos<length(Dest)) and (Dest[CurPos+1]='/')
|
||||||
|
then
|
||||||
|
UncommentLine;
|
||||||
|
FindLineEnd;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result:=Dest;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -73,6 +73,8 @@ const
|
|||||||
ecSelectionUpperCase = ecUserFirst + 50;
|
ecSelectionUpperCase = ecUserFirst + 50;
|
||||||
ecSelectionLowerCase = ecUserFirst + 51;
|
ecSelectionLowerCase = ecUserFirst + 51;
|
||||||
ecSelectionTabs2Spaces = ecUserFirst + 52;
|
ecSelectionTabs2Spaces = ecUserFirst + 52;
|
||||||
|
ecSelectionComment = ecUserFirst + 53;
|
||||||
|
ecSelectionUncomment = ecUserFirst + 54;
|
||||||
|
|
||||||
ecWordCompletion = ecUserFirst + 100;
|
ecWordCompletion = ecUserFirst + 100;
|
||||||
ecCompleteCode = ecUserFirst + 101;
|
ecCompleteCode = ecUserFirst + 101;
|
||||||
@ -465,6 +467,8 @@ begin
|
|||||||
ecSelectionUpperCase: Result:='Selection uppercase';
|
ecSelectionUpperCase: Result:='Selection uppercase';
|
||||||
ecSelectionLowerCase: Result:='Selection lowercase';
|
ecSelectionLowerCase: Result:='Selection lowercase';
|
||||||
ecSelectionTabs2Spaces: Result:='Selection tabs to spaces';
|
ecSelectionTabs2Spaces: Result:='Selection tabs to spaces';
|
||||||
|
ecSelectionComment: Result:='Comment selection';
|
||||||
|
ecSelectionUncomment: Result:='Uncomment selection';
|
||||||
|
|
||||||
// search menu
|
// search menu
|
||||||
ecFind: Result:= 'Find text';
|
ecFind: Result:= 'Find text';
|
||||||
@ -1115,6 +1119,8 @@ begin
|
|||||||
Add(C,'Uppercase selection',ecSelectionUpperCase,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
Add(C,'Uppercase selection',ecSelectionUpperCase,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
||||||
Add(C,'Lowercase selection',ecSelectionLowerCase,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
Add(C,'Lowercase selection',ecSelectionLowerCase,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
||||||
Add(C,'Convert tabs to spaces in selection',ecSelectionTabs2Spaces,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
Add(C,'Convert tabs to spaces in selection',ecSelectionTabs2Spaces,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
||||||
|
Add(C,'Comment selection',ecSelectionComment,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
||||||
|
Add(C,'Uncomment selection',ecSelectionUncomment,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
||||||
|
|
||||||
// editing
|
// editing
|
||||||
C:=Categories[AddCategory('editing commands','Text editing commands')];
|
C:=Categories[AddCategory('editing commands','Text editing commands')];
|
||||||
|
@ -114,6 +114,8 @@ ResourceString
|
|||||||
lisMenuUpperCaseSelection = 'Uppercase selection';
|
lisMenuUpperCaseSelection = 'Uppercase selection';
|
||||||
lisMenuLowerCaseSelection = 'Lowercase selection';
|
lisMenuLowerCaseSelection = 'Lowercase selection';
|
||||||
lisMenuTabsToSpacesSelection = 'Tabs to spaces in selection';
|
lisMenuTabsToSpacesSelection = 'Tabs to spaces in selection';
|
||||||
|
lisMenuCommentSelection = 'Comment selection';
|
||||||
|
lisMenuUncommentSelection = 'Uncomment selection';
|
||||||
lisMenuCompleteCode = 'Complete Code';
|
lisMenuCompleteCode = 'Complete Code';
|
||||||
|
|
||||||
lisMenuFind = 'Find';
|
lisMenuFind = 'Find';
|
||||||
|
20
ide/main.pp
20
ide/main.pp
@ -92,6 +92,8 @@ type
|
|||||||
procedure mnuEditUpperCaseBlockClicked(Sender: TObject);
|
procedure mnuEditUpperCaseBlockClicked(Sender: TObject);
|
||||||
procedure mnuEditLowerCaseBlockClicked(Sender: TObject);
|
procedure mnuEditLowerCaseBlockClicked(Sender: TObject);
|
||||||
procedure mnuEditTabsToSpacesBlockClicked(Sender: TObject);
|
procedure mnuEditTabsToSpacesBlockClicked(Sender: TObject);
|
||||||
|
procedure mnuEditCommentBlockClicked(Sender: TObject);
|
||||||
|
procedure mnuEditUncommentBlockClicked(Sender: TObject);
|
||||||
procedure mnuEditCompleteCodeClicked(Sender: TObject);
|
procedure mnuEditCompleteCodeClicked(Sender: TObject);
|
||||||
|
|
||||||
// search menu
|
// search menu
|
||||||
@ -162,7 +164,8 @@ type
|
|||||||
Procedure OnSrcNotebookDeleteLastJumPoint(Sender: TObject);
|
Procedure OnSrcNotebookDeleteLastJumPoint(Sender: TObject);
|
||||||
Procedure OnSrcNotebookEditorVisibleChanged(Sender : TObject);
|
Procedure OnSrcNotebookEditorVisibleChanged(Sender : TObject);
|
||||||
|
|
||||||
//this is fired when the editor is focused, changed, ?. Anything that causes the status change
|
// this is fired when the editor is focused, changed, ?.
|
||||||
|
// Anything that causes the status change
|
||||||
Procedure OnSrcNotebookEditorChanged(Sender : TObject);
|
Procedure OnSrcNotebookEditorChanged(Sender : TObject);
|
||||||
|
|
||||||
Procedure OnSrcNotebookFileNew(Sender : TObject);
|
Procedure OnSrcNotebookFileNew(Sender : TObject);
|
||||||
@ -1245,6 +1248,8 @@ begin
|
|||||||
itmEditUpperCaseBlock.OnClick:=@mnuEditUpperCaseBlockClicked;
|
itmEditUpperCaseBlock.OnClick:=@mnuEditUpperCaseBlockClicked;
|
||||||
itmEditLowerCaseBlock.OnClick:=@mnuEditLowerCaseBlockClicked;
|
itmEditLowerCaseBlock.OnClick:=@mnuEditLowerCaseBlockClicked;
|
||||||
itmEditTabsToSpacesBlock.OnClick:=@mnuEditTabsToSpacesBlockClicked;
|
itmEditTabsToSpacesBlock.OnClick:=@mnuEditTabsToSpacesBlockClicked;
|
||||||
|
itmEditCommentBlock.OnClick:=@mnuEditCommentBlockClicked;
|
||||||
|
itmEditUncommentBlock.OnClick:=@mnuEditUncommentBlockClicked;
|
||||||
itmEditCompleteCode.OnClick:=@mnuEditCompleteCodeClicked;
|
itmEditCompleteCode.OnClick:=@mnuEditCompleteCodeClicked;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -6402,6 +6407,16 @@ begin
|
|||||||
DoEditMenuCommand(ecSelectionTabs2Spaces);
|
DoEditMenuCommand(ecSelectionTabs2Spaces);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainIDE.mnuEditCommentBlockClicked(Sender: TObject);
|
||||||
|
begin
|
||||||
|
DoEditMenuCommand(ecSelectionComment);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMainIDE.mnuEditUncommentBlockClicked(Sender: TObject);
|
||||||
|
begin
|
||||||
|
DoEditMenuCommand(ecSelectionUncomment);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainIDE.mnuEditCompleteCodeClicked(Sender: TObject);
|
procedure TMainIDE.mnuEditCompleteCodeClicked(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
DoCompleteCodeAtCursor;
|
DoCompleteCodeAtCursor;
|
||||||
@ -6487,6 +6502,9 @@ end.
|
|||||||
|
|
||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.341 2002/08/16 19:00:54 lazarus
|
||||||
|
MG: added Un-/Comment Selection
|
||||||
|
|
||||||
Revision 1.340 2002/08/16 17:47:37 lazarus
|
Revision 1.340 2002/08/16 17:47:37 lazarus
|
||||||
MG: added some IDE menuicons, fixed submenu indicator bug
|
MG: added some IDE menuicons, fixed submenu indicator bug
|
||||||
|
|
||||||
|
@ -135,6 +135,8 @@ type
|
|||||||
itmEditUpperCaseBlock: TMenuItem;
|
itmEditUpperCaseBlock: TMenuItem;
|
||||||
itmEditLowerCaseBlock: TMenuItem;
|
itmEditLowerCaseBlock: TMenuItem;
|
||||||
itmEditTabsToSpacesBlock: TMenuItem;
|
itmEditTabsToSpacesBlock: TMenuItem;
|
||||||
|
itmEditCommentBlock: TMenuItem;
|
||||||
|
itmEditUncommentBlock: TMenuItem;
|
||||||
itmEditCompleteCode: TMenuItem;
|
itmEditCompleteCode: TMenuItem;
|
||||||
|
|
||||||
itmSearchFind: TMenuItem;
|
itmSearchFind: TMenuItem;
|
||||||
@ -385,6 +387,8 @@ begin
|
|||||||
itmEditUnindentBlock.Graphic:=LoadPixmap('menu_unindent');
|
itmEditUnindentBlock.Graphic:=LoadPixmap('menu_unindent');
|
||||||
mnuEdit.Add(itmEditUnindentBlock);
|
mnuEdit.Add(itmEditUnindentBlock);
|
||||||
|
|
||||||
|
mnuEdit.Add(CreateMenuSeparator);
|
||||||
|
|
||||||
itmEditUpperCaseBlock := TMenuItem.Create(Self);
|
itmEditUpperCaseBlock := TMenuItem.Create(Self);
|
||||||
itmEditUpperCaseBlock.Name:='itmEditUpperCaseBlock';
|
itmEditUpperCaseBlock.Name:='itmEditUpperCaseBlock';
|
||||||
itmEditUpperCaseBlock.Caption := lisMenuUpperCaseSelection;
|
itmEditUpperCaseBlock.Caption := lisMenuUpperCaseSelection;
|
||||||
@ -395,6 +399,8 @@ begin
|
|||||||
itmEditLowerCaseBlock.Caption := lisMenuLowerCaseSelection;
|
itmEditLowerCaseBlock.Caption := lisMenuLowerCaseSelection;
|
||||||
mnuEdit.Add(itmEditLowerCaseBlock);
|
mnuEdit.Add(itmEditLowerCaseBlock);
|
||||||
|
|
||||||
|
mnuEdit.Add(CreateMenuSeparator);
|
||||||
|
|
||||||
itmEditTabsToSpacesBlock := TMenuItem.Create(Self);
|
itmEditTabsToSpacesBlock := TMenuItem.Create(Self);
|
||||||
itmEditTabsToSpacesBlock.Name:='itmEditTabsToSpacesBlock';
|
itmEditTabsToSpacesBlock.Name:='itmEditTabsToSpacesBlock';
|
||||||
itmEditTabsToSpacesBlock.Caption := lisMenuTabsToSpacesSelection;
|
itmEditTabsToSpacesBlock.Caption := lisMenuTabsToSpacesSelection;
|
||||||
@ -402,6 +408,18 @@ begin
|
|||||||
|
|
||||||
mnuEdit.Add(CreateMenuSeparator);
|
mnuEdit.Add(CreateMenuSeparator);
|
||||||
|
|
||||||
|
itmEditCommentBlock := TMenuItem.Create(Self);
|
||||||
|
itmEditCommentBlock.Name:='itmEditCommentBlock';
|
||||||
|
itmEditCommentBlock.Caption := lisMenuCommentSelection;
|
||||||
|
mnuEdit.Add(itmEditCommentBlock);
|
||||||
|
|
||||||
|
itmEditUncommentBlock := TMenuItem.Create(Self);
|
||||||
|
itmEditUncommentBlock.Name:='itmEditUncommentBlock';
|
||||||
|
itmEditUncommentBlock.Caption := lisMenuUncommentSelection;
|
||||||
|
mnuEdit.Add(itmEditUncommentBlock);
|
||||||
|
|
||||||
|
mnuEdit.Add(CreateMenuSeparator);
|
||||||
|
|
||||||
itmEditCompleteCode := TMenuItem.Create(Self);
|
itmEditCompleteCode := TMenuItem.Create(Self);
|
||||||
itmEditCompleteCode.Name:='itmEditCompleteCode';
|
itmEditCompleteCode.Name:='itmEditCompleteCode';
|
||||||
itmEditCompleteCode.Caption := lisMenuCompleteCode;
|
itmEditCompleteCode.Caption := lisMenuCompleteCode;
|
||||||
@ -774,6 +792,8 @@ begin
|
|||||||
itmEditUpperCaseBlock.ShortCut:=CommandToShortCut(ecSelectionUpperCase);
|
itmEditUpperCaseBlock.ShortCut:=CommandToShortCut(ecSelectionUpperCase);
|
||||||
itmEditLowerCaseBlock.ShortCut:=CommandToShortCut(ecSelectionLowerCase);
|
itmEditLowerCaseBlock.ShortCut:=CommandToShortCut(ecSelectionLowerCase);
|
||||||
itmEditTabsToSpacesBlock.ShortCut:=CommandToShortCut(ecSelectionTabs2Spaces);
|
itmEditTabsToSpacesBlock.ShortCut:=CommandToShortCut(ecSelectionTabs2Spaces);
|
||||||
|
itmEditCommentBlock.ShortCut:=CommandToShortCut(ecSelectionComment);
|
||||||
|
itmEditUncommentBlock.ShortCut:=CommandToShortCut(ecSelectionUncomment);
|
||||||
itmEditCompleteCode.ShortCut:=CommandToShortCut(ecCompleteCode);
|
itmEditCompleteCode.ShortCut:=CommandToShortCut(ecCompleteCode);
|
||||||
|
|
||||||
itmSearchFind.ShortCut:=CommandToShortCut(ecFind);
|
itmSearchFind.ShortCut:=CommandToShortCut(ecFind);
|
||||||
|
@ -213,6 +213,8 @@ type
|
|||||||
procedure UpperCaseSelection;
|
procedure UpperCaseSelection;
|
||||||
procedure LowerCaseSelection;
|
procedure LowerCaseSelection;
|
||||||
procedure TabsToSpacesInSelection;
|
procedure TabsToSpacesInSelection;
|
||||||
|
procedure CommentSelection;
|
||||||
|
procedure UncommentSelection;
|
||||||
|
|
||||||
|
|
||||||
// editor commands
|
// editor commands
|
||||||
@ -862,6 +864,12 @@ Begin
|
|||||||
ecSelectionTabs2Spaces:
|
ecSelectionTabs2Spaces:
|
||||||
TabsToSpacesInSelection;
|
TabsToSpacesInSelection;
|
||||||
|
|
||||||
|
ecSelectionComment:
|
||||||
|
CommentSelection;
|
||||||
|
|
||||||
|
ecSelectionUnComment:
|
||||||
|
UncommentSelection;
|
||||||
|
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Handled:=false;
|
Handled:=false;
|
||||||
@ -1007,6 +1015,7 @@ begin
|
|||||||
OldBlockEnd:=FEditor.BlockEnd;
|
OldBlockEnd:=FEditor.BlockEnd;
|
||||||
FEditor.BeginUpdate;
|
FEditor.BeginUpdate;
|
||||||
FEditor.BeginUndoBlock;
|
FEditor.BeginUndoBlock;
|
||||||
|
// ToDo: replace step by step to keep bookmarks and breakpoints
|
||||||
FEditor.SelText:=TabsToSpaces(EditorComponent.SelText,EditorComponent.TabWidth);
|
FEditor.SelText:=TabsToSpaces(EditorComponent.SelText,EditorComponent.TabWidth);
|
||||||
FEditor.BlockBegin:=OldBlockBegin;
|
FEditor.BlockBegin:=OldBlockBegin;
|
||||||
FEditor.BlockEnd:=OldBlockEnd;
|
FEditor.BlockEnd:=OldBlockEnd;
|
||||||
@ -1014,6 +1023,38 @@ begin
|
|||||||
FEditor.EndUpdate;
|
FEditor.EndUpdate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSourceEditor.CommentSelection;
|
||||||
|
var OldBlockBegin, OldBlockEnd: TPoint;
|
||||||
|
begin
|
||||||
|
if not EditorComponent.SelAvail then exit;
|
||||||
|
OldBlockBegin:=FEditor.BlockBegin;
|
||||||
|
OldBlockEnd:=FEditor.BlockEnd;
|
||||||
|
FEditor.BeginUpdate;
|
||||||
|
FEditor.BeginUndoBlock;
|
||||||
|
// ToDo: replace step by step to keep bookmarks and breakpoints
|
||||||
|
FEditor.SelText:=CommentLines(EditorComponent.SelText);
|
||||||
|
FEditor.BlockBegin:=OldBlockBegin;
|
||||||
|
FEditor.BlockEnd:=OldBlockEnd;
|
||||||
|
FEditor.EndUndoBlock;
|
||||||
|
FEditor.EndUpdate;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSourceEditor.UncommentSelection;
|
||||||
|
var OldBlockBegin, OldBlockEnd: TPoint;
|
||||||
|
begin
|
||||||
|
if not EditorComponent.SelAvail then exit;
|
||||||
|
OldBlockBegin:=FEditor.BlockBegin;
|
||||||
|
OldBlockEnd:=FEditor.BlockEnd;
|
||||||
|
FEditor.BeginUpdate;
|
||||||
|
FEditor.BeginUndoBlock;
|
||||||
|
// ToDo: replace step by step to keep bookmarks and breakpoints
|
||||||
|
FEditor.SelText:=UncommentLines(EditorComponent.SelText);
|
||||||
|
FEditor.BlockBegin:=OldBlockBegin;
|
||||||
|
FEditor.BlockEnd:=OldBlockEnd;
|
||||||
|
FEditor.EndUndoBlock;
|
||||||
|
FEditor.EndUpdate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSourceEditor.RemoveBreakPoint(const ABreakPointMark: TSynEditMark);
|
procedure TSourceEditor.RemoveBreakPoint(const ABreakPointMark: TSynEditMark);
|
||||||
begin
|
begin
|
||||||
if not IsBreakPointMark(ABreakPointMark) then Exit;
|
if not IsBreakPointMark(ABreakPointMark) then Exit;
|
||||||
|
Loading…
Reference in New Issue
Block a user