feat: out-of-box experience #2

Merged
reya merged 64 commits from feat/ui into master 2026-08-25 13:23:08 +00:00
23 changed files with 7267 additions and 67 deletions
Showing only changes of commit 6a3e9604c9 - Show all commits
Generated
+228 -58
View File
@@ -675,6 +675,15 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbd3e1070bbdf4cd88a75264e18e8a26f7cb5c6949eadf0ceb85fb159cf08f8"
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]]
name = "bindgen"
version = "0.71.1"
@@ -721,15 +730,30 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d21f40d350a700f6aa107e45fb26448cf489d34794b2ba4522181dc9f1173af6"
[[package]]
name = "bit-set"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
dependencies = [
"bit-vec 0.8.0",
]
[[package]]
name = "bit-set"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd"
dependencies = [
"bit-vec",
"bit-vec 0.9.1",
]
[[package]]
name = "bit-vec"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
[[package]]
name = "bit-vec"
version = "0.9.1"
@@ -1244,7 +1268,7 @@ dependencies = [
[[package]]
name = "collections"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"gpui_util",
"indexmap",
@@ -1339,6 +1363,15 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "convert_case"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "affbf0190ed2caf063e3def54ff444b449371d55c58e513a95ab98eca50adb49"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "core-foundation"
version = "0.9.4"
@@ -1690,7 +1723,7 @@ version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"
dependencies = [
"convert_case",
"convert_case 0.10.0",
"proc-macro2",
"quote",
"rustc_version",
@@ -1701,7 +1734,7 @@ dependencies = [
[[package]]
name = "derive_refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"proc-macro2",
"quote",
@@ -1790,6 +1823,19 @@ dependencies = [
"libloading",
]
[[package]]
name = "dock"
version = "1.0.0"
dependencies = [
"anyhow",
"gpui",
"gpui-component",
"itertools 0.13.0",
"serde",
"serde_json",
"smallvec",
]
[[package]]
name = "document-features"
version = "0.2.12"
@@ -2037,6 +2083,17 @@ dependencies = [
"zune-inflate",
]
[[package]]
name = "fancy-regex"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "998b056554fbe42e03ae0e152895cd1a7e1002aec800fdc6635d20270260c46f"
dependencies = [
"bit-set 0.8.0",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "faster-hex"
version = "0.10.0"
@@ -3436,12 +3493,13 @@ dependencies = [
[[package]]
name = "gpui"
version = "0.2.2"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"accesskit",
"anyhow",
"async-channel",
"async-task",
"backtrace",
"bindgen",
"bitflags 2.13.1",
"block",
@@ -3466,6 +3524,7 @@ dependencies = [
"gpui_macros",
"gpui_shared_string",
"gpui_util",
"hdrhistogram",
"heapless 0.9.3",
"http_client",
"image",
@@ -3485,6 +3544,7 @@ dependencies = [
"pollster 0.4.0",
"postage",
"profiling",
"proptest",
"rand 0.9.5",
"raw-window-handle",
"refineable",
@@ -3520,7 +3580,7 @@ dependencies = [
[[package]]
name = "gpui-base"
version = "0.5.2"
source = "git+https://github.com/longbridge/gpui-component#da4f93696dc2b2b4d91bcc42412b9053a3d24de8"
source = "git+https://github.com/longbridge/gpui-component#9e3a29dcbdebc318632bf68203f26c33e9f0e902"
dependencies = [
"aho-corasick",
"anyhow",
@@ -3528,6 +3588,7 @@ dependencies = [
"chrono",
"gpui",
"gpui_macros",
"gpui_platform",
"instant",
"lsp-types",
"objc2 0.6.4",
@@ -3541,6 +3602,7 @@ dependencies = [
"serde_json",
"smallvec",
"smol",
"syntect",
"tracing",
"unicode-segmentation",
"web-time",
@@ -3550,7 +3612,7 @@ dependencies = [
[[package]]
name = "gpui-component"
version = "0.5.2"
source = "git+https://github.com/longbridge/gpui-component#da4f93696dc2b2b4d91bcc42412b9053a3d24de8"
source = "git+https://github.com/longbridge/gpui-component#9e3a29dcbdebc318632bf68203f26c33e9f0e902"
dependencies = [
"anyhow",
"chrono",
@@ -3630,7 +3692,7 @@ dependencies = [
[[package]]
name = "gpui-component-assets"
version = "0.5.1"
source = "git+https://github.com/longbridge/gpui-component#da4f93696dc2b2b4d91bcc42412b9053a3d24de8"
source = "git+https://github.com/longbridge/gpui-component#9e3a29dcbdebc318632bf68203f26c33e9f0e902"
dependencies = [
"anyhow",
"gpui",
@@ -3644,7 +3706,7 @@ dependencies = [
[[package]]
name = "gpui-component-macros"
version = "0.5.1"
source = "git+https://github.com/longbridge/gpui-component#da4f93696dc2b2b4d91bcc42412b9053a3d24de8"
source = "git+https://github.com/longbridge/gpui-component#9e3a29dcbdebc318632bf68203f26c33e9f0e902"
dependencies = [
"proc-macro2",
"quote",
@@ -3654,7 +3716,7 @@ dependencies = [
[[package]]
name = "gpui_apple"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"block",
@@ -3677,7 +3739,7 @@ dependencies = [
[[package]]
name = "gpui_linux"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"accesskit",
"accesskit_unix",
@@ -3729,7 +3791,7 @@ dependencies = [
[[package]]
name = "gpui_macos"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"accesskit",
"accesskit_macos",
@@ -3775,7 +3837,7 @@ dependencies = [
[[package]]
name = "gpui_macros"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"heck 0.5.0",
"proc-macro2",
@@ -3786,7 +3848,7 @@ dependencies = [
[[package]]
name = "gpui_platform"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"console_error_panic_hook",
"gpui",
@@ -3799,7 +3861,7 @@ dependencies = [
[[package]]
name = "gpui_shared_string"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"schemars",
"serde",
@@ -3809,7 +3871,7 @@ dependencies = [
[[package]]
name = "gpui_util"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"log",
@@ -3819,7 +3881,7 @@ dependencies = [
[[package]]
name = "gpui_web"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"console_error_panic_hook",
@@ -3831,6 +3893,7 @@ dependencies = [
"log",
"parking_lot",
"raw-window-handle",
"scheduler",
"uuid",
"wasm-bindgen",
"wasm-bindgen-futures",
@@ -3842,7 +3905,7 @@ dependencies = [
[[package]]
name = "gpui_wgpu"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"bytemuck",
@@ -3872,7 +3935,7 @@ dependencies = [
[[package]]
name = "gpui_windows"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"accesskit",
"accesskit_windows",
@@ -3909,9 +3972,9 @@ dependencies = [
[[package]]
name = "h2"
version = "0.4.15"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155"
checksum = "a9f37a958b41b3b19ee2707c06439c0e9e547e847223eb791ecb0cb821c65e27"
dependencies = [
"atomic-waker",
"bytes",
@@ -3997,6 +4060,20 @@ dependencies = [
"foldhash 0.2.0",
]
[[package]]
name = "hdrhistogram"
version = "7.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f49d1053f4708f0af3cf9fc5bffc7e68a914a3c45becb231c80068c9c3f78bea"
dependencies = [
"base64",
"byteorder",
"crossbeam-channel",
"flate2",
"nom 8.0.0",
"num-traits",
]
[[package]]
name = "heapless"
version = "0.8.0"
@@ -4185,7 +4262,7 @@ dependencies = [
[[package]]
name = "http_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"async-compression",
@@ -4205,7 +4282,7 @@ dependencies = [
[[package]]
name = "http_client_tls"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"rustls",
"rustls-platform-verifier 0.5.3",
@@ -4460,7 +4537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
dependencies = [
"byteorder-lite",
"quick-error",
"quick-error 2.0.1",
]
[[package]]
@@ -5181,7 +5258,7 @@ dependencies = [
[[package]]
name = "media"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"bindgen",
@@ -5293,7 +5370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2bf919621e7975acb27d881bae2fb993e0d45c8e0446e85e6272971e00dc8df"
dependencies = [
"arrayvec",
"bit-set",
"bit-set 0.9.1",
"bitflags 2.13.1",
"cfg-if",
"cfg_aliases",
@@ -5397,7 +5474,7 @@ dependencies = [
[[package]]
name = "nostr"
version = "0.45.2"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"aes",
"base64",
@@ -5423,7 +5500,7 @@ dependencies = [
[[package]]
name = "nostr-connect"
version = "0.45.1"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"async-utility",
"futures-core",
@@ -5437,7 +5514,7 @@ dependencies = [
[[package]]
name = "nostr-database"
version = "0.45.1"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"nostr",
"opaquerr",
@@ -5446,7 +5523,7 @@ dependencies = [
[[package]]
name = "nostr-gossip"
version = "0.45.0"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"nostr",
"opaquerr",
@@ -5455,7 +5532,7 @@ dependencies = [
[[package]]
name = "nostr-gossip-memory"
version = "0.45.0"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"indexmap",
"lru",
@@ -5467,7 +5544,7 @@ dependencies = [
[[package]]
name = "nostr-lmdb"
version = "0.45.1"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"async-utility",
"flatbuffers",
@@ -5482,7 +5559,7 @@ dependencies = [
[[package]]
name = "nostr-memory"
version = "0.45.1"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"btreecap",
"nostr",
@@ -5493,7 +5570,7 @@ dependencies = [
[[package]]
name = "nostr-sdk"
version = "0.45.1"
source = "git+https://github.com/rust-nostr/nostr#0a10756496173b7c97d7aa611fb8663931d1eaad"
source = "git+https://github.com/rust-nostr/nostr#6969fdb5d229e15daf8839488f204014bc686058"
dependencies = [
"async-utility",
"async-wsocket",
@@ -6229,7 +6306,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "perf"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"collections",
"serde",
@@ -6576,6 +6653,36 @@ dependencies = [
"syn 2.0.119",
]
[[package]]
name = "proptest"
version = "1.10.0"
source = "git+https://github.com/proptest-rs/proptest?rev=3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b#3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b"
dependencies = [
"bit-set 0.8.0",
"bit-vec 0.8.0",
"bitflags 2.13.1",
"num-traits",
"proptest-macro",
"rand 0.9.5",
"rand_chacha 0.9.0",
"rand_xorshift",
"regex-syntax",
"rusty-fork",
"tempfile",
"unarray",
]
[[package]]
name = "proptest-macro"
version = "0.5.0"
source = "git+https://github.com/proptest-rs/proptest?rev=3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b#3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b"
dependencies = [
"convert_case 0.11.0",
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "psm"
version = "0.1.32"
@@ -6623,6 +6730,12 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quick-error"
version = "2.0.1"
@@ -6660,9 +6773,9 @@ dependencies = [
[[package]]
name = "quinn-proto"
version = "0.11.16"
version = "0.11.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560"
checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83"
dependencies = [
"aws-lc-rs",
"bytes",
@@ -6801,6 +6914,15 @@ dependencies = [
"rand_core 0.10.1",
]
[[package]]
name = "rand_xorshift"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
dependencies = [
"rand_core 0.9.5",
]
[[package]]
name = "range-alloc"
version = "0.1.5"
@@ -6857,7 +6979,7 @@ dependencies = [
"avif-serialize",
"imgref",
"loop9",
"quick-error",
"quick-error 2.0.1",
"rav1e",
"rayon",
"rgb",
@@ -6981,7 +7103,7 @@ dependencies = [
[[package]]
name = "refineable"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"derive_refineable",
]
@@ -7064,7 +7186,7 @@ dependencies = [
[[package]]
name = "reqwest_client"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"bytes",
@@ -7410,6 +7532,18 @@ version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
[[package]]
name = "rusty-fork"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2"
dependencies = [
"fnv",
"quick-error 1.2.3",
"tempfile",
"wait-timeout",
]
[[package]]
name = "rustybuzz"
version = "0.20.1"
@@ -7465,7 +7599,7 @@ dependencies = [
[[package]]
name = "scheduler"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"async-task",
"backtrace",
@@ -7474,6 +7608,7 @@ dependencies = [
"futures",
"parking_lot",
"rand 0.9.5",
"wasm_thread",
"web-time",
]
@@ -7849,6 +7984,7 @@ name = "signed"
version = "1.0.0"
dependencies = [
"assets",
"dock",
"gpui",
"gpui-component",
"gpui_linux",
@@ -8189,7 +8325,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "sum_tree"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"heapless 0.9.3",
"log",
@@ -8365,6 +8501,24 @@ dependencies = [
"syn 2.0.119",
]
[[package]]
name = "syntect"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "656b45c05d95a5704399aeef6bd0ddec7b2b3531b7c9e900abbf7c4d2190c925"
dependencies = [
"bincode",
"fancy-regex",
"flate2",
"fnv",
"once_cell",
"regex-syntax",
"serde",
"serde_derive",
"thiserror 2.0.20",
"walkdir",
]
[[package]]
name = "sys-locale"
version = "0.3.2"
@@ -8535,7 +8689,7 @@ dependencies = [
"fax",
"flate2",
"half",
"quick-error",
"quick-error 2.0.1",
"weezl",
"zune-jpeg 0.5.15",
]
@@ -9341,6 +9495,12 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "unarray"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
[[package]]
name = "unicase"
version = "2.9.0"
@@ -9538,7 +9698,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "util_macros"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"perf",
"quote",
@@ -9644,6 +9804,15 @@ dependencies = [
"libc",
]
[[package]]
name = "wait-timeout"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
dependencies = [
"libc",
]
[[package]]
name = "waker-fn"
version = "1.2.0"
@@ -9976,8 +10145,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f519832254e56965a9940c4af57dcb75f702b6f6fa4a0b172f685395843a4d7"
dependencies = [
"arrayvec",
"bit-set",
"bit-vec",
"bit-set 0.9.1",
"bit-vec 0.9.1",
"bitflags 2.13.1",
"bytemuck",
"cfg_aliases",
@@ -10048,7 +10217,7 @@ dependencies = [
"android_system_properties",
"arrayvec",
"ash",
"bit-set",
"bit-set 0.9.1",
"bitflags 2.13.1",
"block2 0.6.2",
"bytemuck",
@@ -10806,6 +10975,7 @@ version = "1.0.0"
dependencies = [
"anyhow",
"assets",
"dock",
"futures",
"gix",
"gpui",
@@ -11307,9 +11477,9 @@ dependencies = [
[[package]]
name = "zerovec-derive"
version = "0.11.4"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47402523226a02bfe5230160dc3ccc089aa6f6f19e7fcbb4e6f824bbb1b4aa62"
checksum = "9f212a141d820099d57ffafb9569be9617a6f27d3dc881fbee8fb56642f917a9"
dependencies = [
"proc-macro2",
"quote",
@@ -11325,7 +11495,7 @@ checksum = "34b31d188d9d685a4f9c7b46d6e36631b07058d2cfe190267adce54dc230bf12"
[[package]]
name = "zlog"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"anyhow",
"chrono",
@@ -11342,7 +11512,7 @@ checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
[[package]]
name = "ztracing"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
dependencies = [
"tracing",
"tracing-subscriber",
@@ -11353,7 +11523,7 @@ dependencies = [
[[package]]
name = "ztracing_macro"
version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#8968bf78084f30809aa2ce1574a3be68ed02a513"
source = "git+https://github.com/zed-industries/zed#4c7244790a075e862eeb4e5ccc12d6c8f5da6f7e"
[[package]]
name = "zune-core"
@@ -11396,9 +11566,9 @@ dependencies = [
[[package]]
name = "zvariant"
version = "5.14.0"
version = "5.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e28c25bd8bb8da5a1f3e7065d0c156b9ee9a7973adf78b0e35eaefdf3b1b5c"
checksum = "c1d34c27cc6cdd1f458427519dd6b8612f7b7e3f7b9a0b2355d041dda9869147"
dependencies = [
"endi",
"enumflags2",
@@ -11412,9 +11582,9 @@ dependencies = [
[[package]]
name = "zvariant_derive"
version = "5.14.0"
version = "5.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d496a145685283b67e232bd9e47377f6b60ad9d51e3601b23867f77c42477f96"
checksum = "864155e69b4352db0c7f374917bf45d1e0c8d17659c8b3dbf9795f3673f8c497"
dependencies = [
"proc-macro-crate",
"proc-macro2",
@@ -11425,9 +11595,9 @@ dependencies = [
[[package]]
name = "zvariant_utils"
version = "4.1.0"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b84ebb462416c27cdb97f2e7f5f0ccc844da1fe2ecc7121e1b690b41318bf42"
checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3"
dependencies = [
"proc-macro2",
"quote",
+2
View File
@@ -22,6 +22,8 @@ reqwest_client = { git = "https://github.com/zed-industries/zed" }
# code preview (fenced code blocks are highlighted with tree-sitter).
gpui-component = { git = "https://github.com/longbridge/gpui-component", features = ["tree-sitter-languages"] }
dock = { path = "crates/dock" }
nostr = { git = "https://github.com/rust-nostr/nostr", features = ["nip59", "nip49", "nip44", "os-rng"] }
nostr-lmdb = { git = "https://github.com/rust-nostr/nostr" }
nostr-memory = { git = "https://github.com/rust-nostr/nostr" }
+19
View File
@@ -0,0 +1,19 @@
[package]
name = "dock"
description = "Dock (DockArea / Dock / Panel) components vendored from gpui-component."
version.workspace = true
edition.workspace = true
publish.workspace = true
[dependencies]
gpui.workspace = true
gpui-component.workspace = true
anyhow.workspace = true
serde.workspace = true
serde_json.workspace = true
itertools = "0.13.0"
smallvec = "1"
[dev-dependencies]
gpui = { workspace = true, features = ["test-support"] }
+509
View File
@@ -0,0 +1,509 @@
//! Dock is a fixed container that places at left, bottom, right of the Windows.
use std::ops::Deref;
use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
App, AppContext, Axis, Context, Element, Empty, Entity, IntoElement, MouseMoveEvent,
MouseUpEvent, ParentElement as _, Pixels, Point, Render, Style, StyleRefinement, Styled as _,
WeakEntity, Window, div, px,
};
use gpui_component::{Side, StyledExt};
use serde::{Deserialize, Serialize};
use super::{DockArea, DockEvent, DockItem, PanelView, TabPanel};
use crate::resize_handle::{PANEL_MIN_SIZE, resize_handle};
#[derive(Clone)]
struct ResizePanel;
impl Render for ResizePanel {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
Empty
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum DockPlacement {
#[serde(rename = "center")]
Center,
#[serde(rename = "left")]
Left,
#[serde(rename = "bottom")]
Bottom,
#[serde(rename = "right")]
Right,
}
impl DockPlacement {
fn axis(&self) -> Axis {
match self {
Self::Left | Self::Right => Axis::Horizontal,
Self::Bottom => Axis::Vertical,
Self::Center => unreachable!(),
}
}
pub fn is_left(&self) -> bool {
matches!(self, Self::Left)
}
pub fn is_bottom(&self) -> bool {
matches!(self, Self::Bottom)
}
pub fn is_right(&self) -> bool {
matches!(self, Self::Right)
}
}
/// The Dock is a fixed container that places at left, bottom, right of the Windows.
///
/// This is unlike Panel, it can't be move or add any other panel.
pub struct Dock {
pub(super) placement: DockPlacement,
dock_area: WeakEntity<DockArea>,
pub(crate) panel: DockItem,
/// The size is means the width or height of the Dock, if the placement is left or right, the size is width, otherwise the size is height.
pub(super) size: Pixels,
pub(super) open: bool,
/// Whether the Dock is collapsible, default: true
pub(super) collapsible: bool,
// Runtime state
/// Whether the Dock is resizing
resizing: bool,
}
impl Dock {
pub(crate) fn new(
dock_area: WeakEntity<DockArea>,
placement: DockPlacement,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let panel = cx.new(|cx| {
let mut tab = TabPanel::new(None, dock_area.clone(), window, cx);
tab.closable = false;
tab
});
let panel = DockItem::Tabs {
size: None,
items: Vec::new(),
active_ix: 0,
view: panel.clone(),
};
Self::subscribe_panel_events(dock_area.clone(), &panel, window, cx);
Self {
placement,
dock_area,
panel,
open: true,
collapsible: true,
size: px(200.0),
resizing: false,
}
}
pub fn left(
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
Self::new(dock_area, DockPlacement::Left, window, cx)
}
pub fn bottom(
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
Self::new(dock_area, DockPlacement::Bottom, window, cx)
}
pub fn right(
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
Self::new(dock_area, DockPlacement::Right, window, cx)
}
/// Update the Dock to be collapsible or not.
///
/// And if the Dock is not collapsible, it will be open.
pub fn set_collapsible(&mut self, collapsible: bool, _: &mut Window, cx: &mut Context<Self>) {
self.collapsible = collapsible;
if !collapsible {
self.open = true
}
cx.notify();
}
pub(super) fn from_state(
dock_area: WeakEntity<DockArea>,
placement: DockPlacement,
size: Pixels,
panel: DockItem,
open: bool,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
Self::subscribe_panel_events(dock_area.clone(), &panel, window, cx);
if !open {
match panel.clone() {
DockItem::Tabs { view, .. } => {
view.update(cx, |panel, cx| {
panel.set_collapsed(true, window, cx);
});
}
DockItem::Split { items, .. } => {
for item in items {
item.set_collapsed(true, window, cx);
}
}
_ => {}
}
}
Self {
placement,
dock_area,
panel,
open,
size,
collapsible: true,
resizing: false,
}
}
fn subscribe_panel_events(
dock_area: WeakEntity<DockArea>,
panel: &DockItem,
window: &mut Window,
cx: &mut Context<Self>,
) {
match panel {
DockItem::Tabs { view, .. } => {
window.defer(cx, {
let view = view.clone();
move |window, cx| {
_ = dock_area.update(cx, |this, cx| {
this.subscribe_panel(&view, window, cx);
});
}
});
}
DockItem::Split { items, view, .. } => {
for item in items {
Self::subscribe_panel_events(dock_area.clone(), item, window, cx);
}
window.defer(cx, {
let view = view.clone();
move |window, cx| {
_ = dock_area.update(cx, |this, cx| {
this.subscribe_panel(&view, window, cx);
});
}
});
}
DockItem::Tiles { view, .. } => {
window.defer(cx, {
let view = view.clone();
move |window, cx| {
_ = dock_area.update(cx, |this, cx| {
this.subscribe_panel(&view, window, cx);
});
}
});
}
DockItem::Panel { .. } => {
// Not supported
}
}
}
pub fn set_panel(&mut self, panel: DockItem, _: &mut Window, cx: &mut Context<Self>) {
self.panel = panel;
cx.notify();
}
pub fn panel(&self) -> &DockItem {
&self.panel
}
pub fn is_open(&self) -> bool {
self.open
}
pub fn toggle_open(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.set_open(!self.open, window, cx);
}
/// Returns the size of the Dock, the size is means the width or height of
/// the Dock, if the placement is left or right, the size is width,
/// otherwise the size is height.
pub fn size(&self) -> Pixels {
self.size
}
/// Set the size of the Dock.
pub fn set_size(&mut self, size: Pixels, _: &mut Window, cx: &mut Context<Self>) {
self.size = size.max(PANEL_MIN_SIZE);
cx.notify();
}
/// Set the open state of the Dock.
pub fn set_open(&mut self, open: bool, window: &mut Window, cx: &mut Context<Self>) {
self.open = open;
let item = self.panel.clone();
cx.defer_in(window, move |_, window, cx| {
item.set_collapsed(!open, window, cx);
});
cx.notify();
}
/// Add item to the Dock.
pub fn add_panel(
&mut self,
panel: Arc<dyn PanelView>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.panel
.add_panel(panel, &self.dock_area, None, window, cx);
cx.notify();
}
/// Remove item from the Dock.
pub fn remove_panel(
&mut self,
panel: Arc<dyn PanelView>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.panel.remove_panel(panel, window, cx);
cx.notify();
}
fn render_resize_handle(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let axis = self.placement.axis();
let view = cx.entity().clone();
resize_handle("resize-handle", axis)
.when(self.placement == DockPlacement::Left, |this| {
this.placement(Side::Left)
})
.on_drag(ResizePanel {}, move |info, _, _, cx| {
cx.stop_propagation();
view.update(cx, |view, _| {
view.resizing = true;
});
cx.new(|_| info.deref().clone())
})
}
fn resize(
&mut self,
mouse_position: Point<Pixels>,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.resizing {
return;
}
if !self.open {
self.set_open(true, window, cx);
}
let dock_area = self
.dock_area
.upgrade()
.expect("DockArea is missing")
.read(cx);
let area_bounds = dock_area.bounds;
let mut left_dock_size = px(0.0);
let mut right_dock_size = px(0.0);
// Get the size of the left dock if it's open and not the current dock
if let Some(left_dock) = &dock_area.left_dock
&& left_dock.entity_id() != cx.entity().entity_id()
{
let left_dock_read = left_dock.read(cx);
if left_dock_read.is_open() {
left_dock_size = left_dock_read.size;
}
}
// Get the size of the right dock if it's open and not the current dock
if let Some(right_dock) = &dock_area.right_dock
&& right_dock.entity_id() != cx.entity().entity_id()
{
let right_dock_read = right_dock.read(cx);
if right_dock_read.is_open() {
right_dock_size = right_dock_read.size;
}
}
let size = match self.placement {
DockPlacement::Left => mouse_position.x - area_bounds.left(),
DockPlacement::Right => area_bounds.right() - mouse_position.x,
DockPlacement::Bottom => area_bounds.bottom() - mouse_position.y,
DockPlacement::Center => unreachable!(),
};
match self.placement {
DockPlacement::Left => {
let max_size =
(area_bounds.size.width - PANEL_MIN_SIZE - right_dock_size).max(PANEL_MIN_SIZE);
self.size = size.clamp(PANEL_MIN_SIZE, max_size);
}
DockPlacement::Right => {
let max_size =
(area_bounds.size.width - PANEL_MIN_SIZE - left_dock_size).max(PANEL_MIN_SIZE);
self.size = size.clamp(PANEL_MIN_SIZE, max_size);
}
DockPlacement::Bottom => {
let max_size = (area_bounds.size.height - PANEL_MIN_SIZE).max(PANEL_MIN_SIZE);
self.size = size.clamp(PANEL_MIN_SIZE, max_size);
}
DockPlacement::Center => unreachable!(),
}
cx.notify();
}
fn done_resizing(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
if !self.resizing {
return;
}
self.resizing = false;
// Dragging the dock's resize handle finished, bubble a layout change
// so subscribers can persist the new dock size.
_ = self.dock_area.update(cx, |_, cx| {
cx.emit(DockEvent::LayoutChanged);
});
}
}
impl Render for Dock {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl gpui::IntoElement {
if !self.open && !self.placement.is_bottom() {
return div();
}
let cache_style = StyleRefinement::default().absolute().size_full();
div()
.relative()
.overflow_hidden()
.map(|this| match self.placement {
DockPlacement::Left | DockPlacement::Right => this.h_flex().h_full().w(self.size),
DockPlacement::Bottom => this.w_full().h(self.size),
DockPlacement::Center => unreachable!(),
})
// Bottom Dock should keep the title bar, then user can click the Toggle button
.when(!self.open && self.placement.is_bottom(), |this| {
this.h(px(29.))
})
.map(|this| match &self.panel {
DockItem::Split { view, .. } => this.child(view.clone()),
DockItem::Tabs { view, .. } => this.child(view.clone()),
DockItem::Panel { view, .. } => this.child(view.clone().view().cached(cache_style)),
// Not support to render Tiles and Tile into Dock
DockItem::Tiles { .. } => this,
})
.child(self.render_resize_handle(window, cx))
.child(DockElement {
view: cx.entity().clone(),
})
}
}
struct DockElement {
view: Entity<Dock>,
}
impl IntoElement for DockElement {
type Element = Self;
fn into_element(self) -> Self::Element {
self
}
}
impl Element for DockElement {
type PrepaintState = ();
type RequestLayoutState = ();
fn id(&self) -> Option<gpui::ElementId> {
None
}
fn source_location(&self) -> Option<&'static std::panic::Location<'static>> {
None
}
fn request_layout(
&mut self,
_: Option<&gpui::GlobalElementId>,
_: Option<&gpui::InspectorElementId>,
window: &mut gpui::Window,
cx: &mut App,
) -> (gpui::LayoutId, Self::RequestLayoutState) {
(window.request_layout(Style::default(), None, cx), ())
}
fn prepaint(
&mut self,
_: Option<&gpui::GlobalElementId>,
_: Option<&gpui::InspectorElementId>,
_: gpui::Bounds<Pixels>,
_: &mut Self::RequestLayoutState,
_window: &mut gpui::Window,
_cx: &mut App,
) -> Self::PrepaintState {
}
fn paint(
&mut self,
_: Option<&gpui::GlobalElementId>,
_: Option<&gpui::InspectorElementId>,
_: gpui::Bounds<Pixels>,
_: &mut Self::RequestLayoutState,
_: &mut Self::PrepaintState,
window: &mut gpui::Window,
cx: &mut App,
) {
window.on_mouse_event({
let view = self.view.clone();
let resizing = view.read(cx).resizing;
move |e: &MouseMoveEvent, phase, window, cx| {
if !resizing {
return;
}
if !phase.bubble() {
return;
}
view.update(cx, |view, cx| view.resize(e.position, window, cx))
}
});
// When any mouse up, stop dragging
window.on_mouse_event({
let view = self.view.clone();
move |_: &MouseUpEvent, phase, window, cx| {
if phase.bubble() {
view.update(cx, |view, cx| view.done_resizing(window, cx));
}
}
})
}
}
+261
View File
@@ -0,0 +1,261 @@
{
"center": {
"panel_name": "StackPanel",
"children": [
{
"panel_name": "TabPanel",
"children": [
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ButtonStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "InputStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "TextStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "SelectStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "DialogStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "SwitchStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ProgressStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "DataTableStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ImageStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "IconStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "TooltipStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ProgressStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "CalendarStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ResizableStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ScrollbarStory"
}
}
}
],
"info": {
"tabs": {
"active_index": 0
}
}
},
{
"panel_name": "TabPanel",
"children": [
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "PopupStory"
}
}
}
],
"info": {
"tabs": {
"active_index": 0
}
}
}
],
"info": {
"stack": {
"sizes": [704.0, 263.0],
"axis": 1
}
}
},
"left_dock": {
"panel": {
"panel_name": "TabPanel",
"children": [
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ListStory"
}
}
}
],
"info": {
"tabs": {
"active_index": 0
}
}
},
"placement": "left",
"size": 350.0,
"open": true,
"resizeable": true
},
"right_dock": {
"panel": {
"panel_name": "TabPanel",
"children": [
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "ImageStory"
}
}
}
],
"info": {
"tabs": {
"active_index": 0
}
}
},
"placement": "right",
"size": 320.0,
"open": true,
"resizeable": true
},
"bottom_dock": {
"panel": {
"panel_name": "TabPanel",
"children": [
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "TextStory"
}
}
},
{
"panel_name": "StoryContainer",
"children": [],
"info": {
"panel": {
"story_klass": "IconStory"
}
}
}
],
"info": {
"tabs": {
"active_index": 0
}
}
},
"placement": "bottom",
"size": 200.0,
"open": true,
"resizeable": true
}
}
+58
View File
@@ -0,0 +1,58 @@
use gpui::{
App, EventEmitter, FocusHandle, Focusable, ParentElement as _, Render, SharedString,
Styled as _, Window,
};
use gpui_component::ActiveTheme as _;
use super::{Panel, PanelEvent, PanelState};
pub(crate) struct InvalidPanel {
name: SharedString,
focus_handle: FocusHandle,
old_state: PanelState,
}
impl InvalidPanel {
pub(crate) fn new(name: &str, state: PanelState, _: &mut Window, cx: &mut App) -> Self {
Self {
focus_handle: cx.focus_handle(),
name: SharedString::from(name.to_owned()),
old_state: state,
}
}
}
impl Panel for InvalidPanel {
fn panel_name(&self) -> &'static str {
"InvalidPanel"
}
fn dump(&self, _cx: &App) -> super::PanelState {
self.old_state.clone()
}
}
impl EventEmitter<PanelEvent> for InvalidPanel {}
impl Focusable for InvalidPanel {
fn focus_handle(&self, _: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for InvalidPanel {
fn render(
&mut self,
_: &mut gpui::Window,
cx: &mut gpui::Context<Self>,
) -> impl gpui::IntoElement {
gpui::div()
.size_full()
.my_6()
.flex()
.flex_col()
.items_center()
.justify_center()
.text_color(cx.theme().muted_foreground)
.child(format!(
"The `{}` panel type is not registered in PanelRegistry.",
self.name.clone()
))
}
}
File diff suppressed because it is too large Load Diff
+386
View File
@@ -0,0 +1,386 @@
use std::collections::HashMap;
use std::sync::Arc;
use gpui::{
AnyElement, AnyView, App, AppContext as _, Context, Entity, EntityId, EventEmitter,
FocusHandle, Focusable, Global, Hsla, IntoElement, Render, SharedString, WeakEntity, Window,
};
use gpui_component::button::Button;
use gpui_component::menu::PopupMenu;
use super::{DockArea, PanelInfo, PanelState, TabPanel};
use crate::invalid_panel::InvalidPanel;
use crate::t;
pub enum PanelEvent {
ZoomIn,
ZoomOut,
LayoutChanged,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum PanelStyle {
/// Display the TabBar when there are multiple tabs, otherwise display the simple title.
#[default]
Auto,
/// Always display the tab bar.
TabBar,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TitleStyle {
pub background: Hsla,
pub foreground: Hsla,
}
#[derive(Clone, Copy, Default)]
pub enum PanelControl {
Both,
#[default]
Menu,
Toolbar,
}
impl PanelControl {
#[inline]
pub fn toolbar_visible(&self) -> bool {
matches!(self, PanelControl::Both | PanelControl::Toolbar)
}
#[inline]
pub fn menu_visible(&self) -> bool {
matches!(self, PanelControl::Both | PanelControl::Menu)
}
}
/// The Panel trait used to define the panel.
#[allow(unused_variables)]
pub trait Panel: EventEmitter<PanelEvent> + Render + Focusable {
/// The name of the panel used to serialize, deserialize and identify the panel.
///
/// This is used to identify the panel when deserializing the panel.
/// Once you have defined a panel name, this must not be changed.
fn panel_name(&self) -> &'static str;
/// The name of the tab of the panel, default is `None`.
///
/// Used to display in the already collapsed tab panel.
fn tab_name(&self, cx: &App) -> Option<SharedString> {
None
}
/// The title of the panel
fn title(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
t("Dock.Unnamed")
}
/// The theme of the panel title, default is `None`.
fn title_style(&self, cx: &App) -> Option<TitleStyle> {
None
}
/// The suffix of the panel title, default is `None`.
///
/// This is used to add a suffix element to the panel title.
fn title_suffix(
&mut self,
window: &mut Window,
cx: &mut Context<Self>,
) -> Option<impl IntoElement> {
None::<gpui::Div>
}
/// Whether the panel can be closed, default is `true`.
///
/// This method called in Panel render, we should make sure it is fast.
fn closable(&self, cx: &App) -> bool {
true
}
/// Return `PanelControl` if the panel is zoomable, default is `PanelControl::Menu`.
///
/// This method called in Panel render, we should make sure it is fast.
fn zoomable(&self, cx: &App) -> Option<PanelControl> {
Some(PanelControl::Menu)
}
/// Return false to hide panel, true to show panel, default is `true`.
///
/// This method called in Panel render, we should make sure it is fast.
fn visible(&self, cx: &App) -> bool {
true
}
/// Set active state of the panel.
///
/// Called with the frame-end net state when this panel becomes (or stops
/// being) the displayed tab of its tab group: exactly one notification
/// per edge, delivered on the next tick after the change — never
/// same-value repeats nor false→true flips within one frame.
///
/// A panel removed from its group is NOT told `false`; [`Panel::on_removed`]
/// is the deactivation signal. A hidden panel occupying `active_ix` still
/// receives `true` even though rendering falls back to the first visible
/// panel, and panels inside a bare `DockItem::Panel` (no tab group) are
/// outside this contract.
fn set_active(&mut self, active: bool, window: &mut Window, cx: &mut Context<Self>) {}
/// Set zoomed state of the panel.
///
/// This method will be called when the panel is zoomed or unzoomed.
///
/// Only current Panel will touch this method.
fn set_zoomed(&mut self, zoomed: bool, window: &mut Window, cx: &mut Context<Self>) {}
/// When this Panel is added to a TabPanel, this will be called.
fn on_added_to(
&mut self,
tab_panel: WeakEntity<TabPanel>,
window: &mut Window,
cx: &mut Context<Self>,
) {
}
/// When this Panel is removed from a TabPanel, this will be called.
fn on_removed(&mut self, window: &mut Window, cx: &mut Context<Self>) {}
/// The addition dropdown menu of the panel, default is `None`.
fn dropdown_menu(
&mut self,
this: PopupMenu,
window: &mut Window,
cx: &mut Context<Self>,
) -> PopupMenu {
this
}
/// The addition toolbar buttons of the panel used to show in the right of the title bar, default is `None`.
fn toolbar_buttons(
&mut self,
window: &mut Window,
cx: &mut Context<Self>,
) -> Option<Vec<Button>> {
None
}
/// Dump the panel, used to serialize the panel.
fn dump(&self, cx: &App) -> PanelState {
PanelState::new(self)
}
/// Whether the panel has inner padding when the panel is in the tabs layout, default is `true`.
fn inner_padding(&self, cx: &App) -> bool {
true
}
}
/// The PanelView trait used to define the panel view.
#[allow(unused_variables)]
pub trait PanelView: 'static + Send + Sync {
fn panel_name(&self, cx: &App) -> &'static str;
fn panel_id(&self, cx: &App) -> EntityId;
fn tab_name(&self, cx: &App) -> Option<SharedString>;
fn title(&self, window: &mut Window, cx: &mut App) -> AnyElement;
fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement>;
fn title_style(&self, cx: &App) -> Option<TitleStyle>;
fn closable(&self, cx: &App) -> bool;
fn zoomable(&self, cx: &App) -> Option<PanelControl>;
fn visible(&self, cx: &App) -> bool;
fn set_active(&self, active: bool, window: &mut Window, cx: &mut App);
fn set_zoomed(&self, zoomed: bool, window: &mut Window, cx: &mut App);
fn on_added_to(&self, tab_panel: WeakEntity<TabPanel>, window: &mut Window, cx: &mut App);
fn on_removed(&self, window: &mut Window, cx: &mut App);
fn dropdown_menu(&self, menu: PopupMenu, window: &mut Window, cx: &mut App) -> PopupMenu;
fn toolbar_buttons(&self, window: &mut Window, cx: &mut App) -> Option<Vec<Button>>;
fn view(&self) -> AnyView;
fn focus_handle(&self, cx: &App) -> FocusHandle;
fn dump(&self, cx: &App) -> PanelState;
fn inner_padding(&self, cx: &App) -> bool;
}
impl<T: Panel> PanelView for Entity<T> {
fn panel_name(&self, cx: &App) -> &'static str {
self.read(cx).panel_name()
}
fn panel_id(&self, _: &App) -> EntityId {
self.entity_id()
}
fn tab_name(&self, cx: &App) -> Option<SharedString> {
self.read(cx).tab_name(cx)
}
fn title(&self, window: &mut Window, cx: &mut App) -> AnyElement {
self.update(cx, |this, cx| this.title(window, cx).into_any_element())
}
fn title_suffix(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement> {
self.update(cx, |this, cx| {
this.title_suffix(window, cx)
.map(|el| el.into_any_element())
})
}
fn title_style(&self, cx: &App) -> Option<TitleStyle> {
self.read(cx).title_style(cx)
}
fn closable(&self, cx: &App) -> bool {
self.read(cx).closable(cx)
}
fn zoomable(&self, cx: &App) -> Option<PanelControl> {
self.read(cx).zoomable(cx)
}
fn visible(&self, cx: &App) -> bool {
self.read(cx).visible(cx)
}
fn set_active(&self, active: bool, window: &mut Window, cx: &mut App) {
self.update(cx, |this, cx| {
this.set_active(active, window, cx);
})
}
fn set_zoomed(&self, zoomed: bool, window: &mut Window, cx: &mut App) {
self.update(cx, |this, cx| {
this.set_zoomed(zoomed, window, cx);
})
}
fn on_added_to(&self, tab_panel: WeakEntity<TabPanel>, window: &mut Window, cx: &mut App) {
self.update(cx, |this, cx| this.on_added_to(tab_panel, window, cx));
}
fn on_removed(&self, window: &mut Window, cx: &mut App) {
self.update(cx, |this, cx| this.on_removed(window, cx));
}
fn dropdown_menu(&self, menu: PopupMenu, window: &mut Window, cx: &mut App) -> PopupMenu {
self.update(cx, |this, cx| this.dropdown_menu(menu, window, cx))
}
fn toolbar_buttons(&self, window: &mut Window, cx: &mut App) -> Option<Vec<Button>> {
self.update(cx, |this, cx| this.toolbar_buttons(window, cx))
}
fn view(&self) -> AnyView {
self.clone().into()
}
fn focus_handle(&self, cx: &App) -> FocusHandle {
self.read(cx).focus_handle(cx)
}
fn dump(&self, cx: &App) -> PanelState {
self.read(cx).dump(cx)
}
fn inner_padding(&self, cx: &App) -> bool {
self.read(cx).inner_padding(cx)
}
}
impl From<&dyn PanelView> for AnyView {
fn from(handle: &dyn PanelView) -> Self {
handle.view()
}
}
impl<T: Panel> From<&dyn PanelView> for Entity<T> {
fn from(value: &dyn PanelView) -> Self {
value.view().downcast::<T>().unwrap()
}
}
impl PartialEq for dyn PanelView {
fn eq(&self, other: &Self) -> bool {
self.view() == other.view()
}
}
/// The deserializer used by [`PanelRegistry`] to rebuild a panel from its
/// persisted [`PanelState`].
type PanelBuilder = dyn Fn(
WeakEntity<DockArea>,
&PanelState,
&PanelInfo,
&mut Window,
&mut App,
) -> Box<dyn PanelView>;
pub struct PanelRegistry {
pub(super) items: HashMap<String, Arc<PanelBuilder>>,
}
impl PanelRegistry {
/// Initialize the panel registry.
pub(crate) fn init(cx: &mut App) {
if cx.try_global::<PanelRegistry>().is_none() {
cx.set_global(PanelRegistry::new());
}
}
pub fn new() -> Self {
Self {
items: HashMap::new(),
}
}
pub fn global(cx: &App) -> &Self {
cx.global::<PanelRegistry>()
}
pub fn global_mut(cx: &mut App) -> &mut Self {
cx.global_mut::<PanelRegistry>()
}
/// Build a panel by name.
///
/// If not registered, return InvalidPanel.
pub fn build_panel(
panel_name: &str,
dock_area: WeakEntity<DockArea>,
panel_state: &PanelState,
panel_info: &PanelInfo,
window: &mut Window,
cx: &mut App,
) -> Box<dyn PanelView> {
if let Some(view) = Self::global(cx)
.items
.get(panel_name)
.cloned()
.map(|f| f(dock_area, panel_state, panel_info, window, cx))
{
view
} else {
// Show an invalid panel if the panel is not registered.
Box::new(cx.new(|cx| InvalidPanel::new(panel_name, panel_state.clone(), window, cx)))
}
}
}
impl Default for PanelRegistry {
fn default() -> Self {
Self::new()
}
}
impl Global for PanelRegistry {}
/// Register the Panel init by panel_name to global registry.
pub fn register_panel<F>(cx: &mut App, panel_name: &str, deserialize: F)
where
F: Fn(
WeakEntity<DockArea>,
&PanelState,
&PanelInfo,
&mut Window,
&mut App,
) -> Box<dyn PanelView>
+ 'static,
{
PanelRegistry::init(cx);
PanelRegistry::global_mut(cx)
.items
.insert(panel_name.to_string(), Arc::new(deserialize));
}
+232
View File
@@ -0,0 +1,232 @@
//! Vendored from `gpui-base`'s private `resizable::resize_handle` module
//! (v0.5.2, rev 9e3a29dcbdebc318632bf68203f26c33e9f0e902). gpui-component
//! keeps this and [`PANEL_MIN_SIZE`] crate-private, so the dock crate carries
//! its own copy.
use std::cell::Cell;
use std::rc::Rc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AnyElement, App, Axis, Element, ElementId, Entity, GlobalElementId, InteractiveElement,
IntoElement, MouseDownEvent, MouseUpEvent, ParentElement as _, Pixels, Point, Render,
StatefulInteractiveElement, Styled as _, Window, div, px,
};
use gpui_component::{ActiveTheme as _, AxisExt as _, Side};
pub(crate) const PANEL_MIN_SIZE: Pixels = px(100.);
pub(crate) const HANDLE_PADDING: Pixels = px(4.);
pub(crate) const HANDLE_SIZE: Pixels = px(1.);
/// Create a resize handle for a resizable panel.
#[doc(hidden)]
pub fn resize_handle<T: 'static, E: 'static + Render>(
id: impl Into<ElementId>,
axis: Axis,
) -> ResizeHandle<T, E> {
ResizeHandle::new(id, axis)
}
type DragHandler<E> = dyn Fn(&Point<Pixels>, &mut Window, &mut App) -> Entity<E>;
#[doc(hidden)]
pub struct ResizeHandle<T: 'static, E: 'static + Render> {
id: ElementId,
axis: Axis,
drag_value: Option<Rc<T>>,
placement: Option<Side>,
on_drag: Option<Rc<DragHandler<E>>>,
}
impl<T: 'static, E: 'static + Render> ResizeHandle<T, E> {
fn new(id: impl Into<ElementId>, axis: Axis) -> Self {
let id = id.into();
Self {
id: id.clone(),
on_drag: None,
drag_value: None,
placement: None,
axis,
}
}
pub fn on_drag(
mut self,
value: T,
f: impl Fn(Rc<T>, &Point<Pixels>, &mut Window, &mut App) -> Entity<E> + 'static,
) -> Self {
let value = Rc::new(value);
self.drag_value = Some(value.clone());
self.on_drag = Some(Rc::new(move |p, window, cx| {
f(value.clone(), p, window, cx)
}));
self
}
pub fn placement(mut self, placement: Side) -> Self {
self.placement = Some(placement);
self
}
}
#[derive(Default, Debug, Clone)]
struct ResizeHandleState {
active: Cell<bool>,
}
impl ResizeHandleState {
fn set_active(&self, active: bool) {
self.active.set(active);
}
fn is_active(&self) -> bool {
self.active.get()
}
}
impl<T: 'static, E: 'static + Render> IntoElement for ResizeHandle<T, E> {
type Element = ResizeHandle<T, E>;
fn into_element(self) -> Self::Element {
self
}
}
impl<T: 'static, E: 'static + Render> Element for ResizeHandle<T, E> {
type PrepaintState = ();
type RequestLayoutState = AnyElement;
fn id(&self) -> Option<ElementId> {
Some(self.id.clone())
}
fn source_location(&self) -> Option<&'static std::panic::Location<'static>> {
None
}
fn request_layout(
&mut self,
id: Option<&GlobalElementId>,
_: Option<&gpui::InspectorElementId>,
window: &mut Window,
cx: &mut App,
) -> (gpui::LayoutId, Self::RequestLayoutState) {
let neg_offset = -HANDLE_PADDING;
let axis = self.axis;
window.with_element_state(id.unwrap(), |state: Option<ResizeHandleState>, window| {
let state = state.unwrap_or_default();
let bg_color = if state.is_active() {
cx.theme().drag_border
} else {
cx.theme().border
};
let mut el = div()
.id(self.id.clone())
.occlude()
.absolute()
.flex_shrink_0()
.group("handle")
.when_some(self.on_drag.clone(), |this, on_drag| {
this.on_drag(
self.drag_value.clone().unwrap(),
move |_, position, window, cx| on_drag(&position, window, cx),
)
})
.map(|this| match self.placement {
Some(Side::Left) => {
// Special for Left Dock
// FIXME: Improve this to let the scroll bar have px(HANDLE_PADDING)
this.cursor_col_resize()
.top_0()
.right(px(1.))
.h_full()
.w(HANDLE_SIZE)
.pl(HANDLE_PADDING)
}
_ => this
.when(axis.is_horizontal(), |this| {
this.cursor_col_resize()
.top_0()
.left(neg_offset)
.h_full()
.w(HANDLE_SIZE)
.px(HANDLE_PADDING)
})
.when(axis.is_vertical(), |this| {
this.cursor_row_resize()
.top(neg_offset)
.left_0()
.w_full()
.h(HANDLE_SIZE)
.py(HANDLE_PADDING)
}),
})
.child(
div()
.bg(bg_color)
.group_hover("handle", |this| this.bg(bg_color))
.when(axis.is_horizontal(), |this| this.h_full().w(HANDLE_SIZE))
.when(axis.is_vertical(), |this| this.w_full().h(HANDLE_SIZE)),
)
.into_any_element();
let layout_id = el.request_layout(window, cx);
((layout_id, el), state)
})
}
fn prepaint(
&mut self,
_: Option<&GlobalElementId>,
_: Option<&gpui::InspectorElementId>,
_: gpui::Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
window: &mut Window,
cx: &mut App,
) -> Self::PrepaintState {
request_layout.prepaint(window, cx);
}
fn paint(
&mut self,
id: Option<&GlobalElementId>,
_: Option<&gpui::InspectorElementId>,
bounds: gpui::Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
_: &mut Self::PrepaintState,
window: &mut Window,
cx: &mut App,
) {
request_layout.paint(window, cx);
window.with_element_state(id.unwrap(), |state: Option<ResizeHandleState>, window| {
let state = state.unwrap_or_default();
window.on_mouse_event({
let state = state.clone();
move |ev: &MouseDownEvent, phase, window, _| {
if bounds.contains(&ev.position) && phase.bubble() {
state.set_active(true);
window.refresh();
}
}
});
window.on_mouse_event({
let state = state.clone();
move |_: &MouseUpEvent, _, window, _| {
if state.is_active() {
state.set_active(false);
window.refresh();
}
}
});
((), state)
});
}
}
+429
View File
@@ -0,0 +1,429 @@
use std::sync::Arc;
use gpui::{
App, AppContext as _, Axis, Context, DismissEvent, Entity, EventEmitter, FocusHandle,
Focusable, IntoElement, ParentElement, Pixels, Render, Styled, Subscription, WeakEntity,
Window,
};
use gpui_component::{
ActiveTheme, AxisExt as _, Placement, ResizablePanelEvent, ResizablePanelGroup, ResizableState,
h_flex, resizable_panel,
};
use smallvec::SmallVec;
use super::{DockArea, Panel, PanelEvent, PanelState, PanelView, TabPanel};
use crate::PanelInfo;
use crate::resize_handle::PANEL_MIN_SIZE;
pub struct StackPanel {
pub(super) parent: Option<WeakEntity<StackPanel>>,
pub(super) axis: Axis,
focus_handle: FocusHandle,
pub(crate) panels: SmallVec<[Arc<dyn PanelView>; 2]>,
state: Entity<ResizableState>,
_subscriptions: Vec<Subscription>,
}
impl Panel for StackPanel {
fn panel_name(&self) -> &'static str {
"StackPanel"
}
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
"StackPanel"
}
fn set_active(&mut self, active: bool, window: &mut Window, cx: &mut Context<Self>) {
for panel in &self.panels {
panel.set_active(active, window, cx);
}
}
fn dump(&self, cx: &App) -> PanelState {
let sizes = self.state.read(cx).sizes().clone();
let mut state = PanelState::new(self);
state.info = PanelInfo::stack(sizes, self.axis);
for panel in &self.panels {
state.add_child(panel.dump(cx));
}
state
}
}
impl StackPanel {
pub fn new(axis: Axis, _: &mut Window, cx: &mut Context<Self>) -> Self {
let state = cx.new(|_| ResizableState::default());
let _subscriptions = vec![
// Bubble up the resize event.
cx.subscribe(&state, |_, _, _: &ResizablePanelEvent, cx| {
cx.emit(PanelEvent::LayoutChanged)
}),
];
Self {
axis,
parent: None,
focus_handle: cx.focus_handle(),
panels: SmallVec::new(),
state,
_subscriptions,
}
}
/// The first level of the stack panel is root, will not have a parent.
fn is_root(&self) -> bool {
self.parent.is_none()
}
/// Return true if self or parent only have last panel.
pub(super) fn is_last_panel(&self, cx: &App) -> bool {
if self.panels.len() > 1 {
return false;
}
if let Some(parent) = &self.parent
&& let Some(parent) = parent.upgrade()
{
return parent.read(cx).is_last_panel(cx);
}
true
}
pub(super) fn panels_len(&self) -> usize {
self.panels.len()
}
/// Return the index of the panel.
pub(crate) fn index_of_panel(&self, panel: Arc<dyn PanelView>) -> Option<usize> {
self.panels.iter().position(|p| p == &panel)
}
fn assert_panel_is_valid(&self, panel: &Arc<dyn PanelView>) {
assert!(
panel.view().downcast::<TabPanel>().is_ok()
|| panel.view().downcast::<StackPanel>().is_ok(),
"Panel must be a `TabPanel` or `StackPanel`"
);
}
/// Add a panel at the end of the stack.
///
/// If `size` is `None`, the panel will be given the average size of all panels in the stack.
///
/// The `panel` must be a [`TabPanel`] or [`StackPanel`].
pub fn add_panel(
&mut self,
panel: Arc<dyn PanelView>,
size: Option<Pixels>,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.insert_panel(panel, self.panels.len(), size, dock_area, window, cx);
}
/// Add a panel at the [`Placement`].
///
/// The `panel` must be a [`TabPanel`] or [`StackPanel`].
pub fn add_panel_at(
&mut self,
panel: Arc<dyn PanelView>,
placement: Placement,
size: Option<Pixels>,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.insert_panel_at(
panel,
self.panels_len(),
placement,
size,
dock_area,
window,
cx,
);
}
/// Insert a panel at the index.
///
/// The `panel` must be a [`TabPanel`] or [`StackPanel`].
#[allow(clippy::too_many_arguments)]
pub fn insert_panel_at(
&mut self,
panel: Arc<dyn PanelView>,
ix: usize,
placement: Placement,
size: Option<Pixels>,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) {
match placement {
Placement::Top | Placement::Left => {
self.insert_panel_before(panel, ix, size, dock_area, window, cx)
}
Placement::Right | Placement::Bottom => {
self.insert_panel_after(panel, ix, size, dock_area, window, cx)
}
}
}
/// Insert a panel at the index.
///
/// The `panel` must be a [`TabPanel`] or [`StackPanel`].
pub fn insert_panel_before(
&mut self,
panel: Arc<dyn PanelView>,
ix: usize,
size: Option<Pixels>,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.insert_panel(panel, ix, size, dock_area, window, cx);
}
/// Insert a panel after the index.
///
/// The `panel` must be a [`TabPanel`] or [`StackPanel`].
pub fn insert_panel_after(
&mut self,
panel: Arc<dyn PanelView>,
ix: usize,
size: Option<Pixels>,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.insert_panel(panel, ix + 1, size, dock_area, window, cx);
}
fn insert_panel(
&mut self,
panel: Arc<dyn PanelView>,
ix: usize,
size: Option<Pixels>,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.assert_panel_is_valid(&panel);
// If the panel is already in the stack, return.
if self.index_of_panel(panel.clone()).is_some() {
return;
}
let view = cx.entity().clone();
window.defer(cx, {
let panel = panel.clone();
move |window, cx| {
// If the panel is a TabPanel, set its parent to this.
if let Ok(tab_panel) = panel.view().downcast::<TabPanel>() {
tab_panel.update(cx, |tab_panel, _| tab_panel.set_parent(view.downgrade()));
} else if let Ok(stack_panel) = panel.view().downcast::<Self>() {
stack_panel.update(cx, |stack_panel, _| {
stack_panel.parent = Some(view.downgrade())
});
}
// Subscribe to the panel's layout change event.
_ = dock_area.update(cx, |this, cx| {
if let Ok(tab_panel) = panel.view().downcast::<TabPanel>() {
this.subscribe_panel(&tab_panel, window, cx);
} else if let Ok(stack_panel) = panel.view().downcast::<Self>() {
this.subscribe_panel(&stack_panel, window, cx);
}
});
}
});
let ix = if ix > self.panels.len() {
self.panels.len()
} else {
ix
};
// Get avg size of all panels to insert new panel, if size is None.
let size = match size {
Some(size) => size,
None => {
let state = self.state.read(cx);
(state.container_size() / (state.sizes().len() + 1) as f32).max(PANEL_MIN_SIZE)
}
};
self.panels.insert(ix, panel.clone());
self.state.update(cx, |state, cx| {
state.insert_panel(Some(size), Some(ix), cx);
});
cx.emit(PanelEvent::LayoutChanged);
cx.notify();
}
/// Remove panel from the stack.
///
/// If `ix` is not found, do nothing.
pub fn remove_panel(
&mut self,
panel: Arc<dyn PanelView>,
window: &mut Window,
cx: &mut Context<Self>,
) {
let Some(ix) = self.index_of_panel(panel.clone()) else {
return;
};
self.panels.remove(ix);
self.state.update(cx, |state, cx| {
state.remove_panel(ix, cx);
});
cx.emit(PanelEvent::LayoutChanged);
self.remove_self_if_empty(window, cx);
}
/// Replace the old panel with the new panel at same index.
pub(super) fn replace_panel(
&mut self,
old_panel: Arc<dyn PanelView>,
new_panel: Entity<StackPanel>,
_: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(ix) = self.index_of_panel(old_panel.clone()) {
self.panels[ix] = Arc::new(new_panel.clone());
self.state.update(cx, |state, cx| {
state.reset_panel(ix, cx);
});
cx.emit(PanelEvent::LayoutChanged);
}
}
/// If children is empty, remove self from parent view.
pub(crate) fn remove_self_if_empty(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if self.is_root() {
return;
}
if !self.panels.is_empty() {
return;
}
let view = cx.entity().clone();
if let Some(parent) = self.parent.as_ref() {
_ = parent.update(cx, |parent, cx| {
parent.remove_panel(Arc::new(view.clone()), window, cx);
});
}
cx.emit(PanelEvent::LayoutChanged);
cx.notify();
}
/// Find the first top left in the stack.
pub(super) fn left_top_tab_panel(
&self,
check_parent: bool,
cx: &App,
) -> Option<Entity<TabPanel>> {
if check_parent
&& let Some(parent) = self.parent.as_ref().and_then(|parent| parent.upgrade())
&& let Some(panel) = parent.read(cx).left_top_tab_panel(true, cx)
{
return Some(panel);
}
let first_panel = self.panels.first();
if let Some(view) = first_panel {
if let Ok(tab_panel) = view.view().downcast::<TabPanel>() {
Some(tab_panel)
} else if let Ok(stack_panel) = view.view().downcast::<StackPanel>() {
stack_panel.read(cx).left_top_tab_panel(false, cx)
} else {
None
}
} else {
None
}
}
/// Find the first top right in the stack.
pub(super) fn right_top_tab_panel(
&self,
check_parent: bool,
cx: &App,
) -> Option<Entity<TabPanel>> {
if check_parent
&& let Some(parent) = self.parent.as_ref().and_then(|parent| parent.upgrade())
&& let Some(panel) = parent.read(cx).right_top_tab_panel(true, cx)
{
return Some(panel);
}
let panel = if self.axis.is_vertical() {
self.panels.first()
} else {
self.panels.last()
};
if let Some(view) = panel {
if let Ok(tab_panel) = view.view().downcast::<TabPanel>() {
Some(tab_panel)
} else if let Ok(stack_panel) = view.view().downcast::<StackPanel>() {
stack_panel.read(cx).right_top_tab_panel(false, cx)
} else {
None
}
} else {
None
}
}
/// Remove all panels from the stack.
pub(super) fn remove_all_panels(&mut self, _: &mut Window, cx: &mut Context<Self>) {
self.panels.clear();
self.state.update(cx, |state, cx| {
state.clear();
cx.notify();
});
}
/// Change the axis of the stack panel.
pub(super) fn set_axis(&mut self, axis: Axis, _: &mut Window, cx: &mut Context<Self>) {
self.axis = axis;
cx.notify();
}
}
impl Focusable for StackPanel {
fn focus_handle(&self, _cx: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl EventEmitter<PanelEvent> for StackPanel {}
impl EventEmitter<DismissEvent> for StackPanel {}
impl Render for StackPanel {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
h_flex()
.size_full()
.overflow_hidden()
.bg(cx.theme().tokens.tab_bar)
.child(
ResizablePanelGroup::new("stack-panel-group")
.with_state(&self.state)
.axis(self.axis)
.children(self.panels.clone().into_iter().map(|panel| {
resizable_panel()
.child(panel.view())
.visible(panel.visible(cx))
})),
)
}
}
+282
View File
@@ -0,0 +1,282 @@
use gpui::{App, AppContext, Axis, Bounds, Entity, Pixels, WeakEntity, Window, point, px, size};
use itertools::Itertools as _;
use serde::{Deserialize, Serialize};
use super::{Dock, DockArea, DockItem, DockPlacement, Panel, PanelRegistry};
/// Used to serialize and deserialize the DockArea
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct DockAreaState {
/// The version is used to mark this persisted state is compatible with the current version
/// For example, some times we many totally changed the structure of the Panel,
/// then we can compare the version to decide whether we can use the state or ignore.
#[serde(default)]
pub version: Option<usize>,
pub center: PanelState,
#[serde(skip_serializing_if = "Option::is_none")]
pub left_dock: Option<DockState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub right_dock: Option<DockState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bottom_dock: Option<DockState>,
}
/// Used to serialize and deserialize the Dock
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DockState {
panel: PanelState,
placement: DockPlacement,
size: Pixels,
open: bool,
}
impl DockState {
pub fn new(dock: Entity<Dock>, cx: &App) -> Self {
let dock = dock.read(cx);
Self {
placement: dock.placement,
size: dock.size,
open: dock.open,
panel: dock.panel.view().dump(cx),
}
}
/// Convert the DockState to Dock
pub fn to_dock(
&self,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut App,
) -> Entity<Dock> {
let item = self.panel.to_item(dock_area.clone(), window, cx);
cx.new(|cx| {
Dock::from_state(
dock_area.clone(),
self.placement,
self.size,
item,
self.open,
window,
cx,
)
})
}
}
/// Used to serialize and deserialize the DockerItem
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PanelState {
pub panel_name: String,
pub children: Vec<PanelState>,
pub info: PanelInfo,
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub struct TileMeta {
pub bounds: Bounds<Pixels>,
pub z_index: usize,
}
impl Default for TileMeta {
fn default() -> Self {
Self {
bounds: Bounds {
origin: point(px(10.), px(10.)),
size: size(px(200.), px(200.)),
},
z_index: 0,
}
}
}
impl From<Bounds<Pixels>> for TileMeta {
fn from(bounds: Bounds<Pixels>) -> Self {
Self { bounds, z_index: 0 }
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PanelInfo {
#[serde(rename = "stack")]
Stack {
sizes: Vec<Pixels>,
axis: usize, // 0 for horizontal, 1 for vertical
},
#[serde(rename = "tabs")]
Tabs { active_index: usize },
#[serde(rename = "panel")]
Panel(serde_json::Value),
#[serde(rename = "tiles")]
Tiles { metas: Vec<TileMeta> },
}
impl PanelInfo {
pub fn stack(sizes: Vec<Pixels>, axis: Axis) -> Self {
Self::Stack {
sizes,
axis: if axis == Axis::Horizontal { 0 } else { 1 },
}
}
pub fn tabs(active_index: usize) -> Self {
Self::Tabs { active_index }
}
pub fn panel(info: serde_json::Value) -> Self {
Self::Panel(info)
}
pub fn tiles(metas: Vec<TileMeta>) -> Self {
Self::Tiles { metas }
}
pub fn axis(&self) -> Option<Axis> {
match self {
Self::Stack { axis, .. } => Some(if *axis == 0 {
Axis::Horizontal
} else {
Axis::Vertical
}),
_ => None,
}
}
pub fn sizes(&self) -> Option<&Vec<Pixels>> {
match self {
Self::Stack { sizes, .. } => Some(sizes),
_ => None,
}
}
pub fn active_index(&self) -> Option<usize> {
match self {
Self::Tabs { active_index } => Some(*active_index),
_ => None,
}
}
}
impl Default for PanelState {
fn default() -> Self {
Self {
panel_name: "".to_string(),
children: Vec::new(),
info: PanelInfo::Panel(serde_json::Value::Null),
}
}
}
impl PanelState {
pub fn new<P: Panel>(panel: &P) -> Self {
Self {
panel_name: panel.panel_name().to_string(),
..Default::default()
}
}
pub fn add_child(&mut self, panel: PanelState) {
self.children.push(panel);
}
pub fn to_item(
&self,
dock_area: WeakEntity<DockArea>,
window: &mut Window,
cx: &mut App,
) -> DockItem {
let info = self.info.clone();
let items: Vec<DockItem> = self
.children
.iter()
.map(|child| child.to_item(dock_area.clone(), window, cx))
.collect();
match info {
PanelInfo::Stack { sizes, axis } => {
let axis = if axis == 0 {
Axis::Horizontal
} else {
Axis::Vertical
};
let sizes = sizes.iter().map(|s| Some(*s)).collect_vec();
DockItem::split_with_sizes(axis, items, sizes, &dock_area, window, cx)
}
PanelInfo::Tabs { active_index } => {
if items.len() == 1 {
return items[0].clone();
}
let items = items
.iter()
.flat_map(|item| match item {
DockItem::Tabs { items, .. } => items.clone(),
_ => {
// ignore invalid panels in tabs
vec![]
}
})
.collect_vec();
DockItem::tabs(items, &dock_area, window, cx).active_index(active_index, cx)
}
PanelInfo::Panel(_) => {
let view = PanelRegistry::build_panel(
&self.panel_name,
dock_area.clone(),
self,
&info,
window,
cx,
);
DockItem::tabs(vec![view.into()], &dock_area, window, cx)
}
PanelInfo::Tiles { metas } => DockItem::tiles(items, metas, &dock_area, window, cx),
}
}
}
#[cfg(test)]
mod tests {
use gpui::px;
use super::*;
#[test]
fn test_deserialize_item_state() {
let json = include_str!("fixtures/layout.json");
let state: DockAreaState = serde_json::from_str(json).unwrap();
assert_eq!(state.version, None);
assert_eq!(state.center.panel_name, "StackPanel");
assert_eq!(state.center.children.len(), 2);
assert_eq!(state.center.children[0].panel_name, "TabPanel");
assert_eq!(state.center.children[1].children.len(), 1);
assert_eq!(
state.center.children[1].children[0].panel_name,
"StoryContainer"
);
assert_eq!(state.center.children[1].panel_name, "TabPanel");
let left_dock = state.left_dock.unwrap();
assert!(left_dock.open);
assert_eq!(left_dock.size, px(350.0));
assert_eq!(left_dock.placement, DockPlacement::Left);
assert_eq!(left_dock.panel.panel_name, "TabPanel");
assert_eq!(left_dock.panel.children.len(), 1);
assert_eq!(left_dock.panel.children[0].panel_name, "StoryContainer");
let bottom_dock = state.bottom_dock.unwrap();
assert!(bottom_dock.open);
assert_eq!(bottom_dock.size, px(200.0));
assert_eq!(bottom_dock.panel.panel_name, "TabPanel");
assert_eq!(bottom_dock.panel.children.len(), 2);
assert_eq!(bottom_dock.panel.children[0].panel_name, "StoryContainer");
let right_dock = state.right_dock.unwrap();
assert!(right_dock.open);
assert_eq!(right_dock.size, px(320.0));
assert_eq!(right_dock.panel.panel_name, "TabPanel");
assert_eq!(right_dock.panel.children.len(), 1);
assert_eq!(right_dock.panel.children[0].panel_name, "StoryContainer");
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1
View File
@@ -6,6 +6,7 @@ publish.workspace = true
[dependencies]
assets = { path = "../assets" }
dock = { workspace = true }
signed_core = { path = "../signed_core" }
signed_git = { path = "../signed_git" }
signed_state = { path = "../signed_state" }
@@ -12,7 +12,7 @@ use gpui::{
ScrollStrategy, SharedString, Size, WeakEntity, Window, div, px, size,
};
use gpui_component::clipboard::Clipboard;
use gpui_component::dock::{Panel, PanelEvent};
use dock::{Panel, PanelEvent};
use gpui_component::list::ListItem;
use gpui_component::resizable::{resizable_panel, v_resizable};
use gpui_component::scroll::{ScrollableElement, Scrollbar};
@@ -5,6 +5,7 @@
use std::rc::Rc;
use assets::CustomIconName;
use dock::{Panel, PanelEvent};
use gpui::prelude::*;
use gpui::{
AnyElement, App, Context, Entity, EventEmitter, FocusHandle, Focusable, Pixels, Render,
@@ -13,7 +14,6 @@ use gpui::{
use gpui_component::avatar::Avatar;
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::dialog::{DialogDescription, DialogFooter, DialogHeader, DialogTitle};
use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::form::{field, v_form};
use gpui_component::input::{Input, InputState, Textarea, TextareaState};
use gpui_component::scroll::Scrollbar;
@@ -5,6 +5,7 @@ use std::sync::Arc;
use anyhow::Error;
use assets::CustomIconName;
use dock::{DockArea, DockPlacement, Panel, PanelEvent};
use gix::Repository;
use gpui::prelude::*;
use gpui::{
@@ -16,7 +17,6 @@ use gpui_component::button::{Button, ButtonVariants};
use gpui_component::combobox::{
Caret, Combobox, ComboboxEvent, ComboboxState, ComboboxTriggerContext,
};
use gpui_component::dock::{DockArea, DockPlacement, Panel, PanelEvent};
use gpui_component::searchable_list::SearchableVec;
use gpui_component::tab::{Tab, TabBar};
use gpui_component::tag::Tag;
@@ -13,7 +13,7 @@ use gpui::{
use gpui_component::avatar::Avatar;
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::dialog::{DialogDescription, DialogFooter, DialogHeader, DialogTitle};
use gpui_component::dock::{Panel, PanelEvent};
use dock::{Panel, PanelEvent};
use gpui_component::form::{field, v_form};
use gpui_component::input::{Input, InputState, Textarea, TextareaState};
use gpui_component::scroll::Scrollbar;
+1 -1
View File
@@ -7,7 +7,7 @@ use gpui::{
SharedString, Size, Subscription, WeakEntity, Window, div, px, size,
};
use gpui_component::avatar::Avatar;
use gpui_component::dock::{DockArea, DockPlacement, Panel, PanelEvent};
use dock::{DockArea, DockPlacement, Panel, PanelEvent};
use gpui_component::scroll::Scrollbar;
use gpui_component::{
ActiveTheme, Sizable, StyledExt, VirtualListScrollHandle, h_flex, v_flex, v_virtual_list,
+1 -1
View File
@@ -8,7 +8,7 @@ use gpui::{
};
use gpui_component::avatar::Avatar;
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::dock::{DockArea, DockPlacement, Panel, PanelEvent};
use dock::{DockArea, DockPlacement, Panel, PanelEvent};
use gpui_component::input::InputState;
use gpui_component::{ActiveTheme, Icon, IconName, Sizable, StyledExt, h_flex, v_flex};
use signed_state::{Backend, BackendEvent, ProfileStore};
+2 -3
View File
@@ -1,10 +1,10 @@
use std::sync::Arc;
use assets::CustomIconName;
use dock::{DockArea, DockItem};
use gpui::prelude::*;
use gpui::{Context, Entity, Render, SharedString, Subscription, Window, div, px};
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::dock::{DockArea, DockItem};
use gpui_component::{ActiveTheme, Root, Sizable, StyledExt, Theme, TitleBar, h_flex, v_flex};
use signed_state::{Backend, BackendEvent};
@@ -22,8 +22,7 @@ pub struct Workspace {
impl Workspace {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let dock = cx.new(|cx| {
DockArea::new("dock", Some(1), window, cx)
.panel_style(gpui_component::dock::PanelStyle::TabBar)
DockArea::new("dock", Some(1), window, cx).panel_style(dock::PanelStyle::TabBar)
});
let weak_dock = dock.downgrade();
+1
View File
@@ -19,6 +19,7 @@ gpui_platform.workspace = true
gpui_linux.workspace = true
gpui_windows.workspace = true
gpui_macos.workspace = true
dock = { workspace = true }
gpui-component.workspace = true
reqwest_client.workspace = true
log.workspace = true
+4
View File
@@ -19,6 +19,10 @@ fn main() {
// Initialize components
gpui_component::init(cx);
// Initialize the dock (registers the panel registry used to
// deserialize persisted layouts).
dock::init(cx);
// Initialize theme
theme::init(cx);