| 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 |   DefaultTopicFontSize = 8;
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   DefaultTopicFixedFontName = 'Courier';
 | 
|---|
| 71 |   DefaultTopicFixedFontSize = 8;
 | 
|---|
| 72 | 
 | 
|---|
| 73 | Type
 | 
|---|
| 74 |   TIndexStyle = ( isFileOnly, isAlphabetical, isFull );
 | 
|---|
| 75 |   TToolbarStyle = ( tsNone, tsImages, tsText, tsImagesAndText );
 | 
|---|
| 76 |   TGlobalSearchLocation = ( gsHelpPaths, gsFixedDrives, gsSelectedHelpPaths, gsCustom );
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   TMRUItem = class
 | 
|---|
| 79 |     Title: string;
 | 
|---|
| 80 |     Filenames: TStringList;
 | 
|---|
| 81 |     constructor Create;
 | 
|---|
| 82 |     destructor Destroy; override;
 | 
|---|
| 83 |   end;
 | 
|---|
| 84 | 
 | 
|---|
| 85 |   TSettings = record
 | 
|---|
| 86 |     MRUList: TList;
 | 
|---|
| 87 | 
 | 
|---|
| 88 |     LastOpenDirectory: string;
 | 
|---|
| 89 |     LastSaveDirectory: string;
 | 
|---|
| 90 | 
 | 
|---|
| 91 |     StartupHelp: boolean;
 | 
|---|
| 92 | 
 | 
|---|
| 93 |     LeftPanelWidth: longint;
 | 
|---|
| 94 |     ShowLeftPanel_Help: boolean;
 | 
|---|
| 95 |     ShowLeftPanel_Standalone: boolean;
 | 
|---|
| 96 | 
 | 
|---|
| 97 |     FileDialogSplit: real;
 | 
|---|
| 98 | 
 | 
|---|
| 99 |     // COlours
 | 
|---|
| 100 |     Colors: array[ 0..NumColorSettings - 1 ] of TColor;
 | 
|---|
| 101 | 
 | 
|---|
| 102 |     NormalFont: TFont;
 | 
|---|
| 103 |     FixedFont: TFont;
 | 
|---|
| 104 |     Fonts: array[ 0..NumFontSettings - 1 ] of TFont;
 | 
|---|
| 105 |     FixedFontSubstitution: boolean;
 | 
|---|
| 106 |     FixedFontSubstitutes: string;
 | 
|---|
| 107 | 
 | 
|---|
| 108 |     IndexStyle: TIndexStyle;
 | 
|---|
| 109 | 
 | 
|---|
| 110 |     SmoothScrolling: boolean;
 | 
|---|
| 111 |     UseOriginalDialogs: boolean;
 | 
|---|
| 112 |     OpenWithExpandedContents: boolean;
 | 
|---|
| 113 | 
 | 
|---|
| 114 |     ToolbarBackgroundImageFilename: string;
 | 
|---|
| 115 |     ToolbarStyle: TToolbarStyle;
 | 
|---|
| 116 | 
 | 
|---|
| 117 |     ConfirmWinHelp: boolean;
 | 
|---|
| 118 | 
 | 
|---|
| 119 |     GlobalSearchLocation: TGlobalSearchLocation;
 | 
|---|
| 120 | 
 | 
|---|
| 121 |     SearchDirectories: TStringList;
 | 
|---|
| 122 |   end;
 | 
|---|
| 123 | 
 | 
|---|
| 124 |   Procedure WriteWindowPos( Form: TForm );
 | 
|---|
| 125 |   Procedure ReadWindowPos( Form: TForm );
 | 
|---|
| 126 |   Procedure LoadSettings;
 | 
|---|
| 127 |   Procedure SaveSettings;
 | 
|---|
| 128 | 
 | 
|---|
| 129 | Procedure AddToMRUList( const Title: string;
 | 
|---|
| 130 |                         Filenames: TStrings );
 | 
|---|
| 131 | 
 | 
|---|
| 132 | Var
 | 
|---|
| 133 |   Settings: TSettings;
 | 
|---|
| 134 | 
 | 
|---|
| 135 | Implementation
 | 
|---|
| 136 | 
 | 
|---|
| 137 | Uses
 | 
|---|
| 138 |   SysUtils,
 | 
|---|
| 139 |   DebugUnit,
 | 
|---|
| 140 |   Dos,
 | 
|---|
| 141 |   ACLFileUtility,
 | 
|---|
| 142 |   ACLUtility,
 | 
|---|
| 143 |   ACLStringUtility,
 | 
|---|
| 144 |   ControlsUtility;
 | 
|---|
| 145 | 
 | 
|---|
| 146 | Const
 | 
|---|
| 147 |   IniFileName = 'NewView.ini';
 | 
|---|
| 148 |   GeneralSection = 'General';
 | 
|---|
| 149 |   FontsSection = 'Fonts';
 | 
|---|
| 150 |   ColoursSection = 'Colours';
 | 
|---|
| 151 |   MRUSection = 'RecentFiles';
 | 
|---|
| 152 |   MRUItemBaseSection = 'RecentFile';
 | 
|---|
| 153 |   SearchSection = 'Search';
 | 
|---|
| 154 | 
 | 
|---|
| 155 |   DefaultWidth = 620;
 | 
|---|
| 156 |   DefaultHeight = 460;
 | 
|---|
| 157 | 
 | 
|---|
| 158 |   MaxMRUListEntries = 9;
 | 
|---|
| 159 | 
 | 
|---|
| 160 | constructor TMRUItem.Create;
 | 
|---|
| 161 | begin
 | 
|---|
| 162 |   Title := '';
 | 
|---|
| 163 |   Filenames := TStringList.Create;
 | 
|---|
| 164 | end;
 | 
|---|
| 165 | 
 | 
|---|
| 166 | destructor TMRUItem.Destroy;
 | 
|---|
| 167 | begin
 | 
|---|
| 168 |   Filenames.Destroy;
 | 
|---|
| 169 | end;
 | 
|---|
| 170 | 
 | 
|---|
| 171 | Function IniFilePath: string;
 | 
|---|
| 172 | Var
 | 
|---|
| 173 |   Dir: string;
 | 
|---|
| 174 |   Name, Ext: string;
 | 
|---|
| 175 |   UserIniFile: string;
 | 
|---|
| 176 | Begin
 | 
|---|
| 177 |  // Put it in the same place as the application
 | 
|---|
| 178 |   UserIniFile := GetApplicationDir;
 | 
|---|
| 179 |   // Note: do NOT combine these two steps. Caused an obscure bug!
 | 
|---|
| 180 |   FSplit( UserIniFile, Dir, Name, Ext );
 | 
|---|
| 181 |   Result := AddSlash( Dir ) + IniFileName;
 | 
|---|
| 182 | End;
 | 
|---|
| 183 | 
 | 
|---|
| 184 | // Note: since Sibyl SPCC 2.1.8.3
 | 
|---|
| 185 | // the Ascii ini file constructor does not throw an exception
 | 
|---|
| 186 | procedure GetIniFile( Var IniFile: TMyIniFile );
 | 
|---|
| 187 | begin
 | 
|---|
| 188 |   IniFile := TMyIniFile.Create( IniFilePath );
 | 
|---|
| 189 | end;
 | 
|---|
| 190 | 
 | 
|---|
| 191 | procedure CloseIniFile( Var IniFIle: TMyIniFile );
 | 
|---|
| 192 | begin
 | 
|---|
| 193 |   try
 | 
|---|
| 194 |     LogEvent(LogSettings, 'Calling IniFile.Destroy');
 | 
|---|
| 195 |     IniFile.Destroy;
 | 
|---|
| 196 |   except
 | 
|---|
| 197 |     on E: Exception do
 | 
|---|
| 198 |     begin
 | 
|---|
| 199 |       // don't care if we can't save settings.
 | 
|---|
| 200 |       LogEvent(LogSettings, '  Exception: ' + E.Message );
 | 
|---|
| 201 |     end;
 | 
|---|
| 202 |   end;
 | 
|---|
| 203 | end;
 | 
|---|
| 204 | 
 | 
|---|
| 205 | Procedure LoadSettings;
 | 
|---|
| 206 | Var
 | 
|---|
| 207 |   IniFile: TMyIniFile;
 | 
|---|
| 208 |   ColorIndex: longint;
 | 
|---|
| 209 |   DefaultColor: TColor;
 | 
|---|
| 210 |   FontName: string;
 | 
|---|
| 211 |   SettingString: string;
 | 
|---|
| 212 | 
 | 
|---|
| 213 |   MRUItem: TMRUItem;
 | 
|---|
| 214 |   MRUItemSection: string;
 | 
|---|
| 215 |   MRUItemFileCount: longint;
 | 
|---|
| 216 |   MRUItemFileIndex: longint;
 | 
|---|
| 217 |   i: longint;
 | 
|---|
| 218 |   Count: longint;
 | 
|---|
| 219 |   MRUFilename: string;
 | 
|---|
| 220 |   MRUFileTitle: string;
 | 
|---|
| 221 | Begin
 | 
|---|
| 222 |   GetIniFile( IniFile );
 | 
|---|
| 223 |   with IniFile do
 | 
|---|
| 224 |   begin
 | 
|---|
| 225 |     IniFile.EraseSection( 'Windows' );
 | 
|---|
| 226 |     with Settings do
 | 
