Browse Source

Add Unassociate functionality, refactor, improve #157

Ruben 7 tháng trước cách đây
mục cha
commit
12d6ff3df4

+ 167 - 131
src/PicView.Avalonia/Views/FileAssociationsView.axaml

@@ -9,155 +9,191 @@
     xmlns:customControls="clr-namespace:PicView.Avalonia.CustomControls"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    xmlns:uc="clr-namespace:PicView.Avalonia.Views.UC"
     xmlns:viewModels="clr-namespace:PicView.Avalonia.ViewModels"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     <Design.DataContext>
         <viewModels:MainViewModel />
     </Design.DataContext>
 
-    <StackPanel
-        Focusable="True"
-        HorizontalAlignment="Center"
-        Orientation="Vertical">
-
-        <TextBlock
-            Classes="txt"
-            FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
-            FontSize="14"
-            Margin="0,20,0,0"
-            Text="File associations" />
-
-        <TextBlock
-            Classes="txt"
-            Foreground="{StaticResource SecondaryTextColor}"
-            HorizontalAlignment="Left"
-            Padding="0,5,10,15"
-            Text="Select file types to associate. Unselected types will be unregistered." />
+    <Panel>
+
+        <uc:SpinWaiter IsVisible="{CompiledBinding AssociationsViewModel.IsProcessing, Mode=OneWay}" />
 
         <StackPanel
-            Background="Transparent"
-            HorizontalAlignment="Right"
-            Margin="0,0,0,5"
-            Orientation="Horizontal">
+            Focusable="True"
+            HorizontalAlignment="Center"
+            IsHitTestVisible="{CompiledBinding !AssociationsViewModel.IsProcessing,
+                                               Mode=OneWay}"
+            Opacity="{CompiledBinding AssociationsViewModel.Opacity,
+                                      Mode=OneWay}"
+            Orientation="Vertical">
+
+            <TextBlock
+                Classes="txt"
+                FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
+                FontSize="14"
+                Margin="0,20,0,0"
+                Text="File associations" />
+
+            <TextBlock
+                Classes="txt"
+                Foreground="{StaticResource SecondaryTextColor}"
+                HorizontalAlignment="Left"
+                Padding="0,5,10,15"
+                Text="Select file types to associate. Unselected types will be unregistered." />
+
+            <StackPanel
+                Background="Transparent"
+                HorizontalAlignment="Right"
+                Margin="0,0,0,5"
+                Orientation="Horizontal">
 
-            <Panel>
+                <Panel>
 
-                <Image
-                    Height="14"
-                    HorizontalAlignment="Left"
-                    Margin="5,0,0,0"
-                    Source="{StaticResource SearchImage}"
-                    Width="14" />
-
-                <AutoCompleteBox
-                    Background="Transparent"
-                    BorderBrush="Transparent"
-                    FontFamily="/Assets/Fonts/Roboto-Regular.ttf#Roboto"
-                    Foreground="{DynamicResource MainTextColor}"
-                    HorizontalAlignment="Left"
-                    Padding="23,7,4,6"
-                    Text="{CompiledBinding AssociationsViewModel.FilterText,
-                                           FallbackValue='',
-                                           Mode=TwoWay}"
-                    Watermark="Filter..."
-                    Width="269"
-                    x:Name="FilterBox" />
-
-                <customControls:IconButton
+                    <Image
+                        Height="14"
+                        HorizontalAlignment="Left"
+                        Margin="5,0,0,0"
+                        Source="{StaticResource SearchImage}"
+                        Width="14" />
+
+                    <AutoCompleteBox
+                        Background="Transparent"
+                        BorderBrush="Transparent"
+                        FontFamily="/Assets/Fonts/Roboto-Regular.ttf#Roboto"
+                        Foreground="{DynamicResource MainTextColor}"
+                        HorizontalAlignment="Left"
+                        Padding="23,7,4,6"
+                        Text="{CompiledBinding AssociationsViewModel.FilterText,
+                                               FallbackValue='',
+                                               Mode=TwoWay}"
+                        Watermark="Filter..."
+                        Width="269"
+                        x:Name="FilterBox" />
+
+                    <customControls:IconButton
+                        Classes="altHover"
+                        Command="{CompiledBinding AssociationsViewModel.ClearFilterCommand}"
+                        Data="{StaticResource CloseGeometry}"
+                        DockPanel.Dock="Right"
+                        Foreground="{DynamicResource MainTextColorFaded}"
+                        HorizontalAlignment="Right"
+                        IconHeight="12"
+                        IconWidth="12"
+                        IsVisible="{CompiledBinding AssociationsViewModel.FilterText,
+                                                    Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
+                        Padding="10,3,10,3"
+                        x:Name="ClearButton" />
+                </Panel>
+
+                <Button
                     Classes="altHover"
