Skip to content

Commit

Permalink
Merge branch 'release-7.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bovender committed Nov 17, 2016
2 parents bea27c8 + 6a8534d commit a2de6f3
Show file tree
Hide file tree
Showing 45 changed files with 538 additions and 167 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ publish:
git push
git push --tags
publish/create-release.rb
update-bovender:
find XLToolbox XLToolboxForExcel Tests -name '*.csproj' -o -name 'packages.config' -print0 | xargs -0 sed -i 's/0\.15\.0/0.15.1/'
2 changes: 1 addition & 1 deletion Tests/Csv/CsvFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ExportTabularCsvWithoutSeparator()
CsvExporter model = new CsvExporter();
string fn = System.IO.Path.GetTempFileName();
model.FileName = fn;
model.FieldSeparator = "";
model.FieldSeparator = " ";
model.Tabularize = true;
// Use a funky decimal separator
model.DecimalSeparator = "~";
Expand Down
1 change: 1 addition & 0 deletions Tests/Export/ExporterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void SetUp()
// Force starting Excel
Instance i = Instance.Default;
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
Bovender.Logging.LogFile.Default.EnableDebugLogging();
}

[TestFixtureTearDown]
Expand Down
1 change: 1 addition & 0 deletions Tests/Export/PresetsViewModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void ColorManagementStates()
// These assertions will fail if there is not a RGB and a CMYK profile
// installed on the test system!
PresetViewModel pvm = new PresetViewModel();
pvm.FileType.AsEnum = FileType.Tiff;
pvm.ColorSpace.AsEnum = ColorSpace.Rgb;
Assert.IsFalse(pvm.UseColorProfile,
"'Use color profile' was checked by default");
Expand Down
4 changes: 2 additions & 2 deletions Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("7.2.2.0")]
[assembly: AssemblyFileVersion("7.2.2.0")]
[assembly: AssemblyVersion("7.2.3.0")]
[assembly: AssemblyFileVersion("7.2.3.0")]
8 changes: 4 additions & 4 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug %28Bovender via NuGet%29'">
<Reference Include="Bovender, Version=0.15.0.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<Reference Include="Bovender, Version=0.15.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Bovender.0.15.0.0\lib\net40\Bovender.dll</HintPath>
<HintPath>..\packages\Bovender.0.15.1.0\lib\net40\Bovender.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<Reference Include="Bovender, Version=0.15.0.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<Reference Include="Bovender, Version=0.15.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Bovender.0.15.0.0\lib\net40\Bovender.dll</HintPath>
<HintPath>..\packages\Bovender.0.15.1.0\lib\net40\Bovender.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
limitations under the License.
-->
<packages>
<package id="Bovender" version="0.15.0.0" targetFramework="net40" />
<package id="Bovender" version="0.15.1.0" targetFramework="net40" />
<package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net40" />
<package id="NLog" version="4.3.7" targetFramework="net40" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net40" />
Expand Down
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
7.2.2
7.2.2.0
7.2.3
7.2.3.0
28 changes: 25 additions & 3 deletions XLToolbox/Csv/CsvExportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ public Message<FileNameMessageContent> ChooseExportFileNameMessage
#region Constructors

public CsvExportViewModel()
: this(new CsvExporter()) { }
: this(new CsvExporter())
{
Logger.Info("Constructed CsvExportViewModel with new CsvExporter");
}

public CsvExportViewModel(CsvExporter model)
: base(model)
Expand Down Expand Up @@ -186,8 +189,10 @@ private CsvExporter CsvExporter

private void DoChooseFileName()
{
Logger.Info("DoChooseFileName: Retrieving previous settings");
WorkbookStorage.Store store = new WorkbookStorage.Store();
string defaultPath = Excel.ViewModels.Instance.Default.ActivePath;
string defaultPath = UserSettings.UserSettings.Default.CsvPath;
Logger.Info("DoChooseFileName: Sending ChooseExportFileNameMessage");
ChooseExportFileNameMessage.Send(
new FileNameMessageContent(store.Get("csv_path", defaultPath),
"CSV files|*.csv;*.txt;*.dat|All files|*.*"),
Expand All @@ -198,18 +203,27 @@ private void ConfirmChooseFileName(FileNameMessageContent messageContent)
{
if (messageContent.Confirmed)
{
Logger.Info("ConfirmChooseFileName: File name confirmed");
CsvExporter.FileName = messageContent.Value;
DoExport();
}
else
{
Logger.Info("ConfirmChooseFileName: Not confirmed, doing nothing");
}
}

private void DoExport()
{
Logger.Info("DoExport: Storing settings");
string path = System.IO.Path.GetDirectoryName(FileName);
using (WorkbookStorage.Store store = new WorkbookStorage.Store())
{
store.Put("csv_path", System.IO.Path.GetDirectoryName(FileName));
store.Put("csv_path", path);
};
UserSettings.UserSettings.Default.CsvPath = path;
((CsvExporter)ProcessModel).Range = Range;
Logger.Info("DoExport: Starting process");
StartProcess();
}

Expand All @@ -222,5 +236,13 @@ private void DoExport()
Message<FileNameMessageContent> _chooseExportFileNameMessage;

#endregion

#region Class logger

private static NLog.Logger Logger { get { return _logger.Value; } }

private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());

#endregion
}
}
18 changes: 6 additions & 12 deletions XLToolbox/Csv/CsvExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,13 @@ public override bool Execute()
CellsProcessed = 0;
_fieldSeparator = FieldSeparator;
_needEscape = true;
string columnSpacer = String.Empty;
switch (_fieldSeparator)
if (_fieldSeparator == "\\t")
{
case "\\t":
_fieldSeparator = "\t";
break;
case "":
columnSpacer = " ";
_needEscape = false;
break;
default:
break;
_fieldSeparator = "\t";
}
if (String.IsNullOrWhiteSpace(_fieldSeparator))
{
_needEscape = false;
}