|---|
| 227 |     begin
 | 
|---|
| 228 |       LastOpenDirectory := ReadString( GeneralSection, 'LastOpenDirectory', '' );
 | 
|---|
| 229 |       LastSaveDirectory := ReadString( GeneralSection, 'LastSaveDirectory', '' );
 | 
|---|
| 230 | 
 | 
|---|
| 231 |       // Read split points, as units of 0.1%
 | 
|---|
| 232 |       LeftPanelWidth := ReadInteger( GeneralSection, 'LeftPanelWidth', 225 );
 | 
|---|
| 233 |       FileDialogSplit := ReadInteger( GeneralSection, 'FileDialogSplit', 500 ) / 1000;
 | 
|---|
| 234 | 
 | 
|---|
| 235 |       ShowLeftPanel_Help := ReadBool( GeneralSection, 'ShowLeftPanel_Help', false );
 | 
|---|
| 236 |       ShowLeftPanel_Standalone := ReadBool( GeneralSection, 'ShowLeftPanel_Standalone', true );
 | 
|---|
| 237 | 
 | 
|---|
| 238 |       // Colours
 | 
|---|
| 239 |       for ColorIndex := 0 to High( Colors ) do
 | 
|---|
| 240 |       begin
 | 
|---|
| 241 |         if GetScreenColorDepth > 8 then
 | 
|---|
| 242 |            DefaultColor := DefaultColors[ ColorIndex ]
 | 
|---|
| 243 |         else
 | 
|---|
| 244 |            DefaultColor := VGADefaultColors[ ColorIndex ];
 | 
|---|
| 245 |         Colors[ ColorIndex ] := ReadInteger( ColoursSection,
 | 
|---|
| 246 |                                              'Color' + IntToStr( ColorIndex ),
 | 
|---|
| 247 |                                              DefaultColor );
 | 
|---|
| 248 |       end;
 | 
|---|
| 249 | 
 | 
|---|
| 250 |       // Most Recently Used files list...
 | 
|---|
| 251 | 
 | 
|---|
| 252 |       Count := ReadInteger( MRUSection,
 | 
|---|
| 253 |                             'Count',
 | 
|---|
| 254 |                             0 );
 | 
|---|
| 255 | 
 | 
|---|
| 256 |       // Old style MRU list
 | 
|---|
| 257 |       for i := 0 to Count - 1 do
 | 
|---|
| 258 |       begin
 | 
|---|
| 259 |         MRUFilename := ReadString( MRUSection,
 | 
|---|
| 260 |                                    'File' + IntToStr( i ),
 | 
|---|
| 261 |                                    '' );
 | 
|---|
| 262 |         MRUFileTitle := ReadString( MRUSection,
 | 
|---|
| 263 |                                     'Title' + IntToStr( i ),
 | 
|---|
| 264 |                                     '' );
 | 
|---|
| 265 |         if MRUFilename <> '' then
 | 
|---|
| 266 |         begin
 | 
|---|
| 267 |           MRUItem := TMRUItem.Create;
 | 
|---|
| 268 |           MRUItem.Title := MRUFileTitle;
 | 
|---|
| 269 |           StringToList( MRUFilename,
 | 
|---|
| 270 |                         MRUItem.Filenames,
 | 
|---|
| 271 |                         '+' );
 | 
|---|
| 272 |           MRUList.Add( MRUItem );
 | 
|---|
| 273 |         end;
 | 
|---|
| 274 |       end;
 | 
|---|
| 275 | 
 | 
|---|
| 276 |       // New style
 | 
|---|
| 277 |       for i := 0 to Count - 1 do
 | 
|---|
| 278 |       begin
 | 
|---|
| 279 |         MRUItemSection := MRUItemBaseSection + IntToStr( i );
 | 
|---|
| 280 | 
 | 
|---|
| 281 |         MRUItem := TMRUItem.Create;
 | 
|---|
| 282 | 
 | 
|---|
| 283 |         MRUItem.Title := ReadString( MRUItemSection,
 | 
|---|
| 284 |                                      'Title',
 | 
|---|
| 285 |                                      '' );
 | 
|---|
| 286 | 
 | 
|---|
| 287 |         MRUItemFileCount := ReadInteger( MRUItemSection,
 | 
|---|
| 288 |                                          'FileCount',
 | 
|---|
| 289 |                                          0 );
 | 
|---|
| 290 |         for MRUItemFileIndex := 0 to MRUItemFileCount - 1 do
 | 
|---|
| 291 |         begin
 | 
|---|
| 292 |           MRUFilename := ReadString( MRUItemSection,
 | 
|---|
| 293 |                                      'File' + IntToStr( MRUItemFileIndex ),
 | 
|---|
| 294 |                                      '' );
 | 
