-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Haacked/haacked/browse-folder-dialog
Haacked browse folder dialog
- Loading branch information
Showing
15 changed files
with
283 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using NullGuard; | ||
|
||
namespace Rothko | ||
{ | ||
public struct BrowseDirectoryResult | ||
{ | ||
readonly bool _success; | ||
readonly string _directoryPath; | ||
|
||
/// <summary> | ||
/// Represents a failed browse result. | ||
/// </summary> | ||
public static readonly BrowseDirectoryResult Failed = new BrowseDirectoryResult(); | ||
|
||
public BrowseDirectoryResult(string directoryPath) | ||
{ | ||
if (directoryPath.Length == 0) throw new ArgumentException("Selected path cannot be empty", "directoryPath"); | ||
|
||
_success = true; | ||
_directoryPath = directoryPath; | ||
} | ||
|
||
public bool Success | ||
{ | ||
get { return _success; } | ||
} | ||
|
||
public string DirectoryPath | ||
{ | ||
get { return _directoryPath; } | ||
} | ||
|
||
public override bool Equals([AllowNull]object obj) | ||
{ | ||
if (!(obj is BrowseDirectoryResult)) return false; | ||
return this == ((BrowseDirectoryResult)obj); | ||
} | ||
|
||
public static bool operator ==(BrowseDirectoryResult a, BrowseDirectoryResult b) | ||
{ | ||
return a._success == b._success && a._directoryPath == b._directoryPath; | ||
} | ||
|
||
public static bool operator !=(BrowseDirectoryResult a, BrowseDirectoryResult b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return (17327 * 67 + _success.GetHashCode()) * 67 + (_directoryPath ?? "").GetHashCode(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
|
||
namespace Rothko.Infrastructure | ||
{ | ||
public class Browser : IBrowser | ||
{ | ||
readonly IProcessStarter processStarter; | ||
readonly IEnvironment environment; | ||
|
||
public Browser(IProcessStarter processStarter, IEnvironment environment) | ||
{ | ||
this.processStarter = processStarter; | ||
this.environment = environment; | ||
} | ||
|
||
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", | ||
Justification = "We can't anticipate the type of exception it'll throw and we want to have the fallback behavior")] | ||
public void OpenUrl(Uri url) | ||
{ | ||
if (url.IsAbsoluteUri) throw new ArgumentException("URL must be an absolute uri", "url"); | ||
|
||
try | ||
{ | ||
processStarter.Start(url.ToString(), null); | ||
} | ||
catch (Exception firstAttemptException) | ||
{ | ||
try | ||
{ | ||
var programFiles = environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles); | ||
|
||
processStarter.Start(Path.Combine(programFiles, @"Internet Explorer", "iexplore.exe"), | ||
url.ToString()); | ||
} | ||
catch (Exception secondAttemptException) | ||
{ | ||
throw new AggregateException(firstAttemptException, secondAttemptException); | ||
} | ||
} | ||
} | ||
|
||
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", | ||
Justification = "By design, this method should not throw.")] | ||
public bool TryOpenUrl(Uri url) | ||
{ | ||
try | ||
{ | ||
OpenUrl(url); | ||
return true; | ||
} | ||
catch (Exception) | ||
{ | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
|
||
namespace Rothko | ||
{ | ||
public interface IBrowser | ||
{ | ||
/// <summary> | ||
/// Opens the user's default browser to the specified URL. | ||
/// </summary> | ||
/// <param name="url"></param> | ||
void OpenUrl(Uri url); | ||
|
||
/// <summary> | ||
/// Opens the user's default browser to the specified URL and returns false if it was unable to. | ||
/// </summary> | ||
/// <param name="url"></param> | ||
bool TryOpenUrl(Uri url); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Rothko | ||
namespace Rothko | ||
{ | ||
public interface IOperatingSystem : ICloneable, ISerializable | ||
public interface IOperatingSystem | ||
{ | ||
PlatformID Platform { get; } | ||
string ServicePack { get; } | ||
Version Version { get; } | ||
string VersionString { get; } | ||
string Name { get; } | ||
string Edition { get; } | ||
IAssemblyFacade Assembly { get; } | ||
IDialogFacade Dialog { get; } | ||
IDirectoryFacade Directory { get; } | ||
IEnvironment Environment { get; } | ||
IFileFacade File { get; } | ||
IMemoryMappedFileFactory MemoryMappedFiles { get; } | ||
IProcessLocator ProcessLocator { get; } | ||
IProcessStarter ProcessStarter { get; } | ||
IRegistry Registry { get; } | ||
IBrowser Browser { get; } | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Rothko | ||
{ | ||
public interface IOperatingSystemInfo : ICloneable, ISerializable | ||
{ | ||
PlatformID Platform { get; } | ||
string ServicePack { get; } | ||
Version Version { get; } | ||
string VersionString { get; } | ||
string Name { get; } | ||
string Edition { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using NullGuard; | ||
|
||
namespace Rothko | ||
{ | ||
public struct SaveDialogResult | ||
{ | ||
readonly bool _success; | ||
readonly string _fileName; | ||
|
||
public static readonly SaveDialogResult Failed = new SaveDialogResult(); | ||
|
||
public SaveDialogResult(string chosenFileName) | ||
{ | ||
_success = true; | ||
_fileName = chosenFileName; | ||
} | ||
|
||
public bool Success | ||
{ | ||
get { return _success; } | ||
} | ||
|
||
public string FileName | ||
{ | ||
get { return _fileName; } | ||
} | ||
|
||
public override bool Equals([AllowNull]object obj) | ||
{ | ||
if (!(obj is SaveDialogResult)) return false; | ||
return this == ((SaveDialogResult)obj); | ||
} | ||
|
||
public static bool operator ==(SaveDialogResult a, SaveDialogResult b) | ||
{ | ||
return a._success == b._success && a._fileName == b._fileName; | ||
} | ||
|
||
public static bool operator !=(SaveDialogResult a, SaveDialogResult b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return (17327 * 67 + _success.GetHashCode()) * 67 + (_fileName ?? "").GetHashCode(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.