mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-07-12 12:57:44 +02:00
chore: snake_case all but UI templates
This commit is contained in:
parent
9f0ca6e8bf
commit
391182607d
55 changed files with 1471 additions and 1427 deletions
|
@ -2,123 +2,123 @@ use gtk::prelude::FrameExt;
|
|||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::components::base::settingBox::SettingBox;
|
||||
use crate::components::base::setting_box::SettingBox;
|
||||
use crate::components::base::utils::{start_audio_listener, Listeners};
|
||||
use crate::components::bluetooth::bluetoothBox::{
|
||||
use crate::components::bluetooth::bluetooth_box::{
|
||||
populate_conntected_bluetooth_devices, start_bluetooth_listener, BluetoothBox,
|
||||
};
|
||||
use crate::components::input::sourceBox::{populate_sources, SourceBox};
|
||||
use crate::components::output::sinkBox::{populate_sinks, SinkBox};
|
||||
use crate::components::wifi::wifiBox::{
|
||||
scanForWifi, show_stored_connections, start_event_listener, WifiBox,
|
||||
use crate::components::input::source_box::{populate_sources, SourceBox};
|
||||
use crate::components::output::sink_box::{populate_sinks, SinkBox};
|
||||
use crate::components::wifi::wifi_box::{
|
||||
scan_for_wifi, show_stored_connections, start_event_listener, WifiBox,
|
||||
};
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::{FlowBox, Frame};
|
||||
|
||||
pub const HANDLE_CONNECTIVITY_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_audio_listener();
|
||||
let wifiBox = WifiBox::new(listeners.clone());
|
||||
start_event_listener(listeners.clone(), wifiBox.clone());
|
||||
show_stored_connections(wifiBox.clone());
|
||||
scanForWifi(wifiBox.clone());
|
||||
let wifiFrame = wrapInFrame(SettingBox::new(&*wifiBox));
|
||||
let wifi_box = WifiBox::new(listeners.clone());
|
||||
start_event_listener(listeners.clone(), wifi_box.clone());
|
||||
show_stored_connections(wifi_box.clone());
|
||||
scan_for_wifi(wifi_box.clone());
|
||||
let wifi_frame = wrap_in_frame(SettingBox::new(&*wifi_box));
|
||||
let bluetooth_box = BluetoothBox::new(listeners.clone());
|
||||
populate_conntected_bluetooth_devices(bluetooth_box.clone());
|
||||
start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
|
||||
let bluetoothFrame = wrapInFrame(SettingBox::new(&*bluetooth_box));
|
||||
resetMain.remove_all();
|
||||
resetMain.insert(&wifiFrame, -1);
|
||||
resetMain.insert(&bluetoothFrame, -1);
|
||||
resetMain.set_max_children_per_line(2);
|
||||
let bluetooth_frame = wrap_in_frame(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&wifi_frame, -1);
|
||||
reset_main.insert(&bluetooth_frame, -1);
|
||||
reset_main.set_max_children_per_line(2);
|
||||
};
|
||||
|
||||
pub const HANDLE_WIFI_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_audio_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
let wifiBox = WifiBox::new(listeners.clone());
|
||||
start_event_listener(listeners.clone(), wifiBox.clone());
|
||||
show_stored_connections(wifiBox.clone());
|
||||
scanForWifi(wifiBox.clone());
|
||||
let wifiFrame = wrapInFrame(SettingBox::new(&*wifiBox));
|
||||
resetMain.remove_all();
|
||||
resetMain.insert(&wifiFrame, -1);
|
||||
resetMain.set_max_children_per_line(1);
|
||||
let wifi_box = WifiBox::new(listeners.clone());
|
||||
start_event_listener(listeners.clone(), wifi_box.clone());
|
||||
show_stored_connections(wifi_box.clone());
|
||||
scan_for_wifi(wifi_box.clone());
|
||||
let wifi_frame = wrap_in_frame(SettingBox::new(&*wifi_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&wifi_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_BLUETOOTH_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_audio_listener();
|
||||
let bluetooth_box = BluetoothBox::new(listeners.clone());
|
||||
start_bluetooth_listener(listeners.clone(), bluetooth_box.clone());
|
||||
populate_conntected_bluetooth_devices(bluetooth_box.clone());
|
||||
let bluetoothFrame = wrapInFrame(SettingBox::new(&*bluetooth_box));
|
||||
resetMain.remove_all();
|
||||
resetMain.insert(&bluetoothFrame, -1);
|
||||
resetMain.set_max_children_per_line(1);
|
||||
let bluetooth_frame = wrap_in_frame(SettingBox::new(&*bluetooth_box));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&bluetooth_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_AUDIO_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
let audioOutput = Arc::new(SinkBox::new());
|
||||
let audioInput = Arc::new(SourceBox::new());
|
||||
let audio_output = Arc::new(SinkBox::new());
|
||||
let audio_input = Arc::new(SourceBox::new());
|
||||
start_audio_listener(
|
||||
listeners.clone(),
|
||||
Some(audioOutput.clone()),
|
||||
Some(audioInput.clone()),
|
||||
Some(audio_output.clone()),
|
||||
Some(audio_input.clone()),
|
||||
);
|
||||
populate_sinks(audioOutput.clone());
|
||||
let audioFrame = wrapInFrame(SettingBox::new(&*audioOutput));
|
||||
populate_sources(audioInput.clone());
|
||||
let sourceFrame = wrapInFrame(SettingBox::new(&*audioInput));
|
||||
resetMain.remove_all();
|
||||
resetMain.insert(&audioFrame, -1);
|
||||
resetMain.insert(&sourceFrame, -1);
|
||||
resetMain.set_max_children_per_line(2);
|
||||
populate_sinks(audio_output.clone());
|
||||
let audio_frame = wrap_in_frame(SettingBox::new(&*audio_output));
|
||||
populate_sources(audio_input.clone());
|
||||
let source_frame = wrap_in_frame(SettingBox::new(&*audio_input));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&audio_frame, -1);
|
||||
reset_main.insert(&source_frame, -1);
|
||||
reset_main.set_max_children_per_line(2);
|
||||
};
|
||||
|
||||
pub const HANDLE_VOLUME_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
let audioOutput = Arc::new(SinkBox::new());
|
||||
start_audio_listener(listeners.clone(), Some(audioOutput.clone()), None);
|
||||
let audio_output = Arc::new(SinkBox::new());
|
||||
start_audio_listener(listeners.clone(), Some(audio_output.clone()), None);
|
||||
while !listeners.pulse_listener.load(Ordering::SeqCst) {
|
||||
std::hint::spin_loop()
|
||||
}
|
||||
populate_sinks(audioOutput.clone());
|
||||
let audioFrame = wrapInFrame(SettingBox::new(&*audioOutput));
|
||||
resetMain.remove_all();
|
||||
resetMain.insert(&audioFrame, -1);
|
||||
resetMain.set_max_children_per_line(1);
|
||||
populate_sinks(audio_output.clone());
|
||||
let audio_frame = wrap_in_frame(SettingBox::new(&*audio_output));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&audio_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_MICROPHONE_CLICK: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
let audioInput = Arc::new(SourceBox::new());
|
||||
start_audio_listener(listeners.clone(), None, Some(audioInput.clone()));
|
||||
populate_sources(audioInput.clone());
|
||||
let sourceFrame = wrapInFrame(SettingBox::new(&*audioInput));
|
||||
resetMain.remove_all();
|
||||
resetMain.insert(&sourceFrame, -1);
|
||||
resetMain.set_max_children_per_line(1);
|
||||
let audio_input = Arc::new(SourceBox::new());
|
||||
start_audio_listener(listeners.clone(), None, Some(audio_input.clone()));
|
||||
populate_sources(audio_input.clone());
|
||||
let source_frame = wrap_in_frame(SettingBox::new(&*audio_input));
|
||||
reset_main.remove_all();
|
||||
reset_main.insert(&source_frame, -1);
|
||||
reset_main.set_max_children_per_line(1);
|
||||
};
|
||||
|
||||
pub const HANDLE_HOME: fn(Arc<Listeners>, FlowBox) =
|
||||
|listeners: Arc<Listeners>, resetMain: FlowBox| {
|
||||
|listeners: Arc<Listeners>, reset_main: FlowBox| {
|
||||
listeners.stop_network_listener();
|
||||
listeners.stop_audio_listener();
|
||||
listeners.stop_bluetooth_listener();
|
||||
resetMain.remove_all();
|
||||
reset_main.remove_all();
|
||||
};
|
||||
|
||||
fn wrapInFrame(widget: SettingBox) -> Frame {
|
||||
fn wrap_in_frame(widget: SettingBox) -> Frame {
|
||||
let frame = Frame::new(None);
|
||||
frame.set_child(Some(&widget));
|
||||
frame.add_css_class("resetSettingFrame");
|
|
@ -1,6 +1,5 @@
|
|||
#![allow(non_snake_case)]
|
||||
pub mod handleSidebarClick;
|
||||
pub mod resetWindow;
|
||||
pub mod resetWindowImpl;
|
||||
pub mod sidebarEntry;
|
||||
pub mod sidebarEntryImpl;
|
||||
pub mod handle_sidebar_click;
|
||||
pub mod reset_window;
|
||||
pub mod reset_window_impl;
|
||||
pub mod sidebar_entry;
|
||||
pub mod sidebar_entry_impl;
|
||||
|
|
|
@ -5,13 +5,13 @@ use glib::Object;
|
|||
use gtk::prelude::*;
|
||||
use gtk::{gio, glib, Application, ListBoxRow, Orientation};
|
||||
|
||||
use crate::components::window::handleSidebarClick::*;
|
||||
use crate::components::window::resetWindowImpl;
|
||||
use crate::components::window::sidebarEntry::SidebarEntry;
|
||||
use crate::components::window::sidebarEntryImpl::Categories;
|
||||
use crate::components::window::handle_sidebar_click::*;
|
||||
use crate::components::window::reset_window_impl;
|
||||
use crate::components::window::sidebar_entry::SidebarEntry;
|
||||
use crate::components::window::sidebar_entry_impl::Categories;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct ReSetWindow(ObjectSubclass<resetWindowImpl::ReSetWindow>)
|
||||
pub struct ReSetWindow(ObjectSubclass<reset_window_impl::ReSetWindow>)
|
||||
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
|
||||
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
|
@ -21,36 +21,35 @@ unsafe impl Send for ReSetWindow {}
|
|||
|
||||
unsafe impl Sync for ReSetWindow {}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
impl ReSetWindow {
|
||||
pub fn new(app: &Application) -> Self {
|
||||
Object::builder().property("application", app).build()
|
||||
}
|
||||
|
||||
pub fn setupCallback(&self) {
|
||||
let selfImp = self.imp();
|
||||
pub fn setup_callback(&self) {
|
||||
let self_imp = 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.listeners.clone(), flowbox.resetMain.get());
|
||||
self_imp.resetSearchEntry.connect_search_changed(
|
||||
clone!(@ weak self as window => move |_| {
|
||||
window.filter_list();
|
||||
}),
|
||||
);
|
||||
|
||||
selfImp
|
||||
self_imp
|
||||
.resetSideBarToggle
|
||||
.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
window.toggle_sidebar();
|
||||
}));
|
||||
|
||||
self_imp.resetSidebarList.connect_row_activated(
|
||||
clone!(@ weak self_imp as flowbox => move |_, y| {
|
||||
let result = y.downcast_ref::<SidebarEntry>().unwrap();
|
||||
let click_event = result.imp().on_click_event.borrow().on_click_event;
|
||||
(click_event)(flowbox.listeners.clone(), flowbox.resetMain.get());
|
||||
}),
|
||||
);
|
||||
|
||||
self_imp
|
||||
.resetClose
|
||||
.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
window.close();
|
||||
|
@ -62,62 +61,62 @@ impl ReSetWindow {
|
|||
// });
|
||||
}
|
||||
|
||||
pub fn handleDynamicSidebar(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp
|
||||
pub fn handle_dynamic_sidebar(&self) {
|
||||
let self_imp = self.imp();
|
||||
self_imp
|
||||
.resetSidebarBreakpoint
|
||||
.set_condition(BreakpointCondition::parse("max-width: 700sp").as_ref().ok());
|
||||
selfImp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(selfImp.resetOverlaySplitView.get()),
|
||||
self_imp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(self_imp.resetOverlaySplitView.get()),
|
||||
"collapsed",
|
||||
&true.to_value(),
|
||||
);
|
||||
selfImp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(selfImp.resetSideBarToggle.get()),
|
||||
self_imp.resetSidebarBreakpoint.add_setter(
|
||||
&Object::from(self_imp.resetSideBarToggle.get()),
|
||||
"visible",
|
||||
&true.to_value(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn filterList(&self) {
|
||||
pub fn filter_list(&self) {
|
||||
let text = self.imp().resetSearchEntry.text().to_string();
|
||||
for (mainEntry, subEntries) in self.imp().sidebarEntries.borrow().iter() {
|
||||
for (main_entry, sub_entriess) in self.imp().sidebar_entries.borrow().iter() {
|
||||
if text.is_empty() {
|
||||
mainEntry.set_visible(true);
|
||||
for subEntry in subEntries {
|
||||
subEntry.set_visible(true);
|
||||
main_entry.set_visible(true);
|
||||
for sub_entry in sub_entriess {
|
||||
sub_entry.set_visible(true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if mainEntry
|
||||
if main_entry
|
||||
.imp()
|
||||
.name
|
||||
.borrow()
|
||||
.to_lowercase()
|
||||
.contains(&text.to_lowercase())
|
||||
{
|
||||
mainEntry.set_visible(true);
|
||||
main_entry.set_visible(true);
|
||||
} else {
|
||||
mainEntry.set_visible(false);
|
||||
main_entry.set_visible(false);
|
||||
}
|
||||
for subEntry in subEntries {
|
||||
if subEntry
|
||||
for sub_entry in sub_entriess {
|
||||
if sub_entry
|
||||
.imp()
|
||||
.name
|
||||
.borrow()
|
||||
.to_lowercase()
|
||||
.contains(&text.to_lowercase())
|
||||
{
|
||||
subEntry.set_visible(true);
|
||||
mainEntry.set_visible(true);
|
||||
sub_entry.set_visible(true);
|
||||
main_entry.set_visible(true);
|
||||
} else {
|
||||
subEntry.set_visible(false);
|
||||
sub_entry.set_visible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggleSidebar(&self) {
|
||||
pub fn toggle_sidebar(&self) {
|
||||
if self.imp().resetOverlaySplitView.shows_sidebar() {
|
||||
self.imp().resetOverlaySplitView.set_show_sidebar(false);
|
||||
} else {
|
||||
|
@ -125,11 +124,11 @@ impl ReSetWindow {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn setupSidebarEntries(&self) {
|
||||
let selfImp = self.imp();
|
||||
let mut sidebarEntries = selfImp.sidebarEntries.borrow_mut();
|
||||
pub fn setup_sidebar_entries(&self) {
|
||||
let self_imp = self.imp();
|
||||
let mut sidebar_entries = self_imp.sidebar_entries.borrow_mut();
|
||||
|
||||
let connectivityList = vec![
|
||||
let connectivity_list = vec![
|
||||
SidebarEntry::new(
|
||||
"WiFi",
|
||||
"network-wireless-symbolic",
|
||||
|
@ -153,7 +152,7 @@ impl ReSetWindow {
|
|||
// ),
|
||||
];
|
||||
|
||||
sidebarEntries.push((
|
||||
sidebar_entries.push((
|
||||
SidebarEntry::new(
|
||||
"Connectivity",
|
||||
"network-wired-symbolic",
|
||||
|
@ -161,10 +160,10 @@ impl ReSetWindow {
|
|||
false,
|
||||
HANDLE_CONNECTIVITY_CLICK,
|
||||
),
|
||||
connectivityList,
|
||||
connectivity_list,
|
||||
));
|
||||
|
||||
let audioList = vec![
|
||||
let audio_list = vec![
|
||||
SidebarEntry::new(
|
||||
"Output",
|
||||
"audio-volume-high-symbolic",
|
||||
|
@ -181,7 +180,7 @@ impl ReSetWindow {
|
|||
),
|
||||
];
|
||||
|
||||
sidebarEntries.push((
|
||||
sidebar_entries.push((
|
||||
SidebarEntry::new(
|
||||
"Audio",
|
||||
"audio-headset-symbolic",
|
||||
|
@ -189,7 +188,7 @@ impl ReSetWindow {
|
|||
false,
|
||||
HANDLE_AUDIO_CLICK,
|
||||
),
|
||||
audioList,
|
||||
audio_list,
|
||||
));
|
||||
|
||||
// let peripheralsList = vec![
|
||||
|
@ -227,28 +226,28 @@ impl ReSetWindow {
|
|||
// peripheralsList,
|
||||
// ));
|
||||
|
||||
selfImp
|
||||
self_imp
|
||||
.resetSidebarList
|
||||
.connect_row_activated(clone!(@ weak selfImp => move |_, _| {
|
||||
selfImp.resetSearchEntry.set_text("");
|
||||
.connect_row_activated(clone!(@ weak self_imp => move |_, _| {
|
||||
self_imp.resetSearchEntry.set_text("");
|
||||
}));
|
||||
|
||||
for (mainEntry, subEntries) in sidebarEntries.iter() {
|
||||
selfImp.resetSidebarList.append(mainEntry);
|
||||
for subEntry in subEntries {
|
||||
selfImp.resetSidebarList.append(subEntry);
|
||||
for (main_entry, sub_entries) in sidebar_entries.iter() {
|
||||
self_imp.resetSidebarList.append(main_entry);
|
||||
for sub_entry in sub_entries {
|
||||
self_imp.resetSidebarList.append(sub_entry);
|
||||
}
|
||||
let separator = ListBoxRow::new();
|
||||
separator.set_child(Some(>k::Separator::new(Orientation::Horizontal)));
|
||||
separator.set_selectable(false);
|
||||
separator.set_activatable(false);
|
||||
selfImp.resetSidebarList.append(&separator);
|
||||
self_imp.resetSidebarList.append(&separator);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setupPopoverButtons(&self) {
|
||||
let selfImp = self.imp();
|
||||
selfImp
|
||||
pub fn setup_popover_buttons(&self) {
|
||||
let self_imp = self.imp();
|
||||
self_imp
|
||||
.resetAboutButton
|
||||
.connect_clicked(clone!(@ weak self as window => move |_| {
|
||||
let dialog = adw::AboutWindow::builder()
|
||||
|
@ -269,14 +268,14 @@ impl ReSetWindow {
|
|||
window.imp().resetPopoverMenu.popdown();
|
||||
dialog.present();
|
||||
}));
|
||||
selfImp
|
||||
self_imp
|
||||
.resetPreferenceButton
|
||||
.connect_clicked(clone!(@weak self as window => move |_| {
|
||||
let preferences = adw::PreferencesWindow::builder().build();
|
||||
window.imp().resetPopoverMenu.popdown();
|
||||
preferences.present();
|
||||
}));
|
||||
selfImp
|
||||
self_imp
|
||||
.resetShortcutsButton
|
||||
.connect_clicked(clone!(@weak self as window => move |_| {
|
||||
let shortcuts = gtk::ShortcutsWindow::builder().build();
|
|
@ -9,9 +9,9 @@ use gtk::subclass::prelude::*;
|
|||
use gtk::{glib, Button, CompositeTemplate, FlowBox, ListBox, PopoverMenu, SearchEntry};
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::wifi::wifiBox::WifiBox;
|
||||
use crate::components::window::resetWindow;
|
||||
use crate::components::window::sidebarEntry::SidebarEntry;
|
||||
use crate::components::wifi::wifi_box::WifiBox;
|
||||
use crate::components::window::reset_window;
|
||||
use crate::components::window::sidebar_entry::SidebarEntry;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
|
@ -39,7 +39,7 @@ pub struct ReSetWindow {
|
|||
pub resetPreferenceButton: TemplateChild<Button>,
|
||||
#[template_child]
|
||||
pub resetShortcutsButton: TemplateChild<Button>,
|
||||
pub sidebarEntries: RefCell<Vec<(SidebarEntry, Vec<SidebarEntry>)>>,
|
||||
pub sidebar_entries: RefCell<Vec<(SidebarEntry, Vec<SidebarEntry>)>>,
|
||||
pub listeners: Arc<Listeners>,
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ unsafe impl Sync for ReSetWindow {}
|
|||
impl ObjectSubclass for ReSetWindow {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetUI";
|
||||
type Type = resetWindow::ReSetWindow;
|
||||
type Type = reset_window::ReSetWindow;
|
||||
type ParentType = adw::ApplicationWindow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
|
@ -68,10 +68,10 @@ impl ObjectImpl for ReSetWindow {
|
|||
self.parent_constructed();
|
||||
|
||||
let obj = self.obj();
|
||||
obj.setupCallback();
|
||||
obj.setupPopoverButtons();
|
||||
obj.handleDynamicSidebar();
|
||||
obj.setupSidebarEntries();
|
||||
obj.setup_callback();
|
||||
obj.setup_popover_buttons();
|
||||
obj.handle_dynamic_sidebar();
|
||||
obj.setup_sidebar_entries();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::window::sidebarEntryImpl;
|
||||
use crate::components::window::sidebarEntryImpl::{Categories, SidebarAction};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::Object;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{glib, FlowBox};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SidebarEntry(ObjectSubclass<sidebarEntryImpl::SidebarEntry>)
|
||||
@extends gtk::ListBoxRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
impl SidebarEntry {
|
||||
pub fn new(
|
||||
entryName: &str,
|
||||
iconName: &str,
|
||||
category: Categories,
|
||||
isSubcategory: bool,
|
||||
clickEvent: fn(Arc<Listeners>, 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);
|
||||
}
|
||||
}
|
||||
}
|
51
src/components/window/sidebar_entry.rs
Normal file
51
src/components/window/sidebar_entry.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::window::sidebar_entry_impl;
|
||||
use crate::components::window::sidebar_entry_impl::{Categories, SidebarAction};
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::Object;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{glib, FlowBox};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SidebarEntry(ObjectSubclass<sidebar_entry_impl::SidebarEntry>)
|
||||
@extends gtk::ListBoxRow, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
impl SidebarEntry {
|
||||
pub fn new(
|
||||
entry_name: &str,
|
||||
icon_name: &str,
|
||||
category: Categories,
|
||||
is_subcategory: bool,
|
||||
click_event: fn(Arc<Listeners>, FlowBox),
|
||||
) -> Self {
|
||||
let entry: SidebarEntry = Object::builder().build();
|
||||
let entry_imp = entry.imp();
|
||||
entry_imp.resetSidebarLabel.get().set_text(entry_name);
|
||||
entry_imp
|
||||
.resetSidebarImage
|
||||
.set_from_icon_name(Some(icon_name));
|
||||
entry_imp.category.set(category);
|
||||
entry_imp.is_subcategory.set(is_subcategory);
|
||||
{
|
||||
let mut name = entry_imp.name.borrow_mut();
|
||||
*name = String::from(entry_name);
|
||||
let mut action = entry_imp.on_click_event.borrow_mut();
|
||||
*action = SidebarAction {
|
||||
on_click_event: click_event,
|
||||
};
|
||||
}
|
||||
Self::set_margin(&entry);
|
||||
entry
|
||||
}
|
||||
|
||||
fn set_margin(entry: &SidebarEntry) {
|
||||
if entry.imp().is_subcategory.get() {
|
||||
let option = entry.child().unwrap();
|
||||
option.set_margin_start(30);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,8 +6,8 @@ use gtk::subclass::prelude::*;
|
|||
use gtk::{glib, CompositeTemplate, FlowBox, Image, Label, ListBoxRow};
|
||||
|
||||
use crate::components::base::utils::Listeners;
|
||||
use crate::components::window::handleSidebarClick::HANDLE_HOME;
|
||||
use crate::components::window::sidebarEntry;
|
||||
use crate::components::window::handle_sidebar_click::HANDLE_HOME;
|
||||
use crate::components::window::sidebar_entry;
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum Categories {
|
||||
|
@ -27,20 +27,19 @@ pub struct SidebarEntry {
|
|||
#[template_child]
|
||||
pub resetSidebarImage: TemplateChild<Image>,
|
||||
pub category: Cell<Categories>,
|
||||
pub isSubcategory: Cell<bool>,
|
||||
pub onClickEvent: RefCell<SidebarAction>,
|
||||
pub is_subcategory: Cell<bool>,
|
||||
pub on_click_event: RefCell<SidebarAction>,
|
||||
pub name: RefCell<String>,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub struct SidebarAction {
|
||||
pub onClickEvent: fn(Arc<Listeners>, FlowBox),
|
||||
pub on_click_event: fn(Arc<Listeners>, FlowBox),
|
||||
}
|
||||
|
||||
impl Default for SidebarAction {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
onClickEvent: HANDLE_HOME,
|
||||
on_click_event: HANDLE_HOME,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +48,7 @@ impl Default for SidebarAction {
|
|||
impl ObjectSubclass for SidebarEntry {
|
||||
const ABSTRACT: bool = false;
|
||||
const NAME: &'static str = "resetSidebarEntry";
|
||||
type Type = sidebarEntry::SidebarEntry;
|
||||
type Type = sidebar_entry::SidebarEntry;
|
||||
type ParentType = ListBoxRow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
Loading…
Add table
Add a link
Reference in a new issue