Skip to content

Commit

Permalink
Merge pull request #301 from SergejDK/menuitemaccelerator
Browse files Browse the repository at this point in the history
MenuItem Accelerator Property
  • Loading branch information
TimLariviere authored Feb 1, 2019
2 parents 892c59b + 2e19f6d commit 0e43355
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
8 changes: 8 additions & 0 deletions src/Fabulous.Core/ViewConverters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,14 @@ module Converters =
NavigationPage.SetTitleView(target, null)
| _, _ -> ()

/// Update the AcceleratorProperty of a MenuItem, given previous and current Accelerator
let internal updateAccelerator prevValue currValue (target: Xamarin.Forms.MenuItem) =
match prevValue, currValue with
| ValueNone, ValueNone -> ()
| ValueSome prevVal, ValueSome newVal when prevVal = newVal -> ()
| _, ValueNone -> Xamarin.Forms.MenuItem.SetAccelerator(target, null)
| _, ValueSome newVal -> Xamarin.Forms.MenuItem.SetAccelerator(target, makeAccelerator newVal)

/// Check if two LayoutOptions are equal
let internal equalLayoutOptions (x:Xamarin.Forms.LayoutOptions) (y:Xamarin.Forms.LayoutOptions) =
x.Alignment = y.Alignment && x.Expands = y.Expands
Expand Down
49 changes: 36 additions & 13 deletions src/Fabulous.Core/Xamarin.Forms.Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ type View() =
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _TitleIconAttribKey : AttributeKey<_> = AttributeKey<_>("TitleIcon")
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _TitleViewAttribKey : AttributeKey<_> = AttributeKey<_>("TitleView")
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _TitleViewAttribKey : AttributeKey<_> = AttributeKey<_>("TitleView")
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _BarBackgroundColorAttribKey : AttributeKey<_> = AttributeKey<_>("BarBackgroundColor")
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _BarTextColorAttribKey : AttributeKey<_> = AttributeKey<_>("BarTextColor")
Expand Down Expand Up @@ -404,6 +404,8 @@ type View() =
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _IsPresentedChangedAttribKey : AttributeKey<_> = AttributeKey<_>("IsPresentedChanged")
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _AcceleratorAttribKey : AttributeKey<_> = AttributeKey<_>("Accelerator")
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _TextDetailAttribKey : AttributeKey<_> = AttributeKey<_>("TextDetail")
[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
static member val _TextDetailColorAttribKey : AttributeKey<_> = AttributeKey<_>("TextDetailColor")
Expand Down Expand Up @@ -9736,10 +9738,10 @@ type View() =
| _, ValueSome currValue -> Xamarin.Forms.NavigationPage.SetTitleIcon(targetChild, makeFileImageSource currValue)
| ValueSome _, ValueNone -> Xamarin.Forms.NavigationPage.SetTitleIcon(targetChild, null) // TODO: not always perfect, should set back to original default?
| _ -> ()
// Adjust the attached properties
let prevChildValueOpt = match prevChildOpt with ValueNone -> ValueNone | ValueSome prevChild -> prevChild.TryGetAttributeKeyed<ViewElement>(View._TitleViewAttribKey)
let childValueOpt = newChild.TryGetAttributeKeyed<ViewElement>(View._TitleViewAttribKey)
updatePageTitleView prevChildValueOpt childValueOpt targetChild
// Adjust the attached properties
let prevChildValueOpt = match prevChildOpt with ValueNone -> ValueNone | ValueSome prevChild -> prevChild.TryGetAttributeKeyed<ViewElement>(View._TitleViewAttribKey)
let childValueOpt = newChild.TryGetAttributeKeyed<ViewElement>(View._TitleViewAttribKey)
updatePageTitleView prevChildValueOpt childValueOpt targetChild
())
match prevBarBackgroundColorOpt, currBarBackgroundColorOpt with
| ValueSome prevValue, ValueSome currValue when prevValue = currValue -> ()
Expand Down Expand Up @@ -10580,6 +10582,7 @@ type View() =
?command: unit -> unit,
?commandParameter: System.Object,
?icon: string,
?accelerator: string,
?classId: string,
?styleId: string,
?automationId: string,
Expand All @@ -10590,12 +10593,14 @@ type View() =
let attribCount = match command with Some _ -> attribCount + 1 | None -> attribCount
let attribCount = match commandParameter with Some _ -> attribCount + 1 | None -> attribCount
let attribCount = match icon with Some _ -> attribCount + 1 | None -> attribCount
let attribCount = match accelerator with Some _ -> attribCount + 1 | None -> attribCount

let attribBuilder = View.BuildElement(attribCount, ?classId=classId, ?styleId=styleId, ?automationId=automationId, ?created=created, ?ref=ref)
match text with None -> () | Some v -> attribBuilder.Add(View._TextAttribKey, (v))
match command with None -> () | Some v -> attribBuilder.Add(View._CommandAttribKey, makeCommand(v))
match commandParameter with None -> () | Some v -> attribBuilder.Add(View._CommandParameterAttribKey, (v))
match icon with None -> () | Some v -> attribBuilder.Add(View._IconAttribKey, (v))
match accelerator with None -> () | Some v -> attribBuilder.Add(View._AcceleratorAttribKey, (v))
attribBuilder

[<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>]
Expand All @@ -10621,6 +10626,8 @@ type View() =
let mutable currCommandParameterOpt = ValueNone
let mutable prevIconOpt = ValueNone
let mutable currIconOpt = ValueNone
let mutable prevAcceleratorOpt = ValueNone
let mutable currAcceleratorOpt = ValueNone
for kvp in curr.AttributesKeyed do
if kvp.Key = View._TextAttribKey.KeyValue then
currTextOpt <- ValueSome (kvp.Value :?> string)
Expand All @@ -10630,6 +10637,8 @@ type View() =
currCommandParameterOpt <- ValueSome (kvp.Value :?> System.Object)
if kvp.Key = View._IconAttribKey.KeyValue then
currIconOpt <- ValueSome (kvp.Value :?> string)
if kvp.Key = View._AcceleratorAttribKey.KeyValue then
currAcceleratorOpt <- ValueSome (kvp.Value :?> string)
match prevOpt with
| ValueNone -> ()
| ValueSome prev ->
Expand All @@ -10642,6 +10651,8 @@ type View() =
prevCommandParameterOpt <- ValueSome (kvp.Value :?> System.Object)
if kvp.Key = View._IconAttribKey.KeyValue then
prevIconOpt <- ValueSome (kvp.Value :?> string)
if kvp.Key = View._AcceleratorAttribKey.KeyValue then
prevAcceleratorOpt <- ValueSome (kvp.Value :?> string)
match prevTextOpt, currTextOpt with
| ValueSome prevValue, ValueSome currValue when prevValue = currValue -> ()
| _, ValueSome currValue -> target.Text <- currValue
Expand All @@ -10662,12 +10673,14 @@ type View() =
| _, ValueSome currValue -> target.Icon <- makeFileImageSource currValue
| ValueSome _, ValueNone -> target.Icon <- null
| ValueNone, ValueNone -> ()
updateAccelerator prevAcceleratorOpt currAcceleratorOpt target

