Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions crates/core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,9 @@ pub struct AppSettings {
pub portable_remember_master_key: bool,
#[serde(default)]
pub home_connection_layout: HomeConnectionLayout,
/// 首页是否显示「最近连接」分组
#[serde(default = "default_true")]
pub home_show_recent_connections: bool,
/// 连接列表排序方式
#[serde(default)]
pub connection_sort_order: ConnectionSortOrder,
Expand Down Expand Up @@ -1524,6 +1527,7 @@ impl Default for AppSettings {
require_master_key_on_startup: false,
portable_remember_master_key: false,
home_connection_layout: HomeConnectionLayout::default(),
home_show_recent_connections: true,
connection_sort_order: ConnectionSortOrder::default(),
connection_sidebar_expanded: true,
connection_sidebar_tree_state: ConnectionSidebarTreeState::default(),
Expand Down Expand Up @@ -1893,6 +1897,27 @@ mod tests {
assert!(!AppSettings::default().sync_enabled);
}

#[test]
fn home_show_recent_connections_defaults_on_and_round_trips() {
// 默认开启(与历史行为一致)。
assert!(AppSettings::default().home_show_recent_connections);

// 关闭后序列化往返保持关闭。
let settings = AppSettings {
home_show_recent_connections: false,
..AppSettings::default()
};
let json = serde_json::to_string(&settings).expect("serialize app settings");
assert!(json.contains(r#""home_show_recent_connections":false"#));
let restored: AppSettings = serde_json::from_str(&json).expect("roundtrip");
assert!(!restored.home_show_recent_connections);

// 旧配置文件缺省该字段时,反序列化回退到默认开启(向后兼容)。
let legacy_settings: AppSettings =
serde_json::from_value(serde_json::json!({})).expect("empty deserialize");
assert!(legacy_settings.home_show_recent_connections);
}

#[test]
fn sql_format_settings_default_preserves_keyword_case() {
let settings = AppSettings::default().sql_format;
Expand Down
8 changes: 8 additions & 0 deletions main/locales/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,14 @@ Settings:
en: Connections
zh-CN: 连接显示
zh-HK: 連線顯示
show_recent:
en: Show Recent Connections
zh-CN: 显示最近连接分组
zh-HK: 顯示最近連線分組
show_recent_desc:
en: Show the recent connections group on Home. Turn off to keep only grouped connections.
zh-CN: 在首页显示「最近连接」分组,关闭后仅显示各分组内的连接
zh-HK: 在首頁顯示「最近連線」分組,關閉後僅顯示各分組內的連線
home_layout:
en: Home Connection Layout
zh-CN: 主页连接布局
Expand Down
7 changes: 6 additions & 1 deletion main/src/home_tab/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ impl HomePage {
cx,
));
}
} else if !AppSettings::global(cx).home_show_recent_connections {
// 设置关闭「最近连接」分组后,导航布局与卡片布局保持一致:不渲染该分组。
if matching.is_empty() {
body = body.child(self.render_empty_home(cx));
}
} else if recent.is_empty() {
body = body.child(self.render_empty_home(cx));
} else {
Expand Down Expand Up @@ -251,7 +256,7 @@ impl HomePage {
if visible_count == 0 {
body = body.child(self.render_empty_home(cx));
}
if !recent.is_empty() {
if !recent.is_empty() && AppSettings::global(cx).home_show_recent_connections {
body = body.child(self.render_recent_group(recent, selected, layout, card_width, cx));
}
for (id, title, connections) in groups {
Expand Down
27 changes: 27 additions & 0 deletions main/src/home_tab/tests/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,33 @@ fn recent_section_does_not_participate_in_search() {
assert!(navigation.contains("if !query.is_empty()"));
}

#[test]
fn recent_group_respects_home_show_recent_connections_setting() {
let settings = include_str!("../../../../crates/core/src/settings.rs");
let content = include_str!("../content.rs");
let display_group = include_str!("../../settings/connection_display_settings.rs");

// 设置字段默认开启,旧配置缺省字段时回退开启(向后兼容)。
assert!(settings.contains("home_show_recent_connections"));
assert!(settings.contains(r#"#[serde(default = "default_true")]"#));

// 分组内容区与导航主页两处最近连接渲染都被设置短路。
assert!(
content.contains(
"if !recent.is_empty() && AppSettings::global(cx).home_show_recent_connections"
)
);
let navigation = content
.split("fn render_navigation_home_content")
.nth(1)
.expect("navigation home content exists");
assert!(navigation.contains("home_show_recent_connections"));

// 设置页提供「连接显示」分组的开关,修改后立即持久化。
assert!(display_group.contains("home_show_recent_connections"));
assert!(display_group.contains("update_and_save"));
}

#[test]
fn persistent_sidebar_supports_connection_group_drag_and_drop() {
let rows = include_str!("../../persistent_connection_sidebar/rows.rs");
Expand Down
2 changes: 2 additions & 0 deletions main/src/setting_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::license::{get_license_service, is_feature_enabled, offline_license_pu
use crate::settings::agent_settings::agent_setting_group;
use crate::settings::appearance::render as render_appearance_settings;
use crate::settings::database_settings::database_setting_group;
use crate::settings::connection_display_settings::connection_display_setting_group;
use crate::settings::llm_providers_view::LlmProvidersView;
use crate::settings::local_terminal_settings::local_terminal_setting_group;
use crate::settings::mcp_settings::mcp_setting_group;
Expand Down Expand Up @@ -939,6 +940,7 @@ impl SettingsPanel {
.description(t!("Settings.General.Log.file_path_desc").to_string()),
),
remote_file_editor_setting_group(&default_settings.remote_file_editor, cx),
connection_display_setting_group(),
SettingGroup::new()
.title(t!("Settings.General.Proxy.group_title"))
.item(
Expand Down
26 changes: 26 additions & 0 deletions main/src/settings/connection_display_settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use gpui::App;
use gpui_component::setting::{SettingField, SettingGroup, SettingItem};
use one_core::settings::AppSettings;
use rust_i18n::t;

/// 连接显示设置分组:首页是否显示「最近连接」分组。
pub fn connection_display_setting_group() -> SettingGroup {
let default_settings = AppSettings::default();
SettingGroup::new()
.title(t!("Settings.General.ConnectionDisplay.group_title"))
.item(
SettingItem::new(
t!("Settings.General.ConnectionDisplay.show_recent"),
SettingField::switch(
|cx: &App| AppSettings::global(cx).home_show_recent_connections,
|val: bool, cx: &mut App| {
AppSettings::update_and_save(cx, |settings| {
settings.home_show_recent_connections = val;
});
},
)
.default_value(default_settings.home_show_recent_connections),
)
.description(t!("Settings.General.ConnectionDisplay.show_recent_desc").to_string()),
)
}
1 change: 1 addition & 0 deletions main/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod agent_settings;
pub mod appearance;
mod appearance_import;
mod appearance_state;
pub mod connection_display_settings;
pub mod database_settings;
pub mod llm_providers_view;
pub mod local_terminal_settings;
Expand Down
Loading