From 1b137755fc52060d1637573dfe44197aa1642c0f Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 14 Oct 2015 16:39:48 +0000 Subject: [PATCH] IDE: Move loading and saving ButtonNames in IDECoolbar and EditorToolbar config into methods. git-svn-id: trunk@50059 - --- ide/editortoolbarstatic.pas | 23 +++++---------------- ide/frames/idecoolbar_options.pas | 1 - ide/idecoolbardata.pas | 24 +++------------------- ide/mainbar.pas | 3 --- ide/toolbarconfig.pas | 33 +++++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 43 deletions(-) diff --git a/ide/editortoolbarstatic.pas b/ide/editortoolbarstatic.pas index 64efdd16ba..495898f786 100644 --- a/ide/editortoolbarstatic.pas +++ b/ide/editortoolbarstatic.pas @@ -24,10 +24,9 @@ unit EditorToolbarStatic; interface uses - SysUtils, Classes, Forms, ComCtrls, Controls, ExtCtrls, fgl, - MenuIntf, IDEImagesIntf, SrcEditorIntf, BaseIDEIntf, LazIDEIntf, - LazarusIDEStrConsts, LazConfigStorage, Laz2_XMLCfg, LCLProc, ToolbarConfig, - ToolBarIntf; + SysUtils, Classes, fgl, ComCtrls, Controls, LCLProc, + MenuIntf, IDEImagesIntf, SrcEditorIntf, BaseIDEIntf, + LazarusIDEStrConsts, LazConfigStorage, Laz2_XMLCfg, ToolbarConfig; type @@ -167,15 +166,7 @@ begin begin FVisible := XMLConfig.GetValue(Path + 'Visible', True); FPosition := XMLConfig.GetValue(Path + 'Position', 'Top'); - ButtonCount := XMLConfig.GetValue(Path + 'Count', 0); - for I := 1 to ButtonCount do - begin - ButtonName := XMLConfig.GetValue(Path + 'Button' + IntToStr(I) + '/Name', ''); - if ButtonName = '' then // Old format - ButtonName := XMLConfig.GetValue(Path + 'Buttons/Name' + IntToStr(I) + '/Value', ''); - if ButtonName <> '' then - ButtonNames.Add(ButtonName); - end; + LoadButtonNames(XMLConfig, Path); end else begin // Plan B: Load the old configuration. User settings are not lost. @@ -205,15 +196,11 @@ begin end; procedure TEditorToolBarOptions.Save(XMLConfig: TXMLConfig; Path: String); -var - I: Integer; begin Path := Path + BasePath; XMLConfig.SetDeleteValue(Path + 'Visible', FVisible, True); XMLConfig.SetDeleteValue(Path + 'Position', FPosition, 'Top'); - XMLConfig.SetDeleteValue(Path + 'Count', ButtonNames.Count, 0); - for I := 0 to ButtonNames.Count-1 do - XMLConfig.SetDeleteValue(Path + 'Button' + IntToStr(I+1) + '/Name', ButtonNames[I], ''); + SaveButtonNames(XMLConfig, Path); end; { TEditorToolbar } diff --git a/ide/frames/idecoolbar_options.pas b/ide/frames/idecoolbar_options.pas index a5e933fa1f..889642f7c3 100644 --- a/ide/frames/idecoolbar_options.pas +++ b/ide/frames/idecoolbar_options.pas @@ -394,7 +394,6 @@ procedure TIdeCoolbarOptionsFrame.bConfigClick(Sender: TObject); var ToConfig: Integer; ToolBar: TToolBar; - I: Integer; begin ToConfig := GetSelectedBand; if ToConfig = -1 then diff --git a/ide/idecoolbardata.pas b/ide/idecoolbardata.pas index c8e7ef33dd..39dec6c7ae 100644 --- a/ide/idecoolbardata.pas +++ b/ide/idecoolbardata.pas @@ -34,7 +34,7 @@ interface uses Classes, SysUtils, LCLProc, ComCtrls, ToolWin, Controls, fgl, - ToolBarIntf, IDEImagesIntf, Laz2_XMLCfg, ToolbarConfig; + IDEImagesIntf, Laz2_XMLCfg, ToolbarConfig; type @@ -198,33 +198,15 @@ begin end; procedure TIDEToolBarOptions.Load(XMLConfig: TXMLConfig; SubPath: String); -var - ButtonCount: Integer; - ButtonName: string; - I: Integer; begin FBreak := XMLConfig.GetValue(SubPath + 'Break/Value', False); - ButtonCount := XMLConfig.GetValue(SubPath + 'Count', 0); - if ButtonCount = 0 then // Old format - ButtonCount := XMLConfig.GetValue(SubPath + 'ButtonCount/Value', 0); - for I := 1 to ButtonCount do - begin - ButtonName := XMLConfig.GetValue(SubPath + 'Button' + IntToStr(I) + '/Name', ''); - if ButtonName = '' then // Old format - ButtonName := XMLConfig.GetValue(SubPath + 'Buttons/Name' + IntToStr(I) + '/Value', ''); - if ButtonName <> '' then - ButtonNames.Add(ButtonName); - end; + LoadButtonNames(XMLConfig, SubPath); end; procedure TIDEToolBarOptions.Save(XMLConfig: TXMLConfig; SubPath: String); -var - I: Integer; begin XMLConfig.SetDeleteValue(SubPath + 'Break/Value', FBreak, False); - XMLConfig.SetDeleteValue(SubPath + 'Count', ButtonNames.Count, 0); - for I := 0 to ButtonNames.Count-1 do - XMLConfig.SetDeleteValue(SubPath + 'Button' + IntToStr(I+1) + '/Name', ButtonNames[I], ''); + SaveButtonNames(XMLConfig, SubPath); end; { TIDEToolBarOptionList } diff --git a/ide/mainbar.pas b/ide/mainbar.pas index 35c8bd18dd..459d1214d5 100644 --- a/ide/mainbar.pas +++ b/ide/mainbar.pas @@ -771,9 +771,6 @@ begin end; procedure TMainIDEBar.CoolBarOnChange(Sender: TObject); -var - I, J: Integer; - ToolBar: TToolBar; begin IDECoolBar.CopyFromRealCoolbar(Coolbar); IDECoolBar.CopyToOptions(EnvironmentOptions.Desktop.IDECoolBarOptions); diff --git a/ide/toolbarconfig.pas b/ide/toolbarconfig.pas index 46ec44d00e..56ecd44e05 100644 --- a/ide/toolbarconfig.pas +++ b/ide/toolbarconfig.pas @@ -27,6 +27,8 @@ uses // LCL and LazControls LCLProc, Forms, Graphics, ExtCtrls, Buttons, StdCtrls, Controls, ComCtrls, Menus, ButtonPanel, TreeFilterEdit, LclIntf, + // LazUtils + Laz2_XMLCfg, // IdeIntf IDECommands, ToolBarIntf, IDEImagesIntf, // IDE @@ -109,6 +111,9 @@ type TIDEToolBarOptionsBase = class private FButtonNames: TStringList; + protected + procedure LoadButtonNames(XMLConfig: TXMLConfig; SubPath: String); + procedure SaveButtonNames(XMLConfig: TXMLConfig; SubPath: String); public constructor Create; destructor Destroy; override; @@ -671,6 +676,34 @@ begin FButtonNames.Assign(Source.FButtonNames); end; +procedure TIDEToolBarOptionsBase.LoadButtonNames(XMLConfig: TXMLConfig; SubPath: String); +var + ButtonCount: Integer; + ButtonName: string; + I: Integer; +begin + ButtonCount := XMLConfig.GetValue(SubPath + 'Count', 0); + if ButtonCount = 0 then // Old format + ButtonCount := XMLConfig.GetValue(SubPath + 'ButtonCount/Value', 0); + for I := 1 to ButtonCount do + begin + ButtonName := XMLConfig.GetValue(SubPath + 'Button' + IntToStr(I) + '/Name', ''); + if ButtonName = '' then // Old format + ButtonName := XMLConfig.GetValue(SubPath + 'Buttons/Name' + IntToStr(I) + '/Value', ''); + if ButtonName <> '' then + ButtonNames.Add(ButtonName); + end; +end; + +procedure TIDEToolBarOptionsBase.SaveButtonNames(XMLConfig: TXMLConfig; SubPath: String); +var + I: Integer; +begin + XMLConfig.SetDeleteValue(SubPath + 'Count', ButtonNames.Count, 0); + for I := 0 to ButtonNames.Count-1 do + XMLConfig.SetDeleteValue(SubPath + 'Button' + IntToStr(I+1) + '/Name', ButtonNames[I], ''); +end; + { TIDEToolbarBase } { For future needs ... constructor TIDEToolbarBase.Create(AOwner: TComponent);