pub fn message(x: i32, y: i32, txt: &str)
Expand description
Displays a message box
Examples found in repository?
examples/editor.rs (line 433)
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {name} - RustyEd"));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}