### Integration Example: Applying Dark Scheme to View Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md Demonstrates applying a dark color scheme to a source view. This example initializes a view, gets a scheme, and sets it on the buffer. ```rust use sourceview5::{View, StyleSchemeManager}; let view = View::builder() .show_line_numbers(true) .highlight_current_line(true) .build(); let buffer = view.buffer(); let manager = StyleSchemeManager::default(); // Apply dark scheme if let Some(scheme) = manager.scheme("builder-dark") { buffer.set_property("style-scheme", &scheme); } ``` -------------------------------- ### Basic Cargo.toml Setup for Sourceview5 Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md Add the sourceview5 crate and its dependencies to your Cargo.toml file for basic integration. ```toml [dependencies] sourceview5 = "0.12.0-alpha" gtk4 = "0.12.0-alpha" glib = "0.23.0-alpha" ``` -------------------------------- ### Common Configurations Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md Examples of common search configurations. ```APIDOC ## Common Configurations ### Case-Insensitive Search ```rust let settings = SearchSettings::new(); settings.set_search_text("error"); settings.set_case_sensitive(false); ``` ### Regular Expression Search ```rust let settings = SearchSettings::new(); settings.set_search_text(r"^fn\s+\w+\s*("); settings.set_regex_enabled(true); ``` ### Whole Word Search ```rust let settings = SearchSettings::new(); settings.set_search_text("match"); settings.set_at_word_boundaries(true); ``` ``` -------------------------------- ### Complete Search Example with Sourceview5 Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/search-settings.md Demonstrates setting up a buffer, configuring SearchSettings for case-insensitive search, and iterating through matches using SearchContext. ```rust use sourceview5::{SearchSettings, SearchContext, Buffer}; let buffer = Buffer::new(None); buffer.set_text("Hello World\nhello world\nHELLO WORLD"); let settings = SearchSettings::builder() .search_text("hello") .case_sensitive(false) .wrap_around(true) .build(); let context = SearchContext::new(&buffer, Some(&settings)); let mut iter = buffer.start_iter(); while let Some((start, end, _)) = context.forward(&iter) { println!("Match at {}..{}", start.offset(), end.offset()); iter = end; } ``` -------------------------------- ### Integration with View Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme-manager.md Example demonstrating how to integrate StyleSchemeManager with a View to set color schemes and languages. ```APIDOC ## Integration with View ```rust use sourceview5::{View, StyleSchemeManager, Buffer, LanguageManager}; let view = View::new(); let buffer = view.buffer(); // Set a color scheme let style_manager = StyleSchemeManager::default(); if let Some(scheme) = style_manager.scheme("builder-dark") { buffer.set_property("style-scheme", &scheme); } // Set a language for syntax highlighting let lang_manager = LanguageManager::default(); if let Some(lang) = lang_manager.language("rust") { buffer.set_language(Some(&lang)); } ``` ``` -------------------------------- ### BackgroundPatternType Enum and Example Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/types.md Specifies the background pattern for the editor. The example shows how to set the grid pattern when building a `View`. ```rust pub enum BackgroundPatternType { None, Grid, __Unknown(i32), } ``` ```rust use sourceview5::{View, BackgroundPatternType}; let view = View::builder() .background_pattern(BackgroundPatternType::Grid) .build(); ``` -------------------------------- ### Documentation Hover Provider Example Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/hover.md A sample implementation of a HoverProvider that displays documentation for a symbol at the cursor. It includes placeholder logic for looking up documentation. ```rust pub struct DocsHoverProvider; impl HoverProviderExt for DocsHoverProvider { fn populate( &self, context: &HoverContext, display: &HoverDisplay, ) -> bool { // Extract symbol at cursor let iter = context.iter(); let buffer = context.buffer(); // Look up documentation from language server or database let docs = lookup_docs(iter, buffer); // Assuming lookup_docs is defined elsewhere if !docs.is_empty() { let label = gtk::Label::new(Some(&docs)); label.set_wrap(true); display.append(&label); true } else { false } } } ``` -------------------------------- ### Complete File Loading Workflow Example Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/file-loader.md Demonstrates the full process of loading a file asynchronously, including querying file info, opening a stream, creating a buffer with language detection, and initiating the load. ```rust use sourceview5::{Buffer, FileLoader, LanguageManager, StyleSchemeManager}; use gio::File; let file_path = "src/main.rs"; let file = File::for_path(file_path); // Query file information let file_info = file.query_info( "*", gio::FileQueryInfoFlags::NONE, None::<&gio::Cancellable>, )?; // Open file for reading let stream = file.read(None::<&gio::Cancellable>)?; // Create buffer with appropriate language let buffer = { let manager = LanguageManager::default(); let language = manager.guess_language(Some(file_path), None); let buf = Buffer::new(None); if let Some(lang) = language { buf.set_language(Some(&lang)); } buf }; // Load file let loader = FileLoader::new(&file_info, &stream, &buffer, &file); loader.load_async( gio::glib::PRIORITY_DEFAULT, None, |result| { match result { Ok(()) => println!("Loaded {}", file_path), Err(e) => eprintln!("Failed to load {}: {}", file_path, e), } }, ); ``` -------------------------------- ### Cargo.toml Setup with Version Features Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/configuration.md Configure sourceview5 and its dependencies with specific version features in Cargo.toml to target particular GtkSourceView and GTK4 versions. ```toml [dependencies] sourceview5 = { version = "0.12.0-alpha", features = ["v5_18", "gtk_v4_18"] } gtk4 = { version = "0.12.0-alpha", features = ["v4_18"] } glib = "0.23.0-alpha" ``` -------------------------------- ### Custom Color Schemes Source: https://github.com/world/rust/sourceview5-rs/blob/main/_autodocs/api-reference/style-scheme.md Explains how to create and use custom color schemes by providing an XML example and steps to integrate them. ```APIDOC ## Custom Color Schemes Create custom schemes by adding `.xml` files to scheme search paths: ```xml