From c957a0099d2b5d0d70508f5efe2bbb7d2a87d4ac Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Tue, 14 Jun 2016 10:16:22 +0200 Subject: [PATCH] refact widgets that replace the free project with projutils functions --- lazproj/coedit.lpi | 2 +- lazproj/coedit.lpr | 2 +- src/ce_dubproject.pas | 2 + src/ce_lcldragdrop.pas | 30 +++----- src/ce_libmaneditor.pas | 22 +++--- src/ce_main.lfm | 72 +++++++++++++++++++ src/ce_main.pas | 1 + src/ce_miniexplorer.pas | 30 +++----- src/ce_projgroup.pas | 11 ++- ...{ce_anyprojloader.pas => ce_projutils.pas} | 35 ++++++++- 10 files changed, 147 insertions(+), 60 deletions(-) rename src/{ce_anyprojloader.pas => ce_projutils.pas} (63%) diff --git a/lazproj/coedit.lpi b/lazproj/coedit.lpi index 3b341556..80d0cea2 100644 --- a/lazproj/coedit.lpi +++ b/lazproj/coedit.lpi @@ -397,7 +397,7 @@ - + diff --git a/lazproj/coedit.lpr b/lazproj/coedit.lpr index 58d59c90..37097230 100644 --- a/lazproj/coedit.lpr +++ b/lazproj/coedit.lpr @@ -11,7 +11,7 @@ uses ce_main, ce_writableComponent, ce_staticmacro, ce_inspectors, ce_editoroptions, ce_dockoptions, ce_shortcutseditor, ce_mru, ce_processes, ce_dubproject, ce_dialogs, ce_dubprojeditor, ce_controls, ce_dfmt, - ce_lcldragdrop, ce_stringrange, ce_dlangmaps, ce_projgroup, ce_anyprojloader; + ce_lcldragdrop, ce_stringrange, ce_dlangmaps, ce_projgroup, ce_projutils; {$R *.res} diff --git a/src/ce_dubproject.pas b/src/ce_dubproject.pas index 1ab815e3..31761563 100644 --- a/src/ce_dubproject.pas +++ b/src/ce_dubproject.pas @@ -13,6 +13,7 @@ type TCEDubProject = class(TComponent, ICECommonProject) private + fProjectName: string; fInGroup: boolean; fDubProc: TCEProcess; fPreCompilePath: string; @@ -88,6 +89,7 @@ type function targetUpToDate: boolean; // property json: TJSONObject read fJSON; + property packageName: string read fPackageName; end; // these 9 built types always exist diff --git a/src/ce_lcldragdrop.pas b/src/ce_lcldragdrop.pas index 30e5a2ce..5545566c 100644 --- a/src/ce_lcldragdrop.pas +++ b/src/ce_lcldragdrop.pas @@ -7,7 +7,7 @@ interface uses Classes, SysUtils, Controls, ComCtrls, ce_common, ce_nativeproject, ce_dubproject, ce_interfaces, - ce_dialogs; + ce_dialogs, ce_projutils; type @@ -126,13 +126,14 @@ end; procedure TDDHandler.DragDrop(Sender, Source: TObject; X, Y: Integer); var fname: string; - proj: boolean = false; + fmt: TCEProjectFileFormat; begin if Source.isNil then exit; fname := getFilename(Source); if not fname.fileExists then exit; - if isValidNativeProject(fname) then + fmt := projectFormat(fname); + if fmt in [pffCe, pffDub] then begin if assigned(fFreeProj) then begin @@ -140,24 +141,13 @@ begin exit; fFreeProj.getProject.Free; end; - TCENativeProject.create(nil); - proj := true; + if fmt = pffCe then + TCENativeProject.create(nil) + else + TCEDubProject.create(nil); + fProj.loadFromFile(fname); end - else if isValidDubProject(fname) then - begin - if assigned(fFreeProj) and not fFreeProj.inGroup then - begin - if fProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then - exit; - fFreeProj.getProject.Free; - end; - TCEDubProject.create(nil); - proj := true; - end; - if assigned(fProj) and proj then - fProj.loadFromFile(fname) - else - getMultiDocHandler.openDocument(fname); + else getMultiDocHandler.openDocument(fname); end; initialization diff --git a/src/ce_libmaneditor.pas b/src/ce_libmaneditor.pas index f6eb0b66..94356939 100644 --- a/src/ce_libmaneditor.pas +++ b/src/ce_libmaneditor.pas @@ -9,7 +9,7 @@ uses Menus, ComCtrls, Buttons, LazFileUtils, strutils, fphttpclient, StdCtrls, xfpjson, ce_widget, ce_interfaces, ce_nativeproject, ce_dmdwrap, ce_common, ce_dialogs, ce_sharedres, process, ce_dubproject, ce_observer, ce_dlang, ce_stringrange, - ce_libman; + ce_libman, ce_projutils; type @@ -509,12 +509,14 @@ end; procedure TCELibManEditorWidget.btnOpenProjClick(Sender: TObject); var fname: string; + fmt: TCEProjectFileFormat; begin if List.Selected.isNil then exit; fname := List.Selected.SubItems[2]; if not fname.fileExists then exit; // - if isValidNativeProject(fname) then + fmt := projectFormat(fname); + if fmt in [pffCe, pffDub] then begin if assigned(fFreeProj) then begin @@ -522,18 +524,10 @@ begin exit; fFreeProj.getProject.Free; end; - TCENativeProject.create(nil); - fProj.loadFromFile(fname); - end - else if isValidDubProject(fname) then - begin - if assigned(fFreeProj) then - begin - if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then - exit; - fFreeProj.getProject.Free; - end; - TCEDubProject.create(nil); + if fmt = pffCe then + TCENativeProject.create(nil) + else + TCEDubProject.create(nil); fProj.loadFromFile(fname); end else dlgOkInfo('the project file for this library seems to be invalid'); diff --git a/src/ce_main.lfm b/src/ce_main.lfm index 8565d62c..da9450ba 100644 --- a/src/ce_main.lfm +++ b/src/ce_main.lfm @@ -3712,6 +3712,42 @@ object CEMainForm: TCEMainForm end object MenuItem88: TMenuItem Action = actProjGroupCompile + Bitmap.Data = { + 36040000424D3604000000000000360000002800000010000000100000000100 + 2000000000000004000064000000640000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000000 + 001F000000080000003300000033000000040000002400000000000000000000 + 0000000000000000000000000000000000330000003300000033000000332D73 + BAAF1B3D60523F93D4FF3F93D4FF102438413578BAC300000024000000000000 + 0000000000230000002F00000000B88445FFC89451FFCE934AFF6D8192FF40A9 + EAFF429EDDFF52D0F8FF52D0F8FF439EDCFF48AAE2FF3980C8B6000000000000 + 0023AA7A3EBFB68243ED00000033B58142FFF5C378FFFCC371FFAD7E49FF3B9E + E3FF4ECFFBFF41B0EDFF42B1EDFF50CFFAFF439EDCFF1B3D5F5200000000AA7A + 3FBED2A76FFFD7A561FFB88241FFD39F58FFEDB96BFFF7B962FF288DE3FF4CCF + FCFF40B0EDFFC39F7BFF987653CB42B1EEFF52D0F9FF3F92D5FF00000000B984 + 43E9DDBB8CFFEEC486FFE8B466FFF1CC96FFF7DCB5FFFFDEADFF288CDFFF4CCE + FBFF3FAFEDFFFAB66DFFC7751FCE41B1EFFF52D0F9FF3F92D5FF000000330000 + 0033B78242FFE4B163FFEBC68EFFEACFA9FFD1A774FFD9A970FFCCBBA4FF399C + E1FF4CCEFBFF3FB0EEFF40B1EFFF4FCFFCFF429EDCFF16324E31B98545FFB782 + 42FFC8934EFFDFAB5EFFE4C494FFB68245DAB8813F3CBE823B2561809CFF37A8 + EFFF399DE3FF4CCFFDFF4AC7F8FF3D9EE1FF45AAE4FF3982CB9FC38F4EFFE2B5 + 72FFDEB06AFFDBA658FFC59555FF926935300000000000000000AA7333436A83 + 99FFCD9F5FFF298DE2FF2B8FE1FFB48B5AFF3081D29100000000C5995FFFF1DC + BBFFECD2ACFFD6A152FFC18C49FF70502A620000000C0000000C704F2861C88D + 44FFDFA24CFFEACEA6FFF1D7B2FFD79A51FF0000000000000000B98442FFB680 + 3EFFCEA673FFDBAE6EFFCB954BFFB88344FF6E4F2A616E4F2A61B88344FFCD97 + 4AFFDCAE6DFFD0A772FFB9813CFFBE843FFF0000000000000000000000000000 + 002FBA8547FFCE9949FFDAB276FFC9944BFFBE8943FFBE8943FFC9944BFFDAB2 + 76FFCE9949FFBA8546FF0000002F00000000000000000000000000000000B782 + 42ECD3AE7CFFE7CBA4FFEAD4B2FFE8D0ADFFCF9D56FFCF9D56FFE8D0ADFFEAD4 + B2FFE7CBA4FFD3AE7CFFB78242EC00000000000000000000000000000000B985 + 44AFCCA26CFFD4B080FFB98343FFCCA470FFC9984EFFC9984EFFCCA470FFB983 + 43FFD4B080FFCCA26CFFB98544AF000000000000000000000000000000000000 + 0000B98544AFB98443E900000000B78140FFE9D4B4FFE9D4B4FFB78140FF0000 + 0000B98443E9B98544AF00000000000000000000000000000000000000000000 + 0000000000000000000000000000BA8545FFB9843FFFB9843FFFBA8545FF0000 + 0000000000000000000000000000000000000000000000000000 + } end end object MenuItem8: TMenuItem @@ -4153,6 +4189,42 @@ object CEMainForm: TCEMainForm end object MenuItem89: TMenuItem Action = actProjGroupCompile + Bitmap.Data = { + 36040000424D3604000000000000360000002800000010000000100000000100 + 2000000000000004000064000000640000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000000 + 001F000000080000003300000033000000040000002400000000000000000000 + 0000000000000000000000000000000000330000003300000033000000332D73 + BAAF1B3D60523F93D4FF3F93D4FF102438413578BAC300000024000000000000 + 0000000000230000002F00000000B88445FFC89451FFCE934AFF6D8192FF40A9 + EAFF429EDDFF52D0F8FF52D0F8FF439EDCFF48AAE2FF3980C8B6000000000000 + 0023AA7A3EBFB68243ED00000033B58142FFF5C378FFFCC371FFAD7E49FF3B9E + E3FF4ECFFBFF41B0EDFF42B1EDFF50CFFAFF439EDCFF1B3D5F5200000000AA7A + 3FBED2A76FFFD7A561FFB88241FFD39F58FFEDB96BFFF7B962FF288DE3FF4CCF + FCFF40B0EDFFC39F7BFF987653CB42B1EEFF52D0F9FF3F92D5FF00000000B984 + 43E9DDBB8CFFEEC486FFE8B466FFF1CC96FFF7DCB5FFFFDEADFF288CDFFF4CCE + FBFF3FAFEDFFFAB66DFFC7751FCE41B1EFFF52D0F9FF3F92D5FF000000330000 + 0033B78242FFE4B163FFEBC68EFFEACFA9FFD1A774FFD9A970FFCCBBA4FF399C + E1FF4CCEFBFF3FB0EEFF40B1EFFF4FCFFCFF429EDCFF16324E31B98545FFB782 + 42FFC8934EFFDFAB5EFFE4C494FFB68245DAB8813F3CBE823B2561809CFF37A8 + EFFF399DE3FF4CCFFDFF4AC7F8FF3D9EE1FF45AAE4FF3982CB9FC38F4EFFE2B5 + 72FFDEB06AFFDBA658FFC59555FF926935300000000000000000AA7333436A83 + 99FFCD9F5FFF298DE2FF2B8FE1FFB48B5AFF3081D29100000000C5995FFFF1DC + BBFFECD2ACFFD6A152FFC18C49FF70502A620000000C0000000C704F2861C88D + 44FFDFA24CFFEACEA6FFF1D7B2FFD79A51FF0000000000000000B98442FFB680 + 3EFFCEA673FFDBAE6EFFCB954BFFB88344FF6E4F2A616E4F2A61B88344FFCD97 + 4AFFDCAE6DFFD0A772FFB9813CFFBE843FFF0000000000000000000000000000 + 002FBA8547FFCE9949FFDAB276FFC9944BFFBE8943FFBE8943FFC9944BFFDAB2 + 76FFCE9949FFBA8546FF0000002F00000000000000000000000000000000B782 + 42ECD3AE7CFFE7CBA4FFEAD4B2FFE8D0ADFFCF9D56FFCF9D56FFE8D0ADFFEAD4 + B2FFE7CBA4FFD3AE7CFFB78242EC00000000000000000000000000000000B985 + 44AFCCA26CFFD4B080FFB98343FFCCA470FFC9984EFFC9984EFFCCA470FFB983 + 43FFD4B080FFCCA26CFFB98544AF000000000000000000000000000000000000 + 0000B98544AFB98443E900000000B78140FFE9D4B4FFE9D4B4FFB78140FF0000 + 0000B98443E9B98544AF00000000000000000000000000000000000000000000 + 0000000000000000000000000000BA8545FFB9843FFFB9843FFFBA8545FF0000 + 0000000000000000000000000000000000000000000000000000 + } end object MenuItem90: TMenuItem Caption = '-' diff --git a/src/ce_main.pas b/src/ce_main.pas index 11d90b82..8df1d3bc 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -2904,6 +2904,7 @@ begin fMsgs.message('start compiling a project group...', nil, amcAll, amkInf); for i:= 0 to fProjectGroup.projectCount-1 do begin + //TODO-cprojectgroup: verify that compilation is not paralell since the projects use an async proc. fProjectGroup.getProject(i).activate; fProject.compile; end; diff --git a/src/ce_miniexplorer.pas b/src/ce_miniexplorer.pas index 1cb9ab12..18036d06 100644 --- a/src/ce_miniexplorer.pas +++ b/src/ce_miniexplorer.pas @@ -8,7 +8,7 @@ uses Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics, ExtCtrls, Menus, ComCtrls, Buttons, lcltype, strutils, ce_widget, ce_sharedres, ce_common, ce_interfaces, ce_observer, ce_writableComponent, ce_dubproject, - ce_nativeproject, EditBtn, ce_dialogs, ce_synmemo; + ce_nativeproject, EditBtn, ce_dialogs, ce_synmemo, ce_projutils; type @@ -465,7 +465,7 @@ end; procedure TCEMiniExplorerWidget.btnEditClick(Sender: TObject); var fname: string; - proj: boolean = false; + fmt: TCEProjectFileFormat; begin if lstFiles.Selected.isNil then exit; if lstFiles.Selected.Data.isNil then exit; @@ -474,7 +474,8 @@ begin {$IFNDEF WINDOWS} fname := fname[2..fname.length]; {$ENDIF} - if isValidNativeProject(fname) then + fmt := projectFormat(fname); + if fmt in [pffCe, pffDub] then begin if assigned(fFreeProj) then begin @@ -482,24 +483,13 @@ begin exit; fFreeProj.getProject.Free; end; - TCENativeProject.create(nil); - proj := true; + if fmt = pffCe then + TCENativeProject.create(nil) + else + TCEDubProject.create(nil); + fProj.loadFromFile(fname); end - else if isValidDubProject(fname) then - begin - if assigned(fFreeProj) then - begin - if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then - exit; - fFreeProj.getProject.Free; - end; - TCEDubProject.create(nil); - proj := true; - end; - if assigned(fProj) and proj then - fProj.loadFromFile(fname) - else - getMultiDocHandler.openDocument(fname); + else getMultiDocHandler.openDocument(fname); end; procedure TCEMiniExplorerWidget.lstFilesDblClick(Sender: TObject); diff --git a/src/ce_projgroup.pas b/src/ce_projgroup.pas index 82dab972..be89692e 100644 --- a/src/ce_projgroup.pas +++ b/src/ce_projgroup.pas @@ -7,7 +7,7 @@ uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, ExtCtrls, Menus, Buttons, dialogs, ComCtrls, StdCtrls, ce_widget, ce_common, ce_interfaces, ce_writableComponent, ce_observer, - ce_nativeproject, ce_dubproject, ce_anyprojloader, ce_sharedres; + ce_nativeproject, ce_dubproject, ce_projutils, ce_sharedres; type @@ -474,14 +474,19 @@ begin Data:= p; case p.project.getFormat of pfNative: Caption := p.fFilename.extractFileName; - pfDub: Caption := TCEDubProject(p.project.getProject).json.Strings['name']; + pfDub: Caption := TCEDubProject(p.project.getProject).packageName; end; SubItems.Add(typeStr[p.fProj.getFormat]); SubItems.Add(p.fProj.configurationName(p.fProj.getActiveConfigurationIndex)); end; end; if fFreeProj <> nil then - StaticText1.Caption:= 'Free standing: ' + shortenPath(fFreeProj.filename, 30) + begin + case fFreeProj.getFormat of + pfNative: StaticText1.Caption:= 'Free standing: ' + fFreeProj.filename.extractFileName; + pfDub: StaticText1.Caption:= 'Free standing: ' + TCEDubProject(fFreeProj.getProject).packageName; + end; + end else StaticText1.Caption:= 'No free standing project'; end; diff --git a/src/ce_anyprojloader.pas b/src/ce_projutils.pas similarity index 63% rename from src/ce_anyprojloader.pas rename to src/ce_projutils.pas index 23e9aebe..2ffae082 100644 --- a/src/ce_anyprojloader.pas +++ b/src/ce_projutils.pas @@ -1,4 +1,4 @@ -unit ce_anyprojloader; +unit ce_projutils; {$I ce_defines.inc} interface @@ -7,6 +7,9 @@ uses Classes, SysUtils, ce_nativeproject, ce_dubproject, ce_interfaces, ce_common, ce_observer; +type + TCEProjectFileFormat = (pffNone, pffCe, pffDub); + (** * Loads either a DUB or a CE project. If the filename is invalid or if it * doesn't points to a valid project, nil is returned, otherwise a project. @@ -15,8 +18,38 @@ uses *) function loadProject(const filename: string; discret: boolean): ICECommonProject; +(** + * Indicates wether a file is a project, either CE or DUB. + *) +function isProject(const filename: string): boolean; + +(** + * Indicates wether a file is a project, either CE or DUB. + *) +function projectFormat(const filename: string): TCEProjectFileFormat; + implementation +function isProject(const filename: string): boolean; +begin + if filename.extractFileExt = '.json' then + result := isValidDubProject(filename) + else + result := isValidNativeProject(filename); +end; + +function projectFormat(const filename: string): TCEProjectFileFormat; +begin + result := pffNone; + if filename.extractFileExt = '.json' then + begin + if isValidDubProject(filename) then + result := pffDub; + end + else + if isValidNativeProject(filename) then result := pffCe; +end; + function loadProject(const filename: string; discret: boolean): ICECommonProject; var isDubProject: boolean = false;