Code: Select all
; - Window Constants
Enumeration 1
#Window_MenuMaster
EndEnumeration
#WindowIndex = #PB_Compiler_EnumerationValue
; - Gadget Constants
Enumeration 1
; Window_MenuMaster
#MenuBar_MenuMaster_Files
#MenuBar_MenuMaster_OpenRecipes
#Gadget_MenuMaster_cRecipes
#Gadget_MenuMaster_Area34
#Gadget_MenuMaster_Recipes
#Gadget_MenuMaster_cVersion
#Gadget_MenuMaster_Area37
#Gadget_MenuMaster_cTitle
#Gadget_MenuMaster_Area39
#Gadget_MenuMaster_lVersion
#Gadget_MenuMaster_Version
#Gadget_MenuMaster_lTitle
#Gadget_MenuMaster_Title
#Gadget_MenuMaster_lCategories
#Gadget_MenuMaster_Categories
#Gadget_MenuMaster_lServes
#Gadget_MenuMaster_Serves
#Gadget_MenuMaster_cIngredients
#Gadget_MenuMaster_Area49
#Gadget_MenuMaster_Ingredients
#Gadget_MenuMaster_cInstructions
#Gadget_MenuMaster_Area52
#Gadget_MenuMaster_Instructions
#Gadget_MenuMaster_cControl
#Gadget_MenuMaster_Area55
#Gadget_MenuMaster_Save
#Gadget_MenuMaster_Export
#Gadget_MenuMaster_Import
#Gadget_MenuMaster_Print
#Gadget_MenuMaster_Help
#Gadget_MenuMaster_Search
#Gadget_MenuMaster_Exit
#Gadget_MenuMaster_lControl1
#Gadget_MenuMaster_lControl2
#Gadget_MenuMaster_lControl3
EndEnumeration
#GadgetIndex = #PB_Compiler_EnumerationValue
; - MenuBar Constants
Enumeration 1
#MenuBar_MenuMaster
EndEnumeration
#MenuBarIndex = #PB_Compiler_EnumerationValue
; - Image Constants
Enumeration 1
#Image_MenuMaster_Save
#Image_MenuMaster_Export
#Image_MenuMaster_Import
#Image_MenuMaster_Print
#Image_MenuMaster_Help
#Image_MenuMaster_Exit
EndEnumeration
#ImageIndex = #PB_Compiler_EnumerationValue
; - Load Images
CatchImage(#Image_MenuMaster_Save, ?_OPT_MenuMaster_Save)
CatchImage(#Image_MenuMaster_Export, ?_OPT_MenuMaster_Export)
CatchImage(#Image_MenuMaster_Import, ?_OPT_MenuMaster_Import)
CatchImage(#Image_MenuMaster_Print, ?_OPT_MenuMaster_Print)
CatchImage(#Image_MenuMaster_Help, ?_OPT_MenuMaster_Help)
CatchImage(#Image_MenuMaster_Exit, ?_OPT_MenuMaster_Exit)
;
DataSection
_OPT_MenuMaster_Save : IncludeBinary "Images\save32x32.ico"
_OPT_MenuMaster_Export : IncludeBinary "Images\export32x32.ico"
_OPT_MenuMaster_Import : IncludeBinary "Images\import32x32.ico"
_OPT_MenuMaster_Print : IncludeBinary "Images\printer32x32.ico"
_OPT_MenuMaster_Help : IncludeBinary "Images\help32x32.ico"
_OPT_MenuMaster_Exit : IncludeBinary "Images\exit32x32.ico"
EndDataSection
;
Procedure.l Window_MenuMaster()
If OpenWindow(#Window_MenuMaster,57,56,845,640,"Menu Master Quickview",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowColor(#Window_MenuMaster,$A2A2A2)
CreateMenu(#MenuBar_MenuMaster,WindowID(#Window_MenuMaster))
MenuTitle("Files")
MenuItem(#MenuBar_MenuMaster_OpenRecipes,"Open recipes")
ContainerGadget(#Gadget_MenuMaster_cRecipes,5,5,210,535,#PB_Container_Flat|#PB_Container_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_cRecipes,#PB_Gadget_BackColor,$BFBFBF)
ListIconGadget(#Gadget_MenuMaster_Recipes,5,5,200,522,"Recipe names",194,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
SetGadgetColor(#Gadget_MenuMaster_Recipes,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Recipes,LoadFont(#Gadget_MenuMaster_Recipes,"Comic Sans MS",10,0))
CloseGadgetList()
ContainerGadget(#Gadget_MenuMaster_cVersion,220,5,620,45,#PB_Container_Flat|#PB_Container_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_cVersion,#PB_Gadget_BackColor,$BFBFBF)
TextGadget(#Gadget_MenuMaster_lVersion,10,15,150,20,"MealMaster version")
SetGadgetColor(#Gadget_MenuMaster_lVersion,#PB_Gadget_BackColor,$BFBFBF)
SetGadgetFont(#Gadget_MenuMaster_lVersion,LoadFont(#Gadget_MenuMaster_lVersion,"Comic Sans MS",10,0))
StringGadget(#Gadget_MenuMaster_Version,160,10,100,25,"",#PB_String_ReadOnly|#PB_String_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_Version,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Version,LoadFont(#Gadget_MenuMaster_Version,"Comic Sans MS",10,0))
CloseGadgetList()
ContainerGadget(#Gadget_MenuMaster_cTitle,220,55,620,105,#PB_Container_Flat|#PB_Container_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_cTitle,#PB_Gadget_BackColor,$BFBFBF)
TextGadget(#Gadget_MenuMaster_lTitle,10,15,150,20,"Recipe title")
SetGadgetColor(#Gadget_MenuMaster_lTitle,#PB_Gadget_BackColor,$BFBFBF)
SetGadgetFont(#Gadget_MenuMaster_lTitle,LoadFont(#Gadget_MenuMaster_lTitle,"Comic Sans MS",10,0))
StringGadget(#Gadget_MenuMaster_Title,160,10,450,25,"",#PB_String_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_Title,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Title,LoadFont(#Gadget_MenuMaster_Title,"Comic Sans MS",10,0))
TextGadget(#Gadget_MenuMaster_lCategories,10,45,150,20,"Categories")
SetGadgetColor(#Gadget_MenuMaster_lCategories,#PB_Gadget_BackColor,$BFBFBF)
SetGadgetFont(#Gadget_MenuMaster_lCategories,LoadFont(#Gadget_MenuMaster_lCategories,"Comic Sans MS",10,0))
StringGadget(#Gadget_MenuMaster_Categories,160,40,450,25,"",#PB_String_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_Categories,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Categories,LoadFont(#Gadget_MenuMaster_Categories,"Comic Sans MS",10,0))
TextGadget(#Gadget_MenuMaster_lServes,10,75,150,20,"No of serves")
SetGadgetColor(#Gadget_MenuMaster_lServes,#PB_Gadget_BackColor,$BFBFBF)
SetGadgetFont(#Gadget_MenuMaster_lServes,LoadFont(#Gadget_MenuMaster_lServes,"Comic Sans MS",10,0))
StringGadget(#Gadget_MenuMaster_Serves,160,70,125,25,"",#PB_String_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_Serves,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Serves,LoadFont(#Gadget_MenuMaster_Serves,"Comic Sans MS",10,0))
CloseGadgetList()
ContainerGadget(#Gadget_MenuMaster_cIngredients,220,165,160,375,#PB_Container_Flat|#PB_Container_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_cIngredients,#PB_Gadget_BackColor,$BFBFBF)
ListViewGadget(#Gadget_MenuMaster_Ingredients,5,5,150,365)
SetGadgetColor(#Gadget_MenuMaster_Ingredients,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Ingredients,LoadFont(#Gadget_MenuMaster_Ingredients,"Comic Sans MS",10,0))
CloseGadgetList()
ContainerGadget(#Gadget_MenuMaster_cInstructions,385,165,455,375,#PB_Container_Flat|#PB_Container_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_cInstructions,#PB_Gadget_BackColor,$BFBFBF)
EditorGadget(#Gadget_MenuMaster_Instructions,5,5,445,365)
SetGadgetColor(#Gadget_MenuMaster_Instructions,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Instructions,LoadFont(#Gadget_MenuMaster_Instructions,"Comic Sans MS",10,0))
CloseGadgetList()
ContainerGadget(#Gadget_MenuMaster_cControl,5,545,835,70,#PB_Container_Flat|#PB_Container_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_cControl,#PB_Gadget_BackColor,$BFBFBF)
ButtonImageGadget(#Gadget_MenuMaster_Save,5,5,45,45,ImageID(#Image_MenuMaster_Save))
ButtonImageGadget(#Gadget_MenuMaster_Export,50,5,45,45,ImageID(#Image_MenuMaster_Export))
ButtonImageGadget(#Gadget_MenuMaster_Import,95,5,45,45,ImageID(#Image_MenuMaster_Import))
ButtonImageGadget(#Gadget_MenuMaster_Print,140,5,45,45,ImageID(#Image_MenuMaster_Print))
ButtonImageGadget(#Gadget_MenuMaster_Help,185,5,45,45,ImageID(#Image_MenuMaster_Help))
StringGadget(#Gadget_MenuMaster_Search,535,25,225,25,"",#PB_String_BorderLess)
SetGadgetColor(#Gadget_MenuMaster_Search,#PB_Gadget_BackColor,$DBDBDB)
SetGadgetFont(#Gadget_MenuMaster_Search,LoadFont(#Gadget_MenuMaster_Search,"Comic Sans MS",10,0))
ButtonImageGadget(#Gadget_MenuMaster_Exit,780,5,45,45,ImageID(#Image_MenuMaster_Exit))
TextGadget(#Gadget_MenuMaster_lControl1,5,50,225,15," Save Export Import Print Help")
SetGadgetColor(#Gadget_MenuMaster_lControl1,#PB_Gadget_BackColor,$BFBFBF)
SetGadgetFont(#Gadget_MenuMaster_lControl1,LoadFont(#Gadget_MenuMaster_lControl1,"Comic Sans MS",8,0))
TextGadget(#Gadget_MenuMaster_lControl2,535,50,225,15,"Search for a recipe here...")
SetGadgetColor(#Gadget_MenuMaster_lControl2,#PB_Gadget_BackColor,$BFBFBF)
SetGadgetFont(#Gadget_MenuMaster_lControl2,LoadFont(#Gadget_MenuMaster_lControl2,"Comic Sans MS",8,0))
TextGadget(#Gadget_MenuMaster_lControl3,780,50,45,15,"Exit",#PB_Text_Center)
SetGadgetColor(#Gadget_MenuMaster_lControl3,#PB_Gadget_BackColor,$BFBFBF)
SetGadgetFont(#Gadget_MenuMaster_lControl3,LoadFont(#Gadget_MenuMaster_lControl3,"Comic Sans MS",8,0))
CloseGadgetList()
HideWindow(#Window_MenuMaster,0)
ProcedureReturn WindowID(#Window_MenuMaster)
EndIf
EndProcedure
;
Enumeration
; ElectroChrisso's variables
#RecipeVersion
#RecipeNone
#RecipeCategory
#RecipeYield
#RecipeIngredients
#RecipeMethod
EndEnumeration
;
Structure ProgramData
RecipeFileName.s
RecipeFileHandle.i
QuitValue.i
EndStructure
; Set the system to use SQLite database handling
UseSQLiteDatabase()
;
Global Program.ProgramData
;
Declare DisplayRecipeTitles()
Declare DisplayRecipeDetails(FilePos.q)
Declare.i GetRecipeDetails(FilePos.q)
;
Procedure DisplayRecipeTitles()
Protected FilePtr.q, i.i
Program\RecipeFileName = OpenFileRequester("Choose a Meal-Master file", "", "MealMasterFile|*.mmf|TextFile|*.txt|All|*.*", 1)
If Program\RecipeFileName <> ""
Program\RecipeFileHandle = ReadFile(#PB_Any, Program\RecipeFileName)
If Program\RecipeFileHandle
ClearGadgetItems(#Gadget_MenuMaster_Recipes)
SetGadgetText(#Gadget_MenuMaster_Recipes, "")
i = 0
Repeat
FilePtr = Loc(Program\RecipeFileHandle)
TitleString.s = ReadString(Program\RecipeFileHandle)
If FindString(TitleString, "Meal-Master", 10)
Repeat
TitleString.s = ReadString(Program\RecipeFileHandle)
Until Left(TitleString.s, 12) = " Title:"
AddGadgetItem(#Gadget_MenuMaster_Recipes, i, Mid(TitleString.s, 13))
SetGadgetItemData(#Gadget_MenuMaster_Recipes, i, FilePtr)
i + 1
EndIf
Until Eof(Program\RecipeFileHandle)
CloseFile(Program\RecipeFileHandle)
EndIf
EndIf
EndProcedure
;
Procedure DisplayRecipeDetails(FilePos.q)
If Program\RecipeFileName <> ""
GetRecipeDetails(FilePos.q)
EndIf
EndProcedure
;
Procedure.i GetRecipeDetails(FilePos.q)
Protected.i Result, File, State, Pos, Count, i
Protected Line.s, Text.s, Version.s, Title.s, Category.s, Yield.s, Ingredients.s, Method.s
Program\RecipeFileHandle = ReadFile(#PB_Any, Program\RecipeFileName)
If Program\RecipeFileHandle
FileSeek(Program\RecipeFileHandle, FilePos)
State = #RecipeNone
While FindTitle.s <> "MMMMM"
If FindTitle.s <> "MMMMM"
Line.s = ReadString(Program\RecipeFileHandle)
Select State
Case #RecipeNone
Pos = FindString(Line.s, "Meal-Master")
If Pos
Version.s = Trim(Mid(Line.s, Pos + 11));:Debug Line.s
For i = 1 To Len(Version)
If ValF(Mid(Version, i)) > 0
Version = Mid(Version, i)
Break
EndIf
Next i
Title.s = ""
Category.s = ""
Yield.s = ""
Ingredients.s = ""
Method.s = ""
State = #RecipeVersion
EndIf
Case #RecipeVersion
Pos = FindString(Line.s, "Title:")
If Pos
Title.s = Trim(Mid(Line.s, Pos + 7))
State = #RecipeCategory
EndIf
Case #RecipeCategory
Pos = FindString(Line.s, "Categories:")
If Pos
Category.s = Trim(Mid(Line.s, Pos + 12))
State = #RecipeYield
EndIf
Case #RecipeYield
Count = Len(Line.s)
For i = 1 To Count
If Val(Mid(Line.s, i)) > 0
Yield.s = Trim(Mid(Line.s, i))
State = #RecipeIngredients
Break
EndIf
Next i
Case #RecipeIngredients
If Trim(Line) <> ""
If Val(Trim(Line.s)) > 0
Line.s = Trim(Line.s)
Pos = FindString(Line.s, " ")
If Pos
Ingredients.s + Trim(Left(Line.s, Pos)) + " "
Ingredients.s + Trim(Mid(Line.s, Pos)) + #LF$
Else
Ingredients.s + Trim(Line.s) + #LF$
EndIf
Else
If Trim(Left(Line.s, 3)) <> ""
If Left(Line.s, 5) = "MMMMM"
Ingredients.s + Trim(Mid(Line.s, 6), "-") + #LF$
Else
Method.s = Line.s + #LF$
State = #RecipeMethod
EndIf
Else
Line.s = Trim(Line.s)
If Left(Line.s, 1) = "-"
Ingredients.s = Left(Ingredients.s, Len(Ingredients.s) - 2) + " " + Trim(Mid(Line.s, Pos), "-") + #LF$
Else
Ingredients.s + Trim(Mid(Line.s, Pos), "-") + #LF$
EndIf
EndIf
EndIf
EndIf
Case #RecipeMethod
If Len(Line.s) = 5 And (Line.s = "MMMMM" Or Line.s = "-----")
ClearGadgetItems(#Gadget_MenuMaster_Ingredients)
SetGadgetText(#Gadget_MenuMaster_Version , Version.s)
SetGadgetText(#Gadget_MenuMaster_Title , Title.s)
SetGadgetText(#Gadget_MenuMaster_Categories , Category.s )
For ShowIngredients.i = 1 To CountString(Ingredients.s, #LF$)
AddGadgetItem(#Gadget_MenuMaster_Ingredients, -1, StringField(Ingredients.s, ShowIngredients.i, #LF$))
Next ShowIngredients.i
SetGadgetText(#Gadget_MenuMaster_Serves , Yield.s)
SetGadgetText(#Gadget_MenuMaster_Instructions , Method.s)
State = #RecipeNone
CloseFile(Program\RecipeFileHandle)
ProcedureReturn
Else
If Len(Line.s) <> 0
Method.s + Line.s + #LF$
EndIf
EndIf
EndSelect
EndIf
Wend
CloseFile(Program\RecipeFileHandle)
EndIf
EndProcedure
;
If Window_MenuMaster()
Program\QuitValue = 0
Repeat
EventID = WaitWindowEvent()
MenuID = EventMenu()
GadgetID = EventGadget()
WindowID = EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select WindowID
Case #Window_MenuMaster : Program\QuitValue = 1
EndSelect
Case #PB_Event_Menu
Select MenuID
Case #MenuBar_MenuMaster_OpenRecipes : DisplayRecipeTitles()
EndSelect
Case #PB_Event_Gadget
Select GadgetID
Case #Gadget_MenuMaster_Recipes
Select EventType()
Case #PB_EventType_Change : DisplayRecipeDetails(GetGadgetItemData(#Gadget_MenuMaster_Recipes, GetGadgetState(#Gadget_MenuMaster_Recipes)))
EndSelect
Case #Gadget_MenuMaster_Save :
Case #Gadget_MenuMaster_Export :
Case #Gadget_MenuMaster_Import :
Case #Gadget_MenuMaster_Print :
Case #Gadget_MenuMaster_Help :
Case #Gadget_MenuMaster_Search :
Case #Gadget_MenuMaster_Exit :
EndSelect
EndSelect
Until Program\QuitValue
CloseWindow(#Window_MenuMaster)
EndIf
End
It shows now the correct recipe, not the one behind.
But it was only a 'quick shot'.
Many things still todo.