1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
|
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
* *
***************************************************************************
Author: Mattias Gaertner
Abstract:
Miscellaneous options of the lazarus IDE.
}
unit MiscOptions;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLProc, BuildProfileManager, CodeToolsStructs, TextTools,
LazFileUtils, Laz2_XMLCfg, LazFileCache, LazConf, IDEProcs;
type
{ TFindRenameIdentifierOptions }
TFindRenameScope = (
frCurrentUnit,
frOwnerProjectPackage, // the project/package the current unit beongs to
frProject,
frAllOpenProjectsAndPackages
);
TFindRenameIdentifierOptions = class
private
FChangeStamp: integer;
FExtraFiles: TStrings;
FIdentifierFilename: string;
FIdentifierPosition: TPoint;
FRename: boolean;
FRenameShowResult: boolean;
FRenameTo: string;
FScope: TFindRenameScope;
FSearchInComments: boolean;
fSavedStamp: integer;
function GetModified: boolean;
procedure SetExtraFiles(AValue: TStrings);
procedure SetIdentifierFilename(AValue: string);
procedure SetIdentifierPosition(AValue: TPoint);
procedure SetModified(AValue: boolean);
procedure SetRename(AValue: boolean);
procedure SetRenameShowResult(AValue: boolean);
procedure SetRenameTo(AValue: string);
procedure SetScope(AValue: TFindRenameScope);
procedure SetSearchInComments(AValue: boolean);
public
constructor Create;
destructor Destroy; override;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string);
property ChangeStamp: integer read FChangeStamp;
procedure IncreaseChangeStamp; inline;
property Modified: boolean read GetModified write SetModified;
property IdentifierFilename: string read FIdentifierFilename write SetIdentifierFilename;
property IdentifierPosition: TPoint read FIdentifierPosition write SetIdentifierPosition;
property Rename: boolean read FRename write SetRename;
property RenameTo: string read FRenameTo write SetRenameTo;
property SearchInComments: boolean read FSearchInComments write SetSearchInComments;
property RenameShowResult: boolean read FRenameShowResult write SetRenameShowResult;
property Scope: TFindRenameScope read FScope write SetScope;
property ExtraFiles: TStrings read FExtraFiles write SetExtraFiles;
end;
{ TMiscellaneousOptions }
TMiscellaneousOptions = class
private
fBuildLazProfiles: TBuildLazarusProfiles;
FChangeStamp: integer;
FExtractProcName: string;
fFilename: string;
FFindRenameIdentifierOptions: TFindRenameIdentifierOptions;
FMakeResourceStringInsertPolicy: TResourcestringInsertPolicy;
FShowCompOptFullFilenames: boolean;
FShowCompOptMultiLine: boolean;
FSortSelDirection: TSortDirection;
FSortSelDomain: TSortDomain;
fSavedStamp: integer;
function GetBuildLazOpts: TBuildLazarusProfile;
function GetFilename: string;
function GetModified: boolean;
procedure SetExtractProcName(AValue: string);
procedure SetMakeResourceStringInsertPolicy(
AValue: TResourcestringInsertPolicy);
procedure SetModified(AValue: boolean);
procedure SetShowCompOptFullFilenames(AValue: boolean);
procedure SetShowCompOptMultiLine(const AValue: boolean);
procedure SetSortSelDirection(AValue: TSortDirection);
public
constructor Create;
destructor Destroy; override;
procedure Load;
procedure Save;
property Filename: string read GetFilename;
property ChangeStamp: integer read FChangeStamp;
procedure IncreaseChangeStamp; inline;
property Modified: boolean read GetModified write SetModified;
property BuildLazProfiles: TBuildLazarusProfiles read fBuildLazProfiles;
property BuildLazOpts: TBuildLazarusProfile read GetBuildLazOpts;
property ExtractProcName: string read FExtractProcName write SetExtractProcName;
property SortSelDirection: TSortDirection read FSortSelDirection
write SetSortSelDirection;
property SortSelDomain: TSortDomain read FSortSelDomain write FSortSelDomain;
property MakeResourceStringInsertPolicy: TResourcestringInsertPolicy
read FMakeResourceStringInsertPolicy
write SetMakeResourceStringInsertPolicy;
property FindRenameIdentifierOptions: TFindRenameIdentifierOptions
read FFindRenameIdentifierOptions;
property ShowCompOptFullFilenames: boolean read FShowCompOptFullFilenames
write SetShowCompOptFullFilenames;
property ShowCompOptMultiLine: boolean read FShowCompOptMultiLine
write SetShowCompOptMultiLine;
end;
const
SortDirectionNames: array[TSortDirection] of string = (
'Ascending', 'Descending');
SortDomainNames: array[TSortDomain] of string = (
'Words', 'Lines', 'Paragraphs');
ResourcestringInsertPolicyNames: array[TResourcestringInsertPolicy] of string
= ('None', 'Append', 'Alphabetically', 'Context');
FindRenameScopeNames: array[TFindRenameScope] of string = (
'CurrentUnit', 'Project', 'OwnerProjectPackage',
'AllOpenProjectsAndPackages'
);
var MiscellaneousOptions: TMiscellaneousOptions = nil;
function SortDirectionNameToType(const s: string): TSortDirection;
function SortDomainNameToType(const s: string): TSortDomain;
function ResourcestringInsertPolicyNameToType(
const s: string): TResourcestringInsertPolicy;
function FindRenameScopeNameToScope(const s: string): TFindRenameScope;
implementation
const
MiscOptsFilename = 'miscellaneousoptions.xml';
MiscOptsVersion = 3;
function SortDirectionNameToType(const s: string): TSortDirection;
begin
for Result:=Low(TSortDirection) to High(TSortDirection) do
if CompareText(SortDirectionNames[Result],s)=0 then exit;
Result:=sdAscending;
end;
function SortDomainNameToType(const s: string): TSortDomain;
begin
for Result:=Low(TSortDomain) to High(TSortDomain) do
if CompareText(SortDomainNames[Result],s)=0 then exit;
Result:=sdLines;
end;
function ResourcestringInsertPolicyNameToType(
const s: string): TResourcestringInsertPolicy;
begin
for Result:=Low(TResourcestringInsertPolicy)
to High(TResourcestringInsertPolicy) do
if CompareText(ResourcestringInsertPolicyNames[Result],s)=0 then exit;
Result:=rsipAppend;
end;
function FindRenameScopeNameToScope(const s: string): TFindRenameScope;
begin
for Result:=Low(TFindRenameScope) to High(TFindRenameScope) do
if CompareText(FindRenameScopeNames[Result],s)=0 then exit;
Result:=frAllOpenProjectsAndPackages;
end;
{ TMiscellaneousOptions }
// inline
procedure TMiscellaneousOptions.IncreaseChangeStamp;
begin
LUIncreaseChangeStamp(fChangeStamp);
end;
constructor TMiscellaneousOptions.Create;
begin
inherited Create;
fSavedStamp:=LUInvalidChangeStamp;
fBuildLazProfiles:=TBuildLazarusProfiles.Create;
FExtractProcName:='NewProc';
fSortSelDirection:=sdAscending;
fSortSelDomain:=sdLines;
fMakeResourceStringInsertPolicy:=rsipAppend;
FFindRenameIdentifierOptions:=TFindRenameIdentifierOptions.Create;
end;
destructor TMiscellaneousOptions.Destroy;
begin
fBuildLazProfiles.Free;
FFindRenameIdentifierOptions.Free;
inherited Destroy;
end;
function TMiscellaneousOptions.GetFilename: string;
var
ConfFileName: string;
begin
if fFilename='' then begin
ConfFileName:=AppendPathDelim(GetPrimaryConfigPath)+MiscOptsFilename;
CopySecondaryConfigFile(MiscOptsFilename);
if (not FileExistsUTF8(ConfFileName)) then begin
//DebugLn('Note: miscellaneous options file not found - using defaults');
end;
FFilename:=ConfFilename;
end;
Result:=fFilename;
end;
function TMiscellaneousOptions.GetModified: boolean;
begin
Result:=(ChangeStamp<>fSavedStamp) or FindRenameIdentifierOptions.Modified;
end;
procedure TMiscellaneousOptions.SetExtractProcName(AValue: string);
begin
if FExtractProcName=AValue then Exit;
FExtractProcName:=AValue;
IncreaseChangeStamp;
end;
procedure TMiscellaneousOptions.SetMakeResourceStringInsertPolicy(
AValue: TResourcestringInsertPolicy);
begin
if FMakeResourceStringInsertPolicy=AValue then Exit;
FMakeResourceStringInsertPolicy:=AValue;
IncreaseChangeStamp;
end;
procedure TMiscellaneousOptions.SetModified(AValue: boolean);
begin
if AValue then
IncreaseChangeStamp
else begin
fSavedStamp:=ChangeStamp;
FindRenameIdentifierOptions.Modified:=false;
end;
end;
procedure TMiscellaneousOptions.SetShowCompOptFullFilenames(AValue: boolean);
begin
if FShowCompOptFullFilenames=AValue then Exit;
FShowCompOptFullFilenames:=AValue;
IncreaseChangeStamp;
end;
procedure TMiscellaneousOptions.SetShowCompOptMultiLine(const AValue: boolean);
begin
if FShowCompOptMultiLine=AValue then Exit;
FShowCompOptMultiLine:=AValue;
IncreaseChangeStamp;
end;
procedure TMiscellaneousOptions.SetSortSelDirection(AValue: TSortDirection);
begin
if FSortSelDirection=AValue then Exit;
FSortSelDirection:=AValue;
IncreaseChangeStamp;
end;
function TMiscellaneousOptions.GetBuildLazOpts: TBuildLazarusProfile;
begin
Result:=BuildLazProfiles.Current;
end;
procedure TMiscellaneousOptions.Load;
var XMLConfig: TXMLConfig;
FileVersion: integer;
Path: String;
begin
try
XMLConfig:=TXMLConfig.Create(GetFilename);
except
DebugLn('ERROR: unable to open miscellaneous options "',GetFilename,'"');
exit;
end;
try
try
Path:='MiscellaneousOptions/';
FileVersion:=XMLConfig.GetValue(Path+'Version/Value',0);
BuildLazProfiles.Load(XMLConfig,Path+'BuildLazarusOptions/',FileVersion);
SortSelDirection:=SortDirectionNameToType(XMLConfig.GetValue(
Path+'SortSelection/Direction',SortDirectionNames[sdAscending]));
SortSelDomain:=SortDomainNameToType(XMLConfig.GetValue(
Path+'SortSelection/Domain',SortDomainNames[sdLines]));
MakeResourceStringInsertPolicy:=ResourcestringInsertPolicyNameToType(
XMLConfig.GetValue(Path+'MakeResourcestringInsertPolicy/Value',
ResourcestringInsertPolicyNames[rsipAppend]));
ExtractProcName:=XMLConfig.GetValue(Path+'ExtractProcName/Value','NewProc');
FindRenameIdentifierOptions.LoadFromXMLConfig(XMLConfig,
Path+'FindRenameIdentifier/');
ShowCompOptFullFilenames:=XMLConfig.GetValue(Path+'ShowCompOpts/Filenames/Full',false);
ShowCompOptMultiLine:=XMLConfig.GetValue(Path+'ShowCompOpts/MultiLine',true);
finally
XMLConfig.Free;
end;
except
on E: Exception do begin
DebugLn('ERROR: unable read miscellaneous options from "',GetFilename,'": ',E.Message);
end;
end;
Modified:=false;
end;
procedure TMiscellaneousOptions.Save;
var XMLConfig: TXMLConfig;
Path: String;
XMLFilename: String;
begin
if not Modified then exit;
XMLFilename:=GetFilename;
try
XMLConfig:=TXMLConfig.CreateClean(XMLFilename);
except
on E: Exception do begin
DebugLn('ERROR: unable to open miscellaneous options "',XMLFilename,'":',E.Message);
exit;
end;
end;
try
try
Path:='MiscellaneousOptions/';
XMLConfig.SetValue(Path+'Version/Value',MiscOptsVersion);
BuildLazProfiles.Save(XMLConfig,Path+'BuildLazarusOptions/');
XMLConfig.SetDeleteValue(Path+'SortSelection/Direction',
SortDirectionNames[SortSelDirection],
SortDirectionNames[sdAscending]);
XMLConfig.SetDeleteValue(Path+'SortSelection/Domain',
SortDomainNames[SortSelDomain],SortDomainNames[sdLines]);
XMLConfig.SetDeleteValue(Path+'MakeResourcestringInsertPolicy/Value',
ResourcestringInsertPolicyNames[MakeResourceStringInsertPolicy],
ResourcestringInsertPolicyNames[rsipAppend]);
XMLConfig.SetDeleteValue(Path+'ExtractProcName/Value',ExtractProcName,
'NewProc');
FindRenameIdentifierOptions.SaveToXMLConfig(XMLConfig,
Path+'FindRenameIdentifier/');
XMLConfig.SetDeleteValue(Path+'ShowCompOpts/MultLine',ShowCompOptMultiLine,true);
XMLConfig.Flush;
finally
XMLConfig.Free;
end;
except
on E: Exception do begin
DebugLn('ERROR: unable read miscellaneous options from "',XMLFilename,'": ',E.Message);
end;
end;
Modified:=false;
end;
{ TFindRenameIdentifierOptions }
// inline
procedure TFindRenameIdentifierOptions.IncreaseChangeStamp;
begin
LUIncreaseChangeStamp(fChangeStamp);
end;
procedure TFindRenameIdentifierOptions.SetExtraFiles(AValue: TStrings);
begin
if (FExtraFiles=AValue) or FExtraFiles.Equals(AValue) then Exit;
FExtraFiles.Assign(AValue);
IncreaseChangeStamp;
end;
function TFindRenameIdentifierOptions.GetModified: boolean;
begin
Result:=fSavedStamp=ChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetIdentifierFilename(AValue: string);
begin
if FIdentifierFilename=AValue then Exit;
FIdentifierFilename:=AValue;
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetIdentifierPosition(AValue: TPoint);
begin
if ComparePoints(FIdentifierPosition,AValue)=0 then Exit;
FIdentifierPosition:=AValue;
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetModified(AValue: boolean);
begin
if AValue then
IncreaseChangeStamp
else
fSavedStamp:=ChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetRename(AValue: boolean);
begin
if FRename=AValue then Exit;
FRename:=AValue;
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetRenameShowResult(AValue: boolean);
begin
if FRenameShowResult=AValue then Exit;
FRenameShowResult:=AValue;
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetRenameTo(AValue: string);
begin
if FRenameTo=AValue then Exit;
FRenameTo:=AValue;
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetScope(AValue: TFindRenameScope);
begin
if FScope=AValue then Exit;
FScope:=AValue;
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetSearchInComments(AValue: boolean);
begin
if FSearchInComments=AValue then Exit;
FSearchInComments:=AValue;
IncreaseChangeStamp;
end;
constructor TFindRenameIdentifierOptions.Create;
begin
inherited;
fSavedStamp:=LUInvalidChangeStamp;
fExtraFiles:=TStringList.Create;
end;
destructor TFindRenameIdentifierOptions.Destroy;
begin
FreeAndNil(FExtraFiles);
inherited Destroy;
end;
procedure TFindRenameIdentifierOptions.LoadFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
begin
fIdentifierFilename:=XMLConfig.GetValue(Path+'Identifier/Filename','');
LoadPoint(XMLConfig,Path+'Identifier/',fIdentifierPosition,Point(0,0));
fRename:=XMLConfig.GetValue(Path+'Rename/Value',false);
fRenameTo:=XMLConfig.GetValue(Path+'Rename/Identifier','');
fSearchInComments:=XMLConfig.GetValue(Path+'SearchInComments/Value',true);
fRenameShowResult:=XMLConfig.GetValue(Path+'RenameShowResult/Value',false);
fScope:=FindRenameScopeNameToScope(XMLConfig.GetValue(Path+'Scope/Value',
FindRenameScopeNames[frAllOpenProjectsAndPackages]));
LoadStringList(XMLConfig,fExtraFiles,Path+'ExtraFiles/');
Modified:=false;
end;
procedure TFindRenameIdentifierOptions.SaveToXMLConfig(XMLConfig: TXMLConfig;
const Path: string);
begin
XMLConfig.SetDeleteValue(Path+'Identifier/Filename',IdentifierFilename,'');
SavePoint(XMLConfig,Path+'Identifier/',IdentifierPosition,Point(0,0));
XMLConfig.SetDeleteValue(Path+'Rename/Value',Rename,false);
XMLConfig.SetDeleteValue(Path+'Rename/Identifier',RenameTo,'');
XMLConfig.SetDeleteValue(Path+'SearchInComments/Value',SearchInComments,true);
XMLConfig.SetDeleteValue(Path+'RenameShowResult/Value',RenameShowResult,false);
XMLConfig.SetDeleteValue(Path+'Scope/Value',FindRenameScopeNames[Scope],
FindRenameScopeNames[frAllOpenProjectsAndPackages]);
SaveStringList(XMLConfig,ExtraFiles,Path+'ExtraFiles/');
Modified:=false;
end;
end.
|