Skip to content

Commit

Permalink
boxes: Disable stream change during edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhirup-99 committed Jan 9, 2021
1 parent b1cd3ec commit fa8d43f
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(self, view: Any) -> None:
self.stream_id = None # type: Optional[int]
self.recipient_user_ids = [] # type: List[int]
self.msg_body_edit_enabled = True
self.in_edit_message_box = False
self.edit_caption = None # type: Optional[str]
self.FOCUS_CONTAINER_HEADER = 0
self.FOCUS_HEADER_BOX_RECIPIENT = 0
self.FOCUS_HEADER_BOX_STREAM = 0
Expand Down Expand Up @@ -84,7 +86,7 @@ def private_box_view(self, button: Any=None, email: str='',
self.focus_position = self.FOCUS_CONTAINER_MESSAGE

def stream_box_view(self, stream_id: int, caption: str='', title: str='',
) -> None:
is_in_edit: bool=False) -> None:
self.set_editor_mode()
self.stream_id = stream_id
self.recipient_user_ids = self.model.get_other_subscribers_in_stream(
Expand All @@ -96,17 +98,20 @@ def stream_box_view(self, stream_id: int, caption: str='', title: str='',
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box = ReadlineEdit(
caption="Stream: ",
edit_text=caption
)
self.stream_write_box.enable_autocomplete(
func=self._stream_box_autocomplete,
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box.set_completer_delims("")

if not is_in_edit:
self.stream_write_box = ReadlineEdit(
caption="Stream: ",
edit_text=caption
)
self.stream_write_box.enable_autocomplete(
func=self._stream_box_autocomplete,
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box.set_completer_delims("")
else:
self.stream_write_box = urwid.AttrMap(urwid.SelectableIcon(
"Stream: " + caption), None, 'selected')
self.title_write_box = ReadlineEdit(caption="Topic: ",
edit_text=title)
self.title_write_box.enable_autocomplete(
Expand All @@ -133,9 +138,11 @@ def stream_box_view(self, stream_id: int, caption: str='', title: str='',

def stream_box_edit_view(self, stream_id: int, caption: str='',
title: str='') -> None:
self.stream_box_view(stream_id, caption, title)
self.in_edit_message_box = True
self.edit_caption = caption
self.stream_box_view(stream_id=stream_id, caption=caption,
title=title, is_in_edit=True)
self.edit_mode_button = EditModeButton(self.model.controller, 20)

self.header_write_box.widget_list.append(self.edit_mode_button)

def _topic_box_autocomplete(self, text: str, state: Optional[int]
Expand Down Expand Up @@ -360,6 +367,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.keypress(size, 'esc')
elif is_command_key('GO_BACK', key):
self.msg_edit_id = None
self.in_edit_message_box = False
self.edit_caption = None
self.msg_body_edit_enabled = True
self.view.controller.exit_editor_mode()
self.main_view(False)
Expand Down Expand Up @@ -393,8 +402,11 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if self.focus_position == self.FOCUS_CONTAINER_HEADER:
if self.to_write_box is None:
if header.focus_col == self.FOCUS_HEADER_BOX_STREAM:
stream_name = (header[self.FOCUS_HEADER_BOX_STREAM]
.edit_text)
if not self.in_edit_message_box:
stream_name = (header[self.FOCUS_HEADER_BOX_STREAM]
.edit_text)
else:
stream_name = self.edit_caption
if not self.model.is_valid_stream(stream_name):
invalid_stream_error = (
'Invalid stream name.'
Expand Down Expand Up @@ -1338,6 +1350,8 @@ def valid_char(self, ch: str) -> bool:
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if ((is_command_key('ENTER', key) and self.get_edit_text() == '')
or is_command_key('GO_BACK', key)):
self.in_edit_message_box = False
self.edit_caption = None
self.panel_view.view.controller.exit_editor_mode()
self.reset_search_text()
self.panel_view.set_focus("body")
Expand Down

0 comments on commit fa8d43f

Please sign in to comment.