feat(gui): one tab per open company, each a window on that company alone (D-78)

The viewer was a window on one company: App mixed what is one company's
(loader, books, page, filters, receipts, dock, menus) with what is the
app's (the color scheme). Two companies in two tabs need those apart, or
a filter set in one tab shows in the other.

- company.rs: CompanyView owns everything per company, including its own
  loader, its own handle to the Owner (the process-wide set_owner stays
  the program's default, each view takes a handle when made and a test can
  give a view another), its own dock and so its agent process.
- app.rs: App holds the per-app state, the views and which is in front.
  A view not in front still reads its loader every frame and takes the
  agent's books.show for its own page, so showing it later is current at
  once and the loader's channel never piles up Books behind it.
- Every egui id a view makes is scoped by the view's own id (push_id around
  the view; the owner dialogs' and the palette's modals, the pages' split
  widths, the sidebar's footer memo and links memo take it too; the
  projects' figure cache is keyed by the books). Otherwise egui's memory
  (a scrolled sidebar) carries from one tab into the next.
- data.rs: dropping a Loader wakes its thread at once and the thread
  stops, so a closed tab lets go of its watcher and its viewer presence
  now and not at the thread's next look (up to 3 s); Loader::watch tells
  a test the thread has ended.
- tabs.rs: the tab bar. One tab per company (the books' name, else their
  id), the front one marked by a heavier name, an accent bar and
  "selected" to assistive technology, not colour alone; a close control
  on each (middle click too); "+" lists the data root's companies not
  open; overflow scrolls with a step control at each end. It runs beside
  the sidebar, not above it: above it the owner's 1479x519 window makes
  the sidebar's links scroll (sidenav.rs), with a bar of 36, 28 or 24
  points alike, so the sidebar keeps the window's whole height.
- lib.rs/app.rs: a company named on the command line is the only tab;
  otherwise the companies open at the last close come back, in order,
  with the same one in front and each one's page and report period; a
  company that is gone is skipped, none left opens the data root's first.
  The old per-app keys keep their names; open_companies, active_company
  and company.<id>.* are new. The window's title names the company in
  front.
- scheme_menu.rs: the scheme button and its state moved out of App as they
  are (one scheme for the window).

A new tab's dock opens closed with the front tab's agent chosen, so
opening a company never starts an agent nobody asked for.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 09:29:21 -07:00
1 parent 526c27233e
commit 48cf9e3a03
11 files changed
+3362 -1893

No files matched your search

+57 -3
View File
@@ -39,24 +39,63 @@ pub struct Loader {
/// Set when this is dropped: the loader's thread then ends, letting go
/// of the books (and the viewer's presence on them).
gone: Arc<std::sync::atomic::AtomicBool>,
/// Wakes the thread at once when this is dropped, so it ends now and
/// not at its next look.
wake: Sender<()>,
/// Set by the thread as it ends.
ended: Arc<std::sync::atomic::AtomicBool>,
}
/// Says whether a loader's thread has ended, after the loader is gone.
#[derive(Clone)]
pub struct LoaderWatch(Arc<std::sync::atomic::AtomicBool>);
impl LoaderWatch {
/// Whether the thread has ended: its watcher, its hold on the books
/// and its viewer presence are released.
pub fn ended(&self) -> bool {
self.0.load(std::sync::atomic::Ordering::SeqCst)
}
}
/// Sets the flag when the loader's thread ends, however it ends.
struct Ends(Arc<std::sync::atomic::AtomicBool>);
impl Drop for Ends {
fn drop(&mut self) {
self.0.store(true, std::sync::atomic::Ordering::SeqCst);
}
}
impl Drop for Loader {
fn drop(&mut self) {
self.gone.store(true, std::sync::atomic::Ordering::SeqCst);
let _ = self.wake.send(());
}
}
impl Loader {
pub fn spawn(source: Source, ctx: egui::Context) -> Loader {
let (tx, rx) = channel();
let (wake, events) = channel();
let gone = Arc::new(std::sync::atomic::AtomicBool::new(false));
let ended = Arc::new(std::sync::atomic::AtomicBool::new(false));
let stop = gone.clone();
let ends = Ends(ended.clone());
let wake_to_watcher = wake.clone();
std::thread::Builder::new()
.name("books-loader".into())
.spawn(move || run(source, ctx, tx, &stop))
.spawn(move || {
let _ends = ends;
run(source, ctx, tx, &stop, wake_to_watcher, events)
})
.expect("spawn loader");
Loader { rx, gone }
Loader {
rx,
gone,
wake,
ended,
}
}
/// Every update since the last call, in order (books before the
@@ -69,6 +108,16 @@ impl Loader {
pub fn wait(&self, timeout: Duration) -> Option<Update> {
self.rx.recv_timeout(timeout).ok()
}
/// Whether the thread has ended (it ends once this is dropped).
pub fn finished(&self) -> bool {
self.ended.load(std::sync::atomic::Ordering::SeqCst)
}
/// A handle that outlives the loader and says when its thread ended.
pub fn watch(&self) -> LoaderWatch {
LoaderWatch(self.ended.clone())
}
}
/// Load once, synchronously (tests and one-shot tools).
@@ -123,6 +172,8 @@ fn run(
ctx: egui::Context,
tx: Sender<Update>,
gone: &std::sync::atomic::AtomicBool,
ev_tx: Sender<()>,
ev_rx: Receiver<()>,
) {
let gone = || gone.load(std::sync::atomic::Ordering::SeqCst);
let send = |u: Update| {
@@ -180,7 +231,6 @@ fn run(
};
check_show(&send);
let (ev_tx, ev_rx) = channel();
let mut watcher = notify::recommended_watcher(move |res: notify::Result<notify::Event>| {
if res.is_ok() {
let _ = ev_tx.send(());
@@ -225,6 +275,10 @@ fn run(
std::thread::sleep(Duration::from_secs(3));
}
}
// Dropped meanwhile (the wake-up is the drop): end now.
if gone() {
return;
}
let before = snap.journal_seq();
let grew = match snap.refresh() {
Ok(n) => n > 0,