Merge pull request #3694 from jlewin/master

Add event, notify, rebuild on Macro changes
This commit is contained in:
johnlewin 2018-09-05 08:49:53 -07:00 committed by GitHub
commit 474ff5607e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 12 deletions

View file

@ -101,7 +101,7 @@ namespace MatterHackers.MatterControl.Library
}); });
this.ChildContainers = childContainers.Concat( this.ChildContainers = childContainers.Concat(
zipFiles.Select(f => new LocalZipContainerLink(f.FileLocation, f.Name))).OrderBy(d => d.Name).ToList(); zipFiles.Select(f => new LocalLibraryZipContainerLink(f.Id, f.FileLocation, f.Name))).OrderBy(d => d.Name).ToList();
// PrintItems projected onto FileSystemFileItem // PrintItems projected onto FileSystemFileItem
this.Items = nonZipFiles.Select<PrintItem, ILibraryItem>(printItem => this.Items = nonZipFiles.Select<PrintItem, ILibraryItem>(printItem =>
@ -189,8 +189,12 @@ namespace MatterHackers.MatterControl.Library
{ {
sqlItem.PrintItem.Delete(); sqlItem.PrintItem.Delete();
} }
else if (item is LocalLibraryZipContainerLink link)
this.Items.Remove(item); {
string sql = $"SELECT * FROM PrintItem WHERE ID = @id";
var container = Datastore.Instance.dbSQLite.Query<PrintItem>(sql, link.RowID).FirstOrDefault();
container?.Delete();
}
} }
this.ReloadContent(); this.ReloadContent();

View file

@ -36,6 +36,16 @@ using MatterHackers.Agg.Platform;
namespace MatterHackers.MatterControl.Library namespace MatterHackers.MatterControl.Library
{ {
public class LocalLibraryZipContainerLink : LocalZipContainerLink
{
public int RowID { get; }
public LocalLibraryZipContainerLink(int id, string filePath, string nameOverride = null)
: base (filePath, nameOverride)
{
this.RowID = id;
}
}
public class LocalZipContainerLink : FileSystemItem, ILibraryContainerLink public class LocalZipContainerLink : FileSystemItem, ILibraryContainerLink
{ {
private static ImageBuffer thumbnail; private static ImageBuffer thumbnail;
@ -49,7 +59,7 @@ namespace MatterHackers.MatterControl.Library
public Stream ZipStream { get; set; } public Stream ZipStream { get; set; }
public override bool IsProtected { get; } = true; public override bool IsProtected { get; } = false;
public LocalZipContainerLink(string filePath, string nameOverride = null) public LocalZipContainerLink(string filePath, string nameOverride = null)
: base(filePath) : base(filePath)

View file

@ -41,14 +41,19 @@ namespace MatterHackers.MatterControl.PrinterControls
public class MacroControls : FlowLeftRightWithWrapping public class MacroControls : FlowLeftRightWithWrapping
{ {
private EventHandler unregisterEvents; private EventHandler unregisterEvents;
PrinterConfig printer; private PrinterConfig printer;
ThemeConfig theme; private ThemeConfig theme;
private MacroControls(PrinterConfig printer, ThemeConfig theme) private MacroControls(PrinterConfig printer, ThemeConfig theme)
{ {
this.printer = printer; this.printer = printer;
this.theme = theme; this.theme = theme;
Rebuild(); this.Rebuild();
printer.Settings.MacrosChanged.RegisterEvent((s, e) =>
{
UiThread.RunOnIdle(() => Rebuild());
}, ref unregisterEvents);
ActiveSliceSettings.ActiveProfileModified.RegisterEvent((s, e) => ActiveSliceSettings.ActiveProfileModified.RegisterEvent((s, e) =>
{ {
@ -62,7 +67,7 @@ namespace MatterHackers.MatterControl.PrinterControls
base.OnClosed(e); base.OnClosed(e);
} }
void Rebuild() private void Rebuild()
{ {
addedChildren.Clear(); addedChildren.Clear();

View file

@ -107,8 +107,8 @@ namespace MatterHackers.MatterControl
contentRow.AddChild(container); contentRow.AddChild(container);
var addMacroButton = theme.CreateDialogButton("Save".Localize()); var saveMacroButton = theme.CreateDialogButton("Save".Localize());
addMacroButton.Click += (s, e) => saveMacroButton.Click += (s, e) =>
{ {
UiThread.RunOnIdle(() => UiThread.RunOnIdle(() =>
{ {
@ -121,15 +121,17 @@ namespace MatterHackers.MatterControl
if (!printerSettings.Macros.Contains(gcodeMacro)) if (!printerSettings.Macros.Contains(gcodeMacro))
{ {
printerSettings.Macros.Add(gcodeMacro); printerSettings.Macros.Add(gcodeMacro);
printerSettings.Save();
} }
printerSettings.NotifyMacrosChanged();
printerSettings.Save();
this.DialogWindow.ChangeToPage(new MacroListPage(printerSettings)); this.DialogWindow.ChangeToPage(new MacroListPage(printerSettings));
} }
}); });
}; };
this.AddPageAction(addMacroButton); this.AddPageAction(saveMacroButton);
// Define field validation // Define field validation
var validationMethods = new ValidationMethods(); var validationMethods = new ValidationMethods();

View file

@ -106,6 +106,7 @@ namespace MatterHackers.MatterControl
{ {
printerSettings.Macros.Remove(localMacroReference); printerSettings.Macros.Remove(localMacroReference);
printerSettings.Save(); printerSettings.Save();
printerSettings.NotifyMacrosChanged();
this.RebuildList(printerSettings); this.RebuildList(printerSettings);
}; };
macroRow.AddChild(removeLink); macroRow.AddChild(removeLink);

View file

@ -60,6 +60,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
[JsonIgnore] [JsonIgnore]
public RootedObjectEventHandler PrintLevelingEnabledChanged = new RootedObjectEventHandler(); public RootedObjectEventHandler PrintLevelingEnabledChanged = new RootedObjectEventHandler();
public RootedObjectEventHandler MacrosChanged = new RootedObjectEventHandler();
public static PrinterSettings Empty { get; } public static PrinterSettings Empty { get; }
public int DocumentVersion { get; set; } = LatestVersion; public int DocumentVersion { get; set; } = LatestVersion;
@ -119,6 +121,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
} }
} }
internal void NotifyMacrosChanged()
{
this.MacrosChanged.CallEvents(this, null);
}
/// <summary> /// <summary>
/// Move conflicting user overrides to the temporary staging area, allowing presets values to take effect /// Move conflicting user overrides to the temporary staging area, allowing presets values to take effect
/// </summary> /// </summary>