win_ctx/lib.rs
1//! ## Features
2//!
3//! - Create and edit context menu entries and sub-entries
4//! - Toggle the pre-Windows 11 context menu
5//!
6//! ## Basic examples
7//!
8//! The following code creates a top-level context menu entry that appears on
9//! right-clicked folders and opens the target folder in the terminal.
10//!
11//! ```no_run
12//! use win_ctx::*;
13//!
14//! CtxEntry::new_with_options(
15//! "Open in terminal",
16//! &ActivationType::Folder,
17//! &EntryOptions {
18//! command: Some("cmd /s /k pushd \"%V\""),
19//! icon: Some("C:\\Windows\\System32\\cmd.exe"),
20//! position: None,
21//! separator: None,
22//! extended: false,
23//! }
24//! )?;
25//! ```
26//!
27//! The following code creates a context menu entry with child entries that each
28//! open the target folder in the selected program.
29//!
30//! To reduce line count, the more basic non-options functions can be used,
31//! and individual values are then set on the resulting entries.
32//!
33//! ```no_run
34//! use win_ctx::{CtxEntry, ActivationType};
35//!
36//! let mut parent = CtxEntry::new("Open directory in", &ActivationType::Background)?;
37//! parent.set_extended(true);
38//!
39//! let mut child_1 = parent.new_child("Terminal")?;
40//! child_1.set_command(Some("cmd /s /k pushd \"%V\""))?;
41//! child_1.set_icon(Some("C:\\Windows\\System32\\cmd.exe"))?;
42//!
43//! let mut child_2 = parent.new_child("Powershell")?;
44//! child_2.set_command(Some("powershell -noexit -command Set-Location -literalPath '%V'"))?;
45//! child_2.set_icon(Some("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"))?;
46//! ```
47//!
48//! ## Errors
49//!
50//! It's possible that an entry's underlying registry key goes out of sync,
51//! so most `CtxEntry` functions verify this and return a [`std::io::Result`].
52//!
53//! Errors will have an [`ErrorKind`] of either:
54//! - `PermissionDenied` for insufficient privileges,
55//! - `InvalidValue` for invalid entry renames, or
56//! - `NotFound` for operations on missing keys and values.
57//!
58//! [`ErrorKind`]: https://doc.rust-lang.org/std/io/enum.ErrorKind.html
59//! [`std::io::Result`]: https://doc.rust-lang.org/std/io/type.Result.html
60
61pub use entry::*;
62pub use utils::toggle_classic_menu;
63
64mod entry;
65mod path;
66mod utils;