mirror of
https://gitlab.com/liyaowhen/youtubecollector-git.git
synced 2026-10-01 01:12:59 +00:00
fixed bug that made window crash when there were no playlists
This commit is contained in:
@@ -86,11 +86,13 @@ namespace Song {
|
||||
|
||||
var config = Config.get_instance();
|
||||
config.config_changed.connect(() => {
|
||||
if (config.playlists.length() == 1) {
|
||||
config.playlists.foreach((i) => {
|
||||
change_page(i);
|
||||
return;
|
||||
});
|
||||
if (config.playlists != null) {
|
||||
if (config.playlists.length() == 1) {
|
||||
config.playlists.foreach((i) => {
|
||||
change_page(i);
|
||||
return;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace Song {
|
||||
|
||||
private Settings settings = new Settings ("com.liyaowhen.Song");
|
||||
|
||||
private PlaylistObject playlist;
|
||||
public PlaylistObject playlist;
|
||||
private Gtk.Button remove_button;
|
||||
private Gtk.Revealer remove_button_revealer;
|
||||
|
||||
@@ -13,10 +13,17 @@ namespace Song {
|
||||
}
|
||||
|
||||
construct {
|
||||
|
||||
|
||||
orientation = Gtk.Orientation.HORIZONTAL;
|
||||
add_css_class("toolbar");
|
||||
remove_button = new Gtk.Button.from_icon_name("app-remove-symbolic");
|
||||
|
||||
remove_button.clicked.connect(() => {
|
||||
print("clicked");
|
||||
confirm_delete_popup();
|
||||
});
|
||||
|
||||
remove_button_revealer = new Gtk.Revealer();
|
||||
remove_button_revealer.set_child(remove_button);
|
||||
remove_button_revealer.transition_type = Gtk.RevealerTransitionType.SWING_LEFT;
|
||||
@@ -39,6 +46,7 @@ namespace Song {
|
||||
if (playlist.name != null) {
|
||||
main_button.label = playlist.name;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Config.get_instance().loaded.connect(() => {
|
||||
@@ -60,5 +68,29 @@ namespace Song {
|
||||
public void exit_removal_mode() {
|
||||
remove_button_revealer.set_reveal_child(false);
|
||||
}
|
||||
|
||||
private void confirm_delete_popup() {
|
||||
|
||||
|
||||
var alert_dialog = new Adw.AlertDialog("Remove Playlist?",
|
||||
"Deleting a playlist is a non-reversable action,
|
||||
however the playlist's items will remain intact in the configuration folder");
|
||||
|
||||
alert_dialog.add_response("Cancel", "Cancel");
|
||||
alert_dialog.add_response("Confirm", "Confirm");
|
||||
alert_dialog.set_response_appearance("Confirm", Adw.ResponseAppearance.DESTRUCTIVE);
|
||||
|
||||
alert_dialog.present(this);
|
||||
|
||||
|
||||
alert_dialog.response.connect((i, e) => {
|
||||
if (e == "Confirm") {
|
||||
Config.get_instance().playlists.remove(playlist);
|
||||
Config.get_instance().save.begin();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
-23
@@ -60,7 +60,7 @@ namespace Song {
|
||||
vexpand_set = true;
|
||||
hexpand_set = true;
|
||||
|
||||
PlaylistObject initial_playlist;
|
||||
PlaylistObject? initial_playlist = null;
|
||||
|
||||
/*var playlist_names = settings.get_strv("playlists");
|
||||
foreach (string _name in playlist_names) {
|
||||
@@ -75,23 +75,33 @@ namespace Song {
|
||||
Config config = Config.get_instance();
|
||||
|
||||
bool firstDeclared = false;
|
||||
config.playlists.foreach((_playlist) => {
|
||||
var button = new PlaylistButton(_playlist);
|
||||
if (!firstDeclared) {initial_playlist = _playlist; firstDeclared = true;}
|
||||
|
||||
playlist_buttons.add(button);
|
||||
append(button);
|
||||
});
|
||||
|
||||
config.config_changed.connect(() => {
|
||||
playlist_buttons.clear();
|
||||
config.playlists.foreach((_playlist) => {
|
||||
if (config.playlists != null) {
|
||||
foreach (PlaylistObject _playlist in config.playlists) {
|
||||
var button = new PlaylistButton(_playlist);
|
||||
if (!firstDeclared) {initial_playlist = _playlist; firstDeclared = true;}
|
||||
|
||||
playlist_buttons.add(button);
|
||||
append(button);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print("\n aaaaaa" + playlist_buttons.size.to_string() + "\n");
|
||||
|
||||
config.config_changed.connect(() => {
|
||||
foreach (PlaylistButton e in playlist_buttons) {
|
||||
print("\n" + e.playlist.name + "eee");
|
||||
e.destroy();
|
||||
}
|
||||
if (config.playlists != null) {
|
||||
config.playlists.foreach((_playlist) => {
|
||||
var button = new PlaylistButton(_playlist);
|
||||
|
||||
playlist_buttons.add(button);
|
||||
append(button);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Timeout.add(1000, () => {
|
||||
if (playlist_buttons == null) {
|
||||
@@ -105,9 +115,10 @@ namespace Song {
|
||||
//print("sidbar requesting main_view_content switch to playlist of name:\n" + playlists.nth_data(0).name);
|
||||
Timeout.add(1, () => {
|
||||
if (SongController.main_view_content != null) {
|
||||
SongController.main_view_content.change_page(initial_playlist);
|
||||
return false;
|
||||
|
||||
if (initial_playlist != null) {
|
||||
SongController.main_view_content.change_page(initial_playlist);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}, 1);
|
||||
@@ -163,16 +174,17 @@ namespace Song {
|
||||
print("\n sidebar buttons are null");
|
||||
}
|
||||
if (i.get_active()) {
|
||||
sidebar_content.playlist_buttons.foreach((e) => {
|
||||
foreach (PlaylistButton e in sidebar_content.playlist_buttons) {
|
||||
e.enter_removal_mode();
|
||||
print(e.name);
|
||||
});
|
||||
print(e.playlist.name);
|
||||
}
|
||||
} else {
|
||||
sidebar_content.playlist_buttons.foreach((e) => {
|
||||
foreach (PlaylistButton e in sidebar_content.playlist_buttons) {
|
||||
e.exit_removal_mode();
|
||||
print(e.name);
|
||||
});
|
||||
print(e.playlist.name);
|
||||
}
|
||||
}
|
||||
print("\n" + sidebar_content.playlist_buttons.size.to_string() + "\n");
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user