add edit name
This commit is contained in:
@@ -5,21 +5,25 @@ from ..base import View
|
||||
from ..button_interface import ButtonInterface
|
||||
|
||||
from .recipe_manager import RecipeManager
|
||||
from .recipe import Recipe, Step
|
||||
from .recipe import Recipe
|
||||
|
||||
class EditRecipe(View, ButtonInterface):
|
||||
def __init__(self, parent, im_size, center,
|
||||
recipe_manager: RecipeManager,
|
||||
edit_step_command,
|
||||
deactivate_command,
|
||||
recipe: Recipe = None):
|
||||
recipe_id: int = None):
|
||||
self.deactivate_command = deactivate_command
|
||||
self.recipe_manager = recipe_manager
|
||||
self.recipe = recipe
|
||||
self.recipe_id = recipe_id
|
||||
self.edit_step_command = edit_step_command
|
||||
if recipe is None:
|
||||
self.is_add_form = recipe_id is None
|
||||
if recipe_id is None:
|
||||
self.recipe = Recipe("New", [])
|
||||
|
||||
self.recipe_manager.tmp_recipe = self.recipe
|
||||
else:
|
||||
self.recipe = recipe_manager.get_recipe(recipe_id)
|
||||
|
||||
self.confirm_view = False
|
||||
self.selected_field = 0 # 0: name, 1+: steps
|
||||
|
||||
@@ -94,14 +98,18 @@ class EditRecipe(View, ButtonInterface):
|
||||
pass
|
||||
else:
|
||||
# edit name
|
||||
self.edit_step_command(self.recipe, self.selected_field)
|
||||
self.edit_step_command(self.recipe_id, self.selected_field)
|
||||
|
||||
def right_press(self):
|
||||
self.selected_field = (self.selected_field + 1) % (len(self.recipe.steps) + 3)
|
||||
|
||||
def right_long_press(self):
|
||||
# save
|
||||
self.recipe_manager.add_recipe(self.recipe)
|
||||
if self.is_add_form:
|
||||
self.recipe_manager.add_recipe(self.recipe)
|
||||
else:
|
||||
self.recipe_manager.update_recipe(self.recipe_id, self.recipe)
|
||||
# if view is in edit mode, the recipe is already updated (by reference)
|
||||
self.deactivate_command()
|
||||
|
||||
def has_button(self) -> Tuple[bool, bool, bool, bool]:
|
||||
|
||||
Reference in New Issue
Block a user