Skip to content

Commit

Permalink
Add session options (for #24 and #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
chelh committed May 2, 2017
1 parent 854c6c5 commit fff2970
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 37 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Switch | Meaning
`-f <file>` | Specify Office file
`-d <dir>` | Specify version-control directory
`-r` | Do the selected action, then immediately exit (**required** on Linux/Mac)
`-a` | Add new document modules when publishing (expert option)
`-i` | Ignore empty modules

Any other parameter passed to VBA Sync Tool will be read and parsed as a session `.ini` file.

Expand Down
5 changes: 4 additions & 1 deletion src/VBASync.WPF/AboutWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public AboutWindow()
.Replace("{0}", MainWindow.CopyrightYear.ToString());
CopyrightBlock.Inlines.Clear();
CopyrightBlock.Inlines.Add(TextBefore("{1}", copyrightText));
var licenseRtfHyperlink = new Hyperlink();
var licenseRtfHyperlink = new Hyperlink
{
NavigateUri = new Uri("file:///")
};
licenseRtfHyperlink.Inlines.Add("LICENSE.rtf");
licenseRtfHyperlink.RequestNavigate += (s, e)
=> Process.Start(Path.Combine(exeDir, "LICENSE.rtf"));
Expand Down
8 changes: 7 additions & 1 deletion src/VBASync.WPF/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ namespace VBASync.WPF
{
internal class MainViewModel : ViewModelBase
{
private readonly Action _onLoadIni;
private readonly string _lastSessionPath;

private Model.ActiveSession _activeSession;
private ChangesViewModel _changes;
private SessionViewModel _session;
private SettingsViewModel _settings;

internal MainViewModel(Model.Startup startup)
internal MainViewModel(Model.Startup startup, Action onLoadIni)
{
Session = new SessionViewModel
{
Expand All @@ -33,6 +34,7 @@ internal MainViewModel(Model.Startup startup)
AddNewDocumentsToFile = startup.AddNewDocumentsToFile,
DiffTool = startup.DiffTool,
DiffToolParameters = startup.DiffToolParameters,
IgnoreEmpty = startup.IgnoreEmpty,
Language = startup.Language,
Portable = startup.Portable
};
Expand All @@ -41,6 +43,8 @@ internal MainViewModel(Model.Startup startup)
{
RecentFiles.Add(recentFile);
}

_onLoadIni = onLoadIni;
_lastSessionPath = startup.LastSessionPath;

BrowseForSessionCommand = new WpfCommand(v => BrowseForSession());
Expand Down Expand Up @@ -110,6 +114,7 @@ public void LoadIni(Model.AppIniFile ini)
Session.FilePath = ini.GetString("General", "FilePath") ?? Session.FilePath;
Settings.AddNewDocumentsToFile = ini.GetBool("General", "AddNewDocumentsToFile")
?? Settings.AddNewDocumentsToFile;
_onLoadIni();
}

public void RefreshActiveSession()
Expand All @@ -128,6 +133,7 @@ internal void SaveSession(Stream st, bool saveGlobalSettings, bool saveSessionSe
if (saveSessionSettings)
{
sb.AppendLine($"AddNewDocumentsToFile={iniBool(Settings.AddNewDocumentsToFile)}");
sb.AppendLine($"IgnoreEmpty={iniBool(Settings.IgnoreEmpty)}");
}
if (saveGlobalSettings)
{
Expand Down
4 changes: 1 addition & 3 deletions src/VBASync.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal partial class MainWindow {
public MainWindow(Startup startup) {
InitializeComponent();

DataContext = _vm = new MainViewModel(startup);
DataContext = _vm = new MainViewModel(startup, QuietRefreshIfInputsOk);
DataContextChanged += (s, e) => QuietRefreshIfInputsOk();
_vm.Session.PropertyChanged += (s, e) => QuietRefreshIfInputsOk();
QuietRefreshIfInputsOk();
Expand All @@ -49,8 +49,6 @@ private void AboutMenu_Click(object sender, RoutedEventArgs e)

private void ApplyButton_Click(object sender, RoutedEventArgs e)
{
CheckAndFixErrors();

var changes = _vm.Changes;
var committedChanges = changes?.Where(p => p.Commit).ToList();
if (committedChanges == null || committedChanges.Count == 0)
Expand Down
8 changes: 8 additions & 0 deletions src/VBASync.WPF/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal class SettingsViewModel : ViewModelBase, Model.ISessionSettings
private bool _addNewDocumentsToFile;
private string _diffTool;
private string _diffToolParameters;
private bool _ignoreEmpty;
private string _language;
private bool _portable;

Expand All @@ -26,6 +27,12 @@ public string DiffToolParameters
set => SetField(ref _diffToolParameters, value, nameof(DiffToolParameters));
}

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

public string Language
{
get => _language;
Expand All @@ -43,6 +50,7 @@ public bool Portable
_addNewDocumentsToFile = _addNewDocumentsToFile,
_diffTool = _diffTool,
_diffToolParameters = _diffToolParameters,
_ignoreEmpty = _ignoreEmpty,
_language = _language,
_portable = _portable
};
Expand Down
9 changes: 7 additions & 2 deletions src/VBASync.WPF/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,18 @@
</TabItem>
<TabItem Header="{x:Static l10n:VBASyncResources.SWSessionTab}">
<StackPanel Margin="4">
<CheckBox VerticalAlignment="Top" IsChecked="{Binding IgnoreEmpty}">
<TextBlock
Margin="4,0,0,0"
Text="{x:Static l10n:VBASyncResources.SWIgnoreEmpty}"
TextWrapping="Wrap" />
</CheckBox>
<CheckBox
x:Name="AddNewDocumentsToFileBox"
Margin="0,4,0,0"
VerticalAlignment="Top"
IsChecked="{Binding AddNewDocumentsToFile}">
<TextBlock
Margin="4,0,0,0"
Tag="{Binding ElementName=AddNewDocumentsToFileBox}"
Text="{x:Static l10n:VBASyncResources.SWAddNewDocumentsToFile}"
TextWrapping="Wrap" />
</CheckBox>
Expand Down
9 changes: 9 additions & 0 deletions src/VBASync/Localization/VBASyncResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 30 additions & 27 deletions src/VBASync/Localization/VBASyncResources.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -407,4 +407,7 @@ File 2: {'{2}'}</value>
<data name="SWSessionTab" xml:space="preserve">
<value>Session</value>
</data>
<data name="SWIgnoreEmpty" xml:space="preserve">
<value>Ignore empty modules</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/VBASync/Model/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public static Patch GetLicensesPatch(ISession session, string evfPath)
newFolder = session.FolderPath;
}

if (sessionSettings.IgnoreEmpty)
{
oldModules = oldModules.Where(kvp => ModuleProcessing.HasCode(kvp.Value.Item1)).ToList();
newModules = newModules.Where(kvp => ModuleProcessing.HasCode(kvp.Value.Item1)).ToList();
}

// find modules which aren't in both lists and record them as new/deleted
var patches = new List<Patch>();
patches.AddRange(GetDeletedModuleChanges(oldModules, newModules));
Expand Down
6 changes: 3 additions & 3 deletions src/VBASync/Model/ModuleProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public static string FixCase(string oldString, string newString)
return sb.ToString();
}

internal static bool HasContent(string moduleText)
internal static bool HasCode(string moduleText)
{
_inBlock = false;
return moduleText?.Split(new[] { "\r\n" }, StringSplitOptions.None).Any(LineIsContent) ?? false;
return moduleText?.Split(new[] { "\r\n" }, StringSplitOptions.None).Any(LineIsCode) ?? false;
}

internal static ModuleType TypeFromText(string moduleText)
Expand All @@ -120,7 +120,7 @@ internal static ModuleType TypeFromText(string moduleText)
return ModuleType.Class;
}

private static bool LineIsContent(string line)
private static bool LineIsCode(string line)
{
// must set _inBlock to false before using this
var trimLine = line?.TrimStart();
Expand Down
1 change: 1 addition & 0 deletions src/VBASync/Model/SessionInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public interface ISession
public interface ISessionSettings
{
bool AddNewDocumentsToFile { get; set; }
bool IgnoreEmpty { get; set; }
}
}
1 change: 1 addition & 0 deletions src/VBASync/Model/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Startup : ISession, ISessionSettings
public bool AutoRun { get; set; }
public string DiffTool { get; set; }
public string DiffToolParameters { get; set; }
public bool IgnoreEmpty { get; set; }
public string FilePath { get; set; }
public string FolderPath { get; set; }
public string Language { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions src/VBASync/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private static void Main(string[] args)
string filePathSwitch = null;
string folderPathSwitch = null;
var addNewDocumentsToFileSwitch = false;
var ignoreEmptySwitch = false;
for (var i = 1; i < args.Length; ++i)
{
switch (args[i].ToUpperInvariant())
Expand Down Expand Up @@ -70,6 +71,10 @@ private static void Main(string[] args)
case "/A":
addNewDocumentsToFileSwitch = true;
break;
case "-I":
case "/I":
ignoreEmptySwitch = true;
break;
default:
ini.AddFile(args[i]);
break;
Expand All @@ -83,6 +88,7 @@ private static void Main(string[] args)
AutoRun = autoRunSwitch || (ini.GetBool("General", "AutoRun") ?? false),
DiffTool = ini.GetString("DiffTool", "Path"),
DiffToolParameters = ini.GetString("DiffTool", "Parameters") ?? "\"{OldFile}\" \"{NewFile}\"",
IgnoreEmpty = ignoreEmptySwitch || (ini.GetBool("General", "IgnoreEmpty") ?? false),
FilePath = filePathSwitch ?? ini.GetString("General", "FilePath"),
FolderPath = folderPathSwitch ?? ini.GetString("General", "FolderPath"),
Language = ini.GetString("General", "Language"),
Expand Down

0 comments on commit fff2970

Please sign in to comment.