-
-
Notifications
You must be signed in to change notification settings - Fork 613
Indicate to the user that a stash save is in progress #1702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use crate::{ | ||
error::Result, | ||
sync::{self, CommitId, RepoPath}, | ||
AsyncGitNotification, | ||
}; | ||
use crossbeam_channel::Sender; | ||
use std::{ | ||
sync::atomic::{AtomicUsize, Ordering}, | ||
sync::Arc, | ||
}; | ||
|
||
/// | ||
pub struct AsyncStash { | ||
pending: Arc<AtomicUsize>, | ||
sender: Sender<AsyncGitNotification>, | ||
repo: RepoPath, | ||
} | ||
|
||
impl AsyncStash { | ||
/// | ||
pub fn new( | ||
repo: RepoPath, | ||
sender: Sender<AsyncGitNotification>, | ||
) -> Self { | ||
Self { | ||
repo, | ||
sender, | ||
pending: Arc::new(AtomicUsize::new(0)), | ||
} | ||
} | ||
|
||
/// | ||
pub fn stash_save( | ||
&mut self, | ||
message: Option<&str>, | ||
include_untracked: bool, | ||
keep_index: bool, | ||
) -> Result<Option<CommitId>> { | ||
if self.is_pending() { | ||
log::trace!("request blocked, still pending"); | ||
return Ok(None); | ||
} | ||
|
||
let repo = self.repo.clone(); | ||
let sender = self.sender.clone(); | ||
let pending = self.pending.clone(); | ||
let message = message.map(ToOwned::to_owned); | ||
|
||
self.pending.fetch_add(1, Ordering::Relaxed); | ||
|
||
rayon_core::spawn(move || { | ||
let res = sync::stash::stash_save( | ||
&repo, | ||
message.as_deref(), | ||
include_untracked, | ||
keep_index, | ||
); | ||
|
||
pending.fetch_sub(1, Ordering::Relaxed); | ||
|
||
sender | ||
.send(AsyncGitNotification::Stash) | ||
.expect("error sending stash notification"); | ||
|
||
if let Err(e) = res { | ||
log::error!("AsyncStash error: {}", e); | ||
} | ||
}); | ||
|
||
Ok(None) | ||
} | ||
|
||
/// | ||
pub fn is_pending(&self) -> bool { | ||
self.pending.load(Ordering::Relaxed) > 0 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//! sync git api for stash | ||
|
||
use super::{CommitId, RepoPath}; | ||
use crate::{ | ||
error::{Error, Result}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,11 +31,13 @@ pub enum InputType { | |
} | ||
|
||
/// primarily a subcomponet for user input of text (used in `CommitComponent`) | ||
#[allow(clippy::struct_excessive_bools)] | ||
pub struct TextInputComponent { | ||
title: String, | ||
default_msg: String, | ||
msg: String, | ||
visible: bool, | ||
disabled: bool, | ||
show_char_count: bool, | ||
theme: SharedTheme, | ||
key_config: SharedKeyConfig, | ||
|
@@ -57,6 +59,7 @@ impl TextInputComponent { | |
Self { | ||
msg: String::new(), | ||
visible: false, | ||
disabled: false, | ||
theme, | ||
key_config, | ||
show_char_count, | ||
|
@@ -222,6 +225,16 @@ impl TextInputComponent { | |
self.default_msg = v; | ||
} | ||
|
||
/// | ||
pub fn disable(&mut self) { | ||
self.disabled = true; | ||
} | ||
|
||
/// | ||
pub fn enable(&mut self) { | ||
self.disabled = false; | ||
} | ||
|
||
fn get_draw_text(&self) -> Text { | ||
let style = self.theme.text(true, false); | ||
|
||
|
@@ -419,7 +432,7 @@ impl Component for TextInputComponent { | |
} | ||
|
||
fn event(&mut self, ev: &Event) -> Result<EventState> { | ||
if self.visible { | ||
if self.visible && !self.disabled { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is pretty invasive. why do we need that? the text input for the stashing can just close IMO and does not need to learn a new state of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without disabled, it's possible to type in the field while the operation is pending. I suppose we could close the model and continue the operation in the background. In this case, is there a pattern for handling stashing errors if they occur? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that's what I think we should do, what we do in other cases already. just close the text input popup regularly and then the new popup will block any other input and visualise that the stashing is in progress There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for error handling use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I'll make that change soon 👍🏻 |
||
if let Event::Key(e) = ev { | ||
if key_match(e, self.key_config.keys.exit_popup) { | ||
self.hide(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.