Skip to content

Commit

Permalink
A bit of Fixes and Improvements when applying data (#150)
Browse files Browse the repository at this point in the history
* +Indication for long waiting Apply in wizard

* Fixed an empty `<PropertyGroup />` when applying
  • Loading branch information
3F authored May 7, 2020
1 parent 7d54260 commit 937c6a4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
11 changes: 7 additions & 4 deletions Wizard/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,18 @@ protected bool RemoveXmlTarget(string name)
return false;
}

protected static void RemoveEmptyPropertyGroups(IXProject xp)
=> xp?.Project.Xml.PropertyGroups.ToArray()
.Where(p => p.Properties.Count < 1)
.ForEach(p => p.Parent?.RemoveChild(p));

protected void RemoveProperties(params string[] names)
{
foreach(string name in names)
{
if(!string.IsNullOrWhiteSpace(name)) {
// Log.send(this, $"'{ProjectPath}' Remove old properties: '{name}'", Message.Level.Trace);
while(XProject.RemoveProperty(name, true)) { }
}
if(!string.IsNullOrWhiteSpace(name)) while(XProject.RemoveProperty(name, true)) { }
}
RemoveEmptyPropertyGroups(XProject); //TODO: id for our group
}

/// <summary>
Expand Down
49 changes: 36 additions & 13 deletions Wizard/UI/ConfiguratorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,11 @@ private bool SaveProjects(IEnumerable<IProject> projects)
{
foreach(var prj in projects)
{
if(!DDNS.IsValidNS(prj.Config.Namespace)) {
MessageBox.Show($"{prj.ProjectPath}\n\n>> Namespace: '{prj.Config.Namespace}'", "Fix data before continue", 0, MessageBoxIcon.Warning);
if(!DDNS.IsValidNS(prj.Config.Namespace))
{
this.ForegroundAction(_=> MessageBox.Show(
$"{prj.ProjectPath}\n\n>> Namespace: '{prj.Config.Namespace}'", "Fix data before continue", 0, MessageBoxIcon.Warning
));
return false;
}

Expand Down Expand Up @@ -440,6 +443,21 @@ private void UpdateRefBefore()
}
}

private bool Apply()
{
exec.TargetsFileIfCfg?.Reset();
UpdateRefBefore();

if(!SaveProjects(projectItems.Data)) {
return false;
}
// updates other installed with which we did not interact in this session
SaveProjects(projectItems.GetInactiveInstalled(GetProjects(exec.ActiveSlnFile)));

exec.SaveTStorageOrDelete();
return true;
}

private void EnableTabsWhenNoSln(bool status) => ((Control)tabCfgDxp).Enabled = status;

private string GetBuildInfo()
Expand Down Expand Up @@ -467,7 +485,7 @@ private string GetBuildInfo()

private void ConfiguratorForm_Load(object sender, EventArgs e)
{
TopMost = false; TopMost = true;
this.ForegroundAction();

if(!string.IsNullOrEmpty(pkgVer.Activated))
{
Expand Down Expand Up @@ -501,17 +519,22 @@ private void comboBoxSln_SelectedIndexChanged(object sender, EventArgs e)

private void btnApply_Click(object sender, EventArgs e)
{
exec.TargetsFileIfCfg?.Reset();
UpdateRefBefore();

if(!SaveProjects(projectItems.Data)) {
return;
}
// updates other installed with which we did not interact in this session
SaveProjects(projectItems.GetInactiveInstalled(GetProjects(exec.ActiveSlnFile)));
Task.Factory.StartNew(() =>
{
btnApply.UIAction(x => x.Enabled = false);
progressLine.StartTrainEffect(panelTop.Width);
void _stop() => progressLine.StopAll();

exec.SaveTStorageOrDelete();
Close();
if(Apply())
{
this.UIAction(x => { _stop(); x.Close(); });
}
else
{
_stop();
btnApply.UIAction(x => x.Enabled = true);
}
});
}

private void lnkSrc_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) => "https://github.com/3F/DllExport".OpenUrl();
Expand Down
7 changes: 7 additions & 0 deletions Wizard/UI/Extensions/ControlExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,12 @@ internal static void UIBlinkText(this Control ctrl, int delay, string text, Canc
}
}
}

internal static void ForegroundAction(this Form ctrl, Action<Form> act = null)
{
ctrl.TopMost = false;
act?.Invoke(ctrl);
ctrl.TopMost = true;
}
}
}

0 comments on commit 937c6a4

Please sign in to comment.