Ported the old tab renaming code into main

Needs to be cleaned up
This commit is contained in:
Lars Brubaker 2022-01-21 15:21:07 -08:00
parent 035b84d065
commit b664670a42
47 changed files with 644 additions and 337 deletions

View file

@ -298,7 +298,7 @@ namespace MatterHackers.MatterControl
}
}
private async Task PersistUserWorkspaceTabs(bool saveSceneChanges)
public async Task PersistUserWorkspaceTabs(bool saveSceneChanges)
{
if (saveSceneChanges)
{
@ -839,7 +839,7 @@ namespace MatterHackers.MatterControl
{
this.Library.RegisterContainer(
new DynamicContainerLink(
() => "Downloads".Localize(),
"Downloads".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "download_icon.png")),
() => new FileSystemContainer(ApplicationDataStorage.Instance.DownloadsDirectory)
@ -858,7 +858,7 @@ namespace MatterHackers.MatterControl
this.Library.RegisterContainer(
new DynamicContainerLink(
() => "Library".Localize(),
"Library".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "library_icon.png")),
() => this.Library.LibraryCollectionContainer));
@ -883,7 +883,7 @@ namespace MatterHackers.MatterControl
this.Library.RegisterContainer(
new DynamicContainerLink(
() => "History".Localize(),
"History".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "history_icon.png")),
() => new RootHistoryContainer())
@ -899,7 +899,7 @@ namespace MatterHackers.MatterControl
ExtraContainers = new List<ILibraryContainerLink>()
{
new DynamicContainerLink(
() => "Printers".Localize(),
"Printers".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "printer_icon.png")),
() => new OpenPrintersContainer())

View file

@ -60,6 +60,8 @@ namespace MatterHackers.MatterControl
public string Name { get; set; }
public event EventHandler NameChanged;
public bool IsProtected { get; set; }
public bool IsVisible { get; set; }
@ -71,6 +73,6 @@ namespace MatterHackers.MatterControl
public string Path { get; set; }
public string AssetPath { get; set; }
}
}
}
}

View file

@ -27,11 +27,9 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Collections.Generic;
using System;
using System.IO;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.Library;
using MatterHackers.MatterControl.SlicerConfiguration;
using Newtonsoft.Json;
@ -57,7 +55,7 @@ namespace MatterHackers.MatterControl
{
wrappedLibrary.ExtraContainers.Add(
new DynamicContainerLink(
() => printer.Settings.GetValue(SettingsKey.printer_name),
printer.Settings.GetValue(SettingsKey.printer_name),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "printer_icon.png")),
() => new PrinterContainer(printer))
@ -78,6 +76,7 @@ namespace MatterHackers.MatterControl
this.SceneContext = sceneContext;
}
[JsonIgnore]
public string Name
{
get
@ -96,13 +95,18 @@ namespace MatterHackers.MatterControl
return "Unknown";
}
set
{
#if DEBUG
throw new NotImplementedException();
#endif
}
}
[JsonIgnore]
public ISceneContext SceneContext { get; }
public EditContext EditContext { get; set; }
public string PrinterID { get; set; }
[JsonIgnore]

View file

@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("AddBase")
{
OperationType = typeof(IObject3D),
TitleResolver = () => "Add Base".Localize(),
TitleGetter = () => "Add Base".Localize(),
ResultType = typeof(BaseObject3D),
Action = (sceneContext) =>
{
@ -97,7 +97,7 @@ namespace MatterHackers.MatterControl
scene.SelectedItem = baseMesh;
},
Icon = (theme) => StaticData.Instance.LoadIcon("add_base.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "A path must be selected".Localize().Stars(),
HelpTextGetter = () => "A path must be selected".Localize().Stars(),
// this is for when base is working with generic meshes
//IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && !(sceneContext.Scene.SelectedItem is IPathObject),
// this is for when only IPathObjects are working correctly
@ -220,7 +220,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("EditComponent")
{
OperationType = typeof(IObject3D),
TitleResolver = () => "Edit Component".Localize(),
TitleGetter = () => "Edit Component".Localize(),
ResultType = typeof(ComponentObject3D),
Action = (sceneContext) =>
{
@ -249,7 +249,7 @@ namespace MatterHackers.MatterControl
&& !componentObject.ProOnly;
},
Icon = (theme) => StaticData.Instance.LoadIcon("scale_32x32.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "A component must be selected".Localize().Stars(),
HelpTextGetter = () => "A component must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && (sceneContext.Scene.SelectedItem is ComponentObject3D),
};
}
@ -286,7 +286,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("ImageConverter")
{
OperationType = typeof(ImageObject3D),
TitleResolver = () => "Image Converter".Localize(),
TitleGetter = () => "Image Converter".Localize(),
ResultType = typeof(ComponentObject3D),
Action = (sceneContext) =>
{
@ -340,7 +340,7 @@ namespace MatterHackers.MatterControl
imageObject.Invalidate(InvalidateType.Image);
},
Icon = (theme) => StaticData.Instance.LoadIcon("image_converter.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "An image must be selected".Localize().Stars(),
HelpTextGetter = () => "An image must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && sceneContext.Scene.SelectedItem is ImageObject3D,
};
}
@ -350,7 +350,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("ImageToPath")
{
OperationType = typeof(ImageObject3D),
TitleResolver = () => "Image to Path".Localize(),
TitleGetter = () => "Image to Path".Localize(),
ResultType = typeof(ImageToPathObject3D_2),
Action = (sceneContext) =>
{
@ -375,7 +375,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("image_to_path.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "An image must be selected".Localize().Stars(),
HelpTextGetter = () => "An image must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && sceneContext.Scene.SelectedItem is ImageObject3D,
};
}
@ -385,7 +385,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("InflatePath")
{
OperationType = typeof(IPathObject),
TitleResolver = () => "Inflate Path".Localize(),
TitleGetter = () => "Inflate Path".Localize(),
ResultType = typeof(InflatePathObject3D),
Action = (sceneContext) =>
{
@ -405,7 +405,7 @@ namespace MatterHackers.MatterControl
inflatePath.Invalidate(InvalidateType.Properties);
},
Icon = (theme) => StaticData.Instance.LoadIcon("inflate_path.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "A path must be selected".Localize().Stars(),
HelpTextGetter = () => "A path must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && sceneContext.Scene.SelectedItem is IPathObject,
};
}
@ -415,7 +415,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("LinearExtrude")
{
OperationType = typeof(IPathObject),
TitleResolver = () => "Linear Extrude".Localize(),
TitleGetter = () => "Linear Extrude".Localize(),
ResultType = typeof(LinearExtrudeObject3D),
Action = (sceneContext) =>
{
@ -439,7 +439,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("linear_extrude.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "A path must be selected".Localize().Stars(),
HelpTextGetter = () => "A path must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && sceneContext.Scene.SelectedItem is IPathObject,
};
}
@ -449,7 +449,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("Revolve")
{
OperationType = typeof(IPathObject),
TitleResolver = () => "Revolve".Localize(),
TitleGetter = () => "Revolve".Localize(),
ResultType = typeof(RevolveObject3D),
Action = (sceneContext) =>
{
@ -473,7 +473,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("revolve.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "A path must be selected".Localize().Stars(),
HelpTextGetter = () => "A path must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && sceneContext.Scene.SelectedItem is IPathObject,
};
}
@ -482,7 +482,7 @@ namespace MatterHackers.MatterControl
{
return new SceneOperation("Make Component")
{
TitleResolver = () => "Make Component".Localize(),
TitleGetter = () => "Make Component".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -517,7 +517,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("component.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) =>
{
var sceneItem = sceneContext.Scene.SelectedItem;
@ -534,13 +534,13 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(MirrorObject3D_2),
TitleResolver = () => "Mirror".Localize(),
TitleGetter = () => "Mirror".Localize(),
Action = (sceneContext) =>
{
new MirrorObject3D_2().WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("mirror_32x32.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -550,7 +550,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("OutlinePath")
{
OperationType = typeof(IPathObject),
TitleResolver = () => "Outline Path".Localize(),
TitleGetter = () => "Outline Path".Localize(),
ResultType = typeof(OutlinePathObject3D),
Action = (sceneContext) =>
{
@ -570,7 +570,7 @@ namespace MatterHackers.MatterControl
outlinePath.Invalidate(InvalidateType.Properties);
},
Icon = (theme) => StaticData.Instance.LoadIcon("outline.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "A path must be selected".Localize().Stars(),
HelpTextGetter = () => "A path must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && sceneContext.Scene.SelectedItem is IPathObject,
};
}
@ -581,13 +581,13 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(RotateObject3D_2),
TitleResolver = () => "Rotate".Localize(),
TitleGetter = () => "Rotate".Localize(),
Action = (sceneContext) =>
{
new RotateObject3D_2().WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon(Path.Combine("ViewTransformControls", "rotate.png"), 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null,
};
}
@ -598,13 +598,13 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(ScaleObject3D_3),
TitleResolver = () => "Scale".Localize(),
TitleGetter = () => "Scale".Localize(),
Action = (sceneContext) =>
{
new ScaleObject3D_3().WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("scale_32x32.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null,
};
}
@ -614,7 +614,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("SmoothPath")
{
OperationType = typeof(IPathObject),
TitleResolver = () => "Smooth Path".Localize(),
TitleGetter = () => "Smooth Path".Localize(),
ResultType = typeof(SmoothPathObject3D),
Action = (sceneContext) =>
{
@ -634,7 +634,7 @@ namespace MatterHackers.MatterControl
smoothPath.Invalidate(InvalidateType.Properties);
},
Icon = (theme) => StaticData.Instance.LoadIcon("smooth_path.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "A path must be selected".Localize().Stars(),
HelpTextGetter = () => "A path must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && sceneContext.Scene.SelectedItem is IPathObject,
};
}
@ -645,13 +645,13 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(TranslateObject3D),
TitleResolver = () => "Translate".Localize(),
TitleGetter = () => "Translate".Localize(),
Action = (sceneContext) =>
{
new TranslateObject3D().WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon(Path.Combine("ViewTransformControls", "translate.png"), 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null,
};
}
@ -662,7 +662,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(ArrayAdvancedObject3D),
TitleResolver = () => "Advanced Array".Localize(),
TitleGetter = () => "Advanced Array".Localize(),
Action = (sceneContext) =>
{
var array = new ArrayAdvancedObject3D
@ -672,7 +672,7 @@ namespace MatterHackers.MatterControl
array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem);
},
Icon = (theme) => StaticData.Instance.LoadIcon("array_advanced.png", 16, 16).SetPreMultiply(),
HelpTextResolver = () => "A single part must be selected".Localize().Stars(),
HelpTextGetter = () => "A single part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && !(sceneContext.Scene.SelectedItem is SelectionGroupObject3D),
};
}
@ -683,7 +683,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(AlignObject3D),
TitleResolver = () => "Align".Localize(),
TitleGetter = () => "Align".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -692,7 +692,7 @@ namespace MatterHackers.MatterControl
align.AddSelectionAsChildren(scene, selectedItem);
},
Icon = (theme) => StaticData.Instance.LoadIcon("align_left_dark.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 2 parts must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem is SelectionGroupObject3D,
};
}
@ -701,12 +701,12 @@ namespace MatterHackers.MatterControl
{
return new SceneOperation("ArrangeAllParts")
{
TitleResolver = () => "Arrange All Parts".Localize(),
TitleGetter = () => "Arrange All Parts".Localize(),
Action = async (sceneContext) =>
{
await sceneContext.Scene.AutoArrangeChildren(new Vector3(sceneContext.BedCenter)).ConfigureAwait(false);
},
HelpTextResolver = () => "No part to arrange".Localize().Stars(),
HelpTextGetter = () => "No part to arrange".Localize().Stars(),
IsEnabled = (sceneContext) =>
{
return sceneContext.EditableScene && sceneContext.Scene.VisibleMeshes().Any();
@ -765,7 +765,7 @@ namespace MatterHackers.MatterControl
new SceneSelectionSeparator(),
new OperationGroup("Transform")
{
TitleResolver = () => "Transform".Localize(),
TitleGetter = () => "Transform".Localize(),
InitialSelectionIndex = 2,
Operations = new List<SceneOperation>()
{
@ -777,7 +777,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Placement")
{
TitleResolver = () => "Placement".Localize(),
TitleGetter = () => "Placement".Localize(),
Operations = new List<SceneOperation>()
{
AlignOperation(),
@ -786,7 +786,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Reshape")
{
TitleResolver = () => "Reshape".Localize(),
TitleGetter = () => "Reshape".Localize(),
Operations = new List<SceneOperation>()
{
CurveOperation(),
@ -801,7 +801,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Image")
{
TitleResolver = () => "Image".Localize(),
TitleGetter = () => "Image".Localize(),
Operations = new List<SceneOperation>()
{
ImageConverterOperation(),
@ -810,7 +810,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Path")
{
TitleResolver = () => "Path".Localize(),
TitleGetter = () => "Path".Localize(),
Visible = OperationGroup.GetVisible("Path", false),
Operations = new List<SceneOperation>()
{
@ -824,7 +824,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Merge")
{
TitleResolver = () => "Merge".Localize(),
TitleGetter = () => "Merge".Localize(),
InitialSelectionIndex = 1,
Operations = new List<SceneOperation>()
{
@ -836,7 +836,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Duplication")
{
TitleResolver = () => "Duplication".Localize(),
TitleGetter = () => "Duplication".Localize(),
Operations = new List<SceneOperation>()
{
LinearArrayOperation(),
@ -846,7 +846,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Mesh")
{
TitleResolver = () => "Mesh".Localize(),
TitleGetter = () => "Mesh".Localize(),
InitialSelectionIndex = 1,
Operations = new List<SceneOperation>()
{
@ -856,7 +856,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Printing")
{
TitleResolver = () => "Printing".Localize(),
TitleGetter = () => "Printing".Localize(),
Visible = OperationGroup.GetVisible("Path", false),
Operations = new List<SceneOperation>()
{
@ -866,7 +866,7 @@ namespace MatterHackers.MatterControl
},
new OperationGroup("Design Apps")
{
TitleResolver = () => "Design Apps".Localize(),
TitleGetter = () => "Design Apps".Localize(),
Visible = OperationGroup.GetVisible("Path", false),
Operations = new List<SceneOperation>()
{
@ -940,7 +940,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(CombineObject3D_2),
TitleResolver = () => "Combine".Localize(),
TitleGetter = () => "Combine".Localize(),
Action = (sceneContext) =>
{
#if DEBUG
@ -955,7 +955,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("combine.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 2 parts must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => BooleanCandidate(sceneContext.Scene.SelectedItem, true),
};
}
@ -966,14 +966,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(CurveObject3D_3),
TitleResolver = () => "Curve".Localize(),
TitleGetter = () => "Curve".Localize(),
Action = (sceneContext) =>
{
var curve = new CurveObject3D_3();
curve.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("curve.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -983,7 +983,7 @@ namespace MatterHackers.MatterControl
return new SceneOperation("Dual Extrusion Align")
{
OperationType = typeof(IObject3D),
TitleResolver = () => "Dual Extrusion Align".Localize(),
TitleGetter = () => "Dual Extrusion Align".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -1009,7 +1009,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("dual_align.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 2 parts must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem is SelectionGroupObject3D,
};
}
@ -1018,9 +1018,9 @@ namespace MatterHackers.MatterControl
{
return new SceneOperation("Duplicate")
{
TitleResolver = () => "Duplicate".Localize(),
TitleGetter = () => "Duplicate".Localize(),
Action = (sceneContext) => sceneContext.DuplicateItem(5),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null,
Icon = (theme) => StaticData.Instance.LoadIcon("duplicate.png", 16, 16).SetPreMultiply(),
};
@ -1032,7 +1032,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(FitToBoundsObject3D_3),
TitleResolver = () => "Fit to Bounds".Localize(),
TitleGetter = () => "Fit to Bounds".Localize(),
Action = async (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -1056,7 +1056,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(FitToCylinderObject3D),
TitleResolver = () => "Fit to Cylinder".Localize(),
TitleGetter = () => "Fit to Cylinder".Localize(),
Action = async (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -1080,7 +1080,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(SelectionGroupObject3D),
ResultType = typeof(GroupObject3D),
TitleResolver = () => "Group".Localize(),
TitleGetter = () => "Group".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -1111,7 +1111,7 @@ namespace MatterHackers.MatterControl
scene.SelectedItem = newGroup;
},
HelpTextResolver = () => "At least 2 parts must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene is InteractiveScene scene
&& scene.SelectedItem != null
&& scene.SelectedItem is SelectionGroupObject3D
@ -1126,14 +1126,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(HollowOutObject3D),
TitleResolver = () => "Hollow Out".Localize(),
TitleGetter = () => "Hollow Out".Localize(),
Action = (sceneContext) =>
{
var hollowOut = new HollowOutObject3D();
hollowOut.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("hollow.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1144,7 +1144,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(IntersectionObject3D_2),
TitleResolver = () => "Intersect".Localize(),
TitleGetter = () => "Intersect".Localize(),
Action = (sceneContext) =>
{
#if DEBUG
@ -1159,7 +1159,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("intersect.png", 16, 16),
HelpTextResolver = () => "At least 2 parts must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => BooleanCandidate(sceneContext.Scene.SelectedItem, true),
};
}
@ -1182,7 +1182,7 @@ namespace MatterHackers.MatterControl
{
return new SceneOperation("Lay Flat")
{
TitleResolver = () => "Lay Flat".Localize(),
TitleGetter = () => "Lay Flat".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -1198,7 +1198,7 @@ namespace MatterHackers.MatterControl
}
}
},
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null,
Icon = (theme) => StaticData.Instance.LoadIcon("lay_flat.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
};
@ -1210,7 +1210,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(ArrayLinearObject3D),
TitleResolver = () => "Linear Array".Localize(),
TitleGetter = () => "Linear Array".Localize(),
Action = (sceneContext) =>
{
var array = new ArrayLinearObject3D
@ -1220,7 +1220,7 @@ namespace MatterHackers.MatterControl
array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem);
},
Icon = (theme) => StaticData.Instance.LoadIcon("array_linear.png", 16, 16).SetPreMultiply(),
HelpTextResolver = () => "A single part must be selected".Localize().Stars(),
HelpTextGetter = () => "A single part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && !(sceneContext.Scene.SelectedItem is SelectionGroupObject3D),
};
}
@ -1231,14 +1231,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(PinchObject3D_3),
TitleResolver = () => "Pinch".Localize(),
TitleGetter = () => "Pinch".Localize(),
Action = (sceneContext) =>
{
var pinch = new PinchObject3D_3();
pinch.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("pinch.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1249,14 +1249,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(PlaneCutObject3D),
TitleResolver = () => "Plane Cut".Localize(),
TitleGetter = () => "Plane Cut".Localize(),
Action = (sceneContext) =>
{
var cut = new PlaneCutObject3D();
cut.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("plane_cut.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1267,14 +1267,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(PlaneCutObject3D),
TitleResolver = () => "Find Slice".Localize(),
TitleGetter = () => "Find Slice".Localize(),
Action = (sceneContext) =>
{
var cut = new FindSliceObject3D();
cut.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("plane_cut.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1285,7 +1285,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(ArrayRadialObject3D),
TitleResolver = () => "Radial Array".Localize(),
TitleGetter = () => "Radial Array".Localize(),
Action = (sceneContext) =>
{
var array = new ArrayRadialObject3D
@ -1295,7 +1295,7 @@ namespace MatterHackers.MatterControl
array.AddSelectionAsChildren(sceneContext.Scene, sceneContext.Scene.SelectedItem);
},
Icon = (theme) => StaticData.Instance.LoadIcon("array_radial.png", 16, 16).SetPreMultiply(),
HelpTextResolver = () => "A single part must be selected".Localize().Stars(),
HelpTextGetter = () => "A single part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => sceneContext.Scene.SelectedItem != null && !(sceneContext.Scene.SelectedItem is SelectionGroupObject3D),
};
}
@ -1306,14 +1306,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(DecimateObject3D),
TitleResolver = () => "Reduce".Localize(),
TitleGetter = () => "Reduce".Localize(),
Action = (sceneContext) =>
{
var hollowOut = new DecimateObject3D();
hollowOut.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("reduce.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1345,11 +1345,11 @@ namespace MatterHackers.MatterControl
return new SceneOperation("Remove")
{
Action = (sceneContext) => sceneContext.Scene.DeleteSelection(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
Icon = (theme) => StaticData.Instance.LoadIcon("remove.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
ShowInModifyMenu = (sceneContext) => false,
TitleResolver = () => "Remove".Localize(),
TitleGetter = () => "Remove".Localize(),
};
}
@ -1359,14 +1359,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(RepairObject3D),
TitleResolver = () => "Repair".Localize(),
TitleGetter = () => "Repair".Localize(),
Action = (sceneContext) =>
{
var hollowOut = new RepairObject3D();
hollowOut.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("repair.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1377,10 +1377,10 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(SubtractAndReplaceObject3D_2),
TitleResolver = () => "Subtract & Replace".Localize(),
TitleGetter = () => "Subtract & Replace".Localize(),
Action = (sceneContext) => new SubtractAndReplaceObject3D_2().WrapSelectedItemAndSelect(sceneContext.Scene),
Icon = (theme) => StaticData.Instance.LoadIcon("subtract_and_replace.png", 16, 16).SetPreMultiply(),
HelpTextResolver = () => "At least 2 parts must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => BooleanCandidate(sceneContext.Scene.SelectedItem, false),
};
}
@ -1391,7 +1391,7 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(SubtractObject3D_2),
TitleResolver = () => "Subtract".Localize(),
TitleGetter = () => "Subtract".Localize(),
Action = (sceneContext) =>
{
#if DEBUG
@ -1406,7 +1406,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("subtract.png", 16, 16).SetPreMultiply(),
HelpTextResolver = () => "At least 2 parts must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 2 parts must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => BooleanCandidate(sceneContext.Scene.SelectedItem, true),
};
}
@ -1415,7 +1415,7 @@ namespace MatterHackers.MatterControl
{
return new SceneOperation("Convert to Support")
{
TitleResolver = () => "Convert to Support".Localize(),
TitleGetter = () => "Convert to Support".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -1436,7 +1436,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("support.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1445,7 +1445,7 @@ namespace MatterHackers.MatterControl
{
return new SceneOperation("Convert to Wipe Tower")
{
TitleResolver = () => "Convert to Wipe Tower".Localize(),
TitleGetter = () => "Convert to Wipe Tower".Localize(),
Action = (sceneContext) =>
{
var scene = sceneContext.Scene;
@ -1467,7 +1467,7 @@ namespace MatterHackers.MatterControl
}
},
Icon = (theme) => StaticData.Instance.LoadIcon("wipe_tower.png", 16, 16).SetToColor(theme.TextColor).SetPreMultiply(),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1478,14 +1478,14 @@ namespace MatterHackers.MatterControl
{
OperationType = typeof(IObject3D),
ResultType = typeof(TwistObject3D),
TitleResolver = () => "Twist".Localize(),
TitleGetter = () => "Twist".Localize(),
Action = (sceneContext) =>
{
var twist = new TwistObject3D();
twist.WrapSelectedItemAndSelect(sceneContext.Scene);
},
Icon = (theme) => StaticData.Instance.LoadIcon("twist.png", 16, 16).SetToColor(theme.TextColor),
HelpTextResolver = () => "At least 1 part must be selected".Localize().Stars(),
HelpTextGetter = () => "At least 1 part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) => IsMeshObject(sceneContext.Scene.SelectedItem),
};
}
@ -1494,9 +1494,9 @@ namespace MatterHackers.MatterControl
{
return new SceneOperation("Ungroup")
{
TitleResolver = () => "Ungroup".Localize(),
TitleGetter = () => "Ungroup".Localize(),
Action = (sceneContext) => sceneContext.Scene.UngroupSelection(),
HelpTextResolver = () => "A single part must be selected".Localize().Stars(),
HelpTextGetter = () => "A single part must be selected".Localize().Stars(),
IsEnabled = (sceneContext) =>
{
var selectedItem = sceneContext.Scene.SelectedItem;

View file

@ -55,13 +55,13 @@ namespace MatterHackers.Agg.UI
public Func<ISceneContext, bool> IsEnabled { get; set; } = (sceneContext) => true;
public Func<string> HelpTextResolver { get; set; }
public Func<string> HelpTextGetter { get; set; }
public string HelpText => this.HelpTextResolver?.Invoke();
public string HelpText => this.HelpTextGetter?.Invoke();
public Func<string> TitleResolver { get; set; }
public Func<string> TitleGetter { get; set; }
public string Title => this.TitleResolver?.Invoke();
public string Title => this.TitleGetter?.Invoke();
/// <summary>
/// Gets or sets the type that this operation can be applied to

View file

@ -48,10 +48,10 @@ namespace MatterHackers.MatterControl.Library
var libraryItems = new List<GeneratorItem>()
{
new GeneratorItem(
() => "Braille".Localize(),
"Braille".Localize(),
async () => await BrailleObject3D.Create()),
new GeneratorItem(
() => "Braille Card".Localize(),
"Braille Card".Localize(),
async () => await BrailleCardObject3D.Create()),
};

View file

@ -48,10 +48,10 @@ namespace MatterHackers.MatterControl.Library
var libraryItems = new List<GeneratorItem>()
{
new GeneratorItem(
() => "Tee".Localize(),
"Tee".Localize(),
async () => await TeeObject3D.Create()),
new GeneratorItem(
() => "Elbow".Localize(),
"Elbow".Localize(),
async () => await ElbowObject3D.Create()),
};

View file

@ -74,7 +74,7 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane
SceneOperations.AddOperation(
new SceneOperation("Lithophane")
{
TitleResolver = () => "Lithophane".Localize(),
TitleGetter = () => "Lithophane".Localize(),
OperationType = typeof(ImageObject3D),
ResultType = typeof(LithophaneObject3D),
Action = (sceneContext) =>
@ -87,7 +87,7 @@ namespace MatterHackers.MatterControl.Plugins.Lithophane
}
},
IsEnabled = (sceneContext) => sceneContext?.Scene?.SelectedItem is ImageObject3D,
HelpTextResolver = () => "An image must be selected".Localize().Stars(),
HelpTextGetter = () => "An image must be selected".Localize().Stars(),
ShowInModifyMenu = (sceneContext) => sceneContext?.Scene?.SelectedItem is ImageObject3D,
Icon = (theme) => StaticData.Instance.LoadIcon("lithophane.png", 16, 16).SetToColor(theme.TextColor)
},

View file

@ -48,7 +48,20 @@ namespace MatterHackers.MatterControl.Library
public string ID { get; set; } = Guid.NewGuid().ToString();
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public string FileName => $"{this.Name}.{this.ContentType}";

View file

@ -42,12 +42,35 @@ namespace MatterHackers.MatterControl.Library
public InMemoryLibraryItem(IObject3D object3D)
{
this.object3D = object3D;
this.Name = object3D.Name ?? "Unknown".Localize();
if ((string.IsNullOrEmpty(object3D.Name) || object3D.Name.StartsWith("Workspace 20"))
&& object3D.Children.Count == 1
&& !string.IsNullOrEmpty(object3D.Children[0].Name))
{
this.Name = object3D.Children[0].Name;
}
else
{
this.Name = string.IsNullOrEmpty(object3D.Name) ? "Default".Localize() : object3D.Name;
}
}
public string ID => object3D.ID;
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public string FileName => $"{this.Name}.{this.ContentType}";

View file

@ -36,7 +36,9 @@ namespace MatterHackers.MatterControl.Library
{
string ID { get; }
string Name { get; }
string Name { get; set; }
event EventHandler NameChanged;
bool IsProtected { get; }

View file

@ -41,8 +41,6 @@ namespace MatterHackers.MatterControl.Library
void Remove(IEnumerable<ILibraryItem> items);
void Rename(ILibraryItem item, string revisedName);
/// <summary>
/// Move the given items from the source container to this container
/// </summary>

View file

@ -35,7 +35,7 @@ using MatterHackers.Localizations;
namespace MatterHackers.MatterControl.Library
{
public static class LibraryExtensionMethods
public static class LibraryExtensionMethods
{
public static async Task<IObject3D> CreateContent(this ILibraryItem libraryItem, Action<double, string> progressReporter)
{
@ -101,28 +101,23 @@ namespace MatterHackers.MatterControl.Library
return contentProvider?.CreateItem(item, reporter);
}
public static void Rename(this ILibraryContainer libraryContainer, ILibraryItem libraryItem)
public static void Rename(this ILibraryItem item)
{
if (libraryItem == null)
if (item == null)
{
return;
}
var contentProvider = ApplicationController.Instance.Library.GetContentProvider(libraryItem) as ISceneContentProvider;
DialogWindow.Show(
new InputBoxPage(
"Rename Item".Localize(),
"Name".Localize(),
libraryItem.Name,
item.Name,
"Enter New Name Here".Localize(),
"Rename".Localize(),
(newName) =>
{
if (libraryContainer is ILibraryWritableContainer writableContainer)
{
writableContainer.Rename(libraryItem, newName);
}
item.Name = newName;
}));
}
}

View file

@ -0,0 +1,43 @@
/*
Copyright (c) 2018, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
namespace MatterHackers.MatterControl.Library
{
public class LibraryItemNameChangedEvent : EventArgs
{
public LibraryItemNameChangedEvent(string id)
{
this.ID = id;
}
public string ID { get; }
}
}

View file

@ -47,7 +47,20 @@ namespace MatterHackers.MatterControl.Library
public string ID => Guid.NewGuid().ToString();
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public string FileName => $"{this.Name}.{this.ContentType}";

View file

@ -35,7 +35,20 @@ namespace MatterHackers.MatterControl.Library
{
public string ID { get; } = Guid.NewGuid().ToString();
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public bool IsProtected => false;

View file

@ -38,21 +38,19 @@ namespace MatterHackers.MatterControl.Library
{
private readonly Func<ILibraryContainer> containerCreator;
private readonly Func<string> nameResolver;
private readonly ImageBuffer thumbnail;
private readonly ImageBuffer microIcon;
private readonly Func<bool> visibilityResolver;
private readonly Func<bool> visibilityGetter;
public DynamicContainerLink(Func<string> nameResolver,
public DynamicContainerLink(string name,
ImageBuffer thumbnail,
Func<ILibraryContainer> creator = null,
Func<bool> visibilityResolver = null)
: this(nameResolver, thumbnail, null, creator, visibilityResolver)
: this(name, thumbnail, null, creator, visibilityResolver)
{
}
public DynamicContainerLink(Func<string> nameResolver,
public DynamicContainerLink(string name,
ImageBuffer thumbnail,
ImageBuffer microIcon,
Func<ILibraryContainer> creator = null,
@ -69,9 +67,9 @@ namespace MatterHackers.MatterControl.Library
microIcon.SetPreMultiply();
}
this.nameResolver = nameResolver;
this.Name = name;
this.containerCreator = creator;
this.visibilityResolver = visibilityResolver ?? (() => true);
this.visibilityGetter = visibilityResolver ?? (() => true);
}
public string Category { get; set; }
@ -86,9 +84,22 @@ namespace MatterHackers.MatterControl.Library
public bool IsReadOnly { get; set; } = false;
public bool IsVisible => this.visibilityResolver();
public bool IsVisible => this.visibilityGetter();
public string Name => nameResolver?.Invoke();
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public Task<ILibraryContainer> GetContainer(Action<double, string> reportProgress)
{

View file

@ -29,17 +29,17 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl.Library
{
public class FileSystemContainer : WritableContainer, ICustomSearch
public class FileSystemContainer : WritableContainer, ICustomSearch
{
private FileSystemWatcher directoryWatcher;
@ -78,6 +78,13 @@ namespace MatterHackers.MatterControl.Library
}
}
public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)
{
#if DEBUG
throw new NotImplementedException();
#endif
}
public override ICustomSearch CustomSearch { get; }
public string FullPath { get; protected set; }
@ -272,47 +279,6 @@ namespace MatterHackers.MatterControl.Library
}
}
public override void Rename(ILibraryItem item, string revisedName)
{
if (item is DirectoryContainerLink directoryLink)
{
if (Directory.Exists(directoryLink.Path))
{
Process.Start(this.FullPath);
}
}
else if (item is FileSystemFileItem fileItem)
{
string sourceFile = fileItem.Path;
if (File.Exists(sourceFile))
{
string extension = Path.GetExtension(sourceFile);
string destFile = Path.Combine(Path.GetDirectoryName(sourceFile), revisedName);
destFile = Path.ChangeExtension(destFile, extension);
File.Move(sourceFile, destFile);
fileItem.Path = destFile;
this.ReloadContent();
}
}
else if (item is LocalZipContainerLink zipFile)
{
string sourceFile = zipFile.Path;
if (File.Exists(sourceFile))
{
string extension = Path.GetExtension(sourceFile);
string destFile = Path.Combine(Path.GetDirectoryName(sourceFile), revisedName);
destFile = Path.ChangeExtension(destFile, extension);
File.Move(sourceFile, destFile);
this.ReloadContent();
}
}
}
private void DirectoryContentsChanged(object sender, EventArgs e)
{
// Flag for reload

View file

@ -38,8 +38,6 @@ namespace MatterHackers.MatterControl.Library
/// </summary>
public class FileSystemItem : ILibraryItem
{
private string fileName;
public FileSystemItem(string path)
{
this.Path = path;
@ -83,21 +81,78 @@ namespace MatterHackers.MatterControl.Library
public virtual bool LocalContentExists => true;
public event EventHandler NameChanged;
public virtual string Name
{
get
{
if (fileName == null)
{
fileName = System.IO.Path.GetFileName(this.Path);
}
return fileName;
return System.IO.Path.GetFileName(this.Path);
}
set
{
fileName = value;
if (Name != value)
{
string sourceFile = this.Path;
if (File.Exists(sourceFile))
{
string extension = System.IO.Path.GetExtension(sourceFile);
string destFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceFile), value);
destFile = System.IO.Path.ChangeExtension(destFile, extension);
if (sourceFile != destFile)
{
File.Move(sourceFile, destFile);
this.Path = destFile;
ApplicationController.Instance.MainView.Broadcast("ILibraryItem Name Changed", new LibraryItemNameChangedEvent(this.ID));
}
}
NameChanged?.Invoke(this, EventArgs.Empty);
}
/*
if (item is DirectoryContainerLink directoryLink)
{
if (Directory.Exists(directoryLink.Path))
{
Process.Start(this.FullPath);
}
}
else if (item is FileSystemFileItem fileItem)
{
string sourceFile = fileItem.Path;
if (File.Exists(sourceFile))
{
string extension = Path.GetExtension(sourceFile);
string destFile = Path.Combine(Path.GetDirectoryName(sourceFile), revisedName);
destFile = Path.ChangeExtension(destFile, extension);
File.Move(sourceFile, destFile);
fileItem.Path = destFile;
this.ReloadContent();
}
}
else if (item is LocalZipContainerLink zipFile)
{
string sourceFile = zipFile.Path;
if (File.Exists(sourceFile))
{
string extension = Path.GetExtension(sourceFile);
string destFile = Path.Combine(Path.GetDirectoryName(sourceFile), revisedName);
destFile = Path.ChangeExtension(destFile, extension);
File.Move(sourceFile, destFile);
this.ReloadContent();
}
}
*/
}
}

View file

@ -46,6 +46,19 @@ namespace MatterHackers.MatterControl.Library
public bool IsVisible => true;
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
}
}

View file

@ -69,22 +69,20 @@ namespace MatterHackers.MatterControl.Library
public class GeneratorItem : ILibraryObject3D
{
private Func<string> nameResolver;
/// <summary>
/// The delegate responsible for producing the item
/// </summary>
private Func<Task<IObject3D>> collector;
public GeneratorItem(Func<string> nameResolver)
public GeneratorItem(string name)
{
this.nameResolver = nameResolver;
this.Name = name;
this.IsProtected = true;
}
public GeneratorItem(Func<string> nameResolver, Func<Task<IObject3D>> collector, string category = null)
public GeneratorItem(string name, Func<Task<IObject3D>> collector, string category = null)
{
this.nameResolver = nameResolver;
this.Name = name;
this.collector = collector;
this.Category = category;
//this.Color = ColorRange.NextColor();
@ -94,7 +92,20 @@ namespace MatterHackers.MatterControl.Library
public string Category { get; set; }
public string Name => nameResolver?.Invoke();
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public string ContentType { get; set; } = "mcx";

View file

@ -325,7 +325,13 @@ namespace MatterHackers.MatterControl.Library
public bool LocalContentExists => true;
public string Name => this.FileName;
public event EventHandler NameChanged;
public string Name
{
get => this.FileName;
set { } // do nothing (can't rename)
}
public Task<StreamAndLength> GetStream(Action<double, string> progress)
{
@ -362,7 +368,20 @@ namespace MatterHackers.MatterControl.Library
.GetLongHashCode(Path
.GetLongHashCode()))).ToString();
public string Name { get; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public bool IsProtected => false;

View file

@ -68,7 +68,9 @@ namespace MatterHackers.MatterControl.Library
public virtual bool LocalContentExists => File.Exists(CachePath);
public string Name
public event EventHandler NameChanged;
public string Name
{
get
{
@ -79,6 +81,11 @@ namespace MatterHackers.MatterControl.Library
return FileName;
}
set
{
// do nothing (can't rename)
}
}
public string Url { get; }

View file

@ -54,33 +54,33 @@ namespace MatterHackers.MatterControl.Library
Items = new SafeList<ILibraryItem>(oemParts.Select(s => new StaticDataItem(s)));
Items.Add(new GeneratorItem(
() => "Set Temperature".Localize(),
"Set Temperature".Localize(),
async () => await SetTemperatureObject3D.Create())
{
Category = this.Name
});
Items.Add(new GeneratorItem(
() => "PLA Temperature Tower".Localize(),
"PLA Temperature Tower".Localize(),
async () => await TemperatureTowerObject3D.Create(220))
{
Category = this.Name
});
Items.Add(new GeneratorItem(
() => "ABS Temperature Tower".Localize(),
"ABS Temperature Tower".Localize(),
async () => await TemperatureTowerObject3D.Create(250))
{
Category = this.Name
});
Items.Add(new GeneratorItem(
() => "PETG Temperature Tower".Localize(),
"PETG Temperature Tower".Localize(),
async () => await TemperatureTowerObject3D.Create(260))
{
Category = this.Name
});
#if DEBUG
Items.Add(new GeneratorItem(
() => "XY Calibration".Localize(),
"XY Calibration".Localize(),
async () => await XyCalibrationFaceObject3D.Create())
{
Category = this.Name
@ -113,7 +113,16 @@ namespace MatterHackers.MatterControl.Library
public string ID => agg_basics.GetLongHashCode(AssetPath).ToString();
public string Name => this.FileName;
public event EventHandler NameChanged;
public string Name
{
get => this.FileName;
set
{
// do nothing (can't rename)
}
}
public bool IsProtected => true;

View file

@ -55,7 +55,7 @@ namespace MatterHackers.MatterControl.Library
{
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Local Library".Localize(),
"Local Library".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "local_library_icon.png")),
() => new SqliteLibraryContainer(rootLibraryCollection.Id)));
@ -63,7 +63,7 @@ namespace MatterHackers.MatterControl.Library
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Calibration Parts".Localize(),
"Calibration Parts".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "calibration_library_icon.png")),
() => new CalibrationPartsContainer())
@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl.Library
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Primitives".Localize(),
"Primitives".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "primitives_library_icon.png")),
() => new PrimitivesContainer())
@ -91,7 +91,7 @@ namespace MatterHackers.MatterControl.Library
{
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Print Queue".Localize(),
"Print Queue".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "queue_icon.png")),
() => new PrintQueueContainer()));
@ -100,7 +100,7 @@ namespace MatterHackers.MatterControl.Library
#if DEBUG
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Pipe Works".Localize(),
"Pipe Works".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
null,
() => new PipeWorksContainer())
@ -112,7 +112,7 @@ namespace MatterHackers.MatterControl.Library
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Experimental".Localize(),
"Experimental".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
null,
() => new DynamicContainer()
@ -120,19 +120,19 @@ namespace MatterHackers.MatterControl.Library
Items = new SafeList<ILibraryItem>()
{
new GeneratorItem(
() => "Calibration Tab".Localize(),
"Calibration Tab".Localize(),
async () => await XyCalibrationTabObject3D.Create())
{ DateCreated = new System.DateTime(index++) },
new GeneratorItem(
() => "Calibration Face".Localize(),
"Calibration Face".Localize(),
async () => await XyCalibrationFaceObject3D.Create())
{ DateCreated = new System.DateTime(index++) },
new GeneratorItem(
() => "Text2".Localize(),
"Text2".Localize(),
async () => await TextPathObject3D.Create())
{ DateCreated = new System.DateTime(index++) },
new GeneratorItem(
() => "Path".Localize(),
"Path".Localize(),
() =>
{
var storage = new VertexStorage();

View file

@ -55,7 +55,7 @@ namespace MatterHackers.MatterControl.Library
{
this.ChildContainers = new SafeList<ILibraryContainerLink>();
this.Items = new SafeList<ILibraryItem>();
this.IsProtected = true;
this.IsProtected = false;
DefaultSort = new LibrarySortBehavior()
{

View file

@ -58,65 +58,65 @@ namespace MatterHackers.MatterControl.Library
var libraryItems = new List<GeneratorItem>()
{
new GeneratorItem(
() => "Cube".Localize(),
"Cube".Localize(),
async () => await CubeObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Pyramid".Localize(),
"Pyramid".Localize(),
async () => await PyramidObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Wedge".Localize(),
"Wedge".Localize(),
async () => await WedgeObject3D_2.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Half Wedge".Localize(),
"Half Wedge".Localize(),
async () => await HalfWedgeObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Text".Localize(),
"Text".Localize(),
async () => await TextObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Cylinder".Localize(),
"Cylinder".Localize(),
async () => await CylinderObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Cone".Localize(),
"Cone".Localize(),
async () => await ConeObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Half Cylinder".Localize(),
"Half Cylinder".Localize(),
async () => await HalfCylinderObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Torus".Localize(),
"Torus".Localize(),
async () => await TorusObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Ring".Localize(),
"Ring".Localize(),
async () => await RingObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Sphere".Localize(),
"Sphere".Localize(),
async () => await SphereObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Half Sphere".Localize(),
"Half Sphere".Localize(),
async () => await HalfSphereObject3D.Create())
{ DateCreated = new DateTime(index++) },
#if DEBUG
new GeneratorItem(
() => "SCAD Script".Localize(),
"SCAD Script".Localize(),
async () => await OpenScadScriptObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Dual Contouring".Localize(),
"Dual Contouring".Localize(),
async () => await DualContouringObject3D.Create())
{ DateCreated = new DateTime(index++) },
#endif
new GeneratorItem(
() => "Image Converter".Localize(),
"Image Converter".Localize(),
() =>
{
// Construct an image
@ -142,15 +142,15 @@ namespace MatterHackers.MatterControl.Library
})
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Measure Tool".Localize(),
"Measure Tool".Localize(),
async () => await MeasureToolObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Description".Localize(),
"Description".Localize(),
async () => await DescriptionObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Variable Sheet".Localize(),
"Variable Sheet".Localize(),
async () => await SheetObject3D.Create())
{ DateCreated = new DateTime(index++) },
};
@ -166,7 +166,7 @@ namespace MatterHackers.MatterControl.Library
#if DEBUG
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Primitives 2D".Localize(),
"Primitives 2D".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "primitives_library_icon.png")),
() => new Primitives2DContainer())
@ -198,35 +198,35 @@ namespace MatterHackers.MatterControl.Library
var libraryItems = new List<GeneratorItem>()
{
new GeneratorItem(
() => "Box".Localize(),
"Box".Localize(),
async () => await BoxPathObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Triangle".Localize(),
"Triangle".Localize(),
async () => await PyramidObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Trapezoid".Localize(),
"Trapezoid".Localize(),
async () => await WedgeObject3D_2.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Text".Localize(),
"Text".Localize(),
async () => await TextPathObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Oval".Localize(),
"Oval".Localize(),
async () => await CylinderObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Star".Localize(),
"Star".Localize(),
async () => await ConeObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Ring".Localize(),
"Ring".Localize(),
async () => await RingObject3D.Create())
{ DateCreated = new DateTime(index++) },
new GeneratorItem(
() => "Circle".Localize(),
"Circle".Localize(),
async () => await SphereObject3D.Create())
{ DateCreated = new DateTime(index++) },
};

View file

@ -52,7 +52,20 @@ namespace MatterHackers.MatterControl.Library
public string ID { get; } = Guid.NewGuid().ToString();
public string Name => this.PrintTask.PrintName;
public event EventHandler NameChanged;
public string Name
{
get => this.PrintTask.PrintName;
set
{
if (this.PrintTask.PrintName != value)
{
this.PrintTask.PrintName = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public bool IsProtected => true;

View file

@ -33,14 +33,14 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.Image;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrintQueue;
namespace MatterHackers.MatterControl.Library
{
public class PrintQueueContainer : WritableContainer
public class PrintQueueContainer : WritableContainer
{
public PrintQueueContainer()
{
@ -71,6 +71,13 @@ namespace MatterHackers.MatterControl.Library
this.ReloadContent();
}
public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)
{
#if DEBUG
throw new NotImplementedException();
#endif
}
public static async Task AddAllItems(IEnumerable<ILibraryItem> items)
{
await Task.Run(async () =>

View file

@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl.Library
{
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Plating History".Localize(),
"Plating History".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "history_icon.png")),
() => new PlatingHistoryContainer())
@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.Library
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Print History".Localize(),
"Print History".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "history_icon.png")),
() => new PrintHistoryContainer()
@ -78,7 +78,7 @@ namespace MatterHackers.MatterControl.Library
{
this.ChildContainers.Add(
new DynamicContainerLink(
() => "Printed Files".Localize(),
"Printed Files".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "history_icon.png")),
() => new FileSystemContainer(ApplicationDataStorage.Instance.PrintHistoryPath)

View file

@ -49,7 +49,20 @@ namespace MatterHackers.MatterControl.Library
{
public string ID { get; set; }
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public bool IsProtected { get; set; }

View file

@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.Library
{
this.ChildContainers.Add(
new DynamicContainerLink(
() => printer.Settings.GetValue(SettingsKey.printer_name),
printer.Settings.GetValue(SettingsKey.printer_name),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "printer_icon.png")),
() => new PrinterContainer(printer),

View file

@ -56,7 +56,7 @@ namespace MatterHackers.MatterControl.Library
this.ChildContainers.Add(
new DynamicContainerLink(
() => "SD Card".Localize(),
"SD Card".Localize(),
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
StaticData.Instance.LoadIcon(Path.Combine("Library", "sd_icon.png")),
() => new SDCardContainer(printer),
@ -77,7 +77,7 @@ namespace MatterHackers.MatterControl.Library
// subPath = "C Frame";
this.ChildContainers.Add(
new DynamicContainerLink(
() => containerName,
containerName,
StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
() => new GitHubContainer(containerName,
"MatterHackers",

View file

@ -43,6 +43,19 @@ namespace MatterHackers.MatterControl.Library
public bool IsVisible { get; } = true;
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
}
}

View file

@ -27,18 +27,11 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrintQueue;
namespace MatterHackers.MatterControl.Library
{
public class SqliteFileItem : FileSystemFileItem
public class SqliteFileItem : FileSystemFileItem
{
public PrintItem PrintItem { get; }
@ -48,6 +41,19 @@ namespace MatterHackers.MatterControl.Library
this.PrintItem = printItem;
}
public override string Name { get => this.PrintItem.Name; set => this.PrintItem.Name = value; }
}
public override string Name
{
get => this.PrintItem.Name;
set
{
if (this.PrintItem.Name != value)
{
this.PrintItem.Name = value;
this.PrintItem.Commit();
ApplicationController.Instance.MainView.Broadcast("ILibraryItem Name Changed", new LibraryItemNameChangedEvent(this.ID));
}
}
}
}
}

View file

@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.DataStorage;
@ -188,26 +189,11 @@ namespace MatterHackers.MatterControl.Library
this.ReloadContent();
}
public override void Rename(ILibraryItem selectedItem, string revisedName)
public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)
{
if (selectedItem is SqliteFileItem sqliteItem)
{
sqliteItem.PrintItem.Name = revisedName;
sqliteItem.PrintItem.Commit();
}
else if (selectedItem is SqliteLibraryContainerLink containerLink)
{
string sql = $"SELECT * FROM PrintItemCollection WHERE ID = {containerLink.CollectionID}";
var container = Datastore.Instance.dbSQLite.Query<PrintItemCollection>(sql).FirstOrDefault();
if (container != null)
{
container.Name = revisedName;
container.Commit();
}
}
this.ReloadContent();
#if DEBUG
throw new NotImplementedException();
#endif
}
protected List<PrintItemCollection> GetChildCollections()
@ -270,8 +256,41 @@ namespace MatterHackers.MatterControl.Library
public bool IsVisible { get; set; } = true;
public string Name { get; set; }
public event EventHandler NameChanged;
public string Name
{
get
{
string sql = $"SELECT * FROM PrintItemCollection WHERE ID = {this.CollectionID}";
var container = Datastore.Instance.dbSQLite.Query<PrintItemCollection>(sql).FirstOrDefault();
return container.Name;
}
set
{
if (value != Name)
{
string sql = $"SELECT * FROM PrintItemCollection WHERE ID = {this.CollectionID}";
var container = Datastore.Instance.dbSQLite.Query<PrintItemCollection>(sql).FirstOrDefault();
if (value != container.Name)
{
if (container != null)
{
container.Name = value;
container.Commit();
}
ApplicationController.Instance.MainView.Broadcast("ILibraryItem Name Changed", new LibraryItemNameChangedEvent(this.ID));
}
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public Task<ILibraryContainer> GetContainer(Action<double, string> reportProgress)
{
return Task.FromResult<ILibraryContainer>(

View file

@ -45,17 +45,9 @@ namespace MatterHackers.MatterControl.Library
this.ItemContentChanged?.Invoke(this, args);
}
public virtual void Add(IEnumerable<ILibraryItem> items)
{
}
public abstract void Add(IEnumerable<ILibraryItem> items);
public virtual void Remove(IEnumerable<ILibraryItem> items)
{
}
public virtual void Rename(ILibraryItem item, string revisedName)
{
}
public abstract void Remove(IEnumerable<ILibraryItem> items);
public virtual void Save(ILibraryItem item, IObject3D content)
{
@ -80,9 +72,7 @@ namespace MatterHackers.MatterControl.Library
}
public virtual void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer)
{
}
public abstract void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer);
public virtual bool AllowAction(ContainerActions containerActions)
{

View file

@ -45,7 +45,20 @@ namespace MatterHackers.MatterControl.Library
public string ID { get; set; }
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public string FileName { get; set; }

View file

@ -51,7 +51,20 @@ namespace MatterHackers.MatterControl.Library
public string ID { get; set; }
public string Name { get; set; }
private string _name;
public string Name
{
get => _name; set
{
if (_name != value)
{
_name = value;
NameChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler NameChanged;
public string FileName => $"{this.Name}.{this.ContentType}";

View file

@ -872,7 +872,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
return;
}
libraryContext.ActiveContainer.Rename(selectedItem.Model);
selectedItem.Model.Rename();
libraryView.SelectedItems.Clear();
}
},

View file

@ -545,6 +545,8 @@ namespace MatterHackers.MatterControl.CustomWidgets
ContentStore = writableContainer,
SourceItem = firstItem
});
mainViewWidget.HookupNameChangeCallback(partTab, workspace);
}
else
{

View file

@ -365,7 +365,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
switch (keyEvent.KeyCode)
{
case Keys.F2:
listView.ActiveContainer.Rename(firstItem);
firstItem.Rename();
listView.SelectedItems.Clear();
break;
}

View file

@ -31,8 +31,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using MatterControlLib;
using MatterHackers.Agg;
@ -552,7 +550,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
private async void Workspaces_Changed(object sender, WorkspacesChangedEventArgs e)
private void Workspaces_Changed(object sender, WorkspacesChangedEventArgs e)
{
var workspace = e.Workspace;
var activePrinter = workspace.Printer;
@ -587,6 +585,26 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
public void HookupNameChangeCallback(ChromeTab partTab, PartWorkspace workspace)
{
var sourceItem = workspace.SceneContext?.EditContext?.SourceItem;
if (sourceItem != null)
{
async void UpdateTabName(object s, EventArgs e)
{
partTab.Title = sourceItem.Name;
await ApplicationController.Instance.PersistUserWorkspaceTabs(false);
}
sourceItem.NameChanged += UpdateTabName;
partTab.Closed += (s, e) => sourceItem.NameChanged -= UpdateTabName;
partTab.Title = sourceItem.Name;
}
}
private GuiWidget CreateNetworkStatusPanel(ThemeConfig theme)
{
var networkStatus = new GuiWidget()
@ -753,32 +771,29 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
var menuTheme = ApplicationController.Instance.MenuTheme;
var popupMenu = new PopupMenu(menuTheme);
if (printer != null)
var renameMenuItem = popupMenu.CreateMenuItem("Rename".Localize());
renameMenuItem.Click += (s, e) =>
{
var renameMenuItem = popupMenu.CreateMenuItem("Rename".Localize());
renameMenuItem.Click += (s, e) =>
if (workspace != null)
{
if (workspace != null)
{
workspace.LibraryView.ActiveContainer.Rename(workspace.LibraryView.ActiveContainer.Items.FirstOrDefault());
}
else if (printer != null)
{
DialogWindow.Show(
new InputBoxPage(
"Rename Item".Localize(),
"Name".Localize(),
printer.Settings.GetValue(SettingsKey.printer_name),
"Enter New Name Here".Localize(),
"Rename".Localize(),
(newName) =>
{
printer.Settings.SetValue(SettingsKey.printer_name, newName);
}));
}
};
}
workspace.SceneContext?.EditContext?.SourceItem?.Rename();
}
else if (printer != null)
{
DialogWindow.Show(
new InputBoxPage(
"Rename Item".Localize(),
"Name".Localize(),
printer.Settings.GetValue(SettingsKey.printer_name),
"Enter New Name Here".Localize(),
"Rename".Localize(),
(newName) =>
{
printer.Settings.SetValue(SettingsKey.printer_name, newName);
}));
}
};
var moveButtons = new FlowLayoutWidget();
@ -873,6 +888,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Name = "newPart" + tabControl.AllTabs.Count(),
};
HookupNameChangeCallback(partTab, workspace);
EnableReduceWidth(partTab, theme);
tabControl.AddTab(partTab);

View file

@ -170,7 +170,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public GuiWidget ContentPanel { get; set; }
private readonly JsonPathContext pathResolver = new JsonPathContext();
private readonly JsonPathContext pathGetter = new JsonPathContext();
private readonly IconButton flattenButton;
private readonly IconButton removeButton;
private readonly OverflowBar.OverflowMenuButton overflowButton;
@ -343,7 +343,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
// Get the named property via reflection
// Selector example: '$.Children<CylinderObject3D>'
var match = pathResolver.Select(componentObject, selector).ToList();
var match = pathGetter.Select(componentObject, selector).ToList();
//// - Add editor row for each
foreach (var instance in match)

View file

@ -696,7 +696,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
base.OnDraw(graphics2D);
}
public override void OnClosed(EventArgs e)
public void HookupNameChange(PartWorkspace workspace)
{
throw new NotImplementedException();
}
public override void OnClosed(EventArgs e)
{
this.parentTabControl = null;
this.TabContent = null;