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:
parent
9ef5181983
commit
1095d6741a
15 changed files with 141 additions and 116 deletions
|
|
@ -41,7 +41,11 @@ namespace MatterHackers.MatterControl.Library
|
|||
this.saveAction = saveAction;
|
||||
}
|
||||
|
||||
public void Save(ILibraryItem item, IObject3D content)
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public void Save(ILibraryItem item, IObject3D content)
|
||||
{
|
||||
saveAction.Invoke(item, content);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -799,7 +799,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
}
|
||||
|
||||
ApplicationController.Instance.BlinkTab(
|
||||
ApplicationController.Instance.MainView.TabControl.AllTabs.FirstOrDefault(t => t.TabContent is PartTabPage));
|
||||
ApplicationController.Instance.MainView.TabControl.AllTabs.FirstOrDefault(t => t.TabContent is DesignTabPage));
|
||||
},
|
||||
IsEnabled = (selectedListItems, listView) =>
|
||||
{
|
||||
|
|
@ -810,7 +810,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
&& listView.SelectedItems.Any()
|
||||
&& listView.SelectedItems.All(i => !(i.Model is ILibraryContainerLink))
|
||||
&& !isFolder
|
||||
&& ApplicationController.Instance.MainView.TabControl.AllTabs.Any(t => t.TabContent is PartTabPage);
|
||||
&& ApplicationController.Instance.MainView.TabControl.AllTabs.Any(t => t.TabContent is DesignTabPage);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -519,7 +519,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
{
|
||||
foreach (var tab in mainViewWidget.TabControl.AllTabs)
|
||||
{
|
||||
if (tab.TabContent is PartTabPage tabContent
|
||||
if (tab.TabContent is DesignTabPage tabContent
|
||||
&& (tabContent.sceneContext.EditContext.SourceFilePath == asset.AssetPath
|
||||
|| (tabContent.sceneContext.EditContext.SourceItem is IAssetPath cloudItem2
|
||||
&& cloudItem2.AssetPath == asset.AssetPath)))
|
||||
|
|
@ -535,7 +535,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
|
||||
ApplicationController.Instance.Workspaces.Add(workspace);
|
||||
|
||||
var partTab = mainViewWidget.CreatePartTab(workspace, true);
|
||||
var partTab = mainViewWidget.CreateDesignTab(workspace, true);
|
||||
mainViewWidget.TabControl.ActiveTab = partTab;
|
||||
|
||||
// Load content after UI widgets to support progress notification during acquire/load
|
||||
|
|
@ -545,8 +545,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
ContentStore = writableContainer,
|
||||
SourceItem = firstItem
|
||||
});
|
||||
|
||||
mainViewWidget.HookupNameChangeCallback(partTab, workspace);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue