Skip to content

Commit

Permalink
Fix duplicated separators in context menu
Browse files Browse the repository at this point in the history
- Auto add separator rather than adding manually
  • Loading branch information
MoojMidge committed Nov 6, 2024
1 parent 71b8345 commit c12875f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 27 deletions.
13 changes: 10 additions & 3 deletions resources/lib/youtube_plugin/kodion/items/base_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from datetime import date, datetime
from hashlib import md5

from .menu_items import separator
from ..compatibility import (
datetime_infolabel,
parse_qsl,
Expand Down Expand Up @@ -193,10 +194,16 @@ def get_fanart(self, default=True):
'fanart.jpg',
))

def add_context_menu(self, context_menu, position='end', replace=False):
context_menu = (item for item in context_menu if item)
def add_context_menu(self,
context_menu,
position='end',
replace=False,
end_separator=separator()):
context_menu = [item for item in context_menu if item]
if context_menu and end_separator and context_menu[-1] != end_separator:
context_menu.append(end_separator)
if replace or not self._context_menu:
self._context_menu = list(context_menu)
self._context_menu = context_menu
elif position == 'end':
self._context_menu.extend(context_menu)
else:
Expand Down
1 change: 0 additions & 1 deletion resources/lib/youtube_plugin/kodion/items/command_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ def __init__(self,
menu_items.refresh(context),
menu_items.goto_home(context),
menu_items.goto_quick_search(context),
menu_items.separator(),
]
self.add_context_menu(context_menu)
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(self, context, params, image=None, fanart=None):
menu_items.goto_page(context, params) if can_jump else None,
menu_items.goto_home(context),
menu_items.goto_quick_search(context),
menu_items.separator(),
]
self.add_context_menu(context_menu)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ def __init__(self, context, query, image=None, fanart=None, location=False):
menu_items.search_sort_by(context, params, 'viewCount'),
menu_items.search_sort_by(context, params, 'rating'),
menu_items.search_sort_by(context, params, 'title'),
menu_items.separator(),
]
self.add_context_menu(context_menu)
6 changes: 2 additions & 4 deletions resources/lib/youtube_plugin/youtube/helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ def update_channel_infos(provider, context, channel_id_dict,
)

if context_menu:
context_menu.append(menu_items.separator())
channel_item.add_context_menu(context_menu)

# update channel mapping
Expand Down Expand Up @@ -342,6 +341,7 @@ def update_playlist_infos(provider, context, playlist_id_dict,
video_count_label = localize('stats.videoCount')
podcast_label = context.localize('playlist.podcast')
untitled = localize('untitled')
separator = menu_items.separator()

path = context.get_path()
ui = context.get_ui()
Expand Down Expand Up @@ -448,7 +448,7 @@ def update_playlist_infos(provider, context, playlist_id_dict,
menu_items.shuffle_playlist(
context, playlist_id
),
menu_items.separator(),
separator,
menu_items.bookmark_add(
context, playlist_item
) if not in_bookmarks_list and channel_id != 'mine' else None,
Expand Down Expand Up @@ -499,7 +499,6 @@ def update_playlist_infos(provider, context, playlist_id_dict,
)

if context_menu:
context_menu.append(menu_items.separator())
playlist_item.add_context_menu(context_menu)

# update channel mapping
Expand Down Expand Up @@ -993,7 +992,6 @@ def update_video_infos(provider, context, video_id_dict,
)

if context_menu:
context_menu.append(menu_items.separator())
media_item.add_context_menu(context_menu)


Expand Down
1 change: 0 additions & 1 deletion resources/lib/youtube_plugin/youtube/helper/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _process_list_response(provider, context, json_data, item_filter):
menu_items.search_sort_by(context, params, 'viewCount'),
menu_items.search_sort_by(context, params, 'rating'),
menu_items.search_sort_by(context, params, 'title'),
menu_items.separator()
),
'position': 0,
}
Expand Down
25 changes: 9 additions & 16 deletions resources/lib/youtube_plugin/youtube/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,29 +436,25 @@ def on_channel_playlists(provider, context, re_match):
menu_items.shuffle_playlist(
context, playlist_id
),
menu_items.separator(),
menu_items.bookmark_add(
context, uploads
) if channel_id != 'mine' else None,
]

if channel_id != 'mine':
if provider.is_logged_in:
context_menu.extend((
menu_items.separator(),
menu_items.bookmark_add(
context, uploads
),
# subscribe to the channel via the playlist item
context_menu.append(
menu_items.subscribe_to_channel(
context, channel_id,
)
)
context_menu.append(
menu_items.subscribe_to_channel(
context, channel_id,
) if provider.is_logged_in else None,
# bookmark channel of the playlist
menu_items.bookmark_add_channel(
context, channel_id,
)
)
))

if context_menu:
context_menu.append(menu_items.separator())
uploads.add_context_menu(context_menu)

result = [uploads]
Expand Down Expand Up @@ -1114,7 +1110,6 @@ def on_playback_history(provider, context, re_match):
menu_items.history_clear(
context
),
menu_items.separator(),
),
'position': 0,
}
Expand Down Expand Up @@ -1606,7 +1601,6 @@ def _update(new_item):
menu_items.bookmarks_clear(
context
),
menu_items.separator(),
),
'position': 0,
},
Expand Down Expand Up @@ -1691,7 +1685,6 @@ def on_watch_later(provider, context, re_match):
menu_items.watch_later_local_clear(
context
),
menu_items.separator(),
),
'position': 0,
}
Expand Down

0 comments on commit c12875f

Please sign in to comment.