-                    Command="{CompiledBinding AssociationsViewModel.ClearFilterCommand}"
-                    Data="{StaticResource CloseGeometry}"
-                    DockPanel.Dock="Right"
-                    Foreground="{DynamicResource MainTextColorFaded}"
-                    HorizontalAlignment="Right"
-                    IconHeight="12"
-                    IconWidth="12"
-                    IsVisible="{CompiledBinding AssociationsViewModel.FilterText,
-                                                Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
-                    Padding="10,3,10,3"
-                    x:Name="ClearButton" />
-            </Panel>
-
-            <Button
-                Classes="altHover"
-                Padding="10,2,10,2"
-                x:Name="SelectAllButton">
-                <TextBlock
-                    Classes="txt"
-                    Foreground="{StaticResource SecondaryTextColor}"
-                    Text="{CompiledBinding Translation.SelectAll,
-                                           Mode=OneWay}" />
-            </Button>
-
-            <Rectangle
-                Fill="{DynamicResource TertiaryBorderColor}"
-                Height="16"
-                Margin="5,0,5,0"
-                Width="2" />
-
-            <Button
-                Classes="altHover"
-                Padding="10,2,10,2"
-                x:Name="UnSelectAllButton">
-                <TextBlock
-                    Classes="txt"
-                    Foreground="{StaticResource SecondaryTextColor}"
-                    Text="Unselect All" />
-            </Button>
-        </StackPanel>
-
+                    Padding="10,2,10,2"
+                    x:Name="SelectAllButton">
+                    <TextBlock
+                        Classes="txt"
+                        Foreground="{StaticResource SecondaryTextColor}"
+                        Text="{CompiledBinding Translation.SelectAll,
+                                               Mode=OneWay}" />
+                </Button>
 
-        <customControls:AutoScrollViewer
-            Background="Transparent"
-            Height="520"
-            x:Name="FileTypesScrollViewer">
-            <StackPanel x:Name="FileTypesContainer">
-                <StackPanel.Styles>
-                    <Style Selector="CheckBox.x">
-                        <Setter Property="Margin" Value="15,0,0,5" />
-                    </Style>
-                    <Style Selector="CheckBox.y">
-                        <Setter Property="Margin" Value="0,10,0,10" />
-                    </Style>
-                </StackPanel.Styles>
+                <Rectangle
+                    Fill="{DynamicResource TertiaryBorderColor}"
+                    Height="16"
+                    Margin="5,0,5,0"
+                    Width="2" />
 
+                <Button
+                    Classes="altHover"
+                    Padding="10,2,10,2"
+                    x:Name="UnSelectAllButton">
+                    <TextBlock
+                        Classes="txt"
+                        Foreground="{StaticResource SecondaryTextColor}"
+                        Text="Unselect All" />
+                </Button>
             </StackPanel>
-        </customControls:AutoScrollViewer>
 
-        <DockPanel Margin="0,15,0,0">
 
