| 1 | Unit SettingsUnit;
 | 
|---|
| 2 | 
 | 
|---|
| 3 | // NewView - a new OS/2 Help Viewer
 | 
|---|
| 4 | // Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
 | 
|---|
| 5 | // This software is released under the Gnu Public License - see readme.txt
 | 
|---|
| 6 | 
 | 
|---|
| 7 | Interface
 | 
|---|
| 8 | 
 | 
|---|
| 9 | // Defines settings (options) in a record and contains functions
 | 
|---|
| 10 | // for loading and saving them to ini file.
 | 
|---|
| 11 | 
 | 
|---|
| 12 | Uses
 | 
|---|
| 13 |   Forms,
 | 
|---|
| 14 |   Classes;
 | 
|---|
| 15 | 
 | 
|---|
| 16 | Const
 | 
|---|
| 17 |   ContentsBackgroundColorIndex          = 0;
 | 
|---|
| 18 |   ContentsTextColorIndex                = 1;
 | 
|---|
| 19 |   ContentsLinesColorIndex               = 2;
 | 
|---|
| 20 |   IndexBackgroundColorIndex             = 3;
 | 
|---|
| 21 |   IndexTextColorIndex                   = 4;
 | 
|---|
| 22 |   SearchBackgroundColorIndex            = 5;
 | 
|---|
| 23 |   SearchTextColorIndex                  = 6;
 | 
|---|
| 24 |   NotesListBackgroundColorIndex         = 7;
 | 
|---|
| 25 |   NotesListTextColorIndex               = 8;
 | 
|---|
| 26 |   TopicBackgroundColorIndex             = 9;
 | 
|---|
| 27 |   NotesTextColorIndex                   = 10;
 | 
|---|
| 28 |   SearchHighlightTextColorIndex         = 11;
 | 
|---|
| 29 |   NumColorSettings                      = 12;
 | 
|---|
| 30 | 
 | 
|---|
| 31 |   clLightYellow = $ffffc0;
 | 
|---|
| 32 |   clLightBlue = $e0e0ff;
 | 
|---|
| 33 |   clLightCyan = $c0ffff;
 | 
|---|
| 34 |   clLightGreen = $e0ffe0;
 | 
|---|
| 35 | 
 | 
|---|
| 36 |   VGADefaultColors: array[ 0 .. NumColorSettings - 1 ] of TColor
 | 
|---|
| 37 |    = ( clWindow,
 | 
|---|
| 38 |        clWindowText,
 | 
|---|
| 39 |        clWindowText,
 | 
|---|
| 40 |        clWindow,
 | 
|---|
| 41 |        clWindowText,
 | 
|---|
| 42 |        clWindow,
 | 
|---|
| 43 |        clWindowText,
 | 
|---|
| 44 |        clWindow,
 | 
|---|
| 45 |        clWindowText,
 | 
|---|
| 46 |        clWindow,
 | 
|---|
| 47 |        clGreen,
 | 
|---|
| 48 |        clYellow );
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   DefaultColors: array[ 0 .. NumColorSettings - 1 ] of TColor
 | 
|---|
| 51 |    = ( clLightCyan,
 | 
|---|
| 52 |        clBlack,
 | 
|---|
| 53 |        clBlue,
 | 
|---|
| 54 |        clLightGreen,
 | 
|---|
| 55 |        clBlack,
 | 
|---|
| 56 |        clLightBlue,
 | 
|---|
| 57 |        clBlack,
 | 
|---|
| 58 |        clWhite,
 | 
|---|
| 59 |        clBlack,
 | 
|---|
| 60 |        clWhite,
 | 
|---|
| 61 |        clGreen,
 | 
|---|
| 62 |        clYellow );
 | 
|---|
| 63 | 
 | 
|---|
| 64 |   ApplicationFontIndex = 0;
 | 
|---|
| 65 |   NumFontSettings = 1;
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   DefaultTopicFontName = 'Helv';
 | 
|---|
| 68 |   DefaultTopicFontNameDBCS = 'Helv Combined';
 | 
|---|
| 69 |   DefaultTopicFontSize = 8;
 | 
|---|
| 70 | 
 | 
|---|
| 71 |   DefaultTopicFixedFontName = 'Courier';
 | 
|---|
| 72 |   DefaultTopicFixedFontSize = 8;
 | 
|---|
| 73 | 
 | 
|---|
| 74 | Type
 | 
|---|
| 75 |   TIndexStyle = ( isFileOnly, isAlphabetical, isFull );
 | 
|---|
| 76 |   TToolbarStyle = ( tsNone, tsImages, tsText, tsImagesAndText );
 | 
|---|
| 77 |   TGlobalSearchLocation = ( gsHelpPaths, gsFixedDrives, gsSelectedHelpPaths, gsCustom );
 | 
|---|
| 78 | 
 | 
|---|
| 79 |   TMRUItem = class
 | 
|---|
| 80 |     Title: string;
 | 
|---|
| 81 |     Filenames: TStringList;
 | 
|---|
| 82 |     constructor Create;
 | 
|---|
| 83 |     destructor Destroy; override;
 | 
|---|
| 84 |   end;
 | 
|---|
| 85 | 
 | 
|---|
| 86 |   TSettings = record
 | 
|---|
| 87 |     MRUList: TList;
 | 
|---|
| 88 | 
 | 
|---|
| 89 |     LastOpenDirectory: string;
 | 
|---|
| 90 |     LastSaveDirectory: string;
 | 
|---|
| 91 | 
 | 
|---|
| 92 |     StartupHelp: boolean;
 | 
|---|
| 93 | 
 | 
|---|
| 94 |     LeftPanelWidth: longint;
 | 
|---|
| 95 |     ShowLeftPanel_Help: boolean;
 | 
|---|
| 96 |     ShowLeftPanel_Standalone: boolean;
 | 
|---|
| 97 | 
 | 
|---|
| 98 |     FileDialogSplit: real;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |     // Colours
 | 
