refactor!(app): rename set_title to set_window_title

This commit is contained in:
Michael Aaron Murphy 2023-10-12 13:54:08 +02:00 committed by Michael Murphy
parent 32eafb0c48
commit 395a90891d
4 changed files with 41 additions and 41 deletions

View file

@ -147,7 +147,9 @@ where
} }
fn update_title(&mut self) -> Command<Message> { fn update_title(&mut self) -> Command<Message> {
let title = self.active_page_title().to_owned(); let header_title = self.active_page_title().to_owned();
self.set_title(title) let window_title = format!("{header_title} — COSMIC AppDemo");
self.set_header_title(header_title);
self.set_window_title(window_title)
} }
} }

View file

@ -76,9 +76,10 @@ impl cosmic::Application for App {
error_status: None, error_status: None,
}; };
let command = app.set_title("Open a file".into()); app.set_header_title("Open a file".into());
let cmd = app.set_window_title("COSMIC OpenDialog Demo".into());
(app, command) (app, cmd)
} }
fn header_end(&self) -> Vec<Element<Self::Message>> { fn header_end(&self) -> Vec<Element<Self::Message>> {
@ -136,43 +137,40 @@ impl cosmic::Application for App {
let mut contents = String::new(); let mut contents = String::new();
std::mem::swap(&mut contents, &mut self.file_contents); std::mem::swap(&mut contents, &mut self.file_contents);
return Command::batch(vec![ // Set the file's URL as the application title.
// Set the file's URL as the application title. self.set_header_title(url.to_string());
self.set_title(url.to_string()),
// Reads the selected file into memory.
cosmic::command::future(async move {
// Check if its a valid local file path.
let path = match url.scheme() {
"file" => url.path(),
other => {
return Message::Error(format!(
"{url} has unknown scheme: {other}"
));
}
};
// Open the file by its path. // Reads the selected file into memory.
let mut file = match tokio::fs::File::open(path).await { return cosmic::command::future(async move {
Ok(file) => file, // Check if its a valid local file path.
Err(why) => { let path = match url.scheme() {
return Message::Error(format!("failed to open {path}: {why}")); "file" => url.path(),
} other => {
}; return Message::Error(format!("{url} has unknown scheme: {other}"));
// Read the file into our contents buffer.
contents.clear();
if let Err(why) = file.read_to_string(&mut contents).await {
return Message::Error(format!("failed to read {path}: {why}"));
} }
};
contents.shrink_to_fit(); // Open the file by its path.
let mut file = match tokio::fs::File::open(path).await {
Ok(file) => file,
Err(why) => {
return Message::Error(format!("failed to open {path}: {why}"));
}
};
// Send this back to the application. // Read the file into our contents buffer.
Message::FileRead(url, contents) contents.clear();
})
.map(cosmic::app::message::app), if let Err(why) = file.read_to_string(&mut contents).await {
]); return Message::Error(format!("failed to read {path}: {why}"));
}
contents.shrink_to_fit();
// Send this back to the application.
Message::FileRead(url, contents)
})
.map(cosmic::app::message::app);
} }
// Creates a new open dialog. // Creates a new open dialog.

View file

@ -240,7 +240,7 @@ pub trait ApplicationExt: Application {
} }
/// Set the title of the main window. /// Set the title of the main window.
fn set_title(&mut self, title: String) -> iced::Command<Message<Self::Message>>; fn set_window_title(&mut self, title: String) -> iced::Command<Message<Self::Message>>;
/// View template for the main window. /// View template for the main window.
fn view_main(&self) -> Element<Message<Self::Message>>; fn view_main(&self) -> Element<Message<Self::Message>>;
@ -264,13 +264,13 @@ impl<App: Application> ApplicationExt for App {
} }
#[cfg(feature = "wayland")] #[cfg(feature = "wayland")]
fn set_title(&mut self, title: String) -> iced::Command<Message<Self::Message>> { fn set_window_title(&mut self, title: String) -> iced::Command<Message<Self::Message>> {
self.core_mut().title = title.clone(); self.core_mut().title = title.clone();
command::set_title(title) command::set_title(title)
} }
#[cfg(not(feature = "wayland"))] #[cfg(not(feature = "wayland"))]
fn set_title(&mut self, title: String) -> iced::Command<Message<Self::Message>> { fn set_window_title(&mut self, title: String) -> iced::Command<Message<Self::Message>> {
self.core_mut().title = title.clone(); self.core_mut().title = title.clone();
iced::Command::none() iced::Command::none()
} }