MainViewModel.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888
  1. using System.Reactive;
  2. using System.Reactive.Linq;
  3. using Avalonia;
  4. using Avalonia.Controls;
  5. using Avalonia.Controls.Primitives;
  6. using Avalonia.Layout;
  7. using Avalonia.Media;
  8. using PicView.Avalonia.Clipboard;
  9. using PicView.Avalonia.Converters;
  10. using PicView.Avalonia.Gallery;
  11. using PicView.Avalonia.Interfaces;
  12. using PicView.Avalonia.Navigation;
  13. using PicView.Avalonia.UI;
  14. using PicView.Core.Calculations;
  15. using PicView.Core.Config;
  16. using PicView.Core.FileHandling;
  17. using PicView.Core.Gallery;
  18. using PicView.Core.ProcessHandling;
  19. using ReactiveUI;
  20. using ImageViewer = PicView.Avalonia.Views.ImageViewer;
  21. namespace PicView.Avalonia.ViewModels;
  22. public class MainViewModel : ViewModelBase
  23. {
  24. public readonly IPlatformSpecificService? PlatformService;
  25. #region Image
  26. private object? _imageSource;
  27. public object? ImageSource
  28. {
  29. get => _imageSource;
  30. set => this.RaiseAndSetIfChanged(ref _imageSource, value);
  31. }
  32. private object? _secondaryImageSource;
  33. public object? SecondaryImageSource
  34. {
  35. get => _secondaryImageSource;
  36. set => this.RaiseAndSetIfChanged(ref _secondaryImageSource, value);
  37. }
  38. private ImageType _imageType;
  39. public ImageType ImageType
  40. {
  41. get => _imageType;
  42. set => this.RaiseAndSetIfChanged(ref _imageType, value);
  43. }
  44. private double _imageWidth;
  45. public double ImageWidth
  46. {
  47. get => _imageWidth;
  48. set => this.RaiseAndSetIfChanged(ref _imageWidth, value);
  49. }
  50. private double _imageHeight;
  51. public double ImageHeight
  52. {
  53. get => _imageHeight;
  54. set => this.RaiseAndSetIfChanged(ref _imageHeight, value);
  55. }
  56. private double _imageSecondaryWidth;
  57. public double SecondaryImageWidth
  58. {
  59. get => _imageSecondaryWidth;
  60. set => this.RaiseAndSetIfChanged(ref _imageSecondaryWidth, value);
  61. }
  62. private Brush? _imageBackground;
  63. public Brush? ImageBackground
  64. {
  65. get => _imageBackground;
  66. set => this.RaiseAndSetIfChanged(ref _imageBackground, value);
  67. }
  68. private bool _isShowingSideBySide = SettingsHelper.Settings.ImageScaling.ShowImageSideBySide;
  69. public bool IsShowingSideBySide
  70. {
  71. get => _isShowingSideBySide;
  72. set => this.RaiseAndSetIfChanged(ref _isShowingSideBySide, value);
  73. }
  74. private double _scrollViewerWidth = double.NaN;
  75. public double ScrollViewerWidth
  76. {
  77. get => _scrollViewerWidth;
  78. set => this.RaiseAndSetIfChanged(ref _scrollViewerWidth, value);
  79. }
  80. private double _scrollViewerHeight = double.NaN;
  81. public double ScrollViewerHeight
  82. {
  83. get => _scrollViewerHeight;
  84. set => this.RaiseAndSetIfChanged(ref _scrollViewerHeight, value);
  85. }
  86. #endregion
  87. #region Gallery
  88. private Thickness _galleryMargin;
  89. public Thickness GalleryMargin
  90. {
  91. get => _galleryMargin;
  92. set => this.RaiseAndSetIfChanged(ref _galleryMargin, value);
  93. }
  94. private bool _isGalleryShown = SettingsHelper.Settings.UIProperties.ShowInterface && SettingsHelper.Settings.Gallery.IsBottomGalleryShown;
  95. public bool IsGalleryShown
  96. {
  97. get => _isGalleryShown;
  98. set => this.RaiseAndSetIfChanged(ref _isGalleryShown, value);
  99. }
  100. private bool _isBottomGalleryShownInHiddenUi = SettingsHelper.Settings.Gallery.ShowBottomGalleryInHiddenUI;
  101. public bool IsBottomGalleryShownInHiddenUI
  102. {
  103. get => _isBottomGalleryShownInHiddenUi;
  104. set => this.RaiseAndSetIfChanged(ref _isBottomGalleryShownInHiddenUi, value);
  105. }
  106. private GalleryMode _galleryMode = GalleryMode.Closed;
  107. public GalleryMode GalleryMode
  108. {
  109. get => _galleryMode;
  110. set => this.RaiseAndSetIfChanged(ref _galleryMode, value);
  111. }
  112. private Stretch _galleryStretch;
  113. public Stretch GalleryStretch
  114. {
  115. get => _galleryStretch;
  116. set => this.RaiseAndSetIfChanged(ref _galleryStretch, value);
  117. }
  118. private int _selectedGalleryItemIndex;
  119. public int SelectedGalleryItemIndex
  120. {
  121. get => _selectedGalleryItemIndex;
  122. set => this.RaiseAndSetIfChanged(ref _selectedGalleryItemIndex, value);
  123. }
  124. private VerticalAlignment _galleryVerticalAlignment = VerticalAlignment.Bottom;
  125. public VerticalAlignment GalleryVerticalAlignment
  126. {
  127. get => _galleryVerticalAlignment;
  128. set => this.RaiseAndSetIfChanged(ref _galleryVerticalAlignment, value);
  129. }
  130. private Orientation _galleryOrientation;
  131. public Orientation GalleryOrientation
  132. {
  133. set => this.RaiseAndSetIfChanged(ref _galleryOrientation, value);
  134. get => _galleryOrientation;
  135. }
  136. private bool _isGalleryCloseIconVisible;
  137. public bool IsGalleryCloseIconVisible
  138. {
  139. get => _isGalleryCloseIconVisible;
  140. set => this.RaiseAndSetIfChanged(ref _isGalleryCloseIconVisible, value);
  141. }
  142. private double _galleryWidth;
  143. public double GalleryWidth
  144. {
  145. get => _galleryWidth;
  146. set => this.RaiseAndSetIfChanged(ref _galleryWidth, value);
  147. }
  148. public double GalleryHeight
  149. {
  150. get
  151. {
  152. if (!SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
  153. {
  154. return 0;
  155. }
  156. if (SettingsHelper.Settings.WindowProperties.Fullscreen)
  157. {
  158. return SettingsHelper.Settings.Gallery.IsBottomGalleryShown ? GetBottomGalleryItemHeight + SizeDefaults.ScrollbarSize : 0;
  159. }
  160. if (!SettingsHelper.Settings.Gallery.ShowBottomGalleryInHiddenUI && !IsInterfaceShown)
  161. {
  162. return 0;
  163. }
  164. return GetBottomGalleryItemHeight + SizeDefaults.ScrollbarSize;
  165. }
  166. }
  167. private double _getGalleryItemWidth = double.NaN;
  168. public double GetGalleryItemWidth
  169. {
  170. get => _getGalleryItemWidth;
  171. set => this.RaiseAndSetIfChanged(ref _getGalleryItemWidth, value);
  172. }
  173. private double _getGalleryItemHeight;
  174. public double GetGalleryItemHeight
  175. {
  176. get
  177. {
  178. return GalleryFunctions.IsFullGalleryOpen ? GetFullGalleryItemHeight : GetBottomGalleryItemHeight;
  179. }
  180. set
  181. {
  182. this.RaiseAndSetIfChanged(ref _getGalleryItemHeight, value);
  183. if (GalleryFunctions.IsBottomGalleryOpen && !GalleryFunctions.IsFullGalleryOpen)
  184. {
  185. GetBottomGalleryItemHeight = value;
  186. }
  187. else
  188. {
  189. GetFullGalleryItemHeight = value;
  190. }
  191. }
  192. }
  193. private double _getFullGalleryItemHeight = SettingsHelper.Settings.Gallery.ExpandedGalleryItemSize;
  194. public double GetFullGalleryItemHeight
  195. {
  196. get => _getFullGalleryItemHeight;
  197. set => this.RaiseAndSetIfChanged(ref _getFullGalleryItemHeight, value);
  198. }
  199. private double _getBottomGalleryItemHeight = SettingsHelper.Settings.Gallery.BottomGalleryItemSize;
  200. public double GetBottomGalleryItemHeight
  201. {
  202. get => _getBottomGalleryItemHeight;
  203. set => this.RaiseAndSetIfChanged(ref _getBottomGalleryItemHeight, value);
  204. }
  205. public double MaxFullGalleryItemHeight
  206. {
  207. get => GalleryDefaults.MaxFullGalleryItemHeight;
  208. }
  209. public double MinFullGalleryItemHeight
  210. {
  211. get => GalleryDefaults.MinFullGalleryItemHeight;
  212. }
  213. public double MaxBottomGalleryItemHeight
  214. {
  215. get => GalleryDefaults.MaxBottomGalleryItemHeight;
  216. }
  217. public double MinBottomGalleryItemHeight
  218. {
  219. get => GalleryDefaults.MinBottomGalleryItemHeight;
  220. }
  221. private Thickness _galleryItemMargin;
  222. public Thickness GalleryItemMargin
  223. {
  224. get => _galleryItemMargin;
  225. set => this.RaiseAndSetIfChanged(ref _galleryItemMargin, value);
  226. }
  227. #region Gallery Stretch IsChecked
  228. private bool _isUniformBottomChecked;
  229. public bool IsUniformBottomChecked
  230. {
  231. get => _isUniformBottomChecked;
  232. set => this.RaiseAndSetIfChanged(ref _isUniformBottomChecked, value);
  233. }
  234. private bool _isUniformFullChecked;
  235. public bool IsUniformFullChecked
  236. {
  237. get => _isUniformFullChecked;
  238. set => this.RaiseAndSetIfChanged(ref _isUniformFullChecked, value);
  239. }
  240. private bool _isUniformMenuChecked;
  241. public bool IsUniformMenuChecked
  242. {
  243. get => _isUniformMenuChecked;
  244. set => this.RaiseAndSetIfChanged(ref _isUniformMenuChecked, value);
  245. }
  246. private bool _isUniformToFillBottomChecked;
  247. public bool IsUniformToFillBottomChecked
  248. {
  249. get => _isUniformToFillBottomChecked;
  250. set => this.RaiseAndSetIfChanged(ref _isUniformToFillBottomChecked, value);
  251. }
  252. private bool _isUniformToFillFullChecked;
  253. public bool IsUniformToFillFullChecked
  254. {
  255. get => _isUniformToFillFullChecked;
  256. set => this.RaiseAndSetIfChanged(ref _isUniformToFillFullChecked, value);
  257. }
  258. private bool _isUniformToFillMenuMenuChecked;
  259. public bool IsUniformToFillMenuChecked
  260. {
  261. get => _isUniformToFillMenuMenuChecked;
  262. set => this.RaiseAndSetIfChanged(ref _isUniformToFillMenuMenuChecked, value);
  263. }
  264. private bool _isFillBottomChecked;
  265. public bool IsFillBottomChecked
  266. {
  267. get => _isFillBottomChecked;
  268. set => this.RaiseAndSetIfChanged(ref _isFillBottomChecked, value);
  269. }
  270. private bool _isFillFullChecked;
  271. public bool IsFillFullChecked
  272. {
  273. get => _isFillFullChecked;
  274. set => this.RaiseAndSetIfChanged(ref _isFillFullChecked, value);
  275. }
  276. private bool _isFillMenuMenuChecked;
  277. public bool IsFillMenuChecked
  278. {
  279. get => _isFillMenuMenuChecked;
  280. set => this.RaiseAndSetIfChanged(ref _isFillMenuMenuChecked, value);
  281. }
  282. private bool _isNoneBottomChecked;
  283. public bool IsNoneBottomChecked
  284. {
  285. get => _isNoneBottomChecked;
  286. set => this.RaiseAndSetIfChanged(ref _isNoneBottomChecked, value);
  287. }
  288. private bool _isNoneFullChecked;
  289. public bool IsNoneFullChecked
  290. {
  291. get => _isNoneFullChecked;
  292. set => this.RaiseAndSetIfChanged(ref _isNoneFullChecked, value);
  293. }
  294. private bool _isNoneMenuChecked;
  295. public bool IsNoneMenuChecked
  296. {
  297. get => _isNoneMenuChecked;
  298. set => this.RaiseAndSetIfChanged(ref _isNoneMenuChecked, value);
  299. }
  300. private bool _isSquareBottomChecked;
  301. public bool IsSquareBottomChecked
  302. {
  303. get => _isSquareBottomChecked;
  304. set => this.RaiseAndSetIfChanged(ref _isSquareBottomChecked, value);
  305. }
  306. private bool _isSquareFullChecked;
  307. public bool IsSquareFullChecked
  308. {
  309. get => _isSquareFullChecked;
  310. set => this.RaiseAndSetIfChanged(ref _isSquareFullChecked, value);
  311. }
  312. private bool _isSquareMenuChecked;
  313. public bool IsSquareMenuChecked
  314. {
  315. get => _isSquareMenuChecked;
  316. set => this.RaiseAndSetIfChanged(ref _isSquareMenuChecked, value);
  317. }
  318. private bool _isFillSquareBottomChecked;
  319. public bool IsFillSquareBottomChecked
  320. {
  321. get => _isFillSquareBottomChecked;
  322. set => this.RaiseAndSetIfChanged(ref _isFillSquareBottomChecked, value);
  323. }
  324. private bool _isFillSquareFullChecked;
  325. public bool IsFillSquareFullChecked
  326. {
  327. get => _isFillSquareFullChecked;
  328. set => this.RaiseAndSetIfChanged(ref _isFillSquareFullChecked, value);
  329. }
  330. private bool _isFillSquareMenuChecked;
  331. public bool IsFillSquareMenuChecked
  332. {
  333. get => _isFillSquareMenuChecked;
  334. set => this.RaiseAndSetIfChanged(ref _isFillSquareMenuChecked, value);
  335. }
  336. #endregion
  337. #endregion Gallery
  338. #region Commands
  339. public ReactiveCommand<Unit, Unit>? ExitCommand { get; }
  340. public ReactiveCommand<Unit, Unit>? MinimizeCommand { get; }
  341. public ReactiveCommand<Unit, Unit>? MaximizeCommand { get; }
  342. public ReactiveCommand<Unit, Unit>? ToggleFullscreenCommand { get; }
  343. public ReactiveCommand<Unit, Unit>? NextCommand { get; }
  344. public ReactiveCommand<Unit, Unit>? NextButtonCommand { get; }
  345. public ReactiveCommand<Unit, Unit>? NextArrowButtonCommand { get; }
  346. public ReactiveCommand<Unit, Unit>? PreviousCommand { get; }
  347. public ReactiveCommand<Unit, Unit>? PreviousButtonCommand { get; }
  348. public ReactiveCommand<Unit, Unit>? PreviousArrowButtonCommand { get; }
  349. public ReactiveCommand<Unit, Unit>? NextFolderCommand { get; }
  350. public ReactiveCommand<Unit, Unit>? PreviousFolderCommand { get; }
  351. public ReactiveCommand<Unit, Unit>? FirstCommand { get; }
  352. public ReactiveCommand<Unit, Unit>? LastCommand { get; }
  353. public ReactiveCommand<Unit, Unit>? OpenFileCommand { get; }
  354. public ReactiveCommand<Unit, Unit>? SaveFileCommand { get; }
  355. public ReactiveCommand<Unit, Unit>? OpenLastFileCommand { get; }
  356. public ReactiveCommand<Unit, Unit>? PasteCommand { get; }
  357. public ReactiveCommand<string, Unit>? CopyFileCommand { get; }
  358. public ReactiveCommand<string, Unit>? CopyBase64Command { get; }
  359. public ReactiveCommand<string, Unit>? CopyFilePathCommand { get; }
  360. public ReactiveCommand<string, Unit>? FilePropertiesCommand { get; }
  361. public ReactiveCommand<Unit, Unit>? CopyImageCommand { get; }
  362. public ReactiveCommand<string, Unit>? CutCommand { get; }
  363. public ReactiveCommand<Unit, Unit>? ReloadCommand { get; }
  364. public ReactiveCommand<string, Unit>? PrintCommand { get; }
  365. public ReactiveCommand<string, Unit>? DeleteFileCommand { get; }
  366. public ReactiveCommand<string, Unit>? RecycleFileCommand { get; }
  367. public ReactiveCommand<Unit, Unit>? CloseMenuCommand { get; }
  368. public ReactiveCommand<Unit, Unit>? ToggleFileMenuCommand { get; }
  369. public ReactiveCommand<Unit, Unit>? ToggleImageMenuCommand { get; }
  370. public ReactiveCommand<Unit, Unit>? ToggleSettingsMenuCommand { get; }
  371. public ReactiveCommand<Unit, Unit>? ToggleToolsMenuCommand { get; }
  372. public ReactiveCommand<string, Unit>? LocateOnDiskCommand { get; }
  373. public ReactiveCommand<string, Unit>? OpenWithCommand { get; }
  374. public ReactiveCommand<Unit, Unit>? RenameCommand { get; }
  375. public ReactiveCommand<Unit, Unit>? NewWindowCommand { get; }
  376. public ReactiveCommand<string, Unit>? DuplicateFileCommand { get; }
  377. public ReactiveCommand<Unit, Unit>? ToggleLoopingCommand { get; }
  378. public ReactiveCommand<Unit, Unit>? RotateLeftCommand { get; }
  379. public ReactiveCommand<Unit, Unit>? RotateRightCommand { get; }
  380. public ReactiveCommand<Unit, Unit>? FlipCommand { get; }
  381. public ReactiveCommand<Unit, Unit>? StretchCommand { get; }
  382. public ReactiveCommand<Unit, Unit>? CropCommand { get; }
  383. public ReactiveCommand<Unit, Unit>? ChangeAutoFitCommand { get; }
  384. public ReactiveCommand<Unit, Unit>? ChangeTopMostCommand { get; }
  385. public ReactiveCommand<Unit, Unit>? ChangeCtrlZoomCommand { get; }
  386. public ReactiveCommand<Unit, Unit>? ToggleUICommand { get; }
  387. public ReactiveCommand<Unit, Unit>? ChangeBackgroundCommand { get; }
  388. public ReactiveCommand<Unit, Unit>? ToggleBottomNavBarCommand { get; }
  389. public ReactiveCommand<Unit, Unit>? ToggleBottomGalleryShownInHiddenUICommand { get; }
  390. public ReactiveCommand<Unit, Unit>? ToggleTaskbarProgressCommand { get; }
  391. public ReactiveCommand<Unit, Unit>? ShowExifWindowCommand { get; }
  392. public ReactiveCommand<Unit, Unit>? ShowAboutWindowCommand { get; }
  393. public ReactiveCommand<Unit, Unit>? ShowSettingsWindowCommand { get; }
  394. public ReactiveCommand<Unit, Unit>? ShowKeybindingsWindowCommand { get; }
  395. public ReactiveCommand<Unit, Unit>? SetExifRating0Command { get; }
  396. public ReactiveCommand<Unit, Unit>? SetExifRating1Command { get; }
  397. public ReactiveCommand<Unit, Unit>? SetExifRating2Command { get; }
  398. public ReactiveCommand<Unit, Unit>? SetExifRating3Command { get; }
  399. public ReactiveCommand<Unit, Unit>? SetExifRating4Command { get; }
  400. public ReactiveCommand<Unit, Unit>? SetExifRating5Command { get; }
  401. public ReactiveCommand<Unit, Unit>? OpenGoogleLinkCommand { get; }
  402. public ReactiveCommand<Unit, Unit>? OpenBingLinkCommand { get; }
  403. public ReactiveCommand<Unit, Unit>? OptimizeImageCommand { get; }
  404. public ReactiveCommand<int, Unit>? ResizeCommand { get; }
  405. public ReactiveCommand<int, Unit>? ConvertCommand { get; }
  406. public ReactiveCommand<Unit, Unit>? SortFilesByNameCommand { get; }
  407. public ReactiveCommand<Unit, Unit>? SortFilesBySizeCommand { get; }
  408. public ReactiveCommand<Unit, Unit>? SortFilesByExtensionCommand { get; }
  409. public ReactiveCommand<Unit, Unit>? SortFilesByCreationTimeCommand { get; }
  410. public ReactiveCommand<Unit, Unit>? SortFilesByLastAccessTimeCommand { get; }
  411. public ReactiveCommand<Unit, Unit>? SortFilesRandomlyCommand { get; }
  412. public ReactiveCommand<Unit, Unit>? SortFilesAscendingCommand { get; }
  413. public ReactiveCommand<Unit, Unit>? SortFilesDescendingCommand { get; }
  414. public ReactiveCommand<Unit, Unit>? ToggleGalleryCommand { get; }
  415. public ReactiveCommand<Unit, Unit>? ToggleBottomGalleryCommand { get; }
  416. public ReactiveCommand<Unit, Unit>? CloseGalleryCommand { get; }
  417. public ReactiveCommand<Unit, Unit>? ToggleScrollCommand { get; }
  418. public ReactiveCommand<Unit, Unit>? ToggleSubdirectoriesCommand { get; }
  419. public ReactiveCommand<Unit, Unit>? ColorPickerCommand { get; }
  420. public ReactiveCommand<int, Unit>? SlideshowCommand { get; }
  421. public ReactiveCommand<string, Unit>? SetAsWallpaperCommand { get; }
  422. public ReactiveCommand<string, Unit>? SetAsLockScreenCommand { get; }
  423. public ReactiveCommand<string, Unit>? GalleryItemStretchCommand { get; }
  424. public ReactiveCommand<Unit, Unit>? ResetSettingsCommand { get; }
  425. public ReactiveCommand<Unit, Unit>? ShowSideBySideCommand { get; }
  426. #endregion Commands
  427. #region Fields
  428. #region Booleans
  429. private bool _isLoading;
  430. public bool IsLoading
  431. {
  432. get => _isLoading;
  433. set => this.RaiseAndSetIfChanged(ref _isLoading, value);
  434. }
  435. private bool _isInterfaceShown = SettingsHelper.Settings.UIProperties.ShowInterface;
  436. public bool IsInterfaceShown
  437. {
  438. get => _isInterfaceShown;
  439. set => this.RaiseAndSetIfChanged(ref _isInterfaceShown, value);
  440. }
  441. private bool _isTopToolbarShown = SettingsHelper.Settings.UIProperties.ShowInterface;
  442. public bool IsTopToolbarShown
  443. {
  444. get => _isTopToolbarShown;
  445. set => this.RaiseAndSetIfChanged(ref _isTopToolbarShown, value);
  446. }
  447. private bool _isBottomToolbarShown = SettingsHelper.Settings.UIProperties.ShowBottomNavBar &&
  448. SettingsHelper.Settings.UIProperties.ShowInterface;
  449. public bool IsBottomToolbarShown
  450. {
  451. get => _isBottomToolbarShown;
  452. set => this.RaiseAndSetIfChanged(ref _isBottomToolbarShown, value);
  453. }
  454. private bool _isBottomToolbarShownSetting = SettingsHelper.Settings.UIProperties.ShowBottomNavBar;
  455. public bool IsBottomToolbarShownSetting
  456. {
  457. get => _isBottomToolbarShownSetting;
  458. set => this.RaiseAndSetIfChanged(ref _isBottomToolbarShownSetting, value);
  459. }
  460. private bool _isShowingTaskbarProgress = SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled;
  461. public bool IsShowingTaskbarProgress
  462. {
  463. get => _isShowingTaskbarProgress;
  464. set => this.RaiseAndSetIfChanged(ref _isShowingTaskbarProgress, value);
  465. }
  466. private bool _isFullscreen = SettingsHelper.Settings.WindowProperties.Fullscreen;
  467. public bool IsFullscreen
  468. {
  469. get => _isFullscreen;
  470. set => this.RaiseAndSetIfChanged(ref _isFullscreen, value);
  471. }
  472. private bool _isTopMost = SettingsHelper.Settings.WindowProperties.TopMost;
  473. public bool IsTopMost
  474. {
  475. get => _isTopMost;
  476. set => this.RaiseAndSetIfChanged(ref _isTopMost, value);
  477. }
  478. private bool _isIncludingSubdirectories = SettingsHelper.Settings.Sorting.IncludeSubDirectories;
  479. public bool IsIncludingSubdirectories
  480. {
  481. get => _isIncludingSubdirectories;
  482. set => this.RaiseAndSetIfChanged(ref _isIncludingSubdirectories, value);
  483. }
  484. private bool _isScrollingEnabled;
  485. public bool IsScrollingEnabled
  486. {
  487. get => _isScrollingEnabled;
  488. set => this.RaiseAndSetIfChanged(ref _isScrollingEnabled, value);
  489. }
  490. private bool _isStretched = SettingsHelper.Settings.ImageScaling.StretchImage;
  491. public bool IsStretched
  492. {
  493. get => _isStretched;
  494. set
  495. {
  496. this.RaiseAndSetIfChanged(ref _isStretched, value);
  497. SettingsHelper.Settings.ImageScaling.StretchImage = value;
  498. WindowHelper.SetSize(this);
  499. }
  500. }
  501. private bool _isLooping = SettingsHelper.Settings.UIProperties.Looping;
  502. public bool IsLooping
  503. {
  504. get => _isLooping;
  505. set => this.RaiseAndSetIfChanged(ref _isLooping, value);
  506. }
  507. private bool _isAutoFit = SettingsHelper.Settings.WindowProperties.AutoFit;
  508. public bool IsAutoFit
  509. {
  510. get => _isAutoFit;
  511. set => this.RaiseAndSetIfChanged(ref _isAutoFit, value);
  512. }
  513. private bool _isCtrlToZoomEnabled = SettingsHelper.Settings.Zoom.CtrlZoom;
  514. public bool IsCtrlToZoomEnabled
  515. {
  516. get => _isCtrlToZoomEnabled;
  517. set
  518. {
  519. this.RaiseAndSetIfChanged(ref _isCtrlToZoomEnabled, value);
  520. SettingsHelper.Settings.Zoom.CtrlZoom = value;
  521. }
  522. }
  523. private bool _isNavigatingInReverse = SettingsHelper.Settings.Zoom.HorizontalReverseScroll;
  524. public bool IsNavigatingInReverse
  525. {
  526. get => _isNavigatingInReverse;
  527. set
  528. {
  529. this.RaiseAndSetIfChanged(ref _isNavigatingInReverse, value);
  530. SettingsHelper.Settings.Zoom.HorizontalReverseScroll = value;
  531. }
  532. }
  533. private bool _isOpeningLastFileOnStartup = SettingsHelper.Settings.StartUp.OpenLastFile;
  534. public bool IsOpeningLastFileOnStartup
  535. {
  536. get => _isOpeningLastFileOnStartup;
  537. set
  538. {
  539. this.RaiseAndSetIfChanged(ref _isOpeningLastFileOnStartup, value);
  540. SettingsHelper.Settings.StartUp.OpenLastFile = value;
  541. }
  542. }
  543. private bool _isStayingCentered = SettingsHelper.Settings.WindowProperties.KeepCentered;
  544. public bool IsStayingCentered
  545. {
  546. get => _isStayingCentered;
  547. set
  548. {
  549. this.RaiseAndSetIfChanged(ref _isStayingCentered, value);
  550. SettingsHelper.Settings.WindowProperties.KeepCentered = value;
  551. }
  552. }
  553. private bool _isFileSavingDialogShown = SettingsHelper.Settings.UIProperties.ShowFileSavingDialog;
  554. public bool IsFileSavingDialogShown
  555. {
  556. get => _isFileSavingDialogShown;
  557. set
  558. {
  559. this.RaiseAndSetIfChanged(ref _isFileSavingDialogShown, value);
  560. SettingsHelper.Settings.UIProperties.ShowFileSavingDialog = value;
  561. }
  562. }
  563. private bool _isOpeningInSameWindow;
  564. public bool IsOpeningInSameWindow
  565. {
  566. get => _isOpeningInSameWindow;
  567. set => this.RaiseAndSetIfChanged(ref _isOpeningInSameWindow, value);
  568. }
  569. private bool _isEditableTitlebarOpen;
  570. public bool IsEditableTitlebarOpen
  571. {
  572. get => _isEditableTitlebarOpen;
  573. set => this.RaiseAndSetIfChanged(ref _isEditableTitlebarOpen, value);
  574. }
  575. #endregion Booleans
  576. public double WindowMinSize
  577. {
  578. get
  579. {
  580. return SizeDefaults.WindowMinSize;
  581. }
  582. }
  583. private double _titlebarHeight = SettingsHelper.Settings.WindowProperties.Fullscreen
  584. || !SettingsHelper.Settings.UIProperties.ShowInterface ? 0 : SizeDefaults.TitlebarHeight;
  585. public double TitlebarHeight
  586. {
  587. set => this.RaiseAndSetIfChanged(ref _titlebarHeight, value);
  588. get => _titlebarHeight;
  589. }
  590. private double _bottombarHeight = SettingsHelper.Settings.WindowProperties.Fullscreen
  591. || !SettingsHelper.Settings.UIProperties.ShowInterface ? 0 : SizeDefaults.BottombarHeight;
  592. public double BottombarHeight
  593. {
  594. set => this.RaiseAndSetIfChanged(ref _bottombarHeight, value);
  595. get => _bottombarHeight;
  596. }
  597. private int _scaleX = 1;
  598. // Used to flip the flip button
  599. public int ScaleX
  600. {
  601. get => _scaleX;
  602. set => this.RaiseAndSetIfChanged(ref _scaleX, value);
  603. }
  604. private UserControl? _currentView;
  605. public UserControl? CurrentView
  606. {
  607. get => _currentView;
  608. set => this.RaiseAndSetIfChanged(ref _currentView, value);
  609. }
  610. public ImageViewer? ImageViewer;
  611. private uint _exifRating;
  612. public uint EXIFRating
  613. {
  614. get => _exifRating;
  615. set => this.RaiseAndSetIfChanged(ref _exifRating, value);
  616. }
  617. private int _getIndex;
  618. public int GetIndex
  619. {
  620. get => _getIndex;
  621. set => this.RaiseAndSetIfChanged(ref _getIndex, value);
  622. }
  623. private double _getSlideshowSpeed = SettingsHelper.Settings.UIProperties.SlideShowTimer;
  624. public double GetSlideshowSpeed
  625. {
  626. get => _getSlideshowSpeed;
  627. set
  628. {
  629. var roundedValue = Math.Round(value, 2);
  630. this.RaiseAndSetIfChanged(ref _getSlideshowSpeed, roundedValue);
  631. SettingsHelper.Settings.UIProperties.SlideShowTimer = roundedValue;
  632. }
  633. }
  634. private double _getNavSpeed = SettingsHelper.Settings.UIProperties.NavSpeed;
  635. public double GetNavSpeed
  636. {
  637. get => Math.Round(_getNavSpeed, 2);
  638. set
  639. {
  640. this.RaiseAndSetIfChanged(ref _getNavSpeed, value);
  641. SettingsHelper.Settings.UIProperties.NavSpeed = value;
  642. }
  643. }
  644. private double _getZoomSpeed = SettingsHelper.Settings.Zoom.ZoomSpeed;
  645. public double GetZoomSpeed
  646. {
  647. get => _getZoomSpeed;
  648. set
  649. {
  650. var roundedValue = Math.Round(value, 2);
  651. this.RaiseAndSetIfChanged(ref _getZoomSpeed, roundedValue);
  652. SettingsHelper.Settings.Zoom.ZoomSpeed = roundedValue;
  653. }
  654. }
  655. #region strings
  656. private string? _getFlipped;
  657. public string? GetFlipped
  658. {
  659. get => _getFlipped;
  660. set => this.RaiseAndSetIfChanged(ref _getFlipped, value);
  661. }
  662. private string? _getBottomGallery;
  663. public string? GetBottomGallery
  664. {
  665. get => _getBottomGallery;
  666. set => this.RaiseAndSetIfChanged(ref _getBottomGallery, value);
  667. }
  668. private string? _getLooping;
  669. public string? GetLooping
  670. {
  671. get => _getLooping;
  672. set => this.RaiseAndSetIfChanged(ref _getLooping, value);
  673. }
  674. private string? _getScrolling;
  675. public string? GetScrolling
  676. {
  677. get => _getScrolling;
  678. set => this.RaiseAndSetIfChanged(ref _getScrolling, value);
  679. }
  680. private string? _getCtrlZoom;
  681. public string? GetCtrlZoom
  682. {
  683. get => _getCtrlZoom;
  684. set => this.RaiseAndSetIfChanged(ref _getCtrlZoom, value);
  685. }
  686. private string? _getPrintSizeInch;
  687. public string? GetPrintSizeInch
  688. {
  689. get => _getPrintSizeInch;
  690. set => this.RaiseAndSetIfChanged(ref _getPrintSizeInch, value);
  691. }
  692. private string? _getPrintSizeCm;
  693. public string? GetPrintSizeCm
  694. {
  695. get => _getPrintSizeCm;
  696. set => this.RaiseAndSetIfChanged(ref _getPrintSizeCm, value);
  697. }
  698. private string? _getSizeMp;
  699. public string? GetSizeMp
  700. {
  701. get => _getSizeMp;
  702. set => this.RaiseAndSetIfChanged(ref _getSizeMp, value);
  703. }
  704. private string? _getResolution;
  705. public string? GetResolution
  706. {
  707. get => _getResolution;
  708. set => this.RaiseAndSetIfChanged(ref _getResolution, value);
  709. }
  710. private string? _getBitDepth;
  711. public string? GetBitDepth
  712. {
  713. get => _getBitDepth;
  714. set => this.RaiseAndSetIfChanged(ref _getBitDepth, value);
  715. }
  716. private string? _getAspectRatio;
  717. public string? GetAspectRatio
  718. {
  719. get => _getAspectRatio;
  720. set => this.RaiseAndSetIfChanged(ref _getAspectRatio, value);
  721. }
  722. private string? _getLatitude;
  723. public string? GetLatitude
  724. {
  725. get => _getLatitude;
  726. set => this.RaiseAndSetIfChanged(ref _getLatitude, value);
  727. }
  728. private string? _getLongitude;
  729. public string? GetLongitude
  730. {
  731. get => _getLongitude;
  732. set => this.RaiseAndSetIfChanged(ref _getLongitude, value);
  733. }
  734. private string? _getAltitude;
  735. public string? GetAltitude
  736. {
  737. get => _getAltitude;
  738. set => this.RaiseAndSetIfChanged(ref _getAltitude, value);
  739. }
  740. private string? _googleLink;
  741. public string? GoogleLink
  742. {
  743. get => _googleLink;
  744. set => this.RaiseAndSetIfChanged(ref _googleLink, value);
  745. }
  746. private string? _bingLink;
  747. public string? BingLink
  748. {
  749. get => _bingLink;
  750. set => this.RaiseAndSetIfChanged(ref _bingLink, value);
  751. }
  752. private string? _getAuthors;
  753. public string? GetAuthors
  754. {
  755. get => _getAuthors;
  756. set => this.RaiseAndSetIfChanged(ref _getAuthors, value);
  757. }
  758. private string? _getDateTaken;
  759. public string? GetDateTaken
  760. {
  761. get => _getDateTaken;
  762. set => this.RaiseAndSetIfChanged(ref _getDateTaken, value);
  763. }
  764. private string? _getCopyright;
  765. public string? GetCopyright
  766. {
  767. get => _getCopyright;
  768. set => this.RaiseAndSetIfChanged(ref _getCopyright, value);
  769. }
  770. private string? _getTitle;
  771. public string? GetTitle
  772. {
  773. get => _getTitle;
  774. set => this.RaiseAndSetIfChanged(ref _getTitle, value);
  775. }
  776. private string? _getSubject;
  777. public string? GetSubject
  778. {
  779. get => _getSubject;
  780. set => this.RaiseAndSetIfChanged(ref _getSubject, value);
  781. }
  782. private string? _getSoftware;
  783. public string? GetSoftware
  784. {
  785. get => _getSoftware;
  786. set => this.RaiseAndSetIfChanged(ref _getSoftware, value);
  787. }
  788. private string? _getResolutionUnit;
  789. public string? GetResolutionUnit
  790. {
  791. get => _getResolutionUnit;
  792. set => this.RaiseAndSetIfChanged(ref _getResolutionUnit, value);
  793. }
  794. private string? _getColorRepresentation;
  795. public string? GetColorRepresentation
  796. {
  797. get => _getColorRepresentation;
  798. set => this.RaiseAndSetIfChanged(ref _getColorRepresentation, value);
  799. }
  800. private string? _getCompression;
  801. public string? GetCompression
  802. {
  803. get => _getCompression;
  804. set => this.RaiseAndSetIfChanged(ref _getCompression, value);
  805. }
  806. private string? _getCompressedBitsPixel;
  807. public string? GetCompressedBitsPixel
  808. {
  809. get => _getCompressedBitsPixel;
  810. set => this.RaiseAndSetIfChanged(ref _getCompressedBitsPixel, value);
  811. }
  812. private string? _getCameraMaker;
  813. public string? GetCameraMaker
  814. {
  815. get => _getCameraMaker;
  816. set => this.RaiseAndSetIfChanged(ref _getCameraMaker, value);
  817. }
  818. private string? _getCameraModel;
  819. public string? GetCameraModel
  820. {
  821. get => _getCameraModel;
  822. set => this.RaiseAndSetIfChanged(ref _getCameraModel, value);
  823. }
  824. private string? _GetExposureProgram;
  825. public string? GetExposureProgram
  826. {
  827. get => _GetExposureProgram;
  828. set => this.RaiseAndSetIfChanged(ref _GetExposureProgram, value);
  829. }
  830. private string? _getExposureTime;
  831. public string? GetExposureTime
  832. {
  833. get => _getExposureTime;
  834. set => this.RaiseAndSetIfChanged(ref _getExposureTime, value);
  835. }
  836. private string? _GetExposureBias;
  837. public string? GetExposureBias
  838. {
  839. get => _GetExposureBias;
  840. set => this.RaiseAndSetIfChanged(ref _GetExposureBias, value);
  841. }
  842. private string? _GetFNumber;
  843. public string? GetFNumber
  844. {
  845. get => _GetFNumber;
  846. set => this.RaiseAndSetIfChanged(ref _GetFNumber, value);
  847. }
  848. private string? _getMaxAperture;
  849. public string? GetMaxAperture
  850. {
  851. get => _getMaxAperture;
  852. set => this.RaiseAndSetIfChanged(ref _getMaxAperture, value);
  853. }
  854. private string? _getDigitalZoom;
  855. public string? GetDigitalZoom
  856. {
  857. get => _getDigitalZoom;
  858. set => this.RaiseAndSetIfChanged(ref _getDigitalZoom, value);
  859. }
  860. private string? _getFocalLength35Mm;
  861. public string? GetFocalLength35Mm
  862. {
  863. get => _getFocalLength35Mm;
  864. set => this.RaiseAndSetIfChanged(ref _getFocalLength35Mm, value);
  865. }
  866. private string? _getFocalLength;
  867. public string? GetFocalLength
  868. {
  869. get => _getFocalLength;
  870. set => this.RaiseAndSetIfChanged(ref _getFocalLength, value);
  871. }
  872. private string? _getISOSpeed;
  873. public string? GetISOSpeed
  874. {
  875. get => _getISOSpeed;
  876. set => this.RaiseAndSetIfChanged(ref _getISOSpeed, value);
  877. }
  878. private string? _getMeteringMode;
  879. public string? GetMeteringMode
  880. {
  881. get => _getMeteringMode;
  882. set => this.RaiseAndSetIfChanged(ref _getMeteringMode, value);
  883. }
  884. private string? _getContrast;
  885. public string? GetContrast
  886. {
  887. get => _getContrast;
  888. set => this.RaiseAndSetIfChanged(ref _getContrast, value);
  889. }
  890. private string? _getSaturation;
  891. public string? GetSaturation
  892. {
  893. get => _getSaturation;
  894. set => this.RaiseAndSetIfChanged(ref _getSaturation, value);
  895. }
  896. private string? _getSharpness;
  897. public string? GetSharpness
  898. {
  899. get => _getSharpness;
  900. set => this.RaiseAndSetIfChanged(ref _getSharpness, value);
  901. }
  902. private string? _getWhiteBalance;
  903. public string? GetWhiteBalance
  904. {
  905. get => _getWhiteBalance;
  906. set => this.RaiseAndSetIfChanged(ref _getWhiteBalance, value);
  907. }
  908. private string? _getFlashMode;
  909. public string? GetFlashMode
  910. {
  911. get => _getFlashMode;
  912. set => this.RaiseAndSetIfChanged(ref _getFlashMode, value);
  913. }
  914. private string? _getFlashEnergy;
  915. public string? GetFlashEnergy
  916. {
  917. get => _getFlashEnergy;
  918. set => this.RaiseAndSetIfChanged(ref _getFlashEnergy, value);
  919. }
  920. private string? _getLightSource;
  921. public string? GetLightSource
  922. {
  923. get => _getLightSource;
  924. set => this.RaiseAndSetIfChanged(ref _getLightSource, value);
  925. }
  926. private string? _getBrightness;
  927. public string? GetBrightness
  928. {
  929. get => _getBrightness;
  930. set => this.RaiseAndSetIfChanged(ref _getBrightness, value);
  931. }
  932. private string? _getPhotometricInterpretation;
  933. public string? GetPhotometricInterpretation
  934. {
  935. get => _getPhotometricInterpretation;
  936. set => this.RaiseAndSetIfChanged(ref _getPhotometricInterpretation, value);
  937. }
  938. private string? _getOrientation;
  939. public string? GetOrientation
  940. {
  941. get => _getOrientation;
  942. set => this.RaiseAndSetIfChanged(ref _getOrientation, value);
  943. }
  944. private string? _getExifVersion;
  945. public string? GetExifVersion
  946. {
  947. get => _getExifVersion;
  948. set => this.RaiseAndSetIfChanged(ref _getExifVersion, value);
  949. }
  950. private string? _GetLensModel;
  951. public string? GetLensModel
  952. {
  953. get => _GetLensModel;
  954. set => this.RaiseAndSetIfChanged(ref _GetLensModel, value);
  955. }
  956. private string? _getLensMaker;
  957. public string? GetLensMaker
  958. {
  959. get => _getLensMaker;
  960. set => this.RaiseAndSetIfChanged(ref _getLensMaker, value);
  961. }
  962. #endregion strings
  963. #region Window Properties
  964. private string? _title = "Loading...";
  965. public string? Title
  966. {
  967. get => _title;
  968. set => this.RaiseAndSetIfChanged(ref _title, value);
  969. }
  970. private string? _titleTooltip = "Loading...";
  971. public string? TitleTooltip
  972. {
  973. get => _titleTooltip;
  974. set => this.RaiseAndSetIfChanged(ref _titleTooltip, value);
  975. }
  976. private string? _windowTitle = "PicView";
  977. public string? WindowTitle
  978. {
  979. get => _windowTitle;
  980. set => this.RaiseAndSetIfChanged(ref _windowTitle, value);
  981. }
  982. private SizeToContent _sizeToContent;
  983. public SizeToContent SizeToContent
  984. {
  985. get => _sizeToContent;
  986. set => this.RaiseAndSetIfChanged(ref _sizeToContent, value);
  987. }
  988. private bool _canResize;
  989. public bool CanResize
  990. {
  991. get => _canResize;
  992. set => this.RaiseAndSetIfChanged(ref _canResize, value);
  993. }
  994. private bool _isRotationAnimationEnabled;
  995. public bool IsRotationAnimationEnabled
  996. {
  997. get => _isRotationAnimationEnabled;
  998. set => this.RaiseAndSetIfChanged(ref _isRotationAnimationEnabled, value);
  999. }
  1000. #endregion Window Properties
  1001. #region Size
  1002. private double _titleMaxWidth;
  1003. public double TitleMaxWidth
  1004. {
  1005. get => _titleMaxWidth;
  1006. set => this.RaiseAndSetIfChanged(ref _titleMaxWidth, value);
  1007. }
  1008. #endregion Size
  1009. #region Zoom
  1010. private double _rotationAngle;
  1011. public double RotationAngle
  1012. {
  1013. get => _rotationAngle;
  1014. set => this.RaiseAndSetIfChanged(ref _rotationAngle, value);
  1015. }
  1016. private double _zoomValue;
  1017. public double ZoomValue
  1018. {
  1019. get => _zoomValue;
  1020. set => this.RaiseAndSetIfChanged(ref _zoomValue, value);
  1021. }
  1022. private ScrollBarVisibility _toggleScrollBarVisibility;
  1023. public ScrollBarVisibility ToggleScrollBarVisibility
  1024. {
  1025. get => _toggleScrollBarVisibility;
  1026. set => this.RaiseAndSetIfChanged(ref _toggleScrollBarVisibility, value);
  1027. }
  1028. #endregion Zoom
  1029. #region Menus
  1030. private bool _isFileMenuVisible;
  1031. public bool IsFileMenuVisible
  1032. {
  1033. get => _isFileMenuVisible;
  1034. set => this.RaiseAndSetIfChanged(ref _isFileMenuVisible, value);
  1035. }
  1036. private bool _isImageMenuVisible;
  1037. public bool IsImageMenuVisible
  1038. {
  1039. get => _isImageMenuVisible;
  1040. set => this.RaiseAndSetIfChanged(ref _isImageMenuVisible, value);
  1041. }
  1042. private bool _isSettingsMenuVisible;
  1043. public bool IsSettingsMenuVisible
  1044. {
  1045. get => _isSettingsMenuVisible;
  1046. set => this.RaiseAndSetIfChanged(ref _isSettingsMenuVisible, value);
  1047. }
  1048. private bool _isToolsMenuVisible;
  1049. public bool IsToolsMenuVisible
  1050. {
  1051. get => _isToolsMenuVisible;
  1052. set => this.RaiseAndSetIfChanged(ref _isToolsMenuVisible, value);
  1053. }
  1054. #endregion Menus
  1055. #endregion Fields
  1056. #region Services
  1057. public ImageIterator? ImageIterator;
  1058. #endregion Services
  1059. #region Methods
  1060. #region Sorting Order
  1061. private FileListHelper.SortFilesBy _sortOrder;
  1062. public FileListHelper.SortFilesBy SortOrder
  1063. {
  1064. get => _sortOrder;
  1065. set => this.RaiseAndSetIfChanged(ref _sortOrder, value);
  1066. }
  1067. private bool _isAscending = SettingsHelper.Settings.Sorting.Ascending;
  1068. public bool IsAscending
  1069. {
  1070. get => _isAscending;
  1071. set => this.RaiseAndSetIfChanged(ref _isAscending, value);
  1072. }
  1073. #endregion Sorting Order
  1074. private async Task ResizeImageByPercentage(int percentage)
  1075. {
  1076. SetTitleHelper.SetLoadingTitle(this);
  1077. var success = await ConversionHelper.ResizeImageByPercentage(FileInfo, percentage);
  1078. if (success)
  1079. {
  1080. ImageIterator?.RemoveCurrentItemFromPreLoader();
  1081. await ImageIterator?.IterateToIndex(ImageIterator.CurrentIndex);
  1082. }
  1083. else
  1084. {
  1085. SetTitleHelper.SetTitle(this);
  1086. }
  1087. }
  1088. private async Task ConvertFileExtension(int index)
  1089. {
  1090. if (FileInfo is null)
  1091. {
  1092. return;
  1093. }
  1094. if (ImageIterator is not null)
  1095. {
  1096. ImageIterator.IsRenamingInProgress = true;
  1097. }
  1098. var newPath = await ConversionHelper.ConvertTask(FileInfo, index);
  1099. if (!string.IsNullOrWhiteSpace(newPath))
  1100. {
  1101. await NavigationHelper.LoadPicFromStringAsync(newPath, this);
  1102. }
  1103. if (ImageIterator is not null)
  1104. {
  1105. ImageIterator.IsRenamingInProgress = false;
  1106. }
  1107. }
  1108. private async Task CopyFileTask(string path)
  1109. {
  1110. if (string.IsNullOrWhiteSpace(path))
  1111. {
  1112. return;
  1113. }
  1114. if (PlatformService is null)
  1115. {
  1116. return;
  1117. }
  1118. await ClipboardHelper.CopyFileToClipboard(path, this);
  1119. }
  1120. private async Task CopyFilePathTask(string path)
  1121. {
  1122. if (string.IsNullOrWhiteSpace(path))
  1123. {
  1124. return;
  1125. }
  1126. if (PlatformService is null)
  1127. {
  1128. return;
  1129. }
  1130. await ClipboardHelper.CopyTextToClipboard(path);
  1131. }
  1132. private async Task CopyBase64Task(string path)
  1133. {
  1134. if (PlatformService is null)
  1135. {
  1136. return;
  1137. }
  1138. await ClipboardHelper.CopyBase64ToClipboard(path, this);
  1139. }
  1140. private async Task CutFileTask(string path)
  1141. {
  1142. if (string.IsNullOrWhiteSpace(path))
  1143. {
  1144. return;
  1145. }
  1146. if (PlatformService is null)
  1147. {
  1148. return;
  1149. }
  1150. await ClipboardHelper.CutFile(path, this);
  1151. }
  1152. private async Task DeleteFileTask(string path)
  1153. {
  1154. if (string.IsNullOrWhiteSpace(path))
  1155. {
  1156. return;
  1157. }
  1158. await Task.Run(() =>
  1159. {
  1160. FileDeletionHelper.DeleteFileWithErrorMsg(path, recycle: false);
  1161. });
  1162. }
  1163. private async Task RecycleFileTask(string path)
  1164. {
  1165. if (string.IsNullOrWhiteSpace(path))
  1166. {
  1167. return;
  1168. }
  1169. await Task.Run(() =>
  1170. {
  1171. FileDeletionHelper.DeleteFileWithErrorMsg(path, recycle: true);
  1172. });
  1173. }
  1174. private async Task DuplicateFileTask(string path)
  1175. {
  1176. if (string.IsNullOrWhiteSpace(path))
  1177. {
  1178. return;
  1179. }
  1180. if (Path.GetFileName(path) == FileInfo.FullName)
  1181. {
  1182. await FunctionsHelper.DuplicateFile();
  1183. }
  1184. else
  1185. {
  1186. await Task.Run(() =>
  1187. {
  1188. FileHelper.DuplicateAndReturnFileName(path);
  1189. });
  1190. }
  1191. }
  1192. private async Task ShowFilePropertiesTask(string path)
  1193. {
  1194. if (string.IsNullOrWhiteSpace(path))
  1195. {
  1196. return;
  1197. }
  1198. if (PlatformService is null)
  1199. {
  1200. return;
  1201. }
  1202. await Task.Run(() =>
  1203. {
  1204. PlatformService.ShowFileProperties(path);
  1205. });
  1206. }
  1207. private async Task PrintTask(string path)
  1208. {
  1209. if (string.IsNullOrWhiteSpace(path))
  1210. {
  1211. return;
  1212. }
  1213. if (PlatformService is null)
  1214. {
  1215. return;
  1216. }
  1217. await Task.Run(() =>
  1218. {
  1219. PlatformService?.Print(path);
  1220. });
  1221. }
  1222. private async Task OpenWithTask(string path)
  1223. {
  1224. if (string.IsNullOrWhiteSpace(path))
  1225. {
  1226. return;
  1227. }
  1228. if (PlatformService is null)
  1229. {
  1230. return;
  1231. }
  1232. await Task.Run(() =>
  1233. {
  1234. PlatformService?.OpenWith(path);
  1235. });
  1236. }
  1237. private async Task LocateOnDiskTask(string path)
  1238. {
  1239. if (string.IsNullOrWhiteSpace(path))
  1240. {
  1241. return;
  1242. }
  1243. if (PlatformService is null)
  1244. {
  1245. return;
  1246. }
  1247. await Task.Run(() =>
  1248. {
  1249. PlatformService?.LocateOnDisk(path);
  1250. });
  1251. }
  1252. private async Task SetAsWallpaperTask(string path)
  1253. {
  1254. if (string.IsNullOrWhiteSpace(path))
  1255. {
  1256. return;
  1257. }
  1258. if (PlatformService is null)
  1259. {
  1260. return;
  1261. }
  1262. await Task.Run(() =>
  1263. {
  1264. PlatformService?.SetAsWallpaper(path, 4);
  1265. });
  1266. }
  1267. private async Task SetAsLockScreenTask(string path)
  1268. {
  1269. if (string.IsNullOrWhiteSpace(path))
  1270. {
  1271. return;
  1272. }
  1273. if (PlatformService is null)
  1274. {
  1275. return;
  1276. }
  1277. await Task.Run(() =>
  1278. {
  1279. PlatformService?.SetAsLockScreen(path);
  1280. });
  1281. }
  1282. public async Task GalleryItemStretchTask(string value)
  1283. {
  1284. if (value.Equals("Square", StringComparison.OrdinalIgnoreCase))
  1285. {
  1286. if (GalleryFunctions.IsFullGalleryOpen)
  1287. {
  1288. await GalleryStretchMode.ChangeFullGalleryStretchSquare(this);
  1289. }
  1290. else
  1291. {
  1292. await GalleryStretchMode.ChangeBottomGalleryStretchSquare(this);
  1293. }
  1294. return;
  1295. }
  1296. if (value.Equals("FillSquare", StringComparison.OrdinalIgnoreCase))
  1297. {
  1298. if (GalleryFunctions.IsFullGalleryOpen)
  1299. {
  1300. await GalleryStretchMode.ChangeFullGalleryStretchSquareFill(this);
  1301. }
  1302. else
  1303. {
  1304. await GalleryStretchMode.ChangeBottomGalleryStretchSquareFill(this);
  1305. }
  1306. return;
  1307. }
  1308. if (Enum.TryParse<Stretch>(value, out var stretch))
  1309. {
  1310. if (GalleryFunctions.IsFullGalleryOpen)
  1311. {
  1312. await GalleryStretchMode.ChangeFullGalleryItemStretch(this, stretch);
  1313. }
  1314. else
  1315. {
  1316. await GalleryStretchMode.ChangeBottomGalleryItemStretch(this, stretch);
  1317. }
  1318. }
  1319. }
  1320. public async Task StartSlideShowTask(int milliseconds)
  1321. {
  1322. if (milliseconds <= 0)
  1323. {
  1324. await Avalonia.Navigation.Slideshow.StartSlideshow(this);
  1325. }
  1326. else
  1327. {
  1328. await Avalonia.Navigation.Slideshow.StartSlideshow(this, milliseconds);
  1329. }
  1330. }
  1331. #endregion Methods
  1332. public MainViewModel(IPlatformSpecificService? platformSpecificService)
  1333. {
  1334. FunctionsHelper.Vm = this;
  1335. PlatformService = platformSpecificService;
  1336. #region Window commands
  1337. ExitCommand = ReactiveCommand.CreateFromTask(WindowHelper.Close);
  1338. MinimizeCommand = ReactiveCommand.CreateFromTask(WindowHelper.Minimize);
  1339. MaximizeCommand = ReactiveCommand.CreateFromTask(WindowHelper.MaximizeRestore);
  1340. ToggleFullscreenCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Fullscreen);
  1341. NewWindowCommand = ReactiveCommand.Create(ProcessHelper.StartNewProcess);
  1342. ShowExifWindowCommand = ReactiveCommand.Create(platformSpecificService.ShowExifWindow);
  1343. ShowSettingsWindowCommand = ReactiveCommand.Create(platformSpecificService.ShowSettingsWindow);
  1344. ShowKeybindingsWindowCommand = ReactiveCommand.Create(platformSpecificService.ShowKeybindingsWindow);
  1345. ShowAboutWindowCommand = ReactiveCommand.Create(platformSpecificService.ShowAboutWindow);
  1346. #endregion Window commands
  1347. #region Navigation Commands
  1348. NextCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Next);
  1349. NextButtonCommand = ReactiveCommand.CreateFromTask(async () =>
  1350. {
  1351. await NavigationHelper.NavigateAndPositionCursor(next:true, arrow: false, vm: this);
  1352. });
  1353. NextArrowButtonCommand = ReactiveCommand.CreateFromTask(async () =>
  1354. {
  1355. await NavigationHelper.NavigateAndPositionCursor(next:true, arrow: true, vm: this);
  1356. });
  1357. NextFolderCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.NextFolder);
  1358. PreviousCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Prev);
  1359. PreviousButtonCommand = ReactiveCommand.CreateFromTask(async () =>
  1360. {
  1361. await NavigationHelper.NavigateAndPositionCursor(next:false, arrow: false, vm: this);
  1362. });
  1363. PreviousArrowButtonCommand = ReactiveCommand.CreateFromTask(async () =>
  1364. {
  1365. await NavigationHelper.NavigateAndPositionCursor(next:false, arrow: true, vm: this);
  1366. });
  1367. PreviousFolderCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.PrevFolder);
  1368. FirstCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.First);
  1369. LastCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Last);
  1370. ReloadCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Reload);
  1371. #endregion Navigation Commands
  1372. #region Sort Commands
  1373. SortFilesByNameCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesByName);
  1374. SortFilesByCreationTimeCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesByCreationTime);
  1375. SortFilesByLastAccessTimeCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesByLastAccessTime);
  1376. SortFilesBySizeCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesBySize);
  1377. SortFilesByExtensionCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesByExtension);
  1378. SortFilesRandomlyCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesRandomly);
  1379. SortFilesAscendingCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesAscending);
  1380. SortFilesDescendingCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SortFilesDescending);
  1381. #endregion Sort Commands
  1382. #region Menus
  1383. CloseMenuCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.CloseMenus);
  1384. ToggleFileMenuCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleFileMenu);
  1385. ToggleImageMenuCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleImageMenu);
  1386. ToggleSettingsMenuCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleSettingsMenu);
  1387. ToggleToolsMenuCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleToolsMenu);
  1388. #endregion Menus
  1389. #region Image commands
  1390. RotateLeftCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.RotateLeft);
  1391. RotateRightCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.RotateRight);
  1392. FlipCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Flip);
  1393. StretchCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Stretch);
  1394. CropCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Crop);
  1395. ToggleScrollCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleScroll);
  1396. OptimizeImageCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.OptimizeImage);
  1397. ChangeBackgroundCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ChangeBackground);
  1398. ShowSideBySideCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SideBySide);
  1399. #endregion Image commands
  1400. #region File commands
  1401. OpenFileCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Open, Observable.Return(true));
  1402. OpenLastFileCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.OpenLastFile);
  1403. SaveFileCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Save);
  1404. CopyFileCommand = ReactiveCommand.CreateFromTask<string>(CopyFileTask);
  1405. CopyFilePathCommand = ReactiveCommand.CreateFromTask<string>(CopyFilePathTask);
  1406. FilePropertiesCommand = ReactiveCommand.CreateFromTask<string>(ShowFilePropertiesTask);
  1407. CopyImageCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.CopyImage);
  1408. CopyBase64Command = ReactiveCommand.CreateFromTask<string>(CopyBase64Task);
  1409. CutCommand = ReactiveCommand.CreateFromTask<string>(CutFileTask);
  1410. PasteCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Paste);
  1411. OpenWithCommand = ReactiveCommand.CreateFromTask<string>(OpenWithTask);
  1412. RenameCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.Rename);
  1413. ResizeCommand = ReactiveCommand.CreateFromTask<int>(ResizeImageByPercentage);
  1414. ConvertCommand = ReactiveCommand.CreateFromTask<int>(ConvertFileExtension);
  1415. DuplicateFileCommand = ReactiveCommand.CreateFromTask<string>(DuplicateFileTask);
  1416. PrintCommand = ReactiveCommand.CreateFromTask<string>(PrintTask);
  1417. DeleteFileCommand = ReactiveCommand.CreateFromTask<string>(DeleteFileTask);
  1418. RecycleFileCommand = ReactiveCommand.CreateFromTask<string>(RecycleFileTask);
  1419. LocateOnDiskCommand = ReactiveCommand.CreateFromTask<string>(LocateOnDiskTask);
  1420. SetAsWallpaperCommand = ReactiveCommand.CreateFromTask<string>(SetAsWallpaperTask);
  1421. SetAsLockScreenCommand = ReactiveCommand.CreateFromTask<string>(SetAsLockScreenTask);
  1422. #endregion File commands
  1423. #region EXIF commands
  1424. SetExifRating0Command = ReactiveCommand.CreateFromTask(FunctionsHelper.Set0Star);
  1425. SetExifRating1Command = ReactiveCommand.CreateFromTask(FunctionsHelper.Set1Star);
  1426. SetExifRating2Command = ReactiveCommand.CreateFromTask(FunctionsHelper.Set2Star);
  1427. SetExifRating3Command = ReactiveCommand.CreateFromTask(FunctionsHelper.Set3Star);
  1428. SetExifRating4Command = ReactiveCommand.CreateFromTask(FunctionsHelper.Set4Star);
  1429. SetExifRating5Command = ReactiveCommand.CreateFromTask(FunctionsHelper.Set5Star);
  1430. OpenGoogleLinkCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.OpenGoogleMaps);
  1431. OpenBingLinkCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.OpenBingMaps);
  1432. #endregion EXIF commands
  1433. #region Gallery Commands
  1434. ToggleGalleryCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleGallery);
  1435. ToggleBottomGalleryCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.OpenCloseBottomGallery);
  1436. CloseGalleryCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.CloseGallery);
  1437. GalleryItemStretchCommand = ReactiveCommand.CreateFromTask<string>(GalleryItemStretchTask);
  1438. #endregion Gallery Commands
  1439. #region UI Commands
  1440. ToggleUICommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleInterface);
  1441. ToggleBottomNavBarCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleBottomToolbar);
  1442. ToggleBottomGalleryShownInHiddenUICommand = ReactiveCommand.CreateFromTask(async() =>
  1443. {
  1444. await HideInterfaceLogic.ToggleBottomGalleryShownInHiddenUI(this);
  1445. });
  1446. ChangeCtrlZoomCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ChangeCtrlZoom);
  1447. ColorPickerCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ColorPicker);
  1448. SlideshowCommand = ReactiveCommand.CreateFromTask<int>(StartSlideShowTask);
  1449. ToggleTaskbarProgressCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleTaskbarProgress);
  1450. #endregion UI Commands
  1451. #region Settings commands
  1452. ChangeAutoFitCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.AutoFitWindow);
  1453. ChangeTopMostCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.SetTopMost);
  1454. ToggleSubdirectoriesCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleSubdirectories);
  1455. ToggleLoopingCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ToggleLooping);
  1456. ResetSettingsCommand = ReactiveCommand.CreateFromTask(FunctionsHelper.ResetSettings);
  1457. #endregion Settings commands
  1458. }
  1459. public MainViewModel()
  1460. {
  1461. // Only use for unit test
  1462. }
  1463. }