IDE: added refactoring tool: remove empty methods

git-svn-id: trunk@14975 -
This commit is contained in:
mattias 2008-04-25 16:19:02 +00:00
parent 4a04d904f2
commit bb13c13e0d
11 changed files with 837 additions and 2 deletions

3
.gitattributes vendored
View File

@ -1990,6 +1990,9 @@ ide/editoroptions.pp svneol=native#text/pascal
ide/editoroptions_new.lfm svneol=native#text/plain
ide/editoroptions_new.lrs svneol=native#text/pascal
ide/editoroptions_new.pp svneol=native#text/pascal
ide/emptymethodsdlg.lfm svneol=native#text/plain
ide/emptymethodsdlg.lrs svneol=native#text/plain
ide/emptymethodsdlg.pas svneol=native#text/plain
ide/encloseselectiondlg.lfm svneol=native#text/plain
ide/encloseselectiondlg.lrs svneol=native#text/pascal
ide/encloseselectiondlg.pas svneol=native#text/pascal

View File

@ -52,6 +52,11 @@ type
pcsPublished
);
TPascalClassSections = set of TPascalClassSection;
const
AllPascalClassSections = [low(TPascalClassSection)..high(TPascalClassSection)];
type
{ TCodeXYPositions - a list of PCodeXYPosition }

View File

@ -117,6 +117,7 @@ begin
if not CodeToolBoss.FindAbstractMethods(Code,Caret.X,Caret.Y,
ListOfPCodeXYPosition,false) then
begin
DebugLn(['ShowAbstractMethodsDialog CodeToolBoss.FindAbstractMethods failed']);
if CodeToolBoss.ErrorMessage<>'' then begin
ErrMsg:='';
LazarusIDE.DoJumpToCodeToolBossError;

444
ide/emptymethodsdlg.lfm Normal file
View File

@ -0,0 +1,444 @@
object EmptyMethodsDialog: TEmptyMethodsDialog
Left = 290
Height = 421
Top = 202
Width = 387
HorzScrollBar.Page = 386
VertScrollBar.Page = 420
ActiveControl = PrivateCheckBox
Caption = 'EmptyMethodsDialog'
ClientHeight = 421
ClientWidth = 387
OnCreate = FormCreate
LCLVersion = '0.9.25'
object ButtonPanel1: TButtonPanel
Left = 6
Height = 50
Top = 371
Width = 375
Align = alBottom
AutoSize = True
TabOrder = 0
ShowButtons = [pbOK, pbCancel]
ShowGlyphs = [pbOK, pbCancel, pbClose, pbHelp]
end
object MethodsGroupBox: TGroupBox
Height = 238
Top = 133
Width = 387
Align = alClient
Caption = 'MethodsGroupBox'
ClientHeight = 219
ClientWidth = 383
TabOrder = 1
object MethodsSynEdit: TSynEdit
Height = 219
Width = 383
Align = alClient
Font.Height = -14
Font.Name = 'courier'
ParentColor = False
TabOrder = 0
Gutter.CodeFoldingWidth = 14
Highlighter = SynPasSyn1
Keystrokes = <
item
Command = 3
ShortCut = 38
end
item
Command = 103
ShortCut = 8230
end
item
Command = 211
ShortCut = 16422
end
item
Command = 4
ShortCut = 40
end
item
Command = 104
ShortCut = 8232
end
item
Command = 212
ShortCut = 16424
end
item
Command = 1
ShortCut = 37
end
item
Command = 101
ShortCut = 8229
end
item
Command = 5
ShortCut = 16421
end
item
Command = 105
ShortCut = 24613
end
item
Command = 2
ShortCut = 39
end
item
Command = 102
ShortCut = 8231
end
item
Command = 6
ShortCut = 16423
end
item
Command = 106
ShortCut = 24615
end
item
Command = 10
ShortCut = 34
end
item
Command = 110
ShortCut = 8226
end
item
Command = 14
ShortCut = 16418
end
item
Command = 114
ShortCut = 24610
end
item
Command = 9
ShortCut = 33
end
item
Command = 109
ShortCut = 8225
end
item
Command = 13
ShortCut = 16417
end
item
Command = 113
ShortCut = 24609
end
item
Command = 7
ShortCut = 36
end
item
Command = 107
ShortCut = 8228
end
item
Command = 15
ShortCut = 16420
end
item
Command = 115
ShortCut = 24612
end
item
Command = 8
ShortCut = 35
end
item
Command = 108
ShortCut = 8227
end
item
Command = 16
ShortCut = 16419
end
item
Command = 116
ShortCut = 24611
end
item
Command = 223
ShortCut = 45
end
item
Command = 201
ShortCut = 16429
end
item
Command = 604
ShortCut = 8237
end
item
Command = 502
ShortCut = 46
end
item
Command = 603
ShortCut = 8238
end
item
Command = 501
ShortCut = 8
end
item
Command = 501
ShortCut = 8200
end
item
Command = 504
ShortCut = 16392
end
item
Command = 601
ShortCut = 32776
end
item
Command = 602
ShortCut = 40968
end
item
Command = 509
ShortCut = 13
end
item
Command = 199
ShortCut = 16449
end
item
Command = 201
ShortCut = 16451
end
item
Command = 610
ShortCut = 24649
end
item
Command = 509
ShortCut = 16461
end
item
Command = 510
ShortCut = 16462
end
item
Command = 503
ShortCut = 16468
end
item
Command = 611
ShortCut = 24661
end
item
Command = 604
ShortCut = 16470
end
item
Command = 603
ShortCut = 16472
end
item
Command = 507
ShortCut = 16473
end
item
Command = 506
ShortCut = 24665
end
item
Command = 601
ShortCut = 16474
end
item
Command = 602
ShortCut = 24666
end
item
Command = 301
ShortCut = 16432
end
item
Command = 302
ShortCut = 16433
end
item
Command = 303
ShortCut = 16434
end
item
Command = 304
ShortCut = 16435
end
item
Command = 305
ShortCut = 16436
end
item
Command = 306
ShortCut = 16437
end
item
Command = 307
ShortCut = 16438
end
item
Command = 308
ShortCut = 16439
end
item
Command = 309
ShortCut = 16440
end
item
Command = 310
ShortCut = 16441
end
item
Command = 351
ShortCut = 24624
end
item
Command = 352
ShortCut = 24625
end
item
Command = 353
ShortCut = 24626
end
item
Command = 354
ShortCut = 24627
end
item
Command = 355
ShortCut = 24628
end
item
Command = 356
ShortCut = 24629
end
item
Command = 357
ShortCut = 24630
end
item
Command = 358
ShortCut = 24631
end
item
Command = 359
ShortCut = 24632
end
item
Command = 360
ShortCut = 24633
end
item
Command = 231
ShortCut = 24654
end
item
Command = 232
ShortCut = 24643
end
item
Command = 233
ShortCut = 24652
end
item
Command = 612
ShortCut = 9
end
item
Command = 613
ShortCut = 8201
end
item
Command = 250
ShortCut = 24642
end>
Lines.Strings = (
'MethodsSynEdit'
)
end
end
object SectionsGroupBox: TGroupBox
Height = 133
Width = 387
Align = alTop
AutoSize = True
Caption = 'SectionsGroupBox'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 15
ChildSizing.Layout = cclTopToBottomThenLeftToRight
ChildSizing.ControlsPerLine = 4
ClientHeight = 114
ClientWidth = 383
TabOrder = 2
object PrivateCheckBox: TCheckBox
Left = 6
Height = 29
Top = 6
Width = 149
Caption = 'PrivateCheckBox'
OnChange = PrivateCheckBoxChange
TabOrder = 0
end
object ProtectedCheckBox: TCheckBox
Left = 6
Height = 29
Top = 35
Width = 149
Caption = 'ProtectedCheckBox'
OnChange = PrivateCheckBoxChange
TabOrder = 1
end
object PublicCheckBox: TCheckBox
Left = 6
Height = 22
Top = 64
Width = 149
Caption = 'PublicCheckBox'
OnChange = PrivateCheckBoxChange
TabOrder = 2
end
object PublishedCheckBox: TCheckBox
Left = 6
Height = 22
Top = 86
Width = 149
Caption = 'PublishedCheckBox'
OnChange = PrivateCheckBoxChange
TabOrder = 3
end
object AllButton: TButton
Left = 170
Height = 29
Top = 6
Width = 116
Caption = 'AllButton'
OnClick = AllButtonClick
TabOrder = 4
end
object PublishedButton: TButton
Left = 170
Height = 29
Top = 35
Width = 116
Caption = 'PublishedButton'
OnClick = PublishedButtonClick
TabOrder = 5
end
end
object SynPasSyn1: TSynPasSyn
Enabled = False
left = 103
top = 199
end
end

82
ide/emptymethodsdlg.lrs Normal file
View File