// Get columns widths, if tabularization is requested
Expand All @@ -157,7 +152,6 @@ public override bool Execute()
// write a column spacer and a field separator.
if (col > 1)
{
sw.Write(columnSpacer);
sw.Write(_fieldSeparator);
}

Expand Down
19 changes: 13 additions & 6 deletions XLToolbox/Csv/CsvImportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ protected override void UpdateProcessMessageContent(ProcessMessageContent proces

private void DoChooseFileName()
{
WorkbookStorage.Store store = new WorkbookStorage.Store();
Logger.Info("DoChooseFileName: Sending ChooseImportFileNameMessage");
ChooseImportFileNameMessage.Send(
new FileNameMessageContent(
store.Get("csv_path", Excel.ViewModels.Instance.Default.ActivePath),
UserSettings.UserSettings.Default.CsvPath,
"CSV files|*.csv;*.txt;*.dat|All files|*.*"),
ConfirmChooseFileName);
}
Expand All @@ -170,10 +170,9 @@ private void ConfirmChooseFileName(FileNameMessageContent messageContent)

private void DoImport()
{
using (WorkbookStorage.Store store = new WorkbookStorage.Store())
{
store.Put("csv_path", System.IO.Path.GetDirectoryName(FileName));
}
Logger.Info("DoImport: Storing settings");
UserSettings.UserSettings.Default.CsvPath = System.IO.Path.GetDirectoryName(FileName);
Logger.Info("DoImport: Executing import");
Importer.Execute();
CloseViewCommand.Execute(null);
}
Expand All @@ -199,5 +198,13 @@ private CsvImporter Importer
Message<FileNameMessageContent> _chooseImportFileNameMessage;

#endregion

#region Class logger

private static NLog.Logger Logger { get { return _logger.Value; } }

private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());

#endregion
}
}
49 changes: 47 additions & 2 deletions XLToolbox/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ static void SaveCsvWithSettings(Xl.Range range)

