fix deprecation warnings that occured due to cursive 0.14.0 upgrade
This commit is contained in:
@@ -10,7 +10,7 @@ use librespot_protocol::authentication::AuthenticationType;
|
||||
|
||||
pub fn create_credentials(path: &Path) -> Result<RespotCredentials, String> {
|
||||
let mut login_cursive = Cursive::default();
|
||||
let mut info_buf = TextContent::new("Failed to authenticate\n");
|
||||
let info_buf = TextContent::new("Failed to authenticate\n");
|
||||
info_buf.append(format!(
|
||||
"Cannot read config file from {}\n",
|
||||
path.to_str().unwrap()
|
||||
@@ -23,23 +23,23 @@ pub fn create_credentials(path: &Path) -> Result<RespotCredentials, String> {
|
||||
ListView::new()
|
||||
.child(
|
||||
"Username",
|
||||
EditView::new().with_id("spotify_user").fixed_width(18),
|
||||
EditView::new().with_name("spotify_user").fixed_width(18),
|
||||
)
|
||||
.child(
|
||||
"Password",
|
||||
EditView::new()
|
||||
.secret()
|
||||
.with_id("spotify_password")
|
||||
.with_name("spotify_password")
|
||||
.fixed_width(18),
|
||||
),
|
||||
)
|
||||
.button("Login", |s| {
|
||||
let username = s
|
||||
.call_on_id("spotify_user", |view: &mut EditView| view.get_content())
|
||||
.call_on_name("spotify_user", |view: &mut EditView| view.get_content())
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let auth_data = s
|
||||
.call_on_id("spotify_password", |view: &mut EditView| view.get_content())
|
||||
.call_on_name("spotify_password", |view: &mut EditView| view.get_content())
|
||||
.unwrap()
|
||||
.to_string()
|
||||
.as_bytes()
|
||||
|
||||
@@ -137,7 +137,7 @@ impl CommandManager {
|
||||
|
||||
fn handle_callbacks(&self, s: &mut Cursive, cmd: &Command) -> Result<Option<String>, String> {
|
||||
let local = {
|
||||
let mut main: ViewRef<Layout> = s.find_id("main").unwrap();
|
||||
let mut main: ViewRef<Layout> = s.find_name("main").unwrap();
|
||||
main.on_command(s, cmd)?
|
||||
};
|
||||
|
||||
@@ -147,7 +147,7 @@ impl CommandManager {
|
||||
s.add_layer(modal);
|
||||
Ok(None)
|
||||
} else if let CommandResult::View(view) = local {
|
||||
s.call_on_id("main", move |v: &mut Layout| {
|
||||
s.call_on_name("main", move |v: &mut Layout| {
|
||||
v.push_view(view);
|
||||
});
|
||||
|
||||
@@ -160,7 +160,7 @@ impl CommandManager {
|
||||
pub fn handle(&self, s: &mut Cursive, cmd: Command) {
|
||||
let result = self.handle_callbacks(s, &cmd);
|
||||
|
||||
s.call_on_id("main", |v: &mut Layout| {
|
||||
s.call_on_name("main", |v: &mut Layout| {
|
||||
v.set_result(result);
|
||||
});
|
||||
|
||||
@@ -213,8 +213,14 @@ impl CommandManager {
|
||||
kb.insert("/".into(), Command::Focus("search".into()));
|
||||
kb.insert("f".into(), Command::Seek(SeekDirection::Relative(1000)));
|
||||
kb.insert("b".into(), Command::Seek(SeekDirection::Relative(-1000)));
|
||||
kb.insert("Shift+f".into(), Command::Seek(SeekDirection::Relative(10000)));
|
||||
kb.insert("Shift+b".into(), Command::Seek(SeekDirection::Relative(-10000)));
|
||||
kb.insert(
|
||||
"Shift+f".into(),
|
||||
Command::Seek(SeekDirection::Relative(10000)),
|
||||
);
|
||||
kb.insert(
|
||||
"Shift+b".into(),
|
||||
Command::Seek(SeekDirection::Relative(-10000)),
|
||||
);
|
||||
kb.insert("+".into(), Command::VolumeUp);
|
||||
kb.insert("-".into(), Command::VolumeDown);
|
||||
kb.insert("r".into(), Command::Repeat(None));
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@@ -220,21 +220,21 @@ fn main() {
|
||||
);
|
||||
|
||||
let mut layout = ui::layout::Layout::new(status, &event_manager, theme)
|
||||
.view("search", search.with_id("search"), "Search")
|
||||
.view("library", libraryview.with_id("library"), "Library")
|
||||
.view("search", search.with_name("search"), "Search")
|
||||
.view("library", libraryview.with_name("library"), "Library")
|
||||
.view("queue", queueview, "Queue");
|
||||
|
||||
// initial view is library
|
||||
layout.set_view("library");
|
||||
|
||||
cursive.add_global_callback(':', move |s| {
|
||||
s.call_on_id("main", |v: &mut ui::layout::Layout| {
|
||||
s.call_on_name("main", |v: &mut ui::layout::Layout| {
|
||||
v.enable_cmdline();
|
||||
});
|
||||
});
|
||||
|
||||
layout.cmdline.set_on_edit(move |s, cmd, _| {
|
||||
s.call_on_id("main", |v: &mut ui::layout::Layout| {
|
||||
s.call_on_name("main", |v: &mut ui::layout::Layout| {
|
||||
if cmd.is_empty() {
|
||||
v.clear_cmdline();
|
||||
}
|
||||
@@ -246,7 +246,7 @@ fn main() {
|
||||
let cmd_manager = cmd_manager.clone();
|
||||
layout.cmdline.set_on_submit(move |s, cmd| {
|
||||
{
|
||||
let mut main = s.find_id::<ui::layout::Layout>("main").unwrap();
|
||||
let mut main = s.find_name::<ui::layout::Layout>("main").unwrap();
|
||||
main.clear_cmdline();
|
||||
}
|
||||
let c = &cmd[1..];
|
||||
@@ -258,7 +258,7 @@ fn main() {
|
||||
});
|
||||
}
|
||||
|
||||
cursive.add_fullscreen_layer(layout.with_id("main"));
|
||||
cursive.add_fullscreen_layer(layout.with_name("main"));
|
||||
|
||||
// cursive event loop
|
||||
while cursive.is_running() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use cursive::view::{View, ViewWrapper};
|
||||
use cursive::views::IdView;
|
||||
use cursive::views::NamedView;
|
||||
use cursive::Cursive;
|
||||
|
||||
use album::Album;
|
||||
@@ -49,7 +49,7 @@ pub trait ViewExt: View {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: ViewExt> ViewExt for IdView<V> {
|
||||
impl<V: ViewExt> ViewExt for NamedView<V> {
|
||||
fn on_command(&mut self, s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
|
||||
self.with_view_mut(move |v| v.on_command(s, cmd)).unwrap()
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ impl ContextMenu {
|
||||
match action {
|
||||
ContextMenuAction::ShowItem(item) => {
|
||||
if let Some(view) = item.open(queue, library) {
|
||||
s.call_on_id("main", move |v: &mut Layout| v.push_view(view));
|
||||
s.call_on_name("main", move |v: &mut Layout| v.push_view(view));
|
||||
}
|
||||
}
|
||||
ContextMenuAction::ShareUrl(url) => {
|
||||
|
||||
@@ -51,7 +51,7 @@ impl QueueView {
|
||||
library.save_playlist(name, &tracks);
|
||||
s.pop_layer();
|
||||
})
|
||||
.with_id("name")
|
||||
.with_name("name")
|
||||
.fixed_width(20);
|
||||
let dialog = Dialog::new()
|
||||
.title("Enter name")
|
||||
|
||||
@@ -4,7 +4,7 @@ use cursive::direction::Orientation;
|
||||
use cursive::event::{AnyCb, Event, EventResult, Key};
|
||||
use cursive::traits::{Boxable, Finder, Identifiable, View};
|
||||
use cursive::view::{Selector, ViewWrapper};
|
||||
use cursive::views::{EditView, IdView, ViewRef};
|
||||
use cursive::views::{EditView, NamedView, ViewRef};
|
||||
use cursive::{Cursive, Printer, Vec2};
|
||||
use std::cell::RefCell;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
@@ -32,8 +32,8 @@ pub struct SearchView {
|
||||
pagination_artists: Pagination<Artist>,
|
||||
results_playlists: Arc<RwLock<Vec<Playlist>>>,
|
||||
pagination_playlists: Pagination<Playlist>,
|
||||
edit: IdView<EditView>,
|
||||
tabs: IdView<TabView>,
|
||||
edit: NamedView<EditView>,
|
||||
tabs: NamedView<TabView>,
|
||||
edit_focused: bool,
|
||||
events: EventManager,
|
||||
spotify: Arc<Spotify>,
|
||||
@@ -59,13 +59,13 @@ impl SearchView {
|
||||
let searchfield = EditView::new()
|
||||
.on_submit(move |s, input| {
|
||||
if !input.is_empty() {
|
||||
s.call_on_id("search", |v: &mut SearchView| {
|
||||
s.call_on_name("search", |v: &mut SearchView| {
|
||||
v.run_search(input);
|
||||
v.focus_view(&Selector::Id(LIST_ID)).unwrap();
|
||||
v.focus_view(&Selector::Name(LIST_ID)).unwrap();
|
||||
});
|
||||
}
|
||||
})
|
||||
.with_id(EDIT_ID);
|
||||
.with_name(EDIT_ID);
|
||||
|
||||
let list_tracks = ListView::new(results_tracks.clone(), queue.clone(), library.clone());
|
||||
let pagination_tracks = list_tracks.get_pagination().clone();
|
||||
@@ -93,7 +93,7 @@ impl SearchView {
|
||||
results_playlists,
|
||||
pagination_playlists,
|
||||
edit: searchfield,
|
||||
tabs: tabs.with_id(LIST_ID),
|
||||
tabs: tabs.with_name(LIST_ID),
|
||||
edit_focused: true,
|
||||
events,
|
||||
spotify,
|
||||
@@ -102,7 +102,7 @@ impl SearchView {
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.edit
|
||||
.call_on(&Selector::Id(EDIT_ID), |v: &mut EditView| {
|
||||
.call_on(&Selector::Name(EDIT_ID), |v: &mut EditView| {
|
||||
v.set_content("");
|
||||
});
|
||||
}
|
||||
@@ -298,7 +298,7 @@ impl SearchView {
|
||||
{
|
||||
let query = query.clone();
|
||||
self.edit
|
||||
.call_on(&Selector::Id(EDIT_ID), |v: &mut EditView| {
|
||||
.call_on(&Selector::Name(EDIT_ID), |v: &mut EditView| {
|
||||
v.set_content(query);
|
||||
});
|
||||
}
|
||||
@@ -420,13 +420,13 @@ impl View for SearchView {
|
||||
}
|
||||
}
|
||||
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>) {
|
||||
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) {
|
||||
self.edit.call_on_any(selector, &mut |v| callback(v));
|
||||
self.tabs.call_on_any(selector, &mut |v| callback(v));
|
||||
}
|
||||
|
||||
fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
|
||||
if let Selector::Id(s) = selector {
|
||||
if let Selector::Name(s) = selector {
|
||||
self.edit_focused = s == &"search_edit";
|
||||
Ok(())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user