@ -0,0 +1,82 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TEmptyMethodsDialog','FORMDATA',[
'TPF0'#19'TEmptyMethodsDialog'#18'EmptyMethodsDialog'#4'Left'#3'"'#1#6'Height'
+#3#165#1#3'Top'#3#202#0#5'Width'#3#131#1#18'HorzScrollBar.Page'#3#130#1#18'V'
+'ertScrollBar.Page'#3#164#1#13'ActiveControl'#7#15'PrivateCheckBox'#7'Captio'
+'n'#6#18'EmptyMethodsDialog'#12'ClientHeight'#3#165#1#11'ClientWidth'#3#131#1
+#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#6'0.9.25'#0#12'TButtonPanel'
+#12'ButtonPanel1'#4'Left'#2#6#6'Height'#2'2'#3'Top'#3's'#1#5'Width'#3'w'#1#5
+'Align'#7#8'alBottom'#8'AutoSize'#9#8'TabOrder'#2#0#11'ShowButtons'#11#4'pbO'
+'K'#8'pbCancel'#0#10'ShowGlyphs'#11#4'pbOK'#8'pbCancel'#7'pbClose'#6'pbHelp'
+#0#0#0#9'TGroupBox'#15'MethodsGroupBox'#6'Height'#3#238#0#3'Top'#3#133#0#5'W'
+'idth'#3#131#1#5'Align'#7#8'alClient'#7'Caption'#6#15'MethodsGroupBox'#12'Cl'
+'ientHeight'#3#219#0#11'ClientWidth'#3''#1#8'TabOrder'#2#1#0#8'TSynEdit'#14
+'MethodsSynEdit'#6'Height'#3#219#0#5'Width'#3''#1#5'Align'#7#8'alClient'#11
+'Font.Height'#2#242#9'Font.Name'#6#7'courier'#11'ParentColor'#8#8'TabOrder'#2
+#0#23'Gutter.CodeFoldingWidth'#2#14#11'Highlighter'#7#10'SynPasSyn1'#10'Keys'
+'trokes'#14#1#7'Command'#2#3#8'ShortCut'#2'&'#0#1#7'Command'#2'g'#8'ShortCut'
+#3'& '#0#1#7'Command'#3#211#0#8'ShortCut'#3'&@'#0#1#7'Command'#2#4#8'ShortCu'
+'t'#2'('#0#1#7'Command'#2'h'#8'ShortCut'#3'( '#0#1#7'Command'#3#212#0#8'Shor'
+'tCut'#3'(@'#0#1#7'Command'#2#1#8'ShortCut'#2'%'#0#1#7'Command'#2'e'#8'Short'
+'Cut'#3'% '#0#1#7'Command'#2#5#8'ShortCut'#3'%@'#0#1#7'Command'#2'i'#8'Short'
+'Cut'#3'%`'#0#1#7'Command'#2#2#8'ShortCut'#2''''#0#1#7'Command'#2'f'#8'Short'
+'Cut'#3''' '#0#1#7'Command'#2#6#8'ShortCut'#3'''@'#0#1#7'Command'#2'j'#8'Sho'
+'rtCut'#3'''`'#0#1#7'Command'#2#10#8'ShortCut'#2'"'#0#1#7'Command'#2'n'#8'Sh'
+'ortCut'#3'" '#0#1#7'Command'#2#14#8'ShortCut'#3'"@'#0#1#7'Command'#2'r'#8'S'
+'hortCut'#3'"`'#0#1#7'Command'#2#9#8'ShortCut'#2'!'#0#1#7'Command'#2'm'#8'Sh'
+'ortCut'#3'! '#0#1#7'Command'#2#13#8'ShortCut'#3'!@'#0#1#7'Command'#2'q'#8'S'
+'hortCut'#3'!`'#0#1#7'Command'#2#7#8'ShortCut'#2'$'#0#1#7'Command'#2'k'#8'Sh'
+'ortCut'#3'$ '#0#1#7'Command'#2#15#8'ShortCut'#3'$@'#0#1#7'Command'#2's'#8'S'
+'hortCut'#3'$`'#0#1#7'Command'#2#8#8'ShortCut'#2'#'#0#1#7'Command'#2'l'#8'Sh'
+'ortCut'#3'# '#0#1#7'Command'#2#16#8'ShortCut'#3'#@'#0#1#7'Command'#2't'#8'S'
+'hortCut'#3'#`'#0#1#7'Command'#3#223#0#8'ShortCut'#2'-'#0#1#7'Command'#3#201
+#0#8'ShortCut'#3'-@'#0#1#7'Command'#3'\'#2#8'ShortCut'#3'- '#0#1#7'Command'#3
+#246#1#8'ShortCut'#2'.'#0#1#7'Command'#3'['#2#8'ShortCut'#3'. '#0#1#7'Comman'
+'d'#3#245#1#8'ShortCut'#2#8#0#1#7'Command'#3#245#1#8'ShortCut'#3#8' '#0#1#7
+'Command'#3#248#1#8'ShortCut'#3#8'@'#0#1#7'Command'#3'Y'#2#8'ShortCut'#4#8
+#128#0#0#0#1#7'Command'#3'Z'#2#8'ShortCut'#4#8#160#0#0#0#1#7'Command'#3#253#1
+#8'ShortCut'#2#13#0#1#7'Command'#3#199#0#8'ShortCut'#3'A@'#0#1#7'Command'#3
+#201#0#8'ShortCut'#3'C@'#0#1#7'Command'#3'b'#2#8'ShortCut'#3'I`'#0#1#7'Comma'
+'nd'#3#253#1#8'ShortCut'#3'M@'#0#1#7'Command'#3#254#1#8'ShortCut'#3'N@'#0#1#7
+'Command'#3#247#1#8'ShortCut'#3'T@'#0#1#7'Command'#3'c'#2#8'ShortCut'#3'U`'#0
+#1#7'Command'#3'\'#2#8'ShortCut'#3'V@'#0#1#7'Command'#3'['#2#8'ShortCut'#3'X'
+'@'#0#1#7'Command'#3#251#1#8'ShortCut'#3'Y@'#0#1#7'Command'#3#250#1#8'ShortC'
+'ut'#3'Y`'#0#1#7'Command'#3'Y'#2#8'ShortCut'#3'Z@'#0#1#7'Command'#3'Z'#2#8'S'
+'hortCut'#3'Z`'#0#1#7'Command'#3'-'#1#8'ShortCut'#3'0@'#0#1#7'Command'#3'.'#1
+#8'ShortCut'#3'1@'#0#1#7'Command'#3'/'#1#8'ShortCut'#3'2@'#0#1#7'Command'#3
+'0'#1#8'ShortCut'#3'3@'#0#1#7'Command'#3'1'#1#8'ShortCut'#3'4@'#0#1#7'Comman'
+'d'#3'2'#1#8'ShortCut'#3'5@'#0#1#7'Command'#3'3'#1#8'ShortCut'#3'6@'#0#1#7'C'
+'ommand'#3'4'#1#8'ShortCut'#3'7@'#0#1#7'Command'#3'5'#1#8'ShortCut'#3'8@'#0#1
+#7'Command'#3'6'#1#8'ShortCut'#3'9@'#0#1#7'Command'#3'_'#1#8'ShortCut'#3'0`'
+#0#1#7'Command'#3'`'#1#8'ShortCut'#3'1`'#0#1#7'Command'#3'a'#1#8'ShortCut'#3
+'2`'#0#1#7'Command'#3'b'#1#8'ShortCut'#3'3`'#0#1#7'Command'#3'c'#1#8'ShortCu'
+'t'#3'4`'#0#1#7'Command'#3'd'#1#8'ShortCut'#3'5`'#0#1#7'Command'#3'e'#1#8'Sh'
+'ortCut'#3'6`'#0#1#7'Command'#3'f'#1#8'ShortCut'#3'7`'#0#1#7'Command'#3'g'#1
+#8'ShortCut'#3'8`'#0#1#7'Command'#3'h'#1#8'ShortCut'#3'9`'#0#1#7'Command'#3
+#231#0#8'ShortCut'#3'N`'#0#1#7'Command'#3#232#0#8'ShortCut'#3'C`'#0#1#7'Comm'
+'and'#3#233#0#8'ShortCut'#3'L`'#0#1#7'Command'#3'd'#2#8'ShortCut'#2#9#0#1#7
+'Command'#3'e'#2#8'ShortCut'#3#9' '#0#1#7'Command'#3#250#0#8'ShortCut'#3'B`'
+#0#0#13'Lines.Strings'#1#6#14'MethodsSynEdit'#0#0#0#0#9'TGroupBox'#16'Sectio'
+'nsGroupBox'#6'Height'#3#133#0#5'Width'#3#131#1#5'Align'#7#5'alTop'#8'AutoSi'
+'ze'#9#7'Caption'#6#16'SectionsGroupBox'#28'ChildSizing.LeftRightSpacing'#2#6
+#28'ChildSizing.TopBottomSpacing'#2#6#29'ChildSizing.HorizontalSpacing'#2#15
+#18'ChildSizing.Layout'#7#29'cclTopToBottomThenLeftToRight'#27'ChildSizing.C'
+'ontrolsPerLine'#2#4#12'ClientHeight'#2'r'#11'ClientWidth'#3''#1#8'TabOrder'
+#2#2#0#9'TCheckBox'#15'PrivateCheckBox'#4'Left'#2#6#6'Height'#2#29#3'Top'#2#6
+#5'Width'#3#149#0#7'Caption'#6#15'PrivateCheckBox'#8'OnChange'#7#21'PrivateC'
,'heckBoxChange'#8'TabOrder'#2#0#0#0#9'TCheckBox'#17'ProtectedCheckBox'#4'Lef'
+'t'#2#6#6'Height'#2#29#3'Top'#2'#'#5'Width'#3#149#0#7'Caption'#6#17'Protecte'
+'dCheckBox'#8'OnChange'#7#21'PrivateCheckBoxChange'#8'TabOrder'#2#1#0#0#9'TC'
+'heckBox'#14'PublicCheckBox'#4'Left'#2#6#6'Height'#2#22#3'Top'#2'@'#5'Width'
+#3#149#0#7'Caption'#6#14'PublicCheckBox'#8'OnChange'#7#21'PrivateCheckBoxCha'
+'nge'#8'TabOrder'#2#2#0#0#9'TCheckBox'#17'PublishedCheckBox'#4'Left'#2#6#6'H'
+'eight'#2#22#3'Top'#2'V'#5'Width'#3#149#0#7'Caption'#6#17'PublishedCheckBox'
+#8'OnChange'#7#21'PrivateCheckBoxChange'#8'TabOrder'#2#3#0#0#7'TButton'#9'Al'
+'lButton'#4'Left'#3#170#0#6'Height'#2#29#3'Top'#2#6#5'Width'#2't'#7'Caption'
+#6#9'AllButton'#7'OnClick'#7#14'AllButtonClick'#8'TabOrder'#2#4#0#0#7'TButto'
+'n'#15'PublishedButton'#4'Left'#3#170#0#6'Height'#2#29#3'Top'#2'#'#5'Width'#2
+'t'#7'Caption'#6#15'PublishedButton'#7'OnClick'#7#20'PublishedButtonClick'#8
+'TabOrder'#2#5#0#0#0#10'TSynPasSyn'#10'SynPasSyn1'#7'Enabled'#8#4'left'#2'g'
+#3'top'#3#199#0#0#0#0
]);

272
ide/emptymethodsdlg.pas Normal file
View File

@ -0,0 +1,272 @@
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************
Author: Mattias Gaertner
Abstract:
A dialog showing the empty methods of the current class
(at cursor in source editor).
With the ability to remove them automatically.
}
unit EmptyMethodsDlg;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls, ButtonPanel, SynEdit, SynHighlighterPas,
CodeToolsStructs, CodeAtom, CodeCache, CodeToolManager, PascalParserTool,
CodeTree,
SrcEditorIntf, LazIDEIntf,
LazarusIDEStrConsts;
type
{ TEmptyMethodsDialog }
TEmptyMethodsDialog = class(TForm)
AllButton: TButton;
PublishedButton: TButton;
ButtonPanel1: TButtonPanel;
PrivateCheckBox: TCheckBox;
ProtectedCheckBox: TCheckBox;
PublicCheckBox: TCheckBox;
PublishedCheckBox: TCheckBox;
SectionsGroupBox: TGroupBox;
MethodsGroupBox: TGroupBox;
MethodsSynEdit: TSynEdit;
SynPasSyn1: TSynPasSyn;
procedure AllButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure OKButtonClick(Sender: TObject);
procedure PrivateCheckBoxChange(Sender: TObject);
procedure PublishedButtonClick(Sender: TObject);
private
FCaret: TPoint;
FCode: TCodeBuffer;
function GetSections: TPascalClassSections;
procedure SetCaret(const AValue: TPoint);
procedure SetCode(const AValue: TCodeBuffer);
procedure SetSections(const AValue: TPascalClassSections);
procedure UpdateList;
public
property Sections: TPascalClassSections read GetSections write SetSections;
property Code: TCodeBuffer read FCode write SetCode;
property Caret: TPoint read FCaret write SetCaret;
end;
function ShowEmptyMethodsDialog: TModalResult;
implementation
function ShowEmptyMethodsDialog: TModalResult;
var
EmptyMethodsDialog: TEmptyMethodsDialog;
ErrMsg: String;
SrcEdit: TSourceEditorInterface;
Code: TCodeBuffer;
Caret: TPoint;
ListOfPCodeXYPosition: TFPList;
AllEmpty: boolean;
begin
ListOfPCodeXYPosition:=TFPList.Create;
try
// init codetools
ErrMsg:=lisSAMIDEIsBusy;
if not LazarusIDE.BeginCodeTools then exit;
// get cursor position
ErrMsg:=lisSAMCursorIsNotInAClassDeclaration;
SrcEdit:=SourceEditorWindow.ActiveEditor;
if SrcEdit=nil then exit;
Code:=TCodeBuffer(SrcEdit.CodeToolsBuffer);
if Code=nil then exit;
Caret:=SrcEdit.CursorTextXY;
ErrMsg:='';
// check cursor is in a class
if not CodeToolBoss.FindEmptyMethods(Code,Caret.X,Caret.Y,
AllPascalClassSections,ListOfPCodeXYPosition,AllEmpty)
then begin
DebugLn(['ShowEmptyMethodsDialog CodeToolBoss.FindEmptyMethods failed']);
if CodeToolBoss.ErrorMessage<>'' then begin
ErrMsg:='';
LazarusIDE.DoJumpToCodeToolBossError;
end;
exit;
end;
CodeToolBoss.FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
EmptyMethodsDialog:=TEmptyMethodsDialog.Create(nil);
try
EmptyMethodsDialog.Code:=Code;
EmptyMethodsDialog.Caret:=Caret;
EmptyMethodsDialog.UpdateList;
Result:=EmptyMethodsDialog.ShowModal;
finally
EmptyMethodsDialog.Free;
end;
finally
CodeToolBoss.FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
if ErrMsg<>'' then begin
MessageDlg(lisCCOErrorCaption,
'Unable to show empty methods of the current class, because'+#13
+ErrMsg,mtError,[mbCancel],0);
end;
end;
end;
{ TEmptyMethodsDialog }
procedure TEmptyMethodsDialog.FormCreate(Sender: TObject);
begin
Caption:='Emtpy Methods';
SectionsGroupBox.Caption:='Search in these class sections:';
PrivateCheckBox.Caption:='Private';
ProtectedCheckBox.Caption:='Protected';
PublicCheckBox.Caption:='Public';
PublishedButton.Caption:='Published';
AllButton.Caption:='All';
PublishedButton.Caption:='Only published';
MethodsGroupBox.Caption:='Found empty methods:';
Sections:=AllPascalClassSections;
ButtonPanel1.OKButton.OnClick:=@OKButtonClick;
end;
procedure TEmptyMethodsDialog.OKButtonClick(Sender: TObject);
var
AllEmpty: boolean;
begin
DebugLn(['TEmptyMethodsDialog.OKButtonClick ']);
if (not CodeToolBoss.RemoveEmptyMethods(Code,Caret.X,Caret.Y,Sections,AllEmpty))
then begin
DebugLn(['TEmptyMethodsDialog.OKButtonClick failed']);
exit;
end;
ModalResult:=mrOk;
end;
procedure TEmptyMethodsDialog.PrivateCheckBoxChange(Sender: TObject);
begin
UpdateList;
end;
procedure TEmptyMethodsDialog.PublishedButtonClick(Sender: TObject);
begin
Sections:=[pcsPublished];
end;
procedure TEmptyMethodsDialog.SetSections(const AValue: TPascalClassSections);
begin
PrivateCheckBox.Checked:=pcsPrivate in AValue;
ProtectedCheckBox.Checked:=pcsProtected in AValue;
PublicCheckBox.Checked:=pcsPublic in AValue;
PublishedCheckBox.Checked:=pcsPublished in AValue;
end;
procedure TEmptyMethodsDialog.SetCaret(const AValue: TPoint);
begin
FCaret:=AValue;
end;
function TEmptyMethodsDialog.GetSections: TPascalClassSections;
begin
Result:=[];
if PrivateCheckBox.Checked then Include(Result,pcsPrivate);
if ProtectedCheckBox.Checked then Include(Result,pcsProtected);
if PublicCheckBox.Checked then Include(Result,pcsPublic);
if PublishedCheckBox.Checked then Include(Result,pcsPublished);
end;
procedure TEmptyMethodsDialog.SetCode(const AValue: TCodeBuffer);
begin
if FCode=AValue then exit;
FCode:=AValue;
end;
procedure TEmptyMethodsDialog.UpdateList;
var
CurSections: TPascalClassSections;
ListOfPCodeXYPosition: TFPList;
i: Integer;
CodePos: TCodeXYPosition;
Tool: TCodeTool;
CleanPos: integer;
Node: TCodeTreeNode;
NodeText: String;
AllEmpty: boolean;
NewTxt: String;
begin
if (Code=nil) or (Caret.X<1) or (Caret.Y<1) then begin
MethodsSynEdit.Text:='';
exit;
end;
CurSections:=Sections;
ListOfPCodeXYPosition:=TFPList.Create;
try
if (not CodeToolBoss.FindEmptyMethods(Code,Caret.X,Caret.Y,
CurSections,ListOfPCodeXYPosition,AllEmpty))
or (not CodeToolBoss.Explore(Code,Tool,false))
then begin
MethodsSynEdit.Text:='CodeToolBoss.FindEmptyMethods failed'#10
+CodeToolBoss.ErrorMessage;
exit;
end;
NewTxt:='';
for i:=0 to ListOfPCodeXYPosition.Count-1 do begin
CodePos:=PCodeXYPosition(ListOfPCodeXYPosition[i])^;
//DebugLn(['TEmptyMethodsDialog.UpdateList ',i,' ',DbgsCXY(CodePos)]);
if Tool.CaretToCleanPos(CodePos,CleanPos)<>0 then begin
DebugLn(['TEmptyMethodsDialog.UpdateList Tool.CaretToCleanPos failed']);
continue;
end;
Node:=Tool.FindDeepestNodeAtPos(CleanPos,false);
if Node=nil then begin
DebugLn(['TEmptyMethodsDialog.UpdateList Tool.FindDeepestNodeAtPos failed']);
continue;
end;
NodeText:=Tool.ExtractProcHead(Node,[phpWithStart,phpWithParameterNames,
phpWithVarModifiers,phpWithDefaultValues,phpWithResultType,
phpWithCallingSpecs,phpWithProcModifiers]);
NewTxt:=NewTxt+NodeText+#10;
end;
MethodsSynEdit.Text:=NewTxt;
finally
CodeToolBoss.FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
end;
end;
procedure TEmptyMethodsDialog.AllButtonClick(Sender: TObject);
begin
Sections:=AllPascalClassSections;
end;
initialization
{$I emptymethodsdlg.lrs}
end.

