winrt_toast/content/
action.rs1use windows::Data::Xml::Dom::XmlElement;
2
3use crate::hs;
4
5#[derive(Debug, Clone)]
7pub struct Action {
8 content: String,
9 arguments: String,
10 r#type: String,
11 activation_type: Option<ActivationType>,
12 placement: Option<ActionPlacement>,
13}
14
15impl Action {
16 pub fn new(
25 content: impl Into<String>,
26 arguments: impl Into<String>,
27 typ: impl Into<String>,
28 ) -> Self {
29 Self {
30 content: content.into(),
31 arguments: arguments.into(),
32 r#type: typ.into(),
33 activation_type: None,
34 placement: None,
35 }
36 }
37
38 pub fn with_activation_type(mut self, activation_type: ActivationType) -> Self {
40 self.activation_type = Some(activation_type);
41 self
42 }
43
44 pub fn with_placement(mut self, placement: ActionPlacement) -> Self {
46 self.placement = Some(placement);
47 self
48 }
49
50 pub(crate) fn write_to_element(&self, el: &XmlElement) -> crate::Result<()> {
51 el.SetAttribute(&hs("content"), &hs(&self.content))?;
52 el.SetAttribute(&hs("arguments"), &hs(&self.arguments))?;
53 el.SetAttribute(&hs("type"), &hs(&self.r#type))?;
54 if let Some(activation_type) = self.activation_type {
55 el.SetAttribute(&hs("activationType"), &hs(activation_type.as_str()))?;
56 }
57 if let Some(placement) = self.placement {
58 el.SetAttribute(&hs("placement"), &hs(placement.as_str()))?;
59 }
60
61 Ok(())
62 }
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
67pub enum ActivationType {
68 Foreground,
70 Background,
72 Protocol,
74}
75
76impl ActivationType {
77 fn as_str(&self) -> &'static str {
78 match self {
79 ActivationType::Foreground => "foreground",
80 ActivationType::Background => "background",
81 ActivationType::Protocol => "protocol",
82 }
83 }
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq)]
88pub enum ActionPlacement {
89 ContextMenu,
92}
93
94impl ActionPlacement {
95 fn as_str(&self) -> &'static str {
96 match self {
97 ActionPlacement::ContextMenu => "contextMenu",
98 }
99 }
100}