Made edit and add buttons work from menu
This commit is contained in:
@@ -7,7 +7,7 @@ from functools import partial
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, cast, Dict, Iterable, Optional, Tuple, Type, Union
|
from typing import Any, Callable, cast, Dict, Iterable, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
from gi.repository import Gdk, GLib, GObject, Gtk, Pango
|
from gi.repository import GLib, GObject, Gtk, Pango
|
||||||
|
|
||||||
from . import ConfigurationStore
|
from . import ConfigurationStore
|
||||||
|
|
||||||
|
@@ -74,10 +74,10 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
self.add_action(action)
|
self.add_action(action)
|
||||||
|
|
||||||
# Add action for menu items.
|
# Add action for menu items.
|
||||||
add_action("add-new-provider", self.on_add_new_provider)
|
add_action("add-new-music-provider", self.on_add_new_music_provider)
|
||||||
add_action("edit-current-provider", self.on_edit_current_provider)
|
add_action("edit-current-music-provider", self.on_edit_current_music_provider)
|
||||||
add_action("switch-provider", self.on_switch_provider)
|
add_action("switch-music-provider", self.on_switch_music_provider)
|
||||||
add_action("remove-provider", self.on_remove_provider)
|
add_action("remove-music-provider", self.on_remove_music_provider)
|
||||||
|
|
||||||
# Add actions for player controls
|
# Add actions for player controls
|
||||||
add_action("play-pause", self.on_play_pause)
|
add_action("play-pause", self.on_play_pause)
|
||||||
@@ -164,10 +164,6 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
self.window.close()
|
self.window.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.app_config.current_provider_id = list(
|
|
||||||
self.app_config.providers.keys()
|
|
||||||
)[0]
|
|
||||||
|
|
||||||
AdapterManager.reset(self.app_config, self.on_song_download_progress)
|
AdapterManager.reset(self.app_config, self.on_song_download_progress)
|
||||||
|
|
||||||
# Connect after we know there's a server configured.
|
# Connect after we know there's a server configured.
|
||||||
@@ -562,16 +558,18 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
|
|
||||||
self.reset_state()
|
self.reset_state()
|
||||||
|
|
||||||
def on_add_new_provider(self, _, provider: ProviderConfiguration):
|
def on_add_new_music_provider(self, *args):
|
||||||
|
self.show_configure_servers_dialog()
|
||||||
|
|
||||||
|
def on_edit_current_music_provider(self, *args):
|
||||||
|
self.show_configure_servers_dialog(self.app_config.provider)
|
||||||
|
|
||||||
|
def on_switch_music_provider(self, _, provider_id: str):
|
||||||
|
print("SWITCH")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_edit_current_provider(self, _):
|
def on_remove_music_provider(self, _, provider_id: str):
|
||||||
pass
|
print("REMOVE")
|
||||||
|
|
||||||
def on_switch_provider(self, _, provider_id: str):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def on_remove_provider(self, _, provider_id: str):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_window_go_to(self, win: Any, action: str, value: str):
|
def on_window_go_to(self, win: Any, action: str, value: str):
|
||||||
@@ -931,7 +929,12 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
assert dialog.provider_config is not None
|
assert dialog.provider_config is not None
|
||||||
provider_id = dialog.provider_config.id
|
provider_id = dialog.provider_config.id
|
||||||
self.app_config.providers[provider_id] = dialog.provider_config
|
self.app_config.providers[provider_id] = dialog.provider_config
|
||||||
|
|
||||||
|
# Switch to the new provider.
|
||||||
|
self.app_config.current_provider_id = provider_id
|
||||||
self.app_config.save()
|
self.app_config.save()
|
||||||
|
self.update_window(force=True)
|
||||||
|
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def update_window(self, force: bool = False):
|
def update_window(self, force: bool = False):
|
||||||
@@ -1300,7 +1303,6 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def save_play_queue(self, song_playing_order_token: int = None):
|
def save_play_queue(self, song_playing_order_token: int = None):
|
||||||
print('SAVE PLAY QUEUE')
|
|
||||||
if (
|
if (
|
||||||
len(self.app_config.state.play_queue) == 0
|
len(self.app_config.state.play_queue) == 0
|
||||||
or self.app_config.provider is None
|
or self.app_config.provider is None
|
||||||
|
@@ -2,12 +2,11 @@ import uuid
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Optional, Type
|
from typing import Any, Optional, Type
|
||||||
|
|
||||||
from gi.repository import Gio, GLib, GObject, Gtk, Pango
|
from gi.repository import Gio, GObject, Gtk, Pango
|
||||||
|
|
||||||
from sublime.adapters import AdapterManager, UIInfo
|
from sublime.adapters import AdapterManager, UIInfo
|
||||||
from sublime.adapters.filesystem import FilesystemAdapter
|
from sublime.adapters.filesystem import FilesystemAdapter
|
||||||
from sublime.config import ConfigurationStore, ProviderConfiguration
|
from sublime.config import ConfigurationStore, ProviderConfiguration
|
||||||
from sublime.ui.common import IconButton
|
|
||||||
|
|
||||||
|
|
||||||
class AdapterTypeModel(GObject.GObject):
|
class AdapterTypeModel(GObject.GObject):
|
||||||
@@ -40,32 +39,35 @@ class ConfigureProviderDialog(Gtk.Dialog):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def set_title(self, editing: bool, provider_config: ProviderConfiguration = None):
|
||||||
|
if editing:
|
||||||
|
assert provider_config is not None
|
||||||
|
title = f"Edit {provider_config.name}"
|
||||||
|
else:
|
||||||
|
title = "Add New Music Source"
|
||||||
|
|
||||||
|
self.header.props.title = title
|
||||||
|
|
||||||
def __init__(self, parent: Any, provider_config: Optional[ProviderConfiguration]):
|
def __init__(self, parent: Any, provider_config: Optional[ProviderConfiguration]):
|
||||||
title = (
|
Gtk.Dialog.__init__(self, transient_for=parent, flags=Gtk.DialogFlags.MODAL)
|
||||||
"Add New Music Source"
|
|
||||||
if not provider_config
|
|
||||||
else "Edit {provider_config.name}"
|
|
||||||
)
|
|
||||||
Gtk.Dialog.__init__(
|
|
||||||
self, title=title, transient_for=parent, flags=Gtk.DialogFlags.MODAL
|
|
||||||
)
|
|
||||||
# TODO esc should prompt or go back depending on the page
|
# TODO esc should prompt or go back depending on the page
|
||||||
self.provider_config = provider_config
|
self.provider_config = provider_config
|
||||||
|
self.editing = provider_config is not None
|
||||||
self.set_default_size(400, 350)
|
self.set_default_size(400, 350)
|
||||||
|
|
||||||
# HEADER
|
# HEADER
|
||||||
header = Gtk.HeaderBar()
|
self.header = Gtk.HeaderBar()
|
||||||
header.props.title = title
|
self.set_title(self.editing, provider_config)
|
||||||
|
|
||||||
self.cancel_back_button = Gtk.Button(label="Cancel")
|
self.cancel_back_button = Gtk.Button(label="Cancel")
|
||||||
self.cancel_back_button.connect("clicked", self._on_cancel_back_clicked)
|
self.cancel_back_button.connect("clicked", self._on_cancel_back_clicked)
|
||||||
header.pack_start(self.cancel_back_button)
|
self.header.pack_start(self.cancel_back_button)
|
||||||
|
|
||||||
self.next_add_button = Gtk.Button(label="Next")
|
self.next_add_button = Gtk.Button(label="Edit" if self.editing else "Next")
|
||||||
self.next_add_button.connect("clicked", self._on_next_add_clicked)
|
self.next_add_button.connect("clicked", self._on_next_add_clicked)
|
||||||
header.pack_end(self.next_add_button)
|
self.header.pack_end(self.next_add_button)
|
||||||
|
|
||||||
self.set_titlebar(header)
|
self.set_titlebar(self.header)
|
||||||
|
|
||||||
content_area = self.get_content_area()
|
content_area = self.get_content_area()
|
||||||
|
|
||||||
@@ -109,8 +111,6 @@ class ConfigureProviderDialog(Gtk.Dialog):
|
|||||||
available_ground_truth_adapters = filter(
|
available_ground_truth_adapters = filter(
|
||||||
lambda a: a.can_be_ground_truth, AdapterManager.available_adapters
|
lambda a: a.can_be_ground_truth, AdapterManager.available_adapters
|
||||||
)
|
)
|
||||||
# TODO: DEBUG REMOVE NEXT LINE
|
|
||||||
available_ground_truth_adapters = AdapterManager.available_adapters
|
|
||||||
for adapter_type in sorted(
|
for adapter_type in sorted(
|
||||||
available_ground_truth_adapters, key=lambda a: a.get_ui_info().name
|
available_ground_truth_adapters, key=lambda a: a.get_ui_info().name
|
||||||
):
|
):
|
||||||
@@ -126,6 +126,19 @@ class ConfigureProviderDialog(Gtk.Dialog):
|
|||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
if self.editing:
|
||||||
|
assert self.provider_config
|
||||||
|
for i, adapter_type in enumerate(self.adapter_type_store):
|
||||||
|
if (
|
||||||
|
adapter_type.adapter_type
|
||||||
|
== self.provider_config.ground_truth_adapter_type
|
||||||
|
):
|
||||||
|
row = self.adapter_options_list.get_row_at_index(i)
|
||||||
|
self.adapter_options_list.select_row(row)
|
||||||
|
break
|
||||||
|
self._name_is_valid = True
|
||||||
|
self._on_next_add_clicked()
|
||||||
|
|
||||||
def _on_cancel_back_clicked(self, _):
|
def _on_cancel_back_clicked(self, _):
|
||||||
if self.stage == DialogStage.SELECT_ADAPTER:
|
if self.stage == DialogStage.SELECT_ADAPTER:
|
||||||
self.close()
|
self.close()
|
||||||
@@ -175,12 +188,12 @@ class ConfigureProviderDialog(Gtk.Dialog):
|
|||||||
self.configure_box.pack_start(form, True, True, 0)
|
self.configure_box.pack_start(form, True, True, 0)
|
||||||
self.configure_box.show_all()
|
self.configure_box.show_all()
|
||||||
|
|
||||||
self._current_index = index
|
|
||||||
self.stack.set_visible_child_name("configure")
|
self.stack.set_visible_child_name("configure")
|
||||||
self.stage = DialogStage.CONFIGURE_ADAPTER
|
self.stage = DialogStage.CONFIGURE_ADAPTER
|
||||||
self.cancel_back_button.set_label("Back")
|
self.cancel_back_button.set_label("Change Type" if self.editing else "Back")
|
||||||
self.next_add_button.set_label("Add")
|
self.next_add_button.set_label("Edit" if self.editing else "Add")
|
||||||
self.next_add_button.set_sensitive(False)
|
self.next_add_button.set_sensitive(index == self._current_index)
|
||||||
|
self._current_index = index
|
||||||
else:
|
else:
|
||||||
if self.provider_config is None:
|
if self.provider_config is None:
|
||||||
self.provider_config = ProviderConfiguration(
|
self.provider_config = ProviderConfiguration(
|
||||||
@@ -190,7 +203,6 @@ class ConfigureProviderDialog(Gtk.Dialog):
|
|||||||
self.config_store,
|
self.config_store,
|
||||||
)
|
)
|
||||||
if self.adapter_type.can_be_cached:
|
if self.adapter_type.can_be_cached:
|
||||||
# TODO if we ever have more caching adapters, need to change this.
|
|
||||||
self.provider_config.caching_adapter_type = FilesystemAdapter
|
self.provider_config.caching_adapter_type = FilesystemAdapter
|
||||||
self.provider_config.caching_adapter_config = ConfigurationStore()
|
self.provider_config.caching_adapter_config = ConfigurationStore()
|
||||||
else:
|
else:
|
||||||
@@ -212,6 +224,10 @@ class ConfigureProviderDialog(Gtk.Dialog):
|
|||||||
self._name_is_valid = True
|
self._name_is_valid = True
|
||||||
entry.get_style_context().remove_class("invalid")
|
entry.get_style_context().remove_class("invalid")
|
||||||
entry.set_tooltip_markup(None)
|
entry.set_tooltip_markup(None)
|
||||||
|
|
||||||
|
assert self.provider_config
|
||||||
|
self.provider_config.name = entry.get_text()
|
||||||
|
self.set_title(self.editing, self.provider_config)
|
||||||
else:
|
else:
|
||||||
self._name_is_valid = False
|
self._name_is_valid = False
|
||||||
entry.get_style_context().add_class("invalid")
|
entry.get_style_context().add_class("invalid")
|
||||||
|
@@ -452,12 +452,14 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
return box, switch
|
return box, switch
|
||||||
|
|
||||||
def _create_model_button(
|
def _create_model_button(
|
||||||
self, text: str, clicked_fn: Callable = None, **kwargs
|
self, text: str, clicked_fn: Callable = None, action_name: str = None, **kwargs
|
||||||
) -> Gtk.ModelButton:
|
) -> Gtk.ModelButton:
|
||||||
model_button = Gtk.ModelButton(text=text, **kwargs)
|
model_button = Gtk.ModelButton(text=text, **kwargs)
|
||||||
model_button.get_style_context().add_class("menu-button")
|
model_button.get_style_context().add_class("menu-button")
|
||||||
if clicked_fn:
|
if clicked_fn:
|
||||||
model_button.connect("clicked", clicked_fn)
|
model_button.connect("clicked", clicked_fn)
|
||||||
|
if action_name:
|
||||||
|
model_button.set_action_name(f"app.{action_name}")
|
||||||
return model_button
|
return model_button
|
||||||
|
|
||||||
def _create_spin_button_menu_item(
|
def _create_spin_button_menu_item(
|
||||||
@@ -526,7 +528,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
("Delete Cached Song Files and Metadata", self._clear_entire_cache),
|
("Delete Cached Song Files and Metadata", self._clear_entire_cache),
|
||||||
]
|
]
|
||||||
for text, clicked_fn in menu_items:
|
for text, clicked_fn in menu_items:
|
||||||
clear_song_cache = self._create_model_button(text, clicked_fn)
|
clear_song_cache = self._create_model_button(text, clicked_fn=clicked_fn)
|
||||||
clear_cache_options.pack_start(clear_song_cache, False, True, 0)
|
clear_cache_options.pack_start(clear_song_cache, False, True, 0)
|
||||||
|
|
||||||
menu.add(clear_cache_options)
|
menu.add(clear_cache_options)
|
||||||
@@ -573,23 +575,19 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
vbox.add(offline_box)
|
vbox.add(offline_box)
|
||||||
|
|
||||||
edit_button = self._create_model_button(
|
edit_button = self._create_model_button(
|
||||||
"Edit Configuration...", self._on_edit_configuration_click
|
"Edit Configuration...", action_name="edit-current-music-provider"
|
||||||
)
|
)
|
||||||
vbox.add(edit_button)
|
vbox.add(edit_button)
|
||||||
|
|
||||||
vbox.add(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
|
vbox.add(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
|
||||||
|
|
||||||
music_provider_button = self._create_model_button(
|
music_provider_button = self._create_model_button(
|
||||||
"Switch Music Provider",
|
"Switch Music Provider", menu_name="switch-provider",
|
||||||
self._on_switch_provider_click,
|
|
||||||
menu_name="switch-provider",
|
|
||||||
)
|
)
|
||||||
# TODO (#197)
|
|
||||||
music_provider_button.set_action_name("app.configure-servers")
|
|
||||||
vbox.add(music_provider_button)
|
vbox.add(music_provider_button)
|
||||||
|
|
||||||
add_new_music_provider_button = self._create_model_button(
|
add_new_music_provider_button = self._create_model_button(
|
||||||
"Add New Music Provider...", self._on_add_new_provider_click
|
"Add New Music Provider...", action_name="add-new-music-provider"
|
||||||
)
|
)
|
||||||
vbox.add(add_new_music_provider_button)
|
vbox.add(add_new_music_provider_button)
|
||||||
|
|
||||||
@@ -817,18 +815,6 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
{"replay_gain": ReplayGainType.from_string(combo.get_active_id())}
|
{"replay_gain": ReplayGainType.from_string(combo.get_active_id())}
|
||||||
)
|
)
|
||||||
|
|
||||||
def _on_edit_configuration_click(self, _):
|
|
||||||
# TODO (#197): EDIT
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _on_switch_provider_click(self, _):
|
|
||||||
# TODO (#197): switch
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _on_add_new_provider_click(self, _):
|
|
||||||
# TODO (#197) add new
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _on_search_entry_focus(self, *args):
|
def _on_search_entry_focus(self, *args):
|
||||||
self._show_search()
|
self._show_search()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user