Merge edit and translate button for HTML widget

Closes #13383
This commit is contained in:
Cédric Krier
2024-07-02 15:58:15 +02:00
parent 5b23e66b10
commit 23d3ce2edf
2 changed files with 16 additions and 14 deletions
+8 -10
View File
@@ -4853,15 +4853,9 @@ function eval_pyson(value){
'rel': 'noreferrer noopener',
}).text(attributes.string).appendTo(this.el);
if (attributes.translate) {
var button = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
'type': 'button',
'aria-label': Sao.i18n.gettext('Translate'),
'title': Sao.i18n.gettext("Translate"),
}).appendTo(this.el);
button.append(
this.button.prepend(
Sao.common.ICONFACTORY.get_icon_img('tryton-translate'));
button.click(this.translate.bind(this));
this.button.click(this.translate.bind(this));
}
},
uri: function(language) {
@@ -4881,7 +4875,9 @@ function eval_pyson(value){
},
display: function() {
Sao.View.Form.HTML._super.display.call(this);
this.button.attr('href', this.uri());
if (!this.attributes.translate) {
this.button.attr('href', this.uri());
}
},
set_readonly: function(readonly) {
Sao.View.Form.HTML._super.set_readonly.call(this, readonly);
@@ -4897,7 +4893,9 @@ function eval_pyson(value){
for (const language of languages) {
options[language.name] = language.code;
}
Sao.common.selection(Sao.i18n.gettext("Choose a language"), options)
Sao.common.selection(
Sao.i18n.gettext("Choose a language"), options, false,
Sao.i18n.getlang())
.done(language => {
window.open(this.uri(language), '_blank', 'noreferrer,noopener');
});
@@ -130,8 +130,10 @@ class HTML(Widget, TranslateMixin):
self.button, expand=False, fill=False, padding=0)
if attrs.get('translate'):
self.widget.pack_start(
self.translate_button(), expand=False, fill=False, padding=0)
self.button.set_image(common.IconFactory.get_image(
'tryton-translate', Gtk.IconSize.SMALL_TOOLBAR))
self.button.set_always_show_image(True)
self.button.connect('clicked', self.translate)
def uri(self, language=None):
if not self.record or self.record.id < 0 or CONNECTION.url is None:
@@ -149,7 +151,8 @@ class HTML(Widget, TranslateMixin):
def display(self):
super().display()
self.button.set_uri(self.uri())
if self.attrs.get('translate'):
self.button.set_uri(self.uri())
def _readonly_set(self, value):
super()._readonly_set(value)
@@ -158,6 +161,7 @@ class HTML(Widget, TranslateMixin):
def translate_dialog(self, languages):
languages = {l['name']: l['code'] for l in languages}
result = selection(_('Choose a language'), languages)
result = selection(
_('Choose a language'), languages, default=CONFIG['client.lang'])
if result:
webbrowser.open(self.uri(language=result[1]), new=2)