Skip to content

Commit

Permalink
Merge pull request #62 from runceel/master
Browse files Browse the repository at this point in the history
  • Loading branch information
soi013 authored Jan 28, 2021
2 parents 6f65fc5 + f318497 commit b2bacf9
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Livet.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Version>3.2.3.1</Version>
<Version>3.2.3.2</Version>
<PackageVersion>$(Version)</PackageVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Windows;
using Livet.Dialogs;
using Livet.Messaging;
Expand Down Expand Up @@ -32,10 +33,17 @@ protected override void InvokeAction(InteractionMessage m)
dialog.Title = folderSelectionMessage.Title;
dialog.Description = folderSelectionMessage.Description;
dialog.SelectedPath = folderSelectionMessage.SelectedPath;
dialog.Multiselect = folderSelectionMessage.Multiselect;

folderSelectionMessage.Response = dialog.ShowDialog(hostWindow).GetValueOrDefault()
? dialog.SelectedPath
: null;
if (dialog.ShowDialog(hostWindow).GetValueOrDefault())
{
folderSelectionMessage.SelectedPaths = dialog.SelectedPaths;
folderSelectionMessage.Response = folderSelectionMessage.SelectedPaths.FirstOrDefault();
}
else
{
folderSelectionMessage.Response = null;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using Livet.Annotations;
using Microsoft.WindowsAPICodePack.Dialogs;
Expand All @@ -19,7 +21,7 @@ internal sealed class CommonOpenFileFolderSelectionDialog : FolderSelectionDialo
/// </summary>
public CommonOpenFileFolderSelectionDialog()
{
_commonOpenFileDialog = new CommonOpenFileDialog {IsFolderPicker = true, Multiselect = false};
_commonOpenFileDialog = new CommonOpenFileDialog { IsFolderPicker = true, Multiselect = false };
_defaultTitle = _commonOpenFileDialog.Title;
}

Expand Down Expand Up @@ -47,6 +49,16 @@ public override string Description
set { }
}

/// <summary>
/// Gets or sets whether the multi selection is enabled on the folder browser dialog.
/// </summary>
public override bool Multiselect
{
get { return _commonOpenFileDialog.Multiselect; }

set { _commonOpenFileDialog.Multiselect = value; }
}

/// <summary>
/// Gets or sets the selected path.
/// </summary>
Expand Down Expand Up @@ -76,6 +88,14 @@ public override string SelectedPath
}
}

/// <summary>
/// Gets or sets the selected paths.
/// </summary>
public override string[] SelectedPaths
{
get { return _commonOpenFileDialog.FileNames.ToArray(); }
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions LivetCask.Extensions/Dialogs/FolderBrowserFolderSelectionDialog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
Expand Down Expand Up @@ -71,6 +72,26 @@ public override string Title
set { }
}


/// <summary>
/// This property is not supported.
/// </summary>
/// <value>Always false.</value>
public override bool Multiselect
{
get { return false; }
set { }
}

/// <summary>
/// Gets or sets the selected paths.
/// </summary>
/// <value>Always return SelectedPath.</value>
public override string[] SelectedPaths
{
get { return new[] { SelectedPath }; }
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions LivetCask.Extensions/Dialogs/FolderSelectionDialog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Windows;

namespace Livet.Dialogs
Expand Down Expand Up @@ -35,6 +36,17 @@ internal abstract class FolderSelectionDialog : IDisposable
/// </value>
public abstract string Title { get; set; }


/// <summary>
/// Gets or sets whether the multi selection is enabled on the folder browser dialog.
/// </summary>
public abstract bool Multiselect { get; set; }

/// <summary>
/// Gets or sets the selected paths.
/// </summary>
public abstract string[] SelectedPaths { get; }

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
Expand Down
58 changes: 53 additions & 5 deletions LivetCask.Extensions/Messaging/IO/FolderSelectionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public sealed class FolderSelectionMessage : ResponsiveInteractionMessage<string
/// <value>
/// <see cref="DependencyProperty" />.
/// </value>
[NotNull] public static readonly DependencyProperty DescriptionProperty =
[NotNull]
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(FolderSelectionMessage),
new UIPropertyMetadata(null));

Expand All @@ -29,7 +30,8 @@ public sealed class FolderSelectionMessage : ResponsiveInteractionMessage<string
/// <value>
/// <see cref="DependencyProperty" />.
/// </value>
[NotNull] public static readonly DependencyProperty TitleProperty =
[NotNull]
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(FolderSelectionMessage),
new UIPropertyMetadata(string.Empty));

Expand All @@ -39,19 +41,44 @@ public sealed class FolderSelectionMessage : ResponsiveInteractionMessage<string
/// <value>
/// <see cref="DependencyProperty" />.
/// </value>
[NotNull] public static readonly DependencyProperty SelectedPathProperty =
[NotNull]
public static readonly DependencyProperty SelectedPathProperty =
DependencyProperty.Register("SelectedPath", typeof(string), typeof(FolderSelectionMessage),
new UIPropertyMetadata(string.Empty));

/// <summary>
/// Defines <see cref="SelectedPaths" /> dependency property.
/// </summary>
/// <value>
/// <see cref="DependencyProperty" />.
/// </value>
[NotNull]
public static readonly DependencyProperty SelectedPathsProperty =
DependencyProperty.Register("SelectedPaths", typeof(string[]), typeof(FolderSelectionMessage),
new UIPropertyMetadata(new[] { string.Empty }));

/// <summary>
/// Defines <see cref="SelectedPath" /> dependency property.
/// </summary>
/// <value>
/// <see cref="DependencyProperty" />.
/// </value>
[NotNull] public static readonly DependencyProperty DialogPreferenceProperty =
[NotNull]
public static readonly DependencyProperty DialogPreferenceProperty =
DependencyProperty.Register("DialogPreference", typeof(FolderSelectionDialogPreference),
typeof(FileSelectionMessage), new UIPropertyMetadata(FolderSelectionDialogPreference.None));
/// <summary>
/// Defines <see cref="Multiselect" /> dependency property.
/// </summary>
/// <value>
/// <see cref="DependencyProperty" />.
/// </value>
[NotNull]
public static readonly DependencyProperty MultiselectProperty =
DependencyProperty.Register("Multiselect", typeof(bool),
typeof(FileSelectionMessage), new UIPropertyMetadata(false));



/// <summary>
/// Initializes a new instance of the <see cref="FolderSelectionMessage" /> class
Expand Down Expand Up @@ -92,6 +119,15 @@ public string Title
set { SetValue(TitleProperty, value); }
}

/// <summary>
/// Gets or sets whether the multi selection is enabled on the folder browser dialog.
/// </summary>
public bool Multiselect
{
get { return (bool)GetValue(MultiselectProperty); }
set { SetValue(MultiselectProperty, value); }
}

/// <summary>
/// Gets or sets the selected path on the folder selection dialog.
/// </summary>
Expand All @@ -105,6 +141,18 @@ public string SelectedPath
set { SetValue(SelectedPathProperty, value); }
}

/// <summary>
/// Gets or sets the selected paths on the folder selection dialog.
/// </summary>
/// <value>
/// The selected paths on the folder selection dialog.
/// </value>
public string[] SelectedPaths
{
get { return GetValue(SelectedPathsProperty) as string[]; }
set { SetValue(SelectedPathsProperty, value); }
}

/// <summary>
/// Gets or sets the dialog preference.
/// </summary>
Expand All @@ -117,7 +165,7 @@ public FolderSelectionDialogPreference DialogPreference
{
var value = GetValue(DialogPreferenceProperty);
return value?.GetType() == typeof(FolderSelectionDialogPreference)
? (FolderSelectionDialogPreference) value
? (FolderSelectionDialogPreference)value
: default;
}
set { SetValue(DialogPreferenceProperty, value); }
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ zlib/libpng ライセンスでは、ライブラリとしての利用にとど

しかし、ソースコードを改変しての再配布にはその旨の明示が義務付けられます。

## GitHub スポンサー

応援してもらえるとモチベーションが上がります。

|Name|GitHub Sponsors|
|----|----|
|runceel|https://github.com/sponsors/runceel|


## 導入

Livet は Visual Studio 2019 の拡張機能を使用することでプロジェクトテンプレートやアイテムテンプレートやコードスニペットが追加され生産性が一番高い状態で開発が出来るように設計されています。
Expand Down
16 changes: 15 additions & 1 deletion Samples/ViewLayerSupport/ViewModels/MessagingWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,25 @@ public void ConfirmFromView([NotNull] ConfirmationMessage message)
OutputMessage = $"{DateTime.Now}: ConfirmFromView: {message.Response ?? false}";
}

public void FileSelected([NotNull] OpeningFileSelectionMessage message)
{
if (message == null) throw new ArgumentNullException(nameof(message));


string selectedPaths = message.Response == null
? "未選択"
: String.Join(";", message.Response);
OutputMessage = $"{DateTime.Now}: FileSelected: {selectedPaths}";
}
public void FolderSelected([NotNull] FolderSelectionMessage message)
{
if (message == null) throw new ArgumentNullException(nameof(message));

OutputMessage = $"{DateTime.Now}: FolderSelected: {message.Response ?? "未選択"}";
string selectedPaths = message.Response == null
? "未選択"
: String.Join(";", message.SelectedPaths);

OutputMessage = $"{DateTime.Now}: FolderSelected: {selectedPaths}";
}

public void Initialize() { }
Expand Down
Loading

0 comments on commit b2bacf9

Please sign in to comment.