static void SaveCsvRange()
{
StoreOrRestoreCsvSelection();
if (CheckSelectionIsRange())
{
SaveCsv(Instance.Default.Application.Selection as Xl.Range);
Expand All @@ -323,6 +324,7 @@ static void SaveCsvRange()

static void SaveCsvRangeWithSettings()
{
StoreOrRestoreCsvSelection();
if (CheckSelectionIsRange())
{
SaveCsvWithSettings(Instance.Default.Application.Selection as Xl.Range);
Expand Down Expand Up @@ -460,7 +462,7 @@ static Csv.CsvExportViewModel CreateCsvExportViewModel(Xl.Range range)
{
args.Content.CloseViewCommand.Execute(null);
};
args.Content.InjectInto<Bovender.Mvvm.Views.ProcessView>().Show();
args.Content.InjectInto<Bovender.Mvvm.Views.ProcessView>().ShowInForm();
};
vm.ProcessFinishedMessage.Sent += (sender, args) =>
{
Expand All @@ -484,7 +486,7 @@ internal static void Exporter_ShowProgress_Sent(object sender, MessageArgs<Proce
{
e.Content.CloseViewCommand.Execute(null);
};
e.Content.InjectInto<Bovender.Mvvm.Views.ProcessView>().ShowDialogInForm();
e.Content.InjectInto<Bovender.Mvvm.Views.ProcessView>().ShowInForm();
}

internal static void Exporter_ProcessFinished_Sent(object sender, MessageArgs<ProcessMessageContent> e)
Expand All @@ -502,6 +504,49 @@ internal static void Exporter_ProcessFinished_Sent(object sender, MessageArgs<Pr
}
}

static void StoreOrRestoreCsvSelection()
{
SelectionViewModel svm = new SelectionViewModel(Instance.Default.Application);
if (svm.IsRange)
{
Logger.Info("RestoreLastCsvSelection: Current selection is range");
Excel.Models.Reference reference = new Excel.Models.Reference(svm.Range);

// If there currently is no range selection (only 1 cell selected), restore the previously
// saved range.
if (reference.CellCount == 1)
{
Logger.Info("RestoreLastCsvSelection: Selection is a single cell: Attempting to restore");
using (WorkbookStorage.Store store = new WorkbookStorage.Store(true))
{
reference.ReferenceString = store.Get(XLToolbox.Properties.StoreNames.Default.CsvRange, String.Empty);
if (reference.IsValid)
{
Logger.Info("RestoreLastCsvSelection: Activating the range");
reference.Activate();
}
else
{
Logger.Warn("RestoreLastCsvSelection: Invalid reference");
}
}
}
else
{
Logger.Info("RestoreLastCsvSelection: Selection is range of cells: Storing");
using (WorkbookStorage.Store store = new WorkbookStorage.Store(true))
{
store.Put(XLToolbox.Properties.StoreNames.Default.CsvRange, "=" + reference.ReferenceString);
}

}
}
else
{
Logger.Info("RestoreLastCsvSelection: Current selection is not a range");
}
}

#endregion

#region Class logger
Expand Down
19 changes: 16 additions & 3 deletions XLToolbox/Excel/Models/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class Reference : IDisposable
{
#region Properties

/// <summary>
/// Gets or sets the FullName of the workbook.
/// </summary>
public string WorkbookPath
{
get
Expand Down Expand Up @@ -148,7 +151,7 @@ public string ReferenceString
set
{
Reset();
_referenceString = value;
_referenceString = value.TrimStart('=');
Match m = null;
// Prevent argument null exceptions if the reference string is empty
if (!String.IsNullOrEmpty(_referenceString))
Expand Down Expand Up @@ -186,6 +189,11 @@ public string ReferenceString
}
}

/// <summary>
/// Gets whether the reference is formally valid.
/// Does not check whether the references workbook and
/// worksheet actually exist.
/// </summary>
public bool IsValid { get; private set; }

/// <summary>
Expand Down Expand Up @@ -440,7 +448,8 @@ private bool Parse(string reference)

private void Reset()
{
if (_rangeWasCreated) _range = (Range)Bovender.ComHelpers.ReleaseComObject(_range);
if (_rangeWasCreated) Bovender.ComHelpers.ReleaseComObject(_range);
_range = null;
_cols = (Range)Bovender.ComHelpers.ReleaseComObject(_cols);
_rows = (Range)Bovender.ComHelpers.ReleaseComObject(_rows);
_workbook = (Workbook)Bovender.ComHelpers.ReleaseComObject(_workbook);
Expand Down Expand Up @@ -470,7 +479,7 @@ private void ParseAddress()
Match m = _addressPattern.Value.Match(_address);
if (!m.Success)
{
Logger.Fatal("NormalizeAddress: Invalid address \"{0}\"", _address);
Logger.Fatal("ParseAddress: Invalid address \"{0}\"", _address);
throw new InvalidOperationException("Invalid address");
}
Top = new RowHelper(m.Groups["top"].Value);
Expand All @@ -482,6 +491,10 @@ private void ParseAddress()
}
}

/// <summary>
/// Normalizes the address by putting the top left cell first,
/// the bottom right cell last.
/// </summary>
private void NormalizeAddress()
{
if (IsRectangle)
Expand Down
10 changes: 8 additions & 2 deletions XLToolbox/Excel/ViewModels/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public bool IsSingleDocumentInterface
public Workbook CreateWorkbook()
{
Logger.Info("CreateWorkbook");
// Calling the Workbooks.Add method with a XlWBATemplate constand
// Calling the Workbooks.Add method with a XlWBATemplate constant
// creates a workbook that contains only one sheet.
Workbook workbook = Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
return workbook;
Expand Down Expand Up @@ -695,6 +695,7 @@ private Instance(bool createNewExcelInstance)
{
_canQuitExcel = true;
_application = new Application();
_createdInstance = true;
}
}

Expand Down Expand Up @@ -727,8 +728,12 @@ protected virtual void Dispose(bool disposing)
{
_application.DisplayAlerts = false;
_application.Quit();
_application = (Application)Bovender.ComHelpers.ReleaseComObject(_application);
_workbooks = (Workbooks)Bovender.ComHelpers.ReleaseComObject(_workbooks);
if (_createdInstance)
{
Bovender.ComHelpers.ReleaseComObject(_application);
}
_application = null;
}
}
}
Expand Down Expand Up @@ -931,6 +936,7 @@ private bool WorkWithVisibleWorkbooks(Predicate<Workbook> operation)
#region Private instance fields

private bool _disposed;
private bool _createdInstance;
private bool _canQuitExcel;
private Application _application;
private Workbooks _workbooks;
Expand Down
Loading

0 comments on commit a2de6f3

Please sign in to comment.