/// Describes a MenuItem in the view
static member inline MenuItem(?text: string,
?command: unit -> unit,
?commandParameter: System.Object,
?icon: string,
?accelerator: string,
?classId: string,
?styleId: string,
?automationId: string,
Expand All @@ -10679,6 +10692,7 @@ type View() =
?command=command,
?commandParameter=commandParameter,
?icon=icon,
?accelerator=accelerator,
?classId=classId,
?styleId=styleId,
?automationId=automationId,
Expand Down Expand Up @@ -10862,6 +10876,7 @@ type View() =
?command: unit -> unit,
?commandParameter: System.Object,
?icon: string,
?accelerator: string,
?classId: string,
?styleId: string,
?automationId: string,
Expand All @@ -10871,7 +10886,7 @@ type View() =
let attribCount = match order with Some _ -> attribCount + 1 | None -> attribCount
let attribCount = match priority with Some _ -> attribCount + 1 | None -> attribCount

let attribBuilder = View.BuildMenuItem(attribCount, ?text=text, ?command=command, ?commandParameter=commandParameter, ?icon=icon, ?classId=classId, ?styleId=styleId, ?automationId=automationId, ?created=created, ?ref=ref)
let attribBuilder = View.BuildMenuItem(attribCount, ?text=text, ?command=command, ?commandParameter=commandParameter, ?icon=icon, ?accelerator=accelerator, ?classId=classId, ?styleId=styleId, ?automationId=automationId, ?created=created, ?ref=ref)
match order with None -> () | Some v -> attribBuilder.Add(View._OrderAttribKey, (v))
match priority with None -> () | Some v -> attribBuilder.Add(View._PriorityAttribKey, (v))
attribBuilder
Expand Down Expand Up @@ -10926,6 +10941,7 @@ type View() =
?command: unit -> unit,
?commandParameter: System.Object,
?icon: string,
?accelerator: string,
?classId: string,
?styleId: string,
?automationId: string,
Expand All @@ -10939,6 +10955,7 @@ type View() =
?command=command,
?commandParameter=commandParameter,
?icon=icon,
?accelerator=accelerator,
?classId=classId,
?styleId=styleId,
?automationId=automationId,
Expand Down Expand Up @@ -12550,9 +12567,9 @@ module ViewElementExtensions =
/// Adjusts the TitleIcon property in the visual element
member x.TitleIcon(value: string) = x.WithAttribute(View._TitleIconAttribKey, (value))

/// Adjusts the TitleView property in the visual element
member x.TitleView(value: ViewElement) = x.WithAttribute(View._TitleViewAttribKey, (value))
/// Adjusts the TitleView property in the visual element
member x.TitleView(value: ViewElement) = x.WithAttribute(View._TitleViewAttribKey, (value))

/// Adjusts the BarBackgroundColor property in the visual element
member x.BarBackgroundColor(value: Xamarin.Forms.Color) = x.WithAttribute(View._BarBackgroundColorAttribKey, (value))

Expand Down Expand Up @@ -12595,6 +12612,9 @@ module ViewElementExtensions =
/// Adjusts the IsPresentedChanged property in the visual element
member x.IsPresentedChanged(value: bool -> unit) = x.WithAttribute(View._IsPresentedChangedAttribKey, (fun f -> System.EventHandler(fun sender args -> f (sender :?> Xamarin.Forms.MasterDetailPage).IsPresented))(value))

/// Adjusts the Accelerator property in the visual element
member x.Accelerator(value: string) = x.WithAttribute(View._AcceleratorAttribKey, (value))

/// Adjusts the TextDetail property in the visual element
member x.TextDetail(value: string) = x.WithAttribute(View._TextDetailAttribKey, (value))

Expand Down Expand Up @@ -13241,9 +13261,9 @@ module ViewElementExtensions =
/// Adjusts the TitleIcon property in the visual element
let titleIcon (value: string) (x: ViewElement) = x.TitleIcon(value)

/// Adjusts the TitleView property in the visual element
let titleView (value: ViewElement) (x: ViewElement) = x.TitleView(value)
/// Adjusts the TitleView property in the visual element
let titleView (value: ViewElement) (x: ViewElement) = x.TitleView(value)

/// Adjusts the BarBackgroundColor property in the visual element
let barBackgroundColor (value: Xamarin.Forms.Color) (x: ViewElement) = x.BarBackgroundColor(value)

Expand Down Expand Up @@ -13286,6 +13306,9 @@ module ViewElementExtensions =
/// Adjusts the IsPresentedChanged property in the visual element
let isPresentedChanged (value: bool -> unit) (x: ViewElement) = x.IsPresentedChanged(value)

/// Adjusts the Accelerator property in the visual element
let accelerator (value: string) (x: ViewElement) = x.Accelerator(value)

/// Adjusts the TextDetail property in the visual element
let textDetail (value: string) (x: ViewElement) = x.TextDetail(value)

Expand Down
21 changes: 10 additions & 11 deletions tools/Generator/Xamarin.Forms.Core.json
Original file line number Diff line number Diff line change
Expand Up @@ -1527,13 +1527,13 @@
"modelType": "string",
"convToValue": "makeFileImageSource",
"defaultValue": "null"
},
{
"name": "TitleView",
"inputType": "ViewElement",
"modelType": "ViewElement",
"updateCode": "updatePageTitleView",
"defaultValue": "null"
},
{
"name": "TitleView",
"inputType": "ViewElement",
"modelType": "ViewElement",
"updateCode": "updatePageTitleView",
"defaultValue": "null"
}
]
},
Expand Down Expand Up @@ -1672,15 +1672,14 @@
"modelType": "string",
"convToValue": "makeFileImageSource",
"defaultValue": "null"
}
],
"attached": [
},
{
"name": "Accelerator",
"inputType": "string",
"modelType": "string",
"convToValue": "makeAccelerator",
"defaultValue": "null"
"defaultValue": "null",
"updateCode": "updateAccelerator"
}
]
},
Expand Down

0 comments on commit 0e43355

Please sign in to comment.