diff --git a/src/main.rs b/src/main.rs index f8b2496..279b224 100644 --- a/src/main.rs +++ b/src/main.rs @@ -589,6 +589,50 @@ impl App { widget::settings::view_column(vec![settings_view.into()]).into() } + + fn create_and_focus_new_terminal(&mut self, pane: pane_grid::Pane) { + self.pane_model.focus = pane; + match &self.term_event_tx_opt { + Some(term_event_tx) => match self.themes.get(self.config.syntax_theme()) { + Some(colors) => { + let current_pane = self.pane_model.focus; + if let Some(tab_model) = self.pane_model.active_mut() { + let entity = tab_model + .insert() + .text("New Terminal") + .closable() + .activate() + .id(); + // Use the startup options, or defaults + let options = self.startup_options.take().unwrap_or_default(); + let mut terminal = Terminal::new( + current_pane, + entity, + term_event_tx.clone(), + self.term_config.clone(), + options, + &self.config, + *colors, + ); + terminal.set_config(&self.config, &self.themes, self.zoom_adj); + tab_model.data_set::>(entity, Mutex::new(terminal)); + } else { + log::error!("Found no active pane"); + } + } + None => { + log::error!( + "failed to find terminal theme {:?}", + self.config.syntax_theme() + ); + //TODO: fall back to known good theme + } + }, + None => { + log::warn!("tried to create new tab before having event channel"); + } + } + } } /// Implement [`Application`] to integrate with COSMIC. @@ -955,49 +999,7 @@ impl Application for App { ); if let Some((pane, _)) = result { self.terminal_ids.insert(pane, widget::Id::unique()); - self.pane_model.focus = pane; - - match &self.term_event_tx_opt { - Some(term_event_tx) => match self.themes.get(self.config.syntax_theme()) { - Some(colors) => { - let current_pane = self.pane_model.focus; - if let Some(tab_model) = self.pane_model.active_mut() { - let entity = tab_model - .insert() - .text("New Terminal") - .closable() - .activate() - .id(); - // Use the startup options, or defaults - let options = self.startup_options.take().unwrap_or_default(); - let mut terminal = Terminal::new( - current_pane, - entity, - term_event_tx.clone(), - self.term_config.clone(), - options, - &self.config, - *colors, - ); - terminal.set_config(&self.config, &self.themes, self.zoom_adj); - tab_model - .data_set::>(entity, Mutex::new(terminal)); - } else { - log::error!("Found no active pane"); - } - } - None => { - log::error!( - "failed to find terminal theme {:?}", - self.config.syntax_theme() - ); - //TODO: fall back to known good theme - } - }, - None => { - log::warn!("tried to create new tab before having event channel"); - } - } + self.create_and_focus_new_terminal(pane); self.pane_model.panes_created += 1; return self.update_title(Some(pane)); } @@ -1147,46 +1149,7 @@ impl Application for App { } } } - Message::TabNew => match &self.term_event_tx_opt { - Some(term_event_tx) => match self.themes.get(self.config.syntax_theme()) { - Some(colors) => { - let current_pane = self.pane_model.focus; - if let Some(tab_model) = self.pane_model.active_mut() { - let entity = tab_model - .insert() - .text("New Terminal") - .closable() - .activate() - .id(); - // Use the startup options, or defaults - let options = self.startup_options.take().unwrap_or_default(); - let mut terminal = Terminal::new( - current_pane, - entity, - term_event_tx.clone(), - self.term_config.clone(), - options, - &self.config, - *colors, - ); - terminal.set_config(&self.config, &self.themes, self.zoom_adj); - tab_model.data_set::>(entity, Mutex::new(terminal)); - } else { - log::error!("Found no active pane"); - } - } - None => { - log::error!( - "failed to find terminal theme {:?}", - self.config.syntax_theme() - ); - //TODO: fall back to known good theme - } - }, - None => { - log::warn!("tried to create new tab before having event channel"); - } - }, + Message::TabNew => self.create_and_focus_new_terminal(self.pane_model.focus), Message::TermEvent(pane, entity, event) => { match event { TermEvent::Bell => {