Skip to content

Commit 81cfb1a

Browse files
authored
Optimization (#797)
1 parent 08dfec2 commit 81cfb1a

22 files changed

+373
-526
lines changed

Files/App.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
</ResourceDictionary.ThemeDictionaries>
4141
</ResourceDictionary>
4242
</ResourceDictionary.MergedDictionaries>
43-
<converters:NegateConverter x:Key="NegateConverter" />
4443
</ResourceDictionary>
4544
</Application.Resources>
4645
</Application>

Files/BaseLayout.cs

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Files.Filesystem;
1+
using Files.Filesystem;
22
using Files.Interacts;
33
using Files.View_Models;
44
using Files.Views.Pages;
@@ -48,66 +48,36 @@ internal set
4848
}
4949
}
5050

51-
private List<ListedItem> _SelectedItems;
51+
private List<ListedItem> _SelectedItems = new List<ListedItem>();
5252

5353
public List<ListedItem> SelectedItems
5454
{
5555
get
5656
{
57-
if (_SelectedItems == null)
58-
{
59-
return new List<ListedItem>();
60-
}
61-
else
62-
{
63-
return _SelectedItems;
64-
}
57+
return _SelectedItems;
6558
}
6659
internal set
6760
{
6861
if (value != _SelectedItems)
6962
{
7063
_SelectedItems = value;
71-
if (value == null)
64+
if (_SelectedItems.Count == 0)
7265
{
7366
IsItemSelected = false;
67+
SelectedItem = null;
7468
}
7569
else
7670
{
7771
IsItemSelected = true;
72+
SelectedItem = _SelectedItems.First();
7873
}
79-
SetSelectedItemsOnUi(value);
8074
NotifyPropertyChanged("SelectedItems");
75+
SetDragModeForItems();
8176
}
8277
}
8378
}
8479

85-
private ListedItem _SelectedItem;
86-
87-
public ListedItem SelectedItem
88-
{
89-
get
90-
{
91-
return _SelectedItem;
92-
}
93-
internal set
94-
{
95-
if (value != _SelectedItem)
96-
{
97-
_SelectedItem = value;
98-
if (value == null)
99-
{
100-
IsItemSelected = false;
101-
}
102-
else
103-
{
104-
IsItemSelected = true;
105-
}
106-
SetSelectedItemOnUi(value);
107-
NotifyPropertyChanged("SelectedItem");
108-
}
109-
}
110-
}
80+
public ListedItem SelectedItem { get; private set; }
11181

11282
public BaseLayout()
11383
{
@@ -124,12 +94,30 @@ public BaseLayout()
12494
}
12595
}
12696

127-
protected abstract void SetSelectedItemOnUi(ListedItem selectedItem);
97+
public abstract void SetSelectedItemOnUi(ListedItem item);
98+
99+
public abstract void SetSelectedItemsOnUi(List<ListedItem> items);
100+
101+
public abstract void SelectAllItems();
102+
103+
public abstract void InvertSelection();
104+
105+
public abstract void ClearSelection();
106+
107+
public abstract void SetDragModeForItems();
108+
109+
public abstract void ScrollIntoView(ListedItem item);
128110

129-
protected abstract void SetSelectedItemsOnUi(List<ListedItem> selectedItems);
111+
public abstract int GetSelectedIndex();
130112

131113
public abstract void FocusSelectedItems();
132114

115+
public abstract void StartRenameItem();
116+
117+
public abstract void ResetItemOpacity();
118+
119+
public abstract void SetItemOpacity(ListedItem item);
120+
133121
protected abstract ListedItem GetItemFromElement(object element);
134122

135123
private void AppSettings_LayoutModeChangeRequested(object sender, EventArgs e)
@@ -139,14 +127,8 @@ private void AppSettings_LayoutModeChangeRequested(object sender, EventArgs e)
139127
App.CurrentInstance.ViewModel.CancelLoadAndClearFiles();
140128
App.CurrentInstance.ViewModel.IsLoadingItems = true;
141129
App.CurrentInstance.ViewModel.IsLoadingItems = false;
142-
if (App.AppSettings.LayoutMode == 0)
143-
{
144-
App.CurrentInstance.ContentFrame.Navigate(typeof(GenericFileBrowser), App.CurrentInstance.ViewModel.WorkingDirectory, null);
145-
}
146-
else
147-
{
148-
App.CurrentInstance.ContentFrame.Navigate(typeof(GridViewBrowser), App.CurrentInstance.ViewModel.WorkingDirectory, null);
149-
}
130+
131+
App.CurrentInstance.ContentFrame.Navigate(App.AppSettings.GetLayoutType(), App.CurrentInstance.ViewModel.WorkingDirectory, null);
150132
}
151133
}
152134

@@ -212,7 +194,7 @@ private void UnloadMenuFlyoutItemByName(string nameToUnload)
212194

213195
public void RightClickContextMenu_Opening(object sender, object e)
214196
{
215-
var selectedFileSystemItems = (App.CurrentInstance.ContentPage as BaseLayout).SelectedItems;
197+
var selectedFileSystemItems = App.CurrentInstance.ContentPage.SelectedItems;
216198

217199
// Find selected items that are not folders
218200
if (selectedFileSystemItems.Cast<ListedItem>().Any(x => x.PrimaryItemAttribute != StorageItemTypes.Folder))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Windows.Storage;
7+
using Windows.UI.Xaml.Data;
8+
9+
namespace Files.Converters
10+
{
11+
class StorageDeleteOptionToBooleanConverter : IValueConverter
12+
{
13+
public object Convert(object value, Type targetType, object parameter, string language)
14+
{
15+
return value is StorageDeleteOption option && option == StorageDeleteOption.PermanentDelete;
16+
}
17+
18+
public object ConvertBack(object value, Type targetType, object parameter, string language)
19+
{
20+
return (value is bool bl && bl) ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default;
21+
}
22+
}
23+
}

Files/Dialogs/ConfirmDeleteDialog.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
xmlns:local1="using:Files"
77
xmlns:local2="using:Files.Helpers"
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:converters="using:Files.Converters"
910
x:Uid="ConfirmDeleteDialog"
1011
Title="Delete Item(s)"
1112
CornerRadius="4"
1213
mc:Ignorable="d"
1314
RequestedTheme="{x:Bind local2:ThemeHelper.RootTheme}">
15+
<ContentDialog.Resources>
16+
<converters:StorageDeleteOptionToBooleanConverter x:Key="StorageDeleteOptionToBooleanConverter" />
17+
</ContentDialog.Resources>
1418

1519
<Grid>
1620
<Grid.RowDefinitions>
@@ -27,7 +31,7 @@
2731
x:Name="chkPermanentlyDelete"
2832
x:Uid="ConfirmDeleteDialogPermanentlyDeleteCheckBox"
2933
Content="Permanently delete"
30-
IsChecked="{x:Bind local1:App.InteractionViewModel.PermanentlyDelete, Mode=TwoWay}" />
34+
IsChecked="{x:Bind local1:App.InteractionViewModel.PermanentlyDelete, Mode=TwoWay, Converter={StaticResource StorageDeleteOptionToBooleanConverter}}" />
3135
</StackPanel>
3236

3337
<StackPanel

Files/Files.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<Compile Include="CommandLine\ParsedCommand.cs" />
147147
<Compile Include="CommandLine\ParsedCommands.cs" />
148148
<Compile Include="CommandLine\ParsedCommandType.cs" />
149+
<Compile Include="Converters\StorageDeleteOptionToBooleanConverter.cs" />
149150
<Compile Include="Dialogs\ConfirmDeleteDialog.xaml.cs">
150151
<DependentUpon>ConfirmDeleteDialog.xaml</DependentUpon>
151152
</Compile>
@@ -154,7 +155,6 @@
154155
<Compile Include="Helpers\ItemsDataTemplateSelector.cs" />
155156
<Compile Include="Helpers\NaturalStringComparer.cs" />
156157
<Compile Include="Helpers\StringExtensions.cs" />
157-
<Compile Include="Helpers\NegateConverter.cs" />
158158
<Compile Include="Helpers\ThemeHelper.cs" />
159159
<Compile Include="Program.cs" />
160160
<Compile Include="ResourceController.cs" />

Files/Helpers/NegateConverter.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)