Skip to content

Commit

Permalink
redundant code in the text tool: the abstract one handles that! #357
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Jan 31, 2023
1 parent dbb367f commit abbdfe9
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/tools/classic_tools/tool_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class ToolText(AbstractClassicTool):

def __init__(self, window, **kwargs):
super().__init__('text', _("Text"), 'tool-text-symbolic', window)

self._should_cancel = False
self._last_click_btn = 1

# There are several types of possible interactions with the canvas,
# depending on where the pointer is during the press event.
Expand Down Expand Up @@ -118,10 +116,6 @@ def on_options_changed(self):

############################################################################

def on_tool_selected(self):
super().on_tool_selected()
self._last_click_btn = 1

def on_tool_unselected(self):
self.set_action_sensitivity('paste', True)
self.set_action_sensitivity('select_all', True)
Expand All @@ -135,7 +129,9 @@ def give_back_control(self, preserve_selection, next_tool=None):

def force_text_tool(self, string):
self.select_flowbox_child()
self.set_common_values(self._last_click_btn, 100, 100)
# XXX déterminer des coordonnées qui fassent sens quel que soit l'état
# du scrolling et du zoom
self.set_common_values(self._last_btn, 100, 100)
self._open_popover_at(100, 100)
self._set_string(string)

Expand All @@ -147,8 +143,7 @@ def _set_string(self, string):
############################################################################

def on_press_on_area(self, event, surface, event_x, event_y):
self._last_click_btn = event.button
self.set_common_values(self._last_click_btn, event_x, event_y)
self.set_common_values(event.button, event_x, event_y)
self._pointer_target = 'input'
if not self._has_current_text():
return
Expand All @@ -158,6 +153,8 @@ def on_press_on_area(self, event, surface, event_x, event_y):
return
elif not should_move:
self._pointer_target = 'apply'
# FIXME avoir appelé set_common_values alors qu'on va juste apply me
# semble être une grosse erreur d'UX
return

self._pointer_target = 'move'
Expand All @@ -171,11 +168,10 @@ def on_motion_on_area(self, event, surface, event_x, event_y, render=True):
self._preview_text()

def on_release_on_area(self, event, surface, event_x, event_y):
self._last_click_btn = event.button
self._should_cancel = True
if 'input' == self._pointer_target:
if not self._has_current_text():
self.set_common_values(self._last_click_btn, event_x, event_y)
self.set_common_values(event.button, event_x, event_y)
self._text_x = self._text_x0 = event_x
self._text_y = self._text_y0 = event_y
self._open_popover_at(event.x, event.y)
Expand Down Expand Up @@ -209,7 +205,7 @@ def _hide_entry(self):
self._popover.popdown()

def _force_refresh(self, *args):
self.set_common_values(self._last_click_btn, self._text_x, self._text_y)
self.set_common_values(self._last_btn, self._text_x, self._text_y)
self._preview_text()

def _on_insert_text(self, *args):
Expand Down

0 comments on commit abbdfe9

Please sign in to comment.