Struct scribe::Workspace [] [src]

pub struct Workspace {
    pub path: PathBuf,
    // some fields omitted
}

An owned collection of buffers and associated path, representing a running editor environment.

Fields

path: PathBuf

Methods

impl Workspace
[src]

fn new(path: PathBuf) -> Workspace

Creates a new empty workspace for the specified path.

fn add_buffer(&mut self, buf: Buffer)

Adds a buffer to the workspace and selects it.

Examples

use scribe::Buffer;
use scribe::Workspace;
use std::path::PathBuf;

// Set up the paths we'll use.
let directory_path = PathBuf::from("tests/sample");
let file_path = PathBuf::from("tests/sample/file");

// Create a workspace.
let mut workspace = Workspace::new(directory_path);

// Add a buffer to the workspace.
let buf = Buffer::from_file(file_path).unwrap();
workspace.add_buffer(buf);

fn open_buffer(&mut self, path: PathBuf) -> Option<Error>

Opens a buffer at the specified path and selects it. 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::PathBuf;

// Set up the paths we'll use.
let directory_path = PathBuf::from("tests/sample");
let file_path = PathBuf::from("tests/sample/file");

// Create a workspace.
let mut workspace = Workspace::new(directory_path);

// Open a buffer in the workspace.
workspace.open_buffer(file_path.clone());

fn current_buffer(&mut self) -> Option<&mut Buffer>

Returns a mutable reference to the currently selected buffer, unless the workspace is empty.

Examples

use scribe::Buffer;
use scribe::Workspace;
use std::path::PathBuf;

// Set up the paths we'll use.
let directory_path = PathBuf::from("tests/sample");
let file_path = PathBuf::from("tests/sample/file");

// Create a workspace.
let mut workspace = Workspace::new(directory_path);

// 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 close_current_buffer(&mut self)

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::PathBuf;

// Set up the paths we'll use.
let directory_path = PathBuf::from("tests/sample");
let file_path = PathBuf::from("tests/sample/file");

// Create a workspace.
let mut workspace = Workspace::new(directory_path);

// 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)

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::PathBuf;

// Set up the paths we'll use.
let directory_path = PathBuf::from("tests/sample");
let file_path = PathBuf::from("tests/sample/file");

// Create a workspace.
let mut workspace = Workspace::new(directory_path);

// 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)

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::PathBuf;

// Set up the paths we'll use.
let directory_path = PathBuf::from("tests/sample");
let file_path = PathBuf::from("tests/sample/file");

// Create a workspace.
let mut workspace = Workspace::new(directory_path);

// 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: &PathBuf) -> bool

Whether or not the workspace contains a buffer with the specified path.

Examples

use scribe::Buffer;
use scribe::Workspace;
use std::path::PathBuf;

// Set up the paths we'll use.
let directory_path = PathBuf::from("tests/sample");
let file_path = PathBuf::from("tests/sample/file");

// Create a workspace.
let mut workspace = Workspace::new(directory_path);

// 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));