1
Plugins development / Re: BrowseTracker : toolbar button to jump to previously edited location
« Last post by Pecan on Today at 06:57:35 pm »@ christ
I've modified the code to use the scintilla editor hook rather than the CB editor modified event. It's working well.
I removed the RegisterEventSink() to your cbEVT_EDITOR_MODIFIED event and added code to simply emulate the event with a call to OnEditorModifiedEvent() when scintilla indicates a mod has been made(BrowseTracker.cpp:2724 see the line marked // (ph 25/09/17)) . Easy change.
Your mod to BrowseTracker is a pleasing addition.
Will commit after using for some days.
I've modified the code to use the scintilla editor hook rather than the CB editor modified event. It's working well.
I removed the RegisterEventSink() to your cbEVT_EDITOR_MODIFIED event and added code to simply emulate the event with a call to OnEditorModifiedEvent() when scintilla indicates a mod has been made(BrowseTracker.cpp:2724 see the line marked // (ph 25/09/17)) . Easy change.
Code
// ----------------------------------------------------------------------------
void BrowseTracker::OnEditorEventHook(cbEditor* pcbEditor, wxScintillaEvent& event)
// ----------------------------------------------------------------------------
{
// Catch changes to the source and queue editor and line to update browse locations
// **Debugging**
// wxString txt = _T("OnEditorModified(): ");
// int flags = event.GetModificationType();
// if (flags & wxSCI_MOD_CHANGEMARKER) txt << _T("wxSCI_MOD_CHANGEMARKER, ");
// if (flags & wxSCI_MOD_INSERTTEXT) txt << _T("wxSCI_MOD_INSERTTEXT, ");
// if (flags & wxSCI_MOD_DELETETEXT) txt << _T("wxSCI_MOD_DELETETEXT, ");
// if (flags & wxSCI_MOD_CHANGEFOLD) txt << _T("wxSCI_MOD_CHANGEFOLD, ");
// if (flags & wxSCI_PERFORMED_USER) txt << _T("wxSCI_PERFORMED_USER, ");
// if (flags & wxSCI_MOD_BEFOREINSERT) txt << _T("wxSCI_MOD_BEFOREINSERT, ");
// if (flags & wxSCI_MOD_BEFOREDELETE) txt << _T("wxSCI_MOD_BEFOREDELETE, ");
// if (flags == wxEVT_SCI_MODIFIED) txt << _T("wxSCI_MODIFIED, ");
// if (flags == wxEVT_SCI_UPDATEUI) txt << _T("wxEVT_SCI_UPDATEUI, ");
// txt << _T("EventFlags=")
// << wxString::Format(_T("%d"), flags)
// << _T(" pos=")
// << wxString::Format(_T("%d"), event.GetPosition())
// << _T(", line=")
// << wxString::Format(_T("%d"), event.GetLine())
// << _T(", linesAdded=")
// << wxString::Format(_T("%d"), event.GetLinesAdded());
// Manager::Get()->GetLogManager()->DebugLog(txt);
//
// if (event.GetEventType() == wxEVT_SCI_CHARADDED)
// { Manager::Get()->GetLogManager()->DebugLog(_T("-- > OnEditorHook: wxEVT_SCI_CHARADDED")); }
// else if (event.GetEventType() == wxEVT_SCI_CHANGE)
// { Manager::Get()->GetLogManager()->DebugLog(_T("-- > OnEditorHook: wxEVT_SCI_CHANGE")); }
// else if (event.GetEventType() == wxEVT_SCI_MODIFIED)
// { Manager::Get()->GetLogManager()->DebugLog(_T("-- > OnEditorHook: wxEVT_SCI_MODIFIED")); }
// else if (event.GetEventType() == wxEVT_SCI_AUTOCOMP_SELECTION)
// { Manager::Get()->GetLogManager()->DebugLog(_T("-- > OnEditorHook: wxEVT_SCI_AUTOCOMP_SELECTION")); }
// else if (event.GetEventType() == wxEVT_SCI_AUTOCOMP_CANCELLED)
// { Manager::Get()->GetLogManager()->DebugLog(_T("-- > OnEditorHook: wxEVT_SCI_AUTOCOMP_CANCELLED")); }
event.Skip();
if (not IsBrowseMarksEnabled())
return;
cbStyledTextCtrl* control = pcbEditor->GetControl();
if( m_bProjectIsLoading) return;
if (event.GetEventType() != wxEVT_SCI_MODIFIED)
return;
// Record action in line only once
if (control->GetCurrentLine() == m_EditorHookCurrentLine)
return;
//if ( event.GetEventType() != wxEVT_SCI_MODIFIED )
// if ( event.GetEventType() == wxEVT_SCI_MODIFIED )
if (event.GetEventType() == wxEVT_SCI_MODIFIED)
{
// Whenever event.GetLinesAdded() != 0, we must re-set BrowseMarks for lines greater
// than LineFromPosition(event.GetPosition())
int flags = event.GetModificationType();
bool changed = false;
changed |= flags & wxSCI_MOD_INSERTTEXT;
changed |= flags & wxSCI_MOD_DELETETEXT;
changed |= flags & wxSCI_PERFORMED_USER;
changed |= (event.GetEventType() == wxEVT_SCI_CHARADDED);
int linesAdded = event.GetLinesAdded();
// **Debugging**
// if (linesAdded)
// Manager::Get()->GetLogManager()->DebugLog(wxString::Format("EditorHook Lines Added linesAdded:%d", linesAdded));
if (changed or linesAdded)
{
#if defined(LOGGING)
//LOGIT( _T("BT EditorEventHook isAdd[%d]isDel[%d]lines[%d]"), isAdd, isDel, linesAdded );
#endif
// rebuild BrowseMarks from scintilla marks
m_EditorHookCurrentLine = control->GetCurrentLine();
//RebuildBrowse_Marks( pcbEditor, isAdd );
// Function to add an item to the map
//std::lock_guard<std::mutex> lock(m_EditorHookmapMutex); // Lock the mutex
if (m_EditorHookmapMutex.try_lock())
{
// Mutex was successfully locked
m_EditorHookFileLineMap.insert({pcbEditor, control->GetCurrentLine()});
m_EditorHookmapMutex.unlock();
} else {
// Mutex is already locked, handle accordingly
m_EditorHookCurrentLine = -1; //try again next later.
}
// Tell JumpTracker that this editor has been modified // (ph 25/09/17)
if (m_pJumpTracker.get())
{
CodeBlocksEvent evt(cbEVT_EDITOR_MODIFIED);
evt.SetEditor(pcbEditor);
m_pJumpTracker->OnEditorModifiedEvent(evt);
}
}//endif changed
}//endif wxEVT_SCI_MODIFIED
// wxSCI_MOD_CHANGEMARKER is an extremely expensive call. It's called
// for each line during a file load, and for every change to every
// margin marker in the known cosmos. So here we allow a "one shot only"
// to catch the marker changed by a margin context menu.
// cf: CloneBookMarkFromEditor() and OnMarginContextMenu()
//if ( event.GetEventType() == wxEVT_SCI_MODIFIED )
if (event.GetEventType() == wxEVT_SCI_MODIFIED)
do{
if ( m_OnEditorEventHookIgnoreMarkerChanges )
break;
int flags = event.GetModificationType();
if (flags & wxSCI_MOD_CHANGEMARKER )
{
m_OnEditorEventHookIgnoreMarkerChanges = true;
int line = event.GetLine();
#if defined(LOGGING)
//LOGIT( _T("BT wxSCI_MOD_CHANGEMARKER line[%d]"), line );
#endif
CloneBookMarkFromEditor( line );
}
}while(false);
}//OnEditorEventHook
Will commit after using for some days.