Skip to content

Commit aeb45d5

Browse files
authored
Fixed issue where preview pane would open itself after switching tabs or closing settings (#3284)
1 parent 3b3dfd9 commit aeb45d5

File tree

5 files changed

+88
-78
lines changed

5 files changed

+88
-78
lines changed

Files/UserControls/PreviewPane.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ public ListedItem SelectedItem
7878
public bool IsHorizontal
7979
{
8080
get => (bool)GetValue(IsHorizontalProperty);
81-
set => SetValue(IsHorizontalProperty, value);
81+
set
82+
{
83+
SetValue(IsHorizontalProperty, value);
84+
EdgeTransitionLocation = value ? EdgeTransitionLocation.Bottom : EdgeTransitionLocation.Right;
85+
}
8286
}
8387

8488
public static DependencyProperty EdgeTransitionLocationProperty =

Files/ViewModels/CurrentInstanceViewModel.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,5 @@ public bool IsPageTypeCloudDrive
114114
get => isPageTypeCloudDrive;
115115
set => SetProperty(ref isPageTypeCloudDrive, value);
116116
}
117-
118-
private bool previewPaneEnabled;
119-
120-
/// <summary>
121-
/// Gets or sets the value indicating whether the preview pane should be shown.
122-
/// </summary>
123-
public bool PreviewPaneEnabled
124-
{
125-
get => previewPaneEnabled;
126-
set => SetProperty(ref previewPaneEnabled, value);
127-
}
128117
}
129118
}

Files/ViewModels/Previews/HtmlPreviewViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public async override void LoadPreviewAndDetails()
3737
Debug.WriteLine(e);
3838
}
3939
base.LoadSystemFileProperties();
40+
RaiseLoadedEvent();
4041
}
4142
}
4243
}

Files/Views/ModernShellPage.xaml

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
NewWindowInvokedCommand="{x:Bind InteractionOperations.OpenNewWindow, Mode=OneWay}"
261261
OpenInTerminalInvokedCommand="{x:Bind InteractionOperations.OpenDirectoryInDefaultTerminal, Mode=OneWay}"
262262
PasteInvokedCommand="{x:Bind InteractionOperations.PasteItemsFromClipboard, Mode=OneWay}"
263-
PreviewPaneEnabled="{x:Bind InstanceViewModel.PreviewPaneEnabled, Mode=TwoWay}"
263+
PreviewPaneEnabled="{x:Bind PreviewPaneEnabled, Mode=TwoWay}"
264264
ShowMultiPaneControls="{x:Bind converters1:MultiBooleanConverter.AndConvert(IsMultiPaneEnabled, IsPageMainPane), Mode=OneWay}" />
265265

266266
<Frame
@@ -274,7 +274,7 @@
274274
x:Name="PreviewPaneGridSplitter"
275275
Grid.Row="1"
276276
Grid.Column="1"
277-
x:Load="{x:Bind InstanceViewModel.PreviewPaneEnabled, Mode=OneWay}"
277+
x:Load="{x:Bind PreviewPaneEnabled, Mode=OneWay}"
278278
Background="Transparent"
279279
ResizeBehavior="BasedOnAlignment">
280280
<Custom:GridSplitter.Element>
@@ -295,7 +295,7 @@
295295
x:Name="PreviewPane"
296296
Grid.Row="1"
297297
Grid.Column="2"
298-
x:Load="{x:Bind InstanceViewModel.PreviewPaneEnabled, Mode=OneWay}"
298+
x:Load="{x:Bind PreviewPaneEnabled, Mode=OneWay}"
299299
SelectedItems="{x:Bind ContentPage.SelectedItems, Mode=OneWay}" />
300300

