Skip to content

Commit

Permalink
Tabs closing flow fixed, first shortcuts, justfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Leinnan committed Sep 2, 2024
1 parent 730afc0 commit da72099
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 54 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ jobs:
target/
key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-build-
- uses: extractions/setup-just@v2

- name: Build
run: cargo build

- name: Test
run: cargo test

- name: Check formatting
run: cargo fmt --all -- --check

- name: Lint
run: cargo clippy -- -D warnings
- name: Validate
run: just validate
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ unwrap_used = { level = "deny", priority = 10 }

[package.metadata.bundle]
name = "LWA File Manager"
image = ["static/icon.png"]
image = ["icon32x32.png", "icon128x128.png"]
identifier = "io.github.Leinnan.lwa_fm"
osx_url_schemes = ["io.github.Leinnan.lwa_fm"]
short_description = "File Manager"
long_description = "File Manager built with egui in Rust"
Binary file added icon128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default := "validate"

install-tools:
cargo install cargo-bundle

bundle:
cargo bundle --release

validate:
cargo build
cargo test
cargo fmt --all -- --check
cargo clippy -- -D warnings
101 changes: 59 additions & 42 deletions src/app/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ impl TabData {
new.set_path(path);
new
}
pub fn set_other_paths(&mut self, other_tabs: &[PathBuf]) {
pub fn update(&mut self, other_tabs: &[PathBuf]) {
self.can_close = !other_tabs.is_empty();
self.path_change = None;
self.other_tabs_paths = other_tabs
.iter()
.filter(|p| !p.eq(&&self.current_path))
Expand Down Expand Up @@ -80,7 +82,13 @@ impl TabViewer for MyTabViewer {
/// Defines the contents of a given `tab`.
#[allow(clippy::too_many_lines)]
fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) {
tab.path_change = None;
if ui.input(|i| i.key_pressed(egui::Key::F) && i.modifiers.ctrl) {
tab.settings.search.visible = !tab.settings.search.visible;
}
if ui.input(|i| i.key_pressed(egui::Key::H) && i.modifiers.ctrl) {
tab.settings.show_hidden = !tab.settings.show_hidden;
tab.refresh_list();
}
let mut require_refresh = false; // replace it with flow using https://docs.rs/notify/latest/notify/
egui::ScrollArea::vertical().show(ui, |ui| {
let text_height = egui::TextStyle::Body.resolve(ui.style()).size * 2.0;
Expand Down Expand Up @@ -364,18 +372,56 @@ impl MyTabs {
}

pub fn ui(&mut self, ui: &mut Ui) {
let tabs_amount = self.dock_state.iter_all_tabs().count();
let tabs: Vec<PathBuf> = self
let tabs = self.get_tabs_paths();

for ((_, _), item) in self.dock_state.iter_all_tabs_mut() {
item.update(&tabs);
}
DockArea::new(&mut self.dock_state)
.style(Self::get_dock_style(ui.style().as_ref(), tabs.len()))
.show_inside(ui, &mut MyTabViewer);

self.after_update();
}

pub fn open_in_new_tab(&mut self, path: &PathBuf) {
let is_not_focused = self.dock_state.focused_leaf().is_none();
if is_not_focused {
self.dock_state
.set_focused_node_and_surface((SurfaceIndex::main(), NodeIndex::root()));
}
let Some(active_tab) = self.get_current_tab() else {
return;
};
let new_window = TabData::from_path(path, Rc::clone(&active_tab.locations));
let root_node = self
.dock_state
.main_surface_mut()
.root_node_mut()
.expect("NO ROOT");
if root_node.is_leaf() {
root_node.append_tab(new_window);
} else {
self.dock_state.push_to_focused_leaf(new_window);
}
}

pub(crate) fn refresh_list(&mut self) {
let Some(active_tab) = self.get_current_tab() else {
return;
};
active_tab.refresh_list();
}

fn get_tabs_paths(&self) -> Vec<PathBuf> {
self.dock_state
.iter_all_tabs()
.map(|(_, tab)| tab.current_path.clone())
.collect();
.collect()
}

for ((_, _), item) in self.dock_state.iter_all_tabs_mut() {
item.can_close = tabs_amount > 1;
item.set_other_paths(&tabs);
}
let mut style = Style::from_egui(ui.style().as_ref());
fn get_dock_style(ui: &egui::Style, tabs_amount: usize) -> Style {
let mut style = Style::from_egui(ui);
style.dock_area_padding = None;
style.tab_bar.fill_tab_bar = true;
style.tab_bar.height = if tabs_amount > 1 {
Expand All @@ -385,10 +431,10 @@ impl MyTabs {
};
style.tab.tab_body.inner_margin = egui::Margin::same(10.0);
style.tab.tab_body.stroke = egui::Stroke::NONE;
DockArea::new(&mut self.dock_state)
.style(style)
.show_inside(ui, &mut MyTabViewer);
style
}

fn after_update(&mut self) {
let Some(active_tab) = self.get_current_tab() else {
return;
};
Expand All @@ -412,33 +458,4 @@ impl MyTabs {
}
}
}

pub fn open_in_new_tab(&mut self, path: &PathBuf) {
let is_not_focused = self.dock_state.focused_leaf().is_none();
if is_not_focused {
self.dock_state
.set_focused_node_and_surface((SurfaceIndex::main(), NodeIndex::root()));
}
let Some(active_tab) = self.get_current_tab() else {
return;
};
let new_window = TabData::from_path(path, Rc::clone(&active_tab.locations));
let root_node = self
.dock_state
.main_surface_mut()
.root_node_mut()
.expect("NO ROOT");
if root_node.is_leaf() {
root_node.append_tab(new_window);
} else {
self.dock_state.push_to_focused_leaf(new_window);
}
}

pub(crate) fn refresh_list(&mut self) {
let Some(active_tab) = self.get_current_tab() else {
return;
};
active_tab.refresh_list();
}
}

0 comments on commit da72099

Please sign in to comment.