mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-12 20:57:46 +02:00
Big restructuring
This commit is contained in:
parent
c4c95df8d3
commit
13084ed86d
22 changed files with 638 additions and 595 deletions
|
@ -1,8 +1,8 @@
|
|||
use gtk::{Align, FlowBox, FlowBoxChild};
|
||||
use gtk::prelude::{FlowBoxChildExt, WidgetExt};
|
||||
use crate::components::audio::AudioBox;
|
||||
use crate::components::bluetooth::BluetoothBox;
|
||||
use crate::components::wifi::WifiBox;
|
||||
use crate::components::audio::audioBox::AudioBox;
|
||||
use crate::components::bluetooth::bluetoothBox::BluetoothBox;
|
||||
use crate::components::wifi::wifiBox::WifiBox;
|
||||
|
||||
pub const HANDLE_CONNECTIVITY_CLICK: fn(FlowBox) = |resetMain: FlowBox| {
|
||||
let wifibox = WifiBox::new();
|
||||
|
|
|
@ -1,248 +1,6 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use adw::BreakpointCondition;
|
||||
use adw::glib::clone;
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::Object;
|
||||
use gtk::{Application, FlowBox, gio, glib};
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crate::components::window::handleSidebarClick::{
|
||||
HANDLE_AUDIO_CLICK, HANDLE_BLUETOOTH_CLICK, HANDLE_CONNECTIVITY_CLICK, HANDLE_MICROPHONE_CLICK,
|
||||
HANDLE_VOLUME_CLICK, HANDLE_VPN_CLICK, HANDLE_WIFI_CLICK,
|
||||
};
|
||||
use crate::components::window::sidebarEntry::{Categories, SidebarAction};
|
||||
|
||||
mod handleSidebarClick;
|
||||
mod sidebarEntry;
|
||||
mod window;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct Window(ObjectSubclass<window::Window>)
|
||||
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
|
||||
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SidebarEntry(ObjectSubclass<sidebarEntry::SidebarEntry>)
|
||||
@extends gtk::ListBoxRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
impl Window {
|
||||
pub fn new(app: &Application) -> Self {
|
||||
Object::builder().property("application", app).build()
|
||||
}
|
||||
|
||||
fn setupCallback(&self) {
|
||||
let selfImp = self.imp();
|
||||
|
||||
selfImp.resetSearchEntry.connect_search_changed(clone!(@ weak self as window => move |_| {
|
||||
window.filterList();
|
||||
}));
|
||||
|
||||
selfImp.resetSideBarToggle.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
window.toggleSidebar();
|
||||
}));
|
||||
|
||||
selfImp.resetSidebarList.connect_row_activated(
|
||||
clone!(@ weak selfImp as flowbox => move |_, y| {
|
||||
let result = y.downcast_ref::<SidebarEntry>().unwrap();
|
||||
let clickEvent = result.imp().onClickEvent.borrow().onClickEvent;
|
||||
(clickEvent)(flowbox.resetMain.get());
|
||||
}),
|
||||
);
|
||||
|
||||
selfImp.resetClose.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
window.close();
|
||||
}));
|
||||
|
||||
// selfImp.resetMenu.connect_clicked(|_| {
|
||||
// WifiBox::donotdisturb();
|
||||
//
|
||||
// });
|
||||
}
|
||||
|
||||
fn handleDynamicSidebar(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp.resetSidebarBreakpoint.set_condition(BreakpointCondition::parse("max-width: 600sp").as_ref().ok());
|
||||
selfImp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(selfImp.resetOverlaySplitView.get()),
|
||||
"collapsed",
|
||||
&true.to_value(),
|
||||
);
|
||||
selfImp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(selfImp.resetSideBarToggle.get()),
|
||||
"visible",
|
||||
&true.to_value(),
|
||||
);
|
||||
}
|
||||
|
||||
fn filterList(&self) {
|
||||
let text = self.imp().resetSearchEntry.text().to_string();
|
||||
for (mainEntry, subEntries) in self.imp().sidebarEntries.borrow().iter() {
|
||||
if text == "" {
|
||||
mainEntry.set_visible(true);
|
||||
for subEntry in subEntries {
|
||||
subEntry.set_visible(true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if mainEntry.imp().name.borrow().to_lowercase().contains(&text.to_lowercase()) {
|
||||
mainEntry.set_visible(true);
|
||||
} else {
|
||||
mainEntry.set_visible(false);
|
||||
}
|
||||
for subEntry in subEntries {
|
||||
if subEntry.imp().name.borrow().to_lowercase().contains(&text.to_lowercase()) {
|
||||
subEntry.set_visible(true);
|
||||
mainEntry.set_visible(true);
|
||||
} else {
|
||||
subEntry.set_visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn toggleSidebar(&self) {
|
||||
if self.imp().resetOverlaySplitView.shows_sidebar() {
|
||||
self.imp().resetOverlaySplitView.set_show_sidebar(false);
|
||||
} else {
|
||||
self.imp().resetOverlaySplitView.set_show_sidebar(true);
|
||||
}
|
||||
}
|
||||
|
||||
fn setupSidebarEntries(&self) {
|
||||
let selfImp = self.imp();
|
||||
let mut sidebarEntries = selfImp.sidebarEntries.borrow_mut();
|
||||
|
||||
let connectivityList = vec![
|
||||
SidebarEntry::new(
|
||||
"WiFi",
|
||||
"network-wireless-symbolic",
|
||||
Categories::Connectivity,
|
||||
true,
|
||||
HANDLE_WIFI_CLICK,
|
||||
),
|
||||
SidebarEntry::new(
|
||||
"Bluetooth",
|
||||
"bluetooth-symbolic",
|
||||
Categories::Connectivity,
|
||||
true,
|
||||
HANDLE_BLUETOOTH_CLICK,
|
||||
),
|
||||
SidebarEntry::new(
|
||||
"VPN",
|
||||
"network-vpn-symbolic",
|
||||
Categories::Connectivity,
|
||||
true,
|
||||
HANDLE_VPN_CLICK,
|
||||
),
|
||||
];
|
||||
|
||||
sidebarEntries.push((
|
||||
SidebarEntry::new(
|
||||
"Connectivity",
|
||||
"network-wired-symbolic",
|
||||
Categories::Connectivity,
|
||||
false,
|
||||
HANDLE_CONNECTIVITY_CLICK,
|
||||
),
|
||||
connectivityList,
|
||||
));
|
||||
|
||||
let audioList = vec![
|
||||
SidebarEntry::new(
|
||||
"Volume",
|
||||
"audio-volume-high-symbolic",
|
||||
Categories::Audio,
|
||||
true,
|
||||
HANDLE_VOLUME_CLICK,
|
||||
),
|
||||
SidebarEntry::new(
|
||||
"Microphone",
|
||||
"audio-input-microphone-symbolic",
|
||||
Categories::Audio,
|
||||
true,
|
||||
HANDLE_MICROPHONE_CLICK,
|
||||
),
|
||||
];
|
||||
|
||||
sidebarEntries.push((
|
||||
SidebarEntry::new(
|
||||
"Audio",
|
||||
"audio-headset-symbolic",
|
||||
Categories::Audio,
|
||||
false,
|
||||
HANDLE_AUDIO_CLICK,
|
||||
),
|
||||
audioList,
|
||||
));
|
||||
|
||||
for (mainEntry, subEntries) in sidebarEntries.iter() {
|
||||
selfImp.resetSidebarList.append(mainEntry);
|
||||
for subEntry in subEntries {
|
||||
selfImp.resetSidebarList.append(subEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setupPopoverButtons(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp.resetAboutButton.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
let dialog = adw::AboutWindow::builder()
|
||||
.application_name("ReSet")
|
||||
.application_icon("ReSet")
|
||||
.developer_name("Xetibo")
|
||||
.license("GPL-3.0")
|
||||
.license_type(gtk::License::Gpl30)
|
||||
.website("https://github.com/Xetibo/ReSet")
|
||||
.issue_url("https://github.com/Xetibo/ReSet/issues")
|
||||
.version("0.0.1")
|
||||
.transient_for(&window)
|
||||
.modal(true)
|
||||
.copyright("© 2022-2023 Xetibo")
|
||||
.developers(vec!["DashieTM".to_string(), "Takatori".to_string()])
|
||||
.designers(vec!["DashieTM".to_string(), "Takatori".to_string()])
|
||||
.build();
|
||||
|
||||
dialog.present();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl SidebarEntry {
|
||||
pub fn new(
|
||||
entryName: &str,
|
||||
iconName: &str,
|
||||
category: Categories,
|
||||
isSubcategory: bool,
|
||||
clickEvent: fn(FlowBox),
|
||||
) -> Self {
|
||||
let entry: SidebarEntry = Object::builder().build();
|
||||
let entryImp = entry.imp();
|
||||
entryImp.resetSidebarLabel.get().set_text(entryName);
|
||||
entryImp.resetSidebarImage.set_from_icon_name(Some(iconName));
|
||||
entryImp.category.set(category);
|
||||
entryImp.isSubcategory.set(isSubcategory);
|
||||
{
|
||||
let mut name = entryImp.name.borrow_mut();
|
||||
*name = String::from(entryName);
|
||||
let mut action = entryImp.onClickEvent.borrow_mut();
|
||||
*action = SidebarAction {
|
||||
onClickEvent: clickEvent,
|
||||
};
|
||||
}
|
||||
Self::setMargin(&entry);
|
||||
entry
|
||||
}
|
||||
|
||||
fn setMargin(entry: &SidebarEntry) {
|
||||
if entry.imp().isSubcategory.get() {
|
||||
let option = entry.child().unwrap();
|
||||
option.set_margin_start(30);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub mod window;
|
||||
pub mod windowImpl;
|
||||
pub mod sidebarEntry;
|
||||
pub mod sidebarEntryImpl;
|
||||
pub mod handleSidebarClick;
|
||||
|
|
|
@ -1,63 +1,48 @@
|
|||
use std::cell::{Cell, RefCell};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::Object;
|
||||
use gtk::{FlowBox, glib};
|
||||
use gtk::prelude::*;
|
||||
use crate::components::window::sidebarEntryImpl;
|
||||
use crate::components::window::sidebarEntryImpl::{Categories, SidebarAction};
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::{CompositeTemplate, FlowBox, glib, Image, Label, ListBoxRow};
|
||||
use gtk::subclass::prelude::*;
|
||||
|
||||
use crate::components::window::handleSidebarClick::HANDLE_HOME;
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum Categories {
|
||||
Connectivity,
|
||||
Audio,
|
||||
#[default]
|
||||
Misc,
|
||||
glib::wrapper! {
|
||||
pub struct SidebarEntry(ObjectSubclass<sidebarEntryImpl::SidebarEntry>)
|
||||
@extends gtk::ListBoxRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetSidebarEntry.ui")]
|
||||
pub struct SidebarEntry {
|
||||
#[template_child]
|
||||
pub resetSidebarLabel: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub resetSidebarImage: TemplateChild<Image>,
|
||||
pub category: Cell<Categories>,
|
||||
pub isSubcategory: Cell<bool>,
|
||||
pub onClickEvent: RefCell<SidebarAction>,
|
||||
pub name : RefCell<String>,
|
||||
}
|
||||
impl SidebarEntry {
|
||||
pub fn new(
|
||||
entryName: &str,
|
||||
iconName: &str,
|
||||
category: Categories,
|
||||
isSubcategory: bool,
|
||||
clickEvent: fn(FlowBox),
|
||||
) -> Self {
|
||||
let entry: SidebarEntry = Object::builder().build();
|
||||
let entryImp = entry.imp();
|
||||
entryImp.resetSidebarLabel.get().set_text(entryName);
|
||||
entryImp
|
||||
.resetSidebarImage
|
||||
.set_from_icon_name(Some(iconName));
|
||||
entryImp.category.set(category);
|
||||
entryImp.isSubcategory.set(isSubcategory);
|
||||
{
|
||||
let mut name = entryImp.name.borrow_mut();
|
||||
*name = String::from(entryName);
|
||||
let mut action = entryImp.onClickEvent.borrow_mut();
|
||||
*action = SidebarAction {
|
||||
onClickEvent: clickEvent,
|
||||
};
|
||||
}
|
||||
Self::setMargin(&entry);
|
||||
entry
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub struct SidebarAction {
|
||||
pub onClickEvent: fn(FlowBox),
|
||||
}
|
||||
|
||||
impl Default for SidebarAction {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
onClickEvent: HANDLE_HOME
|
||||
fn setMargin(entry: &SidebarEntry) {
|
||||
if entry.imp().isSubcategory.get() {
|
||||
let option = entry.child().unwrap();
|
||||
option.set_margin_start(30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for SidebarEntry {
|
||||
const NAME: &'static str = "resetSidebarEntry";
|
||||
type Type = super::SidebarEntry;
|
||||
type ParentType = ListBoxRow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for SidebarEntry {}
|
||||
|
||||
impl ListBoxRowImpl for SidebarEntry {}
|
||||
|
||||
impl WidgetImpl for SidebarEntry {}
|
||||
|
|
64
src/components/window/sidebarEntryImpl.rs
Normal file
64
src/components/window/sidebarEntryImpl.rs
Normal file
|
@ -0,0 +1,64 @@
|
|||
use std::cell::{Cell, RefCell};
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::{CompositeTemplate, FlowBox, glib, Image, Label, ListBoxRow};
|
||||
use gtk::subclass::prelude::*;
|
||||
|
||||
use crate::components::window::handleSidebarClick::HANDLE_HOME;
|
||||
use crate::components::window::sidebarEntry;
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum Categories {
|
||||
Connectivity,
|
||||
Audio,
|
||||
#[default]
|
||||
Misc,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetSidebarEntry.ui")]
|
||||
pub struct SidebarEntry {
|
||||
#[template_child]
|
||||
pub resetSidebarLabel: TemplateChild<Label>,
|
||||
#[template_child]
|
||||
pub resetSidebarImage: TemplateChild<Image>,
|
||||
pub category: Cell<Categories>,
|
||||
pub isSubcategory: Cell<bool>,
|
||||
pub onClickEvent: RefCell<SidebarAction>,
|
||||
pub name : RefCell<String>,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub struct SidebarAction {
|
||||
pub onClickEvent: fn(FlowBox),
|
||||
}
|
||||
|
||||
impl Default for SidebarAction {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
onClickEvent: HANDLE_HOME
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for SidebarEntry {
|
||||
const NAME: &'static str = "resetSidebarEntry";
|
||||
type Type = sidebarEntry::SidebarEntry;
|
||||
type ParentType = ListBoxRow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for SidebarEntry {}
|
||||
|
||||
impl ListBoxRowImpl for SidebarEntry {}
|
||||
|
||||
impl WidgetImpl for SidebarEntry {}
|
|
@ -1,73 +1,204 @@
|
|||
use adw::glib::StaticTypeExt;
|
||||
use adw::subclass::prelude::AdwApplicationWindowImpl;
|
||||
use adw::{Breakpoint, OverlaySplitView};
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{glib, Box, Button, CompositeTemplate, FlowBox, ListBox, SearchEntry, PopoverMenu};
|
||||
use std::cell::RefCell;
|
||||
use adw::BreakpointCondition;
|
||||
use adw::glib::clone;
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::Object;
|
||||
use gtk::{Application, gio, glib};
|
||||
use gtk::prelude::*;
|
||||
|
||||
use crate::components::wifi::WifiBox;
|
||||
use crate::components::window::SidebarEntry;
|
||||
use crate::components::window::handleSidebarClick::{
|
||||
HANDLE_AUDIO_CLICK, HANDLE_BLUETOOTH_CLICK, HANDLE_CONNECTIVITY_CLICK, HANDLE_MICROPHONE_CLICK,
|
||||
HANDLE_VOLUME_CLICK, HANDLE_VPN_CLICK, HANDLE_WIFI_CLICK,
|
||||
};
|
||||
use crate::components::window::sidebarEntry::SidebarEntry;
|
||||
use crate::components::window::sidebarEntryImpl::Categories;
|
||||
use crate::components::window::windowImpl;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct Window(ObjectSubclass<windowImpl::Window>)
|
||||
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
|
||||
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetMainWindow.ui")]
|
||||
pub struct Window {
|
||||
#[template_child]
|
||||
pub resetMain: TemplateChild<FlowBox>,
|
||||
#[template_child]
|
||||
pub resetSidebarBreakpoint: TemplateChild<Breakpoint>,
|
||||
#[template_child]
|
||||
pub resetOverlaySplitView: TemplateChild<OverlaySplitView>,
|
||||
#[template_child]
|
||||
pub resetSearchEntry: TemplateChild<SearchEntry>,
|
||||
#[template_child]
|
||||
pub resetSidebarList: TemplateChild<ListBox>,
|
||||
#[template_child]
|
||||
pub resetSideBarToggle: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub resetPath: TemplateChild<Box>,
|
||||
#[template_child]
|
||||
pub resetPopoverMenu: TemplateChild<PopoverMenu>,
|
||||
#[template_child]
|
||||
pub resetClose: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub resetAboutButton: TemplateChild<Button>,
|
||||
pub sidebarEntries: RefCell<Vec<(SidebarEntry, Vec<SidebarEntry>)>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for Window {
|
||||
const NAME: &'static str = "resetUI";
|
||||
type Type = super::Window;
|
||||
type ParentType = adw::ApplicationWindow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
WifiBox::ensure_type();
|
||||
klass.bind_template();
|
||||
impl Window {
|
||||
pub fn new(app: &Application) -> Self {
|
||||
Object::builder().property("application", app).build()
|
||||
}
|
||||
|
||||
fn instance_init(obj: &InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
pub fn setupCallback(&self) {
|
||||
let selfImp = self.imp();
|
||||
|
||||
selfImp.resetSearchEntry.connect_search_changed(clone!(@ weak self as window => move |_| {
|
||||
window.filterList();
|
||||
}));
|
||||
|
||||
selfImp.resetSideBarToggle.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
window.toggleSidebar();
|
||||
}));
|
||||
|
||||
selfImp.resetSidebarList.connect_row_activated(
|
||||
clone!(@ weak selfImp as flowbox => move |_, y| {
|
||||
let result = y.downcast_ref::<SidebarEntry>().unwrap();
|
||||
let clickEvent = result.imp().onClickEvent.borrow().onClickEvent;
|
||||
(clickEvent)(flowbox.resetMain.get());
|
||||
}),
|
||||
);
|
||||
|
||||
selfImp.resetClose.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
window.close();
|
||||
}));
|
||||
|
||||
// selfImp.resetMenu.connect_clicked(|_| {
|
||||
// WifiBox::donotdisturb();
|
||||
//
|
||||
// });
|
||||
}
|
||||
|
||||
pub fn handleDynamicSidebar(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp.resetSidebarBreakpoint.set_condition(BreakpointCondition::parse("max-width: 600sp").as_ref().ok());
|
||||
selfImp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(selfImp.resetOverlaySplitView.get()),
|
||||
"collapsed",
|
||||
&true.to_value(),
|
||||
);
|
||||
selfImp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(selfImp.resetSideBarToggle.get()),
|
||||
"visible",
|
||||
&true.to_value(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn filterList(&self) {
|
||||
let text = self.imp().resetSearchEntry.text().to_string();
|
||||
for (mainEntry, subEntries) in self.imp().sidebarEntries.borrow().iter() {
|
||||
if text == "" {
|
||||
mainEntry.set_visible(true);
|
||||
for subEntry in subEntries {
|
||||
subEntry.set_visible(true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if mainEntry.imp().name.borrow().to_lowercase().contains(&text.to_lowercase()) {
|
||||
mainEntry.set_visible(true);
|
||||
} else {
|
||||
mainEntry.set_visible(false);
|
||||
}
|
||||
for subEntry in subEntries {
|
||||
if subEntry.imp().name.borrow().to_lowercase().contains(&text.to_lowercase()) {
|
||||
subEntry.set_visible(true);
|
||||
mainEntry.set_visible(true);
|
||||
} else {
|
||||
subEntry.set_visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggleSidebar(&self) {
|
||||
if self.imp().resetOverlaySplitView.shows_sidebar() {
|
||||
self.imp().resetOverlaySplitView.set_show_sidebar(false);
|
||||
} else {
|
||||
self.imp().resetOverlaySplitView.set_show_sidebar(true);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setupSidebarEntries(&self) {
|
||||
let selfImp = self.imp();
|
||||
let mut sidebarEntries = selfImp.sidebarEntries.borrow_mut();
|
||||
|
||||
let connectivityList = vec![
|
||||
SidebarEntry::new(
|
||||
"WiFi",
|
||||
"network-wireless-symbolic",
|
||||
Categories::Connectivity,
|
||||
true,
|
||||
HANDLE_WIFI_CLICK,
|
||||
),
|
||||
SidebarEntry::new(
|
||||
"Bluetooth",
|
||||
"bluetooth-symbolic",
|
||||
Categories::Connectivity,
|
||||
true,
|
||||
HANDLE_BLUETOOTH_CLICK,
|
||||
),
|
||||
SidebarEntry::new(
|
||||
"VPN",
|
||||
"network-vpn-symbolic",
|
||||
Categories::Connectivity,
|
||||
true,
|
||||
HANDLE_VPN_CLICK,
|
||||
),
|
||||
];
|
||||
|
||||
sidebarEntries.push((
|
||||
SidebarEntry::new(
|
||||
"Connectivity",
|
||||
"network-wired-symbolic",
|
||||
Categories::Connectivity,
|
||||
false,
|
||||
HANDLE_CONNECTIVITY_CLICK,
|
||||
),
|
||||
connectivityList,
|
||||
));
|
||||
|
||||
let audioList = vec![
|
||||
SidebarEntry::new(
|
||||
"Volume",
|
||||
"audio-volume-high-symbolic",
|
||||
Categories::Audio,
|
||||
true,
|
||||
HANDLE_VOLUME_CLICK,
|
||||
),
|
||||
SidebarEntry::new(
|
||||
"Microphone",
|
||||
"audio-input-microphone-symbolic",
|
||||
Categories::Audio,
|
||||
true,
|
||||
HANDLE_MICROPHONE_CLICK,
|
||||
),
|
||||
];
|
||||
|
||||
sidebarEntries.push((
|
||||
SidebarEntry::new(
|
||||
"Audio",
|
||||
"audio-headset-symbolic",
|
||||
Categories::Audio,
|
||||
false,
|
||||
HANDLE_AUDIO_CLICK,
|
||||
),
|
||||
audioList,
|
||||
));
|
||||
|
||||
for (mainEntry, subEntries) in sidebarEntries.iter() {
|
||||
selfImp.resetSidebarList.append(mainEntry);
|
||||
for subEntry in subEntries {
|
||||
selfImp.resetSidebarList.append(subEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setupPopoverButtons(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp.resetAboutButton.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
let dialog = adw::AboutWindow::builder()
|
||||
.application_name("ReSet")
|
||||
.application_icon("ReSet")
|
||||
.developer_name("Xetibo")
|
||||
.license("GPL-3.0")
|
||||
.license_type(gtk::License::Gpl30)
|
||||
.website("https://github.com/Xetibo/ReSet")
|
||||
.issue_url("https://github.com/Xetibo/ReSet/issues")
|
||||
.version("0.0.1")
|
||||
.transient_for(&window)
|
||||
.modal(true)
|
||||
.copyright("© 2022-2023 Xetibo")
|
||||
.developers(vec!["DashieTM".to_string(), "Takatori".to_string()])
|
||||
.designers(vec!["DashieTM".to_string(), "Takatori".to_string()])
|
||||
.build();
|
||||
|
||||
dialog.present();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for Window {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
let object = self.obj();
|
||||
object.setupCallback();
|
||||
object.setupPopoverButtons();
|
||||
object.handleDynamicSidebar();
|
||||
object.setupSidebarEntries();
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for Window {}
|
||||
|
||||
impl WindowImpl for Window {}
|
||||
|
||||
impl ApplicationWindowImpl for Window {}
|
||||
|
||||
impl AdwApplicationWindowImpl for Window {}
|
||||
|
|
75
src/components/window/windowImpl.rs
Normal file
75
src/components/window/windowImpl.rs
Normal file
|
@ -0,0 +1,75 @@
|
|||
use std::cell::RefCell;
|
||||
|
||||
use adw::{Breakpoint, OverlaySplitView};
|
||||
use adw::glib::StaticTypeExt;
|
||||
use adw::subclass::prelude::AdwApplicationWindowImpl;
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::{Box, Button, CompositeTemplate, FlowBox, glib, ListBox, PopoverMenu, SearchEntry};
|
||||
use gtk::subclass::prelude::*;
|
||||
|
||||
use crate::components::wifi::wifiBox::WifiBox;
|
||||
use crate::components::window::window;
|
||||
use crate::components::window::sidebarEntry::SidebarEntry;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/Xetibo/ReSet/resetMainWindow.ui")]
|
||||
pub struct Window {
|
||||
#[template_child]
|
||||
pub resetMain: TemplateChild<FlowBox>,
|
||||
#[template_child]
|
||||
pub resetSidebarBreakpoint: TemplateChild<Breakpoint>,
|
||||
#[template_child]
|
||||
pub resetOverlaySplitView: TemplateChild<OverlaySplitView>,
|
||||
#[template_child]
|
||||
pub resetSearchEntry: TemplateChild<SearchEntry>,
|
||||
#[template_child]
|
||||
pub resetSidebarList: TemplateChild<ListBox>,
|
||||
#[template_child]
|
||||
pub resetSideBarToggle: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub resetPath: TemplateChild<Box>,
|
||||
#[template_child]
|
||||
pub resetPopoverMenu: TemplateChild<PopoverMenu>,
|
||||
#[template_child]
|
||||
pub resetClose: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub resetAboutButton: TemplateChild<Button>,
|
||||
pub sidebarEntries: RefCell<Vec<(SidebarEntry, Vec<SidebarEntry>)>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for Window {
|
||||
const NAME: &'static str = "resetUI";
|
||||
type Type = window::Window;
|
||||
type ParentType = adw::ApplicationWindow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
WifiBox::ensure_type();
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for Window {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
let obj = self.obj();
|
||||
obj.setupCallback();
|
||||
obj.setupPopoverButtons();
|
||||
obj.handleDynamicSidebar();
|
||||
obj.setupSidebarEntries();
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for Window {}
|
||||
|
||||
impl WindowImpl for Window {}
|
||||
|
||||
impl ApplicationWindowImpl for Window {}
|
||||
|
||||
impl AdwApplicationWindowImpl for Window {}
|
Loading…
Add table
Add a link
Reference in a new issue