Casual recipe pdf finder/lister (needs work)

Share your advanced PureBasic knowledge/code with the community.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Casual recipe pdf finder/lister (needs work)

Post by Fangbeast »

I needed a simple lister & searcher for my wife's scanned pdf recipe collection and came up with this. Nothing special, needs a few buttons of your own (lazy sods) and needs improving but it works for what I need.

Somehow, srod's underpants made it in there again, don't know why :):):)

If anyone can make some nice improvements, I'd be happy with that.

Code: Select all

; Visual designer generated

;- Required Image Decoders

UsePNGImageDecoder()

Define EventID, MenuID, GadgetID, WindowID

;- Window Constants

Enumeration 1
  #Window_Recipeview
EndEnumeration

#WindowIndex = #PB_Compiler_EnumerationValue

;- Gadget Constants

Enumeration 1
  ; Window_Recipeview
  
  #Gadget_Recipeview_Recipenames
  #Gadget_Recipeview_Recipeview
  #Gadget_Recipeview_cControl
  #Gadget_Recipeview_Getdirectory
  #Gadget_Recipeview_cStatusbar
  #Gadget_Recipeview_sStatus
  #Gadget_Recipeview_Printrecipe
  #Gadget_Recipeview_Showhelp
  #Gadget_Recipeview_Recipedirectory
  #Gadget_Recipeview_Recipecategory
  #Gadget_Recipeview_Recipesubcategory
  #Gadget_Recipeview_Recipesearch
  #Gadget_Recipeview_Exitprogram
  #Gadget_Recipeview_sMessage
  #Gadget_Recipeview_sCurrent
  #Gadget_Recipeview_sRecords
EndEnumeration

#GadgetIndex = #PB_Compiler_EnumerationValue

;- Image Constants

Enumeration 1
  #Image_Recipeview_Getdirectory
  #Image_Recipeview_Printrecipe
  #Image_Recipeview_Showhelp
  #Image_Recipeview_Exitprogram
EndEnumeration

#ImageIndex = #PB_Compiler_EnumerationValue

;- Load Images

CatchImage(#Image_Recipeview_Getdirectory,  ?_OPT_Recipeview_Getdirectory)
CatchImage(#Image_Recipeview_Printrecipe,   ?_OPT_Recipeview_Printrecipe)
CatchImage(#Image_Recipeview_Showhelp,      ?_OPT_Recipeview_Showhelp)
CatchImage(#Image_Recipeview_Exitprogram,   ?_OPT_Recipeview_Exitprogram)

; Data section

DataSection
  _OPT_Recipeview_Getdirectory: : IncludeBinary "Images\_54x54\Open.Png"
  _OPT_Recipeview_Printrecipe:  : IncludeBinary "Images\_54x54\Print.png"
  _OPT_Recipeview_Showhelp:     : IncludeBinary "Images\_54x54\Help.Png"
  _OPT_Recipeview_Exitprogram:  : IncludeBinary "Images\_54x54\Exit.png"
EndDataSection

; Encapsulated window code

Procedure.i Window_Recipeview()
  If OpenWindow(#Window_Recipeview, 59, 68, 1195, 785, "Simple recipe finder", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
      ListIconGadget(#Gadget_Recipeview_Recipenames, 5, 5, 290, 670, "Recipe name", 260, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
        AddGadgetColumn(#Gadget_Recipeview_Recipenames, 1, "Directory", 0)
        SetGadgetFont(#Gadget_Recipeview_Recipenames, LoadFont(#Gadget_Recipeview_Recipenames, "Segoe Print", 10, 0))
      WebGadget(#Gadget_Recipeview_Recipeview, 300, 5, 890, 670, "")
      ContainerGadget(#Gadget_Recipeview_cControl, 5, 680, 1185, 70, #PB_Container_BorderLess)
      ImageGadget(#Gadget_Recipeview_Getdirectory, 5, 5, 54, 54, ImageID(#Image_Recipeview_Getdirectory))
      ImageGadget(#Gadget_Recipeview_Printrecipe, 65, 5, 54, 54, ImageID(#Image_Recipeview_Printrecipe))
      ImageGadget(#Gadget_Recipeview_Showhelp, 125, 5, 54, 54, ImageID(#Image_Recipeview_Showhelp))
      StringGadget(#Gadget_Recipeview_Recipedirectory, 295, 5, 815, 25, "", #PB_String_ReadOnly|#PB_String_BorderLess)
        SetGadgetColor(#Gadget_Recipeview_Recipedirectory, #PB_Gadget_BackColor, $D8D8D8)
        SetGadgetFont(#Gadget_Recipeview_Recipedirectory, LoadFont(#Gadget_Recipeview_Recipedirectory, "Segoe Print", 10, 0))
      StringGadget(#Gadget_Recipeview_Recipecategory, 295, 35, 255, 25, "", #PB_String_ReadOnly|#PB_String_BorderLess)
        SetGadgetColor(#Gadget_Recipeview_Recipecategory, #PB_Gadget_BackColor, $D8D8D8)
        SetGadgetFont(#Gadget_Recipeview_Recipecategory, LoadFont(#Gadget_Recipeview_Recipecategory, "Segoe Print", 10, 0))
      StringGadget(#Gadget_Recipeview_Recipesubcategory, 560, 35, 255, 25, "", #PB_String_ReadOnly|#PB_String_BorderLess)
        SetGadgetColor(#Gadget_Recipeview_Recipesubcategory, #PB_Gadget_BackColor, $D8D8D8)
        SetGadgetFont(#Gadget_Recipeview_Recipesubcategory, LoadFont(#Gadget_Recipeview_Recipesubcategory, "Segoe Print", 10, 0))
      StringGadget(#Gadget_Recipeview_Recipesearch, 825, 35, 285, 25, "", #PB_String_BorderLess)
        SetGadgetFont(#Gadget_Recipeview_Recipesearch, LoadFont(#Gadget_Recipeview_Recipesearch, "Segoe Print", 10, 0))
      ImageGadget(#Gadget_Recipeview_Exitprogram, 1120, 5, 54, 54, ImageID(#Image_Recipeview_Exitprogram))
      CloseGadgetList()
      ContainerGadget(#Gadget_Recipeview_cStatusbar, 5, 755, 1185, 25, #PB_Container_BorderLess)
      StringGadget(#Gadget_Recipeview_sStatus, 0, 5, 110, 20, "", #PB_String_ReadOnly|#PB_String_BorderLess)
        SetGadgetFont(#Gadget_Recipeview_sStatus, LoadFont(#Gadget_Recipeview_sStatus, "Segoe Print", 9, 0))
      StringGadget(#Gadget_Recipeview_sMessage, 115, 5, 835, 20, "", #PB_String_ReadOnly|#PB_String_BorderLess)
        SetGadgetFont(#Gadget_Recipeview_sMessage, LoadFont(#Gadget_Recipeview_sMessage, "Segoe Print", 9, 0))
      StringGadget(#Gadget_Recipeview_sCurrent, 955, 5, 110, 20, "", #PB_String_ReadOnly|#PB_String_BorderLess)
        SetGadgetFont(#Gadget_Recipeview_sCurrent, LoadFont(#Gadget_Recipeview_sCurrent, "Segoe Print", 9, 0))
      StringGadget(#Gadget_Recipeview_sRecords, 1070, 5, 110, 20, "", #PB_String_ReadOnly|#PB_String_BorderLess)
        SetGadgetFont(#Gadget_Recipeview_sRecords, LoadFont(#Gadget_Recipeview_sRecords, "Segoe Print", 9, 0))
      CloseGadgetList()
      HideWindow(#Window_Recipeview, 0)
    ProcedureReturn WindowID(#Window_Recipeview)
  EndIf
EndProcedure

; My personal constants, declarations etc

Declare   RemoveBorders(GadgetConstant.i)                                                             ; Remove borders from various gadgets

; Program helpers

Declare   GetRecipeDirectory()                                                                        ; Scan recipe directory and load filenames
Declare   LoadLastDirectory()                                                                         ; Load the last directory used
Declare   SaveLastDirectory()                                                                         ; Save the last directory scanned
Declare   SetInfoBarArea(FieldName.s, FieldStatus.s = "##Error##", MessageContent.s = "0", ModuleName.s = #Empty$)  ; Handle the fake statusbar area messages

; 

Declare   SearchEngine(Searchpath.s)                                                                  ; Search and list recipes from a directory
Declare   SearchRecipes()                                                                             ; Search recipes in linked list and display matches
Declare   ShowRecipe()                                                                                ; Load the recipe into the webgadget to display it

; My personal constants

#Author                         = "Srod's underpants"                                                 ; Author's name
#CopyRight                      = "Big Smeghead productions 2018 "                                    ; Copyright holder
#Basename                       = "RecipeView "                                                       ; Base name for initialisation file and database
#Version                        = "v0.00."                                                            ; Program version
#Program                        = #Basename + #Version                                                ; Copyright string
#SystrayNote                    = "Hello, "+ #Program + " is hiding here"                             ; System tray note

; 

#Fish                           = "<°)))o><²³  "                                                      ; Beware the fish!!

#AtTheEndOfTheList              = -1                                                                  ; 
#FirstItemInList                =  0                                                                  ; 

#NoFileCreated                  =  0                                                                  ; 

#NoFileFound                    = -1                                                                  ; 
#NoFileRead                     =  0                                                                  ; 
#FileIsDirectory                = -2                                                                  ; 
  
; 

Structure ProgramData                                                                                ; 
  QuitValue.i                                                                                         ; 
  
  CurrentDirectory.s                                                                                  ; 
  
  LastSelectedRecipe.i                                                                                ; 
  CompileCounters.s                                                                                   ; Compiler and build counter
  
  ; Dealing with search cues in search boxes
  
  SearchCueFont.i                                                                                     ; Searchbox cue font
  SearchNormalFont.i                                                                                  ; Searchbox normal font
  SearchCueText.s                                                                                     ; The cue text to be passed to search windows
  
  SearchFileMarker.s                                                                                  ; 
EndStructure                                                                                         ; 

; 

Structure RecipeNames                                                                                ; 
  Recipename.s                                                                                        ; 
  RecipeCategory.s                                                                                    ; 
EndStructure                                                                                         ; 

; 

Global Program.ProgramData                                                                             ; 

Global NewList Recipes.RecipeNames()                                                                  ; 
Global NewList FoundDirectories.s()                                                                   ; List of dirs found by the search engine

; Create your program directories

Program\CompileCounters     = Str(#PB_Editor_CompileCount) + "." + Str(#PB_Editor_BuildCount) + "a"   ; Add to program version

; Initial program window quit state

Program\QuitValue           =  #False                                                                 ; Initial program quit value

Program\CurrentDirectory.s  = GetCurrentDirectory()                                                   ; 

Program\SearchFileMarker.s = Program\CurrentDirectory.s + "LastDirectorySearched.txt"                 ; 

; Setup the search box cue fonts

Program\SearchCueFont         = LoadFont(#PB_Any,   "Georgia",     10, #PB_Font_Italic)               ; Empty search cue font
Program\SearchNormalFont      = LoadFont(#PB_Any,   "Segoe Print", 10, 0)                             ; Filled cue box font
Program\SearchCueText.s       = Space(256)                                                            ; Set the cue text buffer

PokeS(@Program\SearchCueText, "Type your search string in here", -1, #PB_Unicode)                     ; 

; Program shortcut keys
  
Enumeration #GadgetIndex                                                                             ; 
  #StartSearching                                                                                     ; 
EndEnumeration                                                                                       ; 

; Generic procedures

; Remove borders from various gadgets

Procedure RemoveBorders(GadgetConstant.i)
  
  ; Get the gadget type from the passed gadget constant

  GadgetType.i = GadgetType(GadgetConstant.i)
  
  ; Select the gadget type
  
  Select GadgetType.i

    ; Do the below if it is a ListIconGadget
    
    Case  #PB_GadgetType_ListIcon
      
      ; Remove borders from ListIconGadgets
      
      OldStyle.i  = GetWindowLongPtr_(GadgetID(GadgetConstant.i), #GWL_EXSTYLE)
      
      NewStyle.i  = OldStyle.i & ( ~ #WS_EX_CLIENTEDGE)
      
      SetWindowLongPtr_(GadgetID(GadgetConstant.i), #GWL_EXSTYLE, NewStyle.i)
      
      SetWindowPos_(GadgetID(GadgetConstant.i), 0, 0, 0, 0, 0, #SWP_SHOWWINDOW | #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED)
      
    Case #PB_GadgetType_Editor
      
      ; Remove border from editorgadget (comment) field. Stiil leaves a 1 pixel border but that looks good here
      
      ;       SetWindowLongPtr_(GadgetID(GadgetConstant.i), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(GadgetConstant.i), #GWL_EXSTYLE) & (~#WS_EX_CLIENTEDGE))
      ;       SetWindowPos_(GadgetID(GadgetConstant.i), 0, 0, 0, 0, 0, #SWP_SHOWWINDOW | #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED)
  
      ; 
      
      OldStyle.i  = GetWindowLongPtr_(GadgetID(GadgetConstant.i), #GWL_EXSTYLE)
      
      NewStyle.i  = OldStyle.i & ( ~ #WS_EX_CLIENTEDGE)
      
      SetWindowLongPtr_(GadgetID(GadgetConstant.i), #GWL_EXSTYLE, NewStyle.i)
      SetWindowTheme_(GadgetID(GadgetConstant.i), @null.w, @null.w)
      
      ; SetWindowPos_(GadgetID(1), 0, 0, 0, 0, 0, #SWP_SHOWWINDOW | #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED) ; required for this to work on my Win98
      ; -- End removing border from EditorGadget --
      
  EndSelect
  
EndProcedure

; Program helpers

; Scan recipe directory and load filenames

Procedure GetRecipeDirectory()
  
  ; Get the pdf recipe directory that we need to scan
  
  Recipespath.s = PathRequester("What directory to search?", "D:\smeg\Documents\Underpants (Bollocks)\Cooking & Recipes\")
  
  If Recipespath.s  <> #Empty$
    
    ClearGadgetItems(#Gadget_Recipeview_Recipenames)
    
    SetGadgetText(#Gadget_Recipeview_Recipedirectory, Recipespath.s)
    
    ; Add the recipe names to a linked list with their category name
    
    SearchEngine(Recipespath.s)
    
    ; Add the directory name to the form and save it to an ini file
    
  Else
    
    ; The user cancelled the operation
    
  EndIf
  
EndProcedure

; Load the last directory used

Procedure LoadLastDirectory()
  
  FileSeeker.i = FileSize(Program\SearchFileMarker.s)
  
  If FileSeeker.i <>  #NoFileFound Or FileSeeker.i <>  #FileIsDirectory
    
    CheckLastUsed.i = ReadFile(#PB_Any, Program\SearchFileMarker.s)
    
    If CheckLastUsed.i <> #NoFileRead
      
      Recipespath.s = ReadString(CheckLastUsed.i)
      
      If Recipespath.s <> #Empty$
        
        LastUsedDirectory.i = FileSize(Recipespath.s)
        
        If LastUsedDirectory.i = #FileIsDirectory
          
          SetGadgetText(#Gadget_Recipeview_Recipedirectory, Recipespath.s)
          
          SearchEngine(Recipespath.s)
          
        Else
          
          ; Last used recipe directory cannot be found
          
        EndIf
        
      Else
        
        ; The last used recipe directory is empty
        
      EndIf
      
      CloseFile(CheckLastUsed.i)
      
    Else
      
      ; Can't open the last used file marker
      
    EndIf
    
  Else
    
    ; Can't find the last used file marker
    
  EndIf
  
EndProcedure

; Save the last directory scanned

Procedure SaveLastDirectory()
  
  Recipespath.s = GetGadgetText(#Gadget_Recipeview_Recipedirectory)
  
  If Recipespath.s <> #Empty$
    
    SaveFile.i = CreateFile(#PB_Any, Program\SearchFileMarker.s)
    
    If SaveFile.i <> #NoFileCreated
      
      WriteString(SaveFile.i, Recipespath.s)
      
      CloseFile(SaveFile.i)
      
    Else
      
      ; Last used recipe path marker was not created
      
    EndIf
    
  Else
    
    ; No recipes path to save
    
  EndIf
  
EndProcedure

; Handle the fake statusbar area messages

Procedure SetInfoBarArea(FieldName.s, FieldStatus.s = "##Error##", MessageContent.s = "0", ModuleName.s = #Empty$)
  
  ; Select the name of the field to put our heading string
  
  Select FieldName.s
      
    ; Select the correct heading by the status field
      
    Case "Headings"
      
      Select FieldStatus.s
          
        Case "Welcome"
          
          MessageHeader.s = "Welcome"
          
          Colour.i        = $615E5F
          
        Case "Info"
          
          MessageHeader.s = "Information"
          
          Colour.i        = $DB3D24
          
        Case "Warn"
          
          MessageHeader.s = "Warning"
          
          Colour.i        = $7D1F82
          
        Case "Tool"
          
          MessageHeader.s = "Tooltip"
          
          Colour.i        = $FF0000
          
      EndSelect
      
      ; Send all the strings to the fake status bar area
      
      SetGadgetText(#Gadget_Recipeview_sStatus,     MessageHeader.s)
      
      SetGadgetText(#Gadget_Recipeview_sMessage,    MessageContent.s)
      
      SetGadgetColor(#Gadget_Recipeview_sStatus,    #PB_Gadget_FrontColor, Colour.i)
      
    Case "Current"
      
      SetGadgetText(#Gadget_Recipeview_sCurrent, "Recipe " + MessageContent.s)
      
    Case "Records"
      
      ; Figure out the correct spelling for the record field for singles or multiples
      
      If Val(MessageContent.s)      = 0
        
        RecordHeader.s = "Recipes"
        
      ElseIf Val(MessageContent.s) = 1
        
        RecordHeader.s = "Recipe"
        
      ElseIf Val(MessageContent.s) > = 2
        
        RecordHeader.s = "Recipes"
        
      EndIf
      
      ; Set the record number details in the fake status bar area
      
      SetGadgetText(#Gadget_Recipeview_sRecords, FormatNumber(ValD(MessageContent.s), 0, ".", ",") + " " + RecordHeader.s)
      
  EndSelect
  
EndProcedure

; Recipe related procedures

; Search and list recipes from a directory

Procedure SearchEngine(Searchpath.s)
  
  PseudoCounter.i = 0
  
  ClearList(FoundDirectories.s())
  
  If Searchpath.s <> #Empty$
    
    If Right(Searchpath.s, 1) = "\"
      
      Searchpath.s = Left(Searchpath.s, Len(Searchpath.s) - 1)
      
    EndIf
    
    AddElement(FoundDirectories.s())
    
    FoundDirectories.s() = Searchpath.s
    
    Index.i = 0
    
    Repeat
      
      SelectElement(FoundDirectories.s(), Index.i)
      
      Directory.i = ExamineDirectory(#PB_Any, FoundDirectories.s(), "*.*")
      
      If Directory.i
        
        Path.s = FoundDirectories.s() + "\"
        
        While NextDirectoryEntry(Directory.i)
          
          Filename.s = DirectoryEntryName(Directory.i)
          
          Select DirectoryEntryType(Directory.i)
              
            Case #PB_DirectoryEntry_File
              
              If LCase(GetExtensionPart(Filename.s)) = "pdf"
                
                CurrentRecipeName.s = Left(Filename.s, Len(Filename.s)  - Len(GetExtensionPart(Filename.s)) - 1)
                
                CurrentCategory.s   = Path.s
                
                If Len(CurrentRecipeName.s) And Len(CurrentCategory.s)
                  
                  AddGadgetItem(#Gadget_Recipeview_Recipenames, #AtTheEndOfTheList, CurrentRecipeName.s  + #LF$  + Path.s)
                  
                  PseudoCounter.i + 1
                  
                  AddElement(Recipes())
                  
                  Recipes()\Recipename.s      = CurrentRecipeName.s
                  
                  Recipes()\RecipeCategory.s  = CurrentCategory.s
                  
                Else
                  
                  ; Recipe name or directory is empty
                  
                EndIf
              
                ; 
                
              Else
                
                ; This isn't a PDF file so ignore it
                
              EndIf
              
            Case #PB_DirectoryEntry_Directory
              
              Filename.s = DirectoryEntryName(Directory.i)
              
              If Filename.s <> ".." And Filename.s <> "."
                
                AddElement(FoundDirectories())
                
                FoundDirectories() = Path.s + Filename.s
                
              EndIf
              
          EndSelect
          
        Wend
        
        FinishDirectory(Directory.i)
        
      EndIf
      
      Index.i + 1
      
    Until Index.i > ListSize(FoundDirectories()) -1
    
  EndIf
  
  If CountGadgetItems(#Gadget_Recipeview_Recipenames)
    
    SetGadgetState(#Gadget_Recipeview_Recipenames, #FirstItemInList)
    
    SetGadgetItemState(#Gadget_Recipeview_Recipenames, #FirstItemInList, #PB_ListIcon_Selected)
    
    SetInfoBarArea("Records",   #Empty$, Str(CountGadgetItems(#Gadget_Recipeview_Recipenames)))
    
    PostEvent(#PB_Event_Gadget, #Window_Recipeview, #Gadget_Recipeview_Recipenames, #PB_EventType_Change)
    
  Else
    
    ; There were no PDF recipes files found in the directory
    
  EndIf
  
EndProcedure

; Search recipes in linked list and display matches

Procedure SearchRecipes()
  
  If GetActiveGadget()  = #Gadget_Recipeview_Recipesearch
    
    PseudoCounter.i = 0
    
    SearchText.s = LCase(GetGadgetText(#Gadget_Recipeview_Recipesearch))
    
    If Len(SearchText.s)
      
      ClearGadgetItems(#Gadget_Recipeview_Recipenames)
      
      SetGadgetText(#Gadget_Recipeview_Recipesearch, #Empty$)
      
      If Left(SearchText.s, 2) = "//"
        
        ForEach Recipes()
          
          SearchText.s = RemoveString(SearchText.s, "//", #PB_String_NoCase, 1)
          
          If FindString(Recipes()\RecipeCategory.s, SearchText.s, 1, #PB_String_NoCase) <> #False
            
            AddGadgetItem(#Gadget_Recipeview_Recipenames, #AtTheEndOfTheList, Recipes()\Recipename.s  + #LF$  + Recipes()\RecipeCategory.s)
            
            PseudoCounter.i + 1
            
          Else
            
            ; No string match so don't display this line
            
          EndIf
          
        Next
        
      Else
        
        ForEach Recipes()
          
          If FindString(Recipes()\Recipename.s, SearchText.s, 1, #PB_String_NoCase) <> #False
            
            AddGadgetItem(#Gadget_Recipeview_Recipenames, #AtTheEndOfTheList, Recipes()\Recipename.s  + #LF$  + Recipes()\RecipeCategory.s)
            
            PseudoCounter.i + 1
            
          Else
            
            ; No string match so don't display this line
            
          EndIf
          
        Next
        
      EndIf
      
    Else
      
      ; No search text so do not proceed
      
    EndIf
    
  Else
    
    ; Nothing to do as Returnw asn't pressed from the search bar
    
  EndIf
  
  If CountGadgetItems(#Gadget_Recipeview_Recipenames)
    
    SetGadgetState(#Gadget_Recipeview_Recipenames, #FirstItemInList)
    
    SetGadgetItemState(#Gadget_Recipeview_Recipenames, #FirstItemInList, #PB_ListIcon_Selected)
    
    SetInfoBarArea("Records",   #Empty$, Str(CountGadgetItems(#Gadget_Recipeview_Recipenames)))
    
    PostEvent(#PB_Event_Gadget, #Window_Recipeview, #Gadget_Recipeview_Recipenames, #PB_EventType_Change)
    
  Else
    
    ; There were no PDF recipes files found in the directory
    
  EndIf
  
EndProcedure

; Load the recipe into the webgadget to display it

Procedure ShowRecipe()
  
  CurrentLine.i = GetGadgetState(#Gadget_Recipeview_Recipenames)
  
  If CurrentLine.i >= 0
    
    Program\LastSelectedRecipe.i  = CurrentLine.i
    
    RecipeName.s = GetGadgetItemText(#Gadget_Recipeview_Recipenames, CurrentLine.i, 0)  ;: Debug RecipeName.s
    
    RecipePath.s = GetGadgetItemText(#Gadget_Recipeview_Recipenames, CurrentLine.i, 1)  ;: Debug RecipePath.s
    
    If RecipePath.s + RecipeName.s
      
      SetInfoBarArea("Current",   #Empty$, Str(CurrentLine.i))
      
      NumberOfSeparators.i = CountString(RecipePath.s, "\")
      
      If NumberOfSeparators.i > 1
        
        SetGadgetText(#Gadget_Recipeview_Recipecategory,    StringField(RecipePath.s, NumberOfSeparators.i - 1, "\"))
      
        SetGadgetText(#Gadget_Recipeview_Recipesubcategory, StringField(RecipePath.s, NumberOfSeparators.i,     "\"))
        
      ElseIf NumberOfSeparators.i = 1
        
        SetGadgetText(#Gadget_Recipeview_Recipecategory,    StringField(RecipePath.s, NumberOfSeparators.i,     "\"))
      
        SetGadgetText(#Gadget_Recipeview_Recipesubcategory, #Empty$)
        
      Else
        
        SetGadgetText(#Gadget_Recipeview_Recipecategory,    #Empty$)
      
        SetGadgetText(#Gadget_Recipeview_Recipesubcategory, #Empty$)
        
      EndIf
      
      SetGadgetText(#Gadget_Recipeview_Recipeview, RecipePath.s + RecipeName.s  + ".pdf")
      
      SetActiveGadget(#Gadget_Recipeview_Recipenames)
      
      SetGadgetState(#Gadget_Recipeview_Recipenames, Program\LastSelectedRecipe.i)
      
      SetGadgetItemState(#Gadget_Recipeview_Recipenames, Program\LastSelectedRecipe.i, #PB_ListIcon_Selected)      
      
    Else

      ; The recipe path and recipe name were empty

    EndIf
    
  Else
    
    ; There is no current line to display
    
  EndIf
  
EndProcedure

; Main event handler

If Window_Recipeview()
  
  ;// 
  
  Program\QuitValue = #False
  
  ;// Add keyboard shortcuts
  
  AddKeyboardShortcut(#Window_Recipeview, #PB_Shortcut_Return, #StartSearching)
  
  ;// Remove the ListIconGadget borders
  
  RemoveBorders(#Gadget_Recipeview_Recipenames)
  
  ;// Limit the number of search box characters and set the cue banner text. These variables are set in the MyStuff_Myconstants file.
  
  SendMessage_(GadgetID(#Gadget_Recipeview_Recipesearch), #EM_SETLIMITTEXT, 67, 0)
  SendMessage_(GadgetID(#Gadget_Recipeview_Recipesearch), #EM_SETCUEBANNER,  1,  Program\SearchCueText)
  
  ;// Set initial search string font to be italic font
  
  SetGadgetFont(#Gadget_Recipeview_Recipesearch, FontID(Program\SearchCueFont))
  
  ;// Load the recipes from the last used recipe directory
  
  LoadLastDirectory()
  
  ;// Setup initial welcome dialogues in the fake statusbar area
  
  SetInfoBarArea("Headings",  "Welcome",    "Welcome to " + #Fish + #Basename + #Version + Program\CompileCounters  + ", Have a nice day")
  SetInfoBarArea("Current",   #Empty$, "0")
  SetInfoBarArea("Records",   #Empty$, Str(CountGadgetItems(#Gadget_Recipeview_Recipenames)))
  
  ;// Main event handler
  
  Repeat
    
    EventID  =  WaitWindowEvent()
    MenuID   =  EventMenu()
    GadgetID =  EventGadget()
    WindowID =  EventWindow()
    
    Select EventID
        
      Case #PB_Event_CloseWindow
        Select WindowID
          Case  #Window_Recipeview                : Program\QuitValue  = #True
        EndSelect
        
      Case #PB_Event_Menu
        
        Select MenuID
          Case  #StartSearching                   : SearchRecipes()
        EndSelect
        
      Case #PB_Event_Gadget
        
        Select GadgetID
            
          Case #Gadget_Recipeview_Recipenames
            Select EventType()
              Case #PB_EventType_Change           : ShowRecipe()
            EndSelect
            
          Case #Gadget_Recipeview_Getdirectory
            Select EventType()
              Case #PB_EventType_LeftClick        : GetRecipeDirectory()
            EndSelect
            
          Case #Gadget_Recipeview_Printrecipe     : ; PrintSelectedRecipe()
          Case #Gadget_Recipeview_Showhelp        : ; ShowProgramHelp()
          Case #Gadget_Recipeview_Exitprogram     : Program\QuitValue  = #True
            
        EndSelect
        
    EndSelect
    
  Until Program\QuitValue
  
  SaveLastDirectory()
  
  CloseWindow(#Window_Recipeview)
  
EndIf

End
Amateur Radio, D-STAR/VK3HAF
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Casual recipe pdf finder/lister (needs work)

Post by Bisonte »

I think you should offer the included pictures for download somewhere.
That would make it much easier to try it out. ;)
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Casual recipe pdf finder/lister (needs work)

Post by Fangbeast »

Bisonte wrote:I think you should offer the included pictures for download somewhere.
That would make it much easier to try it out. ;)
Programmers are quite resourceful people and can find their own or make their own. Rashad regularly publishes code to draw his own with his many forum examples, he isn't lazy like me:):)

And what's so hard about substituting ButtonImageGadget with ButtonGadget? I am not going to constantly include graphics with my 'tips and tricks' unless they turn out to be fully fledged programs one day, it's too hard to run around finding places. I think programmers can figure these things out for themselves at any rate.
Amateur Radio, D-STAR/VK3HAF
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Casual recipe pdf finder/lister (needs work)

Post by Bisonte »

But one thing must never be forgotten. Programmers are the laziest people... with the attention span of a housefly. I'm one of them, I know what I'm talking about. :mrgreen:

I just wanted to say that the chances of feedback are higher when it can be started out-of-the-box.
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Casual recipe pdf finder/lister (needs work)

Post by srod »

Bisonte wrote:I just wanted to say that the chances of feedback are higher when it can be started out-of-the-box.
You wouldn't want to open any box which fangles has had his grubby hands on. At least, not before getting your dog to sniff the box before opening! Actually, considering the dog is likely to drop dead on the spot, better use the neighbour's dog! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Casual recipe pdf finder/lister (needs work)

Post by Fangbeast »

Bisonte wrote:But one thing must never be forgotten. Programmers are the laziest people... with the attention span of a housefly. I'm one of them, I know what I'm talking about. :mrgreen:

I just wanted to say that the chances of feedback are higher when it can be started out-of-the-box.
Well, that's true and I don't care about them:):) Look at that lazy tart srod, he gave feedback when you said I had less chance of getting any!!

But then, what else was he going to do when he had abused the mixed sheep and goat collection of his and he had all that time on his hands now?

I did wonder though, what were his underpants doing on the male goat? Ball slingshot??? Weird!
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Casual recipe pdf finder/lister (needs work)

Post by Fangbeast »

You wouldn't want to open any box which fangles has had his grubby hands on.
I didn't use my hands, I used your goat!!
At least, not before getting your dog to sniff the box before opening!
That was a dog I stole from your place?? (oops, I have revealed the burglar, damn!)
Actually, considering the dog is likely to drop dead on the spot, better use the neighbour's dog! :)
The neighbour has two dogs, which one should I use? The German short haired pointer or the other one that looks like a skinny brown raisin loaf?
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Casual recipe pdf finder/lister (needs work)

Post by Fangbeast »

Bisonte, not withstanding the fact that srod is a sheep groping, dingo fancier and goat rotater, smelly underpants wearer (and registered dog botherer heheheh), I added some stuff I wanted today along with my usual formatting and it's now too big to paste to the forum.

Well, it would take me ages to strip it all out and concatenate the files.

Where is a good place to upload it that's not too complicated? The only thing I haven't fixed is some of my keyboard shortcuts don't work, only the first one specified and I am now too tired to find it.

Everything else is good for my wife:):)
Amateur Radio, D-STAR/VK3HAF
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Casual recipe pdf finder/lister (needs work)

Post by Bisonte »

Don't you have a Dropbox or OneDrive account ?

Or use Stargate's or TS-Soft's Bin2Data and post it as a Datasection, if the images are not too big in filesize. ;)
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Casual recipe pdf finder/lister (needs work)

Post by Fangbeast »

Bisonte wrote:Don't you have a Dropbox or OneDrive account ?

Or use Stargate's or TS-Soft's Bin2Data and post it as a Datasection, if the images are not too big in filesize. ;)
Damn, I forgot I had dropbox. haven't used it in a year, must find out if it still exists. It's all that sheep rooter srod's fault for blinding me with his underpants.!!
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4747
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Casual recipe pdf finder/lister (needs work)

Post by Fangbeast »

Okay, hope this works. (latest perversion)

https://drive.google.com/open?id=1bhkkb ... BPxiKMzhZA
Amateur Radio, D-STAR/VK3HAF
Post Reply