Add a few more default responses for confirmations

This commit is contained in:
Kovid Goyal 2021-12-06 17:41:03 +05:30
parent 8f688fb33b
commit 4af2526f54
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 6 deletions

View File

@ -1058,13 +1058,14 @@ class FileTransmission:
'The remote machine wants to read some files from this computer. Do you want to allow the transfer?' 'The remote machine wants to read some files from this computer. Do you want to allow the transfer?'
)], )],
window=window, custom_callback=partial(self.handle_receive_confirmation, asd_id), window=window, custom_callback=partial(self.handle_receive_confirmation, asd_id),
default_data={'response': 'n'}
) )
def handle_receive_confirmation(self, cmd_id: str, data: Dict[str, str], *a: Any) -> None: def handle_receive_confirmation(self, cmd_id: str, data: Dict[str, str], *a: Any) -> None:
asd = self.active_sends.get(cmd_id) asd = self.active_sends.get(cmd_id)
if asd is None: if asd is None:
return return
if data['response'] == 'y': if data.get('response') == 'y':
asd.accepted = True asd.accepted = True
else: else:
self.drop_send(asd.id) self.drop_send(asd.id)
@ -1089,13 +1090,14 @@ class FileTransmission:
'The remote machine wants to send some files to this computer. Do you want to allow the transfer?' 'The remote machine wants to send some files to this computer. Do you want to allow the transfer?'
)], )],
window=window, custom_callback=partial(self.handle_send_confirmation, ar_id), window=window, custom_callback=partial(self.handle_send_confirmation, ar_id),
default_data={'response': 'n'}
) )
def handle_send_confirmation(self, cmd_id: str, data: Dict[str, str], *a: Any) -> None: def handle_send_confirmation(self, cmd_id: str, data: Dict[str, str], *a: Any) -> None:
ar = self.active_receives.get(cmd_id) ar = self.active_receives.get(cmd_id)
if ar is None: if ar is None:
return return
if data['response'] == 'y': if data.get('response') == 'y':
ar.accepted = True ar.accepted = True
else: else:
self.drop_receive(ar.id) self.drop_receive(ar.id)

View File

@ -659,13 +659,14 @@ class Window:
'--choice=o:Open', '--choice=c:Copy to clipboard', '--choice=n;red:Nothing' '--choice=o:Open', '--choice=c:Copy to clipboard', '--choice=n;red:Nothing'
], ],
window=self, window=self,
custom_callback=partial(self.hyperlink_open_confirmed, url, cwd) custom_callback=partial(self.hyperlink_open_confirmed, url, cwd),
default_data={'response': ''}
) )
return return
get_boss().open_url(url, cwd=cwd) get_boss().open_url(url, cwd=cwd)
def hyperlink_open_confirmed(self, url: str, cwd: Optional[str], data: Dict[str, Any], *a: Any) -> None: def hyperlink_open_confirmed(self, url: str, cwd: Optional[str], data: Dict[str, Any], *a: Any) -> None:
q = data['response'] q = data.get('response', '')
if q == 'o': if q == 'o':
get_boss().open_url(url, cwd=cwd) get_boss().open_url(url, cwd=cwd)
elif q == 'c': elif q == 'c':
@ -912,14 +913,15 @@ class Window:
'A program running in this window wants to read from the system clipboard.' 'A program running in this window wants to read from the system clipboard.'
' Allow it do so, once?')], ' Allow it do so, once?')],
window=self, window=self,
custom_callback=self.handle_clipboard_confirmation custom_callback=self.handle_clipboard_confirmation,
default_data={'response': 'n'}
) )
def handle_clipboard_confirmation(self, data: Dict[str, Any], *a: Any) -> None: def handle_clipboard_confirmation(self, data: Dict[str, Any], *a: Any) -> None:
try: try:
loc = 'p' if self.current_clipboard_read_ask else 'c' loc = 'p' if self.current_clipboard_read_ask else 'c'
response = '' response = ''
if data['response'] == 'y': if data.get('response') == 'y':
response = get_primary_selection() if self.current_clipboard_read_ask else get_clipboard_string() response = get_primary_selection() if self.current_clipboard_read_ask else get_clipboard_string()
self.send_osc52(loc, response) self.send_osc52(loc, response)
finally: finally: