6ef13b2cc8a6
side.rs
use super::{Stroke, Tokens, Ui, Value, WordApp, json, regular};
/// Items collected by Copy and Cut, newest first; clicking one pastes it at the caret.
pub(super) fn clipboard(app: &mut WordApp, ui: &mut Ui) {
let items: Vec<String> = app.session.clip_history.items().iter().map(|i| i.preview()).collect();
ui.horizontal_wrapped(|ui| {
if ui.add_enabled(!items.is_empty(), egui::Button::new(tl!("Paste All"))).clicked() {
let _ = app.run("edit.pasteAllClipboard", json!({}));
app.canvas.want_focus = true;
}
if ui.add_enabled(!items.is_empty(), egui::Button::new(tl!("Clear All"))).clicked() {
let _ = app.run("edit.clearClipboard", json!({}));
app.canvas.want_focus = true;
}
});
ui.add_space(4.0);
let hint = if items.is_empty() { "Nothing collected yet. Items you copy or cut appear here." } else { "Click an item to paste it." };
ui.label(egui::RichText::new(tl!(hint)).small().weak());
ui.separator();
let t = Tokens::get(ui.ctx());
egui::ScrollArea::vertical().show(ui, |ui| {
for (i, preview) in items.iter().enumerate() {
egui::Frame::NONE.fill(t.input).stroke(Stroke::new(1.0, t.border)).corner_radius(6).inner_margin(8).show(ui, |ui| {
ui.set_width(ui.available_width());
let text = if preview.is_empty() { tl!("(picture or object)").to_string() } else { preview.clone() };
let mut job =
egui::text::LayoutJob::single_section(text, egui::TextFormat { font_id: regular(12.5), color: t.text, ..Default::default() });
job.wrap.max_width = ui.available_width();
job.wrap.max_rows = 3;
if ui.add(egui::Button::new(job).frame(false)).on_hover_text(tl!("Paste")).clicked() {
let _ = app.run("edit.pasteClipboardItem", json!({"index": i}));
app.canvas.want_focus = true;
}
ui.with_layout(crate::rtl::far_side(ui, egui::Align::Min), |ui| {
if ui.small_button(tl!("Delete")).clicked() {
let _ = app.run("edit.deleteClipboardItem", json!({"index": i}));
app.canvas.want_focus = true;
}
});
});
ui.add_space(6.0);
}
});
}
pub(super) fn styles(app: &mut WordApp, ui: &mut Ui) {
let st = app.session.run("format.state", &json!({})).unwrap_or_default();
let cur = st.get("style").and_then(Value::as_str).unwrap_or("Normal").to_string();
let current_name = app
.session
.doc
.styles
.get(&cur)
.map(crate::i18n::style_name)
.unwrap_or_else(|| st.get("styleName").and_then(Value::as_str).unwrap_or("").to_string());
ui.label(egui::RichText::new(crate::i18n::fmt(tl!("Current style: {style}"), &[("style", ¤t_name)])).small());
// Wrapped: the host gives the pane a fixed width, and the row is wider than its default.
ui.horizontal_wrapped(|ui| {
if ui.button(tl!("New Style…")).clicked() {
app.dialog = crate::dialogs::Dialog::open("newStyle", app);
}
if ui.button(tl!("Update to Match")).clicked() {
let _ = app.run("styles.updateToMatch", json!({}));
}
if ui.button(tl!("Clear")).clicked() {
let _ = app.run("format.clear", json!({}));
}
});
if ui.button(tl!("Manage Styles…")).clicked() {
let _ = app.run("styles.manage", json!({}));
}
if ui.selectable_label(app.session.view.style_inspector, tl!("Style Inspector")).clicked() {
let _ = app.run("styles.inspector", json!({}));
}
// A solid scroll bar takes its own room beside the list instead of floating over the a / ¶ markers.
// Its handle keeps the text colour: the solid default fills it like a button, white on white here.
ui.spacing_mut().scroll = egui::style::ScrollStyle { foreground_color: true, ..egui::style::ScrollStyle::solid() };
ui.separator();
let mut list: Vec<(String, String, bool, bool)> = app
.session
.doc
.styles
.styles
.iter()
.filter(|s| !s.hidden && s.kind != wordcraft_doc::StyleKind::Table)
.map(|s| (s.id.clone(), crate::i18n::style_name(s), s.kind == wordcraft_doc::StyleKind::Character, s.builtin))
.collect();
list.sort_by_key(|s| s.1.to_lowercase());
egui::ScrollArea::vertical().show(ui, |ui| {
for (id, name, is_char, builtin) in list {
ui.horizontal(|ui| {
let r = ui.selectable_label(id == cur, &name);
ui.with_layout(crate::rtl::far_side(ui, egui::Align::Center), |ui| {
ui.label(egui::RichText::new(if is_char { "a" } else { "¶" }).weak());
});
if r.clicked() {
let _ = app.run("para.style", json!({"style": id}));
app.canvas.want_focus = true;
}
crate::rtl::context_menu(&r, |ui| {
if ui.button(tl!("Modify…")).clicked() {
app.dialog = crate::dialogs::Dialog::modify_style(app, &id);
ui.close();
}
if ui.button(tl!("Update to Match Selection")).clicked() {
let _ = app.run("styles.updateToMatch", json!({"style": id}));
app.canvas.want_focus = true;
ui.close();
}
if ui.add_enabled(!builtin, egui::Button::new(tl!("Delete"))).clicked() {
let _ = app.run("styles.delete", json!({"style": id}));
app.canvas.want_focus = true;
ui.close();
}
});
});
}
});
}
No file is open. Choose one in the tree, or press Ctrl+O (⌘O on a Mac) to find one by name.
Syntax highlighting could not load. The unmodified read-only text remains available above.