Struct scribe::Workspace
[−]
[src]
pub struct Workspace { pub path: PathBuf, pub syntax_set: SyntaxSet, // some fields omitted }
An owned collection of buffers and associated path, representing a running editor environment.
Fields
path: PathBuf
syntax_set: SyntaxSet
Methods
impl Workspace
[src]
fn new(path: &Path) -> Result<Workspace>
[src]
Creates a new empty workspace for the specified path.
fn add_buffer(&mut self, buf: Buffer)
[src]
Adds a buffer to the workspace, inserting it after the
current buffer, populates its id
field with a unique
value (relative to the workspace), and selects it.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf);
fn open_buffer(&mut self, path: &Path) -> Result<()>
[src]
Opens a buffer at the specified path, inserting it after the current buffer, and selects it. The path is converted to its canonical, absolute equivalent; if a buffer with the specified path already exists, it is selected, rather than opening a duplicate buffer. Any errors encountered while opening the buffer are returned.
Examples
use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Open a buffer in the workspace. workspace.open_buffer(file_path.clone());
fn current_buffer(&mut self) -> Option<&mut Buffer>
[src]
Returns a mutable reference to the currently selected buffer, unless the workspace is empty.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Get a reference to the current buffer. let buffer_reference = workspace.current_buffer().unwrap();
fn current_buffer_path(&self) -> Option<&Path>
[src]
Returns a reference to the current buffer's path.
If the path can be represented relative to the workspace path, a relative path will be returned. Otherwise, the buffer path is returned as-is.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); assert_eq!(workspace.current_buffer_path(), Some(Path::new("file")));
fn close_current_buffer(&mut self)
[src]
Removes the currently selected buffer from the collection. If the workspace is empty, this method does nothing.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Close the current buffer. workspace.close_current_buffer();
fn previous_buffer(&mut self)
[src]
Selects the previous buffer in the workspace (buffers are ordered as they are added to the workspace). If the currently selected buffer is the first in the collection, this will wrap and select the last buffer.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Select the previous buffer. workspace.previous_buffer();
fn next_buffer(&mut self)
[src]
Selects the next buffer in the workspace (buffers are ordered as they are added to the workspace). If the currently selected buffer is the last in the collection, this will wrap and select the first buffer.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path).unwrap(); workspace.add_buffer(buf); // Select the next buffer. workspace.next_buffer();
fn contains_buffer_with_path(&self, path: &Path) -> bool
[src]
Whether or not the workspace contains a buffer with the specified path. The path is converted to its canonical, absolute equivalent before comparison.
Examples
use scribe::Buffer; use scribe::Workspace; use std::path::Path; // Set up the paths we'll use. let directory_path = Path::new("tests/sample"); let file_path = Path::new("tests/sample/file"); // Create a workspace. let mut workspace = Workspace::new(directory_path).unwrap(); // Add a buffer to the workspace. let buf = Buffer::from_file(file_path.clone()).unwrap(); workspace.add_buffer(buf); assert!(workspace.contains_buffer_with_path(&file_path));