refact with type helpers

This commit is contained in:
Basile Burg 2016-01-27 04:43:54 +01:00
parent 7d6e2863cd
commit c407a40259
20 changed files with 73 additions and 71 deletions

View File

@ -96,7 +96,7 @@ begin
fBackup := TStringList.Create;
//
fname := getCoeditDocPath + optFname;
if fileExists(fname) then
if fname.fileExists then
fDmtWrapper.loadFromFile(fname);
//
btnCancel.OnClick := @doCancel;

View File

@ -169,7 +169,7 @@ var
begin
loader := TMemoryStream.Create;
try
fBasePath := extractFilePath(aFilename);
fBasePath := aFilename.extractFilePath;
fFilename := aFilename;
loader.LoadFromFile(fFilename);
fSaveAsUtf8 := false;

View File

@ -228,7 +228,7 @@ begin
if not doc.isDSource then
continue;
nme := doc.fileName;
if not FileExists(nme) then
if not nme.fileExists then
continue;
{$WARNINGS OFF}
for j := 0 to doc.breakPointsCount-1 do
@ -250,7 +250,7 @@ begin
if fGdb = nil then exit;
if not fGdb.Running then exit;
nme := sender.fileName;
if not FileExists(nme) then exit;
if not nme.fileExists then exit;
//
str := cmd[modification] + nme + ':' + intToStr(line);
fGdb.Suspend;
@ -267,7 +267,7 @@ begin
if fProj = nil then exit;
if fProj.binaryKind <> executable then exit;
str := fProj.outputFilename;
if not FileExists(str) then exit;
if not str.fileExists then exit;
// gdb process
killGdb;
fGdb := TCEProcess.create(nil);

View File

@ -92,7 +92,7 @@ begin
if trv.Selected.isNotNil then
begin
result := trv.Selected.Text;
if (not result.fileExists) and assigned(fProj) then
if not result.fileExists and assigned(fProj) then
result := fProj.filename.extractFilePath + result;
end;
end;
@ -104,7 +104,7 @@ var
fname: string;
begin
fname := getFilename(Source);
Accept := fname.fileExists and (not fname.dirExists);
Accept := fname.fileExists and not fname.dirExists;
end;
procedure TDDHandler.DragDrop(Sender, Source: TObject; X, Y: Integer);

View File

@ -64,13 +64,13 @@ begin
inherited;
fCol := TCollection.Create(TLibraryItem);
fname := getCoeditDocPath + libFname;
if fileExists(fname) then
if fname.fileExists then
loadFromFile(fname);
if fCol.Count = 0 then
begin
{$IFDEF WINDOWS}
fDmdPath := ExeSearch('dmd.exe');
if FileExists(fDmdPath) then
if fDmdPath.fileExists then
begin
// add phobos
fname := ExtractFileDir(fDmdPath);

View File

@ -91,9 +91,9 @@ end;
procedure TCELibManEditorWidget.updateButtonsState;
begin
btnReg.Enabled := (fProj <> nil) and (fProj.binaryKind = staticlib) and
FileExists(fProj.Filename);
btnOpenProj.Enabled := (List.Selected.isNotNil) and
(fileExists(List.Selected.SubItems[2]));
fProj.Filename.fileExists;
btnOpenProj.Enabled := List.Selected.isNotNil and
List.Selected.SubItems[2].fileExists;
end;
procedure TCELibManEditorWidget.projNew(aProject: ICECommonProject);
@ -310,7 +310,7 @@ var
begin
if List.Selected.isNil then exit;
fname := List.Selected.SubItems[2];
if not FileExists(fname) then exit;
if not fname.fileExists then exit;
//
if isValidNativeProject(fname) then
begin
@ -384,7 +384,7 @@ begin
SubItems.add(fname);
SubItems.add(root);
SubItems.add(fProj.filename);
if not FileExists(SubItems[0]) then
if not SubItems[0].fileExists then
dlgOkInfo('the library file does not exist, maybe the project not been already compiled ?');
Selected:= true;
end;

View File

@ -780,7 +780,7 @@ begin
end;
end;
value := application.GetOptionValue('p', 'project');
if value.isNotEmpty and fileExists(value) then
if value.isNotEmpty and value.fileExists then
openProj(value);
value := application.GetOptionValue('f', 'files');
if value.isNotEmpty then
@ -790,7 +790,7 @@ begin
lst.DelimitedText := value;
for value in lst do
begin
if fileExists(value) then
if value.fileExists then
openFile(value);
end;
finally
@ -949,7 +949,7 @@ var
begin
// project and files MRU
fname := getCoeditDocPath + 'mostrecent.txt';
if fileExists(fname) then with TCEPersistentMainMrus.create(nil) do
if fname.fileExists then with TCEPersistentMainMrus.create(nil) do
try
setTargets(fFileMru, fProjMru);
loadFromFile(fname);
@ -958,7 +958,7 @@ begin
end;
// shortcuts for the actions standing in the main action list
fname := getCoeditDocPath + 'mainshortcuts.txt';
if fileExists(fname) then with TCEPersistentMainShortcuts.create(nil) do
if fname.fileExists then with TCEPersistentMainShortcuts.create(nil) do
try
loadFromFile(fname);
assignTo(self);
@ -968,7 +968,7 @@ begin
// globals opts
fAppliOpts := TCEApplicationOptions.Create(self);
fname := getCoeditDocPath + 'application.txt';
if fileExists(fname) then
if fname.fileExists then
begin
fAppliOpts.loadFromFile(fname);
fAppliOpts.assignTo(self);
@ -1524,7 +1524,7 @@ procedure TCEMainForm.saveFile(aDocument: TCESynMemo);
begin
if (aDocument.Highlighter = LfmSyn) or (aDocument.Highlighter = JsSyn) then
saveProjSource(aDocument)
else if fileExists(aDocument.fileName) then
else if aDocument.fileName.fileExists then
aDocument.save;
end;
@ -1548,7 +1548,7 @@ end;
procedure TCEMainForm.actProjOpenContFoldExecute(Sender: TObject);
begin
if fProjectInterface = nil then exit;
if not fileExists(fProjectInterface.filename) then exit;
if not fProjectInterface.filename.fileExists then exit;
//
DockMaster.GetAnchorSite(fExplWidg).Show;
fExplWidg.expandPath(fProjectInterface.filename.extractFilePath);
@ -1598,7 +1598,7 @@ begin
if fDoc.isNil then exit;
//
str := fDoc.fileName;
if (str <> fDoc.tempFilename) and (fileExists(str)) then
if (str <> fDoc.tempFilename) and str.fileExists then
saveFile(fDoc)
else
actFileSaveAs.Execute;
@ -1612,7 +1612,7 @@ begin
//
if fProjectInterface.getFormat = pfNative then
begin
if fileExists(fDoc.fileName) and (not fDoc.isTemporary) then
if fDoc.fileName.fileExists and not fDoc.isTemporary then
fNativeProject.addSource(fDoc.fileName)
else dlgOkInfo('the file has not been added to the project because it does not exist');
end else
@ -1889,7 +1889,7 @@ begin
fMsgs.message('compiling ' + shortenPath(fDoc.fileName, 25), fDoc, amcEdit, amkInf);
if fileExists(fDoc.fileName) then fDoc.save
if fDoc.fileName.fileExists then fDoc.save
else fDoc.saveTempFile;
fname := stripFileExt(fDoc.fileName);
@ -1978,7 +1978,7 @@ end;
procedure TCEMainForm.actFileOpenContFoldExecute(Sender: TObject);
begin
if fDoc.isNil then exit;
if not fileExists(fDoc.fileName) then exit;
if not fDoc.fileName.fileExists then exit;
//
DockMaster.GetAnchorSite(fExplWidg).Show;
fExplWidg.expandPath(fDoc.fileName.extractFilePath);
@ -2015,7 +2015,7 @@ begin
if (not fProjectInterface.targetUpToDate) then if
dlgOkCancel('The project output is not up-to-date, rebuild ?') = mrOK then
fProjectInterface.compile;
if fileExists(fProjectInterface.outputFilename)
if fProjectInterface.outputFilename.fileExists
or (fProjectInterface.getFormat = pfDub) then
fProjectInterface.run;
end;
@ -2065,7 +2065,7 @@ procedure TCEMainForm.layoutLoadFromFile(const aFilename: string);
var
xcfg: TXMLConfigStorage;
begin
if not fileExists(aFilename) then
if not aFilename.fileExists then
exit;
//
xcfg := TXMLConfigStorage.Create(aFilename, true);
@ -2186,7 +2186,7 @@ end;
{$REGION project ---------------------------------------------------------------}
procedure TCEMainForm.showProjTitle;
begin
if (fProjectInterface <> nil) and fileExists(fProjectInterface.filename) then
if (fProjectInterface <> nil) and fProjectInterface.filename.fileExists then
caption := format('Coedit - %s', [shortenPath(fProjectInterface.filename, 30)])
else
caption := 'Coedit';
@ -2331,7 +2331,7 @@ end;
procedure TCEMainForm.actProjSourceExecute(Sender: TObject);
begin
if fProjectInterface = nil then exit;
if not fileExists(fProjectInterface.filename) then exit;
if not fProjectInterface.filename.fileExists then exit;
//
openFile(fProjectInterface.filename);
if fProjectInterface.getFormat = pfNative then

