JCF: Add an option to confirm the formatting of a unit. Patch from Balázs.

git-svn-id: trunk@55491 -
This commit is contained in:
juha 2017-07-12 16:50:23 +00:00
parent 26ce6005f3
commit 30df28348c
6 changed files with 80 additions and 30 deletions

View File

@ -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;

View File

@ -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

View File

@ -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}

View File

@ -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;

View File

@ -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

View File

@ -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;