Tool Create Desktop File For PureBasic

Linux specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6244
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Tool Create Desktop File For PureBasic

Post by mk-soft »

For lazy guys like me ...
Create the desktop file to get PureBasic into the linux start menu ;)
Just run it with the PB IDE

Code: Select all

;-TOP

#ProgramTitle = "Create PureBasic Desktop File"
#ProgramVersion = "v1.01.2 by mk-soft"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  #MainList
  #MainButtonSave
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

; ----

Macro AddElementValue(List, Value)
  AddElement(List) : List = Value
EndMacro

Global NewList Rows.s()

Procedure CreateDesktopFile()
  Protected Name.s
  
  Name = "PureBasic v" + Str(#PB_Compiler_Version / 100) + "." + LSet(Str(#PB_Compiler_Version % 100), 2, "0")
  
  AddElementValue(Rows(), "[Desktop Entry]")
  AddElementValue(Rows(), "Type=Application")
  AddElementValue(Rows(), "Icon=" + #PB_Compiler_Home + "logo.png")
  AddElementValue(Rows(), "Name=" + Name + " (gtk3)")
  AddElementValue(Rows(), "Comment=Developer Utility")
  AddElementValue(Rows(), "Exec=" + #PB_Compiler_Home + "compilers/purebasic")
  AddElementValue(Rows(), "Path=" + #PB_Compiler_Home + "compilers")
  AddElementValue(Rows(), "StartupNotify=false")
  AddElementValue(Rows(), "Terminal=false")
  AddElementValue(Rows(), "Categories=Development")
  
  ForEach Rows()
    AddGadgetItem(#MainList, -1, Rows())
  Next

EndProcedure

Procedure SaveDesktopFile()
  Protected path.s, filename.s, file.s
  
  path = "/home/" + UserName() + "/.local/share/applications/"
  filename = path + "purebasic-v" + LSet(Str(#PB_Compiler_Version), 3, "0") + ".desktop"
  
  file = SaveFileRequester("Save Desktop File", filename, "", 0)
  If file
    If CreateFile(0, file)
      ForEach Rows()
        WriteStringN(0, Rows())
      Next
      CloseFile(0)
    Else
      MessageRequester("Error", "File Not Saved!", #PB_MessageRequester_Error)
    EndIf
  EndIf
EndProcedure

; ----

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainList, 5, 5, dx - 10, dy - 45)
  ResizeGadget(#MainButtonSave, dx - 130, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    MenuItem(#MainMenuAbout, "About")
    MenuBar()
    MenuItem(#MainMenuExit, "E&xit")
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    ListViewGadget(#MainList, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButtonSave, dx - 130, dy - 35, 120, 30, "Save")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    CreateDesktopFile()
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case #MainMenuAbout
              MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
                
            Case #MainMenuExit
              PostEvent(#PB_Event_CloseWindow, #Main, #Null)
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainList
              Select EventType()
                Case #PB_EventType_Change
                  ;
                  
              EndSelect
              
            Case #MainButtonSave
              SaveDesktopFile()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive