Remember path of last edited file in binary widget
Binary widget remember the path of the last edited file, so it can be selected by default by the open button. issue3606 review2861002
This commit is contained in:
1 parent
36891f23da
commit
1b71539f20
4 files changed
+36
-12
No files matched your search
@@ -433,7 +433,11 @@ def file_selection(title, filename='',
|
||||
win.set_icon(TRYTON_ICON)
|
||||
win.set_current_folder(CONFIG['client.default_path'])
|
||||
if filename:
|
||||
win.set_current_name(filename)
|
||||
if action in (gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||
gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER):
|
||||
win.set_current_name(filename)
|
||||
else:
|
||||
win.set_filename(filename)
|
||||
win.set_select_multiple(multi)
|
||||
win.set_default_response(gtk.RESPONSE_OK)
|
||||
if filters is not None:
|
||||
|
||||
@@ -5,7 +5,7 @@ import gettext
|
||||
import os
|
||||
import tempfile
|
||||
from tryton.common import common
|
||||
from tryton.common import file_selection, Tooltips, file_open
|
||||
from tryton.common import file_selection, Tooltips, file_open, slugify
|
||||
from interface import WidgetInterface
|
||||
|
||||
_ = gettext.gettext
|
||||
@@ -78,6 +78,8 @@ class Binary(WidgetInterface):
|
||||
self.tooltips.set_tip(self.but_remove, _('Clear'))
|
||||
self.widget.pack_start(self.but_remove, expand=False, fill=False)
|
||||
|
||||
self.last_open_file = None
|
||||
|
||||
self.tooltips.enable()
|
||||
|
||||
@property
|
||||
@@ -108,7 +110,12 @@ class Binary(WidgetInterface):
|
||||
return self.wid_size.grab_focus()
|
||||
|
||||
def sig_new(self, widget=None):
|
||||
filename = file_selection(_('Open...'))
|
||||
filename = ''
|
||||
if self.last_open_file:
|
||||
last_id, last_filename = self.last_open_file
|
||||
if last_id == self.record.id:
|
||||
filename = last_filename
|
||||
filename = file_selection(_('Open...'), filename=filename)
|
||||
if filename and self.field:
|
||||
self.field.set_client(self.record, open(filename, 'rb').read())
|
||||
if self.filename_field:
|
||||
@@ -119,10 +126,11 @@ class Binary(WidgetInterface):
|
||||
if not self.filename_field:
|
||||
return
|
||||
dtemp = tempfile.mkdtemp(prefix='tryton_')
|
||||
filename = self.filename_field.get(self.record).replace(
|
||||
os.sep, '_').replace(os.altsep or os.sep, '_')
|
||||
filename = self.filename_field.get(self.record)
|
||||
if not filename:
|
||||
return
|
||||
root, ext = os.path.splitext(filename)
|
||||
filename = ''.join([slugify(root), os.extsep, slugify(ext)])
|
||||
file_path = os.path.join(dtemp, filename)
|
||||
with open(file_path, 'wb') as fp:
|
||||
fp.write(self.field.get_data(self.record))
|
||||
@@ -130,6 +138,7 @@ class Binary(WidgetInterface):
|
||||
if type_:
|
||||
type_ = type_[1:]
|
||||
file_open(file_path, type_)
|
||||
self.last_open_file = (self.record.id, file_path)
|
||||
|
||||
def sig_save_as(self, widget=None):
|
||||
filename = ''
|
||||
|
||||
@@ -5,7 +5,7 @@ import glib
|
||||
import gettext
|
||||
import os
|
||||
import tempfile
|
||||
from tryton.common import file_selection, Tooltips, file_open
|
||||
from tryton.common import file_selection, Tooltips, file_open, slugify
|
||||
from tryton.config import PIXMAPS_DIR
|
||||
from interface import WidgetInterface
|
||||
import urllib
|
||||
@@ -141,8 +141,11 @@ class Image(WidgetInterface):
|
||||
if not self.filename_field:
|
||||
return
|
||||
dtemp = tempfile.mkdtemp(prefix='tryton_')
|
||||
filename = self.filename_field.get(self.record).replace(
|
||||
os.sep, '_').replace(os.altsep or os.sep, '_')
|
||||
filename = self.filename_field.get(self.record)
|
||||
if not filename:
|
||||
return
|
||||
root, ext = os.path.splitext(filename)
|
||||
filename = ''.join([slugify(root), os.extsep, slugify(ext)])
|
||||
file_path = os.path.join(dtemp, filename)
|
||||
with open(file_path, 'wb') as fp:
|
||||
fp.write(self.field.get_data(self.record))
|
||||
|
||||
@@ -18,7 +18,7 @@ from tryton.gui.window.win_form import WinForm
|
||||
from tryton.gui.window.view_form.screen import Screen
|
||||
import tryton.rpc as rpc
|
||||
from tryton.common import COLORS, node_attributes, \
|
||||
file_selection, file_open
|
||||
file_selection, file_open, slugify
|
||||
import tryton.common as common
|
||||
from tryton.common.cellrendererbutton import CellRendererButton
|
||||
from tryton.common.cellrendererdate import CellRendererDate
|
||||
@@ -606,6 +606,7 @@ class Binary(Char):
|
||||
self.renderer.connect('open', self.open_binary)
|
||||
self.renderer.connect('save', self.save_binary)
|
||||
self.renderer.connect('clear', self.clear_binary)
|
||||
self.last_open_file = None
|
||||
|
||||
def get_textual_value(self, record):
|
||||
pass
|
||||
@@ -638,8 +639,13 @@ class Binary(Char):
|
||||
cell.set_property('editable', not readonly)
|
||||
|
||||
def new_binary(self, renderer, path):
|
||||
filename = file_selection(_('Open...'))
|
||||
record, field = self._get_record_field(path)
|
||||
filename = ''
|
||||
if self.last_open_file:
|
||||
last_id, last_filename = self.last_open_file
|
||||
if last_id == record.id:
|
||||
filename = last_filename
|
||||
filename = file_selection(_('Open...'), filename=filename)
|
||||
if filename:
|
||||
field.set_client(record, open(filename, 'rb').read())
|
||||
if self.filename:
|
||||
@@ -652,10 +658,11 @@ class Binary(Char):
|
||||
dtemp = tempfile.mkdtemp(prefix='tryton_')
|
||||
record, field = self._get_record_field(path)
|
||||
filename_field = record.group.fields.get(self.filename)
|
||||
filename = filename_field.get(record).replace(
|
||||
os.sep, '_').replace(os.altsep or os.sep, '_')
|
||||
filename = filename_field.get(record)
|
||||
if not filename:
|
||||
return
|
||||
root, ext = os.path.splitext(filename)
|
||||
filename = ''.join([slugify(root), os.extsep, slugify(ext)])
|
||||
file_path = os.path.join(dtemp, filename)
|
||||
with open(file_path, 'wb') as fp:
|
||||
fp.write(field.get_data(record))
|
||||
@@ -663,6 +670,7 @@ class Binary(Char):
|
||||
if type_:
|
||||
type_ = type_[1:]
|
||||
file_open(file_path, type_)
|
||||
self.last_open_file = (record.id, file_path)
|
||||
|
||||
def save_binary(self, renderer, path):
|
||||
filename = ''
|
||||
|
||||
Reference in new issue
Block a user