Skip to main content

Action

Struct Action 

Source
pub struct Action(/* private fields */);
Expand description

Something people can do. A handle: the frame and its controller hold the same action, so a controller can turn it off by a reason of its own.

use ravenrs_app::{Action, ActionCategory, CriteriaMode, Selection};

let pay = Action::simple("Pay", "Pagar")
    .category(ActionCategory::Edit)
    .target_entity("Bill")
    .selection(Selection::RequireMultiple)
    .target_criteria("[Status] = 'Open'", CriteriaMode::TrueForAll)
    .on_execute(|cx| {
        for bill in &cx.selected {
            let mut bill = bill.clone();
            bill.set("Status", "Paid");
            cx.space.borrow_mut().save(bill).map_err(|e| e.to_string())?;
        }
        cx.space.borrow_mut().commit().map_err(|e| e.to_string())
    });
assert_eq!(pay.caption(), "Pagar");

Implementations§

Source§

impl Action

Source

pub fn simple(id: impl Into<String>, caption: impl Into<String>) -> Self

A button: it just runs.

Source

pub fn background( id: impl Into<String>, caption: impl Into<String>, work: impl Fn(&JobContext) -> Result<(), String> + Send + Sync + 'static, ) -> Self

A button whose work runs away from the screen, on a thread of its own: it shows how far it got, can be stopped, and what it hands back is kept on the screen’s thread. While it runs, the action is off, so it never runs twice at once.

use ravenrs_app::{Action, Selection};

let archive = Action::background("Archive", "Arquivar", |job| {
    for record in job.selected() {
        let mut record = record.clone();
        record.set("Archived", true);
        job.save(record);
    }
    Ok(())
})
.selection(Selection::RequireMultiple);
assert!(archive.is_background());
Source

pub fn popup( id: impl Into<String>, caption: impl Into<String>, view: impl Into<String>, ) -> Self

Opens a view in a window, and runs on OK.

Source

pub fn single_choice( id: impl Into<String>, caption: impl Into<String>, items: Vec<ChoiceItem>, ) -> Self

Offers these options, and runs with the one picked.

Source

pub fn parametrized( id: impl Into<String>, caption: impl Into<String>, kind: FieldKind, ) -> Self

Asks for a value of this kind, and runs with it.

Source

pub fn url( id: impl Into<String>, caption: impl Into<String>, template: impl Into<String>, ) -> Self

Opens an address made from the selected record, where {field} takes its value.

Source

pub fn in_background( self, work: impl Fn(&JobContext) -> Result<(), String> + Send + Sync + 'static, ) -> Self

Runs this work away from the screen once it runs, after on_execute, with what people gave it. See Action::background.

Source

pub fn is_background(&self) -> bool

Whether its work runs away from the screen.

Source

pub fn category(self, category: ActionCategory) -> Self

Where it belongs.

Source

pub fn target_entity(self, entity: impl Into<String>) -> Self

Only on views of this entity.

Source

pub fn target_view(self, id: impl Into<String>) -> Self

Only on the view with this id.

Source

pub fn target_view_kind(self, kind: ViewKind) -> Self

Only on views of this kind.

Source

pub fn nesting(self, nesting: Nesting) -> Self

Only on root views, or only on nested ones.

Source

pub fn selection(self, selection: Selection) -> Self

What it needs selected.

Source

pub fn target_criteria( self, criteria: impl Into<String>, mode: CriteriaMode, ) -> Self

What the selected records have to meet. With nothing selected, it does not stop anything; selection says whether something has to be.

Source

pub fn validation_contexts( self, contexts: impl IntoIterator<Item = impl Into<String>>, ) -> Self

The validation contexts to pass before it runs.

Source

pub fn confirmation(self, text: impl Into<String>) -> Self

A question to ask before it runs.

Source

pub fn confirmation_words( self, detail: impl Into<String>, answer: impl Into<String>, ) -> Self

What the question says besides, and what the answer that runs it says.

Source

pub fn on_prepare( self, handler: impl Fn(&ActionContext, &mut Object) + 'static, ) -> Self

For a popup that opens a form: fills in the record it starts with.

Source

pub fn requires(self, operation: Operation) -> Self

What it does to the records of its view, so it fades for who cannot. The secured space refuses it anyway.

Source

pub fn hotkey(self, keys: impl Into<String>) -> Self

The keys that run it, in the words of whoever shows it.

Source

pub fn icon(self, icon: impl Into<String>) -> Self

The name of its icon.

Source

pub fn accessible_name(self, name: impl Into<String>) -> Self

What screen readers call it, instead of its caption: for a caption that only makes sense on the screen, such as an arrow.

Source

pub fn accessible_description(self, text: impl Into<String>) -> Self

What screen readers say after its name, such as what it does to the selected records.

Source

pub fn on_execute( self, handler: impl Fn(&ActionContext) -> Result<(), String> + 'static, ) -> Self

What it does.

Source

pub fn assign(self, entity: &EntityInfo, set: &str) -> Self

Runs as an update: sets fields of every record selected of this entity, as field = expression; ..., each read from the record as it was; checks them against the rules of Save, and keeps them all or none. What does not parse, or names a field the entity has not, is found when the application is put together.

use ravenrs_app::{Action, EntityInfo, FieldInfo, FieldKind, Selection};

let task = EntityInfo::new("Task")
    .field(FieldInfo::new("id", FieldKind::Integer).key())
    .field(FieldInfo::new("state", FieldKind::Text));
let finish = Action::simple("Finish", "Concluir")
    .target_entity("Task")
    .selection(Selection::RequireMultiple)
    .assign(&task, "state = 'done'");
assert_eq!(finish.caption(), "Concluir");
Source

pub fn on_cancel(self, handler: impl Fn(&ActionContext) + 'static) -> Self

What a popup does when canceled.

Source

pub fn on_executing( self, guard: impl Fn(&ActionContext) -> bool + 'static, ) -> Self

Asked before it runs; false stops it.

Source

pub fn on_executed(self, notice: impl Fn(&ActionContext) + 'static) -> Self

Told after it ran.

Source

pub fn id(&self) -> &str

Its id.

Source

pub fn caption(&self) -> &str

What people see.

Source

pub fn kind(&self) -> &ActionKind

How it asks for what it needs.

Source

pub fn action_category(&self) -> &ActionCategory

Where it belongs.

Source

pub fn confirmation_text(&self) -> Option<&str>

The question to ask before it runs.

Source

pub fn confirmation_detail(&self) -> Option<&str>

What the question says besides.

Source

pub fn confirmation_answer(&self) -> Option<&str>

What the answer that runs it says.

Source

pub fn required_operation(&self) -> Option<Operation>

What it does to the records of its view, if it said.

Source

pub fn hotkey_text(&self) -> Option<&str>

The keys that run it.

Source

pub fn icon_name(&self) -> Option<&str>

The name of its icon.

Source

pub fn accessible_name_text(&self) -> Option<&str>

What screen readers call it, when it is not its caption.

Source

pub fn accessible_description_text(&self) -> Option<&str>

What screen readers say after its name, when anything.

Source

pub fn contexts(&self) -> &[String]

The validation contexts to pass before it runs.

Source

pub fn is_active(&self) -> bool

Whether it is in place. If not, it is not shown.

Source

pub fn is_enabled(&self) -> bool

Whether it can be used. If not, it is shown faded.

Source

pub fn active_reasons(&self) -> Reasons

Why it is or is not in place.

Source

pub fn enabled_reasons(&self) -> Reasons

Why it can or cannot be used.

Source

pub fn set_active(&self, reason: &str, on: bool)

Gives a reason for it being in place or not.

Source

pub fn set_enabled(&self, reason: &str, on: bool)

Gives a reason for it being usable or not. Prefer this to set_active when it depends on the record: taking a button away moves the ones beside it, and people click the wrong one.

Trait Implementations§

Source§

impl Clone for Action

Source§

fn clone(&self) -> Action

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Action

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Action

§

impl !Send for Action

§

impl !Sync for Action

§

impl !UnwindSafe for Action

§

impl Freeze for Action

§

impl Unpin for Action

§

impl UnsafeUnpin for Action

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.