Save as causes the file dest to change and the tab name

Refactoring
Add dispose to content store
Added event for source item changed on edit context
Added rename to extensions method
Added local file path to tab tool tip
This commit is contained in:
Lars Brubaker 2022-02-02 17:31:44 -08:00
parent 9ef5181983
commit 1095d6741a
15 changed files with 141 additions and 116 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, John Lewin
Copyright (c) 2022, John Lewin, Lars Brubaker
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -28,10 +28,11 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.DataConverters3D;
using System;
namespace MatterHackers.MatterControl.Library
{
public interface IContentStore
public interface IContentStore : IDisposable
{
void Save(ILibraryItem item, IObject3D content);
}

View file

@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
@ -77,6 +78,30 @@ namespace MatterHackers.MatterControl.Library
}
}
public static void Rename(this ISceneContext sceneContext, string newName)
{
var contentStore = sceneContext.EditContext.ContentStore;
// Save to the destination provider
if (contentStore is FileSystemContainer fileSystemContainer)
{
sceneContext.EditContext.SourceItem = new FileSystemFileItem(Path.ChangeExtension(Path.Combine(fileSystemContainer.FullPath, newName), ".mcx"));
fileSystemContainer.Save(sceneContext.EditContext.SourceItem, sceneContext.Scene);
}
else if (contentStore is ILibraryWritableContainer writableContainer)
{
// Wrap stream with ReadOnlyStream library item and add to container
writableContainer.Add(new[]
{
new InMemoryLibraryItem(sceneContext.Scene)
{
Name = newName
}
});
contentStore.Dispose();
}
}
public static IEnumerable<ILibraryContainer> AncestorsAndSelf(this ILibraryContainer item)
{
var container = item;