Default compiled application icon

Working on new editor enhancements?
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Default compiled application icon

Post by AZJIO »

Is it possible to make a checkbox in the IDE settings to use the standard program icon?
1. If the checkbox is disabled, then the current behavior (without the icon) is used.
2. If the checkbox is enabled, but the field for the icon file name is empty (or the file does not exist), then the PureBasic icon with a modified shade (fuchsia color) is used. This is useful for test or temporary compiled files that show that you are using PureBasic for compilation, and not Delphi or anything else. Another option is to search for an icon (ico) in the source directory, if the checkbox is enabled and the icon name field is empty
3. The third state of the icon inserts the text "icon.ico" into the icon name field, that is, I do not need to worry about filling out this field every time, since I know that the compiler will look for the file "icon.ico" for my program and I will always create a file with this name without specifying it in the compiler settings, since I could set this in the settings as the default state.
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: Default compiled application icon

Post by AZJIO »

I made the icon search logic

Code: Select all

Define icon$, path$, name$, Toggle

If OpenWindow(0, 0, 0, 420, 120, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	CheckBoxGadget(0, 10, 10, 77, 25, "icon", #PB_CheckBox_ThreeState)
	StringGadget(1, 100, 10, 300, 25, "")
	ButtonGadget(2, 160, 50, 100, 30, "OK")
	TextGadget(3, 10, 90, 400, 20, "")
	DisableGadget(1, #True)
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 0
						Select GetGadgetState(0)
							Case #PB_CheckBox_Checked
; 								Debug "Checked"
								DisableGadget(1, #False)
								If Toggle
									DisableGadget(1, #True)
									SetGadgetState(0, #PB_CheckBox_Unchecked)
									SetGadgetText(1 , "") 
									Toggle = -1
								EndIf
								Toggle + 1
							Case #PB_CheckBox_Inbetween
; 								Debug "Inbetween"
								DisableGadget(1, #False)
								Toggle = 0
							Case #PB_CheckBox_Unchecked
; 								Debug "Unchecked"
								If Toggle
									SetGadgetState(0, #PB_CheckBox_Inbetween)
									SetGadgetText(1 , "icon.ico") ; default.ico ?
									Toggle = -1
								EndIf
						EndSelect
						

; 						If GetGadgetState(0) & #PB_CheckBox_Checked
; 							If Toggle
; 								SetGadgetState(0, #PB_CheckBox_Unchecked)
; 								SetGadgetText(1 , "") 
; 								DisableGadget(1, #True)
; 								Toggle = -1
; 							Else
; 								DisableGadget(1, #False)
; 							EndIf
; 							Toggle + 1
; 						Else
; 							If Toggle
; 								SetGadgetState(0, #PB_CheckBox_Inbetween)
; 								SetGadgetText(1 , "icon.ico") ; default.ico ?
; 								Toggle = -1
; 							EndIf
; 							DisableGadget(1, #False)
; 						EndIf

					Case 2
						path$ = GetPathPart(ProgramFilename())
						name$ = GetGadgetText(1)
						If GetGadgetState(0) = #PB_CheckBox_Inbetween ; the flag is designed to find an icon
							Debug "Inbetween"
							If Asc(name$) And FileSize(path$ + name$) > 0
; 								use a standard icon
								icon$ = path$ + name$
							Else
; 								if the icon does not exist, then we try to find any icon
								If ExamineDirectory(0, path$, "*.ico") 
									If NextDirectoryEntry(0)	
										If DirectoryEntryType(0) = #PB_DirectoryEntry_File 
											icon$ = path$ + DirectoryEntryName(0)
										EndIf
									EndIf
									FinishDirectory(0) 
								EndIf
							EndIf
; 							if the icon is not found, and the checkbox implies its presence, then use the standard one
							If FileSize(icon$) < 0
								icon$ = #PB_Compiler_Home + "default.ico "
							EndIf
						ElseIf GetGadgetState(0) = #PB_CheckBox_Checked
							Debug "Checked"
							If Asc(name$)
								If FileSize(path$ + name$) < 0
									 ; if the user specified an icon, it must exist
									icon$ = "icon does not exist (" + name$ + ")"
								EndIf
							Else
; 								if the user has not specified an icon, use the default icon
								name$ = "icon.ico" ; default.ico ?
								icon$ = path$ + name$
								; 							If not found
								If FileSize(icon$) < 0
									icon$ = #PB_Compiler_Home + "default.ico "
								EndIf
							EndIf
						Else
							icon$ = "no icon"
						EndIf
						Debug icon$
						SetGadgetText(3, icon$) 
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
Post Reply