@@ -13,11 +13,13 @@ namespace Files.App.ViewModels.UserControls
13
13
public class InfoPaneViewModel : ObservableObject , IDisposable
14
14
{
15
15
private IInfoPaneSettingsService infoPaneSettingsService { get ; } = Ioc . Default . GetRequiredService < IInfoPaneSettingsService > ( ) ;
16
-
17
- private readonly IContentPageContext contentPageContextService ;
16
+ private IContentPageContext contentPageContext { get ; } = Ioc . Default . GetRequiredService < IContentPageContext > ( ) ;
18
17
19
18
private CancellationTokenSource loadCancellationTokenSource ;
20
19
20
+ /// <summary>
21
+ /// Value indicating if the info pane is on/off
22
+ /// </summary>
21
23
private bool isEnabled ;
22
24
public bool IsEnabled
23
25
{
@@ -30,13 +32,10 @@ public bool IsEnabled
30
32
}
31
33
}
32
34
33
- private bool isItemSelected ;
34
- public bool IsItemSelected
35
- {
36
- get => isItemSelected ;
37
- set => SetProperty ( ref isItemSelected , value ) ;
38
- }
39
-
35
+ /// <summary>
36
+ /// Current selected item in the file list.
37
+ /// TODO see about removing this and accessing it from the page context instead
38
+ /// </summary>
40
39
private ListedItem selectedItem ;
41
40
public ListedItem SelectedItem
42
41
{
@@ -57,6 +56,9 @@ public ListedItem SelectedItem
57
56
}
58
57
}
59
58
59
+ /// <summary>
60
+ /// Enum indicating whether to show the details or preview tab
61
+ /// </summary>
60
62
public InfoPaneTabs SelectedTab
61
63
{
62
64
get => infoPaneSettingsService . SelectedTab ;
@@ -69,6 +71,9 @@ public InfoPaneTabs SelectedTab
69
71
}
70
72
}
71
73
74
+ /// <summary>
75
+ /// Enum indicating if details/preview are available
76
+ /// </summary>
72
77
private PreviewPaneStates previewPaneState ;
73
78
public PreviewPaneStates PreviewPaneState
74
79
{
@@ -80,6 +85,9 @@ public PreviewPaneStates PreviewPaneState
80
85
}
81
86
}
82
87
88
+ /// <summary>
89
+ /// Value indicating if the download cloud files option should be displayed
90
+ /// </summary>
83
91
private bool showCloudItemButton ;
84
92
public bool ShowCloudItemButton
85
93
{
@@ -101,13 +109,31 @@ PreviewPaneState is PreviewPaneStates.NoPreviewAvailable ||
101
109
102
110
public ObservableCollection < TagsListItem > Items { get ; } = new ( ) ;
103
111
104
- public InfoPaneViewModel ( IContentPageContext contentPageContextService = null )
112
+ public InfoPaneViewModel ( )
105
113
{
106
114
infoPaneSettingsService . PropertyChanged += PreviewSettingsService_OnPropertyChangedEvent ;
115
+ contentPageContext . PropertyChanged += ContentPageContext_PropertyChanged ;
107
116
108
117
IsEnabled = infoPaneSettingsService . IsEnabled ;
118
+ }
109
119
110
- this . contentPageContextService = contentPageContextService ?? Ioc . Default . GetRequiredService < IContentPageContext > ( ) ;
120
+ private void ContentPageContext_PropertyChanged ( object ? sender , PropertyChangedEventArgs e )
121
+ {
122
+ switch ( e . PropertyName )
123
+ {
124
+ case nameof ( IContentPageContext . Folder ) :
125
+ case nameof ( IContentPageContext . SelectedItem ) :
126
+
127
+ if ( contentPageContext . SelectedItems . Count == 1 )
128
+ SelectedItem = contentPageContext . SelectedItems . First ( ) ;
129
+ else
130
+ SelectedItem = null ;
131
+
132
+ var shouldUpdatePreview = ( ( MainWindow . Instance . Content as Frame ) ? . Content as MainPage ) ? . ShouldPreviewPaneBeActive ;
133
+ if ( shouldUpdatePreview == true )
134
+ _ = UpdateSelectedItemPreviewAsync ( ) ;
135
+ break ;
136
+ }
111
137
}
112
138
113
139
private async Task LoadPreviewControlAsync ( CancellationToken token , bool downloadItem )
@@ -148,7 +174,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
148
174
{
149
175
ShowCloudItemButton = false ;
150
176
151
- if ( SelectedItem . IsRecycleBinItem )
177
+ if ( item . IsRecycleBinItem )
152
178
{
153
179
if ( item . PrimaryItemAttribute == StorageItemTypes . Folder && ! item . IsArchive )
154
180
{
@@ -159,7 +185,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
159
185
}
160
186
else
161
187
{
162
- var model = new BasicPreviewViewModel ( SelectedItem ) ;
188
+ var model = new BasicPreviewViewModel ( item ) ;
163
189
await model . LoadAsync ( ) ;
164
190
165
191
return new BasicPreview ( model ) ;
@@ -168,7 +194,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
168
194
169
195
if ( item . IsShortcut )
170
196
{
171
- var model = new ShortcutPreviewViewModel ( SelectedItem ) ;
197
+ var model = new ShortcutPreviewViewModel ( item ) ;
172
198
await model . LoadAsync ( ) ;
173
199
174
200
return new BasicPreview ( model ) ;
@@ -187,7 +213,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
187
213
var model = new FolderPreviewViewModel ( item ) ;
188
214
await model . LoadAsync ( ) ;
189
215
190
- if ( ! isItemSelected )
216
+ if ( contentPageContext . SelectedItems . Count == 0 )
191
217
item . FileTags ??= FileTagsHelper . ReadFileTag ( item . ItemPath ) ;
192
218
193
219
return new FolderPreview ( model ) ;
@@ -206,7 +232,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
206
232
var ext = item . FileExtension . ToLowerInvariant ( ) ;
207
233
208
234
if ( ! item . IsFtpItem &&
209
- contentPageContextService . PageType != ContentPageTypes . ZipFolder &&
235
+ contentPageContext . PageType != ContentPageTypes . ZipFolder &&
210
236
( FileExtensionHelpers . IsAudioFile ( ext ) || FileExtensionHelpers . IsVideoFile ( ext ) ) )
211
237
{
212
238
var model = new MediaPreviewViewModel ( item ) ;
@@ -291,7 +317,7 @@ private async Task<UserControl> GetBuiltInPreviewControlAsync(ListedItem item, b
291
317
public async Task UpdateSelectedItemPreviewAsync ( bool downloadItem = false )
292
318
{
293
319
loadCancellationTokenSource ? . Cancel ( ) ;
294
- if ( SelectedItem is not null && IsItemSelected )
320
+ if ( SelectedItem is not null && contentPageContext . SelectedItems . Count == 1 )
295
321
{
296
322
SelectedItem ? . FileDetails ? . Clear ( ) ;
297
323
@@ -328,15 +354,15 @@ public async Task UpdateSelectedItemPreviewAsync(bool downloadItem = false)
328
354
PreviewPaneState = PreviewPaneStates . NoPreviewOrDetailsAvailable ;
329
355
}
330
356
}
331
- else if ( IsItemSelected )
357
+ else if ( contentPageContext . SelectedItems . Count > 0 )
332
358
{
333
359
PreviewPaneContent = null ;
334
360
PreviewPaneState = PreviewPaneStates . NoPreviewOrDetailsAvailable ;
335
361
}
336
362
else
337
363
{
338
364
SelectedItem ? . FileDetails ? . Clear ( ) ;
339
- var currentFolder = contentPageContextService . Folder ;
365
+ var currentFolder = contentPageContext . Folder ;
340
366
341
367
if ( currentFolder is null )
342
368
{
@@ -388,6 +414,7 @@ private async void PreviewSettingsService_OnPropertyChangedEvent(object? sender,
388
414
if ( isEnabled != newEnablingStatus )
389
415
{
390
416
isEnabled = newEnablingStatus ;
417
+ _ = UpdateSelectedItemPreviewAsync ( ) ;
391
418
OnPropertyChanged ( nameof ( IsEnabled ) ) ;
392
419
}
393
420
}
0 commit comments