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
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! # Command Tables

use std::rc::Rc;
use menu_definition::MenuDefinition;

/// A command
pub trait Command {
    /// Execute the command
    fn execute(&self);
}

/// Information about a command in a command table.
pub struct CommandTableEntry {
    /// Name of a command. This is used for command line entry.
    pub name: String,
    /// The underlying command that can be executed.
    pub command: Rc<Command>,
}

/// A group of related commands
///
/// Command tables are a way of grouping a set of related
/// command objects and providing user interfaces to the
/// commands.
///
/// Command tables can be interacted with via menus,
/// toolbars, keystrokes, gestures, and more.
pub struct CommandTable {
    /// The name of the command table
    pub name: String,
    /// Tables inherited by this table
    pub inherit: Vec<Rc<CommandTable>>,
    /// Commands in this table
    pub commands: Vec<CommandTableEntry>,
    /// Menu description
    pub menu_definition: Option<MenuDefinition>,
}

impl CommandTable {
    /// Construct a `CommandTable`.
    pub fn new(name: String,
               inherit: Vec<Rc<CommandTable>>,
               commands: Vec<CommandTableEntry>)
               -> Rc<CommandTable> {
        Rc::new(CommandTable {
            name: name,
            inherit: inherit,
            commands: commands,
            menu_definition: None,
        })
    }
}