Add clipboard extension. Fix #192

This commit is contained in:
Federico Terzi 2020-03-03 00:18:46 +01:00
parent 9183e1f1b9
commit 3e3f314aa2
5 changed files with 53 additions and 4 deletions

View File

@ -0,0 +1,43 @@
/*
* This file is part of espanso.
*
* Copyright (C) 2020 Federico Terzi
*
* espanso is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* espanso is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use serde_yaml::{Mapping, Value};
use crate::clipboard::ClipboardManager;
pub struct ClipboardExtension {
clipboard_manager: Box<dyn ClipboardManager>,
}
impl ClipboardExtension {
pub fn new(clipboard_manager: Box<dyn ClipboardManager>) -> ClipboardExtension {
ClipboardExtension{
clipboard_manager
}
}
}
impl super::Extension for ClipboardExtension {
fn name(&self) -> String {
String::from("clipboard")
}
fn calculate(&self, params: &Mapping, _: &Vec<String>) -> Option<String> {
self.clipboard_manager.get_clipboard()
}
}

View File

@ -18,24 +18,27 @@
*/
use serde_yaml::Mapping;
use crate::clipboard::ClipboardManager;
mod date;
mod shell;
mod script;
mod random;
mod dummy;
mod clipboard;
pub mod dummy;
pub trait Extension {
fn name(&self) -> String;
fn calculate(&self, params: &Mapping, args: &Vec<String>) -> Option<String>;
}
pub fn get_extensions() -> Vec<Box<dyn Extension>> {
pub fn get_extensions(clipboard_manager: Box<dyn ClipboardManager>) -> Vec<Box<dyn Extension>>{
vec![
Box::new(date::DateExtension::new()),
Box::new(shell::ShellExtension::new()),
Box::new(script::ScriptExtension::new()),
Box::new(random::RandomExtension::new()),
Box::new(dummy::DummyExtension::new()),
Box::new(clipboard::ClipboardExtension::new(clipboard_manager)),
]
}

View File

@ -344,7 +344,7 @@ fn daemon_background(receive_channel: Receiver<Event>, config_set: ConfigSet) {
let keyboard_manager = keyboard::get_manager();
let extensions = extension::get_extensions();
let extensions = extension::get_extensions(Box::new(clipboard::get_manager()));
let renderer = render::default::DefaultRenderer::new(extensions,
config_manager.default_config().clone());

View File

@ -218,9 +218,12 @@ pub struct MatchVariable {
#[serde(rename = "type")]
pub var_type: String,
#[serde(default = "default_params")]
pub params: Mapping,
}
fn default_params() -> Mapping {Mapping::new()}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum TriggerEntry {
Char(char),

View File

@ -271,7 +271,7 @@ mod tests {
use super::*;
fn get_renderer(config: Configs) -> DefaultRenderer {
DefaultRenderer::new(crate::extension::get_extensions(), config)
DefaultRenderer::new(vec![Box::new(crate::extension::dummy::DummyExtension::new())], config)
}
fn get_config_for(s: &str) -> Configs {