|---|
| 295 |           if MRUFilename <> '' then
 | 
|---|
| 296 |           begin
 | 
|---|
| 297 |             MRUItem.Filenames.Add( MRUFilename );
 | 
|---|
| 298 |           end;
 | 
|---|
| 299 |         end;
 | 
|---|
| 300 | 
 | 
|---|
| 301 |         if     ( MRUItem.Title <> '' )
 | 
|---|
| 302 |            and ( MRUItem.Filenames.Count > 0 ) then
 | 
|---|
| 303 |         begin
 | 
|---|
| 304 |           // valid MRU item
 | 
|---|
| 305 |           MRUList.Add( MRUItem );
 | 
|---|
| 306 |         end
 | 
|---|
| 307 |         else
 | 
|---|
| 308 |         begin
 | 
|---|
| 309 |           // not valid
 | 
|---|
| 310 |           MRUItem.Destroy;
 | 
|---|
| 311 |           MRUItem := nil;
 | 
|---|
| 312 |         end;
 | 
|---|
| 313 | 
 | 
|---|
| 314 |       end;
 | 
|---|
| 315 | 
 | 
|---|
| 316 |       // Fonts
 | 
|---|
| 317 |       NormalFont := Screen.GetFontFromPointSize(
 | 
|---|
| 318 |         ReadString( FontsSection, 'NormalFont', DefaultTopicFontName ),
 | 
|---|
| 319 |         ReadInteger( FontsSection, 'NormalFontSize', DefaultTopicFontSize ) );
 | 
|---|
| 320 |       if NormalFont = nil then
 | 
|---|
| 321 |         NormalFont := Screen.DefaultFont;
 | 
|---|
| 322 | 
 | 
|---|
| 323 |       FixedFont := Screen.GetFontFromPointSize(
 | 
|---|
| 324 |         ReadString( FontsSection, 'FixedFont', DefaultTopicFixedFontName ),
 | 
|---|
| 325 |         ReadInteger( FontsSection, 'FixedFontSize', DefaultTopicFixedFontSize ) );
 | 
|---|
| 326 |       if FixedFont = nil then
 | 
|---|
| 327 |         FixedFont := Screen.DefaultFont;
 | 
|---|
| 328 | 
 | 
|---|
| 329 |       for i := 0 to NumFontSettings - 1 do
 | 
|---|
| 330 |       begin
 | 
|---|
| 331 |         FontName := 'Font' + IntToStr( i );
 | 
|---|
| 332 |         Fonts[ i ] := nil;
 | 
|---|
| 333 |         if ReadBool( FontsSection,
 | 
|---|
| 334 |                      FontName
 | 
|---|
| 335 |                      + 'Customised',
 | 
|---|
| 336 |                      false ) then
 | 
|---|
| 337 |           Fonts[ i ] := Screen.GetFontFromPointSize(
 | 
|---|
| 338 |             ReadString( FontsSection, FontName + 'Face', DefaultTopicFontName ),
 | 
|---|
| 339 |             ReadInteger( FontsSection, FontName + 'Size', 10 ) );
 | 
|---|
| 340 |       end;
 | 
|---|
| 341 | 
 | 
|---|
| 342 |       FixedFontSubstitution := ReadBool( FontsSection, 'FixedFontSubstitution', true );
 | 
|---|
| 343 |       FixedFontSubstitutes := ReadString( FontsSection, 'FixedFontSubstitutes', 'Courier 18x12' );
 | 
|---|
| 344 | 
 | 
|---|
| 345 |       // Index style
 | 
|---|
| 346 |       SettingString := ReadString( GeneralSection, 'IndexStyle', 'Full' );
 | 
|---|
| 347 |       if StringsSame( SettingString, 'FileOnly' ) then
 | 
|---|
| 348 |         IndexStyle := isFileOnly
 | 
|---|
| 349 |       else if StringsSame( SettingString, 'Alphabetical' ) then
 | 
|---|
| 350 |         IndexStyle := isAlphabetical
 | 
|---|
| 351 |       else
 | 
|---|
| 352 |         IndexStyle := isFull;
 | 
|---|
| 353 | 
 | 
|---|
| 354 |       StartupHelp := ReadBool( GeneralSection, 'StartupHelp', true );
 | 
|---|
| 355 | 
 | 
|---|
| 356 |       SmoothScrolling := ReadBool( GeneralSection, 'SmoothScrolling', true );
 | 
|---|
| 357 |       UseOriginalDialogs := ReadBool( GeneralSection, 'UseOriginalDialogs', false );
 | 
|---|
| 358 |       OpenWithExpandedContents := ReadBool( GeneralSection, 'OpenWithExpandedContents', false );
 | 
|---|
| 359 | 
 | 
