Working on file change detection and save prompt
Origin center for radial array
This commit is contained in:
parent
4434c27fea
commit
70254199e2
6 changed files with 103 additions and 56 deletions
|
|
@ -289,14 +289,17 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
public async Task PersistUserWorkspaceTabs(bool saveSceneChanges)
|
||||
public async Task PersistUserWorkspaceTabs(bool savePrinterScenes)
|
||||
{
|
||||
if (saveSceneChanges)
|
||||
if (savePrinterScenes)
|
||||
{
|
||||
// Persist all pending changes in all workspaces to disk
|
||||
foreach (var workspace in this.Workspaces.ToArray())
|
||||
{
|
||||
await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges);
|
||||
if (workspace.Printer != null)
|
||||
{
|
||||
await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -443,15 +446,17 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public static Func<string, Task<Dictionary<string, string>>> GetProfileHistory;
|
||||
|
||||
public void OnWorkspacesChanged(WorkspacesChangedEventArgs e)
|
||||
public void OnWorkspacesChanged(PartWorkspace workspace, WorkspacesChangedEventArgs.OperationType operationType)
|
||||
{
|
||||
this.WorkspacesChanged?.Invoke(this, e);
|
||||
this.WorkspacesChanged?.Invoke(this, new WorkspacesChangedEventArgs(
|
||||
workspace,
|
||||
operationType));
|
||||
|
||||
if (e.Operation != WorkspacesChangedEventArgs.OperationType.Restore)
|
||||
if (operationType != WorkspacesChangedEventArgs.OperationType.Restore)
|
||||
{
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
await ApplicationController.Instance.PersistUserWorkspaceTabs(true);
|
||||
await Instance.PersistUserWorkspaceTabs(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -481,10 +486,7 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
this.Workspaces.Remove(workspace);
|
||||
|
||||
this.OnWorkspacesChanged(
|
||||
new WorkspacesChangedEventArgs(
|
||||
workspace,
|
||||
WorkspacesChangedEventArgs.OperationType.Remove));
|
||||
this.OnWorkspacesChanged(workspace, WorkspacesChangedEventArgs.OperationType.Remove);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1597,11 +1599,7 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public void OpenWorkspace(PartWorkspace workspace, WorkspacesChangedEventArgs.OperationType operationType)
|
||||
{
|
||||
this.OnWorkspacesChanged(
|
||||
new WorkspacesChangedEventArgs(
|
||||
workspace,
|
||||
operationType));
|
||||
|
||||
this.OnWorkspacesChanged(workspace, operationType);
|
||||
this.Workspaces.Add(workspace);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -701,6 +701,14 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
}
|
||||
|
||||
public bool HadSaveError
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<BoolOption> GetBaseViewOptions()
|
||||
{
|
||||
return new List<BoolOption>();
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
Task SaveChanges(IProgress<ProgressStatus> progress, CancellationTokenSource cancellationToken);
|
||||
|
||||
bool HadSaveError { get; }
|
||||
|
||||
// TODO: Isolate printer specifics from ISceneContext
|
||||
|
||||
// *******************************************************
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -79,6 +78,8 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
this.DebugDepth("Rebuild");
|
||||
var aabb = this.GetAxisAlignedBoundingBox();
|
||||
|
||||
var firstBuild = this.Children.Count == 1;
|
||||
|
||||
var sourceContainer = SourceContainer;
|
||||
this.Children.Modify(list =>
|
||||
{
|
||||
|
|
@ -104,10 +105,17 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
next.Rotate(nextAabb.Center, normal, -angleRadians);
|
||||
}
|
||||
|
||||
next.Matrix *= Matrix4X4.CreateTranslation(-Axis.Origin);
|
||||
|
||||
list.Add(next);
|
||||
}
|
||||
});
|
||||
|
||||
if (firstBuild)
|
||||
{
|
||||
this.Matrix *= Matrix4X4.CreateTranslation(Axis.Origin);
|
||||
}
|
||||
|
||||
ProcessIndexExpressions();
|
||||
|
||||
SourceContainer.Visible = false;
|
||||
|
|
@ -123,7 +131,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|
|||
|
||||
public void DrawEditor(Object3DControlsLayer layer, DrawEventArgs e)
|
||||
{
|
||||
layer.World.RenderDirectionAxis(Axis, this.WorldMatrix(), 30);
|
||||
layer.World.RenderDirectionAxis(new DirectionAxis() { Normal = Axis.Normal, Origin = Vector3.Zero }, this.WorldMatrix(), 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,8 +28,10 @@ either expressed or implied, of the FreeBSD Project.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.Agg.UI;
|
||||
|
|
@ -294,17 +296,16 @@ namespace MatterHackers.MatterControl
|
|||
else if (!ApplicationController.Instance.ApplicationExiting)
|
||||
{
|
||||
// Check if there are unsaved design spaces
|
||||
bool unsavedChanges = false;
|
||||
var unsavedWorkspaces = new List<PartWorkspace>();
|
||||
foreach (var workspace in ApplicationController.Instance.Workspaces)
|
||||
{
|
||||
if (workspace.SceneContext?.Scene?.HasUnsavedChanges == true)
|
||||
{
|
||||
unsavedChanges = true;
|
||||
break;
|
||||
}
|
||||
unsavedWorkspaces.Add(workspace);
|
||||
}
|
||||
}
|
||||
|
||||
void SavePrinterWorkspaces()
|
||||
void SavePrinterWorkspacesAndClose()
|
||||
{
|
||||
// cancel the close so that we can save all our active work spaces
|
||||
eventArgs.Cancel = true;
|
||||
|
|
@ -324,49 +325,73 @@ namespace MatterHackers.MatterControl
|
|||
});
|
||||
}
|
||||
|
||||
if (unsavedChanges)
|
||||
if (unsavedWorkspaces.Count > 0)
|
||||
{
|
||||
exitDialogOpen = true;
|
||||
|
||||
// We need to show an interactive dialog to determine if the original Close request should be honored, thus cancel the current Close request
|
||||
eventArgs.Cancel = true;
|
||||
|
||||
// Ask if the user wants to save all workspaces, close without save, or cancel.
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
if (this.TabContent is PartTabPage partTab
|
||||
&& partTab?.Workspace?.SceneContext?.Scene is InteractiveScene sceneContext
|
||||
&& sceneContext.HasUnsavedChanges)
|
||||
{
|
||||
StyledMessageBox.ShowYNCMessageBox(
|
||||
(response) =>
|
||||
{
|
||||
switch (response)
|
||||
{
|
||||
case StyledMessageBox.ResponseType.YES:
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, partTab.Workspace.SceneContext.SaveChanges);
|
||||
this.parentTabControl.CloseTab(this);
|
||||
this.CloseClicked?.Invoke(this, null);
|
||||
});
|
||||
break;
|
||||
StyledMessageBox.ShowYNCMessageBox(
|
||||
(response) =>
|
||||
{
|
||||
exitDialogOpen = false;
|
||||
|
||||
case StyledMessageBox.ResponseType.NO:
|
||||
UiThread.RunOnIdle(async () =>
|
||||
switch (response)
|
||||
{
|
||||
case StyledMessageBox.ResponseType.YES:
|
||||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
var hadSaveError = false;
|
||||
// Persist each design workspaces to disk (this may require getting a filename
|
||||
foreach (var workspace in ApplicationController.Instance.Workspaces.ToArray())
|
||||
{
|
||||
this.parentTabControl.CloseTab(this);
|
||||
this.CloseClicked?.Invoke(this, null);
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
"Wolud you like to save changes before closing?".Localize(),
|
||||
"Save Changes?".Localize(),
|
||||
"Save Changes".Localize(),
|
||||
"Discard Changes".Localize(),
|
||||
"Cancel".Localize());
|
||||
}
|
||||
if (workspace.Printer == null)
|
||||
{
|
||||
// if we have a filename
|
||||
// save
|
||||
// else
|
||||
// switch to the tab we are about to save
|
||||
// ask the user to give us a filname
|
||||
// if no filename
|
||||
// abort the exit procedure
|
||||
await ApplicationController.Instance.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges);
|
||||
// check for error or abort
|
||||
hadSaveError |= workspace.SceneContext.HadSaveError;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hadSaveError)
|
||||
{
|
||||
// make sure we also save the printer workspaces as we close
|
||||
SavePrinterWorkspacesAndClose();
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case StyledMessageBox.ResponseType.NO:
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
// make sure we still save the printer workspaces
|
||||
SavePrinterWorkspacesAndClose();
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
unsavedWorkspaces.Count == 1 ? "You have one unsave design ({0}). Wolud you like to save changes before closing?".Localize().FormatWith(unsavedWorkspaces[0].Name)
|
||||
: "You have {0} unsave designs. Wolud you like to save changes before closing?".Localize().FormatWith(unsavedWorkspaces.Count),
|
||||
"Save Changes?".Localize(),
|
||||
"Save Changes".Localize(),
|
||||
"Discard Changes".Localize(),
|
||||
"Cancel".Localize());
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
SavePrinterWorkspaces();
|
||||
SavePrinterWorkspacesAndClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4354,6 +4354,12 @@ Translated:You are connected to the Emulator not an actual printer.
|
|||
English:You can also
|
||||
Translated:You can also
|
||||
|
||||
English:You have {0} unsave design(s). Wolud you like to save changes before closing?
|
||||
Translated:You have {0} unsave design(s). Wolud you like to save changes before closing?
|
||||
|
||||
English:You have one unsave design ({0}). Wolud you like to save changes before closing?
|
||||
Translated:You have one unsave design ({0}). Wolud you like to save changes before closing?
|
||||
|
||||
English:You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.
|
||||
Translated:You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue