Use the widget attributes when populating the popup menu
This commit is contained in:
1 parent
622457ba33
commit
6236d0a4f7
3 files changed
+14
-7
No files matched your search
@@ -17,7 +17,7 @@ from tryton.gui.window.view_form.screen import Screen
|
||||
_ = gettext.gettext
|
||||
|
||||
|
||||
def populate(menu, model, record, title='', field=None, context=None):
|
||||
def populate(menu, model, record, title='', attributes=None, context=None):
|
||||
'''
|
||||
Fill menu with the actions of model for the record.
|
||||
If title is filled, the actions will be put in a submenu.
|
||||
@@ -30,6 +30,9 @@ def populate(menu, model, record, title='', field=None, context=None):
|
||||
elif record.id < 0:
|
||||
return
|
||||
|
||||
if attributes is None:
|
||||
attributes = {}
|
||||
|
||||
def load(record):
|
||||
if isinstance(record, int):
|
||||
screen = Screen(model, context=context)
|
||||
@@ -83,10 +86,10 @@ def populate(menu, model, record, title='', field=None, context=None):
|
||||
def edit(menuitem):
|
||||
with Window(hide_current=True, allow_similar=True):
|
||||
Window.create(model,
|
||||
view_ids=field.attrs.get('view_ids', '').split(','),
|
||||
view_ids=attributes.get('view_ids', '').split(','),
|
||||
res_id=id_(record),
|
||||
mode=['form'],
|
||||
name=field.attrs.get('string'),
|
||||
name=attributes.get('string'),
|
||||
context=context)
|
||||
|
||||
if title:
|
||||
@@ -102,7 +105,7 @@ def populate(menu, model, record, title='', field=None, context=None):
|
||||
|
||||
if len(action_menu):
|
||||
action_menu.append(Gtk.SeparatorMenuItem())
|
||||
if field:
|
||||
if attributes:
|
||||
edit_item = Gtk.MenuItem(label=_('Edit...'))
|
||||
edit_item.connect('activate', edit)
|
||||
action_menu.append(edit_item)
|
||||
|
||||
@@ -341,7 +341,7 @@ class Many2One(Widget):
|
||||
if self.has_target(value):
|
||||
populate(
|
||||
menu, self.get_model(), self.id_from_value(value),
|
||||
'', self.field, self.field.get_context(self.record))
|
||||
'', self.attrs, self.field.get_context(self.record))
|
||||
return True
|
||||
|
||||
def _set_completion(self):
|
||||
|
||||
@@ -1049,7 +1049,10 @@ class ViewTree(View):
|
||||
parent = parent.parent
|
||||
else:
|
||||
populate(menu, group.model_name, record)
|
||||
current_col = defaultdict(lambda: -1)
|
||||
for col in self.treeview.get_columns():
|
||||
if col.name:
|
||||
current_col[col.name] += 1
|
||||
if not col.get_visible() or not col.name:
|
||||
continue
|
||||
field = group.fields[col.name]
|
||||
@@ -1066,9 +1069,10 @@ class ViewTree(View):
|
||||
continue
|
||||
label = field.attrs['string']
|
||||
context = field.get_context(record)
|
||||
col_widget = self.widgets[col.name][current_col[col.name]]
|
||||
populate(
|
||||
menu, model, record_id, title=label, field=field,
|
||||
context=context)
|
||||
menu, model, record_id, title=label,
|
||||
attributes=col_widget.attributes, context=context)
|
||||
|
||||
if selection.count_selected_rows() == 1:
|
||||
group = self.group
|
||||
|
||||
Reference in new issue
Block a user