Skip to content

Commit

Permalink
#1364 Fix BorrowError when learning source while target popup menu open
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Dec 17, 2024
1 parent 70c8497 commit 4e8bdde
Showing 1 changed file with 51 additions and 48 deletions.
99 changes: 51 additions & 48 deletions main/src/infrastructure/ui/mapping_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,56 @@ impl MappingPanel {
Ok(op(&p))
}

fn open_target_menu(self: SharedView<Self>) {
enum MenuAction {
SetTarget(Box<ReaperTarget>),
GoToTarget,
}
let menu = {
use swell_ui::menu_tree::*;
let mapping = self.mapping();
let session = self.session();
let session = session.borrow();
let compartment = mapping.borrow().compartment();
let context = session.extended_context();
let recently_touched_items = Backbone::get()
.extract_last_touched_targets()
.into_iter()
.rev()
.map(|t| {
let mut target_model = TargetModel::default_for_compartment(compartment);
let _ = target_model.apply_from_target(&t, context, compartment);
// let target_type_label = ReaperTargetType::from_target(&t);
let target_label = TargetModelFormatVeryShort(&target_model);
// let label = format!("{target_type_label} / {target_label}");
item(target_label.to_string(), MenuAction::SetTarget(Box::new(t)))
})
.collect();
anonymous_menu(vec![
menu(
"Pick recently touched target (by type)",
recently_touched_items,
),
item("Go to target (if supported)", MenuAction::GoToTarget),
])
};
let menu_action = self
.view
.require_window()
.open_popup_menu(menu, Window::cursor_pos());
let Some(menu_action) = menu_action else {
return;
};
self.write(|panel| match &menu_action {
MenuAction::SetTarget(t) => {
panel.set_mapping_target(&t);

Check failure on line 1783 in main/src/infrastructure/ui/mapping_panel.rs

View workflow job for this annotation

GitHub Actions / Clippy

this expression creates a reference which is immediately dereferenced by the compiler
}
MenuAction::GoToTarget => {
panel.go_to_target();
}
});
}

fn show_target_type_menu(&self) {
let window = self.view.require_window();
let (target_category, target_type, control_element_type) = {
Expand Down Expand Up @@ -1901,53 +1951,6 @@ impl<'a> MutableMappingPanel<'a> {
self.resolved_targets().into_iter().next()
}

fn open_target_menu(&mut self) {
enum MenuAction {
SetTarget(Box<ReaperTarget>),
GoToTarget,
}
let compartment = self.mapping.compartment();
let context = self.session.extended_context();
let menu = {
use swell_ui::menu_tree::*;
let recently_touched_items = Backbone::get()
.extract_last_touched_targets()
.into_iter()
.rev()
.map(|t| {
let mut target_model = TargetModel::default_for_compartment(compartment);
let _ = target_model.apply_from_target(&t, context, compartment);
// let target_type_label = ReaperTargetType::from_target(&t);
let target_label = TargetModelFormatVeryShort(&target_model);
// let label = format!("{target_type_label} / {target_label}");
item(target_label.to_string(), MenuAction::SetTarget(Box::new(t)))
})
.collect();
anonymous_menu(vec![
menu(
"Pick recently touched target (by type)",
recently_touched_items,
),
item("Go to target (if supported)", MenuAction::GoToTarget),
])
};
let menu_action = self
.view
.require_window()
.open_popup_menu(menu, Window::cursor_pos());
let Some(menu_action) = menu_action else {
return;
};
match menu_action {
MenuAction::SetTarget(t) => {
self.set_mapping_target(&t);
}
MenuAction::GoToTarget => {
self.go_to_target();
}
}
}

fn set_mapping_target(&mut self, target: &ReaperTarget) {
self.change_target_with_closure(None, |ctx| {
ctx.mapping.target_model.apply_from_target(
Expand Down Expand Up @@ -7256,7 +7259,7 @@ impl View for MappingPanel {
root::ID_TARGET_CHECK_BOX_5 => self.write(|p| p.handle_target_check_box_5_change()),
root::ID_TARGET_CHECK_BOX_6 => self.write(|p| p.handle_target_check_box_6_change()),
root::ID_TARGET_LEARN_BUTTON => self.toggle_learn_target(),
root::ID_TARGET_MENU_BUTTON => self.write(|p| p.open_target_menu()),
root::ID_TARGET_MENU_BUTTON => self.open_target_menu(),
root::ID_TARGET_LINE_2_BUTTON => {
let _ = self.handle_target_line_2_button_press();
}
Expand Down

0 comments on commit 4e8bdde

Please sign in to comment.