Force a particular extension for dexed projects and dexed project groups, close #388

This commit is contained in:
Basile Burg 2019-01-02 18:48:52 +01:00
parent 2dd21f049f
commit f95927b5cf
17 changed files with 72 additions and 41 deletions

View File

@ -209,7 +209,7 @@ end;
function TCENativeProject.getFormat: TCEProjectFormat; function TCENativeProject.getFormat: TCEProjectFormat;
begin begin
exit(pfCE); exit(pfDEXED);
end; end;
function TCENativeProject.getProject: TObject; function TCENativeProject.getProject: TObject;
@ -271,6 +271,12 @@ begin
f := fname; f := fname;
if not FilenameIsAbsolute(f) then if not FilenameIsAbsolute(f) then
f := ExpandFileName(f); f := ExpandFileName(f);
if fname.extractFileExt <> '.dprj' then
begin
dlgOkInfo('project file extension automatically updated to "dprj"');
f := ChangeFileExt(fname, '.dprj');
RenameFile(fname, f);
end;
fbasePath := f.extractFilePath; fbasePath := f.extractFilePath;
inherited customLoadFromFile(f); inherited customLoadFromFile(f);
end; end;
@ -278,13 +284,15 @@ end;
procedure TCENativeProject.customSaveToFile(const fname: string); procedure TCENativeProject.customSaveToFile(const fname: string);
var var
oldAbs, newRel, oldBase: string; oldAbs, newRel, oldBase: string;
f: string;
i: NativeInt; i: NativeInt;
begin begin
beginUpdate; beginUpdate;
if fname <> fFilename then f := fname;
if f <> fFilename then
inGroup(false); inGroup(false);
oldBase := fBasePath; oldBase := fBasePath;
fBasePath := fname.extractFilePath; fBasePath := f.extractFilePath;
// //
for i:= 0 to fSrcs.Count-1 do for i:= 0 to fSrcs.Count-1 do
begin begin
@ -293,7 +301,8 @@ begin
fSrcs[i] := newRel; fSrcs[i] := newRel;
end; end;
endUpdate; endUpdate;
inherited customSaveToFile(fname); f := ChangeFileExt(f, '.dprj');
inherited customSaveToFile(f);
end; end;
procedure TCENativeProject.setLibAliases(value: TStringList); procedure TCENativeProject.setLibAliases(value: TStringList);

View File

@ -90,7 +90,6 @@ inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
end end
end end
inherited toolbar: TCEToolBar inherited toolbar: TCEToolBar
Height = 28
Width = 437 Width = 437
object btnSyncEdit: TCEToolButton[0] object btnSyncEdit: TCEToolButton[0]
Left = 85 Left = 85

View File

@ -98,7 +98,7 @@ procedure TCEProjectConfigurationWidget.projNew(project: ICECommonProject);
begin begin
fProj := nil; fProj := nil;
enabled := false; enabled := false;
if project.getFormat <> pfCE then if project.getFormat <> pfDEXED then
exit; exit;
enabled := true; enabled := true;
// //
@ -132,7 +132,7 @@ procedure TCEProjectConfigurationWidget.projFocused(project: ICECommonProject);
begin begin
fProj := nil; fProj := nil;
enabled := false; enabled := false;
if project.getFormat <> pfCE then if project.getFormat <> pfDEXED then
exit; exit;
enabled := true; enabled := true;
// //

View File

@ -627,7 +627,7 @@ begin
fList.Align:= alClient; fList.Align:= alClient;
fList.BorderSpacing.Around:= 2; fList.BorderSpacing.Around:= 2;
fList.Parent := pnl; fList.Parent := pnl;
fList.ReadOnly:=true; fList.Style:=csDropDownList;
fList.OnSelect:= @lstBoxSelChange; fList.OnSelect:= @lstBoxSelChange;
fList.AutoSize := true; fList.AutoSize := true;
updateList; updateList;

View File

@ -603,7 +603,7 @@ begin
fDoc.loadFromFile(TrimFilename(fname)); fDoc.loadFromFile(TrimFilename(fname));
if assigned(fProj) and (fProj.filename = fDoc.fileName) then if assigned(fProj) and (fProj.filename = fDoc.fileName) then
begin begin
if fProj.getFormat = pfCE then if fProj.getFormat = pfDEXED then
fDoc.Highlighter := LfmSyn fDoc.Highlighter := LfmSyn
else else
fDoc.Highlighter := JsSyn; fDoc.Highlighter := JsSyn;

View File

@ -11,7 +11,7 @@ uses
type type
// describes the project kind. Used as a hint to cast ICECommonProject.getProject() // describes the project kind. Used as a hint to cast ICECommonProject.getProject()
TCEProjectFormat = (pfCE, pfDUB); TCEProjectFormat = (pfDEXED, pfDUB);
// describes the binary kind produces when compiling a project // describes the binary kind produces when compiling a project
TProjectBinaryKind = (executable, staticlib, sharedlib, obj); TProjectBinaryKind = (executable, staticlib, sharedlib, obj);

View File

@ -137,7 +137,7 @@ begin
if not fname.fileExists then exit; if not fname.fileExists then exit;
fmt := projectFormat(fname); fmt := projectFormat(fname);
if fmt in [pffCe, pffDub] then if fmt in [pffDexed, pffDub] then
begin begin
if assigned(fFreeProj) then if assigned(fFreeProj) then
begin begin
@ -145,7 +145,7 @@ begin
exit; exit;
fFreeProj.getProject.Free; fFreeProj.getProject.Free;
end; end;
if fmt = pffCe then if fmt = pffDexed then
TCENativeProject.create(nil) TCENativeProject.create(nil)
else else
TCEDubProject.create(nil); TCEDubProject.create(nil);

View File

@ -111,7 +111,7 @@ inherited CELibManEditorWidget: TCELibManEditorWidget
end end
object button5: TCEToolButton[5] object button5: TCEToolButton[5]
Left = 225 Left = 225
Height = 28 Height = 5
Top = 0 Top = 0
AutoSize = True AutoSize = True
Caption = 'button8' Caption = 'button8'

View File

@ -686,7 +686,7 @@ begin
exit; exit;
fmt := projectFormat(fname); fmt := projectFormat(fname);
if fmt in [pffCe, pffDub] then if fmt in [pffDexed, pffDub] then
begin begin
if assigned(fFreeProj) then if assigned(fFreeProj) then
begin begin
@ -694,7 +694,7 @@ begin
exit; exit;
fFreeProj.getProject.Free; fFreeProj.getProject.Free;
end; end;
if fmt = pffCe then if fmt = pffDexed then
TCENativeProject.create(nil) TCENativeProject.create(nil)
else else
TCEDubProject.create(nil); TCEDubProject.create(nil);

View File

@ -12,7 +12,6 @@ object CEMainForm: TCEMainForm
OnResize = FormResize OnResize = FormResize
OnWindowStateChange = FormWindowStateChange OnWindowStateChange = FormWindowStateChange
ShowHint = True ShowHint = True
LCLVersion = '2.0.0.2'
object mainMenu: TMainMenu object mainMenu: TMainMenu
top = 1 top = 1
object MenuItem1: TMenuItem object MenuItem1: TMenuItem

View File

@ -1059,7 +1059,7 @@ begin
if assigned(hdl) then if assigned(hdl) then
mem := hdl.findDocument(dst.fProject.filename); mem := hdl.findDocument(dst.fProject.filename);
if mem.isNotNil then if mem.isNotNil then
if dst.fProject.getFormat = pfCE then if dst.fProject.getFormat = pfDEXED then
mem.Highlighter := LfmSyn mem.Highlighter := LfmSyn
else else
mem.Highlighter := JsSyn; mem.Highlighter := JsSyn;
@ -2412,7 +2412,7 @@ procedure TCEMainForm.projNew(project: ICECommonProject);
begin begin
fProject := project; fProject := project;
case fProject.getFormat of case fProject.getFormat of
pfCE: fNativeProject := TCENativeProject(fProject.getProject); pfDEXED: fNativeProject := TCENativeProject(fProject.getProject);
pfDUB: fDubProject := TCEDubProject(fProject.getProject); pfDUB: fDubProject := TCEDubProject(fProject.getProject);
end; end;
if not fProject.inGroup then if not fProject.inGroup then
@ -2440,7 +2440,7 @@ procedure TCEMainForm.projFocused(project: ICECommonProject);
begin begin
fProject := project; fProject := project;
case fProject.getFormat of case fProject.getFormat of
pfCE: fNativeProject := TCENativeProject(fProject.getProject); pfDEXED: fNativeProject := TCENativeProject(fProject.getProject);
pfDUB: fDubProject := TCEDubProject(fProject.getProject); pfDUB: fDubProject := TCEDubProject(fProject.getProject);
end; end;
if not fProject.inGroup then if not fProject.inGroup then
@ -2723,7 +2723,7 @@ begin
if fProject.filename = fDoc.fileName then if fProject.filename = fDoc.fileName then
exit; exit;
if fProject.getFormat = pfCE then if fProject.getFormat = pfDEXED then
begin begin
if fDoc.fileName.fileExists and not fDoc.isTemporary then if fDoc.fileName.fileExists and not fDoc.isTemporary then
fNativeProject.addSource(fDoc.fileName) fNativeProject.addSource(fDoc.fileName)
@ -3831,8 +3831,13 @@ begin
ext := fname.extractFileExt.upperCase; ext := fname.extractFileExt.upperCase;
if (ext = '.JSON') or (ext = '.SDL') then if (ext = '.JSON') or (ext = '.SDL') then
newDubProj newDubProj
else if ext = '.DPRJ' then
newNativeProj
else else
newNativeProj; begin
dlgOkError('Unknown project extesion : ' + ext);
exit;
end;
fProject.loadFromFile(fname); fProject.loadFromFile(fname);
showProjTitle; showProjTitle;
@ -3881,6 +3886,7 @@ begin
end; end;
with TSaveDialog.Create(nil) do with TSaveDialog.Create(nil) do
try try
Filter := 'DUB json|*.json|DUB sdl|*.sdl|Dexed project|*.dprj';
if fProject.filename.fileExists then if fProject.filename.fileExists then
InitialDir := fproject.filename.extractFileDir; InitialDir := fproject.filename.extractFileDir;
if execute then if execute then
@ -3916,6 +3922,7 @@ begin
exit; exit;
with TOpenDialog.Create(nil) do with TOpenDialog.Create(nil) do
try try
Filter := 'DUB json|*.json|DUB sdl|*.sdl|Dexed project|*.dprj';
if execute then if execute then
openProj(filename.normalizePath); openProj(filename.normalizePath);
finally finally
@ -3929,7 +3936,7 @@ var
begin begin
if assigned(fProject) then case fProject.getFormat of if assigned(fProject) then case fProject.getFormat of
pfDUB: win := DockMaster.GetAnchorSite(fDubProjWidg); pfDUB: win := DockMaster.GetAnchorSite(fDubProjWidg);
pfCE: win := DockMaster.GetAnchorSite(fPrjCfWidg); pfDEXED: win := DockMaster.GetAnchorSite(fPrjCfWidg);
end end
else win := DockMaster.GetAnchorSite(fPrjCfWidg); else win := DockMaster.GetAnchorSite(fPrjCfWidg);
if win.isNotNil then if win.isNotNil then
@ -3952,7 +3959,7 @@ begin
openFile(fProject.filename); openFile(fProject.filename);
fDoc.isProjectDescription := true; fDoc.isProjectDescription := true;
if fProject.getFormat = pfCE then if fProject.getFormat = pfDEXED then
fDoc.Highlighter := LfmSyn fDoc.Highlighter := LfmSyn
else else
fDoc.Highlighter := JsSyn; fDoc.Highlighter := JsSyn;
@ -4170,6 +4177,7 @@ begin
end; end;
with TOpenDialog.Create(nil) do with TOpenDialog.Create(nil) do
try try
Filter := 'Dexed project groups|*.dgrp';
if execute then if execute then
begin begin
filename := filename.normalizePath; filename := filename.normalizePath;
@ -4188,6 +4196,7 @@ procedure TCEMainForm.actProjSaveGroupAsExecute(Sender: TObject);
begin begin
with TSaveDialog.Create(nil) do with TSaveDialog.Create(nil) do
try try
Filter := 'Dexed project groups|*.dgrp';
if fProjectGroup.groupFilename.fileExists then if fProjectGroup.groupFilename.fileExists then
InitialDir := fProjectGroup.groupFilename.extractFileDir; InitialDir := fProjectGroup.groupFilename.extractFileDir;
if execute then if execute then

View File

@ -679,7 +679,7 @@ begin
if not fname.fileExists then if not fname.fileExists then
exit; exit;
fmt := projectFormat(fname); fmt := projectFormat(fname);
if fmt in [pffCe, pffDub] then if fmt in [pffDexed, pffDub] then
begin begin
if assigned(fFreeProj) then if assigned(fFreeProj) then
begin begin
@ -687,7 +687,7 @@ begin
exit; exit;
fFreeProj.getProject.Free; fFreeProj.getProject.Free;
end; end;
if fmt = pffCe then if fmt = pffDexed then
TCENativeProject.create(nil) TCENativeProject.create(nil)
else else
TCEDubProject.create(nil); TCEDubProject.create(nil);

View File

@ -160,7 +160,7 @@ inherited CEProjectGroupWidget: TCEProjectGroupWidget
end end
object button0: TCEToolButton[5] object button0: TCEToolButton[5]
Left = 113 Left = 113
Height = 28 Height = 5
Top = 0 Top = 0
AutoSize = True AutoSize = True
Caption = 'button0' Caption = 'button0'

View File

@ -5,7 +5,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, ExtCtrls, Menus, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, ExtCtrls, Menus,
Buttons, dialogs, ComCtrls, StdCtrls, Buttons, dialogs, ComCtrls, StdCtrls, LazFileUtils,
ce_widget, ce_common, ce_interfaces, ce_writableComponent, ce_observer, ce_widget, ce_common, ce_interfaces, ce_writableComponent, ce_observer,
ce_ceproject, ce_dubproject, ce_projutils, ce_sharedres, ce_dsgncontrols, ce_ceproject, ce_dubproject, ce_projutils, ce_sharedres, ce_dsgncontrols,
ce_dialogs; ce_dialogs;
@ -388,9 +388,19 @@ end;
procedure TProjectGroup.openGroup(const fname: string); procedure TProjectGroup.openGroup(const fname: string);
var var
i: integer; i: integer;
f: string;
begin begin
fBasePath := fname.extractFilePath; f := fname;
loadFromFile(fname); if not FilenameIsAbsolute(f) then
f := ExpandFileName(f);
if fname.extractFileExt <> '.dgrp' then
begin
dlgOkInfo('project file extension automatically updated to "dgrp"');
f := ChangeFileExt(fname, '.dgrp');
RenameFile(fname, f);
end;
fBasePath := f.extractFilePath;
loadFromFile(f);
for i:= 0 to fItems.Count-1 do for i:= 0 to fItems.Count-1 do
getItem(i).fGroup := self; getItem(i).fGroup := self;
doChanged; doChanged;
@ -402,8 +412,10 @@ var
i: integer; i: integer;
c: boolean = false; c: boolean = false;
n: string; n: string;
f: string;
begin begin
n := fname.extractFilePath; f := fname;
n := f.extractFilePath;
if (fBasePath <> '') and (n <> fBasePath) then if (fBasePath <> '') and (n <> fBasePath) then
begin begin
c := true; c := true;
@ -415,7 +427,8 @@ begin
if c then for i:= 0 to projectCount-1 do if c then for i:= 0 to projectCount-1 do
getItem(i).fFilename := ExtractRelativepath(n, getItem(i).fFilename); getItem(i).fFilename := ExtractRelativepath(n, getItem(i).fFilename);
fBasePath := n; fBasePath := n;
saveToFile(fname); f := ChangeFileExt(f, '.dgrp');
saveToFile(f);
fModified := false; fModified := false;
end; end;
@ -760,7 +773,7 @@ var
prj: TProjectGroupItem; prj: TProjectGroupItem;
fmt: TCEProjectFormat; fmt: TCEProjectFormat;
const const
typeStr: array[TCEProjectFormat] of string = ('CE','DUB'); typeStr: array[TCEProjectFormat] of string = ('DEXED','DUB');
begin begin
if fUpdating then if fUpdating then
exit; exit;
@ -777,7 +790,7 @@ begin
Data:= prj; Data:= prj;
fmt := prj.project.getFormat; fmt := prj.project.getFormat;
case fmt of case fmt of
pfCE: Caption := prj.fFilename.extractFileName; pfDEXED: Caption := prj.fFilename.extractFileName;
pfDUB: Caption := TCEDubProject(prj.project.getProject).packageName; pfDUB: Caption := TCEDubProject(prj.project.getProject).packageName;
end; end;
SubItems.Add(typeStr[fmt]); SubItems.Add(typeStr[fmt]);
@ -797,7 +810,7 @@ begin
begin begin
if fFreeProj.filename.fileExists then if fFreeProj.filename.fileExists then
case fFreeProj.getFormat of case fFreeProj.getFormat of
pfCE: StaticText1.Caption:= 'Free standing: ' + fFreeProj.filename.extractFileName; pfDEXED: StaticText1.Caption:= 'Free standing: ' + fFreeProj.filename.extractFileName;
pfDUB: StaticText1.Caption:= 'Free standing: ' + TCEDubProject(fFreeProj.getProject).packageName; pfDUB: StaticText1.Caption:= 'Free standing: ' + TCEDubProject(fFreeProj.getProject).packageName;
end end
else else

