call heavy things written in D in fpc threads

This commit is contained in:
Basile Burg 2020-05-05 04:07:18 +02:00
parent 739d7225cf
commit 04798b1c83
2 changed files with 52 additions and 15 deletions

View File

@ -138,9 +138,13 @@ type
fAutoExpandErrors: boolean;
fSortSymbols: boolean;
fSmartExpander: boolean;
fTreeDataToThread: string;
fTreeDataFromThread: string;
ndAlias, ndClass, ndEnum, ndFunc, ndUni: TTreeNode;
ndImp, ndIntf, ndMix, ndStruct, ndTmp: TTreeNode;
ndVar, ndWarn, ndErr, ndUt: TTreeNode;
procedure getTreeDataInThread;
procedure gotTreeDataFromThread(sender: TObject);
procedure TreeDblClick(Sender: TObject);
procedure actRefreshExecute(Sender: TObject);
procedure actAutoRefreshExecute(Sender: TObject);
@ -728,6 +732,25 @@ begin
end;
procedure TSymbolListWidget.getSymbols;
begin
if fDoc.isNil then
exit;
if (fDoc.Lines.Count = 0) or not fDoc.isDSource then
begin
clearTree;
updateVisibleCat;
exit;
end;
fTreeDataToThread := fDoc.Lines.Text;
TTHread.ExecuteInThread(@getTreeDataInThread, @gotTreeDataFromThread);
end;
procedure TSymbolListWidget.getTreeDataInThread;
begin
fTreeDataFromThread := listSymbols(PChar(fTreeDataToThread), fDeep);
end;
procedure TSymbolListWidget.gotTreeDataFromThread(sender: TObject);
function getCatNode(node: TTreeNode; stype: TSymbolType ): TTreeNode;
function newCat(const aCat: string): TTreeNode;
@ -817,21 +840,12 @@ begin
if fDoc.isNil then
exit;
if (fDoc.Lines.Count = 0) or not fDoc.isDSource then
begin
clearTree;
updateVisibleCat;
exit;
end;
s := fDoc.Lines.Text;
s := listSymbols(PChar(s), fDeep);
if s.isEmpty or ndAlias.isNil then
if fTreeDataFromThread.isEmpty or ndAlias.isNil then
exit;
clearTree;
updateVisibleCat;
fSyms.LoadFromString(s);
fSyms.LoadFromString(fTreeDataFromThread);
f := TreeFilterEdit1.Filter;
TreeFilterEdit1.Text := '';
tree.BeginUpdate;

View File

@ -95,6 +95,8 @@ type
fDoc: TDexedMemo;
fTodos: TTodoItems;
fOptions: TTodoOptions;
fTodoItemsDataFromThread: string;
fTodoItemsresultFromThread: string;
// IDocumentObserver
procedure docNew(document: TDexedMemo);
procedure docFocused(document: TDexedMemo);
@ -116,6 +118,8 @@ type
// TODOlist things
function getContext: TTodoContext;
procedure scanTodoItems(autoRefreshed: boolean);
procedure scanTodoInThread;
procedure scannedTodoInThread(Sender : TObject);
procedure clearTodoList;
procedure fillTodoList;
procedure lstItemsColumnClick(Sender: TObject; Column: TListColumn);
@ -446,14 +450,33 @@ begin
str += PathSeparator;
end;
end
else str := fDoc.fileName;
else if fDoc.fileName <> newdocPageCaption then
begin
str := fDoc.fileName;
end;
str := todoItems(PChar(str));
if str.length < 10 then
if str.isNotEmpty then
begin
fTodoItemsDataFromThread := str;
TThread.ExecuteInThread(@scanTodoInThread, @scannedTodoInThread);
end;
end;
procedure TTodoListWidget.scanTodoInThread;
begin
fTodoItemsResultFromThread := todoItems(PChar(fTodoItemsDataFromThread));
end;
procedure TTodoListWidget.scannedTodoInThread(Sender : TObject);
var
txt: TmemoryStream;
begin
if fTodoItemsResultFromThread.length < 10 then
exit;
txt := TMemoryStream.create;
try
txt.Write(str[1], str.length);
txt.Write(fTodoItemsResultFromThread[1], fTodoItemsResultFromThread.length);
txt.Position:=0;
fTodos.loadFromTxtStream(txt);
fillTodoList;