From 4ecdea86a6063d58625a786937f7b3449e9ed045 Mon Sep 17 00:00:00 2001 From: dodi Date: Thu, 8 Mar 2012 19:54:52 +0000 Subject: [PATCH] DocMgr: Added description editor. Conditional support for FCL packages git-svn-id: trunk@35831 - --- .gitattributes | 2 + examples/fpdocmanager/FPDocManager.lpi | 16 ++++-- examples/fpdocmanager/FPDocManager.lpr | 4 +- examples/fpdocmanager/fconfig.lfm | 10 ++-- examples/fpdocmanager/fconfig.pas | 4 ++ examples/fpdocmanager/feditor.lfm | 9 ++++ examples/fpdocmanager/feditor.pas | 70 ++++++++++++++++++++++++++ examples/fpdocmanager/fmain.lfm | 20 +++++--- examples/fpdocmanager/fmain.pas | 26 +++++++++- examples/fpdocmanager/umanager.pas | 39 +++++++++++++- 10 files changed, 181 insertions(+), 19 deletions(-) create mode 100644 examples/fpdocmanager/feditor.lfm create mode 100644 examples/fpdocmanager/feditor.pas diff --git a/.gitattributes b/.gitattributes index 1a70c4c296..d7e0607a27 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3773,6 +3773,8 @@ examples/fpdocmanager/docs/umakeskel.xml svneol=native#text/plain examples/fpdocmanager/docs/umanager.xml svneol=native#text/plain examples/fpdocmanager/fconfig.lfm svneol=native#text/plain examples/fpdocmanager/fconfig.pas svneol=native#text/pascal +examples/fpdocmanager/feditor.lfm svneol=native#text/plain +examples/fpdocmanager/feditor.pas svneol=native#text/pascal examples/fpdocmanager/flogview.lfm svneol=native#text/plain examples/fpdocmanager/flogview.pas svneol=native#text/pascal examples/fpdocmanager/fmain.lfm svneol=native#text/plain diff --git a/examples/fpdocmanager/FPDocManager.lpi b/examples/fpdocmanager/FPDocManager.lpi index fa0cb2ba95..11d1f7b9da 100644 --- a/examples/fpdocmanager/FPDocManager.lpi +++ b/examples/fpdocmanager/FPDocManager.lpi @@ -40,7 +40,7 @@ - + @@ -95,9 +95,18 @@ - + + + + + + + + + + @@ -108,7 +117,7 @@ - + @@ -122,6 +131,7 @@ + diff --git a/examples/fpdocmanager/FPDocManager.lpr b/examples/fpdocmanager/FPDocManager.lpr index 7301f4b7f2..3033aca65e 100644 --- a/examples/fpdocmanager/FPDocManager.lpr +++ b/examples/fpdocmanager/FPDocManager.lpr @@ -7,8 +7,8 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, umakeskel, fMain, fConfig, uManager, fLogView, - fUpdateView, ulpk, ConfigFile; + Forms, frmmain, umakeskel, fMain, fConfig, uManager, fLogView, + fUpdateView, ulpk, ConfigFile, feditor; {$R *.res} diff --git a/examples/fpdocmanager/fconfig.lfm b/examples/fpdocmanager/fconfig.lfm index f1c5bf87f5..5f1f4ae931 100644 --- a/examples/fpdocmanager/fconfig.lfm +++ b/examples/fpdocmanager/fconfig.lfm @@ -168,8 +168,8 @@ object CfgWizard: TCfgWizard end object MkLCL: TTabSheet Caption = 'LCL' - ClientHeight = 211 - ClientWidth = 309 + ClientHeight = 212 + ClientWidth = 307 OnShow = MkLCLShow object Label4: TLabel Left = 10 @@ -192,7 +192,7 @@ object CfgWizard: TCfgWizard Left = 100 Height = 23 Top = 66 - Width = 200 + Width = 198 Anchors = [akTop, akLeft, akRight] OnChange = edLazDirChange TabOrder = 1 @@ -266,7 +266,7 @@ object CfgWizard: TCfgWizard end object NoParse: TTabSheet Caption = 'NoParse' - ClientHeight = 211 + ClientHeight = 212 ClientWidth = 307 object Label7: TLabel Left = 10 @@ -289,7 +289,7 @@ object CfgWizard: TCfgWizard end object edNoParse: TMemo Left = 12 - Height = 122 + Height = 123 Top = 88 Width = 288 Anchors = [akTop, akLeft, akRight, akBottom] diff --git a/examples/fpdocmanager/fconfig.pas b/examples/fpdocmanager/fconfig.pas index 2a68761e52..80eb00639f 100644 --- a/examples/fpdocmanager/fconfig.pas +++ b/examples/fpdocmanager/fconfig.pas @@ -164,7 +164,11 @@ begin edLazDir.Text := Manager.LazarusDir; + {$IFDEF FCLadds} swFCLads.Checked := Manager.IsExtended('fcl') <> ''; + {$ELSE} + MkFCL.TabVisible := False; + {$ENDIF} swNoParse.Checked := Manager.ExcludeUnits; edNoParse.Lines.Assign(Manager.NoParseUnits); diff --git a/examples/fpdocmanager/feditor.lfm b/examples/fpdocmanager/feditor.lfm new file mode 100644 index 0000000000..c76ee6d597 --- /dev/null +++ b/examples/fpdocmanager/feditor.lfm @@ -0,0 +1,9 @@ +object ModuleEditor: TModuleEditor + Left = 758 + Height = 624 + Top = 140 + Width = 686 + Caption = 'ModuleEditor' + OnCreate = NewCreate + LCLVersion = '0.9.31' +end diff --git a/examples/fpdocmanager/feditor.pas b/examples/fpdocmanager/feditor.pas new file mode 100644 index 0000000000..b8946c949a --- /dev/null +++ b/examples/fpdocmanager/feditor.pas @@ -0,0 +1,70 @@ +unit fEditor; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, + FrmMain; + +type + + { TModuleEditor } + + TModuleEditor = class(TMainForm) + procedure NewCreate(Sender: TObject); + private + procedure BuildRecent(const AUnit: string); + public + constructor CreateFor(const AUnit: string; TheOwner: TComponent); + end; + +var + ModuleEditor: TModuleEditor; + +implementation + +uses + LazDEOpts, IniFiles; + +{$R *.lfm} + +{ TModuleEditor } + +procedure TModuleEditor.NewCreate(Sender: TObject); +begin +(* New OnCreate handler - do adjustments before calling the inherited handler. +*) +//set Recent to current unit + //what, how? + MainFormCreate(Sender); +end; + +procedure TModuleEditor.BuildRecent(const AUnit: string); +const + SecPrefs = 'Preferences'; +begin + With TInifile.Create(UTF8ToSys(GetoptionFileName)) do + try + EraseSection('Recent'); + WriteInteger('Recent','Count',1); + WriteString('Recent','File1',AUnit); + //for LoadOptions + WriteBool(SecPrefs, 'StartMaximized', False); + WriteBool(SecPrefs, 'ReopenLast', True); + UpdateFile; + Finally + Free; + end; +end; + +constructor TModuleEditor.CreateFor(const AUnit: string; TheOwner: TComponent); +begin + MainForm := Self; //referenced in editor units + BuildRecent(AUnit); //force loading of AUnit + Create(TheOwner); +end; + +end. + diff --git a/examples/fpdocmanager/fmain.lfm b/examples/fpdocmanager/fmain.lfm index 7a1aebbdb7..01a398cb8d 100644 --- a/examples/fpdocmanager/fmain.lfm +++ b/examples/fpdocmanager/fmain.lfm @@ -10,6 +10,7 @@ object Main: TMain Menu = MainMenu1 OnCreate = FormCreate OnResize = FormResize + ShowHint = True LCLVersion = '0.9.31' object lbPackages: TComboBox Left = 0 @@ -38,11 +39,13 @@ object Main: TMain object lbUnits: TListBox Left = 0 Height = 436 + Hint = 'Double click to edit the description file' Top = 0 Width = 100 Align = alLeft ItemHeight = 0 OnClick = lbUnitsClick + OnDblClick = lbUnitsDblClick TabOrder = 0 end object Panel1: TPanel @@ -68,6 +71,7 @@ object Main: TMain object swAll: TRadioButton Left = 10 Height = 19 + Hint = 'Action on all package units' Top = 10 Width = 32 Caption = 'all' @@ -78,6 +82,7 @@ object Main: TMain object swSingle: TRadioButton Left = 48 Height = 19 + Hint = 'Actions only on the selected unit' Top = 10 Width = 43 Caption = 'only' @@ -87,6 +92,7 @@ object Main: TMain object edUnit: TEdit Left = 96 Height = 23 + Hint = 'The selected unit' Top = 10 Width = 260 Anchors = [akTop, akLeft, akRight] @@ -96,6 +102,7 @@ object Main: TMain object buRefresh: TButton Left = 96 Height = 25 + Hint = 'Update descriptions from source files' Top = 40 Width = 75 Caption = 'Refresh' @@ -122,6 +129,7 @@ object Main: TMain object buTest: TButton Left = 9 Height = 25 + Hint = 'Syntax check of the description file' Top = 40 Width = 75 Caption = 'Test only' @@ -179,7 +187,7 @@ object Main: TMain TabOrder = 9 end end - object GroupBox2: TGroupBox + object gbAltDir: TGroupBox Left = 1 Height = 95 Top = 1 @@ -440,11 +448,11 @@ object Main: TMain end object ViewXML: TTabSheet Caption = 'Project' - ClientHeight = 315 + ClientHeight = 436 ClientWidth = 467 inline edXML: TSynEdit Left = 0 - Height = 315 + Height = 436 Top = 0 Width = 467 Align = alClient @@ -928,16 +936,16 @@ object Main: TMain end object ViewINI: TTabSheet Caption = 'INI' - ClientHeight = 375 + ClientHeight = 436 ClientWidth = 467 object edINI: TMemo Left = 0 - Height = 375 + Height = 436 Top = 0 Width = 467 Align = alClient Lines.Strings = ( - 'edINI' + '' ) ScrollBars = ssAutoBoth TabOrder = 0 diff --git a/examples/fpdocmanager/fmain.pas b/examples/fpdocmanager/fmain.pas index e7fd47a09a..ef4a2f2fb1 100644 --- a/examples/fpdocmanager/fmain.pas +++ b/examples/fpdocmanager/fmain.pas @@ -38,7 +38,7 @@ type edDefOut: TEdit; edUnit: TEdit; GroupBox1: TGroupBox; - GroupBox2: TGroupBox; + gbAltDir: TGroupBox; Label2: TLabel; Label3: TLabel; Label4: TLabel; @@ -93,6 +93,7 @@ type procedure lbBackendExit(Sender: TObject); procedure lbPackagesClick(Sender: TObject); procedure lbUnitsClick(Sender: TObject); + procedure lbUnitsDblClick(Sender: TObject); procedure mnConfigClick(Sender: TObject); procedure mnExitClick(Sender: TObject); procedure mnImportLpkClick(Sender: TObject); @@ -133,6 +134,7 @@ implementation uses fConfig, fLogView, fUpdateView, //dwlinear, + fEditor, dWriter; {$R *.lfm} @@ -145,6 +147,10 @@ var s: string; l: TStringList; begin +{$IFDEF FCLAdds} +{$ELSE} + gbAltDir.Visible := False; +{$ENDIF} Manager := TFPDocManager.Create(self); Manager.OnChange := @ProjectsChanged; if not Manager.LoadConfig(GetCurrentDir) then begin @@ -495,11 +501,15 @@ begin //load units... lbUnits.Items.BeginUpdate; lbUnits.Clear; +{$IFDEF old} for i := 0 to pkg.Units.Count - 1 do begin //fn := Manager.UnitName(pkg.Inputs, i); fn := pkg.Units.Names[i]; lbUnits.AddItem(fn, nil); end; +{$ELSE} + pkg.EnumUnits(lbUnits.Items); +{$ENDIF} lbUnits.Sorted := True; lbUnits.Items.EndUpdate; //remember selection @@ -551,6 +561,20 @@ begin ShowUpdate; end; +procedure TMain.lbUnitsDblClick(Sender: TObject); +var + u: string; +begin +//edit unit description in LazDE form +//setup unit + //CurUnit := lbUnits.Items[lbUnits.ItemIndex]; - already set + u := Manager.Package.DescrFileName(CurUnit); +//create form + ModuleEditor := TModuleEditor.CreateFor(u, self); +//show it + ModuleEditor.Show; +end; + procedure TMain.swSingleClick(Sender: TObject); begin edUnit.Enabled := swSingle.Checked; diff --git a/examples/fpdocmanager/umanager.pas b/examples/fpdocmanager/umanager.pas index 4976e1158f..96e94982e8 100644 --- a/examples/fpdocmanager/umanager.pas +++ b/examples/fpdocmanager/umanager.pas @@ -74,6 +74,7 @@ type FRequires: TStrings; FUnitPath: string; FUnits: TStrings; + function GetAltDir: string; procedure SetAllDirs(AValue: boolean); procedure SetAltDir(AValue: string); procedure SetCompOpts(AValue: string); @@ -99,6 +100,8 @@ type function CreateProject(APrj: TFPDocHelper; const AFile: string): boolean; virtual; //new package project function ImportProject(APrj: TFPDocHelper; APkg: TFPDocPackage; const AFile: string): boolean; procedure UpdateConfig; + procedure EnumUnits(AList: TStrings); virtual; + function DescrFileName(const AUnit: string): string; property Name: string read FName write SetName; property Loaded: boolean read FLoaded write SetLoaded; property ProjectFile: string read FProjectFile write SetProjectFile; //xml? @@ -110,7 +113,7 @@ type property ProjectDir: string read FProjectDir write SetProjectDir; property DescrDir: string read FDescrDir write SetDescrDir; property Descriptions: TStrings read FDescriptions write SetDescriptions; - property AltDir: string read FAltDir write SetAltDir; + property AltDir: string read GetAltDir write SetAltDir; property InputDir: string read FInputDir write SetInputDir; property SrcDirs: TStrings read FSrcDirs; property Units: TStrings read FUnits write SetUnits; @@ -439,6 +442,15 @@ begin FAllDirs:=AValue; end; +function TDocPackage.GetAltDir: string; +begin +{$IFDEF FCLadds} + Result := FAltDir; +{$ELSE} + Result := ''; +{$ENDIF} +end; + procedure TDocPackage.SetDescriptions(AValue: TStrings); (* Shall we allow for multiple descriptions? (general + OS specific!?) *) @@ -751,7 +763,7 @@ begin Config.WriteString(SecDoc, 'inputdir', InputDir); Config.WriteString(SecDoc, 'options', CompOpts); Config.WriteString(SecDoc, 'descrdir', DescrDir); - Config.WriteString(SecDoc, 'AltDir', AltDir); + Config.WriteString(SecDoc, 'AltDir', FAltDir); Config.WriteBool(SecDoc, 'AllDirs', AllDirs); Config.WriteString(SecDoc, 'requires', Requires.CommaText); //units @@ -763,6 +775,25 @@ begin Loaded := True; end; +procedure TDocPackage.EnumUnits(AList: TStrings); +var + i: integer; +begin +//override to add further units (from AltDir...) + for i := 0 to Units.Count - 1 do + AList.Add(Units.Names[i]); +end; + +function TDocPackage.DescrFileName(const AUnit: string): string; +begin +(* [ProjectDir +] DescrDir + AUnit + .xml +*) + Result := DescrDir; + if (Result = '') or (Result[1] = '.') then + Result := ProjectDir + Result; + Result := Result + DirectorySeparator + AUnit + '.xml'; +end; + function TDocPackage.IniFileName: string; begin Result := Manager.RootDir + Name + '.ini'; @@ -1163,11 +1194,15 @@ function TFPDocManager.IsExtended(const APkg: string): string; var pkg: TDocPackage; begin +{$IFDEF FCLadds} pkg := AddPackage(APkg); if pkg = nil then Result := '' else Result := pkg.AltDir; +{$ELSE} + Result := ''; +{$ENDIF} end; function TFPDocManager.ImportLpk(const AFile: string): TDocPackage;