Clean up the patch from David Caro

This commit is contained in:
Stephen Boddy 2013-07-16 19:56:14 +02:00
parent 15c92c09a0
commit f4cc83c1e6
1 changed files with 25 additions and 22 deletions

View File

@ -27,26 +27,26 @@ class CustomCommandsMenu(plugin.MenuItem):
conf_file = os.path.join(get_config_dir(),"custom_commands") conf_file = os.path.join(get_config_dir(),"custom_commands")
def __init__( self): def __init__( self):
config = Config() config = Config()
sections = config.plugin_get_config(self.__class__.__name__) sections = config.plugin_get_config(self.__class__.__name__)
if not isinstance(sections, dict): if not isinstance(sections, dict):
return return
noord_cmds = [] noord_cmds = []
for part in sections: for part in sections:
s = sections[part] s = sections[part]
if not (s.has_key("name") and s.has_key("command")): if not (s.has_key("name") and s.has_key("command")):
print "CustomCommandsMenu: Ignoring section %s" % s print "CustomCommandsMenu: Ignoring section %s" % s
continue continue
name = s["name"] name = s["name"]
command = s["command"] command = s["command"]
enabled = s["enabled"] and s["enabled"] or False enabled = s["enabled"] and s["enabled"] or False
if s.has_key("position"): if s.has_key("position"):
self.cmd_list[int(s["position"])] = {'enabled' : enabled, self.cmd_list[int(s["position"])] = {'enabled' : enabled,
'name' : name, 'name' : name,
'command' : command 'command' : command
} }
else: else:
noord_cmds.append( noord_cmds.append(
{'enabled' : enabled, {'enabled' : enabled,
'name' : name, 'name' : name,
'command' : command 'command' : command
@ -55,7 +55,6 @@ class CustomCommandsMenu(plugin.MenuItem):
for cmd in noord_cmds: for cmd in noord_cmds:
self.cmd_list[len(self.cmd_list)] = cmd self.cmd_list[len(self.cmd_list)] = cmd
def callback(self, menuitems, menu, terminal): def callback(self, menuitems, menu, terminal):
"""Add our menu items to the menu""" """Add our menu items to the menu"""
item = gtk.MenuItem(_('Custom Commands')) item = gtk.MenuItem(_('Custom Commands'))
@ -195,10 +194,11 @@ class CustomCommandsMenu(plugin.MenuItem):
button.set_sensitive(False) button.set_sensitive(False)
ui['button_delete'] = button ui['button_delete'] = button
hbox.pack_start(button_box) hbox.pack_start(button_box)
dbox.show_all() dbox.show_all()
res = dbox.run() res = dbox.run()
if res == gtk.RESPONSE_ACCEPT: if res == gtk.RESPONSE_ACCEPT:
self.update_cmd_list(store) self.update_cmd_list(store)
self._save_config() self._save_config()
@ -387,14 +387,17 @@ class CustomCommandsMenu(plugin.MenuItem):
(store, iter) = selection.get_selected() (store, iter) = selection.get_selected()
if iter: if iter:
store.remove(iter) store.remove(iter)
return return
def on_edit(self, button, data): def on_edit(self, button, data):
treeview = data['treeview'] treeview = data['treeview']
selection = treeview.get_selection() selection = treeview.get_selection()
(store, iter) = selection.get_selected() (store, iter) = selection.get_selected()
if not iter: if not iter:
return return
(dialog,enabled,name,command) = self._create_command_dialog( (dialog,enabled,name,command) = self._create_command_dialog(
enabled_var = store.get_value(iter, CC_COL_ENABLED), enabled_var = store.get_value(iter, CC_COL_ENABLED),
name_var = store.get_value(iter, CC_COL_NAME), name_var = store.get_value(iter, CC_COL_NAME),