Improvements to background validation.

This commit is contained in:
Gerald Schmidt 2008-07-09 17:07:02 +00:00
parent e7724180d7
commit 361eed32b0
5 changed files with 48 additions and 34 deletions

View File

@ -9,6 +9,7 @@ ValidationThread::ValidationThread (
const char *system,
bool *finished,
bool *success,
bool *release,
std::pair<int, int> *position,
std::string *message ) : wxThread()
{
@ -21,6 +22,7 @@ ValidationThread::ValidationThread (
mySystem = system;
myFinishedPtr = finished;
mySuccessPtr = success;
myReleasePtr = release;
myPositionPtr = position;
myMessagePtr = message;
}
@ -29,7 +31,7 @@ void *ValidationThread::Entry()
{
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
if ( TestDestroy() )
if ( *myReleasePtr || TestDestroy() )
Exit();
bool res = validator->validateMemory (
@ -37,7 +39,7 @@ void *ValidationThread::Entry()
mySystem.c_str(),
myBuffer.size() );
if ( TestDestroy() )
if ( *myReleasePtr || TestDestroy() )
Exit();
if ( !res )
@ -52,11 +54,14 @@ void *ValidationThread::Entry()
*myPositionPtr = std::make_pair ( 0, 0 );
*myMessagePtr = "";
}
*myFinishedPtr = true;
return NULL;
}
void ValidationThread::OnExit()
{
if ( *myReleasePtr )
return;
*myFinishedPtr = true;
}

View File

@ -8,12 +8,12 @@
class ValidationThread : public wxThread
{
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 OnExit();
private:
std::string myBuffer, mySystem;
bool *myFinishedPtr, *mySuccessPtr;
bool *myFinishedPtr, *mySuccessPtr, *myReleasePtr;
std::pair<int, int> *myPositionPtr;
std::string *myMessagePtr;
};

View File

@ -2567,6 +2567,7 @@ void MyFrame::OnGlobalReplace ( wxCommandEvent& event )
replaceUtf8,
flags & wxFR_MATCHCASE );
currentDoc->SetTextRaw ( bufferUtf8.c_str() );
currentDoc->setValidationRequired ( true );
}
else
{
@ -2581,6 +2582,7 @@ void MyFrame::OnGlobalReplace ( wxCommandEvent& event )
std::string outputBuffer = wr->replaceGlobal ( bufferUtf8, &matchCount );
globalMatchCount += matchCount;
currentDoc->SetTextRaw ( outputBuffer.c_str() );
currentDoc->setValidationRequired ( true );
}
catch ( std::exception& e )
{
@ -4094,6 +4096,7 @@ void MyFrame::OnPrettyPrint ( wxCommandEvent& event )
statusProgress ( wxEmptyString );
}
doc->setValidationRequired ( true );
doc->GotoLine ( line );
doc->SetFocus();
}
@ -4173,6 +4176,7 @@ void MyFrame::OnEncoding ( wxCommandEvent& event )
}
doc->SetTextRaw ( xur->getBuffer().c_str() );
doc->setValidationRequired ( true );
doc->SetFocus();
}

View File

