/usr/lib/lazarus/0.9.30.4/ide/codeexplopts.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | {
/***************************************************************************
CodeExplOpts.pas
-------------------
***************************************************************************/
***************************************************************************
* *
* 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. *
* *
***************************************************************************
Abstract:
Dialog for the options of the code explorer.
}
unit CodeExplOpts;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
Buttons, ExtCtrls, FileUtil, StdCtrls, ButtonPanel, AvgLvlTree,
CodeToolManager, Laz_XMLCfg, BasicCodeTools,
IDEContextHelpEdit,
LazConf, IDEProcs, IDEOptionsIntf, LazarusIDEStrConsts;
type
{ TCodeExplorerOptions }
TCodeExplorerRefresh = (
cerManual, // only via refresh button
cerSwitchEditorPage,// everytime the source editor switches to another page
cerOnIdle // on idle
);
TCodeExplorerMode = (
cemCategory, // Category - Delphi like
cemSource // Follows Source Code
);
TCodeExplorerCategory = (
cecNone,
cecUses,
cecTypes,
cecVariables,
cecConstants,
cecProperties,
cecProcedures,
cecCodeObserver
);
TCodeExplorerCategories = set of TCodeExplorerCategory;
TCEObserverCategory = (
cefcLongProcs, // procedures with many lines of code
cefcLongParamLists, // procedures with many parameters
cefcEmptyProcs, // procs without code (can contain comments)
cefcNestedProcs, // procs with a lot of nested sub procs
cefcUnnamedConsts, // numbers, strings in statements
cefcEmptyBlocks, // empty begin..end block (not even a comment)
cefcWrongIndentation, // possible missing lines or begin blocks
cefcPublishedPropWithoutDefault, // published properties without default specifier
cefcUnsortedClassVisibility, // public,private,protected,published keywords are not sorted
cefcEmptyClassSections, // empty public,private,protected,published section
cefcUnsortedClassMembers, // member of a public,private,protected,published section is not sorted alphabetically
cefcToDos // todo comment
);
TCEObserverCategories = set of TCEObserverCategory;
TCEObserverCategoryGroup = (ocgComplexity, ocgEmpty, ocgStyle, ocgOther);
const
FirstCodeExplorerCategory = cecUses;
DefaultCodeExplorerCategories = [cecUses,
cecTypes,cecVariables,cecConstants,cecProcedures];
cefcAll = [low(TCEObserverCategory)..high(TCEObserverCategory)];
DefaultCodeObserverCategories = [
cefcLongProcs,
cefcEmptyProcs,
cefcUnnamedConsts,
cefcEmptyBlocks,
cefcWrongIndentation,
cefcPublishedPropWithoutDefault,
cefcToDos
];
DefaultCOLongProcLineCount = 50;
DefaultCOLongParamListCount = 6;
DefaultCONestedProcCount = 3;
DefaultCOureCharConst = false;
DefaultCOIgnoreConstants: array[1..2] of ansistring // Note: keep this asciiz
= (
'0',
'1'
);
DefaultCOIgnoreConstInFuncs: array[1..15] of ansistring // Note: keep this asciiz
= (
'Assert',
'Debug',
'DebugLn',
'DbgOut',
'write',
'writeln',
'Format',
'FormatBuf',
'StrFmt',
'StrLFmt',
'FmtStr',
'FloatToStrF',
'FloatToStr',
'CurrToStrF',
'FormatDateTime'
);
type
TCodeExplorerOptions = class(TAbstractIDEEnvironmentOptions)
private
FCategories: TCodeExplorerCategories;
FChangeStep: integer;
FObserveCharConst: boolean;
FCOIgnoreConstInFuncs: TStringToStringTree;
FLongParamListCount: integer;
FLongProcLineCount: integer;
FNestedProcCount: integer;
FObserverCategories: TCEObserverCategories;
FFollowCursor: boolean;
FMode : TCodeExplorerMode;
FObserverIgnoreConstants: TAvgLvlTree;// tree of AnsiString
FOptionsFilename: string;
FRefresh: TCodeExplorerRefresh;
procedure SetCategories(const AValue: TCodeExplorerCategories);
procedure SetFollowCursor(const AValue: boolean);
procedure SetLongParamListCount(const AValue: integer);
procedure SetLongProcLineCount(const AValue: integer);
procedure SetMode(const AValue: TCodeExplorerMode);
procedure SetNestedProcCount(const AValue: integer);
procedure SetObserveCharConst(const AValue: boolean);
procedure SetObserverCategories(const AValue: TCEObserverCategories);
procedure SetRefresh(const AValue: TCodeExplorerRefresh);
public
class function GetGroupCaption:string; override;
class function GetInstance: TAbstractIDEOptions; override;
procedure DoAfterWrite(Restore: boolean); override;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Assign(Source: TPersistent); override;
procedure Load;
procedure Save;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string);
procedure IncreaseChangeStep;
public
// observer: ignore constants
function CreateListOfCOIgnoreConstants: TStrings;
procedure SetListOf_COIgnoreConstants(List: TStrings; Add: boolean);
function COIgnoreConstant(p: PChar): boolean;// test if atom is in COIgnoreConstants
function COIgnoreConstants_AreDefault(Exactly: boolean): boolean; // true if COIgnoreConstants contain/are default values
function COIgnoreConstant_IsDefault(const Atom: string): boolean; // true if Atom is in default values
procedure Add_COIgnoreConstant(const Atom: string);
procedure Clear_COIgnoreConstants;
procedure LoadDefaults_COIgnoreConstants;
public
// observer: ignore constants in functions
function CreateListOfCOIgnoreConstInFuncs: TStrings;
procedure SetListOf_COIgnoreConstInFuncs(List: TStrings; Add: boolean);
function COIgnoreConstInFunc(const Func: string): boolean;// test if function is in COIgnoreConstInFuncs
function COIgnoreConstInFuncs_AreDefault(Exactly: boolean): boolean; // true if COIgnoreConstInFuncs contain/are default values
function COIgnoreConstInFuncs_IsDefault(const Func: string): boolean; // true if Atom is in default values
procedure Add_COIgnoreConstInFuncs(const Func: string);
procedure Clear_COIgnoreConstInFuncs;
procedure LoadDefaults_COIgnoreConstInFuncs;
public
property Refresh: TCodeExplorerRefresh read FRefresh write SetRefresh default cerSwitchEditorPage;
property Mode: TCodeExplorerMode read FMode write SetMode default cemCategory;
property OptionsFilename: string read FOptionsFilename write FOptionsFilename;
property FollowCursor: boolean read FFollowCursor write SetFollowCursor default true;
property Categories: TCodeExplorerCategories read FCategories write SetCategories default DefaultCodeExplorerCategories;
property ChangeStep: integer read FChangeStep write FChangeStep;
public
// Observer
property ObserveCharConst: boolean read FObserveCharConst write SetObserveCharConst default DefaultCOureCharConst;
property ObserverCategories: TCEObserverCategories read FObserverCategories write SetObserverCategories default DefaultCodeObserverCategories;
property ObserverIgnoreConstants: TAvgLvlTree read FObserverIgnoreConstants;
property COIgnoreConstInFuncs: TStringToStringTree read FCOIgnoreConstInFuncs;
property LongParamListCount: integer read FLongParamListCount write SetLongParamListCount default DefaultCOLongParamListCount;
property LongProcLineCount: integer read FLongProcLineCount write SetLongProcLineCount default DefaultCOLongProcLineCount;
property NestedProcCount: integer read FNestedProcCount write SetNestedProcCount default DefaultCONestedProcCount;
end;
const
CodeExplorerVersion = 1;
cerDefault = cerSwitchEditorPage;
CodeExplorerRefreshNames: array[TCodeExplorerRefresh] of string = (
'Manual',
'SwitchEditorPage',
'OnIdle'
);
CodeExplorerModeNames: array[TCodeExplorerMode] of string = (
'Category',
'Source'
);
CodeExplorerCategoryNames: array[TCodeExplorerCategory] of string = (
'?',
'Uses',
'Types',
'Variables',
'Constants',
'Properties',
'Procedures',
'CodeObserver'
);
CodeObserverCategoryNames: array[TCEObserverCategory] of string = (
'LongProcs',
'LongParamLists',
'EmptyProcs',
'NestedProcs',
'UnnamedConsts',
'EmptyBlocks',
'WrongIndentation',
'PublishedPropWithoutDefault',
'UnsortedClassVisibility',
'EmptyClassSections',
'UnsortedClassMembers',
'ToDos'
);
var
CodeExplorerOptions: TCodeExplorerOptions = nil; // set by the IDE
function CodeExplorerRefreshNameToEnum(const s: string): TCodeExplorerRefresh;
function CodeExplorerModeNameToEnum(const s: string): TCodeExplorerMode;
function CodeExplorerCategoryNameToEnum(const s: string): TCodeExplorerCategory;
function CodeExplorerLocalizedString(const c: TCodeExplorerCategory): string;
function CodeObserverCatNameToEnum(const s: string): TCEObserverCategory;
function CodeExplorerLocalizedString(const c: TCEObserverCategory): string;
implementation
function CodeExplorerRefreshNameToEnum(const s: string): TCodeExplorerRefresh;
begin
for Result:=Low(TCodeExplorerRefresh) to High(TCodeExplorerRefresh) do
if SysUtils.CompareText(CodeExplorerRefreshNames[Result],s)=0 then exit;
Result:=cerDefault;
end;
function CodeExplorerModeNameToEnum(const s: string): TCodeExplorerMode;
begin
for Result:=Low(TCodeExplorerMode) to High(TCodeExplorerMode) do
if SysUtils.CompareText(CodeExplorerModeNames[Result],s)=0 then exit;
Result:=cemCategory;
end;
function CodeExplorerCategoryNameToEnum(const s: string): TCodeExplorerCategory;
begin
for Result:=FirstCodeExplorerCategory to High(TCodeExplorerCategory) do
if SysUtils.CompareText(CodeExplorerCategoryNames[Result],s)=0 then exit;
Result:=cecTypes;
end;
function CodeExplorerLocalizedString(const c: TCodeExplorerCategory): string;
begin
case c of
cecUses: Result:=lisCEUses;
cecTypes: Result:=lisCETypes;
cecVariables: Result:=lisCEVariables;
cecConstants: Result:=lisCEConstants;
cecProcedures: Result:=lisCEProcedures;
cecProperties: Result:=lisCEProperties;
cecCodeObserver: Result:=lisCodeObserver;
else Result:='?';
end;
end;
function CodeObserverCatNameToEnum(const s: string): TCEObserverCategory;
begin
for Result:=low(TCEObserverCategory) to High(TCEObserverCategory) do
if SysUtils.CompareText(CodeObserverCategoryNames[Result],s)=0 then exit;
Result:=cefcLongProcs;
end;
function CodeExplorerLocalizedString(const c: TCEObserverCategory): string;
begin
case c of
cefcLongProcs: Result:=lisCELongProcedures;
cefcLongParamLists: Result:=lisCEManyParameters;
cefcEmptyProcs: Result:=lisCEEmptyProcedures;
cefcNestedProcs: Result:=lisCEManyNestedProcedures;
cefcUnnamedConsts: Result:=lisCEUnnamedConstants;
cefcEmptyBlocks: Result:=lisCEEmptyBlocks;
cefcWrongIndentation: Result:=lisCEWrongIndentation;
cefcPublishedPropWithoutDefault: Result:=lisCEPublishedPropertyWithoutDefault;
cefcUnsortedClassVisibility: Result:=lisCEUnsortedVisibility;
cefcEmptyClassSections: Result:=lisCEEmptyClassSections;
cefcUnsortedClassMembers: Result:=lisCEUnsortedMembers;
cefcToDos: Result:=lisCEToDos;
else Result:='?';
end;
end;
{ TCodeExplorerOptions }
procedure TCodeExplorerOptions.SetRefresh(const AValue: TCodeExplorerRefresh);
begin
if FRefresh=AValue then exit;
FRefresh:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetMode(const AValue: TCodeExplorerMode);
begin
if FMode=AValue then exit;
FMode:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetNestedProcCount(const AValue: integer);
begin
if FNestedProcCount=AValue then exit;
FNestedProcCount:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetObserveCharConst(const AValue: boolean);
begin
if FObserveCharConst=AValue then exit;
FObserveCharConst:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetObserverCategories(
const AValue: TCEObserverCategories);
begin
if FObserverCategories=AValue then exit;
FObserverCategories:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetFollowCursor(const AValue: boolean);
begin
if FFollowCursor=AValue then exit;
FFollowCursor:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetLongParamListCount(const AValue: integer);
begin
if FLongParamListCount=AValue then exit;
FLongParamListCount:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetLongProcLineCount(const AValue: integer);
begin
if FLongProcLineCount=AValue then exit;
FLongProcLineCount:=AValue;
IncreaseChangeStep;
end;
procedure TCodeExplorerOptions.SetCategories(
const AValue: TCodeExplorerCategories);
begin
if FCategories=AValue then exit;
FCategories:=AValue;
IncreaseChangeStep;
end;
constructor TCodeExplorerOptions.Create;
begin
FOptionsFilename:=
AppendPathDelim(GetPrimaryConfigPath)+'codeexploreroptions.xml';
FObserverIgnoreConstants:=TAvgLvlTree.Create(TListSortCompare(@CompareAtom));
FCOIgnoreConstInFuncs:=TStringToStringTree.Create(false);
Clear;
LoadDefaults_COIgnoreConstants;
LoadDefaults_COIgnoreConstInFuncs;
end;
destructor TCodeExplorerOptions.Destroy;
begin
Clear_COIgnoreConstants;
FreeAndNil(FObserverIgnoreConstants);
FreeAndNil(FCOIgnoreConstInFuncs);
inherited Destroy;
end;
class function TCodeExplorerOptions.GetGroupCaption: string;
begin
Result := dlgGroupCodeExplorer;
end;
class function TCodeExplorerOptions.GetInstance: TAbstractIDEOptions;
begin
Result := CodeExplorerOptions;
end;
procedure TCodeExplorerOptions.DoAfterWrite(Restore: boolean);
begin
if not Restore then
Save;
end;
procedure TCodeExplorerOptions.Clear;
begin
IncreaseChangeStep;
FMode:=cemCategory;
FRefresh:=cerDefault;
FFollowCursor:=true;
FCategories:=DefaultCodeExplorerCategories;
FObserverCategories:=DefaultCodeObserverCategories;
FLongProcLineCount:=DefaultCOLongProcLineCount;
FLongParamListCount:=DefaultCOLongParamListCount;
FNestedProcCount:=DefaultCONestedProcCount;
FObserveCharConst:=DefaultCOureCharConst;
Clear_COIgnoreConstants;
Clear_COIgnoreConstInFuncs;
end;
procedure TCodeExplorerOptions.Assign(Source: TPersistent);
var
Src: TCodeExplorerOptions;
List: TStrings;
begin
if Source is TCodeExplorerOptions then begin
IncreaseChangeStep;
Src:=TCodeExplorerOptions(Source);
FRefresh:=Src.Refresh;
FMode:=Src.Mode;
FFollowCursor:=Src.FollowCursor;
FCategories:=Src.Categories;
FObserverCategories:=Src.ObserverCategories;
FLongProcLineCount:=Src.LongProcLineCount;
FLongParamListCount:=Src.LongParamListCount;
FNestedProcCount:=Src.NestedProcCount;
FObserveCharConst:=Src.ObserveCharConst;
List:=Src.CreateListOfCOIgnoreConstants;
try
SetListOf_COIgnoreConstants(List,false);
finally
List.Free;
end;
List:=Src.CreateListOfCOIgnoreConstInFuncs;
try
SetListOf_COIgnoreConstInFuncs(List,false);
finally
List.Free;
end;
end else
inherited Assign(Source);
end;
procedure TCodeExplorerOptions.Load;
var
XMLConfig: TXMLConfig;
//FileVersion: integer;
begin
if not FileExistsUTF8(FOptionsFilename) then
begin
Clear;
LoadDefaults_COIgnoreConstants;
LoadDefaults_COIgnoreConstInFuncs;
Exit;
end;
try
XMLConfig:=TXMLConfig.Create(FOptionsFilename);
//FileVersion:=XMLConfig.GetValue('CodeExplorer/Version/Value',0);
LoadFromXMLConfig(XMLConfig,'CodeExplorer/');
XMLConfig.Free;
except
on E: Exception do begin
DebugLn('[TCodeExplorerOptions.Load] error reading "',FOptionsFilename,'" ',E.Message);
end;
end;
end;
procedure TCodeExplorerOptions.Save;
var
XMLConfig: TXMLConfig;
begin
try
InvalidateFileStateCache;
XMLConfig:=TXMLConfig.CreateClean(FOptionsFilename);
XMLConfig.SetDeleteValue('CodeExplorer/Version/Value',
CodeExplorerVersion,0);
SaveToXMLConfig(XMLConfig,'CodeExplorer/');
XMLConfig.Flush;
XMLConfig.Free;
except
on E: Exception do begin
DebugLn('[TCodeExplorerOptions.Save] error writing "',FOptionsFilename,'" ',E.Message);
end;
end;
end;
procedure TCodeExplorerOptions.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
var
c: TCodeExplorerCategory;
f: TCEObserverCategory;
CurPath: String;
List: TStringList;
begin
IncreaseChangeStep;
Clear;
FRefresh:=CodeExplorerRefreshNameToEnum(
XMLConfig.GetValue(Path+'Refresh/Value',''));
FMode:=CodeExplorerModeNameToEnum(
XMLConfig.GetValue(Path+'Mode/Value',''));
FFollowCursor:=XMLConfig.GetValue(Path+'FollowCursor',true);
FCategories:=[];
for c:=FirstCodeExplorerCategory to high(TCodeExplorerCategory) do
if XMLConfig.GetValue(Path+'Categories/'+CodeExplorerCategoryNames[c],
c in DefaultCodeExplorerCategories) then
Include(FCategories,c);
FObserverCategories:=[];
for f:=low(TCEObserverCategory) to high(TCEObserverCategory) do
begin
CurPath:=Path+'CodeObserver/'+CodeObserverCategoryNames[f]+'/';
if XMLConfig.GetValue(CurPath+'Show',f in DefaultCodeObserverCategories)
then
Include(FObserverCategories,f);
case f of
cefcLongProcs:
FLongProcLineCount:=XMLConfig.GetValue(CurPath+'LineCount/Value',
DefaultCOLongProcLineCount);
cefcLongParamLists:
FLongParamListCount:=XMLConfig.GetValue(CurPath+'Count/Value',
DefaultCOLongParamListCount);
cefcNestedProcs:
FNestedProcCount:=XMLConfig.GetValue(CurPath+'Count/Value',
DefaultCONestedProcCount);
cefcUnnamedConsts:
begin
FObserveCharConst:=XMLConfig.GetValue(CurPath+'CharConsts/Value',
DefaultCOureCharConst);
// load standard ObserverIgnoreConstants
if XMLConfig.GetValue(CurPath+'Ignore/ContainsDefaults',true) then
LoadDefaults_COIgnoreConstants;
// load custom ObserverIgnoreConstants
List:=TStringList.Create;
try
LoadStringList(XMLConfig,List,CurPath+'Ignore/');
SetListOf_COIgnoreConstants(List,true);
finally
List.Free;
end;
// load standard COIgnoreConstInFuncs
if XMLConfig.GetValue(CurPath+'IgnoreInFuncs/ContainsDefaults',true) then
LoadDefaults_COIgnoreConstInFuncs;
// load custom COIgnoreConstInFuncs
List:=TStringList.Create;
try
LoadStringList(XMLConfig,List,CurPath+'IgnoreFuncs/');
SetListOf_COIgnoreConstInFuncs(List,true);
finally
List.Free;
end;
end;
end;
end;
end;
procedure TCodeExplorerOptions.SaveToXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
var
c: TCodeExplorerCategory;
f: TCEObserverCategory;
CurPath: String;
List: TStrings;
ContainsDefaults: Boolean;
i: Integer;
begin
XMLConfig.SetDeleteValue(Path+'Refresh/Value',
CodeExplorerRefreshNames[FRefresh],
CodeExplorerRefreshNames[cerDefault]);
XMLConfig.SetDeleteValue(Path+'Mode/Value',
CodeExplorerModeNames[FMode],
CodeExplorerModeNames[cemCategory]);
XMLConfig.SetDeleteValue(Path+'FollowCursor',FFollowCursor,true);
for c:=FirstCodeExplorerCategory to high(TCodeExplorerCategory) do
XMLConfig.SetDeleteValue(Path+'Categories/'+CodeExplorerCategoryNames[c],
c in FCategories,c in DefaultCodeExplorerCategories);
for f:=low(TCEObserverCategory) to high(TCEObserverCategory) do
begin
CurPath:=Path+'CodeObserver/'+CodeObserverCategoryNames[f]+'/';
XMLConfig.SetDeleteValue(CurPath+'Show',
f in FObserverCategories,f in DefaultCodeObserverCategories);
case f of
cefcLongProcs:
XMLConfig.SetDeleteValue(CurPath+'LineCount/Value',
FLongProcLineCount,DefaultCOLongProcLineCount);
cefcLongParamLists:
XMLConfig.SetDeleteValue(CurPath+'Count/Value',
FLongParamListCount,DefaultCOLongParamListCount);
cefcNestedProcs:
XMLConfig.SetDeleteValue(CurPath+'Count/Value',
FNestedProcCount,DefaultCONestedProcCount);
cefcUnnamedConsts:
begin
XMLConfig.SetDeleteValue(CurPath+'CharConsts/Value',
FObserveCharConst,DefaultCOureCharConst);
// save standard ObserverIgnoreConstants
ContainsDefaults:=COIgnoreConstants_AreDefault(false);
XMLConfig.SetDeleteValue(CurPath+'Ignore/ContainsDefaults',
ContainsDefaults,true);
// save ObserverIgnoreConstants
List:=CreateListOfCOIgnoreConstants;
try
for i:=List.Count-1 downto 0 do
if COIgnoreConstant_IsDefault(List[i]) then
List.Delete(i);
SaveStringList(XMLConfig,List,CurPath+'Ignore/');
finally
List.Free;
end;
// save standard COIgnoreConstInFuncs
ContainsDefaults:=COIgnoreConstInFuncs_AreDefault(false);
XMLConfig.SetDeleteValue(CurPath+'IgnoreInFuncs/ContainsDefaults',
ContainsDefaults,true);
// save COIgnoreConstInFuncs
List:=CreateListOfCOIgnoreConstInFuncs;
try
for i:=List.Count-1 downto 0 do
if COIgnoreConstInFuncs_IsDefault(List[i]) then
List.Delete(i);
SaveStringList(XMLConfig,List,CurPath+'IgnoreInFuncs/');
finally
List.Free;
end;
end;
end;
end;
end;
procedure TCodeExplorerOptions.IncreaseChangeStep;
begin
if FChangeStep=high(integer) then
FChangeStep:=low(integer)
else
inc(FChangeStep);
end;
function TCodeExplorerOptions.CreateListOfCOIgnoreConstants: TStrings;
var
AVLNode: TAvgLvlTreeNode;
s: String;
begin
Result:=TStringList.Create;
AVLNode:=ObserverIgnoreConstants.FindLowest;
while AVLNode<>nil do begin
s:=GetAtomString(PChar(AVLNode.Data),false);
if s<>'' then
Result.Add(s);
AVLNode:=ObserverIgnoreConstants.FindSuccessor(AVLNode);
end;
end;
procedure TCodeExplorerOptions.Clear_COIgnoreConstants;
var
AVLNode: TAvgLvlTreeNode;
s: String;
begin
if FObserverIgnoreConstants.Count=0 then exit;
IncreaseChangeStep;
s:='';
AVLNode:=FObserverIgnoreConstants.FindLowest;
while AVLNode<>nil do begin
// decrease reference counter
Pointer(s):=AVLNode.Data;
s:='';
AVLNode:=FObserverIgnoreConstants.FindSuccessor(AVLNode);
end;
if s='' then ; // omit fpc note
FObserverIgnoreConstants.Clear;
end;
procedure TCodeExplorerOptions.SetListOf_COIgnoreConstants(List: TStrings;
Add: boolean);
var
i: Integer;
begin
IncreaseChangeStep;
if not Add then
Clear_COIgnoreConstants;
for i:=0 to List.Count-1 do
Add_COIgnoreConstant(List[i]);
end;
procedure TCodeExplorerOptions.LoadDefaults_COIgnoreConstants;
var
i: Integer;
begin
if COIgnoreConstants_AreDefault(true) then exit;
IncreaseChangeStep;
Clear_COIgnoreConstants;
for i:=low(DefaultCOIgnoreConstants) to high(DefaultCOIgnoreConstants) do
Add_COIgnoreConstant(DefaultCOIgnoreConstants[i]);
end;
function TCodeExplorerOptions.CreateListOfCOIgnoreConstInFuncs: TStrings;
var
AVLNode: TAvgLvlTreeNode;
s: String;
begin
Result:=TStringList.Create;
AVLNode:=COIgnoreConstInFuncs.Tree.FindLowest;
while AVLNode<>nil do begin
s:=PStringToStringItem(AVLNode.Data)^.Name;
if s<>'' then
Result.Add(s);
AVLNode:=COIgnoreConstInFuncs.Tree.FindSuccessor(AVLNode);
end;
end;
procedure TCodeExplorerOptions.SetListOf_COIgnoreConstInFuncs(List: TStrings;
Add: boolean);
var
i: Integer;
begin
IncreaseChangeStep;
if not Add then
Clear_COIgnoreConstInFuncs;
for i:=0 to List.Count-1 do
Add_COIgnoreConstInFuncs(List[i]);
end;
function TCodeExplorerOptions.COIgnoreConstInFunc(const Func: string): boolean;
begin
Result:=FCOIgnoreConstInFuncs.Contains(Func);
end;
function TCodeExplorerOptions.COIgnoreConstInFuncs_AreDefault(Exactly: boolean
): boolean;
const
DefCount = high(DefaultCOIgnoreConstInFuncs)-Low(DefaultCOIgnoreConstInFuncs)+1;
var
i: Integer;
begin
if Exactly and (FCOIgnoreConstInFuncs.Count=DefCount) then
exit(false);
if FCOIgnoreConstInFuncs.Count<DefCount then exit(false);
for i:=low(DefaultCOIgnoreConstInFuncs) to high(DefaultCOIgnoreConstInFuncs) do
if not COIgnoreConstInFunc(DefaultCOIgnoreConstInFuncs[i]) then
exit(false);
Result:=true;
end;
function TCodeExplorerOptions.COIgnoreConstInFuncs_IsDefault(const Func: string
): boolean;
var
i: Integer;
begin
for i:=low(DefaultCOIgnoreConstants) to high(DefaultCOIgnoreConstants) do
if SysUtils.CompareText(Func,DefaultCOIgnoreConstants[i])=0 then
exit(true);
Result:=false;
end;
procedure TCodeExplorerOptions.Add_COIgnoreConstInFuncs(const Func: string);
begin
if Func='' then exit;
if COIgnoreConstInFunc(Func) then exit;
IncreaseChangeStep;
FCOIgnoreConstInFuncs.Values[Func]:='';
end;
procedure TCodeExplorerOptions.Clear_COIgnoreConstInFuncs;
begin
if FCOIgnoreConstInFuncs.Count=0 then exit;
IncreaseChangeStep;
FCOIgnoreConstInFuncs.Clear;
end;
procedure TCodeExplorerOptions.LoadDefaults_COIgnoreConstInFuncs;
var
i: Integer;
begin
if COIgnoreConstInFuncs_AreDefault(true) then exit;
IncreaseChangeStep;
Clear_COIgnoreConstInFuncs;
for i:=low(DefaultCOIgnoreConstInFuncs) to high(DefaultCOIgnoreConstInFuncs) do
Add_COIgnoreConstInFuncs(DefaultCOIgnoreConstInFuncs[i]);
end;
function TCodeExplorerOptions.COIgnoreConstant(p: PChar): boolean;
begin
Result:=FObserverIgnoreConstants.Find(p)<>nil;
end;
procedure TCodeExplorerOptions.Add_COIgnoreConstant(const Atom: string);
var
s: String;
begin
if Atom='' then exit;
if COIgnoreConstant(PChar(Atom)) then exit;
IncreaseChangeStep;
s:=Atom;
FObserverIgnoreConstants.Add(Pointer(s));
Pointer(s):=nil;
end;
function TCodeExplorerOptions.COIgnoreConstants_AreDefault(Exactly: boolean
): boolean;
const
DefCount = high(DefaultCOIgnoreConstants)-Low(DefaultCOIgnoreConstants)+1;
var
i: Integer;
begin
if Exactly and (FObserverIgnoreConstants.Count=DefCount) then
exit(false);
if FObserverIgnoreConstants.Count<DefCount then exit(false);
for i:=low(DefaultCOIgnoreConstants) to high(DefaultCOIgnoreConstants) do
if not COIgnoreConstant(PChar(DefaultCOIgnoreConstants[i])) then
exit(false);
Result:=true;
end;
function TCodeExplorerOptions.COIgnoreConstant_IsDefault(const Atom: string
): boolean;
var
i: Integer;
begin
for i:=low(DefaultCOIgnoreConstants) to high(DefaultCOIgnoreConstants) do
if CompareAtom(PChar(Atom),PChar(DefaultCOIgnoreConstants[i]),false)=0 then
exit(true);
Result:=false;
end;
initialization
RegisterIDEOptionsGroup(GroupCodeExplorer, TCodeExplorerOptions);
end.
|