View File

@ -312,7 +312,7 @@ begin
AssignPng(btnClearCat, 'clean');
//
fname := getCoeditDocPath + optname;
if fileExists(fname) then
if fname.fileExists then
begin
fOptions.loadFromFile(fname);
fOptions.AssignTo(self);
@ -1031,27 +1031,27 @@ begin
and (aMessage[i..i+5] = '-mixin'))) then
begin
// absolute fname
if fileExists(ident) then
if ident.fileExists then
begin
getMultiDocHandler.openDocument(ident);
exit(true);
end;
// relative fname if project file is the base path to a rel. fname
absName := ExpandFileName(ident);
if fileExists(absName) then
if absName.fileExists then
begin
getMultiDocHandler.openDocument(absName);
exit(true);
end;
// if fname relative to native project path or project filed 'root'
absName := expandFilenameEx(symbolExpander.get('<CPP>') + DirectorySeparator, ident);
if fileExists(absName) then
if absName.fileExists then
begin
getMultiDocHandler.openDocument(absName);
exit(true);
end;
absName := expandFilenameEx(symbolExpander.get('<CPR>') + DirectorySeparator, ident);
if fileExists(absName) then
if absName.fileExists then
begin
getMultiDocHandler.openDocument(absName);
exit(true);

View File

@ -268,7 +268,7 @@ begin
treeSetRoots;
//
fname := getCoeditDocPath + OptsFname;
if fileExists(fname) then with TCEMiniExplorerOptions.create(nil) do
if fname.fileExists then with TCEMiniExplorerOptions.create(nil) do
try
loadFromFile(fname);
assignTo(self);
@ -459,7 +459,7 @@ begin
if lstFiles.Selected.isNil then exit;
if lstFiles.Selected.Data.isNil then exit;
fname := PString(lstFiles.Selected.Data)^;
if not fileExists(fname) then exit;
if not fname.fileExists then exit;
{$IFNDEF WINDOWS}
fname := fname[2..length(fname)];
{$ENDIF}
@ -531,7 +531,7 @@ begin
if lstFav.Selected.Data.isNil then exit;
fname := PString(lstFav.Selected.Data)^;
end;
if fileExists(fname) then if not shellOpen(fname) then
if fname.fileExists then if not shellOpen(fname) then
getMessageDisplay.message((format('the shell failed to open "%s"',
[shortenPath(fname, 25)])), nil, amcMisc, amkErr);
end;

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, ce_interfaces, ce_observer,
ce_nativeproject, ce_synmemo;
ce_nativeproject, ce_synmemo, ce_common;
type
@ -141,13 +141,13 @@ var
begin
inherited;
for i := Count-1 downto 0 do
if not fileExists(Strings[i]) then
if not Strings[i].fileExists then
Delete(i);
end;
function TCEMRUFileList.checkItem(const S: string): boolean;
begin
exit( inherited checkItem(S) and fileExists(S));
exit( inherited checkItem(S) and S.fileExists);
end;
constructor TCEMRUDocumentList.create;
@ -176,7 +176,7 @@ end;
procedure TCEMRUDocumentList.docClosing(aDoc: TCESynMemo);
begin
if FileExists(aDoc.fileName) and (aDoc.fileName <> aDoc.tempFilename) then
if aDoc.fileName.fileExists and not aDoc.isTemporary then
Insert(0, aDoc.fileName);
end;
@ -215,7 +215,8 @@ begin
if aProject = nil then exit;
//
fname := aProject.filename;
if FileExists(fname) then Insert(0, fname);
if fname.fileExists then
Insert(0, fname);
end;
initialization

View File

@ -54,7 +54,7 @@ begin
fMru.maxCount := 25;
EntitiesConnector.addSingleService(self);
fname := getCoeditDocPath + OptsFname;
if fileExists(OptsFname) then
if OptsFname.fileExists then
fMru.LoadFromFile(fname);
if fMru.Count = 0 then
fMru.Insert(0, '(your input here)');

View File

@ -357,7 +357,7 @@ begin
lst := TStringList.Create;
fProject.beginUpdate;
try for fname in Filenames do
if FileExists(fname) then
if fname.fileExists then
addFile(fname)
else if fname.dirExists then
begin

View File

@ -216,7 +216,7 @@ begin
fReplaceMru:= TCEMruList.Create;
//
fname := getCoeditDocPath + OptsFname;
if FileExists(fname) then with TCESearchOptions.create(nil) do
if fname.fileExists then with TCESearchOptions.create(nil) do
try
loadFromFile(fname);
AssignTo(self);

View File

@ -208,7 +208,7 @@ begin
fOptions := TStaticMacrosOptions.create(self);
fOptionBackup := TStaticMacrosOptions.create(self);
fname := getCoeditDocPath + OptFname;
if fileExists(fname) then
if fname.fileExists then
begin
fOptions.loadFromFile(fname);
// old option file will create a streaming error.

View File

@ -353,7 +353,7 @@ begin
fOptions := TCESymbolListOptions.Create(self);
fOptions.Name:= 'symbolListOptions';
fname := getCoeditDocPath + OptsFname;
if FileExists(fname) then
if fname.fileExists then
fOptions.loadFromFile(fname);
fOptions.AssignTo(self);
//
@ -650,7 +650,7 @@ end;
procedure TCESymbolListWidget.checkIfHasToolExe;
begin
fToolExeName := exeFullName(toolExeName);
fHasToolExe := FileExists(fToolExeName);
fHasToolExe := fToolExeName.fileExists;
end;
procedure TCESymbolListWidget.callToolProc;

View File

@ -171,7 +171,7 @@ begin
// document
if hasDoc then
begin
if not fileExists(fDoc.fileName) then
if not fDoc.fileName.fileExists then
fDoc.saveTempFile;
fSymbols[CFF] := fDoc.fileName;
fSymbols[CFP] := fDoc.fileName.extractFilePath;
@ -209,7 +209,7 @@ begin
end;
if hasNativeProj then
begin
if fileExists(fProj.fileName) then
if fProj.fileName.fileExists then
begin
fSymbols[CPR] := expandFilenameEx(fProj.basePath, fProj.RootFolder);
if fSymbols[CPR].isEmpty then

View File

