@@ -64,13 +64,19 @@ public static async Task Navigate(bool next, MainViewModel vm)
64
64
var navigateTo = next ? NavigateTo . Next : NavigateTo . Previous ;
65
65
var nextIteration = vm . ImageIterator . GetIteration ( vm . ImageIterator . CurrentIndex , navigateTo ) ;
66
66
var currentFileName = vm . ImageIterator . ImagePaths [ vm . ImageIterator . CurrentIndex ] ;
67
- if ( ! TiffManager . IsTiff ( currentFileName ) || vm . ImageIterator . IsReversed )
67
+ if ( ! TiffManager . IsTiff ( currentFileName ) )
68
68
{
69
69
await CheckCancellationAndStartIterateToIndex ( nextIteration , vm ) . ConfigureAwait ( false ) ;
70
- return ;
71
70
}
71
+ else
72
+ {
73
+ await TiffNavigation ( vm , currentFileName , nextIteration ) . ConfigureAwait ( false ) ;
74
+ }
75
+ }
72
76
73
- if ( TiffNavigationInfo is null )
77
+ private static async Task TiffNavigation ( MainViewModel vm , string currentFileName , int nextIteration )
78
+ {
79
+ if ( TiffNavigationInfo is null && ! vm . ImageIterator . IsReversed )
74
80
{
75
81
var tiffPages = await Task . FromResult ( TiffManager . LoadTiffPages ( currentFileName ) ) . ConfigureAwait ( false ) ;
76
82
if ( tiffPages . Count < 1 )
@@ -80,25 +86,45 @@ public static async Task Navigate(bool next, MainViewModel vm)
80
86
}
81
87
TiffNavigationInfo = new TiffManager . TiffNavigationInfo
82
88
{
83
- CurrentPage = 1 , // Skip first page since it has already been shown
89
+ CurrentPage = 0 ,
84
90
PageCount = tiffPages . Count ,
85
91
Pages = tiffPages
86
92
} ;
87
93
}
88
- else
89
- {
90
- TiffNavigationInfo . CurrentPage += 1 ;
91
- }
92
-
93
- if ( TiffNavigationInfo . CurrentPage >= TiffNavigationInfo . PageCount )
94
+
95
+ if ( TiffNavigationInfo is null )
94
96
{
95
- TiffNavigationInfo . Dispose ( ) ;
96
- TiffNavigationInfo = null ;
97
97
await CheckCancellationAndStartIterateToIndex ( nextIteration , vm ) . ConfigureAwait ( false ) ;
98
98
}
99
99
else
100
100
{
101
- UpdateImage . SetTiffImage ( TiffNavigationInfo , Path . GetFileName ( currentFileName ) , vm ) ;
101
+ if ( vm . ImageIterator . IsReversed )
102
+ {
103
+ if ( TiffNavigationInfo . CurrentPage - 1 <= 0 )
104
+ {
105
+ await CheckCancellationAndStartIterateToIndex ( vm . ImageIterator . CurrentIndex , vm ) . ConfigureAwait ( false ) ;
106
+ TiffNavigationInfo . Dispose ( ) ;
107
+ TiffNavigationInfo = null ;
108
+ return ;
109
+ }
110
+
111
+ TiffNavigationInfo . CurrentPage -= 1 ;
112
+ }
113
+ else
114
+ {
115
+ TiffNavigationInfo . CurrentPage += 1 ;
116
+ }
117
+
118
+ if ( TiffNavigationInfo . CurrentPage >= TiffNavigationInfo . PageCount || TiffNavigationInfo . CurrentPage <= 0 )
119
+ {
120
+ await CheckCancellationAndStartIterateToIndex ( nextIteration , vm ) . ConfigureAwait ( false ) ;
121
+ TiffNavigationInfo . Dispose ( ) ;
122
+ TiffNavigationInfo = null ;
123
+ }
124
+ else
125
+ {
126
+ UpdateImage . SetTiffImage ( TiffNavigationInfo , Path . GetFileName ( currentFileName ) , vm ) ;
127
+ }
102
128
}
103
129
}
104
130
0 commit comments