Enum broot::app::PanelPurpose
source · pub enum PanelPurpose {
None,
ArgEdition {
arg_type: SelectionType,
},
Preview,
}
Expand description
the possible special reason the panel was open
Variants§
Implementations§
source§impl PanelPurpose
impl PanelPurpose
sourcepub fn is_arg_edition(self) -> bool
pub fn is_arg_edition(self) -> bool
Examples found in repository?
src/app/panel.rs (line 249)
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
fn write_purpose(
&self,
w: &mut W,
panel_skin: &PanelSkin,
screen: Screen,
con: &AppContext,
) -> Result<(), ProgramError> {
if !self.purpose.is_arg_edition() {
return Ok(());
}
if let Some(area) = &self.areas.purpose {
let shortcut = con
.verb_store
.verbs
.iter()
.filter(|v| match &v.execution {
VerbExecution::Internal(exec) => exec.internal == Internal::start_end_panel,
_ => false,
})
.filter_map(|v| v.keys.first())
.map(|&k| KEY_FORMAT.to_string(k))
.next()
.unwrap_or_else(|| ":start_end_panel".to_string());
let md = format!("hit *{}* to fill arg ", shortcut);
// Add verbindex in purpose ?
screen.goto(w, area.left, area.top)?;
panel_skin.purpose_skin.write_composite_fill(
w,
Composite::from_inline(&md),
area.width as usize,
Alignment::Right,
)?;
}
Ok(())
}
More examples
src/browser/browser_state.rs (line 551)
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 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
fn on_internal(
&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 page_height = BrowserState::page_height(cc.app.screen);
let bang = input_invocation
.map(|inv| inv.bang)
.unwrap_or(internal_exec.bang);
Ok(match internal_exec.internal {
Internal::back => {
if let Some(filtered_tree) = &self.filtered_tree {
let filtered_selection = &filtered_tree.selected_line().path;
if self.tree.try_select_path(filtered_selection) {
self.tree.make_selection_visible(page_height);
}
self.filtered_tree = None;
CmdResult::Keep
} else if self.tree.selection > 0 {
self.tree.selection = 0;
CmdResult::Keep
} else {
CmdResult::PopState
}
}
Internal::focus => internal_focus::on_internal(
internal_exec,
input_invocation,
trigger_type,
&self.displayed_tree().selected_line().path,
self.displayed_tree().options.clone(),
app_state,
cc,
),
Internal::select => internal_select::on_internal(
internal_exec,
input_invocation,
trigger_type,
self.displayed_tree_mut(),
app_state,
cc,
),
Internal::up_tree => match self.displayed_tree().root().parent() {
Some(path) => internal_focus::on_path(
path.to_path_buf(),
screen,
self.displayed_tree().options.clone(),
bang,
con,
),
None => CmdResult::error("no parent found"),
},
Internal::open_stay => self.open_selection_stay_in_broot(screen, con, bang, false)?,
Internal::open_stay_filter => self.open_selection_stay_in_broot(screen, con, bang, true)?,
Internal::line_down => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(count, page_height, true);
CmdResult::Keep
}
Internal::line_up => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(-count, page_height, true);
CmdResult::Keep
}
Internal::line_down_no_cycle => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(count, page_height, false);
CmdResult::Keep
}
Internal::line_up_no_cycle => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(-count, page_height, false);
CmdResult::Keep
}
Internal::previous_dir => {
self.displayed_tree_mut().try_select_previous_filtered(
|line| line.is_dir(),
page_height,
);
CmdResult::Keep
}
Internal::next_dir => {
self.displayed_tree_mut().try_select_next_filtered(
|line| line.is_dir(),
page_height,
);
CmdResult::Keep
}
Internal::previous_match => {
self.displayed_tree_mut().try_select_previous_filtered(
|line| line.direct_match,
page_height,
);
CmdResult::Keep
}
Internal::next_match => {
self.displayed_tree_mut().try_select_next_filtered(
|line| line.direct_match,
page_height,
);
CmdResult::Keep
}
Internal::previous_same_depth => {
self.displayed_tree_mut().try_select_previous_same_depth(page_height);
CmdResult::Keep
}
Internal::next_same_depth => {
self.displayed_tree_mut().try_select_next_same_depth(page_height);
CmdResult::Keep
}
Internal::page_down => {
let tree = self.displayed_tree_mut();
if !tree.try_scroll(page_height as i32, page_height) {
tree.try_select_last(page_height);
}
CmdResult::Keep
}
Internal::page_up => {
let tree = self.displayed_tree_mut();
if !tree.try_scroll(page_height as i32 * -1, page_height) {
tree.try_select_first();
}
CmdResult::Keep
}
Internal::panel_left => {
let areas = &cc.panel.areas;
if areas.is_first() && areas.nb_pos < con.max_panels_count {
// we ask for the creation of a panel to the left
internal_focus::new_panel_on_path(
self.displayed_tree().selected_line().path.to_path_buf(),
screen,
self.displayed_tree().options.clone(),
PanelPurpose::None,
con,
HDir::Left,
)
} else {
// we let the app handle other cases
CmdResult::HandleInApp(Internal::panel_left_no_open)
}
}
Internal::panel_left_no_open => CmdResult::HandleInApp(Internal::panel_left_no_open),
Internal::panel_right => {
let areas = &cc.panel.areas;
let selected_path = &self.displayed_tree().selected_line().path;
if areas.is_last() && areas.nb_pos < con.max_panels_count {
let purpose = if selected_path.is_file() && cc.app.preview_panel.is_none() {
PanelPurpose::Preview
} else {
PanelPurpose::None
};
// we ask for the creation of a panel to the right
internal_focus::new_panel_on_path(
selected_path.to_path_buf(),
screen,
self.displayed_tree().options.clone(),
purpose,
con,
HDir::Right,
)
} else {
// we ask the app to handle other cases :
// focus the panel to the right or close the leftest one
CmdResult::HandleInApp(Internal::panel_right_no_open)
}
}
Internal::panel_right_no_open => CmdResult::HandleInApp(Internal::panel_right_no_open),
Internal::parent => self.go_to_parent(screen, con, bang),
Internal::print_tree => {
print::print_tree(self.displayed_tree(), cc.app.screen, cc.app.panel_skin, con)?
}
Internal::root_up => {
let tree = self.displayed_tree();
let root = tree.root();
if let Some(new_root) = root.parent() {
self.modified(
screen,
new_root.to_path_buf(),
tree.options.clone(),
None,
bang,
con,
)
} else {
CmdResult::error(format!("{:?} has no parent", root))
}
}
Internal::root_down => {
let tree = self.displayed_tree();
if tree.selection > 0 {
let root_len = tree.root().components().count();
let new_root = tree.selected_line().path
.components()
.take(root_len + 1)
.collect();
self.modified(
screen,
new_root,
tree.options.clone(),
None,
bang,
con,
)
} else {
CmdResult::error("No selected line")
}
}
Internal::stage_all_files => {
let pattern = self.displayed_tree().options.pattern.clone();
self.pending_task = Some(BrowserTask::StageAll(pattern));
if cc.app.stage_panel.is_none() {
let stage_options = self.tree.options.without_pattern();
CmdResult::NewPanel {
state: Box::new(StageState::new(app_state, stage_options, con)),
purpose: PanelPurpose::None,
direction: HDir::Right,
}
} else {
CmdResult::Keep
}
}
Internal::select_first => {
self.displayed_tree_mut().try_select_first();
CmdResult::Keep
}
Internal::select_last => {
let page_height = BrowserState::page_height(screen);
self.displayed_tree_mut().try_select_last(page_height);
CmdResult::Keep
}
Internal::start_end_panel => {
if cc.panel.purpose.is_arg_edition() {
debug!("start_end understood as end");
CmdResult::ClosePanel {
validate_purpose: true,
panel_ref: PanelReference::Active,
}
} else {
debug!("start_end understood as start");
let tree_options = self.displayed_tree().options.clone();
if let Some(input_invocation) = input_invocation {
// we'll go for input arg editing
let path = if let Some(input_arg) = &input_invocation.args {
path::path_from(self.root(), PathAnchor::Unspecified, input_arg)
} else {
self.root().to_path_buf()
};
let arg_type = SelectionType::Any; // We might do better later
let purpose = PanelPurpose::ArgEdition { arg_type };
internal_focus::new_panel_on_path(
path, screen, tree_options, purpose, con, HDir::Right,
)
} else {
// we just open a new panel on the selected path,
// without purpose
internal_focus::new_panel_on_path(
self.displayed_tree().selected_line().path.to_path_buf(),
screen,
tree_options,
PanelPurpose::None,
con,
HDir::Right,
)
}
}
}
Internal::total_search => {
match self.filtered_tree.as_ref().map(|t| t.total_search) {
None => {
CmdResult::error("this verb can be used only after a search")
}
Some(true) => {
CmdResult::error("search was already total: all possible matches have been ranked")
}
Some(false) => {
self.search(self.displayed_tree().options.pattern.clone(), true);
CmdResult::Keep
}
}
}
Internal::quit => CmdResult::Quit,
_ => self.on_internal_generic(
w,
internal_exec,
input_invocation,
trigger_type,
app_state,
cc,
)?,
})
}
sourcepub fn is_preview(self) -> bool
pub fn is_preview(self) -> bool
Examples found in repository?
src/verb/internal_focus.rs (line 61)
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
pub fn new_panel_on_path(
path: PathBuf,
screen: Screen,
tree_options: TreeOptions,
purpose: PanelPurpose,
con: &AppContext,
direction: HDir,
) -> CmdResult {
if purpose.is_preview() {
let pattern = tree_options.pattern.tree_to_preview();
CmdResult::NewPanel {
state: Box::new(PreviewState::new(path, pattern, None, tree_options, con)),
purpose,
direction,
}
} else {
let path = path::closest_dir(&path);
match BrowserState::new(path, tree_options, screen, con, &Dam::unlimited()) {
Ok(os) => CmdResult::NewPanel {
state: Box::new(os),
purpose,
direction,
},
Err(e) => CmdResult::DisplayError(e.to_string()),
}
}
}
More examples
src/app/app.rs (line 582)
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
fn new_panel(
&mut self,
state: Box<dyn PanelState>,
purpose: PanelPurpose,
direction: HDir,
is_input_invocation: bool, // if true we clean the input
con: &AppContext,
) -> Result<(), String> {
match state.get_type() {
PanelStateType::Preview if self.preview_panel.is_some() => {
return Err("There can be only one preview panel".to_owned());
// todo replace instead ?
}
PanelStateType::Stage if self.stage_panel.is_some() => {
return Err("There can be only one stage panel".to_owned());
// todo replace instead ?
}
_ => {}
}
if is_input_invocation {
self.mut_panel().clear_input_invocation(con);
}
let insertion_idx = if purpose.is_preview() {
self.panels.len().get()
} else if direction == HDir::Right {
self.active_panel_idx + 1
} else {
self.active_panel_idx
};
let with_preview = purpose.is_preview() || self.preview_panel.is_some();
let areas = Areas::create(
self.panels.as_mut_slice(),
insertion_idx,
self.screen,
with_preview,
);
let panel_id = self.created_panels_count.into();
match state.get_type() {
PanelStateType::Preview => {
self.preview_panel = Some(panel_id);
}
PanelStateType::Stage => {
self.stage_panel = Some(panel_id);
}
_ => {
self.active_panel_idx = insertion_idx;
}
}
let mut panel = Panel::new(panel_id, state, areas, con);
panel.purpose = purpose;
self.created_panels_count += 1;
self.panels.insert(insertion_idx, panel);
Ok(())
}
Trait Implementations§
source§impl Clone for PanelPurpose
impl Clone for PanelPurpose
source§fn clone(&self) -> PanelPurpose
fn clone(&self) -> PanelPurpose
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more