Add menu
This commit is contained in:
parent
0d54d87153
commit
036712ec6e
3 changed files with 95 additions and 31 deletions
17
Cargo.lock
generated
17
Cargo.lock
generated
|
|
@ -839,7 +839,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config"
|
name = "cosmic-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomicwrites",
|
"atomicwrites",
|
||||||
"cosmic-config-derive",
|
"cosmic-config-derive",
|
||||||
|
|
@ -853,7 +852,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config-derive"
|
name = "cosmic-config-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
@ -916,7 +914,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-theme"
|
name = "cosmic-theme"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"almost",
|
"almost",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
|
|
@ -2047,7 +2044,6 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2063,7 +2059,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_accessibility"
|
name = "iced_accessibility"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"accesskit_unix",
|
"accesskit_unix",
|
||||||
|
|
@ -2073,7 +2068,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
|
|
@ -2088,7 +2082,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2100,7 +2093,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2118,7 +2110,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_renderer"
|
name = "iced_renderer"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_tiny_skia",
|
"iced_tiny_skia",
|
||||||
|
|
@ -2131,7 +2122,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_runtime"
|
name = "iced_runtime"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2143,7 +2133,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_sctk"
|
name = "iced_sctk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"enum-repr",
|
"enum-repr",
|
||||||
"float-cmp",
|
"float-cmp",
|
||||||
|
|
@ -2167,7 +2156,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_style"
|
name = "iced_style"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
@ -2177,7 +2165,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_tiny_skia"
|
name = "iced_tiny_skia"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cosmic-text 0.9.0",
|
"cosmic-text 0.9.0",
|
||||||
|
|
@ -2195,7 +2182,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.11.1"
|
version = "0.11.1"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2217,7 +2203,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_widget"
|
name = "iced_widget"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_renderer",
|
"iced_renderer",
|
||||||
"iced_runtime",
|
"iced_runtime",
|
||||||
|
|
@ -2232,7 +2217,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_winit"
|
name = "iced_winit"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_runtime",
|
"iced_runtime",
|
||||||
|
|
@ -2479,7 +2463,6 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcosmic"
|
name = "libcosmic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#a2bda491520093c3343018204bfc8c4169b5e3b9"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"apply",
|
"apply",
|
||||||
"ashpd",
|
"ashpd",
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ features = ["syntect", "vi"]
|
||||||
#path = "../cosmic-text"
|
#path = "../cosmic-text"
|
||||||
|
|
||||||
[dependencies.libcosmic]
|
[dependencies.libcosmic]
|
||||||
git = "https://github.com/pop-os/libcosmic"
|
#git = "https://github.com/pop-os/libcosmic"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
path = "../libcosmic"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wayland"]
|
default = ["wayland"]
|
||||||
|
|
|
||||||
106
src/main.rs
106
src/main.rs
|
|
@ -7,13 +7,22 @@ use cosmic::{
|
||||||
widget::{column, row, text},
|
widget::{column, row, text},
|
||||||
Alignment, Length, Limits,
|
Alignment, Length, Limits,
|
||||||
},
|
},
|
||||||
widget::{self, icon, segmented_button, view_switcher},
|
theme,
|
||||||
|
widget::{
|
||||||
|
self, button, icon,
|
||||||
|
menu::{MenuBar, MenuTree},
|
||||||
|
segmented_button, view_switcher,
|
||||||
|
},
|
||||||
ApplicationExt, Element,
|
ApplicationExt, Element,
|
||||||
};
|
};
|
||||||
use cosmic_text::{
|
use cosmic_text::{
|
||||||
Attrs, Buffer, Edit, FontSystem, Metrics, SyntaxEditor, SyntaxSystem, ViEditor, ViMode,
|
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;
|
use self::menu_list::MenuList;
|
||||||
mod menu_list;
|
mod menu_list;
|
||||||
|
|
@ -45,6 +54,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Project {
|
||||||
|
path: PathBuf,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Project {
|
||||||
|
pub fn new<P: AsRef<Path>>(path: P) -> io::Result<Self> {
|
||||||
|
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 {
|
pub struct Tab {
|
||||||
path_opt: Option<PathBuf>,
|
path_opt: Option<PathBuf>,
|
||||||
attrs: Attrs<'static>,
|
attrs: Attrs<'static>,
|
||||||
|
|
@ -127,6 +160,7 @@ impl Tab {
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
core: Core,
|
core: Core,
|
||||||
|
projects: Vec<Project>,
|
||||||
tab_model: segmented_button::SingleSelectModel,
|
tab_model: segmented_button::SingleSelectModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,6 +183,15 @@ impl App {
|
||||||
self.tab_model.active_data_mut()
|
self.tab_model.active_data_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn open_project<P: AsRef<Path>>(&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<PathBuf>) {
|
pub fn open_tab(&mut self, path_opt: Option<PathBuf>) {
|
||||||
let mut tab = Tab::new();
|
let mut tab = Tab::new();
|
||||||
if let Some(path) = path_opt {
|
if let Some(path) = path_opt {
|
||||||
|
|
@ -200,11 +243,17 @@ impl cosmic::Application for App {
|
||||||
fn init(core: Core, _flags: Self::Flags) -> (Self, Command<Self::Message>) {
|
fn init(core: Core, _flags: Self::Flags) -> (Self, Command<Self::Message>) {
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
|
projects: Vec::new(),
|
||||||
tab_model: segmented_button::Model::builder().build(),
|
tab_model: segmented_button::Model::builder().build(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for path in env::args().skip(1) {
|
for arg in env::args().skip(1) {
|
||||||
app.open_tab(Some(PathBuf::from(path)));
|
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
|
// Open an empty file if no arguments provided
|
||||||
|
|
@ -277,14 +326,25 @@ impl cosmic::Application for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
|
/*
|
||||||
let menu_bar = row![
|
let menu_bar = row![
|
||||||
MenuList::new(vec!["Open", "Save"], None, |item| {
|
MenuList::new(
|
||||||
match item {
|
vec![
|
||||||
"Open" => Message::Open,
|
"New file",
|
||||||
"Save" => Message::Save,
|
"New window",
|
||||||
_ => Message::Todo,
|
"Open file...",
|
||||||
|
"Save",
|
||||||
|
"Save as..."
|
||||||
|
],
|
||||||
|
None,
|
||||||
|
|item| {
|
||||||
|
match item {
|
||||||
|
"Open" => Message::Open,
|
||||||
|
"Save" => Message::Save,
|
||||||
|
_ => Message::Todo,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
.padding(8)
|
.padding(8)
|
||||||
.placeholder("File"),
|
.placeholder("File"),
|
||||||
MenuList::new(vec!["Todo"], None, |_| Message::Todo).placeholder("Edit"),
|
MenuList::new(vec!["Todo"], None, |_| Message::Todo).placeholder("Edit"),
|
||||||
|
|
@ -294,6 +354,14 @@ impl cosmic::Application for App {
|
||||||
.align_items(Alignment::Start)
|
.align_items(Alignment::Start)
|
||||||
.padding(4)
|
.padding(4)
|
||||||
.spacing(16);
|
.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]);
|
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:
|
// Uncomment to debug layout:
|
||||||
//content.explain(Color::WHITE)
|
content.explain(cosmic::iced::Color::WHITE)
|
||||||
content
|
//content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue