Add space default profile control
This commit is contained in:
@@ -62,6 +62,8 @@ fn render_profiles_header(snapshot: &BrowserSnapshot) -> AnyElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_profile_list(snapshot: &BrowserSnapshot, cx: &mut Context<ElyShell>) -> AnyElement {
|
fn render_profile_list(snapshot: &BrowserSnapshot, cx: &mut Context<ElyShell>) -> AnyElement {
|
||||||
|
let active_space = snapshot.spaces.iter().find(|space| space.id() == &snapshot.active_space_id);
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.min_h_0()
|
.min_h_0()
|
||||||
@@ -71,7 +73,13 @@ fn render_profile_list(snapshot: &BrowserSnapshot, cx: &mut Context<ElyShell>) -
|
|||||||
.border_t_1()
|
.border_t_1()
|
||||||
.border_color(rgb(colors::HAIRLINE))
|
.border_color(rgb(colors::HAIRLINE))
|
||||||
.children(snapshot.profiles.iter().enumerate().map(|(index, profile)| {
|
.children(snapshot.profiles.iter().enumerate().map(|(index, profile)| {
|
||||||
render_profile_row(index, profile, profile.id() == &snapshot.active_profile_id, cx)
|
render_profile_row(
|
||||||
|
index,
|
||||||
|
profile,
|
||||||
|
profile.id() == &snapshot.active_profile_id,
|
||||||
|
active_space.is_some_and(|space| space.default_profile_id() == profile.id()),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
}))
|
}))
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
@@ -80,9 +88,11 @@ fn render_profile_row(
|
|||||||
index: usize,
|
index: usize,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
active: bool,
|
active: bool,
|
||||||
|
default_for_active_space: bool,
|
||||||
cx: &mut Context<ElyShell>,
|
cx: &mut Context<ElyShell>,
|
||||||
) -> AnyElement {
|
) -> AnyElement {
|
||||||
let profile_id = profile.id().clone();
|
let profile_id = profile.id().clone();
|
||||||
|
let default_profile_id = profile.id().clone();
|
||||||
let sync_profile_id = profile.id().clone();
|
let sync_profile_id = profile.id().clone();
|
||||||
let sync_policy = profile.sync_policy();
|
let sync_policy = profile.sync_policy();
|
||||||
|
|
||||||
@@ -130,6 +140,12 @@ fn render_profile_row(
|
|||||||
.flex()
|
.flex()
|
||||||
.items_center()
|
.items_center()
|
||||||
.gap_3()
|
.gap_3()
|
||||||
|
.child(render_profile_default_action(
|
||||||
|
index,
|
||||||
|
default_profile_id,
|
||||||
|
default_for_active_space,
|
||||||
|
cx,
|
||||||
|
))
|
||||||
.child(render_profile_sync_action(index, sync_profile_id, sync_policy, cx))
|
.child(render_profile_sync_action(index, sync_profile_id, sync_policy, cx))
|
||||||
.child(render_profile_action(index, profile_id, active, cx)),
|
.child(render_profile_action(index, profile_id, active, cx)),
|
||||||
)
|
)
|
||||||
@@ -147,6 +163,33 @@ fn profile_color_swatch(color_hex: u32) -> AnyElement {
|
|||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_profile_default_action(
|
||||||
|
index: usize,
|
||||||
|
profile_id: ProfileId,
|
||||||
|
default_for_active_space: bool,
|
||||||
|
cx: &mut Context<ElyShell>,
|
||||||
|
) -> AnyElement {
|
||||||
|
if default_for_active_space {
|
||||||
|
return div()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(rgb(colors::SUCCESS))
|
||||||
|
.child("Default")
|
||||||
|
.into_any_element();
|
||||||
|
}
|
||||||
|
|
||||||
|
Button::new(("default-profile", index))
|
||||||
|
.ghost()
|
||||||
|
.xsmall()
|
||||||
|
.icon(IconName::CircleCheck)
|
||||||
|
.label("Set Default")
|
||||||
|
.tooltip("Use for New Tabs in Active Space")
|
||||||
|
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||||
|
shell.set_active_space_default_profile(&profile_id, cx);
|
||||||
|
}))
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
fn render_profile_action(
|
fn render_profile_action(
|
||||||
index: usize,
|
index: usize,
|
||||||
profile_id: ProfileId,
|
profile_id: ProfileId,
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
use ely_domain::SpaceId;
|
use ely_domain::{ProfileId, SpaceId};
|
||||||
use gpui::{Context, Window};
|
use gpui::{Context, Window};
|
||||||
|
|
||||||
use super::{ElyShell, ShellState};
|
use super::{ElyShell, ShellState};
|
||||||
use crate::{SelectNextSpace, SelectPreviousSpace};
|
use crate::{SelectNextSpace, SelectPreviousSpace};
|
||||||
|
|
||||||
impl ElyShell {
|
impl ElyShell {
|
||||||
|
pub(super) fn set_active_space_default_profile(
|
||||||
|
&mut self,
|
||||||
|
profile_id: &ProfileId,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
if let ShellState::Ready(core) = &mut self.state
|
||||||
|
&& core.set_active_space_default_profile(profile_id).is_ok()
|
||||||
|
{
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn move_space_up(&mut self, space_id: &SpaceId, cx: &mut Context<Self>) {
|
pub(super) fn move_space_up(&mut self, space_id: &SpaceId, cx: &mut Context<Self>) {
|
||||||
if let ShellState::Ready(core) = &mut self.state
|
if let ShellState::Ready(core) = &mut self.state
|
||||||
&& core.move_space_up(space_id).is_ok_and(|moved| moved)
|
&& core.move_space_up(space_id).is_ok_and(|moved| moved)
|
||||||
|
|||||||
@@ -300,6 +300,14 @@ impl BrowserCore {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_active_space_default_profile(
|
||||||
|
&mut self,
|
||||||
|
profile_id: &ProfileId,
|
||||||
|
) -> Result<(), CoreError> {
|
||||||
|
let active_space_id = self.active_space_id.clone();
|
||||||
|
self.set_space_default_profile(&active_space_id, profile_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_space_sidebar_width(
|
pub fn set_space_sidebar_width(
|
||||||
&mut self,
|
&mut self,
|
||||||
space_id: &SpaceId,
|
space_id: &SpaceId,
|
||||||
|
|||||||
@@ -233,6 +233,22 @@ fn space_default_profile_updates_with_profile_validation() -> Result<(), Box<dyn
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn active_space_default_profile_updates_current_space() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
let work_space_id = core.snapshot()?.active_space_id;
|
||||||
|
let research_profile_id = core.create_profile("Research", 0x9fc9a2, ProfileKind::Standard)?;
|
||||||
|
|
||||||
|
core.set_active_space_default_profile(&research_profile_id)?;
|
||||||
|
let snapshot = core.snapshot()?;
|
||||||
|
let Some(work_space) = snapshot.spaces.iter().find(|space| space.id() == &work_space_id) else {
|
||||||
|
return Err("missing work space".into());
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(work_space.default_profile_id(), &research_profile_id);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn space_settings_refresh_updated_at() -> Result<(), Box<dyn Error>> {
|
fn space_settings_refresh_updated_at() -> Result<(), Box<dyn Error>> {
|
||||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user