|---|
| 101 |     Colors: array[ 0..NumColorSettings - 1 ] of TColor;
 | 
|---|
| 102 | 
 | 
|---|
| 103 |     NormalFont: TFont;
 | 
|---|
| 104 |     FixedFont: TFont;
 | 
|---|
| 105 |     Fonts: array[ 0..NumFontSettings - 1 ] of TFont;
 | 
|---|
| 106 |     FixedFontSubstitution: boolean;
 | 
|---|
| 107 |     FixedFontSubstitutes: string;
 | 
|---|
| 108 | 
 | 
|---|
| 109 |     IndexStyle: TIndexStyle;
 | 
|---|
| 110 | 
 | 
|---|
| 111 |     SmoothScrolling: boolean;
 | 
|---|
| 112 |     UseOriginalDialogs: boolean;
 | 
|---|
| 113 |     OpenWithExpandedContents: boolean;
 | 
|---|
| 114 | 
 | 
|---|
| 115 |     ToolbarBackgroundImageFilename: string;
 | 
|---|
| 116 |     ToolbarStyle: TToolbarStyle;
 | 
|---|
| 117 | 
 | 
|---|
| 118 |     ConfirmWinHelp: boolean;
 | 
|---|
| 119 | 
 | 
|---|
| 120 |     GlobalSearchLocation: TGlobalSearchLocation;
 | 
|---|
| 121 | 
 | 
|---|
| 122 |     SearchDirectories: TStringList;
 | 
|---|
| 123 |   end;
 | 
|---|
| 124 | 
 | 
|---|
| 125 |   Procedure WriteWindowPos( Form: TForm );
 | 
|---|
| 126 |   Procedure ReadWindowPos( Form: TForm );
 | 
|---|
| 127 |   Procedure LoadSettings;
 | 
|---|
| 128 |   Procedure SaveSettings;
 | 
|---|
| 129 | 
 | 
|---|
| 130 |   PROCEDURE writeSettingsDetailsTo(aStrings : TStrings);
 | 
|---|
| 131 | 
 | 
|---|
| 132 | 
 | 
|---|
| 133 | Procedure AddToMRUList( const Title: string;
 | 
|---|
| 134 |                         Filenames: TStrings );
 | 
|---|
| 135 | 
 | 
|---|
| 136 | Var
 | 
|---|
| 137 |   Settings: TSettings;
 | 
|---|
| 138 | 
 | 
|---|
| 139 | Implementation
 | 
|---|
| 140 | 
 | 
|---|
| 141 | Uses
 | 
|---|
| 142 |   SysUtils,
 | 
|---|
| 143 |   PMWin,
 | 
|---|
| 144 |   OS2Def,
 | 
|---|
| 145 |   DebugUnit,
 | 
|---|
| 146 |   Dos,
 | 
|---|
| 147 |   FileUtilsUnit,
 | 
|---|
| 148 |   ACLUtility,
 | 
|---|
| 149 |   StringUtilsUnit,
 | 
|---|
| 150 |   ControlsUtility;
 | 
|---|
| 151 | 
 | 
|---|
| 152 | Const
 | 
|---|
| 153 |   IniFileName = 'NewView.ini';
 | 
|---|
| 154 |   GeneralSection = 'General';
 | 
|---|
| 155 |   FontsSection = 'Fonts';
 | 
|---|
| 156 |   ColoursSection = 'Colours';
 | 
|---|
| 157 |   MRUSection = 'RecentFiles';
 | 
|---|
| 158 |   MRUItemBaseSection = 'RecentFile';
 | 
|---|
| 159 |   SearchSection = 'Search';
 | 
|---|
| 160 | 
 | 
|---|
| 161 |   DefaultWidth = 620;
 | 
|---|
| 162 |   DefaultHeight = 460;
 | 
|---|
| 163 | 
 | 
|---|
| 164 |   MaxMRUListEntries = 9;
 | 
|---|
| 165 | 
 | 
|---|
| 166 | constructor TMRUItem.Create;
 | 
|---|
| 167 | begin
 | 
|---|
| 168 |   Title := '';
 | 
|---|
| 169 |   Filenames := TStringList.Create;
 | 
|---|
| 170 | end;
 | 
|---|
| 171 | 
 | 
|---|
| 172 | destructor TMRUItem.Destroy;
 | 
|---|
| 173 | begin
 | 
|---|
| 174 |   Filenames.Destroy;
 | 
|---|
| 175 | end;
 | 
|---|
| 176 | 
 | 
|---|
| 177 | Function IniFilePath: string;
 | 
|---|
| 178 | Var
 | 
|---|
| 179 |   Dir: string;
 | 
|---|
| 180 |   Name, Ext: string;
 | 
|---|
| 181 |   UserIniFile: string;
 | 
|---|
| 182 | Begin
 | 
|---|
| 183 |  // Put it in the same place as the application
 | 
|---|
| 184 |   UserIniFile := GetApplicationDir;
 | 
|---|
| 185 |   // Note: do NOT combine these two steps. Caused an obscure bug!
 | 
|---|
| 186 |   FSplit( UserIniFile, Dir, Name, Ext );
 | 
|---|
| 187 |   Result := AddDirectorySeparator( Dir ) + IniFileName;
 | 
|---|
| 188 | End;
 | 
|---|
| 189 | 
 | 
|---|
| 190 | // Note: since Sibyl SPCC 2.1.8.3
 | 
|---|
| 191 | // the Ascii ini file constructor does not throw an exception
 | 
|---|
| 192 | procedure GetIniFile( Var IniFile: TMyIniFile );
 | 
|---|
| 193 | begin
 | 
|---|
| 194 |   IniFile := TMyIniFile.Create( IniFilePath );
 | 
|---|
| 195 | end;
 | 
|---|
| 196 | 
 | 
|---|
| 197 | procedure CloseIniFile( Var IniFIle: TMyIniFile );
 | 
|---|
| 198 | begin
 | 
|---|
| 199 |   try
 | 
|---|
| 200 |     LogEvent(LogSettings, 'Calling IniFile.Destroy');
 | 
|---|
| 201 |     IniFile.Destroy;
 | 
|---|
| 202 |   except
 | 
|---|
| 203 |     on E: Exception do
 | 
|---|
| 204 |     begin
 | 
|---|
| 205 |       // don't care if we can't save settings.
 | 
|---|
| 206 |       LogEvent(LogSettings, '  Exception: ' + E.Message );
 | 
|---|
| 207 |     end;
 | 
|---|
| 208 |   end;
 | 
|---|
| 209 | end;
 | 
|---|
| 210 | 
 | 
|---|
| 211 | Procedure LoadSettings;
 | 
|---|
| 212 | Var
 | 
|---|
| 213 |   IniFile: TMyIniFile;
 | 
|---|
| 214 |   ColorIndex: longint;
 | 
|---|
| 215 |   DefaultColor: TColor;
 | 
|---|
| 216 |   FontName: string;
 | 
|---|
| 217 |   SettingString: string;
 | 
|---|
| 218 | 
 | 
|---|
| 219 |   MRUItem: TMRUItem;
 | 
|---|
| 220 |   MRUItemSection: string;
 | 
|---|
| 221 |   MRUItemFileCount: longint;
 | 
|---|
| 222 |   MRUItemFileIndex: longint;
 | 
|---|
| 223 |   i: longint;
 | 
|---|
| 224 |   Count: longint;
 | 
|---|
| 225 |   MRUFilename: string;
 | 
|---|
| 226 |   MRUFileTitle: string;
 | 
|---|
| 227 | Begin
 | 
|---|
| 228 |   GetIniFile( IniFile );
 | 
|---|
| 229 |   with IniFile do
 | 
|---|
| 230 |   begin
 | 
|---|
| 231 |     IniFile.EraseSection( 'Windows' );
 | 
|---|
| 232 |     with Settings do
 | 
|---|
| 233 |     begin
 | 
|---|
| 234 |       LastOpenDirectory := ReadString( GeneralSection, 'LastOpenDirectory', '' );
 | 
|---|
| 235 |       LastSaveDirectory := ReadString( GeneralSection, 'LastSaveDirectory', '' );
 | 
|---|
| 236 | 
 | 
|---|
| 237 |       // Read split points, as units of 0.1%
 | 
|---|
| 238 |       LeftPanelWidth := ReadInteger( GeneralSection, 'LeftPanelWidth', 225 );
 | 
|---|
| 239 |       FileDialogSplit := ReadInteger( GeneralSection, 'FileDialogSplit', 500 ) / 1000;
 | 
|---|
| 240 | 
 | 
|---|
| 241 |       ShowLeftPanel_Help := ReadBool( GeneralSection, 'ShowLeftPanel_Help', true );
 | 
|---|
| 242 |       ShowLeftPanel_Standalone := ReadBool( GeneralSection, 'ShowLeftPanel_Standalone', true );
 | 
|---|
| 243 | 
 | 
|---|
| 244 |       // Colours
 | 
|---|
| 245 |       for ColorIndex := 0 to High( Colors ) do
 | 
|---|
| 246 |       begin
 | 
|---|
| 247 |         if GetScreenColorDepth > 8 then
 | 
|---|
| 248 |            DefaultColor := DefaultColors[ ColorIndex ]
 | 
|---|
| 249 |         else
 | 
|---|
| 250 |            DefaultColor := VGADefaultColors[ ColorIndex ];
 | 
|---|
| 251 |         Colors[ ColorIndex ] := ReadInteger( ColoursSection,
 | 
|---|
| 252 |                                              'Color' + IntToStr( ColorIndex ),
 | 
|---|
| 253 |                                              DefaultColor );
 | 
|---|
| 254 |       end;
 | 
|---|
| 255 | 
 | 
|---|
| 256 |       // Most Recently Used files list...
 | 
|---|
| 257 | 
 | 
|---|
| 258 |       Count := ReadInteger( MRUSection,
 | 
|---|
| 259 |                             'Count',
 | 
|---|
| 260 |                             0 );
 | 
|---|
| 261 | 
 | 
|---|
| 262 |       // Old style MRU list
 | 
|---|
| 263 |       for i := 0 to Count - 1 do
 | 
|---|
| 264 |       begin
 | 
|---|
| 265 |         MRUFilename := ReadString( MRUSection,
 | 
|---|
| 266 |                                    'File' + IntToStr( i ),
 | 
|---|
| 267 |                                    '' );
 | 
|---|
| 268 |         MRUFileTitle := ReadString( MRUSection,
 | 
|---|
| 269 |                                     'Title' + IntToStr( i ),
 | 
|---|
| 270 |                                     '' );
 | 
|---|
| 271 |         if MRUFilename <> '' then
 | 
|---|
| 272 |         begin
 | 
|---|
| 273 |           MRUItem := TMRUItem.Create;
 | 
|---|
| 274 |           MRUItem.Title := MRUFileTitle;
 | 
|---|
| 275 | 
 | 