301301
<controls:StatusBarControl
@@ -334,62 +334,5 @@
334334
<TranslateTransform X="0" />
335335
</Custom:GridSplitter.RenderTransform>
336336
</Custom:GridSplitter>
337-
<VisualStateManager.VisualStateGroups>
338-
<VisualStateGroup>
339-
<VisualState>
340-
<VisualState.StateTriggers>
341-
<triggers:IsEqualStateTrigger Value="{x:Bind InstanceViewModel.PreviewPaneEnabled, Mode=OneWay}" To="False" />
342-
<triggers:IsEqualStateTrigger Value="{x:Bind InstanceViewModel.IsPageTypeNotHome, Mode=OneWay}" To="False" />
343-
</VisualState.StateTriggers>
344-
<VisualState.Setters>
345-
<Setter Target="PreviewPaneRow.Height" Value="0" />
346-
<Setter Target="PreviewPaneColumn.Width" Value="0" />
347-
<Setter Target="PreviewPaneGridSplitter.Visibility" Value="Collapsed" />
348-
</VisualState.Setters>
349-
</VisualState>
350-
<VisualState>
351-
<VisualState.StateTriggers>
352-
<triggers:IsEqualStateTrigger Value="{x:Bind AppSettings.EnableAdaptivePreviewPane, Mode=OneWay}" To="False" />
353-
<triggers:CompareStateTrigger
354-
Comparison="GreaterThan"
355-
Value="{x:Bind RootGridWidth, Mode=OneWay}"
356-
To="1000" />
357-
</VisualState.StateTriggers>
358-
359-
<VisualState.Setters>
360-
<Setter Target="PreviewPane.(Grid.Row)" Value="2" />
361-
<Setter Target="PreviewPane.(Grid.Column)" Value="2" />
362-
363-
<Setter Target="PreviewPaneGridSplitter.(Grid.Row)" Value="2" />
364-
<Setter Target="PreviewPaneGridSplitter.(Grid.Column)" Value="1" />
365-
<Setter Target="PreviewPaneGridSplitter.Width" Value="2" />
366-
367-
<Setter Target="PreviewPaneRow.Height" Value="4" />
368-
<Setter Target="PreviewPane.IsHorizontal" Value="False" />
369-
</VisualState.Setters>
370-
</VisualState>
371-
<VisualState>
372-
<VisualState.StateTriggers>
373-
<triggers:CompareStateTrigger
374-
Comparison="LessThanOrEqual"
375-
Value="{x:Bind RootGridWidth, Mode=OneWay}"
376-
To="1000" />
377-
<!--<AdaptiveTrigger MinWindowWidth="0" />-->
378-
</VisualState.StateTriggers>
379-
380-
<VisualState.Setters>
381-
<Setter Target="PreviewPane.(Grid.Row)" Value="4" />
382-
<Setter Target="PreviewPane.(Grid.Column)" Value="0" />
383-
384-
<Setter Target="PreviewPaneGridSplitter.(Grid.Row)" Value="3" />
385-
<Setter Target="PreviewPaneGridSplitter.(Grid.Column)" Value="0" />
386-
<Setter Target="PreviewPaneGridSplitter.Height" Value="2" />
387-
388-
<Setter Target="PreviewPaneColumn.Width" Value="0" />
389-
<Setter Target="PreviewPane.IsHorizontal" Value="True" />
390-
</VisualState.Setters>
391-
</VisualState>
392-
</VisualStateGroup>
393-
</VisualStateManager.VisualStateGroups>
394337
</Grid>
395338
</Page>

Files/Views/ModernShellPage.xaml.cs

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,14 @@ private async void ItemDisplayFrame_Navigated(object sender, NavigationEventArgs
976976
InitialPageType = typeof(ModernShellPage),
977977
NavigationArg = parameters.IsSearchResultPage ? parameters.SearchPathParam : parameters.NavPathParam
978978
};
979+
980+
if(ItemDisplayFrame.CurrentSourcePageType == typeof(YourHome))
981+
{
982+
UpdatePositioning(true);
983+
} else
984+
{
985+
UpdatePositioning();
986+
}
979987
}
980988

981989
private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
@@ -1084,7 +1092,7 @@ await FilesystemHelpers.DeleteItemsAsync(
10841092
break;
10851093

10861094
case (true, false, false, true, VirtualKey.P):
1087-
InstanceViewModel.PreviewPaneEnabled = !InstanceViewModel.PreviewPaneEnabled;
1095+
PreviewPaneEnabled = !PreviewPaneEnabled;
10881096
break;
10891097

10901098
case (true, false, false, true, VirtualKey.R): // ctrl + r, refresh
@@ -1295,16 +1303,81 @@ await InteractionOperations.FilesystemHelpers.PerformOperationTypeAsync(
12951303
return DataPackageOperation.None;
12961304
}
12971305

1298-
// Binding directly to the actual width raise property changed notifications
1299-
// This is a workaroumd
1300-
public double RootGridWidth
1306+
private bool previewPaneEnabled;
1307+
1308+
/// <summary>
1309+
/// Gets or sets the value indicating whether the preview pane should be shown.
1310+
/// </summary>
1311+
public bool PreviewPaneEnabled
13011312
{
1302-
get => RootGrid.ActualWidth;
1313+
get => previewPaneEnabled;
1314+
set
1315+
{
1316+
previewPaneEnabled = value;
1317+
NotifyPropertyChanged(nameof(PreviewPaneEnabled));
1318+
UpdatePositioning();
1319+
}
13031320
}
13041321

13051322
private void RootGrid_SizeChanged(object sender, SizeChangedEventArgs e)
13061323
{
1307-
NotifyPropertyChanged(nameof(RootGridWidth));
1324+
UpdatePositioning(!InstanceViewModel.IsPageTypeNotHome);
1325+
}
1326+
1327+
/// <summary>
1328+
/// Call this function to update the positioning of the preview pane.
1329+
/// This is a workaround as the VisualStateManager causes problems.
1330+
/// </summary>
1331+
private void UpdatePositioning(bool IsHome = false)
1332+
{
1333+
if (!PreviewPaneEnabled || IsHome)
1334+
{
1335+
PreviewPaneRow.Height = new GridLength(0);
1336+
PreviewPaneColumn.Width = new GridLength(0);
1337+
if(PreviewPaneGridSplitter != null)
1338+
{
1339+
PreviewPaneGridSplitter.Visibility = Visibility.Collapsed;
1340+
}
1341+
1342+
if (PreviewPane != null)
1343+
{
1344+
PreviewPane.Visibility = Visibility.Collapsed;
1345+
}
1346+
}
1347+
else if (RootGrid.ActualWidth > 1000 || !AppSettings.EnableAdaptivePreviewPane)
1348+
{
1349+
PreviewPane.SetValue(Grid.RowProperty, 2);
1350+
PreviewPane.SetValue(Grid.ColumnProperty, 2);
1351+
1352+
PreviewPaneGridSplitter.SetValue(Grid.RowProperty, 2);
1353+
PreviewPaneGridSplitter.SetValue(Grid.ColumnProperty, 1);
1354+
PreviewPaneGridSplitter.Width = 2;
1355+
PreviewPaneGridSplitter.Height = RootGrid.ActualHeight;
1356+
1357+
PreviewPaneRow.Height = new GridLength(0);
1358+
PreviewPaneColumn.Width = new GridLength(300);
1359+
PreviewPane.IsHorizontal = false;
1360+
1361+
PreviewPane.Visibility = Visibility.Visible;
1362+
PreviewPaneGridSplitter.Visibility = Visibility.Visible;
1363+
}
1364+
else if (RootGrid.ActualWidth < 1000)
1365+
{
1366+
PreviewPaneRow.Height = new GridLength(200);
1367+
PreviewPaneColumn.Width = new GridLength(0);
1368+
1369+
PreviewPane.SetValue(Grid.RowProperty, 4);
1370+
PreviewPane.SetValue(Grid.ColumnProperty, 0);
1371+
1372+
PreviewPaneGridSplitter.SetValue(Grid.RowProperty, 3);
1373+
PreviewPaneGridSplitter.SetValue(Grid.ColumnProperty, 0);
1374+
PreviewPaneGridSplitter.Height = 2;
1375+
PreviewPaneGridSplitter.Width = RootGrid.Width;
1376+
PreviewPane.IsHorizontal = true;
1377+
1378+
PreviewPane.Visibility = Visibility.Visible;
1379+
PreviewPaneGridSplitter.Visibility = Visibility.Visible;
1380+
}
13081381
}
13091382
}
13101383

0 commit comments

Comments
 (0)