Improvements to background validation.
This commit is contained in:
parent
e7724180d7
commit
361eed32b0
|
@ -9,6 +9,7 @@ ValidationThread::ValidationThread (
|
||||||
const char *system,
|
const char *system,
|
||||||
bool *finished,
|
bool *finished,
|
||||||
bool *success,
|
bool *success,
|
||||||
|
bool *release,
|
||||||
std::pair<int, int> *position,
|
std::pair<int, int> *position,
|
||||||
std::string *message ) : wxThread()
|
std::string *message ) : wxThread()
|
||||||
{
|
{
|
||||||
|
@ -21,6 +22,7 @@ ValidationThread::ValidationThread (
|
||||||
mySystem = system;
|
mySystem = system;
|
||||||
myFinishedPtr = finished;
|
myFinishedPtr = finished;
|
||||||
mySuccessPtr = success;
|
mySuccessPtr = success;
|
||||||
|
myReleasePtr = release;
|
||||||
myPositionPtr = position;
|
myPositionPtr = position;
|
||||||
myMessagePtr = message;
|
myMessagePtr = message;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +31,7 @@ void *ValidationThread::Entry()
|
||||||
{
|
{
|
||||||
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
|
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
|
||||||
|
|
||||||
if ( TestDestroy() )
|
if ( *myReleasePtr || TestDestroy() )
|
||||||
Exit();
|
Exit();
|
||||||
|
|
||||||
bool res = validator->validateMemory (
|
bool res = validator->validateMemory (
|
||||||
|
@ -37,7 +39,7 @@ void *ValidationThread::Entry()
|
||||||
mySystem.c_str(),
|
mySystem.c_str(),
|
||||||
myBuffer.size() );
|
myBuffer.size() );
|
||||||
|
|
||||||
if ( TestDestroy() )
|
if ( *myReleasePtr || TestDestroy() )
|
||||||
Exit();
|
Exit();
|
||||||
|
|
||||||
if ( !res )
|
if ( !res )
|
||||||
|
@ -52,11 +54,14 @@ void *ValidationThread::Entry()
|
||||||
*myPositionPtr = std::make_pair ( 0, 0 );
|
*myPositionPtr = std::make_pair ( 0, 0 );
|
||||||
*myMessagePtr = "";
|
*myMessagePtr = "";
|
||||||
}
|
}
|
||||||
*myFinishedPtr = true;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidationThread::OnExit()
|
void ValidationThread::OnExit()
|
||||||
{
|
{
|
||||||
|
if ( *myReleasePtr )
|
||||||
|
return;
|
||||||
|
|
||||||
|
*myFinishedPtr = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
class ValidationThread : public wxThread
|
class ValidationThread : public wxThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ValidationThread ( const char *buffer, const char *system, bool *finished, bool *success, std::pair<int, int> *position, std::string *message );
|
ValidationThread ( const char *buffer, const char *system, bool *finished, bool *success, bool *release, std::pair<int, int> *position, std::string *message );
|
||||||
virtual void *Entry();
|
virtual void *Entry();
|
||||||
virtual void OnExit();
|
virtual void OnExit();
|
||||||
private:
|
private:
|
||||||
std::string myBuffer, mySystem;
|
std::string myBuffer, mySystem;
|
||||||
bool *myFinishedPtr, *mySuccessPtr;
|
bool *myFinishedPtr, *mySuccessPtr, *myReleasePtr;
|
||||||
std::pair<int, int> *myPositionPtr;
|
std::pair<int, int> *myPositionPtr;
|
||||||
std::string *myMessagePtr;
|
std::string *myMessagePtr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2567,6 +2567,7 @@ void MyFrame::OnGlobalReplace ( wxCommandEvent& event )
|
||||||
replaceUtf8,
|
replaceUtf8,
|
||||||
flags & wxFR_MATCHCASE );
|
flags & wxFR_MATCHCASE );
|
||||||
currentDoc->SetTextRaw ( bufferUtf8.c_str() );
|
currentDoc->SetTextRaw ( bufferUtf8.c_str() );
|
||||||
|
currentDoc->setValidationRequired ( true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2581,6 +2582,7 @@ void MyFrame::OnGlobalReplace ( wxCommandEvent& event )
|
||||||
std::string outputBuffer = wr->replaceGlobal ( bufferUtf8, &matchCount );
|
std::string outputBuffer = wr->replaceGlobal ( bufferUtf8, &matchCount );
|
||||||
globalMatchCount += matchCount;
|
globalMatchCount += matchCount;
|
||||||
currentDoc->SetTextRaw ( outputBuffer.c_str() );
|
currentDoc->SetTextRaw ( outputBuffer.c_str() );
|
||||||
|
currentDoc->setValidationRequired ( true );
|
||||||
}
|
}
|
||||||
catch ( std::exception& e )
|
catch ( std::exception& e )
|
||||||
{
|
{
|
||||||
|
@ -4094,6 +4096,7 @@ void MyFrame::OnPrettyPrint ( wxCommandEvent& event )
|
||||||
statusProgress ( wxEmptyString );
|
statusProgress ( wxEmptyString );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doc->setValidationRequired ( true );
|
||||||
doc->GotoLine ( line );
|
doc->GotoLine ( line );
|
||||||
doc->SetFocus();
|
doc->SetFocus();
|
||||||
}
|
}
|
||||||
|
@ -4173,6 +4176,7 @@ void MyFrame::OnEncoding ( wxCommandEvent& event )
|
||||||
}
|
}
|
||||||
|
|
||||||
doc->SetTextRaw ( xur->getBuffer().c_str() );
|
doc->SetTextRaw ( xur->getBuffer().c_str() );
|
||||||
|
doc->setValidationRequired ( true );
|
||||||
doc->SetFocus();
|
doc->SetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ XmlCtrl::XmlCtrl (
|
||||||
validationThread = NULL;
|
validationThread = NULL;
|
||||||
validationStarted = false;
|
validationStarted = false;
|
||||||
validationFinished = false;
|
validationFinished = false;
|
||||||
|
validationRelease = false;
|
||||||
grammarFound = false;
|
grammarFound = false;
|
||||||
validationRequired = (buffer) ? true : false; // NULL for plain XML template
|
validationRequired = (buffer) ? true : false; // NULL for plain XML template
|
||||||
|
|
||||||
|
@ -138,6 +139,9 @@ static wxColor LightColour ( const wxColour& color, int percent )
|
||||||
|
|
||||||
void XmlCtrl::OnIdle ( wxIdleEvent& event )
|
void XmlCtrl::OnIdle ( wxIdleEvent& event )
|
||||||
{
|
{
|
||||||
|
if ( properties.number && type != FILE_TYPE_BINARY )
|
||||||
|
adjustNoColumnWidth(); // exits if unchanged
|
||||||
|
|
||||||
// poll validation thread output if any
|
// poll validation thread output if any
|
||||||
if (validationStarted && validationFinished)
|
if (validationStarted && validationFinished)
|
||||||
{
|
{
|
||||||
|
@ -155,9 +159,6 @@ void XmlCtrl::OnIdle ( wxIdleEvent& event )
|
||||||
frame->statusProgress ( wxString ( validationMessage.c_str(), wxConvUTF8, validationMessage.size() ) );
|
frame->statusProgress ( wxString ( validationMessage.c_str(), wxConvUTF8, validationMessage.size() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( properties.number && type != FILE_TYPE_BINARY )
|
|
||||||
adjustNoColumnWidth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlCtrl::OnChar ( wxKeyEvent& event )
|
void XmlCtrl::OnChar ( wxKeyEvent& event )
|
||||||
|
@ -445,14 +446,14 @@ void XmlCtrl::handleOpenAngleBracket ( wxKeyEvent& event )
|
||||||
if ( AutoCompActive() )
|
if ( AutoCompActive() )
|
||||||
AutoCompCancel();
|
AutoCompCancel();
|
||||||
|
|
||||||
|
validationRequired = true;
|
||||||
|
|
||||||
if ( *protectTags )
|
if ( *protectTags )
|
||||||
{
|
{
|
||||||
AddText ( _T ( "<" ) );
|
AddText ( _T ( "<" ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
validationRequired = true;
|
|
||||||
|
|
||||||
AddText ( _T ( "<" ) );
|
AddText ( _T ( "<" ) );
|
||||||
|
|
||||||
int pos = GetCurrentPos();
|
int pos = GetCurrentPos();
|
||||||
|
@ -503,14 +504,14 @@ void XmlCtrl::handleCloseAngleBracket ( wxKeyEvent& event )
|
||||||
if ( AutoCompActive() )
|
if ( AutoCompActive() )
|
||||||
AutoCompCancel();
|
AutoCompCancel();
|
||||||
|
|
||||||
|
validationRequired = true;
|
||||||
|
|
||||||
if ( *protectTags )
|
if ( *protectTags )
|
||||||
{
|
{
|
||||||
AddText ( _T ( ">" ) );
|
AddText ( _T ( ">" ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
validationRequired = true;
|
|
||||||
|
|
||||||
wxString insertBuffer;
|
wxString insertBuffer;
|
||||||
int pos;
|
int pos;
|
||||||
pos = GetCurrentPos();
|
pos = GetCurrentPos();
|
||||||
|
@ -689,7 +690,10 @@ void XmlCtrl::handleSpace ( wxKeyEvent& event )
|
||||||
choice.Append ( conversion );
|
choice.Append ( conversion );
|
||||||
}
|
}
|
||||||
if ( !choice.empty() )
|
if ( !choice.empty() )
|
||||||
|
{
|
||||||
UserListShow ( 0, choice );
|
UserListShow ( 0, choice );
|
||||||
|
validationRequired = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlCtrl::handleAmpersand ( wxKeyEvent& event )
|
void XmlCtrl::handleAmpersand ( wxKeyEvent& event )
|
||||||
|
@ -757,6 +761,7 @@ void XmlCtrl::handleForwardSlash ( wxKeyEvent& event )
|
||||||
if ( wideParent.empty() )
|
if ( wideParent.empty() )
|
||||||
return;
|
return;
|
||||||
AddText ( wideParent + _T ( ">" ) );
|
AddText ( wideParent + _T ( ">" ) );
|
||||||
|
validationRequired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlCtrl::OnKeyPressed ( wxKeyEvent& event )
|
void XmlCtrl::OnKeyPressed ( wxKeyEvent& event )
|
||||||
|
@ -868,6 +873,7 @@ void XmlCtrl::OnKeyPressed ( wxKeyEvent& event )
|
||||||
break;
|
break;
|
||||||
case WXK_BACK:
|
case WXK_BACK:
|
||||||
handleBackspace ( event );
|
handleBackspace ( event );
|
||||||
|
validationRequired = true;
|
||||||
return;
|
return;
|
||||||
case WXK_TAB:
|
case WXK_TAB:
|
||||||
if ( *protectTags )
|
if ( *protectTags )
|
||||||
|
@ -914,6 +920,7 @@ void XmlCtrl::OnKeyPressed ( wxKeyEvent& event )
|
||||||
break;
|
break;
|
||||||
case WXK_DELETE:
|
case WXK_DELETE:
|
||||||
handleDelete ( event );
|
handleDelete ( event );
|
||||||
|
validationRequired = true;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -2006,35 +2013,34 @@ bool XmlCtrl::shallowValidate ( int maxLine, bool segmentOnly )
|
||||||
bool XmlCtrl::shallowValidate (
|
bool XmlCtrl::shallowValidate (
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const char *system,
|
const char *system,
|
||||||
size_t bufferLen//,
|
size_t bufferLen
|
||||||
//int startLine,
|
|
||||||
//int maxLine,
|
|
||||||
//int columnOffset,
|
|
||||||
//bool segmentOnly
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ( !validationRequired )
|
if ( !validationRequired )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
|
if ( validationStarted && !validationFinished )
|
||||||
|
{
|
||||||
|
validationRelease = true;
|
||||||
|
return true; // wait for next idle cycle call from main app frame
|
||||||
|
}
|
||||||
validationRequired = false;
|
validationRequired = false;
|
||||||
|
|
||||||
if (validationThread && !validationFinished)
|
validationRelease = false;
|
||||||
{
|
|
||||||
validationThread->Delete();
|
|
||||||
validationThread = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
validationThread = new ValidationThread(
|
validationThread = new ValidationThread(
|
||||||
buffer,
|
buffer,
|
||||||
system,
|
system,
|
||||||
&validationFinished,
|
&validationFinished,
|
||||||
&validationSuccess,
|
&validationSuccess,
|
||||||
|
&validationRelease,
|
||||||
&validationPosition,
|
&validationPosition,
|
||||||
&validationMessage
|
&validationMessage
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( validationThread->Create() != wxTHREAD_NO_ERROR )
|
if ( validationThread->Create() != wxTHREAD_NO_ERROR )
|
||||||
{
|
{
|
||||||
|
validationStarted = false;
|
||||||
validationFinished = true;
|
validationFinished = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2042,7 +2048,6 @@ bool XmlCtrl::shallowValidate (
|
||||||
validationStarted = true;
|
validationStarted = true;
|
||||||
validationFinished = false;
|
validationFinished = false;
|
||||||
|
|
||||||
|
|
||||||
validationThread->Run();
|
validationThread->Run();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,9 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
attributeMap.clear();
|
attributeMap.clear();
|
||||||
elementMap.clear();
|
elementMap.clear();
|
||||||
entitySet.clear();
|
entitySet.clear();
|
||||||
// don't delete validationThread in case it's gone
|
|
||||||
|
// don't delete thread in case it's gone - just set the release flag
|
||||||
|
validationRelease = true;
|
||||||
}
|
}
|
||||||
int getType();
|
int getType();
|
||||||
int getParentCloseAngleBracket ( int pos, int range = USHRT_MAX * 4 );
|
int getParentCloseAngleBracket ( int pos, int range = USHRT_MAX * 4 );
|
||||||
|
@ -147,19 +149,17 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
bool shallowValidate (
|
bool shallowValidate (
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const char *system,
|
const char *system,
|
||||||
size_t bufferLen//,
|
size_t bufferLen );
|
||||||
//int startLine = 0,
|
|
||||||
//int maxLine = 0,
|
|
||||||
//int columnOffset = 0,
|
|
||||||
//bool segmentOnly = false
|
|
||||||
);
|
|
||||||
std::string myGetTextRaw(); // alternative to faulty stc implementation
|
std::string myGetTextRaw(); // alternative to faulty stc implementation
|
||||||
bool getValidationRequired();
|
bool getValidationRequired();
|
||||||
void setValidationRequired ( bool b );
|
void setValidationRequired ( bool b );
|
||||||
private:
|
private:
|
||||||
// the following are used for background validation
|
// the following are used for background validation
|
||||||
ValidationThread *validationThread;
|
ValidationThread *validationThread;
|
||||||
bool validationStarted, validationFinished, validationSuccess;
|
bool validationStarted,
|
||||||
|
validationFinished,
|
||||||
|
validationSuccess,
|
||||||
|
validationRelease;
|
||||||
std::pair<int, int> validationPosition;
|
std::pair<int, int> validationPosition;
|
||||||
std::string validationMessage;
|
std::string validationMessage;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue