IDE PureBasic - Lire les préférences

Programmation d'applications complexes
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

IDE PureBasic - Lire les préférences

Message par falsam »

Obtenir le paramétrage de l'IDE PureBasic dans le cadre d'un développement d'utilitaires à ajouter à l'IDE.

Code : Tout sélectionner

Enumeration 0
  #PB_Token_Text
  #PB_Token_Keyword
  #PB_Token_Comment
  #PB_Token_Constant
  #PB_Token_String
  #PB_Token_Function
  #PB_Token_Asm
  #PB_Token_Operator
  #PB_Token_Structure
  #PB_Token_Number
  #PB_Token_Pointer
  #PB_Token_Separator
  #PB_Token_Label
  #PB_Token_Max
EndEnumeration

Structure PREFERENCES
  CurrentLanguage.s
  TabLength.l
  RealTab.l
  EnableColoring.l
  EnableKeywordBolding.l
  EnableLineNumbers.l
  DisplayFullPath.l
  EditorFontName.s
  EditorFontSize.l
  EditorFontStyle.l
  BackgroundColor.l
  ProcedureBackColor.l
  LineNumberColor.l
  LineNumberBackColor.l
  CurrentLineColor.l
  SelectionColor.l
  TokenColor.l[13]
EndStructure
Global Prefs.PREFERENCES

Procedure.s GetSpecialFolderLocation(folder)
  Protected pid, path.s
  
  If SHGetSpecialFolderLocation_(#Null, folder, @pid) = #S_OK
    path = Space(#MAX_PATH)
    If ( SHGetPathFromIDList_(pid, @path) = #True ) And ( Right(path, 1) <> "\" )
      path + "\"
    EndIf 
  EndIf
  
  ProcedureReturn path
  
EndProcedure 

Procedure ReadPreferences()
  Protected Filename.s = "PureBasic.prefs"
  
  If FileSize(Filename) = -1
    Filename = GetSpecialFolderLocation(#CSIDL_APPDATA) + "PureBasic\PureBasic.prefs"
  EndIf
  
  OpenPreferences(Filename)
  
  PreferenceGroup("Global")
  
  Prefs\CurrentLanguage      = ReadPreferenceString("CurrentLanguage",      "English")
  Prefs\TabLength            = ReadPreferenceLong  ("TabLength",            2)
  Prefs\RealTab              = ReadPreferenceLong  ("RealTab",              #False)
  Prefs\EnableColoring       = ReadPreferenceLong  ("EnableColoring",       #False)
  Prefs\EnableKeywordBolding = ReadPreferenceLong  ("EnableKeywordBolding", #False)
  Prefs\EnableLineNumbers    = ReadPreferenceLong  ("EnableLineNumbers",    #False)
  Prefs\DisplayFullPath      = ReadPreferenceLong  ("DisplayFullPath",      #False)
  
  PreferenceGroup("Editor")
  
  Prefs\EditorFontName       = ReadPreferenceString("EditorFontName",  "Courier")
  Prefs\EditorFontSize       = ReadPreferenceLong  ("EditorFontSize",  10)
  Prefs\EditorFontStyle      = ReadPreferenceLong  ("EditorFontStyle",  0)
  
  Prefs\BackgroundColor      = ReadPreferenceLong  ("BackgroundColor",     $FFFFFF)
  Prefs\ProcedureBackColor   = ReadPreferenceLong  ("ProcedureBackColor",  $FFFFFF)
  Prefs\LineNumberColor      = ReadPreferenceLong  ("LineNumberColor",     $000000)
  Prefs\LineNumberBackColor  = ReadPreferenceLong  ("LineNumberBackColor", $FFFFFF)
  Prefs\CurrentLineColor     = ReadPreferenceLong  ("CurrentLineColor",    $00FFFF)
  Prefs\SelectionColor       = ReadPreferenceLong  ("SelectionColor",      $808080)
  
  Prefs\TokenColor[#PB_Token_Text     ] = ReadPreferenceLong("NormalTextColor",   $000000)
  Prefs\TokenColor[#PB_Token_Keyword  ] = ReadPreferenceLong("BasicKeywordColor", $000000)
  Prefs\TokenColor[#PB_Token_Comment  ] = ReadPreferenceLong("CommentColor",      $000000)
  Prefs\TokenColor[#PB_Token_Constant ] = ReadPreferenceLong("ConstantColor",     $000000)
  Prefs\TokenColor[#PB_Token_String   ] = ReadPreferenceLong("StringColor",       $000000)
  Prefs\TokenColor[#PB_Token_Function ] = ReadPreferenceLong("PureKeywordColor",  $000000)
  Prefs\TokenColor[#PB_Token_Asm      ] = ReadPreferenceLong("ASMKeywordColor",   $000000)
  Prefs\TokenColor[#PB_Token_Operator ] = ReadPreferenceLong("OperatorColor",     $000000)
  Prefs\TokenColor[#PB_Token_Structure] = ReadPreferenceLong("StructureColor",    $000000)
  Prefs\TokenColor[#PB_Token_Number   ] = ReadPreferenceLong("NumberColor",       $000000)
  Prefs\TokenColor[#PB_Token_Pointer  ] = ReadPreferenceLong("PointerColor",      $000000)
  Prefs\TokenColor[#PB_Token_Separator] = ReadPreferenceLong("SeparatorColor",    $000000)
  Prefs\TokenColor[#PB_Token_Label    ] = ReadPreferenceLong("LabelColor",        $000000)
  
  ClosePreferences()
EndProcedure

ReadPreferences()

;Exemple
Debug "Police de votre IDE " + Prefs\EditorFontName + " Taille " + Prefs\EditorFontSize
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: IDE PureBasic - Lire les préférences

Message par Kwai chang caine »

Merci ça peut être utile 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Shadow
Messages : 1373
Inscription : mer. 04/nov./2015 17:39

Re: IDE PureBasic - Lire les préférences

Message par Shadow »

Merci Falsam :)
Processeur: Intel Core I7-4790 - 4 Cœurs - 8 Thread: 3.60 Ghz.
Ram: 32 GB.
Disque: C: SDD 250 GB, D: 3 TB.
Vidéo: NVIDIA GeForce GTX 960: 2 GB DDR5.
Écran: Asus VX248 24 Pouces: 1920 x 1080.
Système: Windows 7 64 Bits.

PureBasic: 5.60 x64 Bits.
Répondre