|---|
| 276 |           StrExtractStrings(MRUItem.Filenames, MRUFilename, ['+'], #0);
 | 
|---|
| 277 |           MRUList.Add( MRUItem );
 | 
|---|
| 278 |         end;
 | 
|---|
| 279 |       end;
 | 
|---|
| 280 | 
 | 
|---|
| 281 |       // New style
 | 
|---|
| 282 |       for i := 0 to Count - 1 do
 | 
|---|
| 283 |       begin
 | 
|---|
| 284 |         MRUItemSection := MRUItemBaseSection + IntToStr( i );
 | 
|---|
| 285 | 
 | 
|---|
| 286 |         MRUItem := TMRUItem.Create;
 | 
|---|
| 287 | 
 | 
|---|
| 288 |         MRUItem.Title := ReadString( MRUItemSection,
 | 
|---|
| 289 |                                      'Title',
 | 
|---|
| 290 |                                      '' );
 | 
|---|
| 291 | 
 | 
|---|
| 292 |         MRUItemFileCount := ReadInteger( MRUItemSection,
 | 
|---|
| 293 |                                          'FileCount',
 | 
|---|
| 294 |                                          0 );
 | 
|---|
| 295 |         for MRUItemFileIndex := 0 to MRUItemFileCount - 1 do
 | 
|---|
| 296 |         begin
 | 
|---|
| 297 |           MRUFilename := ReadString( MRUItemSection,
 | 
|---|
| 298 |                                      'File' + IntToStr( MRUItemFileIndex ),
 | 
|---|
| 299 |                                      '' );
 | 
|---|
| 300 |           if MRUFilename <> '' then
 | 
|---|
| 301 |           begin
 | 
|---|
| 302 |             MRUItem.Filenames.Add( MRUFilename );
 | 
|---|
| 303 |           end;
 | 
|---|
| 304 |         end;
 | 
|---|
| 305 | 
 | 
|---|
| 306 |         if     ( MRUItem.Title <> '' )
 | 
|---|
| 307 |            and ( MRUItem.Filenames.Count > 0 ) then
 | 
|---|
| 308 |         begin
 | 
|---|
| 309 |           // valid MRU item
 | 
|---|
| 310 |           MRUList.Add( MRUItem );
 | 
|---|
| 311 |         end
 | 
|---|
| 312 |         else
 | 
|---|
| 313 |         begin
 | 
|---|
| 314 |           // not valid
 | 
|---|
| 315 |           MRUItem.Destroy;
 | 
|---|
| 316 |           MRUItem := nil;
 | 
|---|
| 317 |         end;
 | 
|---|
| 318 | 
 | 
|---|
| 319 |       end;
 | 
|---|
| 320 | 
 | 
|---|
| 321 |       // Fonts
 | 
|---|
| 322 |       if Application.DBCSSystem then
 | 
|---|
| 323 |         NormalFont := Screen.GetFontFromPointSize(
 | 
|---|
| 324 |           ReadString( FontsSection, 'NormalFont', DefaultTopicFontNameDBCS ),
 | 
|---|
| 325 |           ReadInteger( FontsSection, 'NormalFontSize', DefaultTopicFontSize ) )
 | 
|---|
| 326 |       else
 | 
|---|
| 327 |         NormalFont := Screen.GetFontFromPointSize(
 | 
|---|
| 328 |           ReadString( FontsSection, 'NormalFont', DefaultTopicFontName ),
 | 
|---|
| 329 |           ReadInteger( FontsSection, 'NormalFontSize', DefaultTopicFontSize ) );
 | 
|---|
| 330 |       if NormalFont = nil then
 | 
|---|
| 331 |         NormalFont := Screen.DefaultFont;
 | 
|---|
| 332 | 
 | 
|---|
| 333 |       FixedFont := Screen.GetFontFromPointSize(
 | 
|---|
| 334 |         ReadString( FontsSection, 'FixedFont', DefaultTopicFixedFontName ),
 | 
|---|
| 335 |         ReadInteger( FontsSection, 'FixedFontSize', DefaultTopicFixedFontSize ) );
 | 
|---|
| 336 |       if FixedFont = nil then
 | 
|---|
| 337 |         FixedFont := Screen.DefaultFont;
 | 
|---|
| 338 | 
 | 
|---|
| 339 |       for i := 0 to NumFontSettings - 1 do
 | 
|---|
| 340 |       begin
 | 
|---|
| 341 |         FontName := 'Font' + IntToStr( i );
 | 
|---|
| 342 |         Fonts[ i ] := nil;
 | 
|---|
| 343 |         if ReadBool( FontsSection,
 | 
|---|
| 344 |                      FontName
 | 
|---|
| 345 |                      + 'Customised',
 | 
|---|
| 346 |                      false ) then
 | 
|---|
| 347 |           Fonts[ i ] := Screen.GetFontFromPointSize(
 | 
|---|
| 348 |             ReadString( FontsSection, FontName + 'Face', DefaultTopicFontName ),
 | 
|---|
| 349 |             ReadInteger( FontsSection, FontName + 'Size', 10 ) );
 | 
|---|
| 350 |       end;
 | 
|---|
| 351 | 
 | 
|---|
| 352 |       FixedFontSubstitution := ReadBool( FontsSection, 'FixedFontSubstitution', true );
 | 
|---|
| 353 |       FixedFontSubstitutes := ReadString( FontsSection, 'FixedFontSubstitutes', 'Courier 18x12' );
 | 
|---|
| 354 | 
 | 
|---|
| 355 |       // Index style
 | 
|---|
| 356 |       SettingString := ReadString( GeneralSection, 'IndexStyle', 'Full' );
 | 
|---|
| 357 |       if StrEqualIgnoringCase( SettingString, 'FileOnly' ) then
 | 
|---|
| 358 |         IndexStyle := isFileOnly
 | 
|---|
| 359 |       else if StrEqualIgnoringCase( SettingString, 'Alphabetical' ) then
 | 
|---|
| 360 |         IndexStyle := isAlphabetical
 | 
|---|
| 361 |       else
 | 
|---|
| 362 |         IndexStyle := isFull;
 | 
|---|
| 363 | 
 | 
|---|
| 364 |       StartupHelp := ReadBool( GeneralSection, 'StartupHelp', true );
 | 
|---|
| 365 | 
 | 
|---|
| 366 |       SmoothScrolling := ReadBool( GeneralSection, 'SmoothScrolling', true );
 | 
|---|
| 367 |       UseOriginalDialogs := ReadBool( GeneralSection, 'UseOriginalDialogs', false );
 | 
|---|
| 368 |       OpenWithExpandedContents := ReadBool( GeneralSection, 'OpenWithExpandedContents', false );
 | 
|---|
| 369 | 
 | 
|---|
| 370 |       ToolBarBackgroundImageFilename := ReadString( GeneralSection, 'ToolbarBackground', '' );
 | 
|---|
| 371 |       SettingString := ReadString( GeneralSection, 'ToolbarStyle', 'ImagesAndText' );
 | 
|---|
| 372 | 
 | 
|---|
| 373 |       if StrEqualIgnoringCase( SettingString, 'None' ) then
 | 
|---|
| 374 |         ToolbarStyle := tsNone
 | 
|---|
| 375 |       else if StrEqualIgnoringCase( SettingString, 'Images' ) then
 | 
|---|
| 376 |         ToolbarStyle := tsImages
 | 
|---|
| 377 |       else if StrEqualIgnoringCase( SettingString, 'Text' ) then
 | 
|---|
| 378 |         ToolbarStyle := tsText
 | 
|---|
| 379 |       else
 | 
|---|
| 380 |         ToolbarStyle := tsImagesAndText;
 | 
|---|
| 381 | 
 | 
|---|
| 382 |       ConfirmWinHelp := ReadBool( GeneralSection, 'ConfirmWinHelp', true );
 | 
|---|
| 383 | 
 | 
|---|
| 384 |       Count := ReadInteger( SearchSection,
 | 
|---|
| 385 |                             'CustomDirCount',
 | 
|---|
| 386 |                             0 );
 | 
|---|
| 387 | 
 | 
|---|
| 388 |       SearchDirectories.Clear;
 | 
|---|
| 389 |       for i := 0 to Count - 1 do
 | 
|---|
| 390 |       begin
 | 
|---|
| 391 |         SettingString := ReadString( SearchSection,
 | 
|---|
| 392 |                                      'CustomDir' + IntToStr( i ),
 | 
|---|
| 393 |                                      '' );
 | 
|---|
| 394 |         if trim( SettingString ) <> '' then
 | 
|---|
| 395 |           SearchDirectories.Add( SettingString );
 | 
|---|
| 396 |       end;
 | 
|---|
| 397 | 
 | 
|---|
| 398 |       SettingString := ReadString( SearchSection,
 | 
|---|
| 399 |                                    'Location',
 | 
|---|
| 400 |                                    'HelpPaths' );
 | 
|---|
| 401 |       if StrEqualIgnoringCase( SettingString, 'HelpPaths' ) then
 | 
|---|
| 402 |         GlobalSearchLocation := gsHelpPaths
 | 
|---|
| 403 |       else if StrEqualIgnoringCase( SettingString, 'FixedDrives' ) then
 | 
|---|
| 404 |         GlobalSearchLocation := gsFixedDrives
 | 
|---|
| 405 |       else if StrEqualIgnoringCase( SettingString, 'SelectedHelpPaths' ) then
 | 
|---|
| 406 |         GlobalSearchLocation := gsSelectedHelpPaths
 | 
|---|
| 407 |       else
 | 
|---|
| 408 |         GlobalSearchLocation := gsCustom;
 | 
|---|
| 409 | 
 | 
|---|
| 410 |     end;
 | 
|---|
| 411 |   end;
 | 
|---|
| 412 |   CloseIniFile( IniFile );
 | 
|---|
| 413 | End;
 | 
|---|
| 414 | 
 | 
|---|
| 415 | Procedure SaveSettings;
 | 
|---|
| 416 | Var
 | 
|---|
| 417 |   IniFile: TMyIniFile;
 | 
|---|
| 418 |   ColorIndex: longint;
 | 
|---|
| 419 |   FontIndex: longint;
 | 
|---|
| 420 |   FontName: string;
 | 
|---|
| 421 |   i: longint;
 | 
|---|
| 422 |   MRUItemFileIndex: longint;
 | 
|---|
| 423 |   SettingString: string;
 | 
|---|
| 424 |   MRUItem: TMRUItem;
 | 
|---|
| 425 |   MRUItemSection: string;
 | 
|---|
| 426 | 
 | 
|---|
| 427 | Begin
 | 
|---|
| 428 |   LogEvent(LogSettings, 'SaveSettings' );
 | 
|---|
| 429 |   GetIniFile( IniFile );
 | 
|---|
| 430 |   with IniFile do
 | 
|---|
| 431 |   begin
 | 
|---|
| 432 |     with Settings do
 | 
|---|
| 433 |     begin
 | 
|---|
| 434 |       WriteString( GeneralSection, 'LastOpenDirectory', LastOpenDirectory );
 | 
|---|
| 435 |       WriteString( GeneralSection, 'LastSaveDirectory', LastSaveDirectory );
 | 
|---|
| 436 | 
 | 
|---|
| 437 |       WriteInteger( GeneralSection, 'LeftPanelWidth', LeftPanelWidth );
 | 
|---|
| 438 |       // Write split points, as units of 0.1%
 | 
|---|
| 439 |       WriteInteger( GeneralSection, 'FileDialogSplit', Round( FileDialogSplit * 1000 ) );
 | 
|---|
| 440 | 
 | 
|---|
| 441 |       WriteBool( GeneralSection, 'ShowLeftPanel_Help', ShowLeftPanel_Help );
 | 
|---|
| 442 |       WriteBool( GeneralSection, 'ShowLeftPanel_Standalone', ShowLeftPanel_Standalone );
 | 
|---|
| 443 | 
 | 
|---|
| 444 |       // COlours
 | 
|---|
| 445 |       for ColorIndex := 0 to High( Colors ) do
 | 
|---|
| 446 |         WriteInteger( ColoursSection,
 | 
|---|
| 447 |                       'Color' + IntToStr( ColorIndex ),
 | 
|---|
| 448 |                       Colors[ ColorIndex ] );
 | 
|---|
| 449 | 
 | 
|---|
| 450 |       EraseSection( MRUSection ); // get rid of old style MRU
 | 
|---|
| 451 |       WriteInteger( MRUSection,
 | 
|---|
| 452 |                     'Count',
 | 
|---|
| 453 |                     MRUList.Count );
 | 
|---|
| 454 | 
 | 
|---|
| 455 |       for i := 0 to MRUList.Count - 1 do
 | 
|---|
| 456 |       begin
 | 
|---|
| 457 |         MRUItem := MRUList[ i ];
 | 
|---|
| 458 | 
 | 
|---|
| 459 |         MRUItemSection := MRUItemBaseSection + IntToStr( i );
 | 
|---|
| 460 |         EraseSection( MRUItemSection );
 | 
|---|
| 461 | 
 | 
|---|
| 462 |         WriteString( MRUItemSection,
 | 
|---|
| 463 |                      'Title',
 | 
|---|
| 464 |                      MRUItem.Title );
 | 
|---|
| 465 | 
 | 
|---|
| 466 |         WriteInteger( MRUItemSection,
 | 
|---|
| 467 |                       'FileCount',
 | 
|---|
| 468 |                       MRUItem.Filenames.Count );
 | 
|---|
| 469 | 
 | 
|---|
| 470 |         for MRUItemFileIndex := 0 to MRUItem.Filenames.Count - 1 do
 | 
|---|
| 471 |           WriteString( MRUItemSection,
 | 
|---|
| 472 |                        'File' + IntToStr( MRUItemFileIndex ),
 | 
|---|
| 473 |                        MRUItem.Filenames[ MRUItemFileIndex ] );
 | 
|---|
| 474 |       end;
 | 
|---|
| 475 | 
 | 
|---|
| 476 |       // clear unused sections
 | 
|---|
| 477 |       for i := MRUList.Count to MaxMRUListEntries do
 | 
|---|
| 478 |       begin
 | 
|---|
| 479 |         MRUItemSection := MRUItemBaseSection + IntToStr( i );
 | 
|---|
| 480 |         EraseSection( MRUItemSection );
 | 
|---|
| 481 |       end;
 | 
|---|
| 482 | 
 | 
|---|
| 483 |       WriteString( FontsSection, 'NormalFont', NormalFont.FaceName );
 | 
|---|
| 484 |       WriteInteger( FontsSection, 'NormalFontSize', NormalFont.PointSize );
 | 
|---|
| 485 |       WriteString( FontsSection, 'FixedFont', FixedFont.FaceName );
 | 
|---|
| 486 |       WriteInteger( FontsSection, 'FixedFontSize', FixedFont.PointSize );
 | 
|---|
| 487 | 
 | 
|---|
| 488 |       for FontIndex := 0 to NumFontSettings - 1 do
 | 
|---|
| 489 |       begin
 | 
|---|
| 490 |         FontName := 'Font' + IntToStr( FontIndex );
 | 
|---|
| 491 | 
 | 
|---|
| 492 |         WriteBool( FontsSection, FontName + 'Customised', Fonts[ FontIndex ] <> nil );
 | 
|---|
| 493 | 
 | 
|---|
| 494 |         if Fonts[ FontIndex ] <> nil then
 | 
|---|
| 495 |         begin
 | 
|---|
| 496 |           WriteString( FontsSection, FontName + 'Face', Fonts[ FontIndex ].FaceName );
 | 
|---|
| 497 |           WriteInteger( FontsSection, FontName + 'Size', Fonts[ FontIndex ].PointSize );
 | 
|---|
| 498 |         end;
 | 
|---|
| 499 | 
 | 
|---|
| 500 |       end;
 | 
|---|
| 501 | 
 | 
|---|
| 502 |       WriteBool( FontsSection, 'FixedFontSubstitution', FixedFontSubstitution );
 | 
|---|
| 503 |       WriteString( FontsSection, 'FixedFontSubstitutes', FixedFontSubstitutes );
 | 
|---|
| 504 | 
 | 
|---|
| 505 |       case IndexStyle of
 | 
|---|
| 506 |         isFileOnly:
 | 
|---|
| 507 |           SettingString := 'FileOnly';
 | 
|---|
| 508 |         isAlphabetical:
 | 
|---|
| 509 |           SettingString := 'Alphabetical';
 | 
|---|
| 510 |         isFull:
 | 
|---|
| 511 |           SettingString := 'Full';
 | 
|---|
| 512 |       end;
 | 
|---|
| 513 | 
 | 
|---|
| 514 |       WriteString( GeneralSection, 'IndexStyle', SettingString );
 | 
|---|
| 515 | 
 | 
|---|
| 516 |       WriteBool( GeneralSection, 'StartupHelp', StartupHelp );
 | 
|---|
| 517 | 
 | 
|---|
| 518 |       WriteBool( GeneralSection, 'SmoothScrolling', SmoothScrolling );
 | 
|---|
| 519 |       WriteBool( GeneralSection, 'UseOriginalDialogs', UseOriginalDialogs );
 | 
|---|
| 520 |       WriteBool( GeneralSection, 'OpenWithExpandedContents', OpenWithExpandedContents );
 | 
|---|
| 521 | 
 | 
|---|
| 522 |       WriteString( GeneralSection, 'ToolbarBackground', ToolbarBackgroundImageFilename );
 | 
|---|
| 523 | 
 | 
|---|
| 524 |       case ToolbarStyle of
 | 
|---|
| 525 |         tsNone:
 | 
|---|
| 526 |           SettingString := 'None';
 | 
|---|
| 527 |         tsImages:
 | 
|---|
| 528 |           SettingString := 'Images';
 | 
|---|
| 529 |         tsText:
 | 
|---|
| 530 |           SettingString := 'Text';
 | 
|---|
| 531 |         tsImagesAndText:
 | 
|---|
| 532 |           SettingString := 'ImagesAndText';
 | 
|---|
| 533 |       end;
 | 
|---|
| 534 | 
 | 
|---|
| 535 |       WriteString( GeneralSection, 'ToolbarStyle', SettingString );
 | 
|---|
| 536 | 
 | 
|---|
| 537 |       WriteBool( GeneralSection, 'ConfirmWinHelp', ConfirmWinHelp );
 | 
|---|
| 538 | 
 | 
|---|
| 539 |       WriteInteger( SearchSection,
 | 
|---|
| 540 |                     'CustomDirCount',
 | 
|---|
| 541 |                     SearchDirectories.Count );
 | 
|---|
| 542 | 
 | 
|---|
| 543 |       SearchDirectories.Sorted := true;
 | 
|---|
| 544 |       SearchDirectories.CaseSensitive := false;
 | 
|---|
| 545 |       SearchDirectories.Duplicates := dupIgnore;
 | 
|---|
| 546 | 
 | 
|---|
| 547 |       for i := 0 to SearchDirectories.Count - 1 do
 | 
|---|
| 548 |       begin
 | 
|---|
| 549 |         WriteString( SearchSection,
 | 
|---|
| 550 |                      'CustomDir' + IntToStr( i ),
 | 
|---|
| 551 |                      SearchDirectories[ i ] );
 | 
|---|
| 552 |       end;
 | 
|---|
| 553 | 
 | 
|---|
| 554 |       case GlobalSearchLocation of
 | 
|---|
| 555 |         gsHelpPaths:
 | 
|---|
| 556 |           SettingString := 'HelpPaths';
 | 
|---|
| 557 | 
 | 
|---|
| 558 |         gsFixedDrives:
 | 
|---|
| 559 |           SettingString := 'FixedDrives';
 | 
|---|
| 560 | 
 | 
|---|
| 561 |         gsSelectedHelpPaths:
 | 
|---|
| 562 |           SettingString := 'SelectedHelpPaths';
 | 
|---|
| 563 | 
 | 
|---|
| 564 |         gsCustom:
 | 
|---|
| 565 |           SettingString := 'Custom';
 | 
|---|
| 566 |       end;
 | 
|---|
| 567 | 
 | 
|---|
| 568 |       WriteString( SearchSection,
 | 
|---|
| 569 |                    'Location',
 | 
|---|
| 570 |                    SettingString );
 | 
|---|
| 571 | 
 | 
|---|
| 572 |     end;
 | 
|---|
| 573 |   end;
 | 
|---|
| 574 |   CloseIniFile( IniFile );
 | 
|---|
| 575 |   LogEvent(LogSettings, ' Done' );
 | 
|---|
| 576 | 
 | 
|---|
| 577 | End;
 | 
|---|
| 578 | 
 | 
|---|
| 579 | Procedure AddToMRUList( const Title: string;
 | 
|---|
| 580 |                         Filenames: TStrings );
 | 
|---|
| 581 | var
 | 
|---|
| 582 |   MRUIndex: longint;
 | 
|---|
| 583 |   PreviousMRUIndex: longint;
 | 
|---|
| 584 |   MRUItem: TMRUItem;
 | 
|---|
| 585 | begin
 | 
|---|
| 586 |   PreviousMRUIndex := -1;
 | 
|---|
| 587 |   for MRUIndex := 0 to Settings.MRUList.Count - 1 do
 | 
|---|
| 588 |   begin
 | 
|---|
| 589 |     MRUItem := Settings.MRUList[ MRUIndex ];
 | 
|---|
| 590 | 
 | 
|---|
| 591 |     if     ( MRUItem.Title = Title )
 | 
|---|
| 592 |        and ( MRUItem.Filenames.Equals( Filenames ) ) then
 | 
|---|
| 593 |     begin
 | 
|---|
| 594 |       // found identical entry in the list already.
 | 
|---|
| 595 |       PreviousMRUIndex := MRUIndex;
 | 
|---|
| 596 |       break;
 | 
|---|
| 597 |     end;
 | 
|---|
| 598 |   end;
 | 
|---|
| 599 | 
 | 
|---|
| 600 |   if PreviousMRUIndex > -1 then
 | 
|---|
| 601 |   begin
 | 
|---|
| 602 |     // is already in list, move to top of list
 | 
|---|
| 603 |     MRUItem := Settings.MRUList[ PreviousMRUIndex ];
 | 
|---|
| 604 |     Settings.MRUList.Delete( PreviousMRUIndex );
 | 
|---|
| 605 |   end
 | 
|---|
| 606 |   else
 | 
|---|
| 607 |   begin
 | 
|---|
| 608 |     // not yet in list. Create new
 | 
|---|
| 609 |     MRUItem := TMRUItem.Create;
 | 
|---|
| 610 |     MRUItem.Title := Title;
 | 
|---|
| 611 |     MRUItem.Filenames.Assign( Filenames );
 | 
|---|
| 612 |   end;
 | 
|---|
| 613 | 
 | 
|---|
| 614 |   Settings.MRUList.Insert( 0, MRUItem );
 | 
|---|
| 615 | 
 | 
|---|
| 616 |   while Settings.MRUList.Count > MaxMRUListEntries do
 | 
|---|
| 617 |   begin
 | 
|---|
| 618 |     MRUItem := Settings.MRUList[ MaxMRUListEntries ];
 | 
|---|
| 619 |     Settings.MRUList.Delete( MaxMRUListEntries );
 | 
|---|
| 620 |     MRUItem.Destroy;
 | 
|---|
| 621 |   end;
 | 
|---|
| 622 | end;
 | 
|---|
| 623 | 
 | 
|---|
| 624 | Procedure WriteWindowPos( Form: TForm );
 | 
|---|
| 625 | Var
 | 
|---|
| 626 |   IniFile: TMyIniFile;
 | 
|---|
| 627 | Begin
 | 
|---|
| 628 |   GetIniFile( IniFile );
 | 
|---|
| 629 |   SaveFormSizePosition( Form, IniFile );
 | 
|---|
| 630 |   CloseIniFile( IniFile );
 | 
|---|
| 631 | End;
 | 
|---|
| 632 | 
 | 
|---|
| 633 | Procedure ReadWindowPos( Form: TForm );
 | 
|---|
| 634 | Var
 | 
|---|
| 635 |   IniFile: TMyIniFile;
 | 
|---|
| 636 | Begin
 | 
|---|
| 637 |   GetIniFile( IniFile );
 | 
|---|
| 638 |   LoadFormSizePosition( Form, IniFile );
 | 
|---|
| 639 |   CloseIniFile( IniFile );
 | 
|---|
| 640 | End;
 | 
|---|
| 641 | 
 | 
|---|
| 642 |   PROCEDURE writeSettingsDetailsTo(aStrings : TStrings);
 | 
|---|
| 643 |   Var
 | 
|---|
| 644 |       tmpRect : RECTL;
 | 
|---|
| 645 |       // DesktopHWND : HWND=0;
 | 
|---|
| 646 |   Begin
 | 
|---|
| 647 |     aStrings.Add('');
 | 
|---|
| 648 |     aStrings.Add('---- Settings ----');
 | 
|---|
| 649 |     aStrings.Add('info WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN): ' + IntToStr(WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN)));
 | 
|---|
| 650 |     aStrings.Add('info Screen.Width: ' + IntToStr(Screen.Width));
 | 
|---|
| 651 | 
 | 
|---|
| 652 |     // some tests
 | 
|---|
| 653 |     {
 | 
|---|
| 654 |     WinQueryWindowRect(HWND_DESKTOP, tmpRect);
 | 
|---|
| 655 |     aStrings.Add('info: WinQueryWindowRect(HWND_DESKTOP, tmpRect)');
 | 
|---|
| 656 |     aStrings.Add('info: ' + IntToStr(tmpRect.xLeft) + ', ' + IntToStr(tmpRect.yBottom) + ', ' + IntToStr(tmpRect.xRight) + ', ' + IntToStr(tmpRect.yTop));
 | 
|---|
| 657 |     If DesktopHWND = 0 Then DesktopHWND := WinQueryDesktopWindow(AppHandle, 0);
 | 
|---|
| 658 |     WinQueryWindowRect(DesktopHWND, tmpRect);
 | 
|---|
| 659 |     aStrings.Add('info: WinQueryWindowRect(DesktopHWND, tmpRect)');
 | 
|---|
| 660 |     aStrings.Add('info: ' + IntToStr(tmpRect.xLeft) + ', ' + IntToStr(tmpRect.yBottom) + ', ' + IntToStr(tmpRect.xRight) + ', ' + IntToStr(tmpRect.yTop));
 | 
|---|
| 661 |     }
 | 
|---|
| 662 | 
 | 
|---|
| 663 |     aStrings.Add('LastOpenDirectory: ' + Settings.LastOpenDirectory);
 | 
|---|
| 664 |     aStrings.Add('LastSaveDirectory: ' + Settings.LastSaveDirectory);
 | 
|---|
| 665 |     aStrings.Add('StartupHelp:       ' + boolToStr(Settings.StartupHelp));
 | 
|---|
| 666 |     // LeftPanelWidth: longint;
 | 
|---|
| 667 |     aStrings.Add('ShowLeftPanel_Help: ' + boolToStr(Settings.ShowLeftPanel_Help));
 | 
|---|
| 668 |     aStrings.Add('ShowLeftPanel_Standalone: ' + boolToStr(Settings.ShowLeftPanel_Standalone));
 | 
|---|
| 669 |     // FileDialogSplit: real;
 | 
|---|
| 670 |     // Colors: array[ 0..NumColorSettings - 1 ] of TColor;
 | 
|---|
| 671 |     // NormalFont: TFont;
 | 
|---|
| 672 |     // FixedFont: TFont;
 | 
|---|
| 673 |     // Fonts: array[ 0..NumFontSettings - 1 ] of TFont;
 | 
|---|
| 674 |     aStrings.Add('FixedFontSubstitution: ' + boolToStr(Settings.FixedFontSubstitution));
 | 
