Merge pull request #561 from tunz/overwrite

Check overwrite, when save to file instaed of clipboard
This commit is contained in:
Maximilian Hils 2015-04-23 11:35:02 +02:00
commit 1c5277b21f
1 changed files with 20 additions and 2 deletions

View File

@ -196,18 +196,36 @@ def raw_format_flow(f, focus, extended, padding):
def save_data(path, data, master, state): def save_data(path, data, master, state):
if not path: if not path:
return return
path = os.path.expanduser(path)
try: try:
with file(path, "wb") as f: with file(path, "wb") as f:
f.write(data) f.write(data)
except IOError, v: except IOError, v:
signals.status_message.send(message=v.strerror) signals.status_message.send(message=v.strerror)
def ask_save_overwite(path, data, master, state):
if not path:
return
path = os.path.expanduser(path)
if os.path.exists(path):
def save_overwite(k):
if k == "y":
save_data(path, data, master, state)
signals.status_prompt_onekey.send(
prompt = "'"+path+"' already exists. Overwite?",
keys = (
("yes", "y"),
("no", "n"),
),
callback = save_overwite
)
else:
save_data(path, data, master, state)
def ask_save_path(prompt, data, master, state): def ask_save_path(prompt, data, master, state):
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = prompt, prompt = prompt,
callback = save_data, callback = ask_save_overwite,
args = (data, master, state) args = (data, master, state)
) )