Skip to content

Commit

Permalink
background image: resolve home folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Apr 30, 2020
1 parent d69d25a commit 2468e96
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ViewModels/MainWindowViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open ReactiveUI
open Avalonia
open Avalonia.Controls
open System
open System.IO
open ui
open Avalonia.Media.Imaging
open Avalonia.Media
Expand All @@ -25,8 +26,6 @@ type MainWindowViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid:
if _maingrid.IsNone then EditorViewModel(1)
else _maingrid.Value

let trace fmt = trace (sprintf "MainWindowVM #%d" mainGrid.GridId) fmt

let mutable m_windowState = WindowState.Normal
let mutable m_customTitleBar = false
let mutable m_fullscreen = false
Expand All @@ -43,11 +42,19 @@ type MainWindowViewModel(cfg: config.ConfigObject.Workspace option, ?_maingrid:
let toggleFullScreen(gridid: int) =
if gridid = mainGrid.GridId then
this.Fullscreen <- not this.Fullscreen
trace "ToggleFullScreen %A" this.Fullscreen
trace (sprintf "MainWindowVM #%d" mainGrid.GridId) "ToggleFullScreen %A" this.Fullscreen

let updateBackgroundImage() =
try
let new_img = new Bitmap(States.background_image_file)
let path = States.background_image_file
let path = if path.StartsWith("~/") then
Path.Join(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
path.[2..])
else
path
trace (sprintf "MainWindowVM #%d" mainGrid.GridId) "%s" path
let new_img = new Bitmap(path)
ignore <| this.RaiseAndSetIfChanged(&m_bgimg_src, new_img, "BackgroundImage")
ignore <| this.RaiseAndSetIfChanged(&m_bgimg_w, m_bgimg_src.Size.Width, "BackgroundImageW")
ignore <| this.RaiseAndSetIfChanged(&m_bgimg_h, m_bgimg_src.Size.Height, "BackgroundImageH")
Expand Down

0 comments on commit 2468e96

Please sign in to comment.