reaper_medium/
message_box.rs

1use crate::TryFromRawError;
2
3/// Type of message box to be displayed.
4#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
5pub enum MessageBoxType {
6    Okay,
7    OkayCancel,
8    AbortRetryIgnore,
9    YesNoCancel,
10    YesNo,
11    RetryCancel,
12}
13
14impl MessageBoxType {
15    /// Converts this value to an integer as expected by the low-level API.
16    pub fn to_raw(&self) -> i32 {
17        use MessageBoxType::*;
18        match self {
19            Okay => 0,
20            OkayCancel => 1,
21            AbortRetryIgnore => 2,
22            YesNoCancel => 3,
23            YesNo => 4,
24            RetryCancel => 5,
25        }
26    }
27}
28
29/// Message box result informing about the user's choice.
30#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
31pub enum MessageBoxResult {
32    Okay,
33    Cancel,
34    Abort,
35    Retry,
36    Ignore,
37    Yes,
38    No,
39}
40
41impl MessageBoxResult {
42    /// Converts an integer as returned by the low-level API to an automation mode.
43    pub fn try_from_raw(v: i32) -> Result<MessageBoxResult, TryFromRawError<i32>> {
44        use MessageBoxResult::*;
45        match v {
46            1 => Ok(Okay),
47            2 => Ok(Cancel),
48            3 => Ok(Abort),
49            4 => Ok(Retry),
50            5 => Ok(Ignore),
51            6 => Ok(Yes),
52            7 => Ok(No),
53            _ => Err(TryFromRawError::new(
54                "couldn't convert to message box result",
55                v,
56            )),
57        }
58    }
59}