refactor!(app): rename set_title to set_window_title
This commit is contained in:
parent
32eafb0c48
commit
395a90891d
4 changed files with 41 additions and 41 deletions
|
|
@ -147,7 +147,9 @@ where
|
|||
}
|
||||
|
||||
fn update_title(&mut self) -> Command<Message> {
|
||||
let title = self.active_page_title().to_owned();
|
||||
self.set_title(title)
|
||||
let header_title = self.active_page_title().to_owned();
|
||||
let window_title = format!("{header_title} — COSMIC AppDemo");
|
||||
self.set_header_title(header_title);
|
||||
self.set_window_title(window_title)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ fn test_config(config: Config) {
|
|||
pub fn main() {
|
||||
println!("Testing config");
|
||||
test_config(Config::new("com.system76.Example", 1).unwrap());
|
||||
|
||||
|
||||
println!("Testing state");
|
||||
test_config(Config::new_state("com.system76.Example", 1).unwrap());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,9 +76,10 @@ impl cosmic::Application for App {
|
|||
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>> {
|
||||
|
|
@ -136,43 +137,40 @@ impl cosmic::Application for App {
|
|||
let mut contents = String::new();
|
||||
std::mem::swap(&mut contents, &mut self.file_contents);
|
||||
|
||||
return Command::batch(vec![
|
||||
// Set the file's URL as the application title.
|
||||
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}"
|
||||
));
|
||||
}
|
||||
};
|
||||
// Set the file's URL as the application title.
|
||||
self.set_header_title(url.to_string());
|
||||
|
||||
// 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}"));
|
||||
}
|
||||
};
|
||||
|
||||
// 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}"));
|
||||
// Reads the selected file into memory.
|
||||
return 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}"));
|
||||
}
|
||||
};
|
||||
|
||||
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.
|
||||
Message::FileRead(url, contents)
|
||||
})
|
||||
.map(cosmic::app::message::app),
|
||||
]);
|
||||
// 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();
|
||||
|
||||
// Send this back to the application.
|
||||
Message::FileRead(url, contents)
|
||||
})
|
||||
.map(cosmic::app::message::app);
|
||||
}
|
||||
|
||||
// Creates a new open dialog.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue