Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.misc.pluginlist.fc_bookmarks_order #3328

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/python/Components/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,32 @@ def onDeselect(self, session):
description = property(lambda self: descriptionsList(self.choices.choices, choicesList.TYPE_LIST))


# This is the control, and base class, for a list of items.
#
class ConfigArray(ConfigElement):
def __init__(self, default=None):
ConfigElement.__init__(self)
if default is None:
default = []
self.default = default
self.lastValue = default
self.value = shallowcopy(default)

def load(self):
ConfigElement.load(self)
if not isinstance(self.value, list):
self.value = [] if self.value is None else list(self.value)

def getText(self):
return " ".join(self.value)

def fromString(self, value):
return eval(value)

def toString(self, value):
return str([x[0] if isinstance(x, list) else x for x in value])


# This is the control, and base class, for slider settings.
#
class ConfigSlider(ConfigElement):
Expand Down
28 changes: 19 additions & 9 deletions lib/python/Plugins/Extensions/FileCommander/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from Components.ActionMap import ActionMap, HelpableActionMap, HelpableNumberActionMap
from Components.ChoiceList import ChoiceList, ChoiceEntryComponent
from Components.config import config, ConfigYesNo, ConfigText, ConfigDirectory, ConfigSelection, ConfigLocations, ConfigSelectionNumber, ConfigSubsection
from Components.config import config, ConfigYesNo, ConfigText, ConfigDirectory, ConfigSelection, ConfigLocations, ConfigSelectionNumber, ConfigSubsection, ConfigArray
from Components.Console import Console as console
from Components.FileList import AUDIO_EXTENSIONS, DVD_EXTENSIONS, EXTENSIONS, FILE_PATH, FILE_IS_DIR, FileList, IMAGE_EXTENSIONS, MOVIE_EXTENSIONS, RECORDING_EXTENSIONS
from Components.Harddisk import harddiskmanager
Expand All @@ -29,7 +29,7 @@
from Components.Sources.StaticText import StaticText
from Components.Task import Condition, Job, job_manager as JobManager, Task
from Plugins.Plugin import PluginDescriptor
from Screens.ChoiceBox import ChoiceBox
from Screens.ChoiceBox import ChoiceBoxNew
from Screens.Console import Console
from Screens.DVD import DVDPlayer
from Screens.HelpMenu import HelpableScreen
Expand Down Expand Up @@ -105,6 +105,7 @@
if config.plugins.FileCommander.defaultPathRight.value and config.plugins.FileCommander.defaultPathRight.value not in default:
default.append(config.plugins.FileCommander.defaultPathRight.value)
config.plugins.FileCommander.bookmarks = ConfigLocations(default=default)
config.plugins.FileCommander.bookmarks_order = ConfigArray(default=[])
config.plugins.FileCommander.myExtensions = ConfigText(default="", visible_width=15, fixed_size=False)
config.plugins.FileCommander.extension = ConfigSelection(default="^.*$", choices=[
("^.*$", _("All files")),
Expand Down Expand Up @@ -936,7 +937,7 @@ def makeSymlinkCallback(newName):

def keyManageBookmarks(self, current):
bookmarks = config.plugins.FileCommander.bookmarks.value
order = config.misc.pluginlist.fc_bookmarks_order.value.split(",")
order = config.plugins.FileCommander.bookmarks_order.value
directory = current and self.sourceColumn.getCurrentDirectory() or self.sourceColumn.getPath()
if directory in bookmarks:
bookmarks.remove(directory)
Expand All @@ -950,8 +951,8 @@ def keyManageBookmarks(self, current):
self.displayStatus(_("Bookmark added."))
config.plugins.FileCommander.bookmarks.value = bookmarks
config.plugins.FileCommander.bookmarks.save()
config.misc.pluginlist.fc_bookmarks_order.value = ",".join(order)
config.misc.pluginlist.fc_bookmarks_order.save()
config.plugins.FileCommander.bookmarks_order.value = order
config.plugins.FileCommander.bookmarks_order.save()

def keyMediaInfo(self):
self.shortcutAction("mediainfo")
Expand Down Expand Up @@ -1479,13 +1480,13 @@ def selectBookmarkCallback(answer):

bookmarks = [(x, x) for x in config.plugins.FileCommander.bookmarks.value]
bookmarks.insert(0, (_("Storage Devices"), None))
order = config.misc.pluginlist.fc_bookmarks_order.value.split(",")
order = config.plugins.FileCommander.bookmarks_order.value
if order and _("Storage Devices") in order:
order.remove(_("Storage Devices"))
order.insert(0, _("Storage Devices"))
config.misc.pluginlist.fc_bookmarks_order.value = ",".join(order)
config.misc.pluginlist.fc_bookmarks_order.save()
self.session.openWithCallback(selectBookmarkCallback, ChoiceBox, title=_("Select Bookmark"), list=bookmarks, reorderConfig="fc_bookmarks_order")
config.plugins.FileCommander.bookmarks_order.value = order
config.plugins.FileCommander.bookmarks_order.save()
self.session.openWithCallback(selectBookmarkCallback, ChoiceBoxNew, windowTitle=_("Select Bookmark"), choiceList=bookmarks, reorderConfig=config.plugins.FileCommander.bookmarks_order)

def keySettings(self):
def settingsCallback(*answer):
Expand Down Expand Up @@ -2990,6 +2991,15 @@ def convertSettings():
config.plugins.FileCommander.save()
conversionDone = True

config.misc.pluginlist = ConfigSubsection()
config.misc.pluginlist.fc_bookmarks_order = ConfigText(default="")
config.plugins.FileCommander.bookmarks_order = ConfigArray(default=[])
if config.misc.pluginlist.fc_bookmarks_order.value:
config.plugins.Filecommander.bookmarks_order.value = config.misc.pluginlist.fc_bookmarks_order.value.split(",")
config.plugins.FileCommander.save()
config.misc.pluginlist.fc_bookmarks_order.value = ""
config.misc.pluginlist.save()


def filescanOpen(list, session, **kwargs):
path = "/".join(list[0].path.split("/")[:-1]) + "/"
Expand Down
62 changes: 29 additions & 33 deletions lib/python/Screens/ChoiceBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from Screens.MessageBox import MessageBox
from Screens.Screen import Screen, ScreenSummary

config.misc.pluginlist = ConfigSubsection()
config.misc.pluginlist.eventinfo_order = ConfigText(default="")
config.misc.pluginlist.extension_order = ConfigText(default="")
config.misc.pluginlist.fc_bookmarks_order = ConfigText(default="")
#config.misc.pluginlist = ConfigSubsection()
#config.misc.pluginlist.eventinfo_order = ConfigText(default="")
#config.misc.pluginlist.extension_order = ConfigText(default="")


class ChoiceBoxNew(Screen, HelpableScreen):
Expand All @@ -29,29 +28,26 @@ def __init__(self, session, text="", choiceList=None, selection=0, buttonList=No
buttonList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue", "text"] + (len(choiceList) - 14) * [""]
else:
buttonList = buttonList + (len(choiceList) - len(buttonList)) * [""]
if reorderConfig:
self.configOrder = getattr(config.misc.pluginlist, reorderConfig)
if self.configOrder.value:
prevList = [x for x in zip(choiceList, buttonList)]
newList = []
for button in self.configOrder.value.split(","):
for entry in prevList:
if entry[0][0] == button:
prevList.remove(entry)
newList.append(entry)
choiceList = [x for x in zip(*(newList + prevList))]
choiceList, buttonList = choiceList[0], choiceList[1]
number = 1
newButtons = []
for button in buttonList:
if (not button or button.isdigit()) and number <= 10:
newButtons.append(str(number % 10))
number += 1
else:
newButtons.append(not button.isdigit() and button or "")
buttonList = newButtons
else:
self.configOrder = None
self.reorderConfig = reorderConfig
if self.reorderConfig:
prevList = [x for x in zip(choiceList, buttonList)]
newList = []
for button in self.reorderConfig.value:
for entry in prevList:
if entry[0][0] == button:
prevList.remove(entry)
newList.append(entry)
choiceList = [x for x in zip(*(newList + prevList))]
choiceList, buttonList = choiceList[0], choiceList[1]
number = 1
newButtons = []
for button in buttonList:
if (not button or button.isdigit()) and number <= 10:
newButtons.append(str(number % 10))
number += 1
else:
newButtons.append(not button.isdigit() and button or "")
buttonList = newButtons
self.choiceList = []
self.buttonMap = {}
actionMethods = {
Expand Down Expand Up @@ -91,7 +87,7 @@ def __init__(self, session, text="", choiceList=None, selection=0, buttonList=No
"previous": (self.keyMoveItemUp, _("Move the current entry up")),
"next": (self.keyMoveItemDown, _("Move the current entry down")),
}, prio=0, description=_("Choice List Order Actions"))
self["moveActions"].setEnabled(len(choiceList) > 1 and self.configOrder)
self["moveActions"].setEnabled(len(choiceList) > 1 and self.reorderConfig)
self["summary_list"] = StaticText() # Temporary hack to support old display skins.
self["summary_selection"] = StaticText() # Temporary hack to support old display skins.
self.onLayoutFinish.append(self.layoutFinished)
Expand Down Expand Up @@ -182,14 +178,14 @@ def moveItem(self, direction):
self["list"].instance.goLineDown()
else:
self["list"].instance.goLineUp()
self.configOrder.value = ",".join(x[0][0] for x in self.choiceList)
self.configOrder.save()
self.reorderConfig.value = [x[0][0] for x in self.choiceList]
self.reorderConfig.save()

def keyResetList(self):
def keyResetListCallback(answer):
if answer:
self.configOrder.value = ""
self.configOrder.save()
self.reorderConfig.value = []
self.reorderConfig.save()

self.session.openWithCallback(keyResetListCallback, MessageBox, _("Reset list order to the default list order?"), MessageBox.TYPE_YESNO, windowTitle=self.getTitle())

Expand Down Expand Up @@ -282,5 +278,5 @@ def __init__(self, session, title="", list=None, keys=None, selection=0, skin_na
allowCancel = allow_cancel
if allowCancel is None:
allowCancel = True
ChoiceBoxNew.__init__(self, session, text=text, choiceList=choiceList, selection=selection, buttonList=buttonList, reorderConfig=reorderConfig, allowCancel=allowCancel, skinName=skinName, windowTitle=windowTitle)
ChoiceBoxNew.__init__(self, session, text=text, choiceList=choiceList, selection=selection, buttonList=buttonList, reorderConfig=None, allowCancel=allowCancel, skinName=skinName, windowTitle=windowTitle)
self.list = self.choiceList # Support for old skins an plugins
Loading