|---|
| 675 |     aStrings.Add('FixedFontSubstitutes: ' + Settings.FixedFontSubstitutes);
 | 
|---|
| 676 |     // IndexStyle: TIndexStyle;
 | 
|---|
| 677 |     aStrings.Add('SmoothScrolling: ' + boolToStr(Settings.SmoothScrolling));
 | 
|---|
| 678 |     aStrings.Add('UseOriginalDialogs: ' + boolToStr(Settings.UseOriginalDialogs));
 | 
|---|
| 679 |     aStrings.Add('OpenWithExpandedContents: ' + boolToStr(Settings.OpenWithExpandedContents));
 | 
|---|
| 680 |     aStrings.Add('ToolbarBackgroundImageFilename: ' + Settings.ToolbarBackgroundImageFilename);
 | 
|---|
| 681 |     // ToolbarStyle: TToolbarStyle;
 | 
|---|
| 682 |     aStrings.Add('ConfirmWinHelp: ' + boolToStr(Settings.ConfirmWinHelp));
 | 
|---|
| 683 |     // GlobalSearchLocation: TGlobalSearchLocation;
 | 
|---|
| 684 |     // SearchDirectories: TStringList;
 | 
|---|
| 685 |   end;
 | 
|---|
| 686 | 
 | 
|---|
| 687 | 
 | 
|---|
| 688 | Initialization
 | 
|---|
| 689 |   Settings.NormalFont := Screen.GetFontFromPointSize( 'Helv',
 | 
|---|
| 690 |                                                       8 );
 | 
|---|
| 691 |   Settings.FixedFont := Screen.GetFontFromPointSize( 'Courier',
 | 
|---|
| 692 |                                                       8 );
 | 
|---|
| 693 |   Settings.SearchDirectories := TStringList.Create;
 | 
|---|
| 694 | 
 | 
|---|
| 695 | Finalization
 | 
|---|
| 696 |   Settings.NormalFont.Destroy;
 | 
|---|
| 697 |   Settings.FixedFont.Destroy;
 | 
|---|
| 698 |   Settings.SearchDirectories.Destroy;
 | 
|---|
| 699 | End.
 | 
|---|