Remove redundant key definitions
This commit is contained in:
parent
774c59d540
commit
3dec3a93fb
1 changed files with 130 additions and 159 deletions
|
|
@ -417,202 +417,173 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
bool invertIcons = ApplicationController.Instance.MenuTheme.InvertIcons;
|
||||
|
||||
return new Dictionary<string, NamedAction>()
|
||||
// Build workspace actions, each having a unique ID
|
||||
var actions = new []
|
||||
{
|
||||
new NamedAction()
|
||||
{
|
||||
"Insert",
|
||||
new NamedAction()
|
||||
ID = "Insert",
|
||||
Title = "Insert".Localize(),
|
||||
Icon = AggContext.StaticData.LoadIcon("cube.png", 16, 16, invertIcons),
|
||||
Action = () =>
|
||||
{
|
||||
ID = "Insert",
|
||||
Title = "Insert".Localize(),
|
||||
Icon = AggContext.StaticData.LoadIcon("cube.png", 16, 16, invertIcons),
|
||||
Action = () =>
|
||||
var extensionsWithoutPeriod = new HashSet<string>(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(s => s.Trim().Trim('.')));
|
||||
|
||||
foreach(var extension in ApplicationController.Instance.Library.ContentProviders.Keys)
|
||||
{
|
||||
var extensionsWithoutPeriod = new HashSet<string>(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(s => s.Trim().Trim('.')));
|
||||
|
||||
foreach(var extension in ApplicationController.Instance.Library.ContentProviders.Keys)
|
||||
{
|
||||
extensionsWithoutPeriod.Add(extension.ToUpper());
|
||||
}
|
||||
|
||||
var extensionsArray = extensionsWithoutPeriod.OrderBy(t => t).ToArray();
|
||||
|
||||
string filter = string.Format(
|
||||
"{0}|{1}",
|
||||
string.Join(",", extensionsArray),
|
||||
string.Join("", extensionsArray.Select(e => $"*.{e.ToLower()};").ToArray()));
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
AggContext.FileDialogs.OpenFileDialog(
|
||||
new OpenFileDialogParams(filter, multiSelect: true),
|
||||
(openParams) =>
|
||||
{
|
||||
ViewControls3D.LoadAndAddPartsToPlate(this, openParams.FileNames, sceneContext);
|
||||
});
|
||||
});
|
||||
extensionsWithoutPeriod.Add(extension.ToUpper());
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Print",
|
||||
new NamedAction()
|
||||
{
|
||||
ID = "Print",
|
||||
Title = "Print".Localize(),
|
||||
Shortcut = "Ctrl+P",
|
||||
Action = this.PushToPrinterAndPrint,
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
|| (sceneContext.EditContext.SourceItem is ILibraryAsset libraryAsset
|
||||
&& string.Equals(Path.GetExtension(libraryAsset.FileName) ,".gcode" ,StringComparison.OrdinalIgnoreCase))
|
||||
}
|
||||
},
|
||||
{
|
||||
"Cut",
|
||||
new NamedAction()
|
||||
{
|
||||
ID = "Cut",
|
||||
Title = "Cut".Localize(),
|
||||
Shortcut = "Ctrl+X",
|
||||
Action = () =>
|
||||
|
||||
var extensionsArray = extensionsWithoutPeriod.OrderBy(t => t).ToArray();
|
||||
|
||||
string filter = string.Format(
|
||||
"{0}|{1}",
|
||||
string.Join(",", extensionsArray),
|
||||
string.Join("", extensionsArray.Select(e => $"*.{e.ToLower()};").ToArray()));
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
sceneContext.Scene.Cut();
|
||||
},
|
||||
IsEnabled = () => sceneContext.Scene.SelectedItem != null
|
||||
AggContext.FileDialogs.OpenFileDialog(
|
||||
new OpenFileDialogParams(filter, multiSelect: true),
|
||||
(openParams) =>
|
||||
{
|
||||
ViewControls3D.LoadAndAddPartsToPlate(this, openParams.FileNames, sceneContext);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"Copy",
|
||||
new NamedAction()
|
||||
{
|
||||
ID = "Copy",
|
||||
Title = "Copy".Localize(),
|
||||
Shortcut = "Ctrl+C",
|
||||
Action = () =>
|
||||
{
|
||||
sceneContext.Scene.Copy();
|
||||
},
|
||||
IsEnabled = () => sceneContext.Scene.SelectedItem != null
|
||||
}
|
||||
ID = "Print",
|
||||
Title = "Print".Localize(),
|
||||
Shortcut = "Ctrl+P",
|
||||
Action = this.PushToPrinterAndPrint,
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
|| (sceneContext.EditContext.SourceItem is ILibraryAsset libraryAsset
|
||||
&& string.Equals(Path.GetExtension(libraryAsset.FileName) ,".gcode" ,StringComparison.OrdinalIgnoreCase))
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"Paste",
|
||||
new NamedAction()
|
||||
ID = "Cut",
|
||||
Title = "Cut".Localize(),
|
||||
Shortcut = "Ctrl+X",
|
||||
Action = () =>
|
||||
{
|
||||
ID = "Paste",
|
||||
Title = "Paste".Localize(),
|
||||
Shortcut = "Ctrl+V",
|
||||
Action = () =>
|
||||
{
|
||||
sceneContext.Paste();
|
||||
},
|
||||
IsEnabled = () => Clipboard.Instance.ContainsImage || Clipboard.Instance.GetText() == "!--IObjectSelection--!"
|
||||
}
|
||||
sceneContext.Scene.Cut();
|
||||
},
|
||||
IsEnabled = () => sceneContext.Scene.SelectedItem != null
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"Delete",
|
||||
new NamedAction()
|
||||
ID = "Copy",
|
||||
Title = "Copy".Localize(),
|
||||
Shortcut = "Ctrl+C",
|
||||
Action = () =>
|
||||
{
|
||||
ID = "Delete",
|
||||
Icon = AggContext.StaticData.LoadIcon("remove.png").SetPreMultiply(),
|
||||
Title = "Remove".Localize(),
|
||||
Action = sceneContext.Scene.DeleteSelection,
|
||||
IsEnabled = () => sceneContext.Scene.SelectedItem != null
|
||||
}
|
||||
sceneContext.Scene.Copy();
|
||||
},
|
||||
IsEnabled = () => sceneContext.Scene.SelectedItem != null
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"Export",
|
||||
new NamedAction()
|
||||
ID = "Paste",
|
||||
Title = "Paste".Localize(),
|
||||
Shortcut = "Ctrl+V",
|
||||
Action = () =>
|
||||
{
|
||||
ID = "Export",
|
||||
Title = "Export".Localize(),
|
||||
Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16, invertIcons),
|
||||
Action = () =>
|
||||
{
|
||||
ApplicationController.Instance.ExportLibraryItems(
|
||||
new[] { new InMemoryLibraryItem(sceneContext.Scene)},
|
||||
centerOnBed: false,
|
||||
printer: printer);
|
||||
},
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
|| (sceneContext.EditContext.SourceItem is ILibraryAsset libraryAsset
|
||||
&& string.Equals(Path.GetExtension(libraryAsset.FileName) ,".gcode" ,StringComparison.OrdinalIgnoreCase))
|
||||
}
|
||||
sceneContext.Paste();
|
||||
},
|
||||
IsEnabled = () => Clipboard.Instance.ContainsImage || Clipboard.Instance.GetText() == "!--IObjectSelection--!"
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"Save",
|
||||
new NamedAction()
|
||||
{
|
||||
ID = "Save",
|
||||
Title = "Save".Localize(),
|
||||
Shortcut = "Ctrl+S",
|
||||
Action = () =>
|
||||
{
|
||||
ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, sceneContext.SaveChanges).ConfigureAwait(false);
|
||||
},
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
}
|
||||
ID = "Delete",
|
||||
Icon = AggContext.StaticData.LoadIcon("remove.png").SetPreMultiply(),
|
||||
Title = "Remove".Localize(),
|
||||
Action = sceneContext.Scene.DeleteSelection,
|
||||
IsEnabled = () => sceneContext.Scene.SelectedItem != null
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"SaveAs",
|
||||
new NamedAction()
|
||||
ID = "Export",
|
||||
Title = "Export".Localize(),
|
||||
Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16, invertIcons),
|
||||
Action = () =>
|
||||
{
|
||||
ID = "SaveAs",
|
||||
Title = "Save As".Localize(),
|
||||
Action = () => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
DialogWindow.Show(
|
||||
new SaveAsPage(
|
||||
async (newName, destinationContainer) =>
|
||||
ApplicationController.Instance.ExportLibraryItems(
|
||||
new[] { new InMemoryLibraryItem(sceneContext.Scene)},
|
||||
centerOnBed: false,
|
||||
printer: printer);
|
||||
},
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
|| (sceneContext.EditContext.SourceItem is ILibraryAsset libraryAsset
|
||||
&& string.Equals(Path.GetExtension(libraryAsset.FileName) ,".gcode" ,StringComparison.OrdinalIgnoreCase))
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
ID = "Save",
|
||||
Title = "Save".Localize(),
|
||||
Shortcut = "Ctrl+S",
|
||||
Action = () =>
|
||||
{
|
||||
ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, sceneContext.SaveChanges).ConfigureAwait(false);
|
||||
},
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
ID = "SaveAs",
|
||||
Title = "Save As".Localize(),
|
||||
Action = () => UiThread.RunOnIdle(() =>
|
||||
{
|
||||
DialogWindow.Show(
|
||||
new SaveAsPage(
|
||||
async (newName, destinationContainer) =>
|
||||
{
|
||||
// Save to the destination provider
|
||||
if (destinationContainer is ILibraryWritableContainer writableContainer)
|
||||
{
|
||||
// Save to the destination provider
|
||||
if (destinationContainer is ILibraryWritableContainer writableContainer)
|
||||
// Wrap stream with ReadOnlyStream library item and add to container
|
||||
writableContainer.Add(new[]
|
||||
{
|
||||
// Wrap stream with ReadOnlyStream library item and add to container
|
||||
writableContainer.Add(new[]
|
||||
new InMemoryLibraryItem(sceneContext.Scene)
|
||||
{
|
||||
new InMemoryLibraryItem(sceneContext.Scene)
|
||||
{
|
||||
Name = newName
|
||||
}
|
||||
});
|
||||
Name = newName
|
||||
}
|
||||
});
|
||||
|
||||
destinationContainer.Dispose();
|
||||
}
|
||||
}));
|
||||
}),
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
}
|
||||
destinationContainer.Dispose();
|
||||
}
|
||||
}));
|
||||
}),
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"ArrangeAll",
|
||||
new NamedAction()
|
||||
ID = "ArrangeAll",
|
||||
Title = "Arrange All Parts".Localize(),
|
||||
Action = () =>
|
||||
{
|
||||
ID = "ArrangeAll",
|
||||
Title = "Arrange All Parts".Localize(),
|
||||
Action = () =>
|
||||
{
|
||||
sceneContext.Scene.AutoArrangeChildren(this.BedCenter);
|
||||
},
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
}
|
||||
sceneContext.Scene.AutoArrangeChildren(this.BedCenter);
|
||||
},
|
||||
IsEnabled = () => sceneContext.EditableScene
|
||||
},
|
||||
new NamedAction()
|
||||
{
|
||||
"ClearBed",
|
||||
new NamedAction()
|
||||
ID = "ClearBed",
|
||||
Title = "Clear Bed".Localize(),
|
||||
Action = () =>
|
||||
{
|
||||
ID = "ClearBed",
|
||||
Title = "Clear Bed".Localize(),
|
||||
Action = () =>
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
this.ClearPlate();
|
||||
});
|
||||
}
|
||||
this.ClearPlate();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Construct dictionary from workspace actions by ID
|
||||
return actions.ToDictionary(a => a.ID);
|
||||
}
|
||||
|
||||
private void ViewState_ViewModeChanged(object sender, ViewModeChangedEventArgs e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue