mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-05 12:36:07 +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
|
||||
procedure FreeThenNil(var Obj: TObject);
|
||||
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);
|
||||
function NameToValidIdentifier(const s: string): string;
|
||||
|
||||
@ -746,4 +748,99 @@ begin
|
||||
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.
|
||||
|
@ -73,6 +73,8 @@ const
|
||||
ecSelectionUpperCase = ecUserFirst + 50;
|
||||
ecSelectionLowerCase = ecUserFirst + 51;
|
||||
ecSelectionTabs2Spaces = ecUserFirst + 52;
|
||||
ecSelectionComment = ecUserFirst + 53;
|
||||
ecSelectionUncomment = ecUserFirst + 54;
|
||||
|
||||
ecWordCompletion = ecUserFirst + 100;
|
||||
ecCompleteCode = ecUserFirst + 101;
|
||||
@ -465,6 +467,8 @@ begin
|
||||
ecSelectionUpperCase: Result:='Selection uppercase';
|
||||
ecSelectionLowerCase: Result:='Selection lowercase';
|
||||
ecSelectionTabs2Spaces: Result:='Selection tabs to spaces';
|
||||
ecSelectionComment: Result:='Comment selection';
|
||||
ecSelectionUncomment: Result:='Uncomment selection';
|
||||
|
||||
// search menu
|
||||
ecFind: Result:= 'Find text';
|
||||
@ -1115,6 +1119,8 @@ begin
|
||||
Add(C,'Uppercase selection',ecSelectionUpperCase,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,'Comment selection',ecSelectionComment,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
||||
Add(C,'Uncomment selection',ecSelectionUncomment,VK_UNKNOWN, [],VK_UNKNOWN,[]);
|
||||
|
||||
// editing
|
||||
C:=Categories[AddCategory('editing commands','Text editing commands')];
|
||||
|
@ -114,6 +114,8 @@ ResourceString
|
||||
lisMenuUpperCaseSelection = 'Uppercase selection';
|
||||
lisMenuLowerCaseSelection = 'Lowercase selection';
|
||||
lisMenuTabsToSpacesSelection = 'Tabs to spaces in selection';
|
||||
lisMenuCommentSelection = 'Comment selection';
|
||||
lisMenuUncommentSelection = 'Uncomment selection';
|
||||
lisMenuCompleteCode = 'Complete Code';
|
||||
|
||||
lisMenuFind = 'Find';
|
||||
|
24
ide/main.pp
24
ide/main.pp
@ -1,8 +1,8 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
/***************************************************************************
|
||||
main.pp - Toolbar
|
||||
-------------------
|
||||
main.pp - Toolbar
|
||||
-------------------
|
||||
TMainIDE is the application toolbar window.
|
||||
|
||||
|
||||
@ -92,6 +92,8 @@ type
|
||||
procedure mnuEditUpperCaseBlockClicked(Sender: TObject);
|
||||
procedure mnuEditLowerCaseBlockClicked(Sender: TObject);
|
||||
procedure mnuEditTabsToSpacesBlockClicked(Sender: TObject);
|
||||
procedure mnuEditCommentBlockClicked(Sender: TObject);
|
||||
procedure mnuEditUncommentBlockClicked(Sender: TObject);
|
||||
procedure mnuEditCompleteCodeClicked(Sender: TObject);
|
||||
|
||||
// search menu
|
||||
@ -162,7 +164,8 @@ type
|
||||
Procedure OnSrcNotebookDeleteLastJumPoint(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 OnSrcNotebookFileNew(Sender : TObject);
|
||||
@ -1245,6 +1248,8 @@ begin
|
||||
itmEditUpperCaseBlock.OnClick:=@mnuEditUpperCaseBlockClicked;
|
||||
itmEditLowerCaseBlock.OnClick:=@mnuEditLowerCaseBlockClicked;
|
||||
itmEditTabsToSpacesBlock.OnClick:=@mnuEditTabsToSpacesBlockClicked;
|
||||
itmEditCommentBlock.OnClick:=@mnuEditCommentBlockClicked;
|
||||
itmEditUncommentBlock.OnClick:=@mnuEditUncommentBlockClicked;
|
||||
itmEditCompleteCode.OnClick:=@mnuEditCompleteCodeClicked;
|
||||
end;
|
||||
|
||||
@ -6402,6 +6407,16 @@ begin
|
||||
DoEditMenuCommand(ecSelectionTabs2Spaces);
|
||||
end;
|
||||
|
||||
procedure TMainIDE.mnuEditCommentBlockClicked(Sender: TObject);
|
||||
begin
|
||||
DoEditMenuCommand(ecSelectionComment);
|
||||
end;
|
||||
|
||||
procedure TMainIDE.mnuEditUncommentBlockClicked(Sender: TObject);
|
||||
begin
|
||||
DoEditMenuCommand(ecSelectionUncomment);
|
||||
end;
|
||||
|
||||
procedure TMainIDE.mnuEditCompleteCodeClicked(Sender: TObject);
|
||||
begin
|
||||
DoCompleteCodeAtCursor;
|
||||
@ -6487,6 +6502,9 @@ end.
|
||||
|
||||
{ =============================================================================
|
||||
$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
|
||||
MG: added some IDE menuicons, fixed submenu indicator bug
|
||||
|
||||
|
@ -135,6 +135,8 @@ type
|
||||
itmEditUpperCaseBlock: TMenuItem;
|
||||
itmEditLowerCaseBlock: TMenuItem;
|
||||
itmEditTabsToSpacesBlock: TMenuItem;
|
||||
itmEditCommentBlock: TMenuItem;
|
||||
itmEditUncommentBlock: TMenuItem;
|
||||
itmEditCompleteCode: TMenuItem;
|
||||
|
||||
itmSearchFind: TMenuItem;
|
||||
@ -385,6 +387,8 @@ begin
|
||||
itmEditUnindentBlock.Graphic:=LoadPixmap('menu_unindent');
|
||||
mnuEdit.Add(itmEditUnindentBlock);
|
||||
|
||||
mnuEdit.Add(CreateMenuSeparator);
|
||||
|
||||
itmEditUpperCaseBlock := TMenuItem.Create(Self);
|
||||
itmEditUpperCaseBlock.Name:='itmEditUpperCaseBlock';
|
||||
itmEditUpperCaseBlock.Caption := lisMenuUpperCaseSelection;
|
||||
@ -395,6 +399,8 @@ begin
|
||||
itmEditLowerCaseBlock.Caption := lisMenuLowerCaseSelection;
|
||||
mnuEdit.Add(itmEditLowerCaseBlock);
|
||||
|
||||
mnuEdit.Add(CreateMenuSeparator);
|
||||
|
||||
itmEditTabsToSpacesBlock := TMenuItem.Create(Self);
|
||||
itmEditTabsToSpacesBlock.Name:='itmEditTabsToSpacesBlock';
|
||||
itmEditTabsToSpacesBlock.Caption := lisMenuTabsToSpacesSelection;
|
||||
@ -402,6 +408,18 @@ begin
|
||||
|
||||
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.Name:='itmEditCompleteCode';
|
||||
itmEditCompleteCode.Caption := lisMenuCompleteCode;
|
||||
@ -774,6 +792,8 @@ begin
|
||||
itmEditUpperCaseBlock.ShortCut:=CommandToShortCut(ecSelectionUpperCase);
|
||||
itmEditLowerCaseBlock.ShortCut:=CommandToShortCut(ecSelectionLowerCase);
|
||||
itmEditTabsToSpacesBlock.ShortCut:=CommandToShortCut(ecSelectionTabs2Spaces);
|
||||
itmEditCommentBlock.ShortCut:=CommandToShortCut(ecSelectionComment);
|
||||
itmEditUncommentBlock.ShortCut:=CommandToShortCut(ecSelectionUncomment);
|
||||
itmEditCompleteCode.ShortCut:=CommandToShortCut(ecCompleteCode);
|
||||
|
||||
itmSearchFind.ShortCut:=CommandToShortCut(ecFind);
|
||||
|
@ -213,6 +213,8 @@ type
|
||||
procedure UpperCaseSelection;
|
||||
procedure LowerCaseSelection;
|
||||
procedure TabsToSpacesInSelection;
|
||||
procedure CommentSelection;
|
||||
procedure UncommentSelection;
|
||||
|
||||
|
||||
// editor commands
|
||||
@ -862,6 +864,12 @@ Begin
|
||||
ecSelectionTabs2Spaces:
|
||||
TabsToSpacesInSelection;
|
||||
|
||||
ecSelectionComment:
|
||||
CommentSelection;
|
||||
|
||||
ecSelectionUnComment:
|
||||
UncommentSelection;
|
||||
|
||||
else
|
||||
begin
|
||||
Handled:=false;
|
||||
@ -1007,6 +1015,7 @@ begin
|
||||
OldBlockEnd:=FEditor.BlockEnd;
|
||||
FEditor.BeginUpdate;
|
||||
FEditor.BeginUndoBlock;
|
||||
// ToDo: replace step by step to keep bookmarks and breakpoints
|
||||
FEditor.SelText:=TabsToSpaces(EditorComponent.SelText,EditorComponent.TabWidth);
|
||||
FEditor.BlockBegin:=OldBlockBegin;
|
||||
FEditor.BlockEnd:=OldBlockEnd;
|
||||
@ -1014,6 +1023,38 @@ begin
|
||||
FEditor.EndUpdate;
|
||||
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);
|
||||
begin
|
||||
if not IsBreakPointMark(ABreakPointMark) then Exit;
|
||||
|
Loading…
Reference in New Issue
Block a user