@ -362,7 +362,7 @@ var
begin
tempn := fMemo.fileName;
if tempn = fMemo.tempFilename then exit;
if not fileExists(tempn) then exit;
if not tempn.fileExists then exit;
//
fname := getCoeditDocPath + 'editorcache' + DirectorySeparator;
ForceDirectories(fname);
@ -379,14 +379,14 @@ var
chksm: Cardinal;
begin
tempn := fMemo.fileName;
if not fileExists(tempn) then exit;
if not tempn.fileExists then exit;
//
fname := getCoeditDocPath + 'editorcache' + DirectorySeparator;
chksm := crc32(0, nil, 0);
chksm := crc32(chksm, @tempn[1], length(tempn));
fname := fname + format('%.8X.txt', [chksm]);
//
if not fileExists(fname) then exit;
if not fname.fileExists then exit;
loadFromFile(fname);
end;
{$IFDEF DEBUG}{$R+}{$ENDIF}
@ -548,7 +548,7 @@ begin
fBreakPoints.Free;
fCallTipStrings.Free;
//
if fileExists(fTempFileName) then
if fTempFileName.fileExists then
sysutils.DeleteFile(fTempFileName);
//
inherited;

View File

@ -225,7 +225,7 @@ begin
AssignPng(btnGo, 'arrow_pen');
//
fname := getCoeditDocPath + OptFname;
if FileExists(fname) then
if fname.fileExists then
fOptions.loadFromFile(fname);
fOptions.AssignTo(self);
//

View File

@ -267,7 +267,7 @@ begin
inherited;
fTools := TCEToolItems.Create(TCEToolItem);
fname := getCoeditDocPath + toolsFname;
if fileExists(fname) then loadFromFile(fname);
if fname.fileExists then loadFromFile(fname);
//
EntitiesConnector.addObserver(self);
end;

View File

