From 30df28348c7902cee7f37863827a9c635743402e Mon Sep 17 00:00:00 2001 From: juha Date: Wed, 12 Jul 2017 16:50:23 +0000 Subject: [PATCH] =?UTF-8?q?JCF:=20Add=20an=20option=20to=20confirm=20the?= =?UTF-8?q?=20formatting=20of=20a=20unit.=20Patch=20from=20Bal=C3=A1zs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: trunk@55491 - --- .../jcf2/IdePlugin/lazarus/jcfidemain.pas | 28 +++++++-- .../jcf2/IdePlugin/lazarus/jcfuiconsts.pas | 2 + components/jcf2/ReadWrite/ConvertTypes.pas | 2 +- .../jcf2/Settings/JcfRegistrySettings.pas | 5 ++ components/jcf2/Ui/Settings/frFiles.lfm | 57 +++++++++++-------- components/jcf2/Ui/Settings/frFiles.pas | 16 +++++- 6 files changed, 80 insertions(+), 30 deletions(-) diff --git a/components/jcf2/IdePlugin/lazarus/jcfidemain.pas b/components/jcf2/IdePlugin/lazarus/jcfidemain.pas index ba1325404c..36e4bfa186 100644 --- a/components/jcf2/IdePlugin/lazarus/jcfidemain.pas +++ b/components/jcf2/IdePlugin/lazarus/jcfidemain.pas @@ -43,6 +43,9 @@ uses EditorConverter, FileConverter, ConvertTypes, jcfuiconsts; type + + { TJcfIdeMain } + TJcfIdeMain = class(TObject) private fcEditorConverter: TEditorConverter; @@ -57,7 +60,7 @@ type procedure ClearToolMessages; procedure ConvertEditor(const pciEditor: TSourceEditorInterface); - + function CanFormat(const AMsg: String): Boolean; protected public @@ -81,7 +84,7 @@ uses { jcf } JcfStringUtils, { local } - fAbout, frFiles {, JcfRegistrySettings, fRegistrySettings}; + fAbout, frFiles, JcfRegistrySettings{, fRegistrySettings}; function FileIsAllowedType(const psFileName: string): boolean; @@ -112,6 +115,17 @@ begin inherited; end; +function TJcfIdeMain.CanFormat(const AMsg: String): Boolean; +var + JCFRegistrySettings: TJCFRegistrySettings; +begin + Result := True; + JCFRegistrySettings := GetRegSettings; + if JCFRegistrySettings.ConfirmFormat then + if MessageDlg(AMsg, mtConfirmation, [mbYes, mbNo], 0) <> mrYes then + Result := False +end; + procedure TJcfIdeMain.DoFormatCurrentIDEWindow(Sender: TObject); var lsMsg: string; @@ -122,8 +136,8 @@ begin lsMsg := Format(lisJEDICodeFormatOfStartFormatting, [SourceEditorManagerIntf .ActiveEditor.FileName + NativeLineBreak]); - if MessageDlg(lsMsg, mtConfirmation, [mbYes, mbNo], 0) = mrYes then - ConvertEditor(SourceEditorManagerIntf.ActiveEditor); + if CanFormat(lsMsg) then + ConvertEditor(SourceEditorManagerIntf.ActiveEditor) end; end; @@ -151,7 +165,8 @@ begin lsMsg := Format(lisJEDICodeFormatOfAreYouSureThatYouWantToFormatAllFi, [ lazProject.MainFile.FileName + NativeLineBreak, IntToStr(lazProject. FileCount)]); - if MessageDlg(lsMsg, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin + if CanFormat(lsMsg) then + begin ClearToolMessages; { loop through all modules in the project } for liLoop := 0 to lazProject.FileCount - 1 do @@ -172,6 +187,9 @@ begin if (SourceEditorManagerIntf = nil) then Exit; + if not CanFormat(lisJEDICodeFormatAllOpenWindow) then + Exit; + ClearToolMessages; fcEditorConverter.BeforeConvert; diff --git a/components/jcf2/IdePlugin/lazarus/jcfuiconsts.pas b/components/jcf2/IdePlugin/lazarus/jcfuiconsts.pas index 163fc11d80..2396d3adf4 100644 --- a/components/jcf2/IdePlugin/lazarus/jcfuiconsts.pas +++ b/components/jcf2/IdePlugin/lazarus/jcfuiconsts.pas @@ -14,6 +14,7 @@ resourcestring lisNoSettingsFound = 'No settings found'; //Format File settings tab + lisFrFileConfirmFormat = 'Show confirmation dialog before format'; lisFrFilesFileIsWritable = 'File is writable'; lisFrFilesFormatFileIs = 'Format file is %s'; lisFrFilesFileNotFound = 'File not found'; @@ -313,6 +314,7 @@ resourcestring lisJEDICodeFormatOfStartFormatting = 'JEDI Code Format of %sStart formatting?'; lisJEDICodeFormatOfAreYouSureThatYouWantToFormatAllFi = 'JEDI Code Format of' +' %sAre you sure that you want to format all %s files in the project?'; + lisJEDICodeFormatAllOpenWindow = 'JEDI Code Format of all open windows?'; implementation diff --git a/components/jcf2/ReadWrite/ConvertTypes.pas b/components/jcf2/ReadWrite/ConvertTypes.pas index 6b590bac47..6670738ab3 100644 --- a/components/jcf2/ReadWrite/ConvertTypes.pas +++ b/components/jcf2/ReadWrite/ConvertTypes.pas @@ -58,7 +58,7 @@ type TShowParseTreeOption = (eShowAlways, eShowOnError, eShowNever); const - OLD_REG_ROOT_KEY = '\Software\Jedi\JediCodeFormat'; + OLD_REG_ROOT_KEY = 'Software\Jedi\JediCodeFormat'; {$IFDEF FPC} REG_ROOT_KEY = OLD_REG_ROOT_KEY; {$ENDIF} {$IFDEF DELPHI1} REG_ROOT_KEY = '\Software\Borland\Delphi\1.0\Jedi\JCF'; {$ENDIF} {$IFDEF DELPHI2} REG_ROOT_KEY = '\Software\Borland\Delphi\2.0\Jedi\JCF'; {$ENDIF} diff --git a/components/jcf2/Settings/JcfRegistrySettings.pas b/components/jcf2/Settings/JcfRegistrySettings.pas index 9ae75d2186..388124c292 100644 --- a/components/jcf2/Settings/JcfRegistrySettings.pas +++ b/components/jcf2/Settings/JcfRegistrySettings.pas @@ -96,6 +96,7 @@ type fbEditorIntegration: boolean; fbFormatBeforeSave: boolean; fbFormatAfterLoad: boolean; + fbConfirmFormat: boolean; procedure ReadMRUFiles; procedure WriteMRUFiles; @@ -180,6 +181,7 @@ type Write fbEditorIntegration; property FormatBeforeSave: boolean Read fbFormatBeforeSave Write fbFormatBeforeSave; property FormatAfterLoad: boolean Read fbFormatAfterLoad Write fbFormatAfterLoad; + property ConfirmFormat: boolean Read fbConfirmFormat Write fbConfirmFormat; end; function GetRegSettings: TJCFRegistrySettings; @@ -228,6 +230,7 @@ const REG_EDITOR_INTEGRATION = 'EditorIntegration'; REG_FORMAT_BEFORE_SAVE = 'FormatBeforeSave'; REG_FORMAT_AFTER_LOAD = 'FormatAfterLoad'; + REG_CONFIRM_FORMAT = 'ConfirmFormat'; { file-based settings, ie @@ -435,6 +438,7 @@ begin fbEditorIntegration := fcReg.ReadBool(REG_IDE_SECTION, REG_EDITOR_INTEGRATION, False); fbFormatBeforeSave := fcReg.ReadBool(REG_IDE_SECTION, REG_FORMAT_BEFORE_SAVE, False); fbFormatAfterLoad := fcReg.ReadBool(REG_IDE_SECTION, REG_FORMAT_AFTER_LOAD, False); + fbConfirmFormat := fcReg.ReadBool(REG_IDE_SECTION, REG_CONFIRM_FORMAT, True); fbHasRead := True; end; @@ -484,6 +488,7 @@ begin fcReg.WriteBool(REG_IDE_SECTION, REG_EDITOR_INTEGRATION, fbEditorIntegration); fcReg.WriteBool(REG_IDE_SECTION, REG_FORMAT_BEFORE_SAVE, fbFormatBeforeSave); fcReg.WriteBool(REG_IDE_SECTION, REG_FORMAT_AFTER_LOAD, fbFormatAfterLoad); + fcReg.WriteBool(REG_IDE_SECTION, REG_CONFIRM_FORMAT, fbConfirmFormat); end; function TJCFRegistrySettings.CanClearMRU: boolean; diff --git a/components/jcf2/Ui/Settings/frFiles.lfm b/components/jcf2/Ui/Settings/frFiles.lfm index 85a51f2262..f20b05b9be 100644 --- a/components/jcf2/Ui/Settings/frFiles.lfm +++ b/components/jcf2/Ui/Settings/frFiles.lfm @@ -1,56 +1,67 @@ -inherited fFiles: TfFiles +object fFiles: TfFiles + Left = 0 Height = 281 + Top = 0 Width = 338 ClientHeight = 281 ClientWidth = 338 OnResize = FrameResize + TabOrder = 0 DesignLeft = 597 DesignTop = 402 - object lblStatus: TLabel[0] + object lblStatus: TLabel Left = 8 - Height = 14 - Top = 42 - Width = 42 + Height = 15 + Top = 56 + Width = 45 Caption = 'lblStatus' ParentColor = False end - object lblDate: TLabel[1] + object lblDate: TLabel Left = 8 - Height = 14 - Top = 64 - Width = 34 + Height = 15 + Top = 78 + Width = 37 Caption = 'lblDate' ParentColor = False end - object lblVersion: TLabel[2] + object lblVersion: TLabel Left = 8 - Height = 14 - Top = 88 - Width = 46 + Height = 15 + Top = 102 + Width = 51 Caption = 'lblVersion' ParentColor = False end - object lblDescription: TLabel[3] + object lblDescription: TLabel Left = 8 - Height = 14 - Top = 114 - Width = 58 + Height = 15 + Top = 128 + Width = 63 Caption = 'Description:' ParentColor = False end - object lblFormatFileName: TLabel[4] + object lblFormatFileName: TLabel Left = 8 - Height = 14 - Top = 8 - Width = 88 + Height = 15 + Top = 22 + Width = 101 Caption = 'lblFormatFileName' ParentColor = False end - object mDescription: TMemo[5] + object mDescription: TMemo Left = 8 Height = 89 - Top = 134 + Top = 148 Width = 301 TabOrder = 0 end + object cbConfirmFormat: TCheckBox + Left = 8 + Height = 19 + Top = 2 + Width = 233 + Caption = 'Show confirmation dialog before format' + TabOrder = 1 + end end diff --git a/components/jcf2/Ui/Settings/frFiles.pas b/components/jcf2/Ui/Settings/frFiles.pas index 48d614e35f..d769feec2b 100644 --- a/components/jcf2/Ui/Settings/frFiles.pas +++ b/components/jcf2/Ui/Settings/frFiles.pas @@ -33,13 +33,14 @@ uses { delphi } SysUtils, Classes, Controls, Forms, StdCtrls, Graphics, { lazarus } - IDEOptionsIntf; + IDEOptionsIntf, dialogs; type { TfFiles } TfFiles = class(TAbstractIDEOptionsEditor) + cbConfirmFormat: TCheckBox; lblStatus: TLabel; lblDate: TLabel; lblVersion: TLabel; @@ -69,6 +70,10 @@ var begin { from the registry, about the file } lcSet := GetRegSettings; + + cbConfirmFormat.Caption := lisFrFileConfirmFormat; + cbConfirmFormat.Checked := lcSet.ConfirmFormat; + lblFormatFileName.Caption := Format(lisFrFilesFormatFileIs, [lcSet.FormatConfigFileName]); //lblFormatFileName.Caption := PathCompactPath(lblFormatFileName.Canvas.Handle, 'Format file is ' + lcSet.FormatConfigFileName, 450, cpCenter); @@ -105,8 +110,14 @@ begin end; procedure TfFiles.WriteSettings(AOptions: TAbstractIDEOptions); +var + lcSet: TJCFRegistrySettings; begin FormatSettings.Description := mDescription.Text; + + lcSet := GetRegSettings; + lcSet.ConfirmFormat := cbConfirmFormat.Checked; + lcSet.WriteAll; end; procedure TfFiles.FrameResize(Sender: TObject); @@ -114,9 +125,12 @@ const SPACING = 8; begin inherited; + cbConfirmFormat.Left := SPACING; + cbConfirmFormat.Top := 2; lblFormatFileName.Left := SPACING; lblFormatFileName.Width := ClientWidth - (lblFormatFileName.Left + SPACING); + lblFormatFileName.Top := cbConfirmFormat.Top + cbConfirmFormat.Height + SPACING; // file name is varaible height due to wrap. Rest go below lblStatus.Left := SPACING;