Added an open file menu item
This commit is contained in:
parent
e19620dfc7
commit
8ed11e7c52
5 changed files with 44 additions and 31 deletions
|
|
@ -704,6 +704,33 @@ namespace MatterHackers.MatterControl
|
|||
return actions.ToDictionary(a => a.ID);
|
||||
}
|
||||
|
||||
public static void OpenFileWithSystemDialog(Action<string[]> openFiles)
|
||||
{
|
||||
var extensionsWithoutPeriod = new HashSet<string>(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(t => t.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(t => $"*.{t.ToLower()};").ToArray()));
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
AggContext.FileDialogs.OpenFileDialog(
|
||||
new OpenFileDialogParams(filter, multiSelect: true),
|
||||
(openParams) =>
|
||||
{
|
||||
openFiles?.Invoke(openParams.FileNames);
|
||||
});
|
||||
}, .1);
|
||||
}
|
||||
|
||||
public async Task OpenIntoNewTab(IEnumerable<ILibraryItem> selectedLibraryItems)
|
||||
{
|
||||
await this.MainView.CreateNewDesignTab(false);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.Platform;
|
||||
|
|
@ -92,6 +93,11 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
PopupMenu.MenuItem menuItem;
|
||||
|
||||
menuItem = popupMenu.CreateMenuItem("Open File", StaticData.Instance.LoadIcon("fa-folder-open_16.png", 16, 16).SetToColor(menuTheme.TextColor));
|
||||
menuItem.Click += (s, e) => ApplicationController.OpenFileWithSystemDialog((fileNames) => ApplicationController.Instance.MainView.OpenFile(fileNames.FirstOrDefault()));
|
||||
|
||||
popupMenu.CreateSeparator();
|
||||
|
||||
menuItem = popupMenu.CreateMenuItem("Help".Localize(), StaticData.Instance.LoadIcon("help_page.png", 16, 16).SetToColor(menuTheme.TextColor));
|
||||
menuItem.Click += (s, e) => ApplicationController.Instance.ShowApplicationHelp("Docs");
|
||||
|
||||
|
|
|
|||
|
|
@ -466,14 +466,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
#endif
|
||||
|
||||
public void OpenDropFile(string filePath)
|
||||
public void OpenFile(string filePath)
|
||||
{
|
||||
Instance_OpenNewFile(this, filePath);
|
||||
}
|
||||
|
||||
private async void Instance_OpenNewFile(object sender, string filePath)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
if (!string.IsNullOrEmpty(filePath)
|
||||
&& File.Exists(filePath))
|
||||
{
|
||||
if (Path.GetExtension(filePath).ToLower() == ".mcx")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
foreach (var file in e.DragFiles)
|
||||
{
|
||||
ApplicationController.Instance.MainView.OpenDropFile(file);
|
||||
ApplicationController.Instance.MainView.OpenFile(file);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -650,38 +650,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
var openFileButton = openMenuItems.CreateMenuItem("Add File to Bed".Localize(), StaticData.Instance.LoadIcon("fa-folder-open_16.png", 16, 16).SetToColor(theme.TextColor));
|
||||
|
||||
openFileButton.Click += (s, e) =>
|
||||
{
|
||||
var extensionsWithoutPeriod = new HashSet<string>(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(t => t.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(t => $"*.{t.ToLower()};").ToArray()));
|
||||
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
AggContext.FileDialogs.OpenFileDialog(
|
||||
new OpenFileDialogParams(filter, multiSelect: true),
|
||||
(openParams) =>
|
||||
{
|
||||
sceneContext.AddToPlate(openParams.FileNames);
|
||||
});
|
||||
}, .1);
|
||||
};
|
||||
|
||||
// popupMenu.AddChild(openLibraryButton, 0);
|
||||
{
|
||||
ApplicationController.OpenFileWithSystemDialog((fileNames) =>
|
||||
{
|
||||
sceneContext.AddToPlate(fileNames);
|
||||
});
|
||||
};
|
||||
|
||||
return popupMenu;
|
||||
}
|
||||
|
||||
private void UpdateToolbarButtons(object sender, EventArgs e)
|
||||
private void UpdateToolbarButtons(object sender, EventArgs e)
|
||||
{
|
||||
// Set enabled level based on operation rules
|
||||
foreach (var (button, operation) in operationButtons.Select(kvp => (kvp.Key, kvp.Value)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue