Struct CtxEntry

Source
pub struct CtxEntry {
    pub name_path: Vec<String>,
    pub entry_type: ActivationType,
}

Fields§

§name_path: Vec<String>

The path to the entry as a list of entry names

§entry_type: ActivationType

Implementations§

Source§

impl CtxEntry

Source

pub fn get<N: AsRef<str>>( name_path: &[N], entry_type: &ActivationType, ) -> Option<CtxEntry>

Gets an existing entry at the given name path. The last name corresponds to the returned entry.

§Examples
let name_path = &["Root entry", "Sub entry", "Sub sub entry"];
let entry = CtxEntry::get(name_path, &ActivationType::Folder)?;
Source

pub fn get_all_of_type(entry_type: &ActivationType) -> HashMap<String, CtxEntry>

Gets all root entries with the given entry type.

§Examples
let entries = CtxEntry::get_all_of_type(&ActivationType::Folder);
Source

pub fn new(name: &str, entry_type: &ActivationType) -> Result<CtxEntry>

Creates a new top-level entry with the given entry type. The resulting entry will appear in the context menu but will do nothing until modified.

§Examples
let mut entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
Source

pub fn new_with_options( name: &str, entry_type: &ActivationType, opts: &EntryOptions, ) -> Result<CtxEntry>

Creates a new top-level entry under the given entry_type.

§Examples
let entry = CtxEntry::new(
    "Open in terminal",
    &ActivationType::Folder,
    &EntryOptions {
        // This command opens the target directory in cmd.
        command: Some("cmd /s /k pushd \"%V\""),
        icon: Some("C:\\Windows\\System32\\cmd.exe"),
        position: None,
        extended: false,
    }
)?;
Source

pub fn delete(self) -> Result<()>

Deletes the entry and any children.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
entry.delete()?;
Source

pub fn name(&self) -> Result<String>

Gets the entry’s current name.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let name = entry.name()?;
Source

pub fn rename(&mut self, new_name: &str) -> Result<()>

Renames the entry.

§Examples
let mut entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
entry.rename("Renamed entry")?;
Source

pub fn command(&self) -> Result<Option<String>>

Gets the entry’s command, if any.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let command = entry.command()?;
Source

pub fn set_command(&mut self, command: Option<&str>) -> Result<()>

Sets the entry’s command.

§Examples
let mut entry = CtxEntry::new("Basic entry", ActivationType::Folder)?;
// This command opens the target directory in Powershell.
entry.set_command(Some("powershell.exe -noexit -command Set-Location -literalPath '%V'"))?;
Source

pub fn icon(&self) -> Result<Option<String>>

Gets the entry’s icon, if any.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let icon = entry.icon()?;
Source

pub fn set_icon(&mut self, icon: Option<&str>) -> Result<()>

Sets the entry’s icon.

§Examples
let mut entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
entry.set_icon(Some("C:\\Windows\\System32\\control.exe"))?;
Source

pub fn position(&self) -> Result<Option<MenuPosition>>

Gets the entry’s position, if any.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let position = entry.position()?;
Source

pub fn set_position(&mut self, position: Option<MenuPosition>) -> Result<()>

Sets the entry’s menu position. By default, new root entries are positioned at the top. Does not affect child entries.

§Examples
let mut entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
entry.set_position(Some(MenuPosition::Bottom))?;
Source

pub fn extended(&self) -> Result<bool>

Gets whether the entry appears with Shift+RClick.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let is_extended = entry.extended()?;
Source

pub fn set_extended(&mut self, extended: bool) -> Result<()>

Sets whether the entry should only appear with Shift+RClick.

§Examples
let mut entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
entry.set_extended(true)?;
Source

pub fn separator(&self) -> Result<Option<Separator>>

Gets the entry’s separator(s), if any.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let separator = entry.separator()?;
Source

pub fn set_separator(&mut self, separator: Option<Separator>) -> Result<()>

Sets the entry’s separator(s).

§Examples
let mut entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
entry.set_separator(Some(Separator::After))?;
Source

pub fn parent(&self) -> Option<CtxEntry>

Gets the entry’s parent, if any.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let child = entry.new_child("Basic child entry")?;
let parent = child.parent()?;
assert_eq!(entry.name().unwrap(), parent.name().unwrap());
Source

pub fn child(&self, name: &str) -> Result<Option<CtxEntry>>

Gets one of the entry’s children, if any.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let created_child = entry.new_child("Basic child entry")?;
let retrieved_child = entry.child("Basic child entry")?;
assert_eq!(created_child.name().unwrap(), retrieved_child.name().unwrap());
Source

pub fn children(&self) -> Result<Vec<CtxEntry>>

Gets the entry’s children, if any.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let child_1 = entry.new_child("Child 1")?;
let child_2 = entry.new_child("Child 2")?;
let children = entry.children()?;
Source

pub fn new_child(&self, name: &str) -> Result<CtxEntry>

Creates a new child entry under the entry. The resulting entry will appear in the context menu but will do nothing until modified.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let child = entry.new_child("Basic child entry")?;
Source

pub fn new_child_with_options( &self, name: &str, opts: &EntryOptions, ) -> Result<CtxEntry>

Creates a new child entry under the entry.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let child = entry.new_child_with_options(
    "Basic child entry",
    &EntryOptions {
        // This command opens the target directory in cmd.
        command: Some("cmd /s /k pushd \"%V\""),
        icon: Some("C:\\Windows\\System32\\cmd.exe"),
        position: None,
        extended: false,
    }
)?;
Source

pub fn path(&self) -> String

Gets the full path to the entry’s registry key.

§Examples
let entry = CtxEntry::new("Basic entry", ActivationType::Background)?;
let path = entry.path();

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.