Skip to content

Commit

Permalink
Prevent publishing documents that don't exist in the target file (for #…
Browse files Browse the repository at this point in the history
  • Loading branch information
chelh committed May 1, 2017
1 parent c8b25b6 commit 854c6c5
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 192 deletions.
16 changes: 12 additions & 4 deletions src/VBASync.WPF/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal MainViewModel(Model.Startup startup)
};
Settings = new SettingsViewModel
{
AddNewDocumentsToFile = startup.AddNewDocumentsToFile,
DiffTool = startup.DiffTool,
DiffToolParameters = startup.DiffToolParameters,
Language = startup.Language,
Expand Down Expand Up @@ -107,21 +108,28 @@ public void LoadIni(Model.AppIniFile ini)
Session.Action = ini.GetActionType("General", "ActionType") ?? Session.Action;
Session.FolderPath = ini.GetString("General", "FolderPath") ?? Session.FolderPath;
Session.FilePath = ini.GetString("General", "FilePath") ?? Session.FilePath;
Settings.AddNewDocumentsToFile = ini.GetBool("General", "AddNewDocumentsToFile")
?? Settings.AddNewDocumentsToFile;
}

public void RefreshActiveSession()
{
_activeSession?.Dispose();
_activeSession = new Model.ActiveSession(_session);
_activeSession = new Model.ActiveSession(_session, _settings);
}

internal void SaveSession(Stream st, bool saveSettings)
internal void SaveSession(Stream st, bool saveGlobalSettings, bool saveSessionSettings)
{
Func<bool, string> iniBool = b => b ? "true" : "false";
var sb = new StringBuilder();
sb.AppendLine("ActionType=" + (Session.Action == Model.ActionType.Extract ? "Extract" : "Publish"));
sb.AppendLine($"FolderPath=\"{Session.FolderPath}\"");
sb.AppendLine($"FilePath=\"{Session.FilePath}\"");
if (saveSettings)
if (saveSessionSettings)
{
sb.AppendLine($"AddNewDocumentsToFile={iniBool(Settings.AddNewDocumentsToFile)}");
}
if (saveGlobalSettings)
{
sb.AppendLine($"Language=\"{Settings.Language}\"");
sb.AppendLine("");
Expand Down Expand Up @@ -235,7 +243,7 @@ private void SaveSession()
}
using (var fs = new FileStream(path, FileMode.Create))
{
SaveSession(fs, false);
SaveSession(fs, false, true);
}
AddRecentFile(path);
}
Expand Down
19 changes: 2 additions & 17 deletions src/VBASync.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ internal partial class MainWindow {
private readonly MainViewModel _vm;

private bool _doUpdateIncludeAll = true;
private ActionType? _lastQuietRefreshAction;
private string _lastQuietRefreshFilePath;
private string _lastQuietRefreshFolderPath;

public MainWindow(Startup startup) {
InitializeComponent();
Expand All @@ -42,7 +39,7 @@ public MainWindow(Startup startup) {

internal void SettingsMenu_Click(object sender, RoutedEventArgs e)
{
new SettingsWindow(_vm.Settings, s => _vm.Settings = s).ShowDialog();
new SettingsWindow(_vm.Settings, s => { _vm.Settings = s; QuietRefreshIfInputsOk(); }).ShowDialog();
}

private void AboutMenu_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -166,17 +163,8 @@ private void QuietRefreshIfInputsOk() {
ApplyButton.IsEnabled = false;
return;
}
if (_vm.Session.Action == _lastQuietRefreshAction
&& _vm.Session.FilePath == _lastQuietRefreshFilePath
&& _vm.Session.FolderPath == _lastQuietRefreshFolderPath)
{
return;
}
try {
RefreshButton_Click(null, null);
_lastQuietRefreshAction = _vm.Session.Action;
_lastQuietRefreshFilePath = _vm.Session.FilePath;
_lastQuietRefreshFolderPath = _vm.Session.FolderPath;
} catch {
_vm.Changes = null;
ApplyButton.IsEnabled = false;
Expand Down Expand Up @@ -205,9 +193,6 @@ private void RefreshButton_Click(object sender, RoutedEventArgs e) {
finally
{
ApplyButton.IsEnabled = _vm.Changes?.Count > 0;
_lastQuietRefreshAction = null;
_lastQuietRefreshFilePath = null;
_lastQuietRefreshFolderPath = null;
}
}

Expand Down Expand Up @@ -242,7 +227,7 @@ private void Window_Closed(object sender, EventArgs e) {
}
using (var st = new FileStream(lastSessionPath, FileMode.Create))
{
_vm.SaveSession(st, true);
_vm.SaveSession(st, true, false);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/VBASync.WPF/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
namespace VBASync.WPF
{
internal class SettingsViewModel : ViewModelBase
internal class SettingsViewModel : ViewModelBase, Model.ISessionSettings
{
private bool _addNewDocumentsToFile;
private string _diffTool;
private string _diffToolParameters;
private string _language;
private bool _portable;

public bool AddNewDocumentsToFile
{
get => _addNewDocumentsToFile;
set => SetField(ref _addNewDocumentsToFile, value, nameof(AddNewDocumentsToFile));
}

public string DiffTool
{
get => _diffTool;
Expand All @@ -33,6 +40,7 @@ public bool Portable

public SettingsViewModel Clone() => new SettingsViewModel
{
_addNewDocumentsToFile = _addNewDocumentsToFile,
_diffTool = _diffTool,
_diffToolParameters = _diffToolParameters,
_language = _language,
Expand Down
Loading

0 comments on commit 854c6c5

Please sign in to comment.