pub struct Stage { /* private fields */ }
Expand description
a staging area: selection of several paths for later user
The structure is versioned to allow caching of derived structs (filtered list mainly). This scheme implies the stage isn’t cloned, and that it exists in only one instance
Implementations§
source§impl Stage
impl Stage
sourcepub fn contains(&self, path: &Path) -> bool
pub fn contains(&self, path: &Path) -> bool
Examples found in repository?
More examples
src/app/panel_state.rs (line 609)
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
fn toggle_stage(
&self,
app_state: &mut AppState,
cc: &CmdContext,
con: &AppContext,
) -> CmdResult {
if let Some(path) = self.selected_path() {
if app_state.stage.contains(path) {
self.unstage(app_state, cc, con)
} else {
self.stage(app_state, cc, con)
}
} else {
CmdResult::error("no selection")
}
}
src/display/displayable_tree.rs (line 533)
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
pub fn write_on<W: Write>(&self, f: &mut W) -> Result<(), ProgramError> {
#[cfg(not(any(target_family = "windows", target_os = "android")))]
let perm_writer = super::PermWriter::for_tree(self.skin, self.tree);
let tree = self.tree;
let total_size = tree.total_sum();
let scrollbar = if self.in_app {
termimad::compute_scrollbar(
tree.scroll,
tree.lines.len() - 1, // the root line isn't scrolled
self.area.height - 1, // the scrollbar doesn't cover the first line
self.area.top + 1,
)
} else {
None
};
if self.in_app {
f.queue(cursor::MoveTo(self.area.left, self.area.top))?;
}
let mut cw = CropWriter::new(f, self.area.width as usize);
let pattern_object = tree.options.pattern.pattern.object();
self.write_root_line(&mut cw, self.in_app && tree.selection == 0)?;
self.skin.queue_reset(f)?;
let visible_cols: Vec<Col> = tree
.options
.cols_order
.iter()
.filter(|col| col.is_visible(tree, self.app_state))
.cloned()
.collect();
// if necessary we compute the width of the count column
let count_len = if tree.options.show_counts {
tree.lines.iter()
.skip(1) // we don't show the counts of the root
.map(|l| l.sum.map_or(0, |s| s.to_count()))
.max()
.map(|c| format_count(c).len())
.unwrap_or(0)
} else {
0
};
// we compute the length of the dates, depending on the format
let date_len = if tree.options.show_dates {
let date_time: DateTime<Local> = Local::now();
date_time.format(tree.options.date_time_format).to_string().len()
} else {
0 // we don't care
};
for y in 1..self.area.height {
if self.in_app {
f.queue(cursor::MoveTo(self.area.left, y + self.area.top))?;
} else {
write!(f, "\r\n")?;
}
let mut line_index = y as usize;
if line_index > 0 {
line_index += tree.scroll as usize;
}
let mut selected = false;
let mut cw = CropWriter::new(f, self.area.width as usize);
let cw = &mut cw;
if line_index < tree.lines.len() {
let line = &tree.lines[line_index];
selected = self.in_app && line_index == tree.selection;
let label_style = self.label_style(line, selected);
let mut in_branch = false;
let space_style = if selected {
&self.skin.selected_line
} else {
&self.skin.default
};
if visible_cols[0].needs_left_margin() {
cw.queue_char(space_style, ' ')?;
}
let staged = self.app_state
.map_or(false, |a| a.stage.contains(&line.path));
for col in &visible_cols {
let void_len = match col {
Col::Mark => {
self.write_line_selection_mark(cw, &label_style, selected)?
}
Col::Git => {
self.write_line_git_status(cw, line, selected)?
}
Col::Branch => {
in_branch = true;
self.write_branch(cw, line_index, line, selected, staged)?
}
Col::DeviceId => {
#[cfg(not(unix))]
{ 0 }
#[cfg(unix)]
self.write_line_device_id(cw, line, selected)?
}
Col::Permission => {
#[cfg(any(target_family = "windows", target_os = "android"))]
{ 0 }
#[cfg(not(any(target_family = "windows", target_os = "android")))]
perm_writer.write_permissions(cw, line, selected)?
}
Col::Date => {
if let Some(seconds) = line.sum.and_then(|sum| sum.to_valid_seconds()) {
self.write_date(cw, seconds, selected)?
} else {
date_len + 1
}
}
Col::Size => {
if tree.options.sort.prevent_deep_display() {
// as soon as there's only one level displayed we can show the size bars
self.write_line_size_with_bar(cw, line, &label_style, total_size, selected)?
} else {
self.write_line_size(cw, line, &label_style, selected)?
}
}
Col::Count => {
self.write_line_count(cw, line, count_len, selected)?
}
Col::Staged => {
self.write_line_stage_mark(cw, &label_style, staged)?
}
Col::Name => {
in_branch = false;
self.write_line_label(cw, line, &label_style, pattern_object, selected)?
}
};
// void: intercol & replacing missing cells
if in_branch && void_len > 2 {
cond_bg!(void_style, self, selected, self.skin.tree);
cw.repeat(void_style, &BRANCH_FILLING, void_len)?;
} else {
cond_bg!(void_style, self, selected, self.skin.default);
cw.repeat(void_style, &SPACE_FILLING, void_len)?;
}
}
if cw.allowed > 8 && pattern_object.content {
let extract = tree.options.pattern.pattern
.search_content(&line.path, cw.allowed - 2);
if let Some(extract) = extract {
self.write_content_extract(cw, extract, selected)?;
}
}
}
self.extend_line_bg(cw, selected)?;
self.skin.queue_reset(f)?;
if self.in_app {
if let Some((sctop, scbottom)) = scrollbar {
f.queue(cursor::MoveTo(self.area.left + self.area.width - 1, y))?;
let style = if sctop <= y && y <= scbottom {
&self.skin.scrollbar_thumb
} else {
&self.skin.scrollbar_track
};
style.queue_str(f, "▐")?;
}
}
}
if !self.in_app {
write!(f, "\r\n")?;
}
Ok(())
}
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Examples found in repository?
More examples
src/app/panel_state.rs (line 590)
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
fn unstage(
&self,
app_state: &mut AppState,
cc: &CmdContext,
_con: &AppContext,
) -> CmdResult {
if let Some(path) = self.selected_path() {
if app_state.stage.remove(path) && app_state.stage.is_empty() {
if let Some(panel_id) = cc.app.stage_panel {
return CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(panel_id),
};
}
}
}
CmdResult::Keep
}
fn toggle_stage(
&self,
app_state: &mut AppState,
cc: &CmdContext,
con: &AppContext,
) -> CmdResult {
if let Some(path) = self.selected_path() {
if app_state.stage.contains(path) {
self.unstage(app_state, cc, con)
} else {
self.stage(app_state, cc, con)
}
} else {
CmdResult::error("no selection")
}
}
fn execute_verb(
&mut self,
w: &mut W, // needed because we may want to switch from alternate in some externals
verb: &Verb,
invocation: Option<&VerbInvocation>,
trigger_type: TriggerType,
app_state: &mut AppState,
cc: &CmdContext,
) -> Result<CmdResult, ProgramError> {
if verb.needs_selection && !self.has_at_least_one_selection(app_state) {
return Ok(CmdResult::error("This verb needs a selection"));
}
if verb.needs_another_panel && app_state.other_panel_path.is_none() {
return Ok(CmdResult::error("This verb needs another panel"));
}
let res = match &verb.execution {
VerbExecution::Internal(internal_exec) => {
self.on_internal(
w,
internal_exec,
invocation,
trigger_type,
app_state,
cc,
)
}
VerbExecution::External(external) => {
self.execute_external(w, verb, external, invocation, app_state, cc)
}
VerbExecution::Sequence(seq_ex) => {
self.execute_sequence(w, verb, seq_ex, invocation, app_state, cc)
}
};
if res.is_ok() {
// if the stage has been emptied by the operation (eg a "rm"), we
// close it
app_state.stage.refresh();
if app_state.stage.is_empty() {
if let Some(id) = cc.app.stage_panel {
return Ok(CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
});
}
}
}
res
}
sourcepub fn add(&mut self, path: PathBuf) -> bool
pub fn add(&mut self, path: PathBuf) -> bool
return true when there’s a change
Examples found in repository?
src/app/panel_state.rs (line 568)
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
fn stage(
&self,
app_state: &mut AppState,
cc: &CmdContext,
con: &AppContext,
) -> CmdResult {
if let Some(path) = self.selected_path() {
let path = path.to_path_buf();
app_state.stage.add(path);
if cc.app.stage_panel.is_none() {
return CmdResult::NewPanel {
state: Box::new(StageState::new(app_state, self.tree_options(), con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
};
}
} else {
// TODO display error ?
warn!("no path in state");
}
CmdResult::Keep
}
More examples
src/browser/browser_state.rs (line 690)
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
fn do_pending_task(
&mut self,
app_state: &mut AppState,
screen: Screen,
con: &AppContext,
dam: &mut Dam,
) -> Result<(), ProgramError> {
if let Some(pending_task) = self.pending_task.take() {
match pending_task {
BrowserTask::Search { pattern, total } => {
let pattern_str = pattern.raw.clone();
let mut options = self.tree.options.clone();
options.pattern = pattern;
let root = self.tree.root().clone();
let page_height = BrowserState::page_height(screen) as usize;
let builder = TreeBuilder::from(root, options, page_height, con)?;
let filtered_tree = time!(
Info,
"tree filtering",
&pattern_str,
builder.build_tree(total, dam),
);
if let Ok(mut ft) = filtered_tree {
ft.try_select_best_match();
ft.make_selection_visible(BrowserState::page_height(screen));
self.filtered_tree = Some(ft);
}
}
BrowserTask::StageAll(pattern) => {
let tree = self.displayed_tree();
let root = tree.root().clone();
let mut options = tree.options.clone();
let total_search = true;
options.pattern = pattern; // should be the same
let builder = TreeBuilder::from(root, options, con.max_staged_count, con);
let mut paths = builder
.and_then(|mut builder| {
builder.matches_max = Some(con.max_staged_count);
time!(builder.build_paths(
total_search,
dam,
|line| line.file_type.is_file(),
))
})?;
for path in paths.drain(..) {
app_state.stage.add(path);
}
}
}
} else if self.displayed_tree().is_missing_git_status_computation() {
let root_path = self.displayed_tree().root();
let git_status = git::get_tree_status(root_path, dam);
self.displayed_tree_mut().git_status = git_status;
} else {
self.displayed_tree_mut().fetch_some_missing_dir_sum(dam, con);
}
Ok(())
}
sourcepub fn remove(&mut self, path: &Path) -> bool
pub fn remove(&mut self, path: &Path) -> bool
return true when there’s a change
Examples found in repository?
src/app/panel_state.rs (line 590)
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
fn unstage(
&self,
app_state: &mut AppState,
cc: &CmdContext,
_con: &AppContext,
) -> CmdResult {
if let Some(path) = self.selected_path() {
if app_state.stage.remove(path) && app_state.stage.is_empty() {
if let Some(panel_id) = cc.app.stage_panel {
return CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(panel_id),
};
}
}
}
CmdResult::Keep
}
sourcepub fn remove_idx(&mut self, idx: usize)
pub fn remove_idx(&mut self, idx: usize)
Examples found in repository?
src/stage/filtered_stage.rs (line 133)
131 132 133 134 135 136 137 138 139 140 141 142 143
pub fn unstage_selection(&mut self, stage: &mut Stage) -> bool {
if let Some(spi) = self.selection {
stage.remove_idx(self.paths_idx[spi]);
self.stage_version = stage.version();
self.compute(stage);
if spi >= self.paths_idx.len() {
self.selection = Some(spi);
};
true
} else {
false
}
}
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Examples found in repository?
src/app/panel_state.rs (line 503)
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 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 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
fn on_internal_generic(
&mut self,
_w: &mut W,
internal_exec: &InternalExecution,
input_invocation: Option<&VerbInvocation>,
_trigger_type: TriggerType,
app_state: &mut AppState,
cc: &CmdContext,
) -> Result<CmdResult, ProgramError> {
let con = &cc.app.con;
let screen = cc.app.screen;
let bang = input_invocation
.map(|inv| inv.bang)
.unwrap_or(internal_exec.bang);
Ok(match internal_exec.internal {
Internal::back => CmdResult::PopState,
Internal::copy_line | Internal::copy_path => {
#[cfg(not(feature = "clipboard"))]
{
CmdResult::error("Clipboard feature not enabled at compilation")
}
#[cfg(feature = "clipboard")]
{
if let Some(path) = self.selected_path() {
let path = path.to_string_lossy().to_string();
match terminal_clipboard::set_string(path) {
Ok(()) => CmdResult::Keep,
Err(_) => CmdResult::error("Clipboard error while copying path"),
}
} else {
CmdResult::error("Nothing to copy")
}
}
}
Internal::close_panel_ok => CmdResult::ClosePanel {
validate_purpose: true,
panel_ref: PanelReference::Active,
},
Internal::close_panel_cancel => CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Active,
},
#[cfg(unix)]
Internal::filesystems => {
let fs_state = crate::filesystems::FilesystemState::new(
self.selected_path(),
self.tree_options(),
con,
);
match fs_state {
Ok(state) => {
let bang = input_invocation
.map(|inv| inv.bang)
.unwrap_or(internal_exec.bang);
if bang && cc.app.preview_panel.is_none() {
CmdResult::NewPanel {
state: Box::new(state),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
} else {
CmdResult::new_state(Box::new(state))
}
}
Err(e) => CmdResult::DisplayError(format!("{}", e)),
}
}
Internal::help => {
let bang = input_invocation
.map(|inv| inv.bang)
.unwrap_or(internal_exec.bang);
if bang && cc.app.preview_panel.is_none() {
CmdResult::NewPanel {
state: Box::new(HelpState::new(self.tree_options(), screen, con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
} else {
CmdResult::new_state(Box::new(
HelpState::new(self.tree_options(), screen, con)
))
}
}
Internal::mode_input => self.on_mode_verb(Mode::Input, con),
Internal::mode_command => self.on_mode_verb(Mode::Command, con),
Internal::open_leave => {
if let Some(selection) = self.selection() {
selection.to_opener(con)?
} else {
CmdResult::error("no selection to open")
}
}
Internal::open_preview => self.open_preview(None, false, cc),
Internal::preview_image => self.open_preview(Some(PreviewMode::Image), false, cc),
Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc),
Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc),
Internal::toggle_preview => self.open_preview(None, true, cc),
Internal::sort_by_count => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::Count {
o.sort = Sort::None;
o.show_counts = false;
"*not sorting anymore*"
} else {
o.sort = Sort::Count;
o.show_counts = true;
"*now sorting by file count*"
}
},
bang,
con,
),
Internal::sort_by_date => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::Date {
o.sort = Sort::None;
o.show_dates = false;
"*not sorting anymore*"
} else {
o.sort = Sort::Date;
o.show_dates = true;
"*now sorting by last modified date*"
}
},
bang,
con,
),
Internal::sort_by_size => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::Size {
o.sort = Sort::None;
o.show_sizes = false;
"*not sorting anymore*"
} else {
o.sort = Sort::Size;
o.show_sizes = true;
o.show_root_fs = true;
"*now sorting files and directories by total size*"
}
},
bang,
con,
),
Internal::sort_by_type => self.with_new_options(
screen,
&|o| {
match o.sort {
Sort::TypeDirsFirst => {
o.sort = Sort::TypeDirsLast;
"*sorting by type, directories last*"
}
Sort::TypeDirsLast => {
o.sort = Sort::None;
"*not sorting anymore*"
}
_ => {
o.sort = Sort::TypeDirsFirst;
"*sorting by type, directories first*"
}
}
},
bang,
con,
),
Internal::sort_by_type_dirs_first => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::TypeDirsFirst {
o.sort = Sort::None;
"*not sorting anymore*"
} else {
o.sort = Sort::TypeDirsFirst;
"*now sorting by type, directories first*"
}
},
bang,
con,
),
Internal::sort_by_type_dirs_last => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::TypeDirsLast {
o.sort = Sort::None;
"*not sorting anymore*"
} else {
o.sort = Sort::TypeDirsLast;
"*now sorting by type, directories last*"
}
},
bang,
con,
),
Internal::no_sort => self.with_new_options(
screen,
&|o| {
if o.sort == Sort::None {
"*still not searching*"
} else {
o.sort = Sort::None;
"*not sorting anymore*"
}
},
bang,
con,
),
Internal::toggle_counts => {
self.with_new_options(
screen,
&|o| {
o.show_counts ^= true;
if o.show_counts {
"*displaying file counts*"
} else {
"*hiding file counts*"
}
},
bang,
con,
)
}
Internal::toggle_dates => {
self.with_new_options(
screen,
&|o| {
o.show_dates ^= true;
if o.show_dates {
"*displaying last modified dates*"
} else {
"*hiding last modified dates*"
}
},
bang,
con,
)
}
Internal::toggle_device_id => {
self.with_new_options(
screen,
&|o| {
o.show_device_id ^= true;
if o.show_device_id {
"*displaying device id*"
} else {
"*hiding device id*"
}
},
bang,
con,
)
}
Internal::toggle_files => {
self.with_new_options(
screen,
&|o| {
o.only_folders ^= true;
if o.only_folders {
"*displaying only directories*"
} else {
"*displaying both files and directories*"
}
},
bang,
con,
)
}
Internal::toggle_hidden => {
self.with_new_options(
screen,
&|o| {
o.show_hidden ^= true;
if o.show_hidden {
"h:**y** - *Hidden files displayed*"
} else {
"h:**n** - *Hidden files not displayed*"
}
},
bang,
con,
)
}
Internal::toggle_root_fs => {
self.with_new_options(
screen,
&|o| {
o.show_root_fs ^= true;
if o.show_root_fs {
"*displaying filesystem info for the tree's root directory*"
} else {
"*removing filesystem info*"
}
},
bang,
con,
)
}
Internal::toggle_git_ignore => {
self.with_new_options(
screen,
&|o| {
o.respect_git_ignore ^= true;
if o.respect_git_ignore {
"gi:**y** - *applying gitignore rules*"
} else {
"gi:**n** - *not applying gitignore rules*"
}
},
bang,
con,
)
}
Internal::toggle_git_file_info => {
self.with_new_options(
screen,
&|o| {
o.show_git_file_info ^= true;
if o.show_git_file_info {
"*displaying git info next to files*"
} else {
"*removing git file info*"
}
},
bang,
con,
)
}
Internal::toggle_git_status => {
self.with_new_options(
screen, &|o| {
if o.filter_by_git_status {
o.filter_by_git_status = false;
"*not filtering according to git status anymore*"
} else {
o.filter_by_git_status = true;
o.show_hidden = true;
"*only displaying new or modified files*"
}
}, bang, con
)
}
Internal::toggle_perm => {
self.with_new_options(
screen,
&|o| {
o.show_permissions ^= true;
if o.show_permissions {
"*displaying file permissions*"
} else {
"*removing file permissions*"
}
},
bang,
con,
)
}
Internal::toggle_sizes => self.with_new_options(
screen,
&|o| {
if o.show_sizes {
o.show_sizes = false;
o.show_root_fs = false;
"*removing sizes of files and directories*"
} else {
o.show_sizes = true;
o.show_root_fs = true;
"*now diplaying sizes of files and directories*"
}
},
bang,
con,
),
Internal::toggle_trim_root => {
self.with_new_options(
screen,
&|o| {
o.trim_root ^= true;
if o.trim_root {
"*now trimming root from excess files*"
} else {
"*not trimming root files anymore*"
}
},
bang,
con,
)
}
Internal::close_preview => {
if let Some(id) = cc.app.preview_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
}
} else {
CmdResult::Keep
}
}
Internal::panel_left | Internal::panel_left_no_open => {
CmdResult::HandleInApp(Internal::panel_left_no_open)
}
Internal::panel_right | Internal::panel_right_no_open => {
CmdResult::HandleInApp(Internal::panel_right_no_open)
}
Internal::toggle_second_tree => {
CmdResult::HandleInApp(Internal::toggle_second_tree)
}
Internal::clear_stage => {
app_state.stage.clear();
if let Some(panel_id) = cc.app.stage_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(panel_id),
}
} else {
CmdResult::Keep
}
}
Internal::stage => self.stage(app_state, cc, con),
Internal::unstage => self.unstage(app_state, cc, con),
Internal::toggle_stage => self.toggle_stage(app_state, cc, con),
Internal::close_staging_area => {
if let Some(id) = cc.app.stage_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
}
} else {
CmdResult::Keep
}
}
Internal::open_staging_area => {
if cc.app.stage_panel.is_none() {
CmdResult::NewPanel {
state: Box::new(StageState::new(app_state, self.tree_options(), con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
} else {
CmdResult::Keep
}
}
Internal::toggle_staging_area => {
if let Some(id) = cc.app.stage_panel {
CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
}
} else {
CmdResult::NewPanel {
state: Box::new(StageState::new(app_state, self.tree_options(), con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
}
}
Internal::set_syntax_theme => CmdResult::HandleInApp(Internal::set_syntax_theme),
Internal::print_path => print::print_paths(self.sel_info(app_state), con)?,
Internal::print_relative_path => print::print_relative_paths(self.sel_info(app_state), con)?,
Internal::refresh => CmdResult::RefreshState { clear_cache: true },
Internal::quit => CmdResult::Quit,
_ => CmdResult::Keep,
})
}
sourcepub fn paths(&self) -> &[PathBuf]
pub fn paths(&self) -> &[PathBuf]
Examples found in repository?
src/stage/stage_state.rs (line 220)
216 217 218 219 220 221 222 223 224 225 226 227
fn sel_info<'c>(&'c self, app_state: &'c AppState) -> SelInfo<'c> {
match app_state.stage.len() {
0 => SelInfo::None,
1 => SelInfo::One(Selection {
path: &app_state.stage.paths()[0],
stype: SelectionType::File,
is_exe: false,
line: 0,
}),
_ => SelInfo::More(&app_state.stage),
}
}
More examples
src/app/selection.rs (line 121)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
pub fn common_stype(&self) -> Option<SelectionType> {
match self {
SelInfo::None => None,
SelInfo::One(sel) => Some(sel.stype),
SelInfo::More(stage) => {
let stype = SelectionType::from(&stage.paths()[0]);
for path in stage.paths().iter().skip(1) {
if stype != SelectionType::from(path) {
return None;
}
}
Some(stype)
}
}
}
pub fn one_sel(self) -> Option<Selection<'a>> {
match self {
SelInfo::One(sel) => Some(sel),
_ => None,
}
}
pub fn one_path(self) -> Option<&'a Path> {
self.one_sel().map(|sel| sel.path)
}
pub fn extension(&self) -> Option<&str> {
match self {
SelInfo::None => None,
SelInfo::One(sel) => sel.path.extension().and_then(|e| e.to_str()),
SelInfo::More(stage) => {
let common_extension = stage.paths()[0]
.extension().and_then(|e| e.to_str());
#[allow(clippy::question_mark)]
if common_extension.is_none() {
return None;
}
for path in stage.paths().iter().skip(1) {
let extension = path.extension().and_then(|e| e.to_str());
if extension != common_extension {
return None;
}
}
common_extension
}
}
}
src/print.rs (line 35)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
pub fn print_paths(sel_info: SelInfo, con: &AppContext) -> io::Result<CmdResult> {
let string = match sel_info {
SelInfo::None => "".to_string(), // better idea ?
SelInfo::One(sel) => sel.path.to_string_lossy().to_string(),
SelInfo::More(stage) => {
let mut string = String::new();
for path in stage.paths().iter() {
string.push_str(&path.to_string_lossy());
string.push('\n');
}
string
}
};
print_string(string, con)
}
fn relativize_path(path: &Path, con: &AppContext) -> io::Result<String> {
let relative_path = match pathdiff::diff_paths(path, &con.initial_root) {
None => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Cannot relativize {:?}", path), // does this happen ? how ?
));
}
Some(p) => p,
};
Ok(
if relative_path.components().next().is_some() {
relative_path.to_string_lossy().to_string()
} else {
".".to_string()
}
)
}
pub fn print_relative_paths(sel_info: SelInfo, con: &AppContext) -> io::Result<CmdResult> {
let string = match sel_info {
SelInfo::None => "".to_string(),
SelInfo::One(sel) => relativize_path(sel.path, con)?,
SelInfo::More(stage) => {
let mut string = String::new();
for path in stage.paths().iter() {
string.push_str(&relativize_path(path, con)?);
string.push('\n');
}
string
}
};
print_string(string, con)
}
src/verb/verb.rs (line 191)
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
pub fn check_args(
&self,
sel_info: SelInfo<'_>,
invocation: &VerbInvocation,
other_path: &Option<PathBuf>,
) -> Option<String> {
match sel_info {
SelInfo::None => self.check_sel_args(None, invocation, other_path),
SelInfo::One(sel) => self.check_sel_args(Some(sel), invocation, other_path),
SelInfo::More(stage) => {
stage.paths().iter()
.filter_map(|path| {
let sel = Selection {
path,
line: 0,
stype: SelectionType::from(path),
is_exe: false,
};
self.check_sel_args(Some(sel), invocation, other_path)
})
.next()
}
}
}
src/verb/execution_builder.rs (line 72)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
fn get_raw_replacement<F>(
&self,
f: F
) -> Option<String>
where
F: Fn(Option<Selection<'_>>) -> Option<String>
{
match self.sel_info {
SelInfo::None => f(None),
SelInfo::One(sel) => f(Some(sel)),
SelInfo::More(stage) => {
let mut sels = stage.paths().iter()
.map(|path| Selection {
path,
line: 0,
stype: SelectionType::from(path),
is_exe: false,
});
f(sels.next())
.filter(|first_rcr| {
for sel in sels {
let rcr = f(Some(sel));
if rcr.as_ref() != Some(first_rcr) {
return false;
}
}
true
})
}
}
}
src/stage/filtered_stage.rs (line 27)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
fn compute(&mut self, stage: &Stage) {
if self.pattern.is_none() {
self.paths_idx = stage.paths().iter()
.enumerate()
.map(|(idx, _)| idx)
.collect();
} else {
let mut best_score = None;
self.paths_idx.clear();
for (idx, path) in stage.paths().iter().enumerate() {
if let Some(file_name) = path.file_name() {
let subpath = path.to_string_lossy().to_string();
let name = file_name.to_string_lossy().to_string();
let regular_file = path.is_file();
let candidate = Candidate {
path,
subpath: &subpath,
name: &name,
regular_file,
};
if let Some(score) = self.pattern.pattern.score_of(candidate) {
let is_best = match best_score {
Some(old_score) if old_score < score => true,
None => true,
_ => false,
};
if is_best {
self.selection = Some(self.paths_idx.len());
best_score = Some(score);
}
self.paths_idx.push(idx);
}
}
}
}
}
pub fn filtered(stage: &Stage, pattern: InputPattern) -> Self {
let mut fs = Self {
stage_version: stage.version(),
paths_idx: Vec::new(),
pattern,
selection: None,
};
fs.compute(stage);
fs
}
/// check whether the stage has changed, and update the
/// filtered list if necessary
pub fn update(&mut self, stage: &Stage) -> bool {
if stage.version() == self.stage_version {
false
} else {
self.compute(stage);
true
}
}
/// change the pattern, keeping the selection if possible
/// Assumes the stage didn't change (if it changed, we lose the
/// selection)
pub fn set_pattern(&mut self, stage: &Stage, pattern: InputPattern) {
self.stage_version = stage.version(); // in case it changed
self.pattern = pattern;
self.compute(stage);
}
pub fn len(&self) -> usize {
self.paths_idx.len()
}
pub fn path<'s>(&self, stage: &'s Stage, idx: usize) -> Option<&'s Path> {
self.paths_idx
.get(idx)
.and_then(|&idx| stage.paths().get(idx))
.map(|p| p.as_path())
}
pub fn path_sel<'s>(&self, stage: &'s Stage, idx: usize) -> Option<(&'s Path, bool)> {
self.path(stage, idx)
.map(|p| (p, self.selection.map_or(false, |si| idx==si)))
}
pub fn pattern(&self) -> &InputPattern {
&self.pattern
}
pub fn selection(&self) -> Option<usize> {
self.selection
}
pub fn has_selection(&self) -> bool {
self.selection.is_some()
}
pub fn try_select_idx(&mut self, idx: usize) -> bool {
if idx < self.paths_idx.len() {
self.selection = Some(idx);
true
} else {
false
}
}
pub fn selected_path<'s>(&self, stage: &'s Stage) -> Option<&'s Path> {
self.selection
.and_then(|pi| self.paths_idx.get(pi))
.and_then(|&idx| stage.paths().get(idx))
.map(|p| p.as_path())
}
Additional examples can be found in:
sourcepub fn refresh(&mut self)
pub fn refresh(&mut self)
removes paths to non existing files
Examples found in repository?
src/app/panel_state.rs (line 655)
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
fn execute_verb(
&mut self,
w: &mut W, // needed because we may want to switch from alternate in some externals
verb: &Verb,
invocation: Option<&VerbInvocation>,
trigger_type: TriggerType,
app_state: &mut AppState,
cc: &CmdContext,
) -> Result<CmdResult, ProgramError> {
if verb.needs_selection && !self.has_at_least_one_selection(app_state) {
return Ok(CmdResult::error("This verb needs a selection"));
}
if verb.needs_another_panel && app_state.other_panel_path.is_none() {
return Ok(CmdResult::error("This verb needs another panel"));
}
let res = match &verb.execution {
VerbExecution::Internal(internal_exec) => {
self.on_internal(
w,
internal_exec,
invocation,
trigger_type,
app_state,
cc,
)
}
VerbExecution::External(external) => {
self.execute_external(w, verb, external, invocation, app_state, cc)
}
VerbExecution::Sequence(seq_ex) => {
self.execute_sequence(w, verb, seq_ex, invocation, app_state, cc)
}
};
if res.is_ok() {
// if the stage has been emptied by the operation (eg a "rm"), we
// close it
app_state.stage.refresh();
if app_state.stage.is_empty() {
if let Some(id) = cc.app.stage_panel {
return Ok(CmdResult::ClosePanel {
validate_purpose: false,
panel_ref: PanelReference::Id(id),
});
}
}
}
res
}
More examples
src/app/app.rs (line 512)
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 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 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
fn apply_command(
&mut self,
w: &mut W,
cmd: Command,
panel_skin: &PanelSkin,
app_state: &mut AppState,
con: &mut AppContext,
) -> Result<(), ProgramError> {
use CmdResult::*;
let mut error: Option<String> = None;
let is_input_invocation = cmd.is_verb_invocated_from_input();
let app_cmd_context = AppCmdContext {
panel_skin,
preview_panel: self.preview_panel,
stage_panel: self.stage_panel,
screen: self.screen, // it can't change in this function
con,
};
let cmd_result = self.mut_panel().apply_command(w, &cmd, app_state, &app_cmd_context)?;
debug!("cmd_result: {:?}", &cmd_result);
match cmd_result {
ApplyOnPanel { id } => {
if let Some(idx) = self.panel_id_to_idx(id) {
if let DisplayError(txt) = self.panels[idx].apply_command(
w, &cmd, app_state, &app_cmd_context
)? {
// we should probably handle other results
// which implies the possibility of a recursion
error = Some(txt);
} else if is_input_invocation {
self.mut_panel().clear_input();
}
} else {
warn!("no panel found for ApplyOnPanel");
}
}
ClosePanel { validate_purpose, panel_ref } => {
if is_input_invocation {
self.mut_panel().clear_input_invocation(con);
}
let close_idx = self.panel_ref_to_idx(panel_ref)
.unwrap_or_else(||
// when there's a preview panel, we close it rather than the app
if self.panels.len().get()==2 && self.preview_panel.is_some() {
1
} else {
self.active_panel_idx
}
);
let mut new_arg = None;
if validate_purpose {
let purpose = &self.panels[close_idx].purpose;
if let PanelPurpose::ArgEdition { .. } = purpose {
new_arg = self.panels[close_idx]
.state()
.selected_path()
.map(|p| p.to_string_lossy().to_string());
}
}
if self.close_panel(close_idx) {
let screen = self.screen;
self.mut_state().refresh(screen, con);
if let Some(new_arg) = new_arg {
self.mut_panel().set_input_arg(new_arg);
let new_input = self.panel().get_input_content();
let cmd = Command::from_raw(new_input, false);
let app_cmd_context = AppCmdContext {
panel_skin,
preview_panel: self.preview_panel,
stage_panel: self.stage_panel,
screen,
con,
};
self.mut_panel().apply_command(w, &cmd, app_state, &app_cmd_context)?;
}
} else {
self.quitting = true;
}
}
DisplayError(txt) => {
error = Some(txt);
}
ExecuteSequence { sequence } => {
self.tx_seqs.send(sequence).unwrap();
}
HandleInApp(internal) => {
debug!("handling internal {internal:?} at app level");
match internal {
Internal::panel_left_no_open | Internal::panel_right_no_open => {
let new_active_panel_idx = if internal == Internal::panel_left_no_open {
// we're here because the state wants us to either move to the panel
// to the left, or close the rightest one
if self.active_panel_idx == 0 {
self.close_panel(self.panels.len().get()-1);
None
} else {
Some(self.active_panel_idx - 1)
}
} else { // panel_right
// we either move to the right or close the leftest panel
if self.active_panel_idx + 1 == self.panels.len().get() {
self.close_panel(0);
None
} else {
Some(self.active_panel_idx + 1)
}
};
if let Some(idx) = new_active_panel_idx {
if is_input_invocation {
self.mut_panel().clear_input();
}
self.active_panel_idx = idx;
let app_cmd_context = AppCmdContext {
panel_skin,
preview_panel: self.preview_panel,
stage_panel: self.stage_panel,
screen: self.screen,
con,
};
self.mut_panel().refresh_input_status(app_state, &app_cmd_context);
}
}
Internal::toggle_second_tree => {
let panels_count = self.panels.len().get();
let trees_count = self.panels.iter()
.filter(|p| p.state().get_type() == PanelStateType::Tree)
.count();
if trees_count < 2 {
// we open a tree, closing a (non tree) panel if necessary
if panels_count >= con.max_panels_count {
for i in (0..panels_count).rev() {
if self.panels[i].state().get_type() != PanelStateType::Tree {
self.close_panel(i);
break;
}
}
}
if let Some(selected_path) = self.state().selected_path() {
let dir = closest_dir(selected_path);
if let Ok(new_state) = BrowserState::new(
dir,
self.state().tree_options().without_pattern(),
self.screen,
con,
&Dam::unlimited(),
) {
if let Err(s) = self.new_panel(
Box::new(new_state),
PanelPurpose::None,
HDir::Right,
is_input_invocation,
con,
) {
error = Some(s);
}
}
}
} else {
// we close the rightest inactive tree
for i in (0..panels_count).rev() {
if self.panels[i].state().get_type() == PanelStateType::Tree {
if i == self.active_panel_idx {
continue;
}
self.close_panel(i);
break;
}
}
}
}
Internal::set_syntax_theme => {
let arg = cmd
.as_verb_invocation()
.and_then(|vi| vi.args.as_ref());
match arg {
Some(arg) => {
match SyntaxTheme::from_str(arg) {
Ok(theme) => {
con.syntax_theme = Some(theme);
self.update_preview(con, true);
}
Err(e) => {
error = Some(e.to_string());
}
}
}
None => {
error = Some("no theme provided".to_string());
}
}
}
_ => {
info!("unhandled propagated internal. cmd={:?}", &cmd);
}
}
}
Keep => {
if is_input_invocation {
self.mut_panel().clear_input_invocation(con);
}
}
Launch(launchable) => {
self.launch_at_end = Some(*launchable);
self.quitting = true;
}
NewPanel {
state,
purpose,
direction,
} => {
if let Err(s) = self.new_panel(state, purpose, direction, is_input_invocation, con) {
error = Some(s);
}
}
NewState { state, message } => {
self.mut_panel().clear_input();
self.mut_panel().push_state(state);
if let Some(md) = message {
self.mut_panel().set_message(md);
} else {
self.mut_panel().refresh_input_status(app_state, &app_cmd_context);
}
}
PopState => {
if is_input_invocation {
self.mut_panel().clear_input();
}
if self.remove_state() {
self.mut_state().refresh(app_cmd_context.screen, con);
self.mut_panel().refresh_input_status(app_state, &app_cmd_context);
} else if con.quit_on_last_cancel {
self.quitting = true;
}
}
PopStateAndReapply => {
if is_input_invocation {
self.mut_panel().clear_input();
}
if self.remove_state() {
let app_cmd_context = AppCmdContext {
panel_skin,
preview_panel: self.preview_panel,
stage_panel: self.stage_panel,
screen: self.screen,
con,
};
self.mut_panel().apply_command(w, &cmd, app_state, &app_cmd_context)?;
} else if con.quit_on_last_cancel {
self.quitting = true;
}
}
Quit => {
self.quitting = true;
}
RefreshState { clear_cache } => {
if is_input_invocation {
self.mut_panel().clear_input_invocation(con);
}
if clear_cache {
clear_caches();
}
app_state.stage.refresh();
for i in 0..self.panels.len().get() {
self.panels[i].mut_state().refresh(self.screen, con);
}
}
}
if let Some(text) = error {
self.mut_panel().set_error(text);
}
app_state.other_panel_path = self.get_other_panel_path();
if let Some(path) = self.state().tree_root() {
app_state.root = path.to_path_buf();
}
if let Some(shared_root) = &mut self.shared_root {
if let Ok(mut root) = shared_root.lock() {
*root = app_state.root.clone();
}
}
self.update_preview(con, false);
Ok(())
}
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Examples found in repository?
More examples
src/stage/stage_state.rs (line 97)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
fn write_title_line(
&self,
stage: &Stage,
cw: &mut CropWriter<'_, W>,
styles: &StyleMap,
) -> Result<(), ProgramError> {
let total_count = format!("{}", stage.len());
let mut count_len = total_count.len();
if self.filtered_stage.pattern().is_some() {
count_len += total_count.len() + 1; // 1 for '/'
}
if cw.allowed < count_len {
return Ok(());
}
if TITLE.len() + 1 + count_len <= cw.allowed {
cw.queue_str(
&styles.staging_area_title,
TITLE,
)?;
}
let mut show_count_label = false;
let mut rem = cw.allowed - count_len;
if COUNT_LABEL.len() < rem {
rem -= COUNT_LABEL.len();
show_count_label = true;
if self.tree_options.show_sizes {
if let Some(sum) = self.stage_sum.computed() {
let size = file_size::fit_4(sum.to_size());
let size_len = SIZE_LABEL.len() + size.len();
if size_len < rem {
rem -= size_len;
// we display the size in the middle, so we cut rem in two
let left_rem = rem / 2;
rem -= left_rem;
cw.repeat(&styles.staging_area_title, &SPACE_FILLING, left_rem)?;
cw.queue_g_string(
&styles.staging_area_title,
SIZE_LABEL.to_string(),
)?;
cw.queue_g_string(
&styles.staging_area_title,
size,
)?;
}
}
}
}
cw.repeat(&styles.staging_area_title, &SPACE_FILLING, rem)?;
if show_count_label {
cw.queue_g_string(
&styles.staging_area_title,
COUNT_LABEL.to_string(),
)?;
}
if self.filtered_stage.pattern().is_some() {
cw.queue_g_string(
&styles.char_match,
format!("{}", self.filtered_stage.len()),
)?;
cw.queue_char(
&styles.staging_area_title,
'/',
)?;
}
cw.queue_g_string(
&styles.staging_area_title,
total_count,
)?;
cw.fill(&styles.staging_area_title, &SPACE_FILLING)?;
Ok(())
}
fn move_selection(&mut self, dy: i32, cycle: bool) -> CmdResult {
self.filtered_stage.move_selection(dy, cycle);
if let Some(sel) = self.filtered_stage.selection() {
if sel < self.scroll + 5 {
self.scroll = (sel as i32 -5).max(0) as usize;
} else if sel > self.scroll + self.page_height - 5 {
self.scroll = (sel + 5 - self.page_height)
.min(self.filtered_stage.len() - self.page_height);
}
}
CmdResult::Keep
}
}
impl PanelState for StageState {
fn get_type(&self) -> PanelStateType {
PanelStateType::Stage
}
fn selected_path(&self) -> Option<&Path> {
None
}
fn selection(&self) -> Option<Selection<'_>> {
None
}
fn clear_pending(&mut self) {
self.stage_sum.clear();
}
fn do_pending_task(
&mut self,
app_state: &mut AppState,
_screen: Screen,
con: &AppContext,
dam: &mut Dam,
// need the stage here
) -> Result<(), ProgramError> {
if self.need_sum_computation() {
self.stage_sum.compute(&app_state.stage, dam, con);
}
Ok(())
}
fn get_pending_task(&self) -> Option<&'static str> {
if self.need_sum_computation() {
Some("stage size summing")
} else {
None
}
}
fn sel_info<'c>(&'c self, app_state: &'c AppState) -> SelInfo<'c> {
match app_state.stage.len() {
0 => SelInfo::None,
1 => SelInfo::One(Selection {
path: &app_state.stage.paths()[0],
stype: SelectionType::File,
is_exe: false,
line: 0,
}),
_ => SelInfo::More(&app_state.stage),
}
}
sourcepub fn version(&self) -> usize
pub fn version(&self) -> usize
Examples found in repository?
src/stage/stage_sum.rs (line 20)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
pub fn see_stage(&mut self, stage: &Stage) {
if stage.version() != self.stage_version {
self.sum = None;
}
}
pub fn is_up_to_date(&self) -> bool {
self.sum.is_some()
}
pub fn clear(&mut self) {
self.sum = None;
}
pub fn compute(&mut self, stage: &Stage, dam: &Dam, con: &AppContext) -> Option<FileSum> {
if self.stage_version != stage.version() {
self.sum = None;
}
self.stage_version = stage.version();
if self.sum.is_none() {
// produces None in case of interruption
self.sum = stage.compute_sum(dam, con);
}
self.sum
}
More examples
src/stage/filtered_stage.rs (line 63)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
pub fn filtered(stage: &Stage, pattern: InputPattern) -> Self {
let mut fs = Self {
stage_version: stage.version(),
paths_idx: Vec::new(),
pattern,
selection: None,
};
fs.compute(stage);
fs
}
/// check whether the stage has changed, and update the
/// filtered list if necessary
pub fn update(&mut self, stage: &Stage) -> bool {
if stage.version() == self.stage_version {
false
} else {
self.compute(stage);
true
}
}
/// change the pattern, keeping the selection if possible
/// Assumes the stage didn't change (if it changed, we lose the
/// selection)
pub fn set_pattern(&mut self, stage: &Stage, pattern: InputPattern) {
self.stage_version = stage.version(); // in case it changed
self.pattern = pattern;
self.compute(stage);
}
pub fn len(&self) -> usize {
self.paths_idx.len()
}
pub fn path<'s>(&self, stage: &'s Stage, idx: usize) -> Option<&'s Path> {
self.paths_idx
.get(idx)
.and_then(|&idx| stage.paths().get(idx))
.map(|p| p.as_path())
}
pub fn path_sel<'s>(&self, stage: &'s Stage, idx: usize) -> Option<(&'s Path, bool)> {
self.path(stage, idx)
.map(|p| (p, self.selection.map_or(false, |si| idx==si)))
}
pub fn pattern(&self) -> &InputPattern {
&self.pattern
}
pub fn selection(&self) -> Option<usize> {
self.selection
}
pub fn has_selection(&self) -> bool {
self.selection.is_some()
}
pub fn try_select_idx(&mut self, idx: usize) -> bool {
if idx < self.paths_idx.len() {
self.selection = Some(idx);
true
} else {
false
}
}
pub fn selected_path<'s>(&self, stage: &'s Stage) -> Option<&'s Path> {
self.selection
.and_then(|pi| self.paths_idx.get(pi))
.and_then(|&idx| stage.paths().get(idx))
.map(|p| p.as_path())
}
pub fn unselect(&mut self) {
self.selection = None
}
/// unstage the selection, if any, or return false.
/// If possible we select the item below so that the user
/// may easily remove a few items
pub fn unstage_selection(&mut self, stage: &mut Stage) -> bool {
if let Some(spi) = self.selection {
stage.remove_idx(self.paths_idx[spi]);
self.stage_version = stage.version();
self.compute(stage);
if spi >= self.paths_idx.len() {
self.selection = Some(spi);
};
true
} else {
false
}
}
sourcepub fn compute_sum(&self, dam: &Dam, con: &AppContext) -> Option<FileSum>
pub fn compute_sum(&self, dam: &Dam, con: &AppContext) -> Option<FileSum>
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Stage
impl Send for Stage
impl Sync for Stage
impl Unpin for Stage
impl UnwindSafe for Stage
Blanket Implementations§
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian()
.