-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
1,106 additions
and
1,289 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use super::{ | ||
namespace_context::{NamespaceContext, DEFAULT_NAMESPACE}, | ||
CommandsContext, FieldMap, | ||
}; | ||
use crate::Clipboard; | ||
use anyhow::Result; | ||
use cl_core::{resource::FileService, Command, CommandVec, Commands, Preferences}; | ||
|
||
pub struct Application { | ||
pub commands: CommandsContext, | ||
pub namespaces: NamespaceContext, | ||
preferences: Preferences, | ||
clipboard: Option<Clipboard>, | ||
} | ||
|
||
impl Application { | ||
pub fn init( | ||
commands: Commands, | ||
file_service: FileService, | ||
preferences: Preferences, | ||
) -> Application { | ||
let clipboard = Clipboard::new().ok(); | ||
let namespaces = commands | ||
.to_list() | ||
.iter() | ||
.map(|c| c.namespace.to_owned()) | ||
.collect::<Vec<_>>(); | ||
|
||
Application { | ||
commands: CommandsContext::new(commands, file_service), | ||
namespaces: NamespaceContext::new(namespaces), | ||
preferences, | ||
clipboard, | ||
} | ||
} | ||
|
||
pub fn copy_to_clipboard<T>(&mut self, content: T) -> Result<()> | ||
where | ||
T: Into<String>, | ||
{ | ||
if let Some(ref mut clipboard) = &mut self.clipboard { | ||
clipboard.set_content(content.into())?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Reloads the command context, filtering all commands and reseting the select command idx | ||
pub fn reload(&mut self) { | ||
self.commands.filter_commands(DEFAULT_NAMESPACE, ""); | ||
self.commands.reset_selected_command_idx(); | ||
} | ||
|
||
// other | ||
pub fn should_highlight(&mut self) -> bool { | ||
self.preferences.highlight() | ||
} | ||
|
||
/// Filters the command list using the querybox input as query | ||
pub fn filter_commands(&mut self, query_string: &str) -> CommandVec { | ||
let current_namespace = self.namespaces.current(); | ||
self.commands | ||
.filter_commands(¤t_namespace, query_string) | ||
} | ||
} | ||
|
||
// Callback | ||
impl Application { | ||
/// Executes the callback command | ||
pub fn execute_callback(&self) -> Result<()> { | ||
self.commands.execute(self.preferences.quiet_mode()) | ||
} | ||
} | ||
|
||
impl Application { | ||
pub fn add_command(&mut self, command_value_map: FieldMap) -> Result<()> { | ||
let commands = self.commands.add(&command_value_map.into())?; | ||
self.namespaces.update(&commands.keys().collect::<Vec<_>>()); | ||
Ok(()) | ||
} | ||
|
||
pub fn edit_command( | ||
&mut self, | ||
edited_command: FieldMap, | ||
current_command: &Command, | ||
) -> Result<()> { | ||
let commands = self | ||
.commands | ||
.edit(&edited_command.into(), current_command)?; | ||
self.namespaces.update(&commands.keys().collect::<Vec<_>>()); | ||
Ok(()) | ||
} | ||
|
||
pub fn remove_command(&mut self, command: &Command) -> Result<()> { | ||
let commands = self.commands.remove(command)?; | ||
self.namespaces.update(&commands.keys().collect::<Vec<_>>()); | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.