@ -212,7 +212,7 @@ General questions and discussions (Q, BLA) about the use are also allowed since
- **"Save project as"**: saves the current project from a dialog.
- **"Project configuration"**: displays the project configuration widget.
- **"Edit project file"**: opens the project file in a new editor. When saved from a source editor, a project file is directly reloaded. It means that a particular care must be taken during the edition. Coedit will skip any error in the project file, without warnings.
- **"View project command line"**: displays the list of the switches and their arguments, as passed to DMD before the compilation. Note that under Windows, the content can be copied using the <kbd>Ctrl</kbd>+<kbd>C</kbd> shortcut on the dialog.
- **"View project command line"**: displays the list of the switches and their arguments, as passed to DMD before the compilation. Note that under Windows, the content can be copied using the <kbd>Ctrl</kbd> + <kbd>C</kbd> shortcut on the dialog.
- **"View in mini explorer"**: expands the [mini-explorer][lnk_widg_miniexpl] tree on the folder containing the project file.
- **"Compile project"**: compiles the project using the current configuration.
- **"Compile and run project"**: compiles the project using the current configuration and execute the output if the option _binaryKind_ is set to _executable_.
@ -422,10 +422,10 @@ The _source editor widget_ is a standard code editor, specialized for highlighti
- folding: curly brackets blocks, multi-line strings, block comments, nested block comments, DDoc comments blocks.
- colorization of the following categories: keywords, special keywords, numbers, symbols, comments, assembler instructions and identifiers, DDoc comments.
- current identifier markup, selection markup.
- standard keyboard navigation shortcuts <kbd>CTRL</kbd> + (<kbd>SHIFT</kbd> +) <kbd>LEFT</kbd>/<kbd>RIGHT</kbd>, <kbd>CTRL</kbd> + <kbd>HOME</kbd>, <kbd>CTRL</kbd> + <kbd>END</kbd> etc.
- macro recording and playback using <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>R</kbd> (start/stop recording) or <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd> (play).
- synchro-edit (activated when clicking the pen icon located in the gutter, or with the shortcut <kbd>CTRL</kbd>+<kbd>E</kbd> and <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>E</kbd>).
- zoom: (<kbd>CTRL</kbd>+<kbd>WHEEL</kbd>, <kbd>CTRL</kbd>+<kbd>MIDDLE MB</kbd>, <kbd>CTRL</kbd>+<kbd>+</kbd>, <kbd>CTRL</kbd>+<kbd>-</kbd>, <kbd>CTRL</kbd>+<kbd>.</kbd>).
- standard keyboard navigation shortcuts <kbd>CTRL</kbd> + [<kbd>SHIFT</kbd> +] <kbd>LEFT</kbd> | <kbd>RIGHT</kbd>, <kbd>CTRL</kbd> + <kbd>HOME</kbd>, <kbd>CTRL</kbd> + <kbd>END</kbd> etc.
- macro recording and playback using <kbd>CTRL</kbd> + <kbd>SHIFT</kbd> + <kbd>R</kbd> (start or stop recording) or <kbd>CTRL</kbd> + <kbd>SHIFT</kbd> + <kbd>P</kbd> (play).
- synchro-edit (activated when clicking the pen icon located in the gutter, or with the shortcut <kbd>CTRL</kbd> + <kbd>E</kbd> and <kbd>CTRL</kbd> + <kbd>SHIFT</kbd> + <kbd>E</kbd>).
- zoom: <kbd>CTRL</kbd> + <kbd>WHEEL</kbd>, <kbd>CTRL</kbd> + <kbd>MIDDLE MB</kbd>, <kbd>CTRL</kbd> + <kbd>+</kbd> | <kbd>-</kbd> | <kbd>.</kbd>.
- display cache: for each document, the zoom ratio, the folding state and the caret position are saved between two sessions. A cache file has a fixed life-time of three months from its last modification.
- drag & drop editing.
- external modification tracking. Each time the focus is put on a document (switch document, show & hide application), Coedit verifies if its time stamp has changed.
@ -507,22 +507,23 @@ The _find and replace_ widget allows to find and replace text patterns in the fo
![](https://raw.githubusercontent.com/BBasile/CoeditWikiData/master/search1.png)
- top field: the pattern to find.
- second field: the expression used as replacement. Only active when **"replace with"** is checked.
- whole word: only search for the whole expression.
- backward: search from the bottom to the top.
- first field: the pattern to find.
- second field: the pattern used as replacement, only active when **"replace with"** is checked.
- whole word: only search for the whole pattern.
- backward: search from the current position to the top.
- from cursor: when unchecked, the operation always starts from the top of the document.
- case sensitive: when unchecked, character case is ignored.
- prompt: a confirmation is required to replace an expression.
- case sensitive: when unchecked, the case is ignored.
- prompt: a confirmation is required to replace a match.
- allow regex: when checked, the search is performed by a regex engine.
By default <kbd>CTRL</kbd> + <kbd>F</kbd> is used to pass the current source code editor selection to the top field
and <kbd>F3</kbd> to execute a search. Unless _Find all_ is used, the results are directly visible in the editor.
By default <kbd>CTRL</kbd> + <kbd>F</kbd> is used to pass the current identifier to the first field and <kbd>F3</kbd> to execute a search.
Unless _Find all_ is used, the results are directly visible in the editor.
_Find all_ results are displayed in the [messages widget][lnk_widg_msg] and are clickable.
The scope of _Find all_ can be set, either to the current editor or to the whole project, by clicking the icon at the right.
The most recent searches and replacements are saved between each session.
Note that to find a symbol, <kbd>Ctrl</kbd>+<kbd>MB Left</kbd> or the [symbol list][lnk_widg_symlist] are faster.
Note that to find a symbol, <kbd>Ctrl</kbd> + <kbd>MB Left</kbd> or the [symbol list][lnk_widg_symlist] are faster.
## Library manager widget
@ -1180,7 +1181,7 @@ as well as the additional source (the _libdparse.lib_).
### Completion and runnable
In the **File** menu click **New runnable module**.
type import **std.d** and hit <kbd>CTRL</kbd>+<kbd>SCPACE</kbd> to invoke the completion.
type import **std.d** and hit <kbd>CTRL</kbd> + <kbd>SCPACE</kbd> to invoke the completion.
[DCD][lnk_dcd], automatically aware of _libdparse_, will propose the item **lexer**,
which matches to one of the module of the library (the D language lexer).