Add use_pango option for Match (#15)
This commit is contained in:
@@ -30,13 +30,15 @@ pub struct PluginInfo {
|
|||||||
|
|
||||||
/// Represents a match from a plugin
|
/// Represents a match from a plugin
|
||||||
///
|
///
|
||||||
/// The `title` and `description` support pango markup.
|
/// The `title` and `description` support pango markup when `use_pango` is set to true.
|
||||||
/// Refer to [Pango Markup](https://docs.gtk.org/Pango/pango_markup.html) for how to use pango markup.
|
/// Refer to [Pango Markup](https://docs.gtk.org/Pango/pango_markup.html) for how to use pango markup.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(StableAbi, Clone)]
|
#[derive(StableAbi, Clone)]
|
||||||
pub struct Match {
|
pub struct Match {
|
||||||
pub title: RString,
|
pub title: RString,
|
||||||
pub description: ROption<RString>,
|
pub description: ROption<RString>,
|
||||||
|
/// Whether the title and description should be interpreted as pango markup.
|
||||||
|
pub use_pango: bool,
|
||||||
/// The icon name from the icon theme in use
|
/// The icon name from the icon theme in use
|
||||||
pub icon: ROption<RString>,
|
pub icon: ROption<RString>,
|
||||||
/// For runners to differentiate between the matches. Not required.
|
/// For runners to differentiate between the matches. Not required.
|
||||||
|
@@ -589,7 +589,7 @@ fn handle_matches(
|
|||||||
let title = gtk::Label::builder()
|
let title = gtk::Label::builder()
|
||||||
.name(style_names::MATCH_TITLE)
|
.name(style_names::MATCH_TITLE)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.use_markup(true) // Allow pango markup
|
.use_markup(_match.use_pango)
|
||||||
.halign(gtk::Align::Start)
|
.halign(gtk::Align::Start)
|
||||||
.valign(gtk::Align::Center)
|
.valign(gtk::Align::Center)
|
||||||
.vexpand(true)
|
.vexpand(true)
|
||||||
@@ -610,7 +610,7 @@ fn handle_matches(
|
|||||||
>k::Label::builder()
|
>k::Label::builder()
|
||||||
.name(style_names::MATCH_DESC)
|
.name(style_names::MATCH_DESC)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.use_markup(true) // Allow pango markup
|
.use_markup(_match.use_pango)
|
||||||
.halign(gtk::Align::Start)
|
.halign(gtk::Align::Start)
|
||||||
.valign(gtk::Align::Center)
|
.valign(gtk::Align::Center)
|
||||||
.label(desc)
|
.label(desc)
|
||||||
|
@@ -73,8 +73,9 @@ pub fn get_matches(input: RString, entries: &mut Vec<(DesktopEntry, u64)>) -> RV
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(entry, id, _)| Match {
|
.map(|(entry, id, _)| Match {
|
||||||
title: entry.name.into(),
|
title: entry.name.into(),
|
||||||
icon: ROption::RSome(entry.icon.into()),
|
|
||||||
description: entry.desc.map(|desc| desc.into()).into(),
|
description: entry.desc.map(|desc| desc.into()).into(),
|
||||||
|
use_pango: false,
|
||||||
|
icon: ROption::RSome(entry.icon.into()),
|
||||||
id: ROption::RSome(id),
|
id: ROption::RSome(id),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@@ -77,18 +77,21 @@ pub fn get_matches(input: RString, state: &mut State) -> RVec<Match> {
|
|||||||
Match {
|
Match {
|
||||||
title: "Open File".into(),
|
title: "Open File".into(),
|
||||||
description: ROption::RSome(path.clone().into()),
|
description: ROption::RSome(path.clone().into()),
|
||||||
|
use_pango: false,
|
||||||
id: ROption::RSome(IndexAction::Open as u64),
|
id: ROption::RSome(IndexAction::Open as u64),
|
||||||
icon: ROption::RSome("document-open".into()),
|
icon: ROption::RSome("document-open".into()),
|
||||||
},
|
},
|
||||||
Match {
|
Match {
|
||||||
title: "Copy Path".into(),
|
title: "Copy Path".into(),
|
||||||
description: ROption::RSome(path.into()),
|
description: ROption::RSome(path.into()),
|
||||||
|
use_pango: false,
|
||||||
id: ROption::RSome(IndexAction::CopyPath as u64),
|
id: ROption::RSome(IndexAction::CopyPath as u64),
|
||||||
icon: ROption::RSome("edit-copy".into()),
|
icon: ROption::RSome("edit-copy".into()),
|
||||||
},
|
},
|
||||||
Match {
|
Match {
|
||||||
title: "Back".into(),
|
title: "Back".into(),
|
||||||
description: ROption::RNone,
|
description: ROption::RNone,
|
||||||
|
use_pango: false,
|
||||||
id: ROption::RSome(IndexAction::Back as u64),
|
id: ROption::RSome(IndexAction::Back as u64),
|
||||||
icon: ROption::RSome("edit-undo".into()),
|
icon: ROption::RSome("edit-undo".into()),
|
||||||
},
|
},
|
||||||
@@ -119,16 +122,17 @@ pub fn get_matches(input: RString, state: &mut State) -> RVec<Match> {
|
|||||||
.file_name()
|
.file_name()
|
||||||
.map(|name| name.to_string_lossy().into())
|
.map(|name| name.to_string_lossy().into())
|
||||||
.unwrap_or("N/A".into()),
|
.unwrap_or("N/A".into()),
|
||||||
icon: ROption::RSome(if entry_index.directory {
|
|
||||||
"folder".into()
|
|
||||||
} else {
|
|
||||||
"text-x-generic".into()
|
|
||||||
}),
|
|
||||||
description: entry_index
|
description: entry_index
|
||||||
.path
|
.path
|
||||||
.parent()
|
.parent()
|
||||||
.map(|path| path.display().to_string().into())
|
.map(|path| path.display().to_string().into())
|
||||||
.into(),
|
.into(),
|
||||||
|
use_pango: false,
|
||||||
|
icon: ROption::RSome(if entry_index.directory {
|
||||||
|
"folder".into()
|
||||||
|
} else {
|
||||||
|
"text-x-generic".into()
|
||||||
|
}),
|
||||||
id: ROption::RSome(id as u64),
|
id: ROption::RSome(id as u64),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@@ -42,8 +42,9 @@ fn get_matches(input: RString, ctx: &mut rink_core::Context) -> RVec<Match> {
|
|||||||
match rink_core::one_line(ctx, &input) {
|
match rink_core::one_line(ctx, &input) {
|
||||||
Ok(result) => vec![Match {
|
Ok(result) => vec![Match {
|
||||||
title: result.into(),
|
title: result.into(),
|
||||||
icon: ROption::RNone,
|
|
||||||
description: ROption::RNone,
|
description: ROption::RNone,
|
||||||
|
use_pango: false,
|
||||||
|
icon: ROption::RNone,
|
||||||
id: ROption::RNone,
|
id: ROption::RNone,
|
||||||
}]
|
}]
|
||||||
.into(),
|
.into(),
|
||||||
|
@@ -51,6 +51,7 @@ fn get_matches(input: RString, config: &mut Config) -> RVec<Match> {
|
|||||||
})
|
})
|
||||||
.into(),
|
.into(),
|
||||||
),
|
),
|
||||||
|
use_pango: false,
|
||||||
icon: ROption::RNone,
|
icon: ROption::RNone,
|
||||||
id: ROption::RNone,
|
id: ROption::RNone,
|
||||||
}]
|
}]
|
||||||
|
@@ -75,6 +75,7 @@ fn get_matches(input: RString, symbols: &mut Vec<Symbol>) -> RVec<Match> {
|
|||||||
.map(|(symbol, _)| Match {
|
.map(|(symbol, _)| Match {
|
||||||
title: symbol.chr.into(),
|
title: symbol.chr.into(),
|
||||||
description: ROption::RSome(symbol.name.into()),
|
description: ROption::RSome(symbol.name.into()),
|
||||||
|
use_pango: false,
|
||||||
icon: ROption::RNone,
|
icon: ROption::RNone,
|
||||||
id: ROption::RNone,
|
id: ROption::RNone,
|
||||||
})
|
})
|
||||||
|
@@ -217,6 +217,7 @@ fn get_matches(input: RString, data: &mut RuntimeData) -> RVec<Match> {
|
|||||||
}).expect("Google API returned unknown language code!"),
|
}).expect("Google API returned unknown language code!"),
|
||||||
name)
|
name)
|
||||||
.into()),
|
.into()),
|
||||||
|
use_pango: false,
|
||||||
icon: ROption::RNone,
|
icon: ROption::RNone,
|
||||||
id: ROption::RNone
|
id: ROption::RNone
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user