feat: finish exec runner

This commit is contained in:
yyc12345 committed 2026-05-09 20:07:08 +08:00
1 parent 6804b96078
commit a6322bff51
3 files changed
+123 -9

No files matched your search

+54 -5
View File
@@ -246,6 +246,7 @@ pub struct Program {
behaviors: Vec<Rc<ProgramBehavior>>,
ext_keys: Vec<ProgramProgIdExtKey>,
ext_keys_map: HashMap<String, usize>,
}
impl TryFrom<Schema> for Program {
@@ -386,7 +387,7 @@ impl Program {
.map(|behavior| Self::resolve_index(&behavior, &behaviors, &behaviors_index_map))
.transpose()?;
// We build ProgIdKey and ExtKey list at the same time
// We build ext keys
let mut ext_keys: Vec<ProgramProgIdExtKey> = Vec::with_capacity(schema.exts.len());
for (key, value) in &schema.exts {
// Build ProgId first.
@@ -403,7 +404,7 @@ impl Program {
let ext = concept::Ext::new(key.as_str())?;
let ext_key = lowlevel::ExtKey::new(ext);
// Create program Ext key struct
// Create program ProgId Ext key struct
let progid_ext_key = ProgramProgIdExtKey {
ext_key,
progid_key,
@@ -415,6 +416,12 @@ impl Program {
// Add them into list
ext_keys.push(progid_ext_key);
}
// The build ext keys map
let ext_keys_map = ext_keys
.iter()
.enumerate()
.map(|(i, ext)| (ext.ext_key.inner().inner().to_string(), i))
.collect();
// Everything is okey
Ok(Self {
@@ -429,10 +436,39 @@ impl Program {
icons,
behaviors,
ext_keys,
ext_keys_map,
})
}
}
impl Program {
pub fn resolve_name(&self) -> Result<String, ProgramError> {
todo!()
}
pub fn resolve_icon(&self) -> Result<concept::IconRc, ProgramError> {
todo!()
}
pub fn get_ext_count(&self) -> usize {
self.ext_keys.len()
}
pub fn get_ext(&self, index: usize) -> Result<&concept::Ext, ProgramError> {
match self.ext_keys.get(index) {
Some(program_key) => {
let ext_key = &program_key.ext_key;
Ok(ext_key.inner())
}
None => Err(ProgramError::BadIndex),
}
}
pub fn find_ext(&self, body: &str) -> Option<usize> {
self.ext_keys_map.get(body).copied()
}
}
impl Program {
/// Register this application.
///
@@ -577,6 +613,11 @@ impl Program {
Some(program_key) => {
let ext_key = &mut program_key.ext_key;
let progid_key = &program_key.progid_key;
debug_println!(
"Linking ProgId \"{0}\" to extension \"{1}\"subkey...",
progid_key.inner().to_string(),
ext_key.inner().to_string()
);
// Before setting it, we must make sure this extension is existing
ext_key.ensure(scope)?;
@@ -591,6 +632,10 @@ impl Program {
match self.ext_keys.get_mut(index) {
Some(program_key) => {
let ext_key = &mut program_key.ext_key;
debug_println!(
"Unlinking for extension \"{0}\"subkey...",
ext_key.inner().to_string()
);
// Before setting it, we must make sure this extension is existing
ext_key.ensure(scope)?;
@@ -609,6 +654,10 @@ impl Program {
match self.ext_keys.get(index) {
Some(program_key) => {
let ext_key = &program_key.ext_key;
debug_println!(
"Querying for extension \"{0}\"subkey...",
ext_key.inner().to_string()
);
// If there is no such extension key, return None about this extension.
if !ext_key.is_exist(view)? {
@@ -656,7 +705,7 @@ impl Program {
// region: Program Exposed Structs
/// Exposed struct representing the default associated program of specific file extension.
///
///
/// The data including the diaplay name and icon.
pub struct ProgramExtStatus {
name: String,
@@ -669,7 +718,7 @@ impl ProgramExtStatus {
}
/// Get the display name of this program.
///
///
/// The program provided display name will be used firstly.
/// If this program has no display name, the stringified ProgId will be used instead.
pub fn get_name(&self) -> &str {
@@ -677,7 +726,7 @@ impl ProgramExtStatus {
}
/// Get the icon of this program.
///
///
/// Due to the icon is optional, if there is no icon, return None.
pub fn get_icon(&self) -> Option<&concept::IconRc> {
self.icon.as_ref()