/ide/makeresstrdlg.pas

http://github.com/graemeg/lazarus · Pascal · 636 lines · 513 code · 58 blank · 65 comment · 46 complexity · 9f245b269efac2c7050a320303012f7d MD5 · raw file

  1. {
  2. /***************************************************************************
  3. makeresstrdlg.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. Author: Mattias Gaertner
  25. Abstract:
  26. TMakeResStrDialog is the dialog to setup how to convert a string constant
  27. into a pascal resourcestring.
  28. }
  29. unit MakeResStrDlg;
  30. {$mode objfpc}{$H+}
  31. interface
  32. uses
  33. Classes, SysUtils, LCLProc, Forms, Controls, Buttons, StdCtrls,
  34. Dialogs, ExtCtrls, ButtonPanel, IDEWindowIntf,
  35. SynHighlighterPas, SynEdit,
  36. CodeToolManager, CodeToolsStructs, CodeCache,
  37. IDEHelpIntf, IDEDialogs,
  38. LazarusIDEStrConsts,
  39. EditorOptions, InputHistory, MiscOptions, IDEProcs;
  40. type
  41. { TMakeResStrDialog }
  42. TMakeResStrDialog = class(TForm)
  43. ButtonPanel1: TButtonPanel;
  44. CustomIdentifierCheckBox: TCheckBox;
  45. IdentifierGroupBox: TGroupBox;
  46. IdentifierEdit: TEdit;
  47. IdentLengthComboBox: TComboBox;
  48. IdentLengthLabel: TLabel;
  49. IdentPrefixComboBox: TComboBox;
  50. IdentPrefixLabel: TLabel;
  51. // options
  52. ConversionGroupBox: TGroupBox;
  53. CodePanel: TPanel;
  54. // resourcestring section
  55. ResStrSectionLabel: TLabel;
  56. ResStrSectionComboBox: TComboBox;
  57. // resourcestrings with same value
  58. ResStrWithSameValueLabel: TLabel;
  59. ResStrWithSameValuesCombobox: TComboBox;
  60. // insert position type
  61. AppendResStrRadioButton: TRadioButton;
  62. InsertAlphabeticallyResStrRadioButton: TRadioButton;
  63. InsertContextSensitiveRadioButton: TRadioButton;
  64. Splitter1: TSplitter;
  65. SrcPreviewGroupBox: TGroupBox;
  66. SrcPreviewSynEdit: TSynEdit;
  67. StringConstGroupBox: TGroupBox;
  68. StringConstSynEdit: TSynEdit;
  69. // highlighter
  70. SynPasSyn: TSynPasSyn;
  71. procedure CustomIdentifierCheckBoxClick(Sender: TObject);
  72. procedure HelpButtonClick(Sender: TObject);
  73. procedure IdentLengthComboBoxChange(Sender: TObject);
  74. procedure IdentPrefixComboBoxChange(Sender: TObject);
  75. procedure IdentifierEditChange(Sender: TObject);
  76. procedure OkButtonClick(Sender: TObject);
  77. procedure ResStrSectionComboBoxChange(Sender: TObject);
  78. procedure ResStrWithSameValuesComboboxChange(Sender: TObject);
  79. private
  80. procedure SetupComponents;
  81. public
  82. DefaultIdentifier: string;
  83. Code: TCodeBuffer;
  84. StartPos, EndPos: TPoint;
  85. Positions: TCodeXYPositions;
  86. constructor Create(TheOwner: TComponent); override;
  87. destructor Destroy; override;
  88. procedure FillResourceStringSections(NewPositions: TCodeXYPositions);
  89. procedure FillIdentPrefixes;
  90. procedure FillIdentLengths;
  91. procedure FillStringsWithSameValue;
  92. procedure UpdateIdentifier;
  93. procedure UpdateSourcePreview;
  94. function GetIdentifier: string;
  95. function GetDefaultIdentifier: string;
  96. procedure SetSource(NewCode: TCodeBuffer;
  97. const NewStartPos, NewEndPos: TPoint);
  98. function ResStrExistsInCurrentSection(const Identifier: string): boolean;
  99. function ResStrExistsInAnySection(const Identifier: string): boolean;
  100. function ResStrExistsWithSameValue(const Identifier: string): boolean;
  101. procedure GetNewSource(out NewSource, ResourceStringValue: string);
  102. procedure Init;
  103. procedure SaveHistories;
  104. procedure SaveIdentPrefixes;
  105. procedure SaveIdentLengths;
  106. procedure Save;
  107. end;
  108. function ShowMakeResStrDialog(
  109. const StartPos, EndPos: TPoint; Code: TCodeBuffer;
  110. out NewIdentifier, NewIdentifierValue: string;
  111. out NewSourceLines: string;
  112. out ResStrSectionCode: TCodeBuffer;
  113. out ResStrSectionXY: TPoint;
  114. out InsertPolicy: TResourcestringInsertPolicy): TModalResult;
  115. implementation
  116. {$R *.lfm}
  117. function ShowMakeResStrDialog(const StartPos, EndPos: TPoint;
  118. Code: TCodeBuffer; out NewIdentifier, NewIdentifierValue: string; out
  119. NewSourceLines: string; out ResStrSectionCode: TCodeBuffer; out
  120. ResStrSectionXY: TPoint; out InsertPolicy: TResourcestringInsertPolicy
  121. ): TModalResult;
  122. var
  123. MakeResStrDialog: TMakeResStrDialog;
  124. Section: PCodeXYPosition;
  125. ResourcestringSectionID: Integer;
  126. begin
  127. //debugln('ShowMakeResStrDialog StartPos=',dbgs(StartPos),' EndPos=',dbgs(EndPos),' ');
  128. NewIdentifier:='';
  129. NewIdentifierValue:='';
  130. NewSourceLines:='';
  131. ResStrSectionCode:=nil;
  132. ResStrSectionXY:=Point(0,0);
  133. InsertPolicy:=rsipNone;
  134. MakeResStrDialog:=TMakeResStrDialog.Create(nil);
  135. MakeResStrDialog.Positions:=CodeToolBoss.Positions.CreateCopy;
  136. MakeResStrDialog.SetSource(Code,StartPos,EndPos);
  137. MakeResStrDialog.Init;
  138. // show dialog
  139. Result:=MakeResStrDialog.ShowModal;
  140. if Result=mrOk then begin
  141. // return results
  142. NewIdentifier:=MakeResStrDialog.GetIdentifier;
  143. MakeResStrDialog.GetNewSource(NewSourceLines,NewIdentifierValue);
  144. if MakeResStrDialog.ResStrExistsWithSameValue(NewIdentifier) then
  145. InsertPolicy:=rsipNone
  146. else begin
  147. if MakeResStrDialog.InsertAlphabeticallyResStrRadioButton.Checked then
  148. InsertPolicy:=rsipAlphabetically
  149. else if MakeResStrDialog.InsertContextSensitiveRadioButton.Checked then
  150. InsertPolicy:=rsipContext
  151. else
  152. InsertPolicy:=rsipAppend;
  153. end;
  154. ResourcestringSectionID:=MakeResStrDialog.ResStrSectionComboBox.ItemIndex;
  155. Section:=CodeToolBoss.Positions[ResourcestringSectionID];
  156. ResStrSectionCode:=Section^.Code;
  157. ResStrSectionXY:=Point(Section^.X,Section^.Y);
  158. end;
  159. // save settings and clean up
  160. IDEDialogLayoutList.SaveLayout(MakeResStrDialog);
  161. MakeResStrDialog.Positions.Free;
  162. MakeResStrDialog.Free;
  163. end;
  164. { TMakeResStrDialog }
  165. procedure TMakeResStrDialog.CustomIdentifierCheckBoxClick(Sender: TObject);
  166. begin
  167. UpdateIdentifier;
  168. end;
  169. procedure TMakeResStrDialog.HelpButtonClick(Sender: TObject);
  170. begin
  171. LazarusHelp.ShowHelpForIDEControl(Self);
  172. end;
  173. procedure TMakeResStrDialog.IdentLengthComboBoxChange(Sender: TObject);
  174. begin
  175. UpdateIdentifier;
  176. UpdateSourcePreview;
  177. end;
  178. procedure TMakeResStrDialog.IdentPrefixComboBoxChange(Sender: TObject);
  179. begin
  180. UpdateIdentifier;
  181. UpdateSourcePreview;
  182. end;
  183. procedure TMakeResStrDialog.IdentifierEditChange(Sender: TObject);
  184. begin
  185. UpdateIdentifier;
  186. UpdateSourcePreview;
  187. end;
  188. procedure TMakeResStrDialog.OkButtonClick(Sender: TObject);
  189. var
  190. Index: Integer;
  191. begin
  192. Index:=ResStrSectionComboBox.ItemIndex;
  193. if (Index<0) or (Index>=Positions.Count) then begin
  194. IDEMessageDialog(lisMakeResStrInvalidResourcestringSect,
  195. lisMakeResStrPleaseChooseAResourcestring,
  196. mtError,[mbCancel]);
  197. exit;
  198. end;
  199. if ResStrExistsInAnySection(IdentifierEdit.Text)
  200. and (not ResStrExistsWithSameValue(IdentifierEdit.Text)) then begin
  201. if IDEMessageDialog(lisMakeResStrResourcestringAlreadyExis,
  202. Format(lisMakeResStrChooseAnotherName,[IdentifierEdit.Text,LineEnding,LineEnding]),
  203. mtWarning,[mbOk,mbIgnore]) = mrOk
  204. then
  205. exit;
  206. end;
  207. Save;
  208. ModalResult:=mrOk;
  209. end;
  210. procedure TMakeResStrDialog.ResStrSectionComboBoxChange(Sender: TObject);
  211. begin
  212. UpdateIdentifier;
  213. UpdateSourcePreview;
  214. end;
  215. procedure TMakeResStrDialog.ResStrWithSameValuesComboboxChange(Sender: TObject);
  216. var
  217. NewIdentifier: String;
  218. i: Integer;
  219. begin
  220. NewIdentifier:=ResStrWithSameValuesCombobox.Text;
  221. i:=ResStrWithSameValuesCombobox.Items.IndexOf(NewIdentifier);
  222. if i<0 then exit;
  223. IdentifierEdit.Text:=NewIdentifier;
  224. end;
  225. procedure TMakeResStrDialog.SetupComponents;
  226. begin
  227. // source
  228. AppendResStrRadioButton.Caption:=lisMakeResStrAppendToSection;
  229. ConversionGroupBox.Caption:=lisMakeResStrConversionOptions;
  230. CustomIdentifierCheckBox.Caption:=lisMakeResStrCustomIdentifier;
  231. IdentifierGroupBox.Caption := lisMakeResStrDialogIdentifier;
  232. IdentLengthLabel.Caption:=lisMakeResStrIdentifierLength;
  233. IdentPrefixLabel.Caption:=lisMakeResStrIdentifierPrefix;
  234. InsertAlphabeticallyResStrRadioButton.Caption:=lisMakeResStrInsertAlphabetically;
  235. InsertContextSensitiveRadioButton.Caption:=lisMakeResStrInsertContexttSensitive;
  236. ResStrSectionLabel.Caption:=lisMakeResStrResourcestringSection;
  237. ResStrWithSameValueLabel.Caption:=lisMakeResStrStringsWithSameValue;
  238. SrcPreviewGroupBox.Caption:=lisMakeResStrSourcePreview;
  239. StringConstGroupBox.Caption:=lisMakeResStrStringConstantInSource;
  240. // OK, Cancel, Help buttons
  241. ButtonPanel1.OkButton.Caption:=lisMenuOk;
  242. ButtonPanel1.CancelButton.Caption:=lisCancel;
  243. ButtonPanel1.HelpButton.Caption:=lisMenuHelp;
  244. end;
  245. constructor TMakeResStrDialog.Create(TheOwner: TComponent);
  246. begin
  247. inherited Create(TheOwner);
  248. Caption := lisMakeResourceString;
  249. SetupComponents;
  250. IDEDialogLayoutList.ApplyLayout(Self,550,400);
  251. EditorOpts.GetHighlighterSettings(SynPasSyn);
  252. EditorOpts.GetSynEditSettings(StringConstSynEdit);
  253. StringConstSynEdit.ReadOnly:=true;
  254. StringConstSynEdit.Gutter.Visible:=false;
  255. EditorOpts.GetSynEditSettings(SrcPreviewSynEdit);
  256. SrcPreviewSynEdit.ReadOnly:=true;
  257. SrcPreviewSynEdit.Gutter.Visible:=false;
  258. end;
  259. destructor TMakeResStrDialog.Destroy;
  260. begin
  261. inherited Destroy;
  262. end;
  263. procedure TMakeResStrDialog.FillResourceStringSections(
  264. NewPositions: TCodeXYPositions);
  265. var
  266. i: Integer;
  267. p: PCodeXYPosition;
  268. s: String;
  269. begin
  270. Positions:=NewPositions;
  271. // the history list contains the filenames plus the
  272. with ResStrSectionComboBox do begin
  273. Text:='';
  274. Items.BeginUpdate;
  275. for i:=0 to Positions.Count-1 do begin
  276. p:=Positions[i];
  277. s:=p^.Code.Filename+' ('+IntToStr(p^.Y)+','+IntToStr(p^.X)+')';
  278. if i<Items.Count then
  279. Items[i]:=s
  280. else
  281. Items.Add(s);
  282. end;
  283. while Items.Count>Positions.Count do
  284. Items.Delete(Items.Count-1);
  285. Items.EndUpdate;
  286. ItemIndex:=0;
  287. end;
  288. end;
  289. procedure TMakeResStrDialog.FillIdentPrefixes;
  290. var
  291. HistoryList: THistoryList;
  292. begin
  293. // get the Prefixes history list
  294. HistoryList:=
  295. InputHistories.HistoryLists.GetList(hlMakeResourceStringPrefixes,true,
  296. rltCaseSensitive);
  297. IdentPrefixComboBox.Items.Assign(HistoryList);
  298. if IdentPrefixComboBox.Items.Count>0 then
  299. IdentPrefixComboBox.Text:=IdentPrefixComboBox.Items[0]
  300. else
  301. IdentPrefixComboBox.Text:='rs';
  302. end;
  303. procedure TMakeResStrDialog.FillIdentLengths;
  304. var
  305. HistoryList: THistoryList;
  306. begin
  307. // get the Length history list
  308. HistoryList:=
  309. InputHistories.HistoryLists.GetList(hlMakeResourceStringLengths,true,
  310. rltCaseSensitive);
  311. IdentLengthComboBox.Items.Assign(HistoryList);
  312. if IdentLengthComboBox.Items.Count>0 then
  313. IdentLengthComboBox.Text:=IdentLengthComboBox.Items[0]
  314. else begin
  315. with IdentLengthComboBox.Items do begin
  316. Add('8');
  317. Add('12');
  318. Add('20');
  319. Add('50');
  320. end;
  321. IdentLengthComboBox.Text:='12';
  322. end;
  323. end;
  324. procedure TMakeResStrDialog.FillStringsWithSameValue;
  325. var
  326. i: Integer;
  327. CurSection: TCodeXYPosition;
  328. NewSource, ResourceStringValue: string;
  329. StringConstPositions: TCodeXYPositions;
  330. ExistingIdentifier: string;
  331. begin
  332. // get value of the new resourcestring
  333. GetNewSource(NewSource, ResourceStringValue);
  334. // get all existing resourcestrings with same value
  335. StringConstPositions:=TCodeXYPositions.Create;
  336. for i:=0 to Positions.Count-1 do begin
  337. CurSection:=Positions[i]^;
  338. CodeToolBoss.GatherResourceStringsWithValue(
  339. CurSection.Code,CurSection.X,CurSection.Y,
  340. ResourceStringValue,StringConstPositions);
  341. end;
  342. // fill combobox
  343. ResStrWithSameValuesCombobox.Items.Clear;
  344. for i:=0 to StringConstPositions.Count-1 do begin
  345. CurSection:=StringConstPositions[i]^;
  346. CodeToolBoss.GetIdentifierAt(CurSection.Code,CurSection.X,CurSection.Y,
  347. ExistingIdentifier);
  348. if ExistingIdentifier<>'' then
  349. ResStrWithSameValuesCombobox.Items.Add(ExistingIdentifier);
  350. end;
  351. // enable components for selection
  352. if ResStrWithSameValuesCombobox.Items.Count>0 then begin
  353. ResStrWithSameValuesCombobox.Text:=ResStrWithSameValuesCombobox.Items[0];
  354. ResStrWithSameValuesCombobox.Enabled:=true;
  355. end else begin
  356. ResStrWithSameValuesCombobox.Text:='';
  357. ResStrWithSameValuesCombobox.Enabled:=false;
  358. end;
  359. ResStrWithSameValueLabel.Enabled:=ResStrWithSameValuesCombobox.Enabled;
  360. // clean up
  361. StringConstPositions.Free;
  362. end;
  363. procedure TMakeResStrDialog.UpdateIdentifier;
  364. var
  365. CustomIdent: Boolean;
  366. begin
  367. CustomIdent:=CustomIdentifierCheckBox.Checked;
  368. IdentifierEdit.Enabled:=CustomIdent;
  369. IdentPrefixLabel.Enabled:=not CustomIdent;
  370. IdentPrefixComboBox.Enabled:=not CustomIdent;
  371. IdentLengthLabel.Enabled:=not CustomIdent;
  372. IdentLengthComboBox.Enabled:=not CustomIdent;
  373. if not CustomIdent then
  374. IdentifierEdit.Text:=GetDefaultIdentifier;
  375. end;
  376. procedure TMakeResStrDialog.UpdateSourcePreview;
  377. var
  378. NewSource, NewValue: string;
  379. begin
  380. GetNewSource(NewSource,NewValue);
  381. SrcPreviewSynEdit.Text:=NewSource+LineEnding
  382. +StringOfChar('-',
  383. CodeToolBoss.SourceChangeCache.BeautifyCodeOptions.LineLength)
  384. +LineEnding
  385. +CodeToolBoss.SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
  386. GetIdentifier+' = '''+NewValue+'''',0);
  387. end;
  388. function TMakeResStrDialog.GetIdentifier: string;
  389. begin
  390. Result:=IdentifierEdit.Text;
  391. if Result='' then Result:=GetDefaultIdentifier;
  392. end;
  393. function TMakeResStrDialog.GetDefaultIdentifier: string;
  394. var
  395. DefIdenLength: Integer;
  396. i: Integer;
  397. begin
  398. if ResStrWithSameValuesCombobox.Items.Count>0 then begin
  399. Result:=ResStrWithSameValuesCombobox.Items[0];
  400. exit;
  401. end;
  402. DefIdenLength:=StrToIntDef(IdentLengthComboBox.Text,8);
  403. if DefIdenLength<1 then DefIdenLength:=1;
  404. if DefIdenLength>80 then DefIdenLength:=80;
  405. Result:=IdentPrefixComboBox.Text+copy(DefaultIdentifier,1,DefIdenLength);
  406. if ResStrExistsInCurrentSection(Result) then begin
  407. i:=2;
  408. while ResStrExistsInCurrentSection(Result+IntToStr(i)) do inc(i);
  409. Result:=Result+IntToStr(i);
  410. end;
  411. end;
  412. procedure TMakeResStrDialog.SetSource(NewCode: TCodeBuffer; const NewStartPos,
  413. NewEndPos: TPoint);
  414. begin
  415. Code:=NewCode;
  416. StartPos:=NewStartPos;
  417. EndPos:=NewEndPos;
  418. end;
  419. function TMakeResStrDialog.ResStrExistsInCurrentSection(const Identifier: string
  420. ): boolean;
  421. var
  422. CodeXY: PCodeXYPosition;
  423. Index: Integer;
  424. begin
  425. Result:=false;
  426. Index:=ResStrSectionComboBox.ItemIndex;
  427. if (Index<0) or (Index>=Positions.Count) then exit;
  428. CodeXY:=Positions.Items[Index];
  429. Result:=CodeToolBoss.IdentifierExistsInResourceStringSection(
  430. CodeXY^.Code,CodeXY^.X,CodeXY^.Y,Identifier);
  431. end;
  432. function TMakeResStrDialog.ResStrExistsInAnySection(const Identifier: string
  433. ): boolean;
  434. var
  435. CodeXY: PCodeXYPosition;
  436. Index: Integer;
  437. begin
  438. Result:=false;
  439. for Index:=0 to Positions.Count-1 do begin
  440. CodeXY:=Positions.Items[Index];
  441. Result:=CodeToolBoss.IdentifierExistsInResourceStringSection(
  442. CodeXY^.Code,CodeXY^.X,CodeXY^.Y,Identifier);
  443. if Result then exit;
  444. end;
  445. end;
  446. function TMakeResStrDialog.ResStrExistsWithSameValue(const Identifier: string
  447. ): boolean;
  448. var
  449. i: Integer;
  450. begin
  451. if Identifier<>'' then begin
  452. for i:=0 to ResStrWithSameValuesCombobox.Items.Count-1 do begin
  453. if CompareText(Identifier,ResStrWithSameValuesCombobox.Items[i])=0
  454. then begin
  455. Result:=true;
  456. exit;
  457. end;
  458. end;
  459. end;
  460. Result:=false;
  461. end;
  462. procedure TMakeResStrDialog.GetNewSource(out NewSource,
  463. ResourceStringValue: string);
  464. var
  465. FormatStringConstant: string;
  466. FormatParameters: string;
  467. LeftSide: String;
  468. LastLine: string;
  469. NewString: String;
  470. RightSide: String;
  471. StartInStringConst, EndInStringConst: boolean;
  472. begin
  473. NewSource:='';
  474. ResourceStringValue:='';
  475. if not CodeToolBoss.StringConstToFormatString(Code,StartPos.X,StartPos.Y,
  476. Code,EndPos.X,EndPos.Y,FormatStringConstant,FormatParameters,
  477. StartInStringConst,EndInStringConst)
  478. then begin
  479. SrcPreviewSynEdit.Text:=lisCCOErrorCaption+':'#13+CodeToolBoss.ErrorMessage;
  480. exit;
  481. end;
  482. if FormatParameters='' then
  483. NewString:=GetIdentifier
  484. else
  485. NewString:='Format('+GetIdentifier+',['+FormatParameters+'])';
  486. if StartInStringConst then
  487. NewString:='''+'+NewString;
  488. if EndInStringConst then
  489. NewString:=NewString+'+''';
  490. LeftSide:=copy(StringConstSynEdit.Lines[0],1,StartPos.X-1);
  491. LastLine:=StringConstSynEdit.Lines[EndPos.Y-StartPos.Y];
  492. RightSide:=copy(LastLine,EndPos.X,length(LastLine)-EndPos.X+1);
  493. NewSource:=LeftSide+NewString+RightSide;
  494. with CodeToolBoss.SourceChangeCache.BeautifyCodeOptions do
  495. NewSource:=BeautifyStatement(NewSource,0);
  496. ResourceStringValue:=FormatStringConstant;
  497. end;
  498. procedure TMakeResStrDialog.Init;
  499. var
  500. InsertPolicy: TResourcestringInsertPolicy;
  501. begin
  502. // string constant
  503. StringConstSynEdit.Text:=Code.GetLines(StartPos.Y,EndPos.Y);
  504. // reachable resourcestring sections
  505. FillResourceStringSections(Positions);
  506. // identifier prefixes
  507. FillIdentPrefixes;
  508. // identifier lengths
  509. FillIdentLengths;
  510. // existing resource strings with same value
  511. FillStringsWithSameValue;
  512. // identifier
  513. CustomIdentifierCheckBox.Checked:=false;
  514. CodeToolBoss.CreateIdentifierFromStringConst(Code,StartPos.X,StartPos.Y,
  515. Code,EndPos.X,EndPos.Y,DefaultIdentifier,50);
  516. UpdateIdentifier;
  517. // insert policy
  518. InsertPolicy:=MiscellaneousOptions.MakeResourceStringInsertPolicy;
  519. case InsertPolicy of
  520. rsipAlphabetically: InsertAlphabeticallyResStrRadioButton.Checked:=true;
  521. rsipContext: InsertContextSensitiveRadioButton.Checked:=true;
  522. else AppendResStrRadioButton.Checked:=true;
  523. end;
  524. // show new source
  525. UpdateSourcePreview;
  526. end;
  527. procedure TMakeResStrDialog.SaveHistories;
  528. begin
  529. SaveIdentPrefixes;
  530. SaveIdentLengths;
  531. end;
  532. procedure TMakeResStrDialog.SaveIdentPrefixes;
  533. var
  534. HistoryList: THistoryList;
  535. begin
  536. if CustomIdentifierCheckBox.Checked
  537. or (IdentPrefixComboBox.Text='') then
  538. exit;
  539. HistoryList:=
  540. InputHistories.HistoryLists.GetList(hlMakeResourceStringPrefixes,true,rltCaseSensitive);
  541. if HistoryList.Count=0 then
  542. HistoryList.Assign(IdentPrefixComboBox.Items);
  543. HistoryList.Push(IdentPrefixComboBox.Text);
  544. end;
  545. procedure TMakeResStrDialog.SaveIdentLengths;
  546. var
  547. HistoryList: THistoryList;
  548. begin
  549. if CustomIdentifierCheckBox.Checked
  550. or (IdentLengthComboBox.Text='') then
  551. exit;
  552. HistoryList:=
  553. InputHistories.HistoryLists.GetList(hlMakeResourceStringLengths,true,rltCaseSensitive);
  554. if HistoryList.Count=0 then
  555. HistoryList.Assign(IdentLengthComboBox.Items);
  556. HistoryList.Push(IdentLengthComboBox.Text);
  557. end;
  558. procedure TMakeResStrDialog.Save;
  559. var
  560. InsertPolicy: TResourcestringInsertPolicy;
  561. begin
  562. SaveHistories;
  563. if InsertContextSensitiveRadioButton.Checked then
  564. InsertPolicy:=rsipContext
  565. else if InsertAlphabeticallyResStrRadioButton.Checked then
  566. InsertPolicy:=rsipAlphabetically
  567. else
  568. InsertPolicy:=rsipAppend;
  569. MiscellaneousOptions.MakeResourceStringInsertPolicy:=InsertPolicy;
  570. MiscellaneousOptions.Save;
  571. end;
  572. end.