@ -65,6 +65,7 @@ XmlCtrl::XmlCtrl (
validationThread = NULL;
validationStarted = false;
validationFinished = false;
validationRelease = false;
grammarFound = false;
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 )
{
if ( properties.number && type != FILE_TYPE_BINARY )
adjustNoColumnWidth(); // exits if unchanged
// poll validation thread output if any
if (validationStarted && validationFinished)
{
@ -155,9 +159,6 @@ void XmlCtrl::OnIdle ( wxIdleEvent& event )
frame->statusProgress ( wxString ( validationMessage.c_str(), wxConvUTF8, validationMessage.size() ) );
}
}
if ( properties.number && type != FILE_TYPE_BINARY )
adjustNoColumnWidth();
}
void XmlCtrl::OnChar ( wxKeyEvent& event )
@ -445,14 +446,14 @@ void XmlCtrl::handleOpenAngleBracket ( wxKeyEvent& event )
if ( AutoCompActive() )
AutoCompCancel();
validationRequired = true;
if ( *protectTags )
{
AddText ( _T ( "&lt;" ) );
return;
}
validationRequired = true;
AddText ( _T ( "<" ) );
int pos = GetCurrentPos();
@ -503,14 +504,14 @@ void XmlCtrl::handleCloseAngleBracket ( wxKeyEvent& event )
if ( AutoCompActive() )
AutoCompCancel();
validationRequired = true;
if ( *protectTags )
{
AddText ( _T ( "&gt;" ) );
return;
}
validationRequired = true;
wxString insertBuffer;
int pos;
pos = GetCurrentPos();
@ -689,7 +690,10 @@ void XmlCtrl::handleSpace ( wxKeyEvent& event )
choice.Append ( conversion );
}
if ( !choice.empty() )
{
UserListShow ( 0, choice );
validationRequired = true;
}
}
void XmlCtrl::handleAmpersand ( wxKeyEvent& event )
@ -757,6 +761,7 @@ void XmlCtrl::handleForwardSlash ( wxKeyEvent& event )
if ( wideParent.empty() )
return;
AddText ( wideParent + _T ( ">" ) );
validationRequired = true;
}
void XmlCtrl::OnKeyPressed ( wxKeyEvent& event )
@ -868,6 +873,7 @@ void XmlCtrl::OnKeyPressed ( wxKeyEvent& event )
break;
case WXK_BACK:
handleBackspace ( event );
validationRequired = true;
return;
case WXK_TAB:
if ( *protectTags )
@ -914,6 +920,7 @@ void XmlCtrl::OnKeyPressed ( wxKeyEvent& event )
break;
case WXK_DELETE:
handleDelete ( event );
validationRequired = true;
return;
default:
break;
@ -2006,35 +2013,34 @@ bool XmlCtrl::shallowValidate ( int maxLine, bool segmentOnly )
bool XmlCtrl::shallowValidate (
const char *buffer,
const char *system,
size_t bufferLen//,
//int startLine,
//int maxLine,
//int columnOffset,
//bool segmentOnly
size_t bufferLen
)
{
if ( !validationRequired )
return true;
if ( validationStarted && !validationFinished )
{
validationRelease = true;
return true; // wait for next idle cycle call from main app frame
}
validationRequired = false;
if (validationThread && !validationFinished)
{
validationThread->Delete();
validationThread = NULL;
}
validationRelease = false;
validationThread = new ValidationThread(
buffer,
system,
&validationFinished,
&validationSuccess,
&validationRelease,
&validationPosition,
&validationMessage
);
if ( validationThread->Create() != wxTHREAD_NO_ERROR )
{
validationStarted = false;
validationFinished = true;
return false;
}
@ -2042,7 +2048,6 @@ bool XmlCtrl::shallowValidate (
validationStarted = true;
validationFinished = false;
validationThread->Run();
return true;

View File

@ -113,7 +113,9 @@ class XmlCtrl: public wxStyledTextCtrl
attributeMap.clear();
elementMap.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 getParentCloseAngleBracket ( int pos, int range = USHRT_MAX * 4 );
@ -147,19 +149,17 @@ class XmlCtrl: public wxStyledTextCtrl
bool shallowValidate (
const char *buffer,
const char *system,
size_t bufferLen//,
//int startLine = 0,
//int maxLine = 0,
//int columnOffset = 0,
//bool segmentOnly = false
);
size_t bufferLen );
std::string myGetTextRaw(); // alternative to faulty stc implementation
bool getValidationRequired();
void setValidationRequired ( bool b );
private:
// the following are used for background validation
ValidationThread *validationThread;
bool validationStarted, validationFinished, validationSuccess;
bool validationStarted,
validationFinished,
validationSuccess,
validationRelease;
std::pair<int, int> validationPosition;
std::string validationMessage;