From: Thomas M. <tw...@us...> - 2006-05-27 14:38:51
|
Update of /cvsroot/gexperts/gexperts/unstable/Src/Formatter In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv24751/unstable/Src/Formatter Modified Files: GX_CodeFormatterConfig.dfm GX_Formatter.pas Added Files: GX_eCodeFormatter.pas Log Message: * now also available as editor expert Index: GX_Formatter.pas =================================================================== RCS file: /cvsroot/gexperts/gexperts/unstable/Src/Formatter/GX_Formatter.pas,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- GX_Formatter.pas 1 May 2006 12:12:41 -0000 1.23 +++ GX_Formatter.pas 27 May 2006 14:38:40 -0000 1.24 @@ -6,37 +6,50 @@ interface -uses - SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ToolsApi, - GX_Experts, GX_CodeFormatterGXConfigWrapper; - implementation uses -{$IFOPT D+}GX_DbugIntf, {$ENDIF} - Registry, Menus, - GX_GExperts, GX_ConfigurationInfo, GX_OtaUtils, - GX_CodeFormatterTypes, GX_CodeFormatterConfig, GX_CodeFormatterEngine, - GX_CodeFormatterBookmarks, GX_CodeFormatterBreakpoints, - GX_CodeFormatterDefaultSettings, GX_CodeFormatterConfigHandler, GX_CodeFormatterDone, - GX_GenericUtils, GX_CodeFormatterSettings, GX_CodeFormatterSaveList; +{$IFOPT D+}GX_DbugIntf, +{$ENDIF} + SysUtils, + Classes, + Dialogs, + Menus, + ToolsApi, + GX_OtaUtils, + GX_GenericUtils, + GX_Experts, + GX_GExperts, + GX_ConfigurationInfo, + GX_CodeFormatterGXConfigWrapper, + GX_CodeFormatterTypes, + GX_CodeFormatterConfig, + GX_CodeFormatterEngine, + GX_CodeFormatterBookmarks, + GX_CodeFormatterBreakpoints, + GX_CodeFormatterDefaultSettings, + GX_CodeFormatterConfigHandler, + GX_CodeFormatterDone, + GX_CodeFormatterSettings, + GX_CodeFormatterSaveList; type TCodeFormatterExpert = class(TGX_Expert) private FFormatter: TCodeFormatterEngine; procedure ShowDoneDialog(out ShowDone: Boolean); + protected + procedure InternalLoadSettings(Settings: TGExpertsSettings); override; + procedure InternalSaveSettings(Settings: TGExpertsSettings); override; public constructor Create; override; destructor Destroy; override; + procedure Click(Sender: TObject); override; + procedure Configure; override; function GetActionCaption: string; override; class function GetName: string; override; function HasConfigOptions: Boolean; override; function HasMenuItem: Boolean; override; - procedure Configure; override; - procedure InternalLoadSettings(Settings: TGExpertsSettings); override; - procedure InternalSaveSettings(Settings: TGExpertsSettings); override; - procedure Click(Sender: TObject); override; end; { TCodeFormatterExpert } @@ -79,7 +92,7 @@ FirstLine := FullText[0]; if SameText(Copy(FirstLine, 1, 20), '{GXFormatter.config=') then begin - FirstLine := Trim(Copy(FirstLine, 21, Length(FirstLine)-21)); + FirstLine := Trim(Copy(FirstLine, 21, Length(FirstLine) - 21)); TempSettings := TCodeFormatterSettings.Create; if TCodeFormatterConfigHandler.GetDefaultConfig(FirstLine, TempSettings) then begin OrigSettings := FFormatter.Settings.Settings; @@ -105,11 +118,10 @@ finally FreeAndNil(FullText); - if Assigned(TempSettings) then - begin - FreeAndNil(TempSettings); - FFormatter.Settings.Settings := OrigSettings; - end; + if Assigned(TempSettings) then begin + FreeAndNil(TempSettings); + FFormatter.Settings.Settings := OrigSettings; + end; end; end; --- NEW FILE: GX_eCodeFormatter.pas --- unit GX_eCodeFormatter; {$I GX_CondDefine.inc} interface implementation uses {$IFOPT D+}GX_DbugIntf, {$ENDIF} SysUtils, Classes, Dialogs, Menus, ToolsAPI, GX_OtaUtils, GX_GenericUtils, GX_EditorExpert, GX_ConfigurationInfo, GX_CodeFormatterGXConfigWrapper, GX_CodeFormatterTypes, GX_CodeFormatterConfig, GX_CodeFormatterEngine, GX_CodeFormatterBookmarks, GX_CodeFormatterBreakpoints, GX_CodeFormatterDefaultSettings, GX_CodeFormatterConfigHandler, GX_CodeFormatterDone, GX_CodeFormatterSettings, GX_CodeFormatterSaveList; type TeCodeFormatterExpert = class(TEditorExpert) private FFormatter: TCodeFormatterEngine; procedure ShowDoneDialog(out ShowDone: Boolean); protected function GetDisplayName: string; override; class function GetName: string; override; function GetBitmapFileName: string; override; procedure InternalLoadSettings(Settings: TGExpertsSettings); override; procedure InternalSaveSettings(Settings: TGExpertsSettings); override; public constructor Create; override; destructor Destroy; override; procedure Configure; override; procedure Execute(Sender: TObject); override; function HasConfigOptions: Boolean; override; end; { TeCodeFormatterExpert } procedure TeCodeFormatterExpert.Configure; begin TfmCodeFormatterConfig.Execute(FFormatter.Settings); end; constructor TeCodeFormatterExpert.Create; var Settings: TCodeFormatterEngineSettings; begin inherited Create; Settings := BorlandDefaults; FFormatter := TCodeFormatterEngine.Create; FFormatter.Settings.Settings := Settings; ShortCut := Menus.ShortCut(Word('F'), [ssCtrl, ssAlt]); end; destructor TeCodeFormatterExpert.Destroy; begin FreeAndNil(FFormatter); inherited; end; procedure TeCodeFormatterExpert.Execute(Sender: TObject); resourcestring str_NoEditor = 'No source editor'; str_UnsupportedFileTypeS = 'Unsupported file type: %s'; str_UnableToGetContentsS = 'Unable to get contents of %s'; var SourceEditor: IOTASourceEditor; FileName: string; FullText: TStringList; ShowDone: Boolean; Bookmarks: ICodeFormatterSaveList; Breakpoints: ICodeFormatterSaveList; WasBinary: Boolean; i: integer; TempSettings: TCodeFormatterSettings; OrigSettings: TCodeFormatterEngineSettings; FirstLine: string; begin SourceEditor := GxOtaGetCurrentSourceEditor; if not Assigned(SourceEditor) then raise ECodeFormatter.Create(str_NoEditor); FileName := SourceEditor.FileName; if not (IsPascalSourceFile(FileName) or IsDelphiPackage(FileName)) then raise ECodeFormatter.CreateFmt(str_UnsupportedFileTypeS, [ExtractFileName(FileName)]); TempSettings := nil; FullText := TStringList.Create; try if not GxOtaGetFileAsText(Filename, FullText, WasBinary) then raise ECodeFormatter.CreateFmt(str_UnableToGetContentsS, [FileName]); if FullText.Count = 0 then exit; Bookmarks := TBookmarkHandler.Create; Breakpoints := TBreakpointHandler.Create; FirstLine := FullText[0]; if SameText(Copy(FirstLine, 1, 20), '{GXFormatter.config=') then begin FirstLine := Trim(Copy(FirstLine, 21, Length(FirstLine) - 21)); TempSettings := TCodeFormatterSettings.Create; if TCodeFormatterConfigHandler.GetDefaultConfig(FirstLine, TempSettings) then begin OrigSettings := FFormatter.Settings.Settings; FFormatter.Settings.Settings := TempSettings.Settings; end else FreeAndNil(TempSettings); end; FFormatter.Sourcecode := FullText.Text; if FFormatter.Execute then begin if FullText.Text <> FFormatter.Sourcecode then begin GxOtaReplaceEditorText(SourceEditor, FFormatter.Sourcecode); for i := 0 to SourceEditor.EditViewCount - 1 do SourceEditor.EditViews[i].Paint; end; if FFormatter.Settings.ShowDoneDialog then begin ShowDoneDialog(ShowDone); if Showdone <> FFormatter.Settings.ShowDoneDialog then begin FFormatter.Settings.ShowDoneDialog := ShowDone; end; end; end; finally FreeAndNil(FullText); if Assigned(TempSettings) then begin FreeAndNil(TempSettings); FFormatter.Settings.Settings := OrigSettings; end; end; end; function TeCodeFormatterExpert.GetBitmapFileName: string; begin Result := ''; end; function TeCodeFormatterExpert.GetDisplayName: string; begin Result := 'Code Formatter'; end; class function TeCodeFormatterExpert.GetName: string; begin Result := self.ClassName; end; function TeCodeFormatterExpert.HasConfigOptions: Boolean; begin Result := True; end; procedure TeCodeFormatterExpert.InternalLoadSettings(Settings: TGExpertsSettings); var Reader: IConfigReader; begin inherited; Reader := TGxConfigWrapper.Create(Settings, ConfigurationKey); TCodeFormatterConfigHandler.ReadSettings(Reader, FFormatter.Settings); end; procedure TeCodeFormatterExpert.InternalSaveSettings(Settings: TGExpertsSettings); var Writer: IConfigWriter; begin inherited; Writer := TGxConfigWrapper.Create(Settings, ConfigurationKey); TCodeFormatterConfigHandler.WriteSettings(Writer, FFormatter.Settings); end; procedure TeCodeFormatterExpert.ShowDoneDialog(out ShowDone: Boolean); var DoneForm: TfmCodeFormatterDone; begin DoneForm := TfmCodeFormatterDone.Create(nil); try DoneForm.ShowModal; ShowDone := not DoneForm.chk_DontShowAgain.Checked; finally DoneForm.Free; end; end; initialization RegisterEditorExpert(TeCodeFormatterExpert); end. Index: GX_CodeFormatterConfig.dfm =================================================================== RCS file: /cvsroot/gexperts/gexperts/unstable/Src/Formatter/GX_CodeFormatterConfig.dfm,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- GX_CodeFormatterConfig.dfm 19 Feb 2006 21:26:49 -0000 1.6 +++ GX_CodeFormatterConfig.dfm 27 May 2006 14:38:40 -0000 1.7 @@ -1,8 +1,6 @@ object fmCodeFormatterConfig: TfmCodeFormatterConfig Left = 339 Top = 175 - Width = 486 - Height = 450 HelpContext = 100 Caption = 'Delphi Code Formatter Configuration' ClientHeight = 426 @@ -27,6 +25,10 @@ TabOrder = 0 object ts_Indent: TTabSheet Caption = 'Indent' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 object Label1: TLabel Left = 8 Top = 22 @@ -118,6 +120,10 @@ end object ts_Spacing: TTabSheet Caption = 'Spacing' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 DesignSize = ( 470 357) @@ -142,6 +148,10 @@ end object ts_LineBreaks: TTabSheet Caption = 'Line Breaks' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 object Label4: TLabel Left = 240 Top = 104 @@ -322,6 +332,10 @@ end object ts_Capitalization: TTabSheet Caption = 'Capitalization' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 object Label7: TLabel Left = 8 Top = 74 @@ -422,6 +436,10 @@ end object ts_Align: TTabSheet Caption = 'Align' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 object Label16: TLabel Left = 12 Top = 35 @@ -487,6 +505,10 @@ end object ts_Misc: TTabSheet Caption = 'Misc.' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 object Label8: TLabel Left = 8 Top = 8 @@ -538,6 +560,10 @@ ImageIndex = 6 OnResize = ts_PreviewResize OnShow = ts_PreviewShow + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 0 + ExplicitHeight = 0 DesignSize = ( 470 357) @@ -648,7 +674,12 @@ Top = 8 Width = 75 Height = 25 + Hint = + 'You can add {GXFormatter.config=<name>} as the first line to a u' + + 'nit to force a configuration for that particular unit.' Caption = 'Tools >' + ParentShowHint = False + ShowHint = True TabOrder = 1 OnClick = b_ToolsClick end |