|---|
| 360 |       ToolBarBackgroundImageFilename := ReadString( GeneralSection, 'ToolbarBackground', '' );
 | 
|---|
| 361 |       SettingString := ReadString( GeneralSection, 'ToolbarStyle', 'ImagesAndText' );
 | 
|---|
| 362 | 
 | 
|---|
| 363 |       if StringsSame( SettingString, 'None' ) then
 | 
|---|
| 364 |         ToolbarStyle := tsNone
 | 
|---|
| 365 |       else if StringsSame( SettingString, 'Images' ) then
 | 
|---|
| 366 |         ToolbarStyle := tsImages
 | 
|---|
| 367 |       else if StringsSame( SettingString, 'Text' ) then
 | 
|---|
| 368 |         ToolbarStyle := tsText
 | 
|---|
| 369 |       else
 | 
|---|
| 370 |         ToolbarStyle := tsImagesAndText;
 | 
|---|
| 371 | 
 | 
|---|
| 372 |       ConfirmWinHelp := ReadBool( GeneralSection, 'ConfirmWinHelp', true );
 | 
|---|
| 373 | 
 | 
|---|
| 374 |       Count := ReadInteger( SearchSection,
 | 
|---|
| 375 |                             'CustomDirCount',
 | 
|---|
| 376 |                             0 );
 | 
|---|
| 377 | 
 | 
|---|
| 378 |       SearchDirectories.Clear;
 | 
|---|
| 379 |       for i := 0 to Count - 1 do
 | 
|---|
| 380 |       begin
 | 
|---|
| 381 |         SettingString := ReadString( SearchSection,
 | 
|---|
| 382 |                                      'CustomDir' + IntToStr( i ),
 | 
|---|
| 383 |                                      '' );
 | 
|---|
| 384 |         if trim( SettingString ) <> '' then
 | 
|---|
| 385 |           SearchDirectories.Add( SettingString );
 | 
|---|
| 386 |       end;
 | 
|---|
| 387 | 
 | 
|---|
| 388 |       SettingString := ReadString( SearchSection,
 | 
|---|
| 389 |                                    'Location',
 | 
|---|
| 390 |                                    'HelpPaths' );
 | 
|---|
| 391 |       if StringsSame( SettingString, 'HelpPaths' ) then
 | 
|---|
| 392 |         GlobalSearchLocation := gsHelpPaths
 | 
|---|
| 393 |       else if StringsSame( SettingString, 'FixedDrives' ) then
 | 
|---|
| 394 |         GlobalSearchLocation := gsFixedDrives
 | 
|---|
| 395 |       else if StringsSame( SettingString, 'SelectedHelpPaths' ) then
 | 
|---|
| 396 |         GlobalSearchLocation := gsSelectedHelpPaths
 | 
|---|
| 397 |       else
 | 
|---|
| 398 |         GlobalSearchLocation := gsCustom;
 | 
|---|
| 399 | 
 | 
|---|
| 400 |     end;
 | 
|---|
| 401 |   end;
 | 
|---|
| 402 |   CloseIniFile( IniFile );
 | 
|---|
| 403 | End;
 | 
|---|
| 404 | 
 | 
|---|
| 405 | Procedure SaveSettings;
 | 
|---|
| 406 | Var
 | 
|---|
| 407 |   IniFile: TMyIniFile;
 | 
|---|
| 408 |   ColorIndex: longint;
 | 
|---|
| 409 |   FontIndex: longint;
 | 
|---|
| 410 |   FontName: string;
 | 
|---|
| 411 |   i: longint;
 | 
|---|
| 412 |   MRUItemFileIndex: longint;
 | 
|---|
| 413 |   SettingString: string;
 | 
|---|
| 414 |   MRUItem: TMRUItem;
 | 
|---|
| 415 |   MRUItemSection: string;
 | 
|---|
| 416 | 
 | 
|---|
| 417 | Begin
 | 
|---|
| 418 |   LogEvent(LogSettings, 'SaveSettings' );
 | 
|---|
| 419 |   GetIniFile( IniFile );
 | 
|---|
| 420 |   with IniFile do
 | 
|---|
| 421 |   begin
 | 
|---|
| 422 |     with Settings do
 | 
|---|
| 423 |     begin
 | 
|---|
| 424 |       WriteString( GeneralSection, 'LastOpenDirectory', LastOpenDirectory );
 | 
|---|
| 425 |       WriteString( GeneralSection, 'LastSaveDirectory', LastSaveDirectory );
 | 
|---|
| 426 | 
 | 
|---|
| 427 |       WriteInteger( GeneralSection, 'LeftPanelWidth', LeftPanelWidth );
 | 
|---|
| 428 |       // Write split points, as units of 0.1%
 | 
|---|
| 429 |       WriteInteger( GeneralSection, 'FileDialogSplit', Round( FileDialogSplit * 1000 ) );
 | 