-            <Button
-                Background="{DynamicResource AccentColor}"
-                Classes="BorderStyle accentHover mainBtn"
-                Command="{CompiledBinding AssociationsViewModel.ApplyCommand}"
-                DockPanel.Dock="Right"
-                HorizontalAlignment="Right">
-                <StackPanel Orientation="Horizontal">
-                    <Image
-                        Height="18"
-                        Margin="0,0,10,0"
-                        Source="{StaticResource UserShieldImage}"
-                        Width="18" />
+            <customControls:AutoScrollViewer
+                Background="Transparent"
+                Height="520"
+                x:Name="FileTypesScrollViewer">
+                <StackPanel x:Name="FileTypesContainer">
+                    <StackPanel.Styles>
+                        <Style Selector="CheckBox.x">
+                            <Setter Property="Margin" Value="15,0,0,5" />
+                        </Style>
+                        <Style Selector="CheckBox.y">
+                            <Setter Property="Margin" Value="0,10,0,10" />
+                        </Style>
+                    </StackPanel.Styles>
+
+                </StackPanel>
+            </customControls:AutoScrollViewer>
+
+            <DockPanel Margin="0,15,0,0">
+
+                <Button
+                    Classes="altHover"
+                    DockPanel.Dock="Left"
+                    HorizontalAlignment="Left"
+                    Padding="20,10"
+                    x:Name="ResetButton">
                     <TextBlock
                         Classes="txt"
-                        Margin="0,0,10,0"
-                        Text="{CompiledBinding Translation.Apply,
+                        Foreground="{StaticResource SecondaryTextColor}"
+                        Text="{CompiledBinding Translation.Reset,
                                                Mode=OneWay}" />
-                </StackPanel>
-            </Button>
+                </Button>
 
-            <Button
-                Classes="altHover y"
-                DockPanel.Dock="Right"
-                HorizontalAlignment="Right"
-                Padding="5,0">
-                <TextBlock
-                    Classes="txt"
-                    Foreground="{StaticResource SecondaryTextColor}"
-                    Text="{CompiledBinding Translation.ResetButtonText,
-                                           Mode=OneWay}" />
-            </Button>
-
-        </DockPanel>
-    </StackPanel>
+                <Button
+                    Background="{DynamicResource AccentColor}"
+                    Classes="BorderStyle accentHover mainBtn"
+                    Command="{CompiledBinding AssociationsViewModel.ApplyCommand}"
+                    DockPanel.Dock="Right"
+                    HorizontalAlignment="Right"
+                    Padding="20,10">
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock
+                            Classes="txt"
+                            Margin="10,0,0,0"
+                            Text="{CompiledBinding Translation.Apply,
+                                                   Mode=OneWay}" />
+                        <Image
+                            Height="18"
+                            Margin="10,0,0,0"
+                            Source="{StaticResource UserShieldImage}"
+                            Width="18" />
+                    </StackPanel>
+                </Button>
+
+                <Button
+                    Classes="errorHover"
+                    Command="{CompiledBinding AssociationsViewModel.UnassociateCommand}"
+                    DockPanel.Dock="Right"
+                    HorizontalAlignment="Right"
+                    Padding="5,0"
+                    x:Name="UnassociateButton">
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock
+                            Classes="txt"
+                            Margin="10,0,0,0"
+                            Text="Unassociate" />
+                        <Image
+                            Height="18"
+                            Margin="10,0,10,0"
+                            Source="{StaticResource UserShieldImage}"
+                            Width="18" />
+                    </StackPanel>
+                </Button>
+
+
+
+
+
+            </DockPanel>
+        </StackPanel>
+    </Panel>
 </UserControl>

+ 65 - 16
src/PicView.Avalonia/Views/FileAssociationsView.axaml.cs

@@ -32,7 +32,6 @@ public partial class FileAssociationsView : UserControl
         {
             FilterBox.TextChanged += FilterBox_TextChanged;
             
-            // Setup binding for the buttons
             SelectAllButton.Click += delegate
             {
                 foreach (var checkBox in FileTypesContainer.Children.OfType<CheckBox>())
@@ -80,9 +79,56 @@ public partial class FileAssociationsView : UserControl
                 }
             };
             
+            ResetButton.Click += delegate
+            {
+                if (DataContext is not MainViewModel { AssociationsViewModel: not null } vm)
+                {
+                    return;
+                }
+
+                // Use the view model to reset file types to default
+                vm.AssociationsViewModel.ResetFileTypesToDefault();
+                    
+                // Now update the UI checkboxes based on the reset data
+                var checkboxes = FileTypesContainer.Children.OfType<CheckBox>().ToArray();
+                    
+                foreach (var checkbox in checkboxes)
+                {
+                    ResetCheckboxStateFromViewModel(checkbox, vm.AssociationsViewModel);
+                }
+            };
+            
             InitializeCheckBoxesCollection();
         };
     }