View File

@ -424,6 +424,7 @@ begin
ecFindBlockStart: SetResult2(VK_Q,[ssCtrl],VK_B,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecGotoIncludeDirective: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecShowAbstractMethods: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecRemoveEmptyMethods: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// source notebook
ecNextEditor: SetResult(VK_TAB, [ssCtrl], VK_UNKNOWN, []);
@ -748,6 +749,7 @@ begin
ecFindBlockStart: SetResult(VK_Q,[ssCtrl],VK_B,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecGotoIncludeDirective: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecShowAbstractMethods: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecRemoveEmptyMethods: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
// source notebook
ecNextEditor: SetResult(VK_F6,[],VK_UNKNOWN,[],VK_TAB, [ssCtrl], VK_UNKNOWN, []);
@ -1458,6 +1460,7 @@ begin
ecFindBlockOtherEnd : Result:= srkmecFindBlockOtherEnd;
ecFindBlockStart : Result:= srkmecFindBlockStart;
ecShowAbstractMethods : Result:= srkmecShowAbstractMethods;
ecRemoveEmptyMethods : Result:= srkmecRemoveEmptyMethods;
// project (menu string resource)
ecNewProject : Result:= lisMenuNewProject;
@ -2372,6 +2375,8 @@ begin
ecGotoIncludeDirective);
AddDefault(C, 'Show abstract methods', srkmecShowAbstractMethods,
ecShowAbstractMethods);
AddDefault(C, 'Remove empty methods', srkmecRemoveEmptyMethods,
ecRemoveEmptyMethods);
// source notebook - without menu items in the IDE bar
C:=Categories[AddCategory('SourceNotebook',srkmCatSrcNoteBook,

View File

@ -1594,6 +1594,7 @@ resourcestring
+'be shown incorrect.%sYou can select another font in the editor options.';
lisUEDoNotSho = 'Do not show this message again.';
uemInsertTodo = 'Insert Todo';
lisCodeHelpShowEmptyMethods = 'Show empty methods';
uemHighlighter = 'Highlighter';
// Form designer
@ -1847,6 +1848,7 @@ resourcestring
srkmecFindBlockOtherEnd = 'Find block other end';
srkmecFindBlockStart = 'Find block start';
srkmecShowAbstractMethods = 'Show abstract methods';
srkmecRemoveEmptyMethods = 'Remove empty methods';
// run menu
srkmecBuild = 'build program/project';

View File

@ -127,7 +127,7 @@ uses
ProcessList, InitialSetupDlgs, NewDialog, MakeResStrDlg, ToDoList,
DialogProcs, FindReplaceDialog, FindInFilesDlg, CodeExplorer, BuildFileDlg,
ProcedureList, ExtractProcDlg, FindRenameIdentifier, AbstractsMethodsDlg,
CleanDirDlg, CodeContextForm, AboutFrm, BuildManager,
EmptyMethodsDlg, CleanDirDlg, CodeContextForm, AboutFrm, BuildManager,
CompatibilityRestrictions, RestrictionBrowser,
// main ide
MainBar, MainIntf, MainBase;
@ -845,6 +845,7 @@ type
procedure DoFindDeclarationAtCaret(const LogCaretXY: TPoint);
function DoFindRenameIdentifier(Rename: boolean): TModalResult;
function DoShowAbstractMethods: TModalResult;
function DoRemoveEmptyMethods: TModalResult;
function DoInitIdentCompletion(JumpToError: boolean): boolean;
function DoShowCodeContext(JumpToError: boolean): boolean;
procedure DoCompleteCodeAtCursor;
@ -2652,6 +2653,9 @@ begin
ecShowAbstractMethods:
DoShowAbstractMethods;
ecRemoveEmptyMethods:
DoRemoveEmptyMethods;
ecFindBlockOtherEnd:
DoGoToPascalBlockOtherEnd;
@ -12066,6 +12070,11 @@ begin
Result:=ShowAbstractMethodsDialog;
end;
function TMainIDE.DoRemoveEmptyMethods: TModalResult;
begin
Result:=ShowEmptyMethodsDialog;
end;
{-------------------------------------------------------------------------------
function TMainIDE.DoInitIdentCompletion(JumpToError: boolean): boolean;
-------------------------------------------------------------------------------}

View File

@ -420,6 +420,7 @@ type
procedure FindIdentifierReferencesMenuItemClick(Sender: TObject);
procedure RenameIdentifierMenuItemClick(Sender: TObject);
procedure ShowAbstractMethodsMenuItemClick(Sender: TObject);
procedure ShowEmptyMethodsMenuItemClick(Sender: TObject);
procedure RunToClicked(Sender: TObject);
procedure ViewCallStackClick(Sender: TObject);
procedure AddWatchAtCursor(Sender: TObject);
@ -527,7 +528,7 @@ type
procedure UpdateActiveEditColors;
procedure SetIncrementalSearchStr(const AValue: string);
procedure IncrementalSearch(ANext: Boolean; ABackward: Boolean);
procedure IncrementalSearch(ANext, ABackward: Boolean);
// macros
function MacroFuncCol(const s:string; const Data: PtrInt;
@ -849,6 +850,7 @@ var
SrcEditMenuExtractProc: TIDEMenuCommand;
SrcEditMenuInvertAssignment: TIDEMenuCommand;
SrcEditMenuShowAbstractMethods: TIDEMenuCommand;
SrcEditMenuShowEmptyMethods: TIDEMenuCommand;
SrcEditMenuInsertTodo: TIDEMenuCommand;
SrcEditMenuMoveEditorLeft: TIDEMenuCommand;
SrcEditMenuMoveEditorRight: TIDEMenuCommand;
@ -1005,6 +1007,8 @@ begin
'InvertAssignment',uemInvertAssignment);
SrcEditMenuShowAbstractMethods:=RegisterIDEMenuCommand(AParent,
'ShowAbstractMethods',srkmecShowAbstractMethods);
SrcEditMenuShowEmptyMethods:=RegisterIDEMenuCommand(AParent,
'ShowEmptyMethods', lisCodeHelpShowEmptyMethods);
SrcEditMenuInsertTodo:=RegisterIDEMenuCommand(SourceEditorMenuRoot,
'InsertTodo',uemInsertTodo, nil, nil, nil, 'item_todo');
@ -3988,6 +3992,7 @@ begin
IsValidIdent(ASrcEdit.GetWordAtCurrentCaret)
and (not ASrcEdit.ReadOnly);
SrcEditMenuShowAbstractMethods.Enabled:=not ASrcEdit.ReadOnly;
SrcEditMenuShowEmptyMethods.Enabled:=not ASrcEdit.ReadOnly;
end else begin
// user clicked on gutter
SourceEditorMarks.GetMarksForLine(EditorComp,EditorComp.CaretY,
@ -4151,6 +4156,7 @@ begin
@FindIdentifierReferencesMenuItemClick;
SrcEditMenuRenameIdentifier.OnClick:=@RenameIdentifierMenuItemClick;
SrcEditMenuShowAbstractMethods.OnClick:=@ShowAbstractMethodsMenuItemClick;
SrcEditMenuShowEmptyMethods.OnClick:=@ShowEmptyMethodsMenuItemClick;
SrcEditMenuReadOnly.OnClick:=@ReadOnlyClicked;
SrcEditMenuShowLineNumbers.OnClick:=@ToggleLineNumbersClicked;
@ -5371,6 +5377,11 @@ begin
MainIDEInterface.DoCommand(ecShowAbstractMethods);
end;
procedure TSourceNotebook.ShowEmptyMethodsMenuItemClick(Sender: TObject);
begin
MainIDEInterface.DoCommand(ecRemoveEmptyMethods);
end;
procedure TSourceNotebook.RunToClicked(Sender: TObject);
var
ASrcEdit: TSourceEditor;

View File

@ -137,6 +137,7 @@ const
ecInvertAssignment = ecFirstLazarus + 116;
ecShowCodeContext = ecFirstLazarus + 117;
ecShowAbstractMethods = ecFirstLazarus + 118;
ecRemoveEmptyMethods = ecFirstLazarus + 119;
// file menu
ecNew = ecFirstLazarus + 201;