|---|
| 430 | 
 | 
|---|
| 431 |       WriteBool( GeneralSection, 'ShowLeftPanel_Help', ShowLeftPanel_Help );
 | 
|---|
| 432 |       WriteBool( GeneralSection, 'ShowLeftPanel_Standalone', ShowLeftPanel_Standalone );
 | 
|---|
| 433 | 
 | 
|---|
| 434 |       // COlours
 | 
|---|
| 435 |       for ColorIndex := 0 to High( Colors ) do
 | 
|---|
| 436 |         WriteInteger( ColoursSection,
 | 
|---|
| 437 |                       'Color' + IntToStr( ColorIndex ),
 | 
|---|
| 438 |                       Colors[ ColorIndex ] );
 | 
|---|
| 439 | 
 | 
|---|
| 440 |       EraseSection( MRUSection ); // get rid of old style MRU
 | 
|---|
| 441 |       WriteInteger( MRUSection,
 | 
|---|
| 442 |                     'Count',
 | 
|---|
| 443 |                     MRUList.Count );
 | 
|---|
| 444 | 
 | 
|---|
| 445 |       for i := 0 to MRUList.Count - 1 do
 | 
|---|
| 446 |       begin
 | 
|---|
| 447 |         MRUItem := MRUList[ i ];
 | 
|---|
| 448 | 
 | 
|---|
| 449 |         MRUItemSection := MRUItemBaseSection + IntToStr( i );
 | 
|---|
| 450 |         EraseSection( MRUItemSection );
 | 
|---|
| 451 | 
 | 
|---|
| 452 |         WriteString( MRUItemSection,
 | 
|---|
| 453 |                      'Title',
 | 
|---|
| 454 |                      MRUItem.Title );
 | 
|---|
| 455 | 
 | 
|---|
| 456 |         WriteInteger( MRUItemSection,
 | 
|---|
| 457 |                       'FileCount',
 | 
|---|
| 458 |                       MRUItem.Filenames.Count );
 | 
|---|
| 459 | 
 | 
|---|
| 460 |         for MRUItemFileIndex := 0 to MRUItem.Filenames.Count - 1 do
 | 
|---|
| 461 |           WriteString( MRUItemSection,
 | 
|---|
| 462 |                        'File' + IntToStr( MRUItemFileIndex ),
 | 
|---|
| 463 |                        MRUItem.Filenames[ MRUItemFileIndex ] );
 | 
|---|
| 464 |       end;
 | 
|---|
| 465 | 
 | 
|---|
| 466 |       // clear unused sections
 | 
|---|
| 467 |       for i := MRUList.Count to MaxMRUListEntries do
 | 
|---|
| 468 |       begin
 | 
|---|
| 469 |         MRUItemSection := MRUItemBaseSection + IntToStr( i );
 | 
|---|
| 470 |         EraseSection( MRUItemSection );
 | 
|---|
| 471 |       end;
 | 
|---|
| 472 | 
 | 
|---|
| 473 |       WriteString( FontsSection, 'NormalFont', NormalFont.FaceName );
 | 
|---|
| 474 |       WriteInteger( FontsSection, 'NormalFontSize', NormalFont.PointSize );
 | 
|---|
| 475 |       WriteString( FontsSection, 'FixedFont', FixedFont.FaceName );
 | 
|---|
| 476 |       WriteInteger( FontsSection, 'FixedFontSize', FixedFont.PointSize );
 | 
|---|
| 477 | 
 | 
|---|
| 478 |       for FontIndex := 0 to NumFontSettings - 1 do
 | 
|---|
| 479 |       begin
 | 
|---|
| 480 |         FontName := 'Font' + IntToStr( FontIndex );
 | 
|---|
| 481 | 
 | 
|---|
| 482 |         WriteBool( FontsSection, FontName + 'Customised', Fonts[ FontIndex ] <> nil );
 | 
|---|
| 483 | 
 | 
|---|
| 484 |         if Fonts[ FontIndex ] <> nil then
 | 
|---|
| 485 |         begin
 | 
|---|
| 486 |           WriteString( FontsSection, FontName + 'Face', Fonts[ FontIndex ].FaceName );
 | 
|---|
| 487 |           WriteInteger( FontsSection, FontName + 'Size', Fonts[ FontIndex ].PointSize );
 | 
|---|
| 488 |         end;
 | 
|---|
| 489 | 
 | 
|---|
| 490 |       end;
 | 
|---|
| 491 | 
 | 
|---|
| 492 |       WriteBool( FontsSection, 'FixedFontSubstitution', FixedFontSubstitution );
 | 
|---|
| 493 |       WriteString( FontsSection, 'FixedFontSubstitutes', FixedFontSubstitutes );
 | 