+    
+    private static void ResetCheckboxStateFromViewModel(CheckBox checkbox, FileAssociationsViewModel viewModel)
+    {
+        var tag = checkbox.Tag?.ToString();
+        if (tag == "group") // group checkbox
+        {
+            var name = checkbox.Name;
+            var group = viewModel.FileTypeGroups.FirstOrDefault(g => g.Name?.Trim() == name);
+            if (group != null)
+            {
+                checkbox.IsChecked = group.IsSelected;
+            }
+        }
+        else if (!string.IsNullOrEmpty(tag)) // file type checkbox
+        {
+            foreach (var group in viewModel.FileTypeGroups)
+            {
+                foreach (var fileType in group.FileTypes)
+                {
+                    if (fileType.Extension.Contains(tag))
+                    {
+                        checkbox.IsChecked = fileType.IsSelected;
+                        break;
+                    }
+                }
+            }
+        }
+    }
         
     private void InitializeCheckBoxesCollection()
     {
@@ -151,9 +197,11 @@ public partial class FileAssociationsView : UserControl
             // Handle group checkbox changes to update all items in the group
             groupCheckBox.Click += delegate
             {
+                var isChecked = groupCheckBox.IsChecked;
+
                 foreach (var fileType in fileTypeGroup.FileTypes)
                 {
-                    fileType.IsSelected = groupCheckBox.IsChecked;
+                    fileType.IsSelected = isChecked;
                 }
                 UpdateCheckBoxesFromViewModel();
             };
@@ -248,22 +296,23 @@ public partial class FileAssociationsView : UserControl
         // Find the group checkbox
         var groupCheckbox = FileTypesContainer.Children.OfType<CheckBox>()
             .FirstOrDefault(c => c.Tag?.ToString() == "group" && c.Name == group.Name.Trim());
-    
-        if (groupCheckbox != null)
+
+        if (groupCheckbox == null)
         {
-            // Set state based on children
-            if (anyNull)
-                groupCheckbox.IsChecked = null;
-            else if (allTrue)
-                groupCheckbox.IsChecked = true;
-            else if (allFalse)
-                groupCheckbox.IsChecked = false;
-            else
-                groupCheckbox.IsChecked = null; // Mixed state
-            
-            // Update the ViewModel
-            group.IsSelected = groupCheckbox.IsChecked;
+            return;
         }
+
+        if (anyNull)
+            groupCheckbox.IsChecked = null;
+        else if (allTrue)
+            groupCheckbox.IsChecked = true;
+        else if (allFalse)
+            groupCheckbox.IsChecked = false;
+        else
+            groupCheckbox.IsChecked = null;
+            
+        // Update the ViewModel
+        group.IsSelected = groupCheckbox.IsChecked;
     }
 
     private bool IsCheckboxInGroup(CheckBox checkbox, FileTypeGroup group)

+ 16 - 37
src/PicView.Core/FileAssociations/FileTypeHelper.cs

@@ -4,6 +4,7 @@ using System.Runtime.InteropServices;
 using System.Security.Principal;
 using PicView.Core.FileHandling;
 using PicView.Core.Localization;
+using PicView.Core.ProcessHandling;
 
 namespace PicView.Core.FileAssociations;
 
