Merge pull request #3694 from jlewin/master
Add event, notify, rebuild on Macro changes
This commit is contained in:
commit
474ff5607e
6 changed files with 41 additions and 12 deletions
|
|
@ -101,7 +101,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
});
|
||||
|
||||
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
|
||||
this.Items = nonZipFiles.Select<PrintItem, ILibraryItem>(printItem =>
|
||||
|
|
@ -189,8 +189,12 @@ namespace MatterHackers.MatterControl.Library
|
|||
{
|
||||
sqlItem.PrintItem.Delete();
|
||||
}
|
||||
|
||||
this.Items.Remove(item);
|
||||
else if (item is LocalLibraryZipContainerLink link)
|
||||
{
|
||||
string sql = $"SELECT * FROM PrintItem WHERE ID = @id";
|
||||
var container = Datastore.Instance.dbSQLite.Query<PrintItem>(sql, link.RowID).FirstOrDefault();
|
||||
container?.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
this.ReloadContent();
|
||||
|
|
|
|||
|
|
@ -36,6 +36,16 @@ using MatterHackers.Agg.Platform;
|
|||
|
||||
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
|
||||
{
|
||||
private static ImageBuffer thumbnail;
|
||||
|
|
@ -49,7 +59,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public Stream ZipStream { get; set; }
|
||||
|
||||
public override bool IsProtected { get; } = true;
|
||||
public override bool IsProtected { get; } = false;
|
||||
|
||||
public LocalZipContainerLink(string filePath, string nameOverride = null)
|
||||
: base(filePath)
|
||||
|
|
|
|||
|
|
@ -41,14 +41,19 @@ namespace MatterHackers.MatterControl.PrinterControls
|
|||
public class MacroControls : FlowLeftRightWithWrapping
|
||||
{
|
||||
private EventHandler unregisterEvents;
|
||||
PrinterConfig printer;
|
||||
ThemeConfig theme;
|
||||
private PrinterConfig printer;
|
||||
private ThemeConfig theme;
|
||||
|
||||
private MacroControls(PrinterConfig printer, ThemeConfig theme)
|
||||
{
|
||||
this.printer = printer;
|
||||
this.theme = theme;
|
||||
Rebuild();
|
||||
this.Rebuild();
|
||||
|
||||
printer.Settings.MacrosChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() => Rebuild());
|
||||
}, ref unregisterEvents);
|
||||
|
||||
ActiveSliceSettings.ActiveProfileModified.RegisterEvent((s, e) =>
|
||||
{
|
||||
|
|
@ -62,7 +67,7 @@ namespace MatterHackers.MatterControl.PrinterControls
|
|||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
void Rebuild()
|
||||
private void Rebuild()
|
||||
{
|
||||
addedChildren.Clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
contentRow.AddChild(container);
|
||||
|
||||
var addMacroButton = theme.CreateDialogButton("Save".Localize());
|
||||
addMacroButton.Click += (s, e) =>
|
||||
var saveMacroButton = theme.CreateDialogButton("Save".Localize());
|
||||
saveMacroButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
|
|
@ -121,15 +121,17 @@ namespace MatterHackers.MatterControl
|
|||
if (!printerSettings.Macros.Contains(gcodeMacro))
|
||||
{
|
||||
printerSettings.Macros.Add(gcodeMacro);
|
||||
printerSettings.Save();
|
||||
}
|
||||
|
||||
printerSettings.NotifyMacrosChanged();
|
||||
printerSettings.Save();
|
||||
|
||||
this.DialogWindow.ChangeToPage(new MacroListPage(printerSettings));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.AddPageAction(addMacroButton);
|
||||
this.AddPageAction(saveMacroButton);
|
||||
|
||||
// Define field validation
|
||||
var validationMethods = new ValidationMethods();
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
printerSettings.Macros.Remove(localMacroReference);
|
||||
printerSettings.Save();
|
||||
printerSettings.NotifyMacrosChanged();
|
||||
this.RebuildList(printerSettings);
|
||||
};
|
||||
macroRow.AddChild(removeLink);
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
[JsonIgnore]
|
||||
public RootedObjectEventHandler PrintLevelingEnabledChanged = new RootedObjectEventHandler();
|
||||
|
||||
public RootedObjectEventHandler MacrosChanged = new RootedObjectEventHandler();
|
||||
|
||||
public static PrinterSettings Empty { get; }
|
||||
|
||||
public int DocumentVersion { get; set; } = LatestVersion;
|
||||
|
|
@ -119,6 +121,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
internal void NotifyMacrosChanged()
|
||||
{
|
||||
this.MacrosChanged.CallEvents(this, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move conflicting user overrides to the temporary staging area, allowing presets values to take effect
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue