Add settings reset defaults

This commit is contained in:
2026-05-09 01:14:15 -04:00
parent 89a8e05eeb
commit d193f5a400
13 changed files with 465 additions and 136 deletions
@@ -37,7 +37,7 @@ impl ElyShell {
.flex_col()
.gap_5()
.child(render_download_settings_header(snapshot))
.child(render_download_policy_summary(snapshot))
.child(render_download_policy_summary(snapshot, cx))
.child(render_download_policy_rows(&snapshot.active_download_policy, &options, cx)),
)
}
@@ -78,7 +78,10 @@ fn render_download_settings_header(snapshot: &BrowserSnapshot) -> AnyElement {
.into_any_element()
}
fn render_download_policy_summary(snapshot: &BrowserSnapshot) -> AnyElement {
fn render_download_policy_summary(
snapshot: &BrowserSnapshot,
cx: &mut Context<ElyShell>,
) -> AnyElement {
div()
.rounded_md()
.border_1()
@@ -121,10 +124,27 @@ fn render_download_policy_summary(snapshot: &BrowserSnapshot) -> AnyElement {
)
.child(
div()
.text_xs()
.font_semibold()
.text_color(rgb(colors::MUTED))
.child(format!("{} entries", snapshot.download_entries.len())),
.flex()
.items_center()
.gap_2()
.child(
div()
.text_xs()
.font_semibold()
.text_color(rgb(colors::MUTED))
.child(format!("{} entries", snapshot.download_entries.len())),
)
.child(
Button::new("reset-download-settings")
.ghost()
.xsmall()
.icon(IconName::Undo2)
.label("Reset")
.tooltip("Restore Download Defaults")
.on_click(cx.listener(|shell, _, _, cx| {
shell.reset_active_profile_download_settings(cx);
})),
),
)
.into_any_element()
}
@@ -24,7 +24,7 @@ impl ElyShell {
.flex_col()
.gap_5()
.child(render_general_header(snapshot))
.child(render_general_summary(snapshot.new_tab_destination))
.child(render_general_summary(snapshot.new_tab_destination, cx))
.child(render_new_tab_destinations(snapshot.new_tab_destination, cx)),
)
}
@@ -65,7 +65,10 @@ fn render_general_header(snapshot: &BrowserSnapshot) -> AnyElement {
.into_any_element()
}
fn render_general_summary(destination: NewTabDestination) -> AnyElement {
fn render_general_summary(
destination: NewTabDestination,
cx: &mut Context<ElyShell>,
) -> AnyElement {
div()
.rounded_md()
.border_1()
@@ -107,7 +110,28 @@ fn render_general_summary(destination: NewTabDestination) -> AnyElement {
),
)
.child(
div().text_xs().font_semibold().text_color(rgb(colors::SUCCESS)).child("Saved locally"),
div()
.flex()
.items_center()
.gap_2()
.child(
div()
.text_xs()
.font_semibold()
.text_color(rgb(colors::SUCCESS))
.child("Saved locally"),
)
.child(
Button::new("reset-general-settings")
.ghost()
.xsmall()
.icon(IconName::Undo2)
.label("Reset")
.tooltip("Restore General Defaults")
.on_click(cx.listener(|shell, _, _, cx| {
shell.reset_general_settings(cx);
})),
),
)
.into_any_element()
}
@@ -28,7 +28,7 @@ impl ElyShell {
.flex_col()
.gap_5()
.child(render_privacy_header(snapshot))
.child(render_history_summary(snapshot))
.child(render_history_summary(snapshot, cx))
.when(snapshot.active_profile_history_entry_count > 0, |this| {
this.child(render_history_clear_controls(confirming_clear, cx))
})
@@ -77,7 +77,7 @@ fn render_privacy_header(snapshot: &BrowserSnapshot) -> AnyElement {
.into_any_element()
}
fn render_history_summary(snapshot: &BrowserSnapshot) -> AnyElement {
fn render_history_summary(snapshot: &BrowserSnapshot, cx: &mut Context<ElyShell>) -> AnyElement {
div()
.rounded_md()
.border_1()
@@ -124,10 +124,23 @@ fn render_history_summary(snapshot: &BrowserSnapshot) -> AnyElement {
)
.child(
div()
.text_xs()
.font_semibold()
.text_color(rgb(colors::MUTED))
.child(format!("{} Profile entries", snapshot.active_profile_history_entry_count)),
.flex()
.items_center()
.gap_2()
.child(div().text_xs().font_semibold().text_color(rgb(colors::MUTED)).child(
format!("{} Profile entries", snapshot.active_profile_history_entry_count),
))
.child(
Button::new("reset-privacy-settings")
.ghost()
.xsmall()
.icon(IconName::Undo2)
.label("Reset")
.tooltip("Restore Privacy Defaults")
.on_click(cx.listener(|shell, _, _, cx| {
shell.reset_privacy_settings(cx);
})),
),
)
.into_any_element()
}
@@ -28,19 +28,21 @@ impl ElyShell {
.flex()
.flex_col()
.gap_5()
.child(render_profiles_header(snapshot))
.child(render_profiles_header(snapshot, cx))
.child(render_profile_list(snapshot, cx)),
)
}
}
fn render_profiles_header(snapshot: &BrowserSnapshot) -> AnyElement {
fn render_profiles_header(snapshot: &BrowserSnapshot, cx: &mut Context<ElyShell>) -> AnyElement {
div()
.flex()
.items_end()
.justify_between()
.gap_4()
.child(
div()
.min_w_0()
.flex()
.flex_col()
.gap_2()
@@ -54,9 +56,26 @@ fn render_profiles_header(snapshot: &BrowserSnapshot) -> AnyElement {
)
.child(
div()
.text_xs()
.text_color(rgb(colors::MUTED))
.child(format!("{} profiles", snapshot.profiles.len())),
.flex()
.items_center()
.gap_2()
.child(
div()
.text_xs()
.text_color(rgb(colors::MUTED))
.child(format!("{} profiles", snapshot.profiles.len())),
)
.child(
Button::new("reset-profile-sync-settings")
.ghost()
.xsmall()
.icon(IconName::Undo2)
.label("Reset Sync")
.tooltip("Restore Profile Sync Defaults")
.on_click(cx.listener(|shell, _, _, cx| {
shell.reset_profile_sync_settings(cx);
})),
),
)
.into_any_element()
}
@@ -24,7 +24,7 @@ impl ElyShell {
.flex_col()
.gap_5()
.child(render_search_header(snapshot))
.child(render_search_summary(snapshot.search_engine))
.child(render_search_summary(snapshot.search_engine, cx))
.child(render_search_engines(snapshot.search_engine, cx)),
)
}
@@ -65,7 +65,7 @@ fn render_search_header(snapshot: &BrowserSnapshot) -> AnyElement {
.into_any_element()
}
fn render_search_summary(search_engine: SearchEngine) -> AnyElement {
fn render_search_summary(search_engine: SearchEngine, cx: &mut Context<ElyShell>) -> AnyElement {
div()
.rounded_md()
.border_1()
@@ -107,7 +107,28 @@ fn render_search_summary(search_engine: SearchEngine) -> AnyElement {
),
)
.child(
div().text_xs().font_semibold().text_color(rgb(colors::SUCCESS)).child("Saved locally"),
div()
.flex()
.items_center()
.gap_2()
.child(
div()
.text_xs()
.font_semibold()
.text_color(rgb(colors::SUCCESS))
.child("Saved locally"),
)
.child(
Button::new("reset-search-settings")
.ghost()
.xsmall()
.icon(IconName::Undo2)
.label("Reset")
.tooltip("Restore Search Defaults")
.on_click(cx.listener(|shell, _, _, cx| {
shell.reset_search_settings(cx);
})),
),
)
.into_any_element()
}
@@ -64,13 +64,17 @@ impl ElyShell {
.flex()
.flex_col()
.gap_5()
.child(render_sidebar_tabs_header(snapshot, active_space))
.child(render_sidebar_tabs_header(snapshot, active_space, cx))
.child(render_sidebar_tabs_settings(snapshot, active_space, cx)),
)
}
}
fn render_sidebar_tabs_header(snapshot: &BrowserSnapshot, active_space: &Space) -> AnyElement {
fn render_sidebar_tabs_header(
snapshot: &BrowserSnapshot,
active_space: &Space,
cx: &mut Context<ElyShell>,
) -> AnyElement {
div()
.flex()
.items_end()
@@ -98,16 +102,33 @@ fn render_sidebar_tabs_header(snapshot: &BrowserSnapshot, active_space: &Space)
.flex()
.items_center()
.gap_2()
.text_xs()
.font_semibold()
.text_color(rgb(colors::MUTED))
.child(IconName::LayoutDashboard)
.child(format!(
"{} / {} / {}",
sidebar_width_label(active_space),
archive_policy_label(active_space.archive_policy()),
snapshot.favorite_limit.label()
)),
.child(
div()
.flex()
.items_center()
.gap_2()
.text_xs()
.font_semibold()
.text_color(rgb(colors::MUTED))
.child(IconName::LayoutDashboard)
.child(format!(
"{} / {} / {}",
sidebar_width_label(active_space),
archive_policy_label(active_space.archive_policy()),
snapshot.favorite_limit.label()
)),
)
.child(
Button::new("reset-sidebar-tabs-settings")
.ghost()
.xsmall()
.icon(IconName::Undo2)
.label("Reset")
.tooltip("Restore Sidebar & Tabs Defaults")
.on_click(cx.listener(|shell, _, _, cx| {
shell.reset_sidebar_tabs_settings(cx);
})),
),
)
.into_any_element()
}
@@ -8,7 +8,11 @@ use gpui::{
px, rgb,
};
use gpui::{StatefulInteractiveElement, prelude::FluentBuilder};
use gpui_component::{IconName, StyledExt, scroll::ScrollableElement};
use gpui_component::{
IconName, Sizable, StyledExt,
button::{Button, ButtonVariants},
scroll::ScrollableElement,
};
use super::{ElyShell, render_canvas_surface};
@@ -26,7 +30,7 @@ impl ElyShell {
.flex_col()
.gap_5()
.child(render_sync_header(snapshot))
.child(render_sync_queue(snapshot))
.child(render_sync_queue(snapshot, cx))
.child(render_sync_objects(snapshot, cx)),
)
}
@@ -64,7 +68,7 @@ fn render_sync_header(snapshot: &BrowserSnapshot) -> AnyElement {
.into_any_element()
}
fn render_sync_queue(snapshot: &BrowserSnapshot) -> AnyElement {
fn render_sync_queue(snapshot: &BrowserSnapshot, cx: &mut Context<ElyShell>) -> AnyElement {
div()
.rounded_md()
.border_1()
@@ -76,8 +80,33 @@ fn render_sync_queue(snapshot: &BrowserSnapshot) -> AnyElement {
.items_center()
.justify_between()
.gap_4()
.child(metric_block("Pending objects", snapshot.sync_status.pending_objects(), colors::INK))
.child(metric_block("Failed objects", snapshot.sync_status.failed_objects(), colors::ERROR))
.child(
div()
.flex()
.items_center()
.gap_4()
.child(metric_block(
"Pending objects",
snapshot.sync_status.pending_objects(),
colors::INK,
))
.child(metric_block(
"Failed objects",
snapshot.sync_status.failed_objects(),
colors::ERROR,
)),
)
.child(
Button::new("reset-sync-settings")
.ghost()
.xsmall()
.icon(IconName::Undo2)
.label("Reset")
.tooltip("Restore Sync Defaults")
.on_click(cx.listener(|shell, _, _, cx| {
shell.reset_sync_settings(cx);
})),
)
.into_any_element()
}
+2 -93
View File
@@ -10,6 +10,7 @@ mod notes;
mod plugins;
mod reading_list;
mod render;
mod settings_actions;
mod sidebar;
mod site_permissions;
mod space_files;
@@ -28,10 +29,7 @@ mod web_surface_state;
mod web_surface_view;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{
ArchivePolicy, DownloadPolicy, FavoriteLimit, HistoryRecordingPolicy, NewTabDestination,
ProfileId, ProfileSyncPolicy, SearchEngine, SpaceId, SyncObjectKind, SyncObjectPolicy, TabId,
};
use ely_domain::{ProfileId, SpaceId, TabId};
use gpui::{AppContext, Context, Entity, FocusHandle, Subscription, Window};
use gpui_component::input::{InputEvent, InputState};
@@ -268,95 +266,6 @@ impl ElyShell {
}
}
fn set_active_space_archive_policy(
&mut self,
archive_policy: ArchivePolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.set_active_space_archive_policy(archive_policy).is_ok()
{
cx.notify();
}
}
fn set_search_engine(&mut self, search_engine: SearchEngine, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.set_search_engine(search_engine);
cx.notify();
}
}
fn set_new_tab_destination(&mut self, destination: NewTabDestination, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.set_new_tab_destination(destination);
cx.notify();
}
}
fn set_history_recording_policy(
&mut self,
policy: HistoryRecordingPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state {
core.set_history_recording_policy(policy);
cx.notify();
}
}
fn set_active_profile_download_policy(
&mut self,
policy: DownloadPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.set_active_profile_download_policy(policy).is_ok()
{
cx.notify();
}
}
fn set_profile_sync_policy(
&mut self,
profile_id: &ProfileId,
sync_policy: ProfileSyncPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.set_profile_sync_policy(profile_id, sync_policy).is_ok()
{
cx.notify();
}
}
fn set_favorite_limit(&mut self, favorite_limit: FavoriteLimit, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.set_favorite_limit(favorite_limit);
cx.notify();
}
}
fn set_sync_object_policy(
&mut self,
kind: SyncObjectKind,
policy: SyncObjectPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state {
core.set_sync_object_policy(kind, policy);
cx.notify();
}
}
fn archive_idle_tabs_now(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.archive_idle_tabs(std::time::SystemTime::now()).is_ok()
{
cx.notify();
}
}
fn on_close_current_tab(
&mut self,
_: &CloseCurrentTab,
@@ -0,0 +1,161 @@
use ely_domain::{
ArchivePolicy, DownloadPolicy, FavoriteLimit, HistoryRecordingPolicy, NewTabDestination,
ProfileId, ProfileSyncPolicy, SearchEngine, SyncObjectKind, SyncObjectPolicy,
};
use gpui::Context;
use super::{ElyShell, ShellState};
impl ElyShell {
pub(super) fn set_active_space_archive_policy(
&mut self,
archive_policy: ArchivePolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.set_active_space_archive_policy(archive_policy).is_ok()
{
cx.notify();
}
}
pub(super) fn set_search_engine(
&mut self,
search_engine: SearchEngine,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state {
core.set_search_engine(search_engine);
cx.notify();
}
}
pub(super) fn reset_search_settings(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.reset_search_settings();
cx.notify();
}
}
pub(super) fn set_new_tab_destination(
&mut self,
destination: NewTabDestination,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state {
core.set_new_tab_destination(destination);
cx.notify();
}
}
pub(super) fn reset_general_settings(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.reset_general_settings();
cx.notify();
}
}
pub(super) fn set_history_recording_policy(
&mut self,
policy: HistoryRecordingPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state {
core.set_history_recording_policy(policy);
cx.notify();
}
}
pub(super) fn reset_privacy_settings(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.reset_privacy_settings();
cx.notify();
}
}
pub(super) fn set_active_profile_download_policy(
&mut self,
policy: DownloadPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.set_active_profile_download_policy(policy).is_ok()
{
cx.notify();
}
}
pub(super) fn reset_active_profile_download_settings(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.reset_active_profile_download_settings().is_ok()
{
cx.notify();
}
}
pub(super) fn set_profile_sync_policy(
&mut self,
profile_id: &ProfileId,
sync_policy: ProfileSyncPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.set_profile_sync_policy(profile_id, sync_policy).is_ok()
{
cx.notify();
}
}
pub(super) fn reset_profile_sync_settings(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.reset_profile_sync_settings();
cx.notify();
}
}
pub(super) fn set_favorite_limit(
&mut self,
favorite_limit: FavoriteLimit,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state {
core.set_favorite_limit(favorite_limit);
cx.notify();
}
}
pub(super) fn reset_sidebar_tabs_settings(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.reset_sidebar_tabs_settings().is_ok()
{
cx.notify();
}
}
pub(super) fn set_sync_object_policy(
&mut self,
kind: SyncObjectKind,
policy: SyncObjectPolicy,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state {
core.set_sync_object_policy(kind, policy);
cx.notify();
}
}
pub(super) fn reset_sync_settings(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.reset_sync_settings();
cx.notify();
}
}
pub(super) fn archive_idle_tabs_now(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.archive_idle_tabs(std::time::SystemTime::now()).is_ok()
{
cx.notify();
}
}
}