forked from yatli/fvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitleBar.xaml.fs
67 lines (54 loc) · 2.21 KB
/
TitleBar.xaml.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace FVim
open Avalonia.Markup.Xaml
open Avalonia.VisualTree
open Avalonia.Controls
open Avalonia
open Avalonia.Rendering
type TitleBar() as this =
inherit ViewBase<TitleBarViewModel>()
static let TitleProperty = AvaloniaProperty.Register<TitleBar, string>("Title")
static let IsActiveProperty = AvaloniaProperty.Register<TitleBar, bool>("IsActive")
let root() = (this:>IVisual).VisualRoot :?> Window
let toggleMaximize() =
let win = root()
win.WindowState <-
match win.WindowState with
| WindowState.Normal -> WindowState.Maximized
| WindowState.Maximized -> WindowState.Normal
| x -> x
let mutable m_butmin:Button = null
let mutable m_butmax:Button = null
let mutable m_butclose:Button = null
let mutable m_title:TextBlock = null
do
AvaloniaXamlLoader.Load(this)
this.Watch [
this.DoubleTapped.Subscribe(fun ev ->
ev.Handled <- true
toggleMaximize())
this.PointerPressed.Subscribe(fun ev ->
ev.Handled <- true
root().BeginMoveDrag(ev)
)
]
override __.OnTemplateApplied _ =
m_butmin <- this.FindControl("MinimizeButton")
m_butmax <- this.FindControl("MaximizeButton")
m_butclose <- this.FindControl("CloseButton")
m_title <- this.FindControl("Title")
this.Watch [
m_butmin.Click.Subscribe(fun _ -> root().WindowState <- WindowState.Minimized)
m_butmax.Click.Subscribe(fun _ -> toggleMaximize())
m_butclose.Click.Subscribe(fun _ -> root().Close())
this.GetObservable(IsActiveProperty).Subscribe(fun v ->
[m_butmin.Classes; m_butmax.Classes; m_butclose.Classes; m_title.Classes]
|> List.iter (
if v then fun x -> ignore <| x.Remove("inactive")
else fun x -> x.Add("inactive")))
]
member __.Title
with get() = this.GetValue(TitleProperty)
and set(v) = this.SetValue(TitleProperty, v) |> ignore
member __.IsActive
with get() = this.GetValue(IsActiveProperty)
and set(v) = this.SetValue(IsActiveProperty, v) |> ignore