|---|
| 494 | 
 | 
|---|
| 495 |       case IndexStyle of
 | 
|---|
| 496 |         isFileOnly:
 | 
|---|
| 497 |           SettingString := 'FileOnly';
 | 
|---|
| 498 |         isAlphabetical:
 | 
|---|
| 499 |           SettingString := 'Alphabetical';
 | 
|---|
| 500 |         isFull:
 | 
|---|
| 501 |           SettingString := 'Full';
 | 
|---|
| 502 |       end;
 | 
|---|
| 503 | 
 | 
|---|
| 504 |       WriteString( GeneralSection, 'IndexStyle', SettingString );
 | 
|---|
| 505 | 
 | 
|---|
| 506 |       WriteBool( GeneralSection, 'StartupHelp', StartupHelp );
 | 
|---|
| 507 | 
 | 
|---|
| 508 |       WriteBool( GeneralSection, 'SmoothScrolling', SmoothScrolling );
 | 
|---|
| 509 |       WriteBool( GeneralSection, 'UseOriginalDialogs', UseOriginalDialogs );
 | 
|---|
| 510 |       WriteBool( GeneralSection, 'OpenWithExpandedContents', OpenWithExpandedContents );
 | 
|---|
| 511 | 
 | 
|---|
| 512 |       WriteString( GeneralSection, 'ToolbarBackground', ToolbarBackgroundImageFilename );
 | 
|---|
| 513 | 
 | 
|---|
| 514 |       case ToolbarStyle of
 | 
|---|
| 515 |         tsNone:
 | 
|---|
| 516 |           SettingString := 'None';
 | 
|---|
| 517 |         tsImages:
 | 
|---|
| 518 |           SettingString := 'Images';
 | 
|---|
| 519 |         tsText:
 | 
|---|
| 520 |           SettingString := 'Text';
 | 
|---|
| 521 |         tsImagesAndText:
 | 
|---|
| 522 |           SettingString := 'ImagesAndText';
 | 
|---|
| 523 |       end;
 | 
|---|
| 524 | 
 | 
|---|
| 525 |       WriteString( GeneralSection, 'ToolbarStyle', SettingString );
 | 
|---|
| 526 | 
 | 
|---|
| 527 |       WriteBool( GeneralSection, 'ConfirmWinHelp', ConfirmWinHelp );
 | 
|---|
| 528 | 
 | 
|---|
| 529 |       WriteInteger( SearchSection,
 | 
|---|
| 530 |                     'CustomDirCount',
 | 
|---|
| 531 |                     SearchDirectories.Count );
 | 
|---|
| 532 | 
 | 
|---|
| 533 |       SearchDirectories.Sorted := true;
 | 
|---|
| 534 |       SearchDirectories.CaseSensitive := false;
 | 
|---|
| 535 |       SearchDirectories.Duplicates := dupIgnore;
 | 
|---|
| 536 | 
 | 
|---|
| 537 |       for i := 0 to SearchDirectories.Count - 1 do
 | 
|---|
| 538 |       begin
 | 
|---|
| 539 |         WriteString( SearchSection,
 | 
|---|
| 540 |                      'CustomDir' + IntToStr( i ),
 | 
|---|
| 541 |                      SearchDirectories[ i ] );
 | 
|---|
| 542 |       end;
 | 
|---|
| 543 | 
 | 
|---|
| 544 |       case GlobalSearchLocation of
 | 
|---|
| 545 |         gsHelpPaths:
 | 
|---|
| 546 |           SettingString := 'HelpPaths';
 | 
|---|
| 547 | 
 | 
|---|
| 548 |         gsFixedDrives:
 | 
|---|
| 549 |           SettingString := 'FixedDrives';
 | 
|---|
| 550 | 
 | 
|---|
| 551 |         gsSelectedHelpPaths:
 | 
|---|
| 552 |           SettingString := 'SelectedHelpPaths';
 | 
|---|
| 553 | 
 | 
|---|
| 554 |         gsCustom:
 | 
|---|
| 555 |           SettingString := 'Custom';
 | 
|---|
| 556 |       end;
 | 
|---|
| 557 | 
 | 
|---|
| 558 |       WriteString( SearchSection,
 | 
|---|
| 559 |                    'Location',
 | 
|---|
| 560 |                    SettingString );
 | 
|---|
| 561 | 
 | 
|---|
| 562 |     end;
 | 
|---|
| 563 |   end;
 | 
|---|
| 564 |   CloseIniFile( IniFile );
 | 
|---|
| 565 |   LogEvent(LogSettings, ' Done' );
 | 
|---|
| 566 | 
 | 
|---|
| 567 | End;
 | 
|---|
| 568 | 
 | 
|---|
| 569 | Procedure AddToMRUList( const Title: string;
 | 
|---|
| 570 |                         Filenames: TStrings );
 | 
|---|
| 571 | var
 | 
|---|
| 572 |   MRUIndex: longint;
 | 
|---|
| 573 |   PreviousMRUIndex: longint;
 | 
|---|
| 574 |   MRUItem: TMRUItem;
 | 
|---|
| 575 | begin
 | 
|---|
| 576 |   PreviousMRUIndex := -1;
 | 
|---|
| 577 |   for MRUIndex := 0 to Settings.MRUList.Count - 1 do
 | 
|---|
| 578 |   begin
 | 
|---|
| 579 |     MRUItem := Settings.MRUList[ MRUIndex ];
 | 
|---|
| 580 | 
 | 
|---|
| 581 |     if     ( MRUItem.Title = Title )
 | 
|---|
| 582 |        and ( MRUItem.Filenames.Equals( Filenames ) ) then
 | 
|---|
| 583 |     begin
 | 
|---|
| 584 |       // found identical entry in the list already.
 | 
|---|
| 585 |       PreviousMRUIndex := MRUIndex;
 | 
|---|
| 586 |       break;
 | 
|---|
| 587 |     end;
 | 
|---|
| 588 |   end;
 | 
|---|
| 589 | 
 | 
|---|
| 590 |   if PreviousMRUIndex > -1 then
 | 
|---|
| 591 |   begin
 | 
|---|
| 592 |     // is already in list, move to top of list
 | 
|---|
| 593 |     MRUItem := Settings.MRUList[ PreviousMRUIndex ];
 | 
|---|
| 594 |     Settings.MRUList.Delete( PreviousMRUIndex );
 | 
|---|
| 595 |   end
 | 
|---|
| 596 |   else
 | 
|---|
| 597 |   begin
 | 
|---|
| 598 |     // not yet in list. Create new
 | 
|---|
| 599 |     MRUItem := TMRUItem.Create;
 | 
|---|
| 600 |     MRUItem.Title := Title;
 | 
|---|
| 601 |     MRUItem.Filenames.Assign( Filenames );
 | 
|---|
| 602 |   end;
 | 
|---|
| 603 | 
 | 
|---|
| 604 |   Settings.MRUList.Insert( 0, MRUItem );
 | 
|---|
| 605 | 
 | 
|---|
| 606 |   while Settings.MRUList.Count > MaxMRUListEntries do
 | 
|---|
| 607 |   begin
 | 
|---|
| 608 |     MRUItem := Settings.MRUList[ MaxMRUListEntries ];
 | 
|---|
| 609 |     Settings.MRUList.Delete( MaxMRUListEntries );
 | 
|---|
| 610 |     MRUItem.Destroy;
 | 
|---|
| 611 |   end;
 | 
|---|
| 612 | end;
 | 
|---|
| 613 | 
 | 
|---|
| 614 | Procedure WriteWindowPos( Form: TForm );
 | 
|---|
| 615 | Var
 | 
|---|
| 616 |   IniFile: TMyIniFile;
 | 
|---|
| 617 | Begin
 | 
|---|
| 618 |   GetIniFile( IniFile );
 | 
|---|
| 619 |   SaveFormSizePosition( Form, IniFile );
 | 
|---|
| 620 |   CloseIniFile( IniFile );
 | 
|---|
| 621 | End;
 | 
|---|
| 622 | 
 | 
|---|
| 623 | Procedure ReadWindowPos( Form: TForm );
 | 
|---|
| 624 | Var
 | 
|---|
| 625 |   IniFile: TMyIniFile;
 | 
|---|
| 626 | Begin
 | 
|---|
| 627 |   GetIniFile( IniFile );
 | 
|---|
| 628 |   LoadFormSizePosition( Form, IniFile );
 | 
|---|
| 629 |   CloseIniFile( IniFile );
 | 
|---|
| 630 | End;
 | 
|---|
| 631 | 
 | 
|---|
| 632 | Initialization
 | 
|---|
| 633 |   Settings.NormalFont := Screen.GetFontFromPointSize( 'Helv',
 | 
|---|
| 634 |                                                       8 );
 | 
|---|
| 635 |   Settings.FixedFont := Screen.GetFontFromPointSize( 'Courier',
 | 
|---|
| 636 |                                                       8 );
 | 
|---|
| 637 |   Settings.SearchDirectories := TStringList.Create;
 | 
|---|
| 638 | 
 | 
|---|
| 639 | Finalization
 | 
|---|
| 640 |   Settings.NormalFont.Destroy;
 | 
|---|
| 641 |   Settings.FixedFont.Destroy;
 | 
|---|
| 642 |   Settings.SearchDirectories.Destroy;
 | 
|---|
| 643 | End.
 | 
|---|