task_ui: Move status indicator into tab bar of terminal panel (#10846)
I'm not a huge fan of this change (& I expect the placement to change). The plan is to have the button in a toolbar of terminal panel, but I'm not sure if occupying a whole line of vertical space for a single button is worth it; I suppose we might want to put more of tasks ui inside of that toolbar. Release Notes: - Removed task status indicator and added "Spawn task" action to terminal panel context menu.
This commit is contained in:
parent
bcbf2f2fd3
commit
2ee257a562
9 changed files with 46 additions and 120 deletions
|
@ -22,7 +22,6 @@ serde.workspace = true
|
|||
settings.workspace = true
|
||||
ui.workspace = true
|
||||
util.workspace = true
|
||||
terminal.workspace = true
|
||||
workspace.workspace = true
|
||||
language.workspace = true
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use anyhow::Context;
|
|||
use editor::Editor;
|
||||
use gpui::{AppContext, ViewContext, WindowContext};
|
||||
use language::{BasicContextProvider, ContextProvider, Language};
|
||||
use modal::{Spawn, TasksModal};
|
||||
use modal::TasksModal;
|
||||
use project::{Location, TaskSourceKind, WorktreeId};
|
||||
use task::{ResolvedTask, TaskContext, TaskTemplate, TaskVariables};
|
||||
use util::ResultExt;
|
||||
|
@ -16,9 +16,8 @@ use workspace::Workspace;
|
|||
|
||||
mod modal;
|
||||
mod settings;
|
||||
mod status_indicator;
|
||||
|
||||
pub use status_indicator::TaskStatusIndicator;
|
||||
pub use modal::Spawn;
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
settings::TaskSettings::register(cx);
|
||||
|
|
|
@ -31,10 +31,11 @@ pub struct Spawn {
|
|||
}
|
||||
|
||||
impl Spawn {
|
||||
pub(crate) fn modal() -> Self {
|
||||
pub fn modal() -> Self {
|
||||
Self { task_name: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// Rerun last task
|
||||
#[derive(PartialEq, Clone, Deserialize, Default)]
|
||||
pub struct Rerun {
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
use gpui::{IntoElement, Render, View, WeakView};
|
||||
use settings::Settings;
|
||||
use ui::{
|
||||
div, ButtonCommon, Clickable, Color, FluentBuilder, IconButton, IconName, Tooltip,
|
||||
VisualContext, WindowContext,
|
||||
};
|
||||
use workspace::{item::ItemHandle, StatusItemView, Workspace};
|
||||
|
||||
use crate::{modal::Spawn, settings::TaskSettings};
|
||||
|
||||
enum TaskStatus {
|
||||
Failed,
|
||||
Running,
|
||||
Succeeded,
|
||||
}
|
||||
|
||||
/// A status bar icon that surfaces the status of running tasks.
|
||||
/// It has a different color depending on the state of running tasks:
|
||||
/// - red if any open task tab failed
|
||||
/// - else, yellow if any open task tab is still running
|
||||
/// - else, green if there tasks tabs open, and they have all succeeded
|
||||
/// - else, no indicator if there are no open task tabs
|
||||
pub struct TaskStatusIndicator {
|
||||
workspace: WeakView<Workspace>,
|
||||
}
|
||||
|
||||
impl TaskStatusIndicator {
|
||||
pub fn new(workspace: WeakView<Workspace>, cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(|_| Self { workspace })
|
||||
}
|
||||
fn current_status(&self, cx: &mut WindowContext) -> Option<TaskStatus> {
|
||||
self.workspace
|
||||
.update(cx, |this, cx| {
|
||||
let mut status = None;
|
||||
let project = this.project().read(cx);
|
||||
|
||||
for handle in project.local_terminal_handles() {
|
||||
let Some(handle) = handle.upgrade() else {
|
||||
continue;
|
||||
};
|
||||
let handle = handle.read(cx);
|
||||
let task_state = handle.task();
|
||||
if let Some(state) = task_state {
|
||||
match state.status {
|
||||
terminal::TaskStatus::Running => {
|
||||
let _ = status.insert(TaskStatus::Running);
|
||||
}
|
||||
terminal::TaskStatus::Completed { success } => {
|
||||
if !success {
|
||||
let _ = status.insert(TaskStatus::Failed);
|
||||
return status;
|
||||
}
|
||||
status.get_or_insert(TaskStatus::Succeeded);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
status
|
||||
})
|
||||
.ok()
|
||||
.flatten()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for TaskStatusIndicator {
|
||||
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
||||
if !TaskSettings::get_global(cx).show_status_indicator {
|
||||
return div().into_any_element();
|
||||
}
|
||||
let current_status = self.current_status(cx);
|
||||
let color = current_status.map(|status| match status {
|
||||
TaskStatus::Failed => Color::Error,
|
||||
TaskStatus::Running => Color::Warning,
|
||||
TaskStatus::Succeeded => Color::Success,
|
||||
});
|
||||
IconButton::new("tasks-activity-indicator", IconName::Play)
|
||||
.when_some(color, |this, color| this.icon_color(color))
|
||||
.on_click(cx.listener(|this, _, cx| {
|
||||
this.workspace
|
||||
.update(cx, |this, cx| {
|
||||
crate::spawn_task_or_modal(this, &Spawn::modal(), cx)
|
||||
})
|
||||
.ok();
|
||||
}))
|
||||
.tooltip(|cx| Tooltip::for_action("Spawn tasks", &Spawn { task_name: None }, cx))
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
impl StatusItemView for TaskStatusIndicator {
|
||||
fn set_active_pane_item(
|
||||
&mut self,
|
||||
_: Option<&dyn ItemHandle>,
|
||||
_: &mut ui::prelude::ViewContext<Self>,
|
||||
) {
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue