diff --git a/Cargo.lock b/Cargo.lock index c0db41b..7064ae9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -839,7 +839,6 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -853,7 +852,6 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "quote", "syn 1.0.109", @@ -916,7 +914,6 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "almost", "cosmic-config", @@ -2047,7 +2044,6 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iced" version = "0.10.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "iced_accessibility", "iced_core", @@ -2063,7 +2059,6 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "accesskit", "accesskit_unix", @@ -2073,7 +2068,6 @@ dependencies = [ [[package]] name = "iced_core" version = "0.10.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "bitflags 1.3.2", "iced_accessibility", @@ -2088,7 +2082,6 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.7.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "futures", "iced_core", @@ -2100,7 +2093,6 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.9.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -2118,7 +2110,6 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2131,7 +2122,6 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.1.1" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "iced_accessibility", "iced_core", @@ -2143,7 +2133,6 @@ dependencies = [ [[package]] name = "iced_sctk" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "enum-repr", "float-cmp", @@ -2167,7 +2156,6 @@ dependencies = [ [[package]] name = "iced_style" version = "0.9.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "iced_core", "once_cell", @@ -2177,7 +2165,6 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "bytemuck", "cosmic-text 0.9.0", @@ -2195,7 +2182,6 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.11.1" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -2217,7 +2203,6 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.1.3" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "iced_renderer", "iced_runtime", @@ -2232,7 +2217,6 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.10.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "iced_graphics", "iced_runtime", @@ -2479,7 +2463,6 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9" dependencies = [ "apply", "ashpd", diff --git a/Cargo.toml b/Cargo.toml index ba14a2b..de4c39d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,9 @@ features = ["syntect", "vi"] #path = "../cosmic-text" [dependencies.libcosmic] -git = "https://github.com/pop-os/libcosmic" +#git = "https://github.com/pop-os/libcosmic" default-features = false +path = "../libcosmic" [features] default = ["wayland"] diff --git a/src/main.rs b/src/main.rs index dc1c54a..c6488b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,13 +7,22 @@ use cosmic::{ widget::{column, row, text}, Alignment, Length, Limits, }, - widget::{self, icon, segmented_button, view_switcher}, + theme, + widget::{ + self, button, icon, + menu::{MenuBar, MenuTree}, + segmented_button, view_switcher, + }, ApplicationExt, Element, }; use cosmic_text::{ Attrs, Buffer, Edit, FontSystem, Metrics, SyntaxEditor, SyntaxSystem, ViEditor, ViMode, }; -use std::{env, fs, path::PathBuf, sync::Mutex}; +use std::{ + env, fs, io, + path::{Path, PathBuf}, + sync::Mutex, +}; use self::menu_list::MenuList; mod menu_list; @@ -45,6 +54,30 @@ fn main() -> Result<(), Box> { Ok(()) } +pub struct Project { + path: PathBuf, + name: String, +} + +impl Project { + pub fn new>(path: P) -> io::Result { + let path = fs::canonicalize(path)?; + let name = path + .file_name() + .ok_or(io::Error::new( + io::ErrorKind::Other, + format!("Path {:?} has no file name", path), + ))? + .to_str() + .ok_or(io::Error::new( + io::ErrorKind::Other, + format!("Path {:?} is not valid UTF-8", path), + ))? + .to_string(); + Ok(Self { path, name }) + } +} + pub struct Tab { path_opt: Option, attrs: Attrs<'static>, @@ -127,6 +160,7 @@ impl Tab { pub struct App { core: Core, + projects: Vec, tab_model: segmented_button::SingleSelectModel, } @@ -149,6 +183,15 @@ impl App { self.tab_model.active_data_mut() } + pub fn open_project>(&mut self, path: P) { + match Project::new(&path) { + Ok(project) => self.projects.push(project), + Err(err) => { + log::error!("failed to open '{}': {}", path.as_ref().display(), err); + } + } + } + pub fn open_tab(&mut self, path_opt: Option) { let mut tab = Tab::new(); if let Some(path) = path_opt { @@ -200,11 +243,17 @@ impl cosmic::Application for App { fn init(core: Core, _flags: Self::Flags) -> (Self, Command) { let mut app = App { core, + projects: Vec::new(), tab_model: segmented_button::Model::builder().build(), }; - for path in env::args().skip(1) { - app.open_tab(Some(PathBuf::from(path))); + for arg in env::args().skip(1) { + let path = PathBuf::from(arg); + if path.is_dir() { + app.open_project(path); + } else { + app.open_tab(Some(path)); + } } // Open an empty file if no arguments provided @@ -277,14 +326,25 @@ impl cosmic::Application for App { } fn view(&self) -> Element { + /* let menu_bar = row![ - MenuList::new(vec!["Open", "Save"], None, |item| { - match item { - "Open" => Message::Open, - "Save" => Message::Save, - _ => Message::Todo, + MenuList::new( + vec![ + "New file", + "New window", + "Open file...", + "Save", + "Save as..." + ], + None, + |item| { + match item { + "Open" => Message::Open, + "Save" => Message::Save, + _ => Message::Todo, + } } - }) + ) .padding(8) .placeholder("File"), MenuList::new(vec!["Todo"], None, |_| Message::Todo).placeholder("Edit"), @@ -294,6 +354,14 @@ impl cosmic::Application for App { .align_items(Alignment::Start) .padding(4) .spacing(16); + */ + + //TODO: port macros menu_bar! and menu_tree! + let menu_bar: Element<_> = MenuBar::new(vec![MenuTree::with_children( + button("File"), + vec![MenuTree::new(button("New file"))], + )]) + .into(); let mut tab_column = widget::column::with_capacity(3).padding([0, 16]); @@ -337,10 +405,22 @@ impl cosmic::Application for App { } }; - let content: Element<_> = column![menu_bar, tab_column].into(); + let mut project_row = widget::row::with_capacity(2); + if !self.projects.is_empty() { + /*TODO: project tree view + let mut project_list = widget::column::with_capacity(self.projects.len()); + for project in self.projects.iter() { + project_list = project_list.push(widget::text(&project.name)); + } + project_row = project_row.push(project_list); + */ + } + project_row = project_row.push(tab_column); + + let content: Element<_> = column![menu_bar, project_row].into(); // Uncomment to debug layout: - //content.explain(Color::WHITE) - content + content.explain(cosmic::iced::Color::WHITE) + //content } }