DUB project editor, several fixes

- doesn't trow when a 'name is expected'
- expand tree after property is added or set
This commit is contained in:
Basile Burg 2015-09-25 03:00:10 +02:00
parent 057216db69
commit 2eca7e5e37
3 changed files with 34 additions and 16 deletions

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, fpjson, jsonparser, jsonscanner, process, strutils, Classes, SysUtils, fpjson, jsonparser, jsonscanner, process, strutils,
ce_common, ce_interfaces, ce_observer; ce_common, ce_interfaces, ce_observer, ce_dialogs;
type type
@ -339,6 +339,11 @@ var
msgs: ICEMessagesDisplay; msgs: ICEMessagesDisplay;
begin begin
result := false; result := false;
if not FileExists(fFilename) then
begin
dlgOkInfo('The DUB project must be saved before being compiled or run !');
exit;
end;
msgs := getMessageDisplay; msgs := getMessageDisplay;
msgs.clearByData(Self as ICECommonProject); msgs.clearByData(Self as ICECommonProject);
prjname := shortenPath(fFilename); prjname := shortenPath(fFilename);
@ -346,7 +351,10 @@ begin
olddir := GetCurrentDir; olddir := GetCurrentDir;
try try
if not run then if not run then
begin
msgs.message('compiling ' + prjname, self as ICECommonProject, amcProj, amkInf); msgs.message('compiling ' + prjname, self as ICECommonProject, amcProj, amkInf);
if modified then saveToFile(fFilename);
end;
chDir(extractFilePath(fFilename)); chDir(extractFilePath(fFilename));
dubproc.Executable := 'dub' + exeExt; dubproc.Executable := 'dub' + exeExt;
dubproc.Options := dubproc.Options + [poStderrToOutPut, poUsePipes]; dubproc.Options := dubproc.Options + [poStderrToOutPut, poUsePipes];
@ -432,16 +440,16 @@ var
begin begin
fBuildTypes.Clear; fBuildTypes.Clear;
fConfigs.Clear; fConfigs.Clear;
// the CE interface for dub doesn't make the difference between build type // the CE interface for dub doesn't make the difference between build type
//and config, instead each possible combination type + build is generated. //and config, instead each possible combination type + build is generated.
if fJSON.Find('configurations') <> nil then if fJSON.Find('configurations') <> nil then
begin begin
arr := fJSON.Arrays['configurations']; arr := fJSON.Arrays['configurations'];
for i:= 0 to arr.Count-1 do for i:= 0 to arr.Count-1 do
begin begin
item := TJSONObject(arr.Items[i]); item := TJSONObject(arr.Items[i]);
if item.Find('name') = nil then
continue;
fConfigs.Add(item.Strings['name']); fConfigs.Add(item.Strings['name']);
end; end;
end else end else
@ -458,9 +466,12 @@ begin
for i := 0 to arr.Count-1 do for i := 0 to arr.Count-1 do
begin begin
item := TJSONObject(arr.Items[i]); item := TJSONObject(arr.Items[i]);
if item.Find('name') = nil then
continue;
itemname := item.Strings['name']; itemname := item.Strings['name'];
// defaults build types can be overridden // defaults build types can be overridden
if fBuildTypes.IndexOf(itemname) <> -1 then continue; if fBuildTypes.IndexOf(itemname) <> -1 then
continue;
fBuildTypes.Add(itemname); fBuildTypes.Add(itemname);
end; end;
end; end;

View File

@ -21,10 +21,10 @@ inherited CEDubProjectEditorWidget: TCEDubProjectEditorWidget
Height = 416 Height = 416
Top = 4 Top = 4
Width = 403 Width = 403
ActivePage = TabSheet1 ActivePage = TabSheet2
Align = alClient Align = alClient
BorderSpacing.Around = 4 BorderSpacing.Around = 4
TabIndex = 0 TabIndex = 1
TabOrder = 0 TabOrder = 0
object TabSheet1: TTabSheet object TabSheet1: TTabSheet
Caption = 'Inspector' Caption = 'Inspector'

View File

@ -10,9 +10,6 @@ uses
ce_widget, ce_common, ce_interfaces, ce_observer, ce_dubproject, ce_sharedres; ce_widget, ce_common, ce_interfaces, ce_observer, ce_dubproject, ce_sharedres;
type type
//TODO-cDUB: add new properties from UI
{ TCEDubProjectEditorWidget } { TCEDubProjectEditorWidget }
TDubPropAddEvent = procedure(const propName: string; tpe: TJSONtype) of object; TDubPropAddEvent = procedure(const propName: string; tpe: TJSONtype) of object;
@ -81,10 +78,12 @@ var
layout: TPanel; layout: TPanel;
begin begin
inherited create(nil); inherited create(nil);
width := 200; width := 280;
height := 120; height := 130;
fEvent := event; fEvent := event;
caption := 'add a DUB property'; caption := 'add a DUB property';
Position := poMainFormCenter;
ShowHint:=true;
// //
fSelType := TRadioGroup.Create(self); fSelType := TRadioGroup.Create(self);
fSelType.Parent := self; fSelType.Parent := self;
@ -93,6 +92,7 @@ begin
fSelType.BorderSpacing.Around:=2; fSelType.BorderSpacing.Around:=2;
fSelType.Caption:= 'type'; fSelType.Caption:= 'type';
fSelType.ItemIndex:=2; fSelType.ItemIndex:=2;
fSelType.Hint:= 'type of the property to add';
// //
layout := TPanel.Create(self); layout := TPanel.Create(self);
layout.Parent := self; layout.Parent := self;
@ -105,6 +105,7 @@ begin
fEdName.Align:=alClient; fEdName.Align:=alClient;
fEdName.BorderSpacing.Around:=4; fEdName.BorderSpacing.Around:=4;
fEdName.Width:=80; fEdName.Width:=80;
fEdName.Hint:='name of the property to add';
// //
fBtnValidate := TBitBtn.Create(self); fBtnValidate := TBitBtn.Create(self);
fBtnValidate.Parent := layout; fBtnValidate.Parent := layout;
@ -112,6 +113,7 @@ begin
fBtnValidate.BorderSpacing.Around:=4; fBtnValidate.BorderSpacing.Around:=4;
fBtnValidate.Width:= 26; fBtnValidate.Width:= 26;
fBtnValidate.OnClick:=@doValidate; fBtnValidate.OnClick:=@doValidate;
fBtnValidate.Hint:='accept and add a property';
AssignPng(fBtnValidate, 'accept'); AssignPng(fBtnValidate, 'accept');
end; end;
@ -119,7 +121,7 @@ procedure TCEDubProjectPropAddPanel.doValidate(sender: TObject);
var var
tpe: TJSONtype; tpe: TJSONtype;
begin begin
if assigned(fEvent) and (fEdName.Text <> '') then if assigned(fEvent) then
begin begin
case fSelType.ItemIndex of case fSelType.ItemIndex of
0: tpe := TJSONtype.jtArray; 0: tpe := TJSONtype.jtArray;
@ -231,6 +233,7 @@ begin
if fSelectedNode = nil then exit; if fSelectedNode = nil then exit;
// //
setJsonValueFromEditor; setJsonValueFromEditor;
propTree.FullExpand;
end; end;
procedure TCEDubProjectEditorWidget.btnAddPropClick(Sender: TObject); procedure TCEDubProjectEditorWidget.btnAddPropClick(Sender: TObject);
@ -273,12 +276,16 @@ begin
end; end;
end; end;
fProj.endModification; fProj.endModification;
propTree.FullExpand;
nod := propTree.Items.FindNodeWithText('<value>'); nod := propTree.Items.FindNodeWithText('<value>');
if nod <> nil then propTree.Selected := nod if nod = nil then
else nod := propTree.Items.FindNodeWithText(propName); nod := propTree.Items.FindNodeWithText(propName);
if nod <> nil then propTree.Selected := nod; if nod <> nil then
begin
propTree.Selected := nod;
propTree.MakeSelectionVisible; propTree.MakeSelectionVisible;
end; end;
end;
procedure TCEDubProjectEditorWidget.btnDelPropClick(Sender: TObject); procedure TCEDubProjectEditorWidget.btnDelPropClick(Sender: TObject);
var var