cleanup
This commit is contained in:
parent
478f3ead75
commit
7b9cad4d2c
5 changed files with 22 additions and 20 deletions
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
//! Application API example
|
//! Application API example
|
||||||
|
|
||||||
use cosmic::app::{Task, Core, Settings};
|
use cosmic::app::{Core, Settings, Task};
|
||||||
use cosmic::iced_core::Size;
|
use cosmic::iced_core::Size;
|
||||||
use cosmic::widget::{menu, segmented_button};
|
use cosmic::widget::menu;
|
||||||
use cosmic::{executor, iced, ApplicationExt, Element};
|
use cosmic::{executor, iced, ApplicationExt, Element};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
//! Application API example
|
//! Application API example
|
||||||
|
|
||||||
use cosmic::app::{Task, Core, Settings};
|
use cosmic::app::{Core, Settings, Task};
|
||||||
use cosmic::{executor, iced, ApplicationExt, Element};
|
use cosmic::{executor, iced, ApplicationExt, Element};
|
||||||
|
|
||||||
/// Runs application with these settings
|
/// Runs application with these settings
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::{env, process};
|
use std::{env, process};
|
||||||
|
|
||||||
use cosmic::app::{Task, Core, Settings};
|
use cosmic::app::{Core, Settings, Task};
|
||||||
use cosmic::iced::window;
|
use cosmic::iced::window;
|
||||||
use cosmic::iced_core::alignment::{Horizontal, Vertical};
|
use cosmic::iced_core::alignment::{Horizontal, Vertical};
|
||||||
use cosmic::iced_core::keyboard::Key;
|
use cosmic::iced_core::keyboard::Key;
|
||||||
|
|
@ -120,7 +120,7 @@ impl cosmic::Application for App {
|
||||||
return window::close(self.core.main_window_id().unwrap());
|
return window::close(self.core.main_window_id().unwrap());
|
||||||
}
|
}
|
||||||
Message::WindowNew => match env::current_exe() {
|
Message::WindowNew => match env::current_exe() {
|
||||||
Ok(exe) => match process::Task::new(&exe).spawn() {
|
Ok(exe) => match process::Command::new(&exe).spawn() {
|
||||||
Ok(_child) => {}
|
Ok(_child) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("failed to execute {:?}: {}", exe, err);
|
eprintln!("failed to execute {:?}: {}", exe, err);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use cosmic::{
|
||||||
app::Core,
|
app::Core,
|
||||||
iced::{self, event, window},
|
iced::{self, event, window},
|
||||||
iced_core::{id, Alignment, Length, Point},
|
iced_core::{id, Alignment, Length, Point},
|
||||||
iced_widget::{column, container, scrollable, text, text_input},
|
iced_widget::{column, container, scrollable, text},
|
||||||
widget::{button, header_bar},
|
widget::{button, header_bar},
|
||||||
ApplicationExt, Task,
|
ApplicationExt, Task,
|
||||||
};
|
};
|
||||||
|
|
@ -45,7 +45,7 @@ impl cosmic::Application for MultiWindow {
|
||||||
fn init(core: Core, _input: Self::Flags) -> (Self, cosmic::app::Task<Self::Message>) {
|
fn init(core: Core, _input: Self::Flags) -> (Self, cosmic::app::Task<Self::Message>) {
|
||||||
let windows = MultiWindow {
|
let windows = MultiWindow {
|
||||||
windows: HashMap::from([(
|
windows: HashMap::from([(
|
||||||
self.core.main_window_id().unwrap(),
|
core.main_window_id().unwrap(),
|
||||||
Window {
|
Window {
|
||||||
input_id: id::Id::new("main"),
|
input_id: id::Id::new("main"),
|
||||||
input_value: String::new(),
|
input_value: String::new(),
|
||||||
|
|
@ -86,7 +86,7 @@ impl cosmic::Application for MultiWindow {
|
||||||
}
|
}
|
||||||
Message::WindowOpened(id, ..) => {
|
Message::WindowOpened(id, ..) => {
|
||||||
if let Some(window) = self.windows.get(&id) {
|
if let Some(window) = self.windows.get(&id) {
|
||||||
text_input::focus(window.input_id.clone())
|
cosmic::widget::text_input::focus(window.input_id.clone())
|
||||||
} else {
|
} else {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ impl cosmic::Application for MultiWindow {
|
||||||
Message::NewWindow => {
|
Message::NewWindow => {
|
||||||
let count = self.windows.len() + 1;
|
let count = self.windows.len() + 1;
|
||||||
|
|
||||||
let (id, spawn_window) = window::spawn(window::Settings {
|
let (id, spawn_window) = window::open(window::Settings {
|
||||||
position: Default::default(),
|
position: Default::default(),
|
||||||
exit_on_close_request: count % 2 == 0,
|
exit_on_close_request: count % 2 == 0,
|
||||||
decorations: false,
|
decorations: false,
|
||||||
|
|
@ -110,13 +110,11 @@ impl cosmic::Application for MultiWindow {
|
||||||
);
|
);
|
||||||
_ = self.set_window_title(format!("window_{}", count), id);
|
_ = self.set_window_title(format!("window_{}", count), id);
|
||||||
|
|
||||||
spawn_window
|
spawn_window.map(|id| cosmic::app::Message::App(Message::WindowOpened(id, None)))
|
||||||
}
|
}
|
||||||
Message::Input(id, value) => {
|
Message::Input(id, value) => {
|
||||||
if let Some(w) = self.windows.get_mut(&self.core.main_window_id().unwrap()) {
|
if let Some((_, w)) = self.windows.iter_mut().find(|e| e.1.input_id == id) {
|
||||||
if id == w.input_id {
|
w.input_value = value;
|
||||||
w.input_value = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::none()
|
Task::none()
|
||||||
|
|
@ -128,7 +126,7 @@ impl cosmic::Application for MultiWindow {
|
||||||
let w = self.windows.get(&id).unwrap();
|
let w = self.windows.get(&id).unwrap();
|
||||||
|
|
||||||
let input_id = w.input_id.clone();
|
let input_id = w.input_id.clone();
|
||||||
let input = text_input("something", &w.input_value)
|
let input = cosmic::widget::text_input::text_input("something", &w.input_value)
|
||||||
.on_input(move |msg| Message::Input(input_id.clone(), msg))
|
.on_input(move |msg| Message::Input(input_id.clone(), msg))
|
||||||
.id(w.input_id.clone());
|
.id(w.input_id.clone());
|
||||||
let focused = self
|
let focused = self
|
||||||
|
|
@ -136,7 +134,7 @@ impl cosmic::Application for MultiWindow {
|
||||||
.focused_window()
|
.focused_window()
|
||||||
.map(|i| i == id)
|
.map(|i| i == id)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let new_window_button = button(text("New Window")).on_press(Message::NewWindow);
|
let new_window_button = button::custom(text("New Window")).on_press(Message::NewWindow);
|
||||||
|
|
||||||
let content = scrollable(
|
let content = scrollable(
|
||||||
column![input, new_window_button]
|
column![input, new_window_button]
|
||||||
|
|
@ -146,7 +144,7 @@ impl cosmic::Application for MultiWindow {
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_content = container(container(content).center_x(Length::Fixed(200.)))
|
let window_content = container(container(content).center_x(Length::Fixed(200.)))
|
||||||
.style(cosmic::style::Container::Background)
|
.class(cosmic::style::Container::Background)
|
||||||
.center_x(Length::Fill)
|
.center_x(Length::Fill)
|
||||||
.center_y(Length::Fill);
|
.center_y(Length::Fill);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
//! An application which provides an open dialog
|
//! An application which provides an open dialog
|
||||||
|
|
||||||
use apply::Apply;
|
use apply::Apply;
|
||||||
use cosmic::app::{Task, Core, Settings};
|
use cosmic::app::{Core, Settings, Task};
|
||||||
use cosmic::dialog::file_chooser::{self, FileFilter};
|
use cosmic::dialog::file_chooser::{self, FileFilter};
|
||||||
use cosmic::iced_core::Length;
|
use cosmic::iced_core::Length;
|
||||||
use cosmic::widget::button;
|
use cosmic::widget::button;
|
||||||
|
|
@ -77,7 +77,7 @@ impl cosmic::Application for App {
|
||||||
app.set_header_title("Open a file".into());
|
app.set_header_title("Open a file".into());
|
||||||
let cmd = app.set_window_title(
|
let cmd = app.set_window_title(
|
||||||
"COSMIC OpenDialog Demo".into(),
|
"COSMIC OpenDialog Demo".into(),
|
||||||
cosmic::iced::self.core.main_window_id().unwrap(),
|
self.core.main_window_id().unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
(app, cmd)
|
(app, cmd)
|
||||||
|
|
@ -211,7 +211,11 @@ impl cosmic::Application for App {
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
content.push(iced::widget::vertical_space(Length::Fixed(12.0)).into());
|
content.push(
|
||||||
|
iced::widget::vertical_space()
|
||||||
|
.height(Length::Fixed(12.0))
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
content.push(if self.selected_file.is_none() {
|
content.push(if self.selected_file.is_none() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue