Break out terminal creation to remove duplicate code
This commit is contained in:
parent
8fabf94f03
commit
d9ae46598e
1 changed files with 46 additions and 83 deletions
129
src/main.rs
129
src/main.rs
|
|
@ -589,6 +589,50 @@ impl App {
|
||||||
|
|
||||||
widget::settings::view_column(vec![settings_view.into()]).into()
|
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::<Mutex<Terminal>>(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.
|
/// Implement [`Application`] to integrate with COSMIC.
|
||||||
|
|
@ -955,49 +999,7 @@ impl Application for App {
|
||||||
);
|
);
|
||||||
if let Some((pane, _)) = result {
|
if let Some((pane, _)) = result {
|
||||||
self.terminal_ids.insert(pane, widget::Id::unique());
|
self.terminal_ids.insert(pane, widget::Id::unique());
|
||||||
self.pane_model.focus = pane;
|
self.create_and_focus_new_terminal(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::<Mutex<Terminal>>(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.pane_model.panes_created += 1;
|
self.pane_model.panes_created += 1;
|
||||||
return self.update_title(Some(pane));
|
return self.update_title(Some(pane));
|
||||||
}
|
}
|
||||||
|
|
@ -1147,46 +1149,7 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::TabNew => match &self.term_event_tx_opt {
|
Message::TabNew => self.create_and_focus_new_terminal(self.pane_model.focus),
|
||||||
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::<Mutex<Terminal>>(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::TermEvent(pane, entity, event) => {
|
Message::TermEvent(pane, entity, event) => {
|
||||||
match event {
|
match event {
|
||||||
TermEvent::Bell => {
|
TermEvent::Bell => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue