Don't pass the large DialogMessage on the stack
Instead, since the size of DialogMessage is allocated in the Message enum, pass it as a box, so that only the size of a pointer is allocated on the stack instead.
This commit is contained in:
parent
f50ece41eb
commit
72a27129e3
1 changed files with 137 additions and 122 deletions
65
src/main.rs
65
src/main.rs
|
|
@ -375,7 +375,7 @@ pub enum Message {
|
|||
DefaultFontStretch(usize),
|
||||
DefaultFontWeight(usize),
|
||||
DefaultZoomStep(usize),
|
||||
DialogMessage(DialogMessage),
|
||||
DialogMessage(Box<DialogMessage>), // DialogMessage is huge, so we use a box to make the size of this enum smaller on the stack
|
||||
Drop(Option<(pane_grid::Pane, segmented_button::Entity, DndDrop)>),
|
||||
Find(bool),
|
||||
FindNext,
|
||||
|
|
@ -694,7 +694,8 @@ impl App {
|
|||
if let Some(tab_model) = self.pane_model.active() {
|
||||
for entity in tab_model.iter() {
|
||||
if tab_model.is_active(entity)
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity)
|
||||
{
|
||||
let mut terminal = terminal.lock().unwrap();
|
||||
let current_zoom_adj = terminal.zoom_adj();
|
||||
match zoom_message {
|
||||
|
|
@ -722,7 +723,8 @@ impl App {
|
|||
ColorSchemeKind::Light => "color_schemes_light",
|
||||
},
|
||||
self.config.color_schemes(color_scheme_kind),
|
||||
) {
|
||||
)
|
||||
{
|
||||
log::error!("failed to save config: {}", err);
|
||||
}
|
||||
self.update_color_schemes();
|
||||
|
|
@ -1019,7 +1021,8 @@ impl App {
|
|||
for action in group.actions {
|
||||
let action_label = shortcuts::action_label(action);
|
||||
if let Some(regex) = &self.shortcut_search_regex
|
||||
&& regex.find(&action_label).is_none() {
|
||||
&& regex.find(&action_label).is_none()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
found_actions = true;
|
||||
|
|
@ -1535,7 +1538,8 @@ impl App {
|
|||
let options = tty::Options {
|
||||
shell: startup_options.shell.or_else(|| {
|
||||
if let Some(mut args) = shlex::split(&profile.command)
|
||||
&& !args.is_empty() {
|
||||
&& !args.is_empty()
|
||||
{
|
||||
let command = args.remove(0);
|
||||
return Some(tty::Shell::new(command, args));
|
||||
}
|
||||
|
|
@ -1946,13 +1950,13 @@ impl Application for App {
|
|||
.get(&color_scheme_id)
|
||||
.map(|color_scheme| color_scheme.name.clone()),
|
||||
None => Some(format!("COSMIC {:?}", color_scheme_kind)),
|
||||
}
|
||||
&& self.dialog_opt.is_none() {
|
||||
} && self.dialog_opt.is_none()
|
||||
{
|
||||
let (dialog, command) = Dialog::new(
|
||||
DialogSettings::new().kind(DialogKind::SaveFile {
|
||||
filename: format!("{}.ron", color_scheme_name),
|
||||
}),
|
||||
Message::DialogMessage,
|
||||
|msg| Message::DialogMessage(Box::new(msg)),
|
||||
move |result| {
|
||||
Message::ColorSchemeExportResult(
|
||||
color_scheme_kind,
|
||||
|
|
@ -2050,7 +2054,7 @@ impl Application for App {
|
|||
self.color_scheme_errors.clear();
|
||||
let (dialog, command) = Dialog::new(
|
||||
DialogSettings::new().kind(DialogKind::OpenMultipleFiles),
|
||||
Message::DialogMessage,
|
||||
|msg| Message::DialogMessage(Box::new(msg)),
|
||||
move |result| Message::ColorSchemeImportResult(color_scheme_kind, result),
|
||||
);
|
||||
self.dialog_opt = Some(dialog);
|
||||
|
|
@ -2292,7 +2296,8 @@ impl Application for App {
|
|||
},
|
||||
Message::DialogMessage(dialog_message) => {
|
||||
if let Some(dialog) = &mut self.dialog_opt {
|
||||
return dialog.update(dialog_message);
|
||||
// DialogMessage is boxed, so we need to dereference it before updating
|
||||
return dialog.update(*dialog_message);
|
||||
}
|
||||
}
|
||||
Message::Drop(Some((pane, entity, data))) => {
|
||||
|
|
@ -2332,7 +2337,8 @@ impl Application for App {
|
|||
}
|
||||
Message::FindNext => {
|
||||
if !self.find_search_value.is_empty()
|
||||
&& let Some(tab_model) = self.pane_model.active() {
|
||||
&& let Some(tab_model) = self.pane_model.active()
|
||||
{
|
||||
let entity = tab_model.active();
|
||||
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
let mut terminal = terminal.lock().unwrap();
|
||||
|
|
@ -2345,7 +2351,8 @@ impl Application for App {
|
|||
}
|
||||
Message::FindPrevious => {
|
||||
if !self.find_search_value.is_empty()
|
||||
&& let Some(tab_model) = self.pane_model.active() {
|
||||
&& let Some(tab_model) = self.pane_model.active()
|
||||
{
|
||||
let entity = tab_model.active();
|
||||
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
let mut terminal = terminal.lock().unwrap();
|
||||
|
|
@ -2447,7 +2454,8 @@ impl Application for App {
|
|||
let mut terminal = terminal.lock().unwrap();
|
||||
if let Some(url) =
|
||||
terminal.context_menu.as_ref().and_then(|m| m.link.as_ref())
|
||||
&& let Err(err) = open::that_detached(url) {
|
||||
&& let Err(err) = open::that_detached(url)
|
||||
{
|
||||
log::warn!("failed to open {:?}: {}", url, err);
|
||||
}
|
||||
terminal.context_menu = None;
|
||||
|
|
@ -2813,7 +2821,8 @@ impl Application for App {
|
|||
}
|
||||
// Close terminal context menu state
|
||||
if let Some(tab_model) = self.pane_model.active()
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity)
|
||||
{
|
||||
let mut terminal = terminal.lock().unwrap();
|
||||
//Some actions need the menu_state,
|
||||
//so only clear the position for them.
|
||||
|
|
@ -2948,9 +2957,7 @@ impl Application for App {
|
|||
let pos = tab_model
|
||||
.position(tab_model.active())
|
||||
.and_then(|i| (i as usize).checked_sub(1))
|
||||
.unwrap_or_else(|| {
|
||||
tab_model.iter().count().saturating_sub(1)
|
||||
});
|
||||
.unwrap_or_else(|| tab_model.iter().count().saturating_sub(1));
|
||||
|
||||
let entity = tab_model.iter().nth(pos);
|
||||
if let Some(entity) = entity {
|
||||
|
|
@ -2990,7 +2997,8 @@ impl Application for App {
|
|||
},
|
||||
TermEvent::ColorRequest(index, f) => {
|
||||
if let Some(tab_model) = self.pane_model.panes.get(pane)
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity)
|
||||
{
|
||||
let terminal = terminal.lock().unwrap();
|
||||
let rgb = terminal.colors()[index].unwrap_or_default();
|
||||
let text = f(rgb);
|
||||
|
|
@ -3005,7 +3013,8 @@ impl Application for App {
|
|||
}
|
||||
TermEvent::PtyWrite(text) => {
|
||||
if let Some(tab_model) = self.pane_model.panes.get(pane)
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity)
|
||||
{
|
||||
let terminal = terminal.lock().unwrap();
|
||||
terminal.input_no_scroll(text.into_bytes());
|
||||
}
|
||||
|
|
@ -3028,7 +3037,8 @@ impl Application for App {
|
|||
}
|
||||
TermEvent::TextAreaSizeRequest(f) => {
|
||||
if let Some(tab_model) = self.pane_model.panes.get(pane)
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity)
|
||||
{
|
||||
let terminal = terminal.lock().unwrap();
|
||||
let text = f(terminal.size().into());
|
||||
terminal.input_no_scroll(text.into_bytes());
|
||||
|
|
@ -3051,7 +3061,8 @@ impl Application for App {
|
|||
}
|
||||
TermEvent::MouseCursorDirty | TermEvent::Wakeup => {
|
||||
if let Some(tab_model) = self.pane_model.panes.get(pane)
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity)
|
||||
{
|
||||
let mut terminal = terminal.lock().unwrap();
|
||||
terminal.needs_update = true;
|
||||
}
|
||||
|
|
@ -3191,10 +3202,12 @@ impl Application for App {
|
|||
}
|
||||
Message::ContextMenuPopupClosed(id) => {
|
||||
if let Some((popup_id, pane, entity, _, _, _)) = &self.context_menu_popup
|
||||
&& id == *popup_id {
|
||||
&& id == *popup_id
|
||||
{
|
||||
// Clear link underline on the terminal
|
||||
if let Some(tab_model) = self.pane_model.panes.get(*pane)
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(*entity) {
|
||||
&& let Some(terminal) = tab_model.data::<Mutex<Terminal>>(*entity)
|
||||
{
|
||||
let mut terminal = terminal.lock().unwrap();
|
||||
terminal.context_menu = None;
|
||||
terminal.active_regex_match = None;
|
||||
|
|
@ -3311,7 +3324,8 @@ impl Application for App {
|
|||
|
||||
fn on_close_requested(&self, id: window::Id) -> Option<Self::Message> {
|
||||
if let Some((popup_id, _, _, _, _, _)) = &self.context_menu_popup
|
||||
&& id == *popup_id {
|
||||
&& id == *popup_id
|
||||
{
|
||||
return Some(Message::ContextMenuPopupClosed(id));
|
||||
}
|
||||
None
|
||||
|
|
@ -3320,7 +3334,8 @@ impl Application for App {
|
|||
fn view_window(&self, window_id: window::Id) -> Element<'_, Message> {
|
||||
if let Some((popup_id, _pane, entity, ref link, ref autosize_id, _)) =
|
||||
self.context_menu_popup
|
||||
&& window_id == popup_id {
|
||||
&& window_id == popup_id
|
||||
{
|
||||
return widget::autosize::autosize(
|
||||
menu::context_menu(&self.config, &self.key_binds, entity, link.clone()),
|
||||
autosize_id.clone(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue