/ide/codeexplopts.pas

http://github.com/graemeg/lazarus · Pascal · 920 lines · 797 code · 72 blank · 51 comment · 72 complexity · e73a2b62566992b06f92ecf1f2d06032 MD5 · raw file

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