1 ; +-----------------+ 2 ; | PureHTML Styles | 3 ; +-----------------+ 4 5 ;- 6 ;- Macros 7 8 Macro SetIfInteger(Variable, Keyword) 9 If (ReadPreferenceString(Keyword, "")) 10 Variable = Val(ReadPreferenceString(Keyword, "")) 11 EndIf 12 EndMacro 13 Macro SetIfString(Variable, Keyword) 14 If (ReadPreferenceString(Keyword, "")) 15 Variable = ReadPreferenceString(Keyword, "") 16 EndIf 17 EndMacro 18 Macro SetIfColor(Variable, Keyword) 19 If (ReadPreferenceString(Keyword, "")) 20 Variable = ParseColor(ReadPreferenceString(Keyword, "")) 21 EndIf 22 EndMacro 23 24 25 ;- 26 ;- Procedures 27 28 29 30 31 ; Parse a color string 32 Procedure.i ParseColor(Input.s) 33 Protected Result.i = -1 34 35 If (FindString(Input, "RGB(")) 36 Input = StringField(Input, 2, "(") 37 Input = RemoveString(Input, " ") 38 Input = RTrim(Input, ")") 39 Result = RGB(Val(StringField(Input, 1, ",")), Val(StringField(Input, 2, ",")), Val(StringField(Input, 3, ","))) 40 Else 41 Result = Val(Input) 42 EndIf 43 44 ProcedureReturn (Result) 45 EndProcedure 46 47 48 49 50 51 52 ; Load default preferences 53 Procedure.i LoadDefaults() 54 Protected i.i 55 56 ; Formatting defaults 57 Config\TabLength = 2 58 Config\LineNumbers = #True 59 Config\HideIDE = #True 60 Config\IncludeLinks = #False 61 62 ; Font defaults 63 Config\BGColor = $DFFFFF 64 Config\LNColor = $D7FFFF 65 Config\FontName = "Courier New" 66 Config\FontSize = 11 67 68 ; Read style defaults 69 For i = 0 To #PHS_Count - 1 70 Style(i)\Color = DefColor(i) 71 If (i = #PHS_Keyword) 72 Style(i)\Bold = #True 73 Else 74 Style(i)\Bold = #False 75 EndIf 76 Style(i)\Italic = #False 77 Style(i)\Underline = #False 78 Style(i)\Strike = #False 79 Next i 80 EndProcedure 81 82 83 ; Import preferences 84 Procedure.i LoadPrefs(File.s) 85 Protected Result.i = #False 86 Protected i.i, KeyBold.i 87 88 ; Attempt to open preferences 89 If (File And OpenPreferences(File)) 90 Result = #True 91 EndIf 92 If (Result) 93 94 ; Read formatting settings 95 PreferenceGroup("Global") 96 SetIfInteger(Config\TabLength, "TabLength") 97 SetIfInteger(Config\LineNumbers, "EnableLineNumbers") 98 SetIfInteger(Config\HideIDE, #PH_Title + "_HideIDEOptions") 99 SetIfInteger(Config\IncludeLinks, #PH_Title + "_IncludeLinks") 100 SetIfInteger(Style(#PHS_Keyword)\Bold, "EnableKeywordBolding") 101 102 ; Read PureBasic-format settings 103 PreferenceGroup("Editor") 104 SetIfColor(Config\BGColor, "BackgroundColor") 105 SetIfColor(Config\LNColor, "LineNumberBackColor") 106 SetIfString(Config\FontName, "EditorFontName") 107 SetIfInteger(Config\FontSize, "EditorFontSize") 108 For i = 0 To #PHS_Count - 1 109 SetIfColor(Style(i)\Color, StyleKeyword(i) + "Color") 110 Next i 111 112 ; Read colors in import/export location 113 PreferenceGroup("Colors") 114 For i = 0 To #PHS_Count - 1 115 SetIfColor(Style(i)\Color, StyleKeyword(i) + "Color") 116 Next i 117 118 ; Read extra settings, if found 119 For i = 0 To #PHS_Count - 1 120 PreferenceGroup(#PH_Title + "_" + StyleKeyword(i)) 121 SetIfColor(Style(i)\Color, "Color") 122 SetIfInteger(Style(i)\Bold, "Bold") 123 SetIfInteger(Style(i)\Italic, "Italic") 124 SetIfInteger(Style(i)\Underline, "Underline") 125 SetIfInteger(Style(i)\Strike, "Strikethrough") 126 Next i 127 128 EndIf 129 If (Result) 130 ClosePreferences() 131 EndIf 132 133 ProcedureReturn (Result) 134 EndProcedure 135 136 137 138 ; Write a preference in RGB(r, g, b) format 139 Procedure WritePreferenceRGB(Keyword.s, Color.i) 140 Protected Output.s 141 142 Output = "RGB(" + Str(Red(Color)) + ", " + Str(Green(Color)) 143 Output + ", " + Str(Blue(Color)) + ")" 144 WritePreferenceString(Keyword, Output) 145 EndProcedure 146 147 148 ; Export settings to a PB-importable file 149 Procedure.i SavePrefs(File.s) 150 Protected Result.i = #False 151 Protected i.i 152 153 If (CreatePreferences(File)) 154 Result = #True 155 156 ; Write header 157 PreferenceComment("PureBasic IDE Exported Preferences") 158 PreferenceComment("Exported from " + #PH_Title + " version " + VersionString(#PH_Version)) 159 PreferenceComment("") 160 PreferenceGroup("Sections") 161 WritePreferenceInteger("IncludeColors", 1) 162 PreferenceComment("") 163 PreferenceComment("Color settings") 164 PreferenceComment("") 165 166 ; Write colors to export location 167 PreferenceGroup("Colors") 168 For i = 0 To #PHS_Count - 1 169 WritePreferenceRGB(StyleKeyword(i) + "Color", Style(i)\Color) 170 WritePreferenceInteger(StyleKeyword(i) + "Color_Used", 1) 171 Next i 172 WritePreferenceRGB("BackgroundColor", Config\BGColor) 173 WritePreferenceInteger("BackgroundColor_Used", 1) 174 WritePreferenceRGB("LineNumberBackColor", Config\LNColor) 175 WritePreferenceInteger("LineNumberBackColor_Used", 1) 176 WritePreferenceRGB("ProcedureBackColor", Config\BGColor) 177 WritePreferenceInteger("ProcedureBackColor_Used", 0) 178 PreferenceComment("") 179 180 ; Write formatting settings 181 PreferenceGroup("Global") 182 WritePreferenceInteger("TabLength", Config\TabLength) 183 WritePreferenceInteger("EnableLineNumbers", Config\LineNumbers) 184 WritePreferenceInteger(#PH_Title + "_HideIDEOptions", Config\HideIDE) 185 WritePreferenceInteger(#PH_Title + "_IncludeLinks", Config\IncludeLinks) 186 WritePreferenceInteger("EnableKeywordBolding", Style(#PHS_Keyword)\Bold) 187 PreferenceComment("") 188 189 ; Write remaining settings to prefs location 190 PreferenceGroup("Editor") 191 WritePreferenceInteger("BackgroundColor", Config\BGColor) 192 WritePreferenceInteger("LineNumberBackColor", Config\LNColor) 193 WritePreferenceString("EditorFontName", Config\FontName) 194 WritePreferenceInteger("EditorFontSize", Config\FontSize) 195 196 ClosePreferences() 197 EndIf 198 199 ProcedureReturn (Result) 200 EndProcedure 201 202 203 ; Attempt to load PB IDE preferences, if known 204 Procedure LoadIDEPrefs() 205 Config\IOPath = GetCurrentDirectory() 206 207 LoadDefaults() 208 LoadPrefs(GetEnvironmentVariable("PB_TOOL_Preferences")) 209 LoadPrefs(#PH_PrefFile) 210 UpdateForm() 211 EndProcedure 212 213 214 215 ; Import settings to file 216 Procedure.i TryImport() 217 Protected Result.i = #False 218 Protected File.s 219 220 File = OpenFileRequester("Import", Config\IOPath, "Style Preferences (*.prefs)|*.prefs|All Files (*.*)|*.*", 0) 221 If (File) 222 Config\IOPath = GetPathPart(File) 223 If (LoadPrefs(File)) 224 UpdateForm() 225 Info("Successfully imported settings.") 226 Result = #True 227 Else 228 Warn("Failed to import settings:" + #LF$ + File) 229 EndIf 230 EndIf 231 232 ProcedureReturn (Result) 233 EndProcedure 234 235 ; Export settings to file 236 Procedure.i TryExport() 237 Protected Result.i = #False 238 Protected File.s 239 240 File = SaveFileRequester("Export", Config\IOPath, "Style Preferences (*.prefs)|*.prefs|All Files (*.*)|*.*", 0) 241 If (File) 242 If ((SelectedFilePattern() = 0) And (LCase(GetExtensionPart(File)) <> "prefs")) 243 File + ".prefs" 244 EndIf 245 Config\IOPath = GetPathPart(File) 246 If (SavePrefs(File)) 247 Info("Successfully exported settings.") 248 Result = #True 249 Else 250 Warn("Failed to export settings:" + #LF$ + File) 251 EndIf 252 EndIf 253 254 ProcedureReturn (Result) 255 EndProcedure 256 257 258 ;- 259 ; EOF