chore: move add applets page to context drawer
This commit is contained in:
parent
38861985a8
commit
11de7cbd4a
3 changed files with 55 additions and 144 deletions
|
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::pages::desktop::{
|
use crate::pages::desktop::{
|
||||||
self, appearance,
|
self, appearance, dock,
|
||||||
dock::{self, applets::ADD_DOCK_APPLET_DIALOGUE_ID},
|
|
||||||
panel::{
|
panel::{
|
||||||
self,
|
self,
|
||||||
applets_inner::{self, AppletsPage, APPLET_DND_ICON_ID},
|
applets_inner::{self, AppletsPage, APPLET_DND_ICON_ID},
|
||||||
|
|
@ -168,22 +167,6 @@ impl cosmic::Application for SettingsApp {
|
||||||
widgets
|
widgets
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_close_requested(&self, id: window::Id) -> Option<Self::Message> {
|
|
||||||
let message = if id == *applets_inner::ADD_PANEL_APPLET_DIALOGUE_ID {
|
|
||||||
Message::PageMessage(crate::pages::Message::PanelApplet(
|
|
||||||
applets_inner::Message::ClosedAppletDialog,
|
|
||||||
))
|
|
||||||
} else if id == *ADD_DOCK_APPLET_DIALOGUE_ID {
|
|
||||||
Message::PageMessage(crate::pages::Message::DockApplet(dock::applets::Message(
|
|
||||||
applets_inner::Message::ClosedAppletDialog,
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_escape(&mut self) -> Command<Self::Message> {
|
fn on_escape(&mut self) -> Command<Self::Message> {
|
||||||
if self.search_active {
|
if self.search_active {
|
||||||
self.search_active = false;
|
self.search_active = false;
|
||||||
|
|
@ -343,9 +326,7 @@ impl cosmic::Application for SettingsApp {
|
||||||
|
|
||||||
crate::pages::Message::PanelApplet(message) => {
|
crate::pages::Message::PanelApplet(message) => {
|
||||||
if let Some(page) = self.pages.page_mut::<applets_inner::Page>() {
|
if let Some(page) = self.pages.page_mut::<applets_inner::Page>() {
|
||||||
return page
|
return page.update(message).map(cosmic::app::Message::App);
|
||||||
.update(message, *applets_inner::ADD_PANEL_APPLET_DIALOGUE_ID)
|
|
||||||
.map(cosmic::app::Message::App);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,10 +356,7 @@ impl cosmic::Application for SettingsApp {
|
||||||
|
|
||||||
if let Some(page) = self.pages.page_mut::<applets_inner::Page>() {
|
if let Some(page) = self.pages.page_mut::<applets_inner::Page>() {
|
||||||
return page
|
return page
|
||||||
.update(
|
.update(applets_inner::Message::PanelConfig(config))
|
||||||
applets_inner::Message::PanelConfig(config),
|
|
||||||
*applets_inner::ADD_PANEL_APPLET_DIALOGUE_ID,
|
|
||||||
)
|
|
||||||
.map(cosmic::app::Message::App);
|
.map(cosmic::app::Message::App);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -410,10 +388,7 @@ impl cosmic::Application for SettingsApp {
|
||||||
);
|
);
|
||||||
if let Some(page) = self.pages.page_mut::<applets_inner::Page>() {
|
if let Some(page) = self.pages.page_mut::<applets_inner::Page>() {
|
||||||
return page
|
return page
|
||||||
.update(
|
.update(applets_inner::Message::Applets(info_list))
|
||||||
applets_inner::Message::Applets(info_list),
|
|
||||||
*applets_inner::ADD_PANEL_APPLET_DIALOGUE_ID,
|
|
||||||
)
|
|
||||||
.map(cosmic::app::Message::App);
|
.map(cosmic::app::Message::App);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -491,32 +466,6 @@ impl cosmic::Application for SettingsApp {
|
||||||
return page.dnd_icon();
|
return page.dnd_icon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(Some(page)) = (id == *applets_inner::ADD_PANEL_APPLET_DIALOGUE_ID)
|
|
||||||
.then(|| self.pages.page::<applets_inner::Page>())
|
|
||||||
{
|
|
||||||
return page.add_applet_view(crate::pages::Message::PanelApplet);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(Some(page)) =
|
|
||||||
(id == *ADD_DOCK_APPLET_DIALOGUE_ID).then(|| self.pages.page::<dock::applets::Page>())
|
|
||||||
{
|
|
||||||
return page.inner().add_applet_view(|msg| {
|
|
||||||
crate::pages::Message::DockApplet(dock::applets::Message(msg))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// if let Some(Some(page)) = (id == *keyboard::ADD_INPUT_SOURCE_DIALOGUE_ID)
|
|
||||||
// .then(|| self.pages.page::<input::Page>())
|
|
||||||
// {
|
|
||||||
// return page.add_input_source_view();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if let Some(Some(page)) = (id == *keyboard::SPECIAL_CHARACTER_DIALOGUE_ID)
|
|
||||||
// .then(|| self.pages.page::<input::Page>())
|
|
||||||
// {
|
|
||||||
// return page.special_character_key_view();
|
|
||||||
// }
|
|
||||||
|
|
||||||
if let Some(page) = self.pages.page::<desktop::wallpaper::Page>() {
|
if let Some(page) = self.pages.page::<desktop::wallpaper::Page>() {
|
||||||
if id == page.color_dialog {
|
if id == page.color_dialog {
|
||||||
return page.show_color_dialog();
|
return page.show_color_dialog();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use cosmic::{cosmic_config::CosmicConfigEntry, iced::window, iced_runtime::Command};
|
use cosmic::{cosmic_config::CosmicConfigEntry, iced::window, iced_runtime::Command, Element};
|
||||||
use cosmic_panel_config::CosmicPanelConfig;
|
use cosmic_panel_config::CosmicPanelConfig;
|
||||||
use cosmic_settings_page::{self as page, section, Section};
|
use cosmic_settings_page::{self as page, section, Section};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
@ -9,12 +9,12 @@ use crate::{
|
||||||
app,
|
app,
|
||||||
pages::{
|
pages::{
|
||||||
self,
|
self,
|
||||||
desktop::panel::applets_inner::{self, lists, AppletsPage, ReorderWidgetState},
|
desktop::panel::applets_inner::{
|
||||||
|
self, lists, AppletsPage, ContextDrawer, ReorderWidgetState,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub static ADD_DOCK_APPLET_DIALOGUE_ID: Lazy<window::Id> = Lazy::new(window::Id::unique);
|
|
||||||
|
|
||||||
pub(crate) struct Page {
|
pub(crate) struct Page {
|
||||||
inner: applets_inner::Page,
|
inner: applets_inner::Page,
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +38,7 @@ impl Default for Page {
|
||||||
current_config,
|
current_config,
|
||||||
reorder_widget_state: ReorderWidgetState::default(),
|
reorder_widget_state: ReorderWidgetState::default(),
|
||||||
search: String::new(),
|
search: String::new(),
|
||||||
has_dialog: false,
|
context: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ pub struct Message(pub applets_inner::Message);
|
||||||
|
|
||||||
impl Page {
|
impl Page {
|
||||||
pub fn update(&mut self, message: Message) -> Command<app::Message> {
|
pub fn update(&mut self, message: Message) -> Command<app::Message> {
|
||||||
self.inner.update(message.0, *ADD_DOCK_APPLET_DIALOGUE_ID)
|
self.inner.update(message.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +76,16 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
|
|
||||||
fn info(&self) -> page::Info {
|
fn info(&self) -> page::Info {
|
||||||
page::Info::new("dock_applets", "preferences-dock-symbolic")
|
page::Info::new("dock_applets", "preferences-dock-symbolic")
|
||||||
// .title(fl!("applets"))
|
}
|
||||||
|
|
||||||
|
fn context_drawer(&self) -> Option<Element<crate::pages::Message>> {
|
||||||
|
Some(match self.inner.context {
|
||||||
|
Some(ContextDrawer::AddApplet) => self
|
||||||
|
.inner
|
||||||
|
.add_applet_view(|msg| crate::pages::Message::DockApplet(Message(msg))),
|
||||||
|
|
||||||
|
None => return None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ use button::StyleSheet as ButtonStyleSheet;
|
||||||
use cosmic::iced_style::container::StyleSheet;
|
use cosmic::iced_style::container::StyleSheet;
|
||||||
|
|
||||||
use cosmic::widget::{
|
use cosmic::widget::{
|
||||||
button, column, container, header_bar, horizontal_space, icon, list_column, row, scrollable,
|
self, button, column, container, header_bar, horizontal_space, icon, list_column, row,
|
||||||
text, text_input, Column,
|
scrollable, text, text_input, Column,
|
||||||
};
|
};
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
|
|
@ -69,7 +69,6 @@ const SPACING: f32 = 8.0;
|
||||||
const DRAG_START_DISTANCE_SQUARED: f32 = 64.0;
|
const DRAG_START_DISTANCE_SQUARED: f32 = 64.0;
|
||||||
|
|
||||||
pub static APPLET_DND_ICON_ID: Lazy<window::Id> = Lazy::new(window::Id::unique);
|
pub static APPLET_DND_ICON_ID: Lazy<window::Id> = Lazy::new(window::Id::unique);
|
||||||
pub static ADD_PANEL_APPLET_DIALOGUE_ID: Lazy<window::Id> = Lazy::new(window::Id::unique);
|
|
||||||
|
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
pub(crate) available_entries: Vec<Applet<'static>>,
|
pub(crate) available_entries: Vec<Applet<'static>>,
|
||||||
|
|
@ -77,7 +76,7 @@ pub struct Page {
|
||||||
pub(crate) current_config: Option<CosmicPanelConfig>,
|
pub(crate) current_config: Option<CosmicPanelConfig>,
|
||||||
pub(crate) reorder_widget_state: ReorderWidgetState,
|
pub(crate) reorder_widget_state: ReorderWidgetState,
|
||||||
pub(crate) search: String,
|
pub(crate) search: String,
|
||||||
pub(crate) has_dialog: bool,
|
pub(crate) context: Option<ContextDrawer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Page {
|
impl Default for Page {
|
||||||
|
|
@ -98,7 +97,7 @@ impl Default for Page {
|
||||||
current_config,
|
current_config,
|
||||||
reorder_widget_state: ReorderWidgetState::default(),
|
reorder_widget_state: ReorderWidgetState::default(),
|
||||||
search: String::new(),
|
search: String::new(),
|
||||||
has_dialog: false,
|
context: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,6 +133,16 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
page::Info::new("panel_applets", "preferences-dock-symbolic")
|
page::Info::new("panel_applets", "preferences-dock-symbolic")
|
||||||
// .title(fl!("applets"))
|
// .title(fl!("applets"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn context_drawer(&self) -> Option<Element<pages::Message>> {
|
||||||
|
Some(match self.context {
|
||||||
|
Some(ContextDrawer::AddApplet) => {
|
||||||
|
self.add_applet_view(crate::pages::Message::PanelApplet)
|
||||||
|
}
|
||||||
|
|
||||||
|
None => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl page::AutoBind<crate::pages::Message> for Page {}
|
impl page::AutoBind<crate::pages::Message> for Page {}
|
||||||
|
|
@ -156,9 +165,6 @@ pub enum Message {
|
||||||
Search(String),
|
Search(String),
|
||||||
AddApplet(Applet<'static>),
|
AddApplet(Applet<'static>),
|
||||||
AddAppletDialog,
|
AddAppletDialog,
|
||||||
CloseAppletDialog,
|
|
||||||
ClosedAppletDialog,
|
|
||||||
DragAppletDialog,
|
|
||||||
Save,
|
Save,
|
||||||
Cancel,
|
Cancel,
|
||||||
}
|
}
|
||||||
|
|
@ -184,13 +190,14 @@ impl Debug for Message {
|
||||||
Message::Search(_) => write!(f, "Search"),
|
Message::Search(_) => write!(f, "Search"),
|
||||||
Message::AddApplet(_) => write!(f, "AddApplet"),
|
Message::AddApplet(_) => write!(f, "AddApplet"),
|
||||||
Message::AddAppletDialog => write!(f, "AddAppletDialogue"),
|
Message::AddAppletDialog => write!(f, "AddAppletDialogue"),
|
||||||
Message::CloseAppletDialog => write!(f, "CloseAppletDialogue"),
|
|
||||||
Message::DragAppletDialog => write!(f, "DragAppletDialogue"),
|
|
||||||
Message::ClosedAppletDialog => write!(f, "ClosedAppletDialogue"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum ContextDrawer {
|
||||||
|
AddApplet,
|
||||||
|
}
|
||||||
|
|
||||||
impl Page {
|
impl Page {
|
||||||
pub fn save(&self) {
|
pub fn save(&self) {
|
||||||
let Some(config) = self.current_config.as_ref() else {
|
let Some(config) = self.current_config.as_ref() else {
|
||||||
|
|
@ -216,7 +223,7 @@ impl Page {
|
||||||
pub fn add_applet_view<T: Fn(Message) -> crate::pages::Message + Copy + 'static>(
|
pub fn add_applet_view<T: Fn(Message) -> crate::pages::Message + Copy + 'static>(
|
||||||
&self,
|
&self,
|
||||||
msg_map: T,
|
msg_map: T,
|
||||||
) -> Element<app::Message> {
|
) -> Element<crate::pages::Message> {
|
||||||
let mut list_column = list_column();
|
let mut list_column = list_column();
|
||||||
let mut has_some = false;
|
let mut has_some = false;
|
||||||
for info in self
|
for info in self
|
||||||
|
|
@ -282,9 +289,7 @@ impl Page {
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.padding(8.0)
|
.padding(8.0)
|
||||||
.on_press(app::Message::PageMessage(msg_map(Message::AddApplet(
|
.on_press(msg_map(Message::AddApplet(info.clone())))
|
||||||
info.clone(),
|
|
||||||
))))
|
|
||||||
.into(),
|
.into(),
|
||||||
])
|
])
|
||||||
.padding([0, 32, 0, 32])
|
.padding([0, 32, 0, 32])
|
||||||
|
|
@ -299,48 +304,23 @@ impl Page {
|
||||||
.horizontal_alignment(Horizontal::Center),
|
.horizontal_alignment(Horizontal::Center),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
column::with_children(vec![
|
column::with_children(vec![
|
||||||
header_bar()
|
text_input::search_input(fl!("search-applets"), &self.search)
|
||||||
.title(fl!("add-applet"))
|
.on_input(move |s| msg_map(Message::Search(s)))
|
||||||
.on_close(app::Message::PageMessage(msg_map(
|
.on_paste(move |s| msg_map(Message::Search(s)))
|
||||||
Message::CloseAppletDialog,
|
.width(Length::Fixed(312.0))
|
||||||
)))
|
|
||||||
.on_drag(app::Message::PageMessage(msg_map(
|
|
||||||
Message::DragAppletDialog,
|
|
||||||
)))
|
|
||||||
.into(),
|
.into(),
|
||||||
container(
|
scrollable(list_column).into(),
|
||||||
scrollable(
|
|
||||||
column::with_children(vec![
|
|
||||||
text(fl!("add-applet")).size(24).width(Length::Fill).into(),
|
|
||||||
text_input::search_input(fl!("search-applets"), &self.search)
|
|
||||||
.on_input(move |s| {
|
|
||||||
app::Message::PageMessage(msg_map(Message::Search(s)))
|
|
||||||
})
|
|
||||||
.on_paste(move |s| {
|
|
||||||
app::Message::PageMessage(msg_map(Message::Search(s)))
|
|
||||||
})
|
|
||||||
.width(Length::Fixed(312.0))
|
|
||||||
.into(),
|
|
||||||
list_column.into(),
|
|
||||||
])
|
|
||||||
.padding([0, 64, 32, 64])
|
|
||||||
.align_items(Alignment::Center)
|
|
||||||
.spacing(8.0),
|
|
||||||
)
|
|
||||||
.width(Length::Fill)
|
|
||||||
.height(Length::Fill),
|
|
||||||
)
|
|
||||||
.style(theme::Container::Background)
|
|
||||||
.width(Length::Fill)
|
|
||||||
.height(Length::Fill)
|
|
||||||
.into(),
|
|
||||||
])
|
])
|
||||||
|
.padding([0, 64, 32, 64])
|
||||||
|
.align_items(Alignment::Center)
|
||||||
|
.spacing(8.0)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn update(&mut self, message: Message, window_id: window::Id) -> Command<app::Message> {
|
pub fn update(&mut self, message: Message) -> Command<app::Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::PanelConfig(c) => {
|
Message::PanelConfig(c) => {
|
||||||
self.current_config = Some(c);
|
self.current_config = Some(c);
|
||||||
|
|
@ -464,38 +444,12 @@ impl Page {
|
||||||
|
|
||||||
list.push(applet.id.to_string());
|
list.push(applet.id.to_string());
|
||||||
self.save();
|
self.save();
|
||||||
return commands::window::close_window(window_id);
|
|
||||||
}
|
}
|
||||||
Message::AddAppletDialog => {
|
Message::AddAppletDialog => {
|
||||||
self.has_dialog = true;
|
self.context = Some(ContextDrawer::AddApplet);
|
||||||
let window_settings = SctkWindowSettings {
|
return cosmic::command::message(app::Message::OpenContextDrawer(Cow::Owned(fl!(
|
||||||
window_id,
|
"add-applet"
|
||||||
app_id: Some("com.system76.CosmicSettings".to_string()),
|
))));
|
||||||
title: Some(fl!("add-applet")),
|
|
||||||
parent: Some(window::Id::MAIN),
|
|
||||||
autosize: false,
|
|
||||||
size_limits: layout::Limits::NONE
|
|
||||||
.min_width(300.0)
|
|
||||||
.max_width(800.0)
|
|
||||||
.min_height(200.0)
|
|
||||||
.max_height(1080.0),
|
|
||||||
size: (512, 420),
|
|
||||||
resizable: None,
|
|
||||||
client_decorations: true,
|
|
||||||
transparent: true,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
return commands::window::get_window(window_settings);
|
|
||||||
}
|
|
||||||
Message::ClosedAppletDialog => {
|
|
||||||
self.has_dialog = false;
|
|
||||||
}
|
|
||||||
Message::CloseAppletDialog => {
|
|
||||||
self.has_dialog = false;
|
|
||||||
return commands::window::close_window(window_id);
|
|
||||||
}
|
|
||||||
Message::DragAppletDialog => {
|
|
||||||
return commands::window::start_drag_window(window_id);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Command::none()
|
Command::none()
|
||||||
|
|
@ -521,8 +475,7 @@ pub fn lists<
|
||||||
column::with_children(vec![
|
column::with_children(vec![
|
||||||
row::with_children(vec![
|
row::with_children(vec![
|
||||||
text(fl!("applets")).width(Length::Fill).size(24).into(),
|
text(fl!("applets")).width(Length::Fill).size(24).into(),
|
||||||
(button.on_press_maybe((!page.has_dialog).then_some(Message::AddAppletDialog)))
|
(button.on_press(Message::AddAppletDialog)).into(),
|
||||||
.into(),
|
|
||||||
])
|
])
|
||||||
.into(),
|
.into(),
|
||||||
text(fl!("start-segment")).into(),
|
text(fl!("start-segment")).into(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue