Skip to content

Commit

Permalink
optimize ACTL_SYNCHRO
Browse files Browse the repository at this point in the history
  • Loading branch information
ctapmex committed Jun 1, 2021
1 parent ffa490f commit 4ad082c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/FarEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,3 +1360,10 @@ bool FarEditor::isColorerEnable() const
{
return colorerEnable;
}

boolean FarEditor::hasWork()
{
auto invalid_line = baseEditor->getInvalidLine();
EditorInfo ei = enterHandler();
return ei.TotalLines - invalid_line > 0;
}
1 change: 1 addition & 0 deletions src/FarEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class FarEditor : public LineSource

int getParseProgress();
[[nodiscard]] bool isColorerEnable() const;
boolean hasWork();

private:
PluginStartupInfo* info;
Expand Down
57 changes: 45 additions & 12 deletions src/FarEditorSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,17 @@ bool FarEditorSet::configure()

int FarEditorSet::editorInput(const INPUT_RECORD& Rec)
{
if (ignore_event)
if (ignore_event || Rec.EventType != KEY_EVENT)
return 0;
if (Opt.rEnabled) {
FarEditor* editor = getCurrentEditor();
if (editor && editor->isColorerEnable()) {
return editor->editorInput(Rec);
auto res = editor->editorInput(Rec);
if (editor->hasWork())
addEventTimer();
else
removeEventTimer();
return res;
}
}
return 0;
Expand Down Expand Up @@ -555,15 +560,25 @@ int FarEditorSet::editorEvent(const struct ProcessEditorEventInfo* pInfo)
editor = addCurrentEditor();
}
if (editor && editor->isColorerEnable()) {
return editor->editorEvent(pInfo->Event, pInfo->Param);
auto res = editor->editorEvent(pInfo->Event, pInfo->Param);
if (editor->hasWork())
addEventTimer();
else
removeEventTimer();
return res;
}
return 0;
} break;
case EE_CHANGE: {
//запрещено вызывать EditorControl (getCurrentEditor)
auto it_editor = farEditorInstances.find(pInfo->EditorID);
if (it_editor != farEditorInstances.end() && it_editor->second->isColorerEnable()) {
return it_editor->second->editorEvent(pInfo->Event, pInfo->Param);
auto res = it_editor->second->editorEvent(pInfo->Event, pInfo->Param);
if (editor->hasWork())
addEventTimer();
else
removeEventTimer();
return res;
}
else {
return 0;
Expand All @@ -581,9 +596,18 @@ int FarEditorSet::editorEvent(const struct ProcessEditorEventInfo* pInfo)
if (it_editor != farEditorInstances.end()) {
delete it_editor->second;
farEditorInstances.erase(pInfo->EditorID);
removeEventTimer();
}
return 0;
} break;
case EE_GOTFOCUS: {
addEventTimer();
return 0;
} break;
case EE_KILLFOCUS: {
removeEventTimer();
return 0;
} break;
default:
break;
}
Expand Down Expand Up @@ -691,10 +715,7 @@ void FarEditorSet::ReloadBase()
{
ignore_event = true;
try {
if (hTimer) {
DeleteTimerQueueTimer(hTimerQueue, hTimer, nullptr);
}
hTimer = nullptr;
removeEventTimer();
ReadSettings();
applyLogSetting();
if (!Opt.rEnabled) {
Expand Down Expand Up @@ -737,7 +758,7 @@ void FarEditorSet::ReloadBase()
}
//устанавливаем фон редактора при каждой перезагрузке схем.
SetBgEditor();
CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK) ColorThread, nullptr, 200, Opt.ThreadBuildPeriod, 0);
addEventTimer();
} catch (SettingsControlException& e) {
spdlog::error("{0}", e.what());
auto error_mes = UnicodeString(e.what());
Expand Down Expand Up @@ -832,9 +853,7 @@ void FarEditorSet::disableColorer()
SettingsControl ColorerSettings;
ColorerSettings.Set(0, cRegEnabled, Opt.rEnabled);
}
if (hTimer)
DeleteTimerQueueTimer(hTimerQueue, hTimer, nullptr);
hTimer = nullptr;
removeEventTimer();

dropCurrentEditor(true);

Expand Down Expand Up @@ -1206,6 +1225,20 @@ void FarEditorSet::enableColorerInEditor()
new_editor->editorEvent(EE_REDRAW, EEREDRAW_ALL);
}

void FarEditorSet::addEventTimer()
{
if (!hTimer) {
CreateTimerQueueTimer(&hTimer, hTimerQueue, (WAITORTIMERCALLBACK) ColorThread, nullptr, 200, Opt.ThreadBuildPeriod, 0);
}
}

void FarEditorSet::removeEventTimer()
{
if (hTimer)
DeleteTimerQueueTimer(hTimerQueue, hTimer, nullptr);
hTimer = nullptr;
}

#pragma region macro_functions

HANDLE FarEditorSet::openFromMacro(const struct OpenInfo* oInfo)
Expand Down
3 changes: 3 additions & 0 deletions src/FarEditorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class FarEditorSet

void setEmptyLogger();

void addEventTimer();
void removeEventTimer();

enum MENU_ACTION {
NO_ACTION = -1,
LIST_TYPE = 0,
Expand Down

0 comments on commit 4ad082c

Please sign in to comment.