Skip to content

Commit 080da82

Browse files
committed
Merge branch 'release/0.1.7.0'
2 parents 7339a2a + 6d4bd06 commit 080da82

24 files changed

Lines changed: 567 additions & 26 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<UserControl x:Class="Utils.Controls.FilePathControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:s="clr-namespace:System;assembly=mscorlib"
7+
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
8+
x:Name="FilePath" mc:Ignorable="d">
9+
10+
<DockPanel LastChildFill="True" VerticalAlignment="Center">
11+
<Button Margin="2,0,0,0" Name="LoadButton" DockPanel.Dock="Right" Click="LoadButton_Click">
12+
<Button.Style>
13+
<Style BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button">
14+
<Setter Property="BorderThickness" Value="1" />
15+
<Setter Property="BorderBrush" Value="#D0D7E2" />
16+
<Setter Property="Width" Value="23" />
17+
<Setter Property="Height" Value="23" />
18+
<Setter Property="Content" Value="..." />
19+
</Style>
20+
</Button.Style>
21+
</Button>
22+
<sapv:ExpressionTextBox DockPanel.Dock="Left" MaxLines="1" Name="FileNameTextBox" OwnerActivity="{Binding ModelItem}"
23+
ExpressionType="s:String" HintText="{Binding HintText, ElementName=FilePath}" Expression="{Binding Expression, ElementName=FilePath}" />
24+
</DockPanel>
25+
26+
</UserControl>
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
using Microsoft.Win32;
2+
using System;
3+
using System.Activities;
4+
using System.Activities.Presentation.Model;
5+
using System.IO;
6+
using System.Windows;
7+
8+
namespace Utils.Controls
9+
{
10+
/// <summary>
11+
/// Interaction logic for ExpressionFilePathControl.xaml
12+
/// </summary>
13+
public partial class FilePathControl : System.Windows.Controls.UserControl
14+
{
15+
public static readonly DependencyProperty ModelItemProperty = DependencyProperty.Register("ModelItem", typeof(ModelItem), typeof(FilePathControl));
16+
17+
public ModelItem ModelItem
18+
{
19+
get { return GetValue(ModelItemProperty) as ModelItem; }
20+
set { SetValue(ModelItemProperty, value); }
21+
}
22+
23+
public static readonly DependencyProperty ExpressionProperty = DependencyProperty.Register("Expression", typeof(ModelItem), typeof(FilePathControl));
24+
25+
public ModelItem Expression
26+
{
27+
get { return GetValue(ExpressionProperty) as ModelItem; }
28+
set { SetValue(ExpressionProperty, value); }
29+
}
30+
31+
public static readonly DependencyProperty PropertyNameProperty = DependencyProperty.Register("PropertyName", typeof(string), typeof(FilePathControl));
32+
33+
public string PropertyName
34+
{
35+
get { return GetValue(PropertyNameProperty) as string; }
36+
set { SetValue(PropertyNameProperty, value); }
37+
}
38+
39+
public static readonly DependencyProperty HintTextProperty = DependencyProperty.Register("HintText", typeof(string), typeof(FilePathControl), new PropertyMetadata("Text must be qouted"));
40+
public string HintText
41+
{
42+
get { return GetValue(HintTextProperty) as string; }
43+
set { SetValue(HintTextProperty, value); }
44+
}
45+
public static readonly DependencyProperty FileNameProperty = DependencyProperty.Register("FileName", typeof(string), typeof(FilePathControl));
46+
public string FileName
47+
{
48+
get { return GetValue(FileNameProperty) as string; }
49+
set { SetValue(FileNameProperty, value); }
50+
}
51+
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register("Filter", typeof(string), typeof(FilePathControl));
52+
public string Filter
53+
{
54+
get { return GetValue(FilterProperty) as string; }
55+
set { SetValue(FilterProperty, value); }
56+
}
57+
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(FilePathControl));
58+
public string Title
59+
{
60+
get { return GetValue(TitleProperty) as string; }
61+
set { SetValue(TitleProperty, value); }
62+
}
63+
public static readonly RoutedEvent OpenEvent = EventManager.RegisterRoutedEvent("Open", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FilePathControl));
64+
public event RoutedEventHandler Open
65+
{
66+
add { AddHandler(OpenEvent, value); }
67+
remove { RemoveHandler(OpenEvent, value); }
68+
}
69+
public static readonly RoutedEvent FileSelectedEvent = EventManager.RegisterRoutedEvent("FileSelected", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FilePathControl));
70+
public event RoutedEventHandler FileSelected
71+
{
72+
add { AddHandler(FileSelectedEvent, value); }
73+
remove { RemoveHandler(FileSelectedEvent, value); }
74+
}
75+
public bool IsSaveDialog { get; set; }
76+
public bool? ValidateNames { get; set; }
77+
public bool? CheckFileExists { get; set; }
78+
public bool? CheckPathExists { get; set; }
79+
public FilePathControl()
80+
{
81+
Title = "Select File";
82+
this.Loaded += (s, e) =>
83+
{
84+
FileNameTextBox.HintText = HintText;
85+
};
86+
InitializeComponent();
87+
}
88+
private void LoadButton_Click(object sender, RoutedEventArgs e)
89+
{
90+
RoutedEventArgs args = new RoutedEventArgs(OpenEvent);
91+
args.Source = LoadButton;
92+
RaiseEvent(args);
93+
if (args.Handled) return;
94+
95+
FileDialog fileDialog = null;
96+
97+
if (IsSaveDialog)
98+
{
99+
fileDialog = new SaveFileDialog() { OverwritePrompt = false };
100+
}
101+
else
102+
{
103+
fileDialog = new OpenFileDialog();
104+
}
105+
106+
if (Filter == null)
107+
{
108+
Filter = "All files (*.*)|*.*";
109+
}
110+
111+
fileDialog.Filter = Filter;
112+
fileDialog.FileName = FileName;
113+
fileDialog.Title = Title;
114+
115+
if (ValidateNames != null)
116+
{
117+
fileDialog.ValidateNames = ValidateNames.Value;
118+
}
119+
120+
if (CheckFileExists != null)
121+
{
122+
fileDialog.CheckFileExists = CheckFileExists.Value;
123+
}
124+
125+
if (CheckPathExists != null)
126+
{
127+
fileDialog.CheckPathExists = CheckPathExists.Value;
128+
}
129+
130+
var workspacePath = Directory.GetCurrentDirectory();
131+
fileDialog.InitialDirectory = workspacePath;
132+
133+
var result = fileDialog.ShowDialog();
134+
if (result.HasValue && result.Value == true)
135+
{
136+
var workflowRelativePath = GetRelativePath(workspacePath, fileDialog.FileName);
137+
138+
RoutedEventArgs fileArgs = new FileSelectedRoutedEventArgs(FileSelectedEvent, workflowRelativePath);
139+
fileArgs.Source = LoadButton;
140+
RaiseEvent(fileArgs);
141+
142+
if (!fileArgs.Handled && PropertyName != null)
143+
{
144+
ModelItem.Properties[PropertyName].SetValue(new InArgument<string>(workflowRelativePath));
145+
}
146+
}
147+
}
148+
149+
public static string GetRelativePath(string basePath, string path)
150+
{
151+
if (string.IsNullOrWhiteSpace(basePath)) return path;
152+
153+
var workflowRelativePath = path;
154+
try
155+
{
156+
var workspaceUri = new Uri(Path.Combine(basePath, Path.PathSeparator.ToString()));
157+
var workflowUri = new Uri(path);
158+
159+
// the workflow is in the current workspace
160+
if (workspaceUri.IsBaseOf(workflowUri))
161+
{
162+
workflowRelativePath = Uri.UnescapeDataString(workspaceUri.MakeRelativeUri(workflowUri).OriginalString).Replace('/', Path.DirectorySeparatorChar);
163+
}
164+
}
165+
catch { }
166+
167+
return workflowRelativePath;
168+
}
169+
}
170+
171+
public class FileSelectedRoutedEventArgs : RoutedEventArgs
172+
{
173+
public string Path { get; internal set; }
174+
175+
public FileSelectedRoutedEventArgs(RoutedEvent routedEvent, string path)
176+
: base(routedEvent)
177+
{
178+
this.Path = path;
179+
}
180+
}
181+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Activities;
66
using System.ComponentModel;
77

8-
namespace Utils.Path
8+
namespace Utils.PathUtils
99
{
1010

1111
[Designer(typeof(CombineDesigner))]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<sap:ActivityDesigner x:Class="Utils.Path.CombineDesigner"
1+
<sap:ActivityDesigner x:Class="Utils.PathUtils.CombineDesigner"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:s="clr-namespace:System;assembly=mscorlib"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using System.Windows.Navigation;
1313
using System.Windows.Shapes;
1414

15-
namespace Utils.Path
15+
namespace Utils.PathUtils
1616
{
1717
// CombineDesigner.xaml の相互作用ロジック
1818
public partial class CombineDesigner
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.ComponentModel;
77
using System.IO;
88

9-
namespace Utils.Path
9+
namespace Utils.PathUtils
1010
{
1111

1212
[Designer(typeof(CurrentDirDesigner))]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<sap:ActivityDesigner x:Class="Utils.Path.CurrentDirDesigner"
1+
<sap:ActivityDesigner x:Class="Utils.PathUtils.CurrentDirDesigner"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:s="clr-namespace:System;assembly=mscorlib"

Utils/Path/CurrentDirDesigner.xaml.cs renamed to Utils/PathUtils/CurrentDirDesigner.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using System.Windows.Navigation;
1313
using System.Windows.Shapes;
1414

15-
namespace Utils.Path
15+
namespace Utils.PathUtils
1616
{
1717
// CurrentDirDesigner.xaml の相互作用ロジック
1818
public partial class CurrentDirDesigner
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.ComponentModel;
77
using System.IO;
88

9-
namespace Utils.Path
9+
namespace Utils.PathUtils
1010
{
1111

1212
[Designer(typeof(PathUtilsDesigner))]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<sap:ActivityDesigner x:Class="Utils.Path.PathUtilsDesigner"
1+
<sap:ActivityDesigner x:Class="Utils.PathUtils.PathUtilsDesigner"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:s="clr-namespace:System;assembly=mscorlib"

0 commit comments

Comments
 (0)