edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | use ; |
| 2 | use HashMap; |
| 3 | pub use Action; |
| 4 | pub use ; |
| 5 | use json; |
| 6 | use |
| 7 | |
| 8 | |
| 9 | ; |
| 10 | |
| 11 | /// Defines and registers unit structs that can be used as actions. For more complex data types, derive `Action`. |
| 12 | /// |
| 13 | /// For example: |
| 14 | /// |
| 15 | /// ``` |
| 16 | /// use gpui::actions; |
| 17 | /// actions!(editor, [MoveUp, MoveDown, MoveLeft, MoveRight, Newline]); |
| 18 | /// ``` |
| 19 | /// |
| 20 | /// This will create actions with names like `editor::MoveUp`, `editor::MoveDown`, etc. |
| 21 | /// |
| 22 | /// The namespace argument `editor` can also be omitted, though it is required for Zed actions. |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | ; |
| 40 | } |
| 41 | |
| 42 | /// Actions are used to implement keyboard-driven UI. When you declare an action, you can bind keys |
| 43 | /// to the action in the keymap and listeners for that action in the element tree. |
| 44 | /// |
| 45 | /// To declare a list of simple actions, you can use the actions! macro, which defines a simple unit |
| 46 | /// struct action for each listed action name in the given namespace. |
| 47 | /// |
| 48 | /// ``` |
| 49 | /// use gpui::actions; |
| 50 | /// actions!(editor, [MoveUp, MoveDown, MoveLeft, MoveRight, Newline]); |
| 51 | /// ``` |
| 52 | /// |
| 53 | /// Registering the actions with the same name will result in a panic during `App` creation. |
| 54 | /// |
| 55 | /// # Derive Macro |
| 56 | /// |
| 57 | /// More complex data types can also be actions, by using the derive macro for `Action`: |
| 58 | /// |
| 59 | /// ``` |
| 60 | /// use gpui::Action; |
| 61 | /// #[derive(Clone, PartialEq, serde::Deserialize, schemars::JsonSchema, Action)] |
| 62 | /// #[action(namespace = editor)] |
| 63 | /// pub struct SelectNext { |
| 64 | /// pub replace_newest: bool, |
| 65 | /// } |
| 66 | /// ``` |
| 67 | /// |
| 68 | /// The derive macro for `Action` requires that the type implement `Clone` and `PartialEq`. It also |
| 69 | /// requires `serde::Deserialize` and `schemars::JsonSchema` unless `#[action(no_json)]` is |
| 70 | /// specified. In Zed these trait impls are used to load keymaps from JSON. |
| 71 | /// |
| 72 | /// Multiple arguments separated by commas may be specified in `#[action(...)]`: |
| 73 | /// |
| 74 | /// - `namespace = some_namespace` sets the namespace. In Zed this is required. |
| 75 | /// |
| 76 | /// - `name = "ActionName"` overrides the action's name. This must not contain `::`. |
| 77 | /// |
| 78 | /// - `no_json` causes the `build` method to always error and `action_json_schema` to return `None`, |
| 79 | /// and allows actions not implement `serde::Serialize` and `schemars::JsonSchema`. |
| 80 | /// |
| 81 | /// - `no_register` skips registering the action. This is useful for implementing the `Action` trait |
| 82 | /// while not supporting invocation by name or JSON deserialization. |
| 83 | /// |
| 84 | /// - `deprecated_aliases = ["editor::SomeAction"]` specifies deprecated old names for the action. |
| 85 | /// These action names should *not* correspond to any actions that are registered. These old names |
| 86 | /// can then still be used to refer to invoke this action. In Zed, the keymap JSON schema will |
| 87 | /// accept these old names and provide warnings. |
| 88 | /// |
| 89 | /// - `deprecated = "Message about why this action is deprecation"` specifies a deprecation message. |
| 90 | /// In Zed, the keymap JSON schema will cause this to be displayed as a warning. |
| 91 | /// |
| 92 | /// # Manual Implementation |
| 93 | /// |
| 94 | /// If you want to control the behavior of the action trait manually, you can use the lower-level |
| 95 | /// `#[register_action]` macro, which only generates the code needed to register your action before |
| 96 | /// `main`. |
| 97 | /// |
| 98 | /// ``` |
| 99 | /// use gpui::{SharedString, register_action}; |
| 100 | /// #[derive(Clone, PartialEq, Eq, serde::Deserialize, schemars::JsonSchema)] |
| 101 | /// pub struct Paste { |
| 102 | /// pub content: SharedString, |
| 103 | /// } |
| 104 | /// |
| 105 | /// impl gpui::Action for Paste { |
| 106 | /// # fn boxed_clone(&self) -> Box<dyn gpui::Action> { unimplemented!()} |
| 107 | /// # fn partial_eq(&self, other: &dyn gpui::Action) -> bool { unimplemented!() } |
| 108 | /// # fn name(&self) -> &'static str { "Paste" } |
| 109 | /// # fn name_for_type() -> &'static str { "Paste" } |
| 110 | /// # fn build(value: serde_json::Value) -> anyhow::Result<Box<dyn gpui::Action>> { |
| 111 | /// # unimplemented!() |
| 112 | /// # } |
| 113 | /// } |
| 114 | /// |
| 115 | /// register_action!(Paste); |
| 116 | /// ``` |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | /// Error type for `Keystroke::parse`. This is used instead of `anyhow::Error` so that Zed can use |
| 191 | /// markdown to display it. |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | type ActionBuilder = fn ; |
| 232 | |
| 233 | pub |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | /// This type must be public so that our macros can build it in other crates. |
| 265 | /// But this is an implementation detail and should not be used directly. |
| 266 | |
| 267 | ); |
| 268 | |
| 269 | /// This type must be public so that our macros can build it in other crates. |
| 270 | /// But this is an implementation detail and should not be used directly. |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | collect!; |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | /// Generate a list of all the registered actions. |
| 414 | /// Useful for transforming the list of available actions into a |
| 415 | /// format suited for static analysis such as in validating keymaps, or |
| 416 | /// generating documentation. |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 |