Code cleanup.
This commit is contained in:
parent
3233ed8ceb
commit
677c924323
2 changed files with 105 additions and 118 deletions
81
src/main.rs
81
src/main.rs
|
|
@ -445,7 +445,6 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_config(&mut self) -> Command<Message> {
|
fn save_config(&mut self) -> Command<Message> {
|
||||||
|
|
||||||
if let Some(ref config_handler) = self.config_handler {
|
if let Some(ref config_handler) = self.config_handler {
|
||||||
if let Err(err) = self.config.write_entry(config_handler) {
|
if let Err(err) = self.config.write_entry(config_handler) {
|
||||||
log::error!("failed to save config: {}", err);
|
log::error!("failed to save config: {}", err);
|
||||||
|
|
@ -1667,51 +1666,47 @@ impl Application for App {
|
||||||
self.set_context_title(context_page.title());
|
self.set_context_title(context_page.title());
|
||||||
|
|
||||||
// Execute commands for specific pages
|
// Execute commands for specific pages
|
||||||
if self.core.window.show_context {
|
if self.core.window.show_context && self.context_page == ContextPage::GitManagement
|
||||||
match self.context_page {
|
{
|
||||||
ContextPage::GitManagement => {
|
self.git_project_status = None;
|
||||||
self.git_project_status = None;
|
let projects = self.projects.clone();
|
||||||
let projects = self.projects.clone();
|
return Command::perform(
|
||||||
return Command::perform(
|
async move {
|
||||||
async move {
|
let mut project_status = Vec::new();
|
||||||
let mut project_status = Vec::new();
|
for (project_name, project_path) in projects.iter() {
|
||||||
for (project_name, project_path) in projects.iter() {
|
//TODO: send errors to UI
|
||||||
//TODO: send errors to UI
|
match GitRepository::new(project_path) {
|
||||||
match GitRepository::new(project_path) {
|
Ok(repo) => match repo.status().await {
|
||||||
Ok(repo) => match repo.status().await {
|
Ok(status) => {
|
||||||
Ok(status) => {
|
if !status.is_empty() {
|
||||||
if !status.is_empty() {
|
project_status.push((
|
||||||
project_status.push((
|
project_name.clone(),
|
||||||
project_name.clone(),
|
project_path.clone(),
|
||||||
project_path.clone(),
|
status,
|
||||||
status,
|
));
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
log::error!(
|
|
||||||
"failed to get status of {:?}: {}",
|
|
||||||
project_path,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
log::error!(
|
|
||||||
"failed to open repository {:?}: {}",
|
|
||||||
project_path,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!(
|
||||||
|
"failed to get status of {:?}: {}",
|
||||||
|
project_path,
|
||||||
|
err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
log::error!(
|
||||||
|
"failed to open repository {:?}: {}",
|
||||||
|
project_path,
|
||||||
|
err
|
||||||
|
);
|
||||||
}
|
}
|
||||||
message::app(Message::GitProjectStatus(project_status))
|
}
|
||||||
},
|
}
|
||||||
|x| x,
|
message::app(Message::GitProjectStatus(project_status))
|
||||||
);
|
},
|
||||||
}
|
|x| x,
|
||||||
_ => {}
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure focus of correct input
|
// Ensure focus of correct input
|
||||||
|
|
|
||||||
142
src/text_box.rs
142
src/text_box.rs
|
|
@ -608,17 +608,14 @@ where
|
||||||
Point::new(image_position.x + scrollbar_rect.x, image_position.y),
|
Point::new(image_position.x + scrollbar_rect.x, image_position.y),
|
||||||
Size::new(scrollbar_rect.width, layout.bounds().height),
|
Size::new(scrollbar_rect.width, layout.bounds().height),
|
||||||
),
|
),
|
||||||
border_radius: (scrollbar_rect.width as f32 / 2.0).into(),
|
border_radius: (scrollbar_rect.width / 2.0).into(),
|
||||||
border_width: 0.0,
|
border_width: 0.0,
|
||||||
border_color: Color::TRANSPARENT,
|
border_color: Color::TRANSPARENT,
|
||||||
},
|
},
|
||||||
Color::from(track_color),
|
Color::from(track_color),
|
||||||
);
|
);
|
||||||
|
|
||||||
let pressed = match &state.dragging {
|
let pressed = matches!(&state.dragging, Some(Dragging::Scrollbar { .. }));
|
||||||
Some(Dragging::Scrollbar { .. }) => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut hover = false;
|
let mut hover = false;
|
||||||
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
||||||
|
|
@ -668,7 +665,7 @@ where
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
Quad {
|
Quad {
|
||||||
bounds: scrollbar_draw,
|
bounds: scrollbar_draw,
|
||||||
border_radius: (scrollbar_draw.width as f32 / 2.0).into(),
|
border_radius: (scrollbar_draw.width / 2.0).into(),
|
||||||
border_width: 0.0,
|
border_width: 0.0,
|
||||||
border_color: Color::TRANSPARENT,
|
border_color: Color::TRANSPARENT,
|
||||||
},
|
},
|
||||||
|
|
@ -706,81 +703,76 @@ where
|
||||||
Event::Keyboard(KeyEvent::KeyPressed {
|
Event::Keyboard(KeyEvent::KeyPressed {
|
||||||
key_code,
|
key_code,
|
||||||
modifiers,
|
modifiers,
|
||||||
}) if state.is_focused => {
|
}) if state.is_focused => match key_code {
|
||||||
match key_code {
|
KeyCode::Left => {
|
||||||
KeyCode::Left => {
|
editor.action(Action::Motion(Motion::Left));
|
||||||
editor.action(Action::Motion(Motion::Left));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Right => {
|
||||||
KeyCode::Right => {
|
editor.action(Action::Motion(Motion::Right));
|
||||||
editor.action(Action::Motion(Motion::Right));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Up => {
|
||||||
KeyCode::Up => {
|
editor.action(Action::Motion(Motion::Up));
|
||||||
editor.action(Action::Motion(Motion::Up));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Down => {
|
||||||
KeyCode::Down => {
|
editor.action(Action::Motion(Motion::Down));
|
||||||
editor.action(Action::Motion(Motion::Down));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Home => {
|
||||||
KeyCode::Home => {
|
editor.action(Action::Motion(Motion::Home));
|
||||||
editor.action(Action::Motion(Motion::Home));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::End => {
|
||||||
KeyCode::End => {
|
editor.action(Action::Motion(Motion::End));
|
||||||
editor.action(Action::Motion(Motion::End));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::PageUp => {
|
||||||
KeyCode::PageUp => {
|
editor.action(Action::Motion(Motion::PageUp));
|
||||||
editor.action(Action::Motion(Motion::PageUp));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::PageDown => {
|
||||||
KeyCode::PageDown => {
|
editor.action(Action::Motion(Motion::PageDown));
|
||||||
editor.action(Action::Motion(Motion::PageDown));
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Escape => {
|
||||||
KeyCode::Escape => {
|
editor.action(Action::Escape);
|
||||||
editor.action(Action::Escape);
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Enter => {
|
||||||
KeyCode::Enter => {
|
editor.action(Action::Enter);
|
||||||
editor.action(Action::Enter);
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Backspace => {
|
||||||
KeyCode::Backspace => {
|
editor.action(Action::Backspace);
|
||||||
editor.action(Action::Backspace);
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Delete => {
|
||||||
KeyCode::Delete => {
|
editor.action(Action::Delete);
|
||||||
editor.action(Action::Delete);
|
status = Status::Captured;
|
||||||
status = Status::Captured;
|
}
|
||||||
}
|
KeyCode::Tab => {
|
||||||
KeyCode::Tab => {
|
if modifiers.shift() {
|
||||||
if modifiers.shift() {
|
editor.action(Action::Unindent);
|
||||||
editor.action(Action::Unindent);
|
} else {
|
||||||
} else {
|
editor.action(Action::Indent);
|
||||||
editor.action(Action::Indent);
|
|
||||||
}
|
|
||||||
status = Status::Captured;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
status = Status::Captured;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
||||||
state.modifiers = modifiers;
|
state.modifiers = modifiers;
|
||||||
}
|
}
|
||||||
Event::Keyboard(KeyEvent::CharacterReceived(character)) if state.is_focused => {
|
Event::Keyboard(KeyEvent::CharacterReceived(character)) if state.is_focused => {
|
||||||
// Only parse keys when Super, Ctrl, and Alt are not pressed
|
// Only parse keys when Super, Ctrl, and Alt are not pressed
|
||||||
if !state.modifiers.logo()
|
if !state.modifiers.logo() && !state.modifiers.control() && !state.modifiers.alt() {
|
||||||
&& !state.modifiers.control()
|
if !character.is_control() {
|
||||||
&& !state.modifiers.alt()
|
editor.action(Action::Insert(character));
|
||||||
{
|
|
||||||
if !character.is_control() {
|
|
||||||
editor.action(Action::Insert(character));
|
|
||||||
}
|
|
||||||
status = Status::Captured;
|
|
||||||
}
|
}
|
||||||
|
status = Status::Captured;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Event::Mouse(MouseEvent::ButtonPressed(button)) => {
|
Event::Mouse(MouseEvent::ButtonPressed(button)) => {
|
||||||
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue