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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ uses
type
// 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
TProjectBinaryKind = (executable, staticlib, sharedlib, obj);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ interface
uses
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_ceproject, ce_dubproject, ce_projutils, ce_sharedres, ce_dsgncontrols,
ce_dialogs;
@ -388,9 +388,19 @@ end;
procedure TProjectGroup.openGroup(const fname: string);
var
i: integer;
f: string;
begin
fBasePath := fname.extractFilePath;
loadFromFile(fname);
f := 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
getItem(i).fGroup := self;
doChanged;
@ -402,8 +412,10 @@ var
i: integer;
c: boolean = false;
n: string;
f: string;
begin
n := fname.extractFilePath;
f := fname;
n := f.extractFilePath;
if (fBasePath <> '') and (n <> fBasePath) then
begin
c := true;
@ -415,7 +427,8 @@ begin
if c then for i:= 0 to projectCount-1 do
getItem(i).fFilename := ExtractRelativepath(n, getItem(i).fFilename);
fBasePath := n;
saveToFile(fname);
f := ChangeFileExt(f, '.dgrp');
saveToFile(f);
fModified := false;
end;
@ -760,7 +773,7 @@ var
prj: TProjectGroupItem;
fmt: TCEProjectFormat;
const
typeStr: array[TCEProjectFormat] of string = ('CE','DUB');
typeStr: array[TCEProjectFormat] of string = ('DEXED','DUB');
begin
if fUpdating then
exit;
@ -777,7 +790,7 @@ begin
Data:= prj;
fmt := prj.project.getFormat;
case fmt of
pfCE: Caption := prj.fFilename.extractFileName;
pfDEXED: Caption := prj.fFilename.extractFileName;
pfDUB: Caption := TCEDubProject(prj.project.getProject).packageName;
end;
SubItems.Add(typeStr[fmt]);
@ -797,7 +810,7 @@ begin
begin
if fFreeProj.filename.fileExists then
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;
end
else

View File

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

View File

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

View File

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