Skip to content

Commit

Permalink
PluginBrowser: Introduce manual ordering of plugins
Browse files Browse the repository at this point in the history
You are now able to re-order plugins via the < > buttons (on most rcu's aside < 0 >) in pluginbrowser

thx littlesat
  • Loading branch information
arn354 committed Feb 1, 2015
1 parent 1bd4425 commit 1eec85e
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions lib/python/Screens/PluginBrowser.py
Expand Up @@ -61,6 +61,9 @@ def CreateFeedConfig():
f.close()
os.system("ipkg update")

config.misc.pluginbrowser = ConfigSubsection()
config.misc.pluginbrowser.plugin_order = ConfigText(default="")

class PluginBrowserSummary(Screen):
def __init__(self, session, parent):
Screen.__init__(self, session, parent = parent)
Expand Down Expand Up @@ -107,6 +110,11 @@ def __init__(self, session):
"red": self.delete,
"green": self.download
})
self["DirectionActions"] = ActionMap(["DirectionActions"],
{
"moveUp": self.moveUp,
"moveDown": self.moveDown
})

self.onFirstExecBegin.append(self.checkWarnings)
self.onShown.append(self.updateList)
Expand Down Expand Up @@ -155,9 +163,42 @@ def run(self):
plugin = self["list"].l.getCurrentSelection()[0]
plugin(session=self.session)

def moveUp(self):
self.move(-1)

def moveDown(self):
self.move(1)

def move(self, direction):
if len(self.list) > 1:
currentIndex = self["list"].getSelectionIndex()
swapIndex = (currentIndex + direction) % len(self.list)
if currentIndex == 0 and swapIndex != 1:
self.list = self.list[1:] + [self.list[0]]
elif swapIndex == 0 and currentIndex != 1:
self.list = [self.list[-1]] + self.list[:-1]
else:
self.list[currentIndex], self.list[swapIndex] = self.list[swapIndex], self.list[currentIndex]
self["list"].l.setList(self.list)
if direction == 1:
self["list"].down()
else:
self["list"].up()
plugin_order = []
for x in self.list:
plugin_order.append(x[0].path[24:])
config.misc.pluginbrowser.plugin_order.value = ",".join(plugin_order)
config.misc.pluginbrowser.plugin_order.save()

def updateList(self):
self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
self.list = [PluginEntryComponent(plugin, self.listWidth) for plugin in self.pluginlist]
self.list = []
pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)[:]
for x in config.misc.pluginbrowser.plugin_order.value.split(","):
plugin = list(plugin for plugin in pluginlist if plugin.path[24:] == x)
if plugin:
self.list.append(PluginEntryComponent(plugin[0], self.listWidth))
pluginlist.remove(plugin[0])
self.list = self.list + [PluginEntryComponent(plugin, self.listWidth) for plugin in pluginlist]
self["list"].l.setList(self.list)

def delete(self):
Expand Down

0 comments on commit 1eec85e

Please sign in to comment.