diff --git a/Clients/Xamarin.Interactive.Client.Windows/AgentSessionWindow.xaml.cs b/Clients/Xamarin.Interactive.Client.Windows/AgentSessionWindow.xaml.cs index c2c30ab6d..689a594f1 100644 --- a/Clients/Xamarin.Interactive.Client.Windows/AgentSessionWindow.xaml.cs +++ b/Clients/Xamarin.Interactive.Client.Windows/AgentSessionWindow.xaml.cs @@ -9,6 +9,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Windows.Controls.Primitives; using System.Diagnostics; @@ -48,6 +49,7 @@ using Xamarin.PropertyEditing.Windows; using XIR = Xamarin.Interactive.Remote; +using System.Linq; namespace Xamarin.Interactive.Client.Windows { @@ -134,34 +136,41 @@ bool Save (SaveOperation operation) CommonFileDialogComboBox formatComboBox = null; - if (saveOperation.SupportedOptions.HasFlag (WorkbookSaveOptions.Archive)) { - formatComboBox = new CommonFileDialogComboBox (); + var formatComboBoxLookup = new Dictionary (); + var formatComboBoxReverseLookup = new Dictionary (); + + formatComboBox = new CommonFileDialogComboBox (); + if (saveOperation.SupportsSingleFileOption) { + formatComboBoxLookup [formatComboBox.Items.Count] = WorkbookSaveOptions.SingleWorkbookFile; + formatComboBoxReverseLookup [WorkbookSaveOptions.SingleWorkbookFile] = formatComboBox.Items.Count; + formatComboBox.Items.Add (new CommonFileDialogComboBoxItem ( + Catalog.GetString ("Workbook File"))); + } + + if (saveOperation.SupportsMultiFileOptions) { + formatComboBoxLookup [formatComboBox.Items.Count] = WorkbookSaveOptions.PackageDirectory; + formatComboBoxReverseLookup [WorkbookSaveOptions.PackageDirectory] = formatComboBox.Items.Count; formatComboBox.Items.Add (new CommonFileDialogComboBoxItem ( Catalog.GetString ("Package Directory"))); + formatComboBoxLookup [formatComboBox.Items.Count] = WorkbookSaveOptions.Archive; + formatComboBoxReverseLookup [WorkbookSaveOptions.Archive] = formatComboBox.Items.Count; formatComboBox.Items.Add (new CommonFileDialogComboBoxItem ( Catalog.GetString ("Archive"))); - formatComboBox.SelectedIndex = saveOperation.Options.HasFlag ( - WorkbookSaveOptions.Archive) ? 1 : 0; - - var formatGroup = new CommonFileDialogGroupBox ("Workbook Format:"); - formatGroup.Items.Add (formatComboBox); - saveDialog.Controls.Add (formatGroup); } + formatComboBox.SelectedIndex = formatComboBoxReverseLookup [saveOperation.SaveOption]; + + var formatGroup = new CommonFileDialogGroupBox ("Workbook Format:"); + formatGroup.Items.Add (formatComboBox); + saveDialog.Controls.Add (formatGroup); + if (saveDialog.ShowDialog (this) != CommonFileDialogResult.Ok) return false; - if (formatComboBox != null) - switch (formatComboBox.SelectedIndex) { - case 0: - saveOperation.Options &= ~WorkbookSaveOptions.Archive; - break; - case 1: - saveOperation.Options |= WorkbookSaveOptions.Archive; - break; - default: - throw new IndexOutOfRangeException (); - } + // TODO - we could put up some kind of warning for InvolesMultipleFiles + // but saving as single workbook? + + saveOperation.SaveOption = formatComboBoxLookup [formatComboBox.SelectedIndex]; savePath = saveDialog.FileName; diff --git a/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj b/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj index 444d20be8..b7253db24 100644 --- a/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj +++ b/Clients/Xamarin.Interactive.Client.Windows/Xamarin.Interactive.Client.Windows.csproj @@ -94,6 +94,12 @@ 4.0.5150.10665 + + 1.1.2 + + + 1.1.1 + @@ -264,14 +270,6 @@ {0fd4b1dd-45a8-4f02-beb0-5881cd512573} CommonMark.Base - - {2e1fb0df-f9bb-4909-9f32-2d9d022a8e57} - Core - - - {aa0c00cb-8699-4f37-bfae-40ca87acc06d} - Shell - {60af04be-1b6b-411b-bcba-c95eafbd7ac0} Xamarin.PropertyEditing.Windows diff --git a/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/IWorkbookSaveOperation.cs b/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/IWorkbookSaveOperation.cs index 0b449fed6..f0d828541 100644 --- a/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/IWorkbookSaveOperation.cs +++ b/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/IWorkbookSaveOperation.cs @@ -11,8 +11,10 @@ namespace Xamarin.Interactive.Workbook.LoadAndSave { interface IWorkbookSaveOperation { - WorkbookSaveOptions SupportedOptions { get; } - WorkbookSaveOptions Options { get; set; } + bool SupportsMultiFileOptions { get; } + bool SupportsSingleFileOption { get; } + bool InvolesMultipleFiles { get; } + WorkbookSaveOptions SaveOption { get; set; } FilePath Destination { get; set; } } } \ No newline at end of file diff --git a/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/WorkbookSaveOptions.cs b/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/WorkbookSaveOptions.cs index 4dc028ac8..aea84540d 100644 --- a/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/WorkbookSaveOptions.cs +++ b/Clients/Xamarin.Interactive.Client/Workbook/LoadAndSave/WorkbookSaveOptions.cs @@ -9,11 +9,10 @@ namespace Xamarin.Interactive.Workbook.LoadAndSave { - [Flags] enum WorkbookSaveOptions { - None = 0, - Archive = 1 << 0, - Sign = 1 << 1 + SingleWorkbookFile = 0, + Archive = 1, + PackageDirectory = 2 } } \ No newline at end of file diff --git a/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPackage.cs b/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPackage.cs index 0846ce803..7b4f392bc 100644 --- a/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPackage.cs +++ b/Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPackage.cs @@ -249,7 +249,7 @@ public async Task Open ( if (quarantineInfoHandler == null) throw new ArgumentNullException (nameof (quarantineInfoHandler)); - SaveOptions = WorkbookSaveOptions.None; + SaveOptions = WorkbookSaveOptions.SingleWorkbookFile; LogicalPath = openPath; QuarantineInfo quarantineInfo = null; @@ -300,7 +300,7 @@ void Open (FilePath openPath, bool isDirectory, params AgentType [] platformTarg if (isDirectory) { indexPage.Path = indexPageFileName; readPath = openPath.Combine (indexPage.Path); - openedFromDirectory = true; + SaveOptions = WorkbookSaveOptions.PackageDirectory; } else { // If we are opening a file within a .workbook directory somewhere, // actually open that directory. This is to mostly address issues @@ -323,6 +323,7 @@ void Open (FilePath openPath, bool isDirectory, params AgentType [] platformTarg indexPage.Path = openPath.Name; readPath = openPath; + SaveOptions = WorkbookSaveOptions.SingleWorkbookFile; } using (var stream = new FileStream ( @@ -361,7 +362,7 @@ void OpenZip (FileStream stream, AgentType [] platformTargets) Open (extractPath, true, platformTargets); - SaveOptions |= WorkbookSaveOptions.Archive; + SaveOptions = WorkbookSaveOptions.Archive; } FilePath GetTempZipArchivePath () @@ -377,16 +378,28 @@ sealed class SaveOperation : IWorkbookSaveOperation public WorkbookPage OnlyPage; public bool OnlyPageHasDependencies; - public WorkbookSaveOptions SupportedOptions { + public bool InvolesMultipleFiles { get { - if (OnlyPage == null || OnlyPageHasDependencies) - return WorkbookSaveOptions.Archive; + return (OnlyPage == null || OnlyPageHasDependencies); + } + } + + public bool SupportsMultiFileOptions { + get { + // actually it seems, we always can have multifile options... + return true; + } + } - return WorkbookSaveOptions.None; + public bool SupportsSingleFileOption { + get { + // actually it seems, we always can have singlefile options... + // - or do I misunderstand what "OnlyPage == null" means... + return true; } } - public WorkbookSaveOptions Options { get; set; } + public WorkbookSaveOptions SaveOption { get; set; } public FilePath Destination { get; set; } } @@ -400,7 +413,7 @@ public IWorkbookSaveOperation CreateSaveOperation () AllDependencies = dependencies, OnlyPage = onlyPage.Key, OnlyPageHasDependencies = onlyPage.Key != null && onlyPage.Value.Count > 0, - Options = SaveOptions + SaveOption = SaveOptions }; } @@ -411,19 +424,13 @@ public void Save (IWorkbookSaveOperation operation) throw new ArgumentNullException (nameof (operation)); LogicalPath = operation.Destination; - SaveOptions = WorkbookSaveOptions.None; + SaveOptions = operation.SaveOption; - if (IndexPage != null && IndexPage.IsUntitled) + if (IndexPage != null) IndexPage.Title = LogicalPath.NameWithoutExtension; - if (saveOperation.OnlyPage != null && - !saveOperation.OnlyPageHasDependencies && - !openedFromDirectory) { - // The workbook package has only a single page with no relative - // dependencies. If the original path was a workbook directory, - // keep that format. If we originally opened from a workbook - // directory and our target save path is not a directory, keep - // that format. Otherwise, save the page as a single file. + if (saveOperation.SaveOption == WorkbookSaveOptions.SingleWorkbookFile) { + // This is a simple save... so we ignore dependencies var writePath = logicalPath.DirectoryExists ? logicalPath.Combine (saveOperation.OnlyPage.Path) : logicalPath; @@ -471,12 +478,12 @@ public void Save (IWorkbookSaveOperation operation) } } - if (saveOperation.Options.HasFlag (WorkbookSaveOptions.Archive)) + if (saveOperation.SaveOption == WorkbookSaveOptions.Archive) ArchiveDirectory (logicalPath); // For overwrite saves of archives, WorkingPath should continue // to point to the extracted directory in temp - if (!saveOperation.Options.HasFlag (WorkbookSaveOptions.Archive) || + if ((saveOperation.SaveOption != WorkbookSaveOptions.Archive) || WorkingPath == null || !WorkingPath.Exists) WorkingPath = logicalPath; @@ -499,8 +506,6 @@ void CopyDirectoryContents (FilePath sourceDirectory, FilePath destDirectory) void ArchiveDirectory (FilePath directory) { - SaveOptions |= WorkbookSaveOptions.Archive; - var archivePath = GetTempZipArchivePath (); using (var stream = new FileStream ( diff --git a/Package/Windows/AgentAppFiles.wxs b/Package/Windows/AgentAppFiles.wxs index 17d761aae..cccc9389a 100644 --- a/Package/Windows/AgentAppFiles.wxs +++ b/Package/Windows/AgentAppFiles.wxs @@ -300,17 +300,18 @@ + + + - - - - - - - + + + + + + - diff --git a/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs b/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs index 3ccdbf0d1..cc94c2ea8 100644 --- a/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs +++ b/Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs @@ -664,6 +664,12 @@ + + + + + + \ No newline at end of file diff --git a/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj b/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj index 2f07d49c3..06577618f 100644 --- a/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj +++ b/WorkbookApps/Xamarin.Workbooks.Wpf/Xamarin.Workbooks.Wpf.csproj @@ -60,6 +60,9 @@ 4.4.0 + + 1.1.2 + @@ -121,4 +124,4 @@ - + \ No newline at end of file