@@ -26,9 +27,9 @@ public static class FileTypeHelper
             ]),
             
             new FileTypeGroup(TranslationManager.GetTranslation("Graphics"), [
-                new FileTypeItem("Scalable Vector Graphics", [".svg", ".svgz"]),
-                new FileTypeItem("Photoshop", [".psd", ".psb"]),
-                new FileTypeItem("XCF", [".xcf"]),
+                new FileTypeItem("Scalable Vector Graphics", [".svg", ".svgz"], null),
+                new FileTypeItem("Photoshop", [".psd", ".psb"], null),
+                new FileTypeItem("XCF", [".xcf"], null),
                 new FileTypeItem("Tagged Image File Format", [".tif", ".tiff"]),
                 new FileTypeItem("High-Enhanced Image File", [".heic", ".heif"]),
                 new FileTypeItem("JPEG XL", [".jxl"]),
@@ -67,7 +68,7 @@ public static class FileTypeHelper
             
             new FileTypeGroup(TranslationManager.GetTranslation("Uncommon"), [
                 new FileTypeItem("Wordperfect Graphics", [".wpg"]),
-                new FileTypeItem("Paintbrush bitmap graphics", [".pcx"]),
+                new FileTypeItem("Paintbrush bitmap graphics", [".pcx"], null),
                 new FileTypeItem("X Bitmap", [".xbm"]),
                 new FileTypeItem("PX PixMap Bitmap", [".xpm"]),
                 new FileTypeItem("Dr. Halo ", [".cut"]),
@@ -122,17 +123,18 @@ public static class FileTypeHelper
                         }
                     }
                 }
-                
-                if (extensionsToAssociate.Count > 0)
+
+                if (extensionsToAssociate.Count <= 0)
                 {
-                    // Create command arguments - keep argument string shorter to avoid issues
-                    string associateArg = "associate:" + string.Join(",", extensionsToAssociate);
-                    
-                    // Start new process with elevated permissions
-                    return StartProcessWithElevatedPermission(associateArg);
+                    return true; // Nothing to do
                 }
-                
-                return true; // Nothing to do
+
+                // Create command arguments - keep argument string shorter to avoid issues
+                var associateArg = "associate:" + string.Join(",", extensionsToAssociate);
+                    
+                // Start new process with elevated permissions
+                return ProcessHelper.StartProcessWithElevatedPermission(associateArg);
+
             }
             
             // Standard processing path (non-Windows or already has admin rights)
@@ -183,36 +185,13 @@ public static class FileTypeHelper
         return principal.IsInRole(WindowsBuiltInRole.Administrator);
     }
     
-    private static bool StartProcessWithElevatedPermission(string arguments)
-    {
-        try
-        {
-            var startInfo = new ProcessStartInfo
-            {
-                FileName = Process.GetCurrentProcess().MainModule?.FileName,
-                Arguments = arguments,
-                UseShellExecute = true,
-                Verb = "runas" // This requests elevated permissions
-            };
-            
-            Process.Start(startInfo);
-            return true;
-        }
-        catch (Exception ex)
-        {
-            // User declined the UAC prompt or other error
-            Debug.WriteLine($"Failed to start elevated process: {ex.Message}");
-            return false;
-        }
-    }
-    
     public static async Task ProcessFileAssociationArguments(string arg)
     {
         try
         {
             if (arg.StartsWith("associate:", StringComparison.OrdinalIgnoreCase))
             {
-                string extensionsString = arg["associate:".Length..];
+                var extensionsString = arg["associate:".Length..];
                 if (string.IsNullOrWhiteSpace(extensionsString))
                     return;
                     

+ 25 - 2
src/PicView.Core/ProcessHandling/ProcessHelper.cs

@@ -38,15 +38,38 @@ public static class ProcessHelper
 
         return GetAppPath;
     }
+    
+    public static bool StartProcessWithElevatedPermission(string arguments)
+    {
+        try
+        {
+            var startInfo = new ProcessStartInfo
+            {
+                FileName = Process.GetCurrentProcess().MainModule?.FileName,
+                Arguments = arguments,
+                UseShellExecute = true,
+                Verb = "runas"
+            };
+            
+            Process.Start(startInfo);
+            return true;
+        }
+        catch (Exception ex)
+        {
+            // User declined the UAC prompt or other error
+            Debug.WriteLine($"Failed to start elevated process: {ex.Message}");
+            return false;
+        }
+    }
 
     /// <summary>
     /// Restarts the current application.
     /// </summary>
     public static void RestartApp(string? args)
     {
-        var GetAppPath = GetPathToProcess();
+        var getAppPath = GetPathToProcess();
 
-        Process.Start(new ProcessStartInfo(GetAppPath, args));
+        Process.Start(new ProcessStartInfo(getAppPath, args));
     }
 
     /// <summary>

+ 108 - 3
src/PicView.Core/ViewModels/FileAssociationsViewModel.cs

@@ -21,15 +21,23 @@ public class FileAssociationsViewModel : ReactiveObject
         set => this.RaiseAndSetIfChanged(ref field, value);
     } = string.Empty;
 
-    private bool IsProcessing
+    public bool IsProcessing
     {
         get;
         set => this.RaiseAndSetIfChanged(ref field, value);
     }
 
+    public double Opacity
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    } = 1.0;
+
     public ReactiveCommand<Unit, bool> ApplyCommand { get; }
     public ReactiveCommand<Unit, string> ClearFilterCommand { get; }
     
+    public ReactiveCommand<Unit, Unit> UnassociateCommand { get; }
+    
     public FileAssociationsViewModel()
     {
         // Create file type groups and populate with data
@@ -64,8 +72,36 @@ public class FileAssociationsViewModel : ReactiveObject
                 Debug.WriteLine($"Error in ApplyCommand: {ex}");
 #endif
             });
+        
+        UnassociateCommand = ReactiveCommand.CreateFromTask(async () =>
+        {
+            try
+            {
+                IsProcessing = true;
+                UnselectFileTypes();
+                await FileTypeHelper.SetFileAssociations(FileTypeGroups);
+            }
+            finally
+            {
+                IsProcessing = false;
+            }
+        }, canExecute);
+        
+        UnassociateCommand.ThrownExceptions
+            .Subscribe(ex => 
+            {
+                IsProcessing = false;
+#if DEBUG
+                Debug.WriteLine($"Error in UnassociateCommand: {ex}");
+#endif
+            });
             
         ClearFilterCommand = ReactiveCommand.Create(() => FilterText = string.Empty);
+        
+        this.WhenAnyValue(x => x.IsProcessing).Subscribe(isProcessing =>
+        {
+            Opacity = isProcessing ? 0.3 : 1.0;
+        });
     }
     
     private Func<FileTypeGroup, bool> BuildFilter(string? filter)
@@ -129,8 +165,8 @@ public class FileAssociationsViewModel : ReactiveObject
             IsProcessing = false;
         }
     }
-    
-    public void InitializeFileTypes()
+
+    private void InitializeFileTypes()
     {
         var groups = FileTypeHelper.GetFileTypes();
         
@@ -140,4 +176,73 @@ public class FileAssociationsViewModel : ReactiveObject
             list.AddRange(groups);
         });
     }
+    
+    public void ResetFileTypesToDefault()
+    {
+        // Get fresh default file types
+        var defaultGroups = FileTypeHelper.GetFileTypes();
+    
+        // Make a copy of the current groups to avoid enumeration issues
+        var currentGroups = _fileTypeGroups.ToArray();
+    
+        // Update selection states based on the defaults
+        foreach (var group in currentGroups)
+        {
+            var defaultGroup = defaultGroups.FirstOrDefault(g => g.Name == group.Name);
+            if (defaultGroup == null)
+            {
+                continue;
+            }
+
+            // Update the group's selection state
+            group.IsSelected = defaultGroup.IsSelected;
+            
+            // Update each file type's selection state
+            var fileTypes = group.FileTypes.ToArray();
+            foreach (var fileType in fileTypes)
+            {
+                var defaultType = defaultGroup.FileTypes.FirstOrDefault(dt => 
+                    dt.Description == fileType.Description);
+                
+                if (defaultType != null)
+                {
+                    fileType.IsSelected = defaultType.IsSelected;
+                }
+            }
+        }
+    }
+
+    public void UnselectFileTypes()
+    {
+        // Get fresh default file types
+        var defaultGroups = FileTypeHelper.GetFileTypes();
+    
+        // Make a copy of the current groups to avoid enumeration issues
+        var currentGroups = _fileTypeGroups.ToArray();
+    
+        // Update selection states based on the defaults
+        foreach (var group in currentGroups)
+        {
+            var defaultGroup = defaultGroups.FirstOrDefault(g => g.Name == group.Name);
+            if (defaultGroup == null)
+            {
+                continue;
+            }
+            
+            group.IsSelected = false;
+            
+            // Update each file type's selection state
+            var fileTypes = group.FileTypes.ToArray();
+            foreach (var fileType in fileTypes)
+            {
+                var defaultType = defaultGroup.FileTypes.FirstOrDefault(dt => 
+                    dt.Description == fileType.Description);
+                
+                if (defaultType != null)
+                {
+                    fileType.IsSelected = false;
+                }
+            }
+        }
+    }
 }