Skip to content

Commit 439aaac

Browse files
committed
Update from laest PR merge. Merge remote-tracking branch 'rubberduck-vba/next' into next
2 parents e21a5ad + 1349239 commit 439aaac

15 files changed

+200
-153
lines changed

RetailCoder.VBE/NLog.dll.nlog

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,13 @@
1616
deleteOldFileOnStartup="true"
1717
keepFileOpen="false"
1818
encoding="UTF-8"/>
19-
<target
20-
xsi:type="EventLog"
21-
name="eventlog"
22-
source="Rubberduck-VBA"
23-
layout="${message}${newline}Call site: ${callsite:className=true:methodName=true}${newline}Logger: ${logger}${newline}${exception:format=tostring}">
24-
</target>
2519
<target
2620
xsi:type="Debugger"
2721
name="debuglog"
2822
layout="${longdate};${uppercase:${level}};${logger};${message};${exception:format=tostring}"/>
2923
</targets>
3024
<rules>
3125
<logger name="*" minlevel="Info" writeTo="file" />
32-
<logger name="*" minlevel="Error" writeTo="eventlog"/>
3326
<logger name="*" minlevel="Trace" writeTo="debuglog" />
3427
</rules>
3528
</nlog>

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@
469469
<Compile Include="UI\CodeExplorer\Commands\AddClassModuleCommand.cs" />
470470
<Compile Include="UI\CodeExplorer\Commands\AddStdModuleCommand.cs" />
471471
<Compile Include="UI\CodeExplorer\Commands\AddTestModuleCommand.cs" />
472+
<Compile Include="UI\EnvironmentProvider.cs" />
472473
<Compile Include="UI\ModernFolderBrowser.cs" />
473474
<Compile Include="UI\Refactorings\AssignedByValParameterQuickFixDialogFactory.cs" />
474475
<Compile Include="UI\Refactorings\AssignedByValParameterQuickFixMockDialogFactory.cs" />

RetailCoder.VBE/UI/DockableWindowHost.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ protected override void DefWndProc(ref Message m)
147147
if (m.Msg == (int) WM.DESTROY)
148148
{
149149
_thisHandle.Free();
150-
return;
151150
}
152151
base.DefWndProc(ref m);
153152
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace Rubberduck.UI
4+
{
5+
public interface IEnvironmentProvider
6+
{
7+
string GetFolderPath(Environment.SpecialFolder folder);
8+
// ReSharper disable once InconsistentNaming
9+
OperatingSystem OSVersion { get; }
10+
}
11+
12+
//Wrapper to enable unit testing of folder dialogs.
13+
public class EnvironmentProvider : IEnvironmentProvider
14+
{
15+
public string GetFolderPath(Environment.SpecialFolder folder)
16+
{
17+
return Environment.GetFolderPath(folder);
18+
}
19+
20+
public OperatingSystem OSVersion { get { return Environment.OSVersion; } }
21+
}
22+
}
Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace Rubberduck.UI
1+
namespace Rubberduck.UI
42
{
53
public interface IFolderBrowserFactory
64
{
@@ -9,32 +7,46 @@ public interface IFolderBrowserFactory
97
IFolderBrowser CreateFolderBrowser(string description, bool showNewFolderButton);
108

119
IFolderBrowser CreateFolderBrowser(string description, bool showNewFolderButton,
12-
Environment.SpecialFolder rootFolder);
10+
string rootFolder);
1311
}
1412

1513
public class DialogFactory : IFolderBrowserFactory
1614
{
17-
private static readonly bool OldSchool = Environment.OSVersion.Version.Major < 6;
15+
private readonly IEnvironmentProvider _environment;
16+
private readonly bool _oldSchool;
17+
18+
public DialogFactory(IEnvironmentProvider environment)
19+
{
20+
_environment = environment;
21+
try
22+
{
23+
_oldSchool = _environment.OSVersion.Version.Major < 6;
24+
}
25+
catch
26+
{
27+
// ignored - fall back to "safe" dialog version.
28+
}
29+
}
1830

1931
public IFolderBrowser CreateFolderBrowser(string description)
2032
{
21-
return !OldSchool
22-
? new ModernFolderBrowser(description) as IFolderBrowser
23-
: new FolderBrowser(description);
33+
return !_oldSchool
34+
? new ModernFolderBrowser(_environment, description) as IFolderBrowser
35+
: new FolderBrowser(_environment, description);
2436
}
2537

2638
public IFolderBrowser CreateFolderBrowser(string description, bool showNewFolderButton)
2739
{
28-
return !OldSchool
29-
? new ModernFolderBrowser(description, showNewFolderButton) as IFolderBrowser
30-
: new FolderBrowser(description, showNewFolderButton);
40+
return !_oldSchool
41+
? new ModernFolderBrowser(_environment, description, showNewFolderButton) as IFolderBrowser
42+
: new FolderBrowser(_environment, description, showNewFolderButton);
3143
}
3244

33-
public IFolderBrowser CreateFolderBrowser(string description, bool showNewFolderButton, Environment.SpecialFolder rootFolder)
45+
public IFolderBrowser CreateFolderBrowser(string description, bool showNewFolderButton, string rootFolder)
3446
{
35-
return !OldSchool
36-
? new ModernFolderBrowser(description, showNewFolderButton, rootFolder) as IFolderBrowser
37-
: new FolderBrowser(description, showNewFolderButton, rootFolder);
47+
return !_oldSchool
48+
? new ModernFolderBrowser(_environment, description, showNewFolderButton, rootFolder) as IFolderBrowser
49+
: new FolderBrowser(_environment, description, showNewFolderButton, rootFolder);
3850
}
3951
}
4052
}

RetailCoder.VBE/UI/FolderBrowser.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,33 @@ public interface IFolderBrowser : IDisposable
77
{
88
string Description { get; set; }
99
bool ShowNewFolderButton { get; set; }
10-
Environment.SpecialFolder RootFolder { get; set; }
10+
string RootFolder { get; set; }
1111
string SelectedPath { get; set; }
1212
DialogResult ShowDialog();
1313
}
1414

1515
public class FolderBrowser : IFolderBrowser
1616
{
1717
private readonly FolderBrowserDialog _dialog;
18+
private readonly IEnvironmentProvider _environment;
1819

19-
public FolderBrowser(string description, bool showNewFolderButton, Environment.SpecialFolder rootFolder)
20+
public FolderBrowser(IEnvironmentProvider environment, string description, bool showNewFolderButton, string rootFolder)
2021
{
22+
_environment = environment;
2123
_dialog = new FolderBrowserDialog
2224
{
2325
Description = description,
24-
RootFolder = rootFolder,
26+
SelectedPath = rootFolder,
2527
ShowNewFolderButton = showNewFolderButton
2628
};
2729
}
2830

29-
public FolderBrowser(string description, bool showNewFolderButton)
30-
:this(description, showNewFolderButton, Environment.SpecialFolder.MyComputer)
31+
public FolderBrowser(IEnvironmentProvider environment, string description, bool showNewFolderButton)
32+
: this(environment, description, showNewFolderButton, environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
3133
{ }
3234

33-
public FolderBrowser(string description)
34-
: this(description, true)
35+
public FolderBrowser(IEnvironmentProvider environment, string description)
36+
: this(environment, description, true)
3537
{ }
3638

3739
public string Description
@@ -46,10 +48,10 @@ public bool ShowNewFolderButton
4648
set { _dialog.ShowNewFolderButton = value; }
4749
}
4850

49-
public Environment.SpecialFolder RootFolder
51+
public string RootFolder
5052
{
51-
get { return _dialog.RootFolder; }
52-
set { _dialog.RootFolder = value; }
53+
get { return _dialog.SelectedPath; }
54+
set { _dialog.SelectedPath = value; }
5355
}
5456

5557
public string SelectedPath

RetailCoder.VBE/UI/ModernFolderBrowser.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,22 @@ public class ModernFolderBrowser : IFolderBrowser
2929
private static readonly ConstructorInfo VistaDialogEventsCtor = VistaDialogEvents.GetConstructors().SingleOrDefault();
3030
private static readonly MethodInfo IFileDialogAdvise = IFileDialog.GetMethod("Advise", DefaultBindingFlags);
3131
private static readonly MethodInfo IFileDialogUnadvise = IFileDialog.GetMethod("Unadvise", DefaultBindingFlags);
32-
3332
// ReSharper restore InconsistentNaming
3433

3534
private readonly System.Windows.Forms.OpenFileDialog _dialog;
3635
private readonly object _newDialog;
36+
private readonly IEnvironmentProvider _environment;
3737

38-
// ReSharper disable once UnusedParameter.Local
39-
public ModernFolderBrowser(string description, bool showNewFolderButton, Environment.SpecialFolder rootFolder)
38+
// ReSharper disable once UnusedParameter.Local - new folder button suppression isn't supported in this dialog.
39+
public ModernFolderBrowser(IEnvironmentProvider environment, string description, bool showNewFolderButton, string rootFolder)
4040
{
41+
_environment = environment;
4142
_root = rootFolder;
4243
_dialog = new System.Windows.Forms.OpenFileDialog
4344
{
4445
Title = description,
45-
InitialDirectory = Environment.GetFolderPath(_root),
46-
// ReSharper disable once LocalizableElement
46+
InitialDirectory = _root,
47+
// ReSharper disable once LocalizableElement - This is an API keyword.
4748
Filter = "Folders|\n",
4849
AddExtension = false,
4950
CheckFileExists = false,
@@ -56,33 +57,34 @@ public ModernFolderBrowser(string description, bool showNewFolderButton, Environ
5657
IFileDialogSetOptions.Invoke(_newDialog, new object[] { options });
5758
}
5859

59-
public ModernFolderBrowser(string description, bool showNewFolderButton)
60-
: this(description, showNewFolderButton, Environment.SpecialFolder.MyDocuments)
60+
public ModernFolderBrowser(IEnvironmentProvider environment, string description, bool showNewFolderButton)
61+
: this(environment, description, showNewFolderButton, environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
6162
{ }
6263

63-
public ModernFolderBrowser(string description) : this(description, true) { }
64+
public ModernFolderBrowser(IEnvironmentProvider environment, string description) : this(environment, description, true) { }
6465

6566
public string Description
6667
{
6768
get { return _dialog.Title; }
6869
set { _dialog.Title = value; }
6970
}
7071

72+
//Does nothing - new folder button suppression isn't supported in this dialog.
7173
public bool ShowNewFolderButton
7274
{
7375
get { return true; }
7476
// ReSharper disable once ValueParameterNotUsed
7577
set { }
7678
}
7779

78-
private Environment.SpecialFolder _root;
79-
public Environment.SpecialFolder RootFolder
80+
private string _root;
81+
public string RootFolder
8082
{
8183
get { return _root; }
8284
set
8385
{
8486
_root = value;
85-
_dialog.InitialDirectory = Environment.GetFolderPath(_root);
87+
_dialog.InitialDirectory = _root;
8688
}
8789
}
8890

RetailCoder.VBE/UI/SourceControl/BranchesViewViewModel.cs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Text.RegularExpressions;
45
using NLog;
56
using Rubberduck.SourceControl;
67
using Rubberduck.UI.Command;
@@ -219,45 +220,12 @@ public string NewBranchName
219220
}
220221
}
221222

222-
public bool IsNotValidBranchName
223-
{
224-
get { return !IsValidBranchName(NewBranchName); }
225-
}
223+
// Courtesy of http://stackoverflow.com/a/12093994/4088852 - Assumes --allow-onelevel is set TODO: Verify provider honor that.
224+
private static readonly Regex ValidBranchNameRegex = new Regex(@"^(?!@$|build-|/|.*([/.]\.|//|@\{|\\))[^\u0000-\u0037\u0177 ~^:?*[]+/?[^\u0000-\u0037\u0177 ~^:?*[]+(?<!\.lock|[/.])$");
226225

227-
private bool IsValidBranchName(string name)
226+
public bool IsNotValidBranchName
228227
{
229-
// Rules taken from https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
230-
var isValidName = !string.IsNullOrEmpty(name) &&
231-
!LocalBranches.Contains(name) &&
232-
!name.Any(char.IsWhiteSpace) &&
233-
!name.Contains("..") &&
234-
!name.Contains("~") &&
235-
!name.Contains("^") &&
236-
!name.Contains(":") &&
237-
!name.Contains("?") &&
238-
!name.Contains("*") &&
239-
!name.Contains("[") &&
240-
!name.Contains("//") &&
241-
name.FirstOrDefault() != '/' &&
242-
name.LastOrDefault() != '/' &&
243-
name.LastOrDefault() != '.' &&
244-
name != "@" &&
245-
!name.Contains("@{") &&
246-
!name.Contains("\\");
247-
248-
if (!isValidName)
249-
{
250-
return false;
251-
}
252-
// ReSharper disable once LoopCanBeConvertedToQuery
253-
foreach (var section in name.Split('/'))
254-
{
255-
isValidName = isValidName
256-
&& section.FirstOrDefault() != '.'
257-
&& !section.EndsWith(".lock");
258-
}
259-
260-
return isValidName;
228+
get { return string.IsNullOrEmpty(NewBranchName) || !ValidBranchNameRegex.IsMatch(NewBranchName); }
261229
}
262230

263231
private bool _displayMergeBranchesGrid;

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Collections.ObjectModel;
3+
using System.Diagnostics;
4+
using System.IO;
35
using System.Linq;
46
using NLog;
57
using Rubberduck.SourceControl;
@@ -148,12 +150,9 @@ private void UndoChanges(IFileStatusEntry fileStatusEntry)
148150

149151
try
150152
{
151-
var localLocation = Provider.CurrentRepository.LocalLocation.EndsWith("\\")
152-
? Provider.CurrentRepository.LocalLocation
153-
: Provider.CurrentRepository.LocalLocation + "\\";
154-
155-
Provider.Undo(localLocation + fileStatusEntry.FilePath);
156-
153+
var file = Path.GetFileName(fileStatusEntry.FilePath);
154+
Debug.Assert(!string.IsNullOrEmpty(file));
155+
Provider.Undo(Path.Combine(Provider.CurrentRepository.LocalLocation, file));
157156
RefreshView();
158157
}
159158
catch (SourceControlException ex)

0 commit comments

Comments
 (0)