Skip to content

Commit 0439524

Browse files
committed
chore: add remaining pages
1 parent 46ff890 commit 0439524

5 files changed

Lines changed: 228 additions & 7 deletions

File tree

src/ui/src/app.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use std::collections::HashMap;
44

5-
use crate::pages::clone;
65
use crate::{fl, pages};
76
use cosmic::app::{Command, Core};
87
use cosmic::iced::alignment::{Horizontal, Vertical};
@@ -19,6 +18,9 @@ pub struct Devmode {
1918
context_page: ContextPage,
2019
page: Page,
2120
clone: pages::clone::ClonePage,
21+
workspaces: pages::workspaces::WorkspacesPage,
22+
open: pages::open::OpenPage,
23+
config: pages::config::ConfigPage,
2224
key_binds: HashMap<menu::KeyBind, MenuAction>,
2325
nav: nav_bar::Model,
2426
}
@@ -30,10 +32,14 @@ pub struct Devmode {
3032
pub enum Message {
3133
LaunchUrl(String),
3234
ToggleContextPage(ContextPage),
33-
Clone(clone::Message),
35+
Clone(pages::clone::Message),
36+
Workspaces(pages::workspaces::Message),
37+
Open(pages::open::Message),
38+
Config(pages::config::Message),
3439
}
3540

3641
/// Identifies a page in the application.
42+
#[derive(Debug, Clone, Copy)]
3743
pub enum Page {
3844
Clone,
3945
Workspaces,
@@ -137,6 +143,9 @@ impl Application for Devmode {
137143
context_page: ContextPage::default(),
138144
page: Page::Clone,
139145
clone: pages::clone::ClonePage::new(),
146+
workspaces: pages::workspaces::WorkspacesPage::new(),
147+
open: pages::open::OpenPage::new(),
148+
config: pages::config::ConfigPage::new(),
140149
key_binds: HashMap::new(),
141150
nav,
142151
};
@@ -162,9 +171,9 @@ impl Application for Devmode {
162171

163172
let page: Element<Self::Message> = match self.page {
164173
Page::Clone => self.clone.view().map(Message::Clone),
165-
Page::Workspaces => todo!(),
166-
Page::Open => todo!(),
167-
Page::Config => todo!(),
174+
Page::Workspaces => self.workspaces.view().map(Message::Workspaces),
175+
Page::Open => self.open.view().map(Message::Open),
176+
Page::Config => self.config.view().map(Message::Config),
168177
};
169178

170179
widget::container(page)
@@ -185,16 +194,18 @@ impl Application for Devmode {
185194
Message::Clone(message) => {
186195
for command in self.clone.update(message) {
187196
match command {
188-
clone::Command::Clone(_repository, _workspace) => {
197+
pages::clone::Command::Clone(_repository, _workspace) => {
189198
todo!("Implement cloning mechanism.")
190199
}
191200
}
192201
}
193202
}
203+
Message::Workspaces(message) => for command in self.workspaces.update(message) {},
204+
Message::Open(message) => for command in self.open.update(message) {},
205+
Message::Config(message) => for command in self.config.update(message) {},
194206
Message::LaunchUrl(url) => {
195207
let _result = open::that_detached(url);
196208
}
197-
198209
Message::ToggleContextPage(context_page) => {
199210
if self.context_page == context_page {
200211
// Close the context drawer if the toggled context page is the same.
@@ -228,6 +239,10 @@ impl Application for Devmode {
228239
// Activate the page in the model.
229240
self.nav.activate(id);
230241

242+
if let Some(page) = self.nav.active_data::<Page>() {
243+
self.page = *page;
244+
}
245+
231246
Command::none()
232247
}
233248
}

src/ui/src/pages.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
pub mod clone;
2+
pub mod config;
3+
pub mod open;
4+
pub mod workspaces;

src/ui/src/pages/config.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use cosmic::{iced::Length, theme, widget, Apply, Element};
2+
3+
#[derive(Debug, Default)]
4+
pub struct ConfigPage {}
5+
6+
#[derive(Debug, Clone)]
7+
pub enum Message {}
8+
9+
pub enum Command {}
10+
11+
impl ConfigPage {
12+
pub fn new() -> Self {
13+
Self::default()
14+
}
15+
16+
fn header(&self) -> Element<Message> {
17+
widget::row::with_capacity(2)
18+
.push(widget::text::title2("Config"))
19+
.into()
20+
}
21+
22+
pub fn view(&self) -> Element<Message> {
23+
let spacing = theme::active().cosmic().spacing;
24+
25+
widget::column::with_capacity(2)
26+
.push(self.header())
27+
.spacing(spacing.space_xxs)
28+
.apply(widget::container)
29+
.height(Length::Shrink)
30+
.apply(widget::scrollable)
31+
.height(Length::Fill)
32+
.into()
33+
}
34+
35+
pub fn update(&self, message: Message) -> Vec<Command> {
36+
let mut commands = vec![];
37+
match message {}
38+
commands
39+
}
40+
}

src/ui/src/pages/open.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use cosmic::{
2+
iced::{Alignment, Length},
3+
theme, widget, Apply, Element,
4+
};
5+
use slotmap::{DefaultKey, SecondaryMap, SlotMap};
6+
7+
#[derive(Debug, Default)]
8+
pub struct Repository {
9+
url: String,
10+
selected: bool,
11+
}
12+
13+
#[derive(Debug, Default)]
14+
pub struct OpenPage {
15+
projects: Vec<String>,
16+
}
17+
18+
#[derive(Debug, Clone)]
19+
pub enum Message {
20+
Select(String),
21+
}
22+
23+
pub enum Command {}
24+
25+
impl OpenPage {
26+
pub fn new() -> Self {
27+
Self::default()
28+
}
29+
30+
fn header(&self) -> Element<Message> {
31+
widget::row::with_capacity(2)
32+
.push(widget::text::title2("Open"))
33+
.into()
34+
}
35+
36+
pub fn view(&self) -> Element<Message> {
37+
let spacing = theme::active().cosmic().spacing;
38+
39+
let mut items = widget::list::list_column()
40+
.style(theme::Container::ContextDrawer)
41+
.spacing(spacing.space_xxxs)
42+
.padding([spacing.space_none, spacing.space_xxs]);
43+
44+
for item in &self.projects {
45+
let item_text = widget::text(item).width(Length::Fill);
46+
47+
let row = widget::row::with_capacity(4)
48+
.align_items(Alignment::Center)
49+
.spacing(spacing.space_xxs)
50+
.padding([spacing.space_xxxs, spacing.space_xxs])
51+
.push(item_text);
52+
53+
items = items.add(row);
54+
}
55+
56+
widget::column::with_capacity(2)
57+
.push(self.header())
58+
.push(items)
59+
.spacing(spacing.space_xxs)
60+
.apply(widget::container)
61+
.height(Length::Shrink)
62+
.apply(widget::scrollable)
63+
.height(Length::Fill)
64+
.into()
65+
}
66+
67+
pub fn update(&self, message: Message) -> Vec<Command> {
68+
let mut commands = vec![];
69+
match message {
70+
Message::Select(_) => todo!(),
71+
}
72+
commands
73+
}
74+
}

src/ui/src/pages/workspaces.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use cosmic::{
2+
iced::{Alignment, Length},
3+
theme, widget, Apply, Element,
4+
};
5+
use slotmap::{DefaultKey, SecondaryMap, SlotMap};
6+
7+
#[derive(Debug, Default)]
8+
pub struct WorkspacesPage {
9+
workspaces: SlotMap<DefaultKey, String>,
10+
editing: SecondaryMap<DefaultKey, bool>,
11+
workspace_input_ids: SecondaryMap<DefaultKey, widget::Id>,
12+
}
13+
14+
#[derive(Debug, Clone)]
15+
pub enum Message {
16+
EditMode(DefaultKey, bool),
17+
TitleUpdate(DefaultKey, String),
18+
TitleSubmit(DefaultKey),
19+
}
20+
21+
pub enum Command {}
22+
23+
impl WorkspacesPage {
24+
pub fn new() -> Self {
25+
let mut workspaces = SlotMap::new();
26+
let mut workspace_input_ids = SecondaryMap::new();
27+
let id = workspaces.insert("tasks".into());
28+
workspace_input_ids.insert(id, widget::Id::unique());
29+
Self {
30+
workspaces,
31+
workspace_input_ids,
32+
..Default::default()
33+
}
34+
}
35+
36+
fn header(&self) -> Element<Message> {
37+
widget::row::with_capacity(2)
38+
.push(widget::text::title2("Workspaces"))
39+
.into()
40+
}
41+
42+
pub fn view(&self) -> Element<Message> {
43+
let spacing = theme::active().cosmic().spacing;
44+
45+
let mut items = widget::list::list_column()
46+
.style(theme::Container::ContextDrawer)
47+
.spacing(spacing.space_xxxs)
48+
.padding([spacing.space_none, spacing.space_xxs]);
49+
50+
for (id, item) in &self.workspaces {
51+
let item_text = widget::editable_input(
52+
"",
53+
item,
54+
*self.editing.get(id).unwrap_or(&false),
55+
move |editing| Message::EditMode(id, editing),
56+
)
57+
.id(self.workspace_input_ids[id].clone())
58+
.on_submit(Message::TitleSubmit(id))
59+
.on_input(move |text| Message::TitleUpdate(id, text))
60+
.width(Length::Fill);
61+
62+
let row = widget::row::with_capacity(4)
63+
.align_items(Alignment::Center)
64+
.spacing(spacing.space_xxs)
65+
.padding([spacing.space_xxxs, spacing.space_xxs])
66+
.push(item_text);
67+
68+
items = items.add(row);
69+
}
70+
71+
widget::column::with_capacity(2)
72+
.push(self.header())
73+
.push(items)
74+
.spacing(spacing.space_xxs)
75+
.apply(widget::container)
76+
.height(Length::Shrink)
77+
.apply(widget::scrollable)
78+
.height(Length::Fill)
79+
.into()
80+
}
81+
82+
pub fn update(&self, message: Message) -> Vec<Command> {
83+
match message {
84+
Message::TitleSubmit(_) => todo!(),
85+
Message::TitleUpdate(_, _) => todo!(),
86+
Message::EditMode(_, _) => todo!(),
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)