Making better names for collection items (combine, align, subtract, intersect)
This commit is contained in:
parent
5e898a0650
commit
39af203e95
15 changed files with 121 additions and 100 deletions
|
|
@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
using MatterHackers.Agg;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
@ -97,29 +98,35 @@ namespace MatterHackers.MatterControl.Library
|
|||
string sourceFile = this.FilePath;
|
||||
if (File.Exists(sourceFile))
|
||||
{
|
||||
string extension = Path.GetExtension(sourceFile);
|
||||
string destFile = Path.Combine(Path.GetDirectoryName(sourceFile), value);
|
||||
destFile = Path.ChangeExtension(destFile, extension);
|
||||
var extension = Path.GetExtension(sourceFile);
|
||||
var fileNameNumberMatch = new Regex("\\s*\\(\\d+\\)" + extension, RegexOptions.Compiled);
|
||||
|
||||
var directory = Path.GetDirectoryName(sourceFile);
|
||||
var destName = value;
|
||||
var destPathAndName = Path.Combine(directory, Path.ChangeExtension(destName, extension));
|
||||
|
||||
var uniqueFileIncrement = 0;
|
||||
while(File.Exists(destFile))
|
||||
while(File.Exists(destPathAndName))
|
||||
{
|
||||
uniqueFileIncrement++;
|
||||
destFile = Path.Combine(Path.GetDirectoryName(sourceFile), value + $" ({uniqueFileIncrement})");
|
||||
destFile = Path.ChangeExtension(destFile, extension);
|
||||
// remove any number
|
||||
destName = fileNameNumberMatch.Replace(sourceFile, "");
|
||||
// add the new number
|
||||
destName += $" ({++uniqueFileIncrement})";
|
||||
destName = Path.ChangeExtension(destName, extension);
|
||||
destPathAndName = Path.Combine(directory, Path.ChangeExtension(destName, extension));
|
||||
|
||||
if (sourceFile == destFile)
|
||||
if (sourceFile == destPathAndName)
|
||||
{
|
||||
// we have gotten back to the name we currently have (don't change it)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceFile != destFile)
|
||||
if (sourceFile != destPathAndName)
|
||||
{
|
||||
File.Move(sourceFile, destFile);
|
||||
File.Move(sourceFile, destPathAndName);
|
||||
|
||||
this.FilePath = destFile;
|
||||
this.FilePath = destPathAndName;
|
||||
|
||||
NameChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ using MatterHackers.Agg.Image;
|
|||
using MatterHackers.DataConverters3D;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
{
|
||||
|
|
@ -79,9 +80,26 @@ namespace MatterHackers.MatterControl.Library
|
|||
}
|
||||
}
|
||||
|
||||
internal ILibraryItem NewPlatingItem(InteractiveScene scene)
|
||||
internal ILibraryItem NewBedPlate(BedConfig bedConfig)
|
||||
{
|
||||
var name = bedConfig.Printer.Settings.GetValue(SettingsKey.printer_name);
|
||||
string now = DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss");
|
||||
var filename = ApplicationController.Instance.SanitizeFileName($"{name} - {now}.mcx");
|
||||
string mcxPath = Path.Combine(this.FullPath, filename);
|
||||
|
||||
File.WriteAllText(mcxPath, new Object3D().ToJson());
|
||||
|
||||
return new FileSystemFileItem(mcxPath);
|
||||
}
|
||||
|
||||
internal ILibraryItem NewDesign()
|
||||
{
|
||||
string mcxPath = Path.Combine(this.FullPath, "New Design.mcx");
|
||||
var count = 0;
|
||||
while(File.Exists(mcxPath))
|
||||
{
|
||||
mcxPath = Path.Combine(this.FullPath, $"New Design ({++count}).mcx");
|
||||
}
|
||||
|
||||
File.WriteAllText(mcxPath, new Object3D().ToJson());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue