Save as asks for overwrite if exists
Save as dialog does clicking and double clicking as expected New Text icon
This commit is contained in:
parent
dbe806b301
commit
0731ac0bad
11 changed files with 174 additions and 60 deletions
|
|
@ -85,7 +85,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
[MaxDecimalPlaces(2)]
|
||||
[Slider(1, 400, VectorMath.Easing.EaseType.Quadratic, useSnappingGrid: true)]
|
||||
public DoubleOrExpression Height { get; set; } = 5;
|
||||
public DoubleOrExpression Height { get; set; } = 3;
|
||||
|
||||
[Sortable]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
ContainerFilter = (container) => this.ShowContainers,
|
||||
BackgroundColor = theme.BackgroundColor,
|
||||
Border = new BorderDouble(top: 1),
|
||||
DoubleClickAction = LibraryListView.DoubleClickActions.PreviewItem
|
||||
DoubleClickBehavior = LibraryListView.DoubleClickBehaviors.PreviewItem
|
||||
};
|
||||
|
||||
navBar = new OverflowBar(theme)
|
||||
|
|
@ -728,7 +728,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
Icon = StaticData.Instance.LoadIcon("cube.png", 16, 16).SetToColor(theme.TextColor),
|
||||
Action = (selectedLibraryItems, listView) =>
|
||||
{
|
||||
listView.SelectedItems.FirstOrDefault()?.OnDoubleClick();
|
||||
listView.SelectedItems.FirstOrDefault()?.OnDoubleClick(null);
|
||||
},
|
||||
IsEnabled = (selectedListItems, listView) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
{
|
||||
public class LibraryListView : ScrollableWidget
|
||||
{
|
||||
public enum DoubleClickActions
|
||||
public enum DoubleClickBehaviors
|
||||
{
|
||||
PreviewItem,
|
||||
AddToBed
|
||||
AddToBed,
|
||||
}
|
||||
|
||||
public event EventHandler ContentReloaded;
|
||||
|
|
@ -286,6 +286,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
{
|
||||
var listViewItem = new ListViewItem(childContainer, this.ActiveContainer, this);
|
||||
listViewItem.DoubleClick += ListViewItem_DoubleClick;
|
||||
|
||||
items.Add(listViewItem);
|
||||
|
||||
listViewItem.ViewWidget = itemsContentView.AddItem(listViewItem);
|
||||
|
|
@ -304,7 +305,21 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
foreach (var item in this.SortItems(filteredResults))
|
||||
{
|
||||
var listViewItem = new ListViewItem(item, this.ActiveContainer, this);
|
||||
listViewItem.DoubleClick += ListViewItem_DoubleClick;
|
||||
|
||||
if (DoubleClickItemEvent != null)
|
||||
{
|
||||
listViewItem.DoubleClick += DoubleClickItemEvent;
|
||||
}
|
||||
else
|
||||
{
|
||||
listViewItem.DoubleClick += ListViewItem_DoubleClick;
|
||||
}
|
||||
|
||||
if (ClickItemEvent != null)
|
||||
{
|
||||
listViewItem.Click += ClickItemEvent;
|
||||
}
|
||||
|
||||
items.Add(listViewItem);
|
||||
|
||||
listViewItem.ViewWidget = itemsContentView.AddItem(listViewItem);
|
||||
|
|
@ -333,7 +348,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void AddHeaderMarkdown(IconListView listView)
|
||||
public EventHandler<MouseEventArgs> ClickItemEvent;
|
||||
public EventHandler<MouseEventArgs> DoubleClickItemEvent;
|
||||
|
||||
private void AddHeaderMarkdown(IconListView listView)
|
||||
{
|
||||
if (sourceContainer != null
|
||||
&& !string.IsNullOrEmpty(sourceContainer.HeaderMarkdown))
|
||||
|
|
@ -451,7 +469,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
return destImage;
|
||||
}
|
||||
|
||||
private async void ListViewItem_DoubleClick(object sender, MouseEventArgs e)
|
||||
private void ListViewItem_DoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
|
|
@ -502,56 +520,58 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
// List items
|
||||
if (itemModel != null)
|
||||
{
|
||||
if (this.DoubleClickAction == DoubleClickActions.PreviewItem)
|
||||
switch (this.DoubleClickBehavior)
|
||||
{
|
||||
if (itemModel is ILibraryAsset asset && asset.ContentType == "mcx"
|
||||
&& itemModel is ILibraryItem firstItem
|
||||
&& this.ActiveContainer is ILibraryWritableContainer writableContainer)
|
||||
{
|
||||
var mainViewWidget = ApplicationController.Instance.MainView;
|
||||
|
||||
// check if it is already open
|
||||
if (ApplicationController.Instance.SwitchToWorkspaceIfAlreadyOpen(asset.AssetPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var workspace = new PartWorkspace(new BedConfig(ApplicationController.Instance.Library.PlatingHistory));
|
||||
|
||||
ApplicationController.Instance.Workspaces.Add(workspace);
|
||||
|
||||
var partTab = mainViewWidget.CreateDesignTab(workspace, true);
|
||||
mainViewWidget.TabControl.ActiveTab = partTab;
|
||||
|
||||
// Load content after UI widgets to support progress notification during acquire/load
|
||||
await workspace.SceneContext.LoadContent(
|
||||
new EditContext()
|
||||
{
|
||||
ContentStore = writableContainer,
|
||||
SourceItem = firstItem
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
void OpenNewTab()
|
||||
case DoubleClickBehaviors.PreviewItem:
|
||||
if (itemModel is ILibraryAsset asset && asset.ContentType == "mcx"
|
||||
&& itemModel is ILibraryItem firstItem
|
||||
&& this.ActiveContainer is ILibraryWritableContainer writableContainer)
|
||||
{
|
||||
_ = ApplicationController.Instance.OpenIntoNewTab(new[] { itemModel });
|
||||
}
|
||||
var mainViewWidget = ApplicationController.Instance.MainView;
|
||||
|
||||
OpenNewTab();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var activeContext = ApplicationController.Instance.DragDropData;
|
||||
activeContext.SceneContext?.AddToPlate(new[] { itemModel });
|
||||
// check if it is already open
|
||||
if (ApplicationController.Instance.SwitchToWorkspaceIfAlreadyOpen(asset.AssetPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var workspace = new PartWorkspace(new BedConfig(ApplicationController.Instance.Library.PlatingHistory));
|
||||
|
||||
ApplicationController.Instance.Workspaces.Add(workspace);
|
||||
|
||||
var partTab = mainViewWidget.CreateDesignTab(workspace, true);
|
||||
mainViewWidget.TabControl.ActiveTab = partTab;
|
||||
|
||||
// Load content after UI widgets to support progress notification during acquire/load
|
||||
await workspace.SceneContext.LoadContent(
|
||||
new EditContext()
|
||||
{
|
||||
ContentStore = writableContainer,
|
||||
SourceItem = firstItem
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
void OpenNewTab()
|
||||
{
|
||||
_ = ApplicationController.Instance.OpenIntoNewTab(new[] { itemModel });
|
||||
}
|
||||
|
||||
OpenNewTab();
|
||||
}
|
||||
break;
|
||||
|
||||
case DoubleClickBehaviors.AddToBed:
|
||||
var activeContext = ApplicationController.Instance.DragDropData;
|
||||
activeContext.SceneContext?.AddToPlate(new[] { itemModel });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public DoubleClickActions DoubleClickAction { get; set; } = DoubleClickActions.AddToBed;
|
||||
public DoubleClickBehaviors DoubleClickBehavior { get; set; } = DoubleClickBehaviors.AddToBed;
|
||||
|
||||
public void SetActiveContainer(ILibraryContainer container)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
public class ListViewItem
|
||||
{
|
||||
public event EventHandler<MouseEventArgs> DoubleClick;
|
||||
|
||||
public event EventHandler<MouseEventArgs> Click;
|
||||
|
||||
public ILibraryItem Model { get; }
|
||||
|
||||
|
|
@ -52,9 +54,14 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
|
||||
public ILibraryContainer Container { get; }
|
||||
|
||||
internal void OnDoubleClick()
|
||||
public void OnDoubleClick(MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
DoubleClick?.Invoke(this, null);
|
||||
DoubleClick?.Invoke(this, mouseEventArgs);
|
||||
}
|
||||
|
||||
public void OnClick(MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
Click?.Invoke(this, mouseEventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -248,8 +248,12 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
|
||||
if (IsDoubleClick(mouseEvent))
|
||||
{
|
||||
listViewItem.OnDoubleClick();
|
||||
listViewItem.OnDoubleClick(mouseEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
listViewItem.OnClick(mouseEvent);
|
||||
}
|
||||
|
||||
// On mouse down update the view3DWidget reference that will be used in MouseMove and MouseUp
|
||||
view3DWidget = ApplicationController.Instance.DragDropData.View3DWidget;
|
||||
|
|
@ -297,7 +301,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
var delta = mouseDownAt - mouseEvent.Position;
|
||||
|
||||
// If mouseDown on us and we've moved past are drag determination threshold, notify view3DWidget
|
||||
if (mouseDownInBounds && delta.Length > 40
|
||||
if (LibraryBrowserPage.AllowDragToBed
|
||||
&& mouseDownInBounds
|
||||
&& delta.Length > 40
|
||||
&& view3DWidget != null
|
||||
&& !(listViewItem.Model is MissingFileItem))
|
||||
{
|
||||
|
|
@ -458,5 +464,5 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,8 +28,10 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.CustomWidgets;
|
||||
using MatterHackers.MatterControl.Library;
|
||||
using MatterHackers.VectorMath;
|
||||
|
|
@ -44,8 +46,17 @@ namespace MatterHackers.MatterControl
|
|||
protected LibraryListView librarySelectorWidget;
|
||||
private FolderBreadCrumbWidget breadCrumbWidget = null;
|
||||
|
||||
public static bool AllowDragToBed { get; internal set; } = true;
|
||||
|
||||
public LibraryBrowserPage(Action<ILibraryWritableContainer, string> acceptCallback, string acceptButtonText)
|
||||
{
|
||||
AllowDragToBed = false;
|
||||
|
||||
Closed += (s, e) =>
|
||||
{
|
||||
AllowDragToBed = true;
|
||||
};
|
||||
|
||||
this.WindowSize = new Vector2(480, 500);
|
||||
|
||||
contentRow.Padding = 0;
|
||||
|
|
@ -82,14 +93,53 @@ namespace MatterHackers.MatterControl
|
|||
acceptButton.Cursor = Cursors.Hand;
|
||||
acceptButton.Click += (s, e) =>
|
||||
{
|
||||
var closeAfterSave = true;
|
||||
if (librarySelectorWidget.ActiveContainer is ILibraryWritableContainer writableContainer)
|
||||
{
|
||||
acceptCallback(
|
||||
writableContainer,
|
||||
itemNameWidget?.ActualTextEditWidget.Text ?? "none");
|
||||
var outputName = Path.ChangeExtension(itemNameWidget?.ActualTextEditWidget.Text ?? "none", ".mcx");
|
||||
|
||||
if (writableContainer is FileSystemContainer fileSystemContainer)
|
||||
{
|
||||
if (File.Exists(Path.Combine(fileSystemContainer.FullPath, outputName)))
|
||||
{
|
||||
closeAfterSave = false;
|
||||
// ask about overwriting the exisitng file
|
||||
StyledMessageBox.ShowMessageBox(
|
||||
(overwriteFile) =>
|
||||
{
|
||||
if (overwriteFile)
|
||||
{
|
||||
acceptCallback(writableContainer, outputName);
|
||||
this.DialogWindow.CloseOnIdle();
|
||||
}
|
||||
else
|
||||
{
|
||||
// turn the accept button back on
|
||||
acceptButton.Enabled = true;
|
||||
}
|
||||
},
|
||||
"\"{0}\" already exists.\nDo you want to replace it?".Localize().FormatWith(outputName),
|
||||
"Confirm Save As".Localize(),
|
||||
StyledMessageBox.MessageType.YES_NO,
|
||||
"Replace".Localize(),
|
||||
"Cancel".Localize());
|
||||
}
|
||||
else
|
||||
{
|
||||
// save and exit normaly
|
||||
acceptCallback(writableContainer, outputName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
acceptCallback(writableContainer, outputName);
|
||||
}
|
||||
}
|
||||
|
||||
this.DialogWindow.CloseOnIdle();
|
||||
if (closeAfterSave)
|
||||
{
|
||||
this.DialogWindow.CloseOnIdle();
|
||||
}
|
||||
};
|
||||
|
||||
this.AddPageAction(acceptButton);
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
}
|
||||
|
||||
// you can use this code to test the ShellOpenFile code
|
||||
#if true
|
||||
#if false
|
||||
public override void OnKeyPress(KeyPressEventArgs keyPressEvent)
|
||||
{
|
||||
var files = new string[]
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
|
@ -65,8 +66,18 @@ namespace MatterHackers.MatterControl
|
|||
Margin = new BorderDouble(5),
|
||||
Name = "Design Name Edit Field"
|
||||
};
|
||||
itemNameWidget.ActualTextEditWidget.EnterPressed += (s, e) =>
|
||||
|
||||
this.librarySelectorWidget.ClickItemEvent += (s, e) =>
|
||||
{
|
||||
if (s is ListViewItem listViewItem
|
||||
&& this.AcceptButton.Enabled)
|
||||
{
|
||||
itemNameWidget.ActualTextEditWidget.Text = Path.ChangeExtension(listViewItem.Model.Name, ".mcx");
|
||||
}
|
||||
};
|
||||
|
||||
void ClickAccept()
|
||||
{
|
||||
if (this.acceptButton.Enabled)
|
||||
{
|
||||
if (librarySelectorWidget.ActiveContainer is ILibraryWritableContainer)
|
||||
|
|
@ -76,7 +87,18 @@ namespace MatterHackers.MatterControl
|
|||
this.AcceptButton.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.librarySelectorWidget.DoubleClickItemEvent += (s, e) =>
|
||||
{
|
||||
ClickAccept();
|
||||
};
|
||||
|
||||
itemNameWidget.ActualTextEditWidget.EnterPressed += (s, e) =>
|
||||
{
|
||||
ClickAccept();
|
||||
};
|
||||
|
||||
itemNameWidget.ActualTextEditWidget.TextChanged += (s, e) =>
|
||||
{
|
||||
acceptButton.Enabled = libraryNavContext.ActiveContainer is ILibraryWritableContainer
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 8 KiB After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 10 KiB |
|
|
@ -19,6 +19,9 @@ Translated:\nBelow you can find a list of each setting that has changed.
|
|||
English:\nUpdating a default setting will not change any override that you have applied.
|
||||
Translated:\nUpdating a default setting will not change any override that you have applied.
|
||||
|
||||
English:"{0}" already exists.\nDo you want to replace it?
|
||||
Translated:"{0}" already exists.\nDo you want to replace it?
|
||||
|
||||
English:$/kg
|
||||
Translated:$/kg
|
||||
|
||||
|
|
@ -892,6 +895,9 @@ Translated:Configure Plugins
|
|||
English:Configure Wifi
|
||||
Translated:Configure Wifi
|
||||
|
||||
English:Confirm Save As
|
||||
Translated:Confirm Save As
|
||||
|
||||
English:Confirm your new password
|
||||
Translated:Confirm your new password
|
||||
|
||||
|
|
@ -3838,6 +3844,9 @@ Translated:Render Leveling Data on the bed
|
|||
English:Repair
|
||||
Translated:Repair
|
||||
|
||||
English:Replace
|
||||
Translated:Replace
|
||||
|
||||
English:Replacing
|
||||
Translated:Replacing
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue