MainViewModel.cs 50 KB

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