mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 06:11:37 +03:00
Refactor empty filename handling in Save As to use a negative condition
This commit is contained in:
parent
a23eeaf1dd
commit
1f260aaeef
35
paint.py
35
paint.py
@ -1028,23 +1028,24 @@ class PaintApp(App):
|
|||||||
window.close()
|
window.close()
|
||||||
return
|
return
|
||||||
name = self.query_one("#save_as_dialog_filename_input", Input).value
|
name = self.query_one("#save_as_dialog_filename_input", Input).value
|
||||||
if name:
|
if not name:
|
||||||
if self.directory_tree_selected_path:
|
return
|
||||||
name = os.path.join(self.directory_tree_selected_path, name)
|
if self.directory_tree_selected_path:
|
||||||
def on_save_confirmed():
|
name = os.path.join(self.directory_tree_selected_path, name)
|
||||||
async def async_on_save_confirmed():
|
def on_save_confirmed():
|
||||||
self.filename = name
|
async def async_on_save_confirmed():
|
||||||
await self.save(from_save_as=True)
|
self.filename = name
|
||||||
window.close()
|
await self.save(from_save_as=True)
|
||||||
saved_future.set_result(None)
|
window.close()
|
||||||
# https://textual.textualize.io/blog/2023/02/11/the-heisenbug-lurking-in-your-async-code/
|
saved_future.set_result(None)
|
||||||
task = asyncio.create_task(async_on_save_confirmed())
|
# https://textual.textualize.io/blog/2023/02/11/the-heisenbug-lurking-in-your-async-code/
|
||||||
self.background_tasks.add(task)
|
task = asyncio.create_task(async_on_save_confirmed())
|
||||||
task.add_done_callback(self.background_tasks.discard)
|
self.background_tasks.add(task)
|
||||||
if os.path.exists(name):
|
task.add_done_callback(self.background_tasks.discard)
|
||||||
self.confirm_overwrite(name, on_save_confirmed)
|
if os.path.exists(name):
|
||||||
else:
|
self.confirm_overwrite(name, on_save_confirmed)
|
||||||
on_save_confirmed()
|
else:
|
||||||
|
on_save_confirmed()
|
||||||
|
|
||||||
window = DialogWindow(
|
window = DialogWindow(
|
||||||
id="save_as_dialog",
|
id="save_as_dialog",
|
||||||
|
Loading…
Reference in New Issue
Block a user