Skip to content

Commit 5b0ec78

Browse files
author
Carl Chang
committed
move viewwindow last state to global
1 parent f7c2402 commit 5b0ec78

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

Helpers/Setting.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public static DataTable MappedPasswords {
214214
}
215215

216216
private static bool immersionMode;
217-
//this one is not saved
217+
//not saved
218218
public static bool ImmersionMode {
219219
get => immersionMode;
220220
set {
@@ -224,6 +224,9 @@ public static bool ImmersionMode {
224224
}
225225
}
226226

227+
//not saved
228+
public static Rect LastViewWindowRect;
229+
227230
private static SlideAnimConfig slideAnimConfig = new SlideAnimConfig();
228231
[AppConfig]
229232
public static SlideAnimConfig SlideAnimConfig {

MainWindow.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public string CurrentPath {
4949

5050
private VirtualizingWrapPanel virWrapPanel;
5151
private Rect lastWindowRect;
52-
internal Rect lastViewWindowRect;
5352

5453
public MainWindow()
5554
{
@@ -261,7 +260,7 @@ internal void LoadPath(ObjectInfo objInfo, ViewWindow viewWin = null) {
261260
//using a new ObjectInfo to avoid confusion and reduce chance of holding ImageSource
262261
Dispatcher.Invoke(() => {
263262
if (viewWin == null)
264-
new ViewWindow(objInfo.ContainerPath, objInfo.FileName, this).Show();
263+
new ViewWindow(objInfo.ContainerPath, objInfo.FileName).Show();
265264
else
266265
viewWin.ViewPath = (objInfo.ContainerPath, objInfo.FileName);
267266
});

ViewWindow.xaml.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace ZipImageViewer
1616
public partial class ViewWindow : BorderlessWindow, INotifyPropertyChanged
1717
{
1818
public event PropertyChangedEventHandler PropertyChanged;
19-
private readonly MainWindow mainWin;
20-
2119

2220
private (string BasePath, string SubPath) viewPath;
2321
/// <summary>
@@ -118,32 +116,29 @@ public ObservablePair<DependencyProps, DependencyProps> TransParams {
118116
private Setting.Transition LastTransition = Setting.Transition.None;
119117

120118

121-
public ViewWindow(string basePath, string subPath, MainWindow win = null)
119+
public ViewWindow(string basePath, string subPath)
122120
{
123121
InitializeComponent();
124122
Opacity = 0d;
125-
mainWin = win;
126123

127124
ViewPath = (basePath, subPath);
128125
}
129126

130127
private void ViewWindow_Loaded(object sender, RoutedEventArgs e) {
131128
//restore last state
132-
if (mainWin != null) {
133-
if (mainWin.lastViewWindowRect != default) {
134-
Top = mainWin.lastViewWindowRect.Top;
135-
Left = mainWin.lastViewWindowRect.Left;
136-
if (mainWin.lastViewWindowRect.Size != default) {
137-
Width = mainWin.lastViewWindowRect.Width;
138-
Height = mainWin.lastViewWindowRect.Height;
139-
}
140-
else {
141-
WindowState = WindowState.Maximized;
142-
}
129+
if (Setting.LastViewWindowRect != default) {
130+
Top = Setting.LastViewWindowRect.Top;
131+
Left = Setting.LastViewWindowRect.Left;
132+
if (Setting.LastViewWindowRect.Size != default) {
133+
Width = Setting.LastViewWindowRect.Width;
134+
Height = Setting.LastViewWindowRect.Height;
135+
}
136+
else {
137+
WindowState = WindowState.Maximized;
143138
}
144-
if (Setting.ImmersionMode)
145-
SwitchFullScreen(this, ref mainWin.lastViewWindowRect, true);
146139
}
140+
if (Setting.ImmersionMode)
141+
SwitchFullScreen(this, ref Setting.LastViewWindowRect, true);
147142

148143
//fade in window content
149144
this.AnimateDoubleCubicEase(OpacityProperty, 1d, 100, EasingMode.EaseOut);
@@ -155,12 +150,10 @@ private void ViewWin_Closed(object sender, EventArgs e) {
155150

156151
private void ViewWin_Closing(object sender, CancelEventArgs e) {
157152
//save window state
158-
if (mainWin != null) {
159-
if (WindowState == WindowState.Maximized || IsFullScreen(this))
160-
mainWin.lastViewWindowRect = new Rect(Left, Top, 0d, 0d);
161-
else
162-
mainWin.lastViewWindowRect = new Rect(Left, Top, ActualWidth, ActualHeight);
163-
}
153+
if (WindowState == WindowState.Maximized || IsFullScreen(this))
154+
Setting.LastViewWindowRect = new Rect(Left, Top, 0d, 0d);
155+
else
156+
Setting.LastViewWindowRect = new Rect(Left, Top, ActualWidth, ActualHeight);
164157

165158
IM.Source = null;
166159
IM = null;

0 commit comments

Comments
 (0)