View File

@ -319,7 +319,7 @@ var
ce: boolean; ce: boolean;
sp: integer; sp: integer;
begin begin
ce := fProject.getFormat = pfCE; ce := fProject.getFormat = pfDEXED;
btnRemFold.Visible:= ce; btnRemFold.Visible:= ce;
btnAddFold.Visible:= ce; btnAddFold.Visible:= ce;

View File

@ -9,7 +9,7 @@ uses
ce_dlang, ce_stringrange; ce_dlang, ce_stringrange;
type type
TCEProjectFileFormat = (pffNone, pffCe, pffDub); TCEProjectFileFormat = (pffNone, pffDexed, pffDub);
TLexNameCallback = class TLexNameCallback = class
private private
@ -61,8 +61,10 @@ begin
ext := filename.extractFileExt.upperCase; ext := filename.extractFileExt.upperCase;
if (ext = '.JSON') or (ext = '.SDL') then if (ext = '.JSON') or (ext = '.SDL') then
result := isValidDubProject(filename) result := isValidDubProject(filename)
else if (ext = '.DPRJ') then
result := isValidNativeProject(filename)
else else
result := isValidNativeProject(filename); result := false;
end; end;
function projectFormat(const filename: string): TCEProjectFileFormat; function projectFormat(const filename: string): TCEProjectFileFormat;
@ -76,8 +78,8 @@ begin
if isValidDubProject(filename) then if isValidDubProject(filename) then
result := pffDub; result := pffDub;
end end
else else if (ext = '.DPRJ') and isValidNativeProject(filename) then
if isValidNativeProject(filename) then result := pffCe; result := pffDexed;
end; end;
function loadProject(const filename: string; discret: boolean): ICECommonProject; function loadProject(const filename: string; discret: boolean): ICECommonProject;

View File

@ -97,7 +97,7 @@ procedure TCESymbolExpander.projNew(project: ICECommonProject);
begin begin
fProjInterface := project; fProjInterface := project;
case project.getFormat of case project.getFormat of
pfCE: fProj := TCENativeProject(project.getProject); pfDEXED: fProj := TCENativeProject(project.getProject);
pfDUB: fProj := nil; pfDUB: fProj := nil;
end; end;
fNeedUpdate := true; fNeedUpdate := true;
@ -116,7 +116,7 @@ procedure TCESymbolExpander.projFocused(project: ICECommonProject);
begin begin
fProjInterface := project; fProjInterface := project;
case project.getFormat of case project.getFormat of
pfCE: fProj := TCENativeProject(project.getProject); pfDEXED: fProj := TCENativeProject(project.getProject);
pfDUB: fProj := nil; pfDUB: fProj := nil;
end; end;
fNeedUpdate := true; fNeedUpdate := true;