mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Add X's to tabs
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
mod app;
|
||||
mod windows;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::{
|
||||
app::windows::WindowWrapper, auth::Auth, config::Config, flowchart::FlowChart,
|
||||
@@ -14,7 +14,7 @@ use egui_tiles::{TileId, Tree};
|
||||
pub struct AppState {
|
||||
pub auth: Auth,
|
||||
|
||||
pub open_windows: HashMap<AppWindow, TileId>,
|
||||
pub open_windows: HashSet<AppWindow>,
|
||||
|
||||
pub flowchart: FlowChart,
|
||||
pub config: Config,
|
||||
@@ -31,14 +31,26 @@ impl AppState {
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
let enabled = self.open_windows.contains_key(&key);
|
||||
let enabled = self.open_windows.contains(&key);
|
||||
|
||||
if ui.selectable_label(enabled, *name).clicked() {
|
||||
if enabled {
|
||||
let tid = *self.open_windows.get(&key).unwrap();
|
||||
tree.remove_recursively(tid);
|
||||
tree.tiles.remove(tid);
|
||||
self.open_windows.remove(&key);
|
||||
// if let Some(tid) = Self::find_pane_id(*key, tree) {
|
||||
// tree.remove_recursively(*tid);
|
||||
// tree.tiles.remove(*tid);
|
||||
// self.open_windows.remove(&key);
|
||||
// }
|
||||
// let tid = *self.open_windows.get(&key).unwrap();
|
||||
|
||||
match Self::find_pane_id(*key, tree) {
|
||||
Some(tid) => {
|
||||
let tid = tid.clone();
|
||||
tree.remove_recursively(tid);
|
||||
tree.tiles.remove(tid);
|
||||
self.open_windows.remove(&key);
|
||||
}
|
||||
None => unreachable!(),
|
||||
}
|
||||
|
||||
// if self.open_windows.is_empty()
|
||||
} else {
|
||||
@@ -63,11 +75,25 @@ impl AppState {
|
||||
tree.move_tile_to_container(tid, tree.root.unwrap().clone(), n, true);
|
||||
}
|
||||
}
|
||||
self.open_windows.insert(key.clone(), tid);
|
||||
self.open_windows.insert(key.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_pane_id(window_type: AppWindow, tree: &Tree<WindowWrapper>) -> Option<&TileId> {
|
||||
for (tid, window) in tree.tiles.iter() {
|
||||
match window {
|
||||
egui_tiles::Tile::Pane(pane) => {
|
||||
if pane.window == window_type {
|
||||
return Some(tid);
|
||||
}
|
||||
}
|
||||
egui_tiles::Tile::Container(_) => {}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, serde::Deserialize, serde::Serialize, PartialEq, Eq, Hash)]
|
||||
|
||||
@@ -63,6 +63,28 @@ impl egui_tiles::Behavior<WindowWrapper> for AppState {
|
||||
ret
|
||||
}
|
||||
|
||||
fn is_tab_closable(
|
||||
&self,
|
||||
tiles: &egui_tiles::Tiles<WindowWrapper>,
|
||||
tile_id: egui_tiles::TileId,
|
||||
) -> bool {
|
||||
match tiles.get(tile_id).unwrap() {
|
||||
egui_tiles::Tile::Pane(_) => true,
|
||||
egui_tiles::Tile::Container(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_tab_close(
|
||||
&mut self,
|
||||
tiles: &mut egui_tiles::Tiles<WindowWrapper>,
|
||||
tile_id: egui_tiles::TileId,
|
||||
) -> bool {
|
||||
match tiles.get(tile_id).unwrap() {
|
||||
egui_tiles::Tile::Pane(pane) => self.open_windows.remove(&pane.window),
|
||||
egui_tiles::Tile::Container(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn tab_bar_color(&self, visuals: &egui::Visuals) -> egui::Color32 {
|
||||
visuals.panel_fill // same as the tab contents
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ impl Default for Config {
|
||||
impl Config {
|
||||
pub fn update(&mut self, auth: &mut Auth, ui: &mut egui::Ui) {
|
||||
let state_lock = self.state.lock().unwrap();
|
||||
let mut tree_list_none = state_lock.trees.is_none();
|
||||
let mut key_list_none = state_lock.tree_keys.is_none();
|
||||
let tree_list_none = state_lock.trees.is_none();
|
||||
let key_list_none = state_lock.tree_keys.is_none();
|
||||
let is_requesting = state_lock.is_requesting;
|
||||
|
||||
if !tree_list_none
|
||||
@@ -153,8 +153,7 @@ impl Config {
|
||||
pub fn titlebar_buttons(&mut self, ui: &mut egui::Ui) {
|
||||
let state_lock = self.state.lock().unwrap();
|
||||
let mut tree_list_none = state_lock.trees.is_none();
|
||||
let mut key_list_none = state_lock.tree_keys.is_none();
|
||||
let is_requesting = state_lock.is_requesting;
|
||||
|
||||
drop(state_lock);
|
||||
|
||||
if ui.button("Refresh").clicked() {
|
||||
@@ -165,7 +164,6 @@ impl Config {
|
||||
drop(state_lock);
|
||||
|
||||
tree_list_none = true;
|
||||
key_list_none = true;
|
||||
}
|
||||
|
||||
if !tree_list_none {
|
||||
@@ -184,7 +182,6 @@ impl Config {
|
||||
|
||||
if before.ne(&self.tree_option) {
|
||||
(*self.state.lock().unwrap()).tree_keys = None;
|
||||
key_list_none = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user