forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileListToDescriptionConverter.cs
More file actions
49 lines (42 loc) · 1.34 KB
/
FileListToDescriptionConverter.cs
File metadata and controls
49 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using Microsoft.UI.Xaml.Data;
namespace PowerToys.FileLocksmithUI.Converters
{
public sealed partial class FileListToDescriptionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var paths = (string[])value;
if (paths.Length == 0)
{
return string.Empty;
}
string firstPath = paths[0];
firstPath = Path.GetFileName(paths[0]);
if (string.IsNullOrEmpty(firstPath))
{
firstPath = Path.GetDirectoryName(paths[0]);
}
if (string.IsNullOrEmpty(firstPath))
{
firstPath = Path.GetPathRoot(paths[0]);
}
if (paths.Length == 1)
{
return firstPath;
}
else
{
return firstPath + "; +" + (paths.Length - 1);
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return value;
}
}
}