@@ -66,12 +66,27 @@ OverrideMapUpdater::OverrideMapUpdater(void)
6666 /* tinyxml2::XMLElement* pAssoc =*/ add_udl_assoc (" nppexec.xml" , " NppExec" );
6767 }
6868 else {
69- // TODO: !!! NEED TO ADD ERROR CHECKING !!!
7069 // load file and extract the main elements
71- /* tinyxml2::XMLError eResult =*/ pOverrideMapXML->LoadFile (sOverMapPath ().c_str ());
70+ tinyxml2::XMLError eResult = pOverrideMapXML->LoadFile (sOverMapPath ().c_str ());
71+ if (_xml_check_result (eResult, pOverrideMapXML, wsOverMapPath ())) return ;
72+
7273 pRoot = pOverrideMapXML->FirstChildElement (" NotepadPlus" );
74+ if (!pRoot) {
75+ _xml_check_result (tinyxml2::XML_ERROR_PARSING, pOverrideMapXML, wsOverMapPath ());
76+ return ;
77+ }
78+
7379 pFunctionList = pRoot->FirstChildElement (" functionList" );
80+ if (!pFunctionList) {
81+ _xml_check_result (tinyxml2::XML_ERROR_PARSING, pOverrideMapXML, wsOverMapPath ());
82+ return ;
83+ }
84+
7485 pAssociationMap = pFunctionList->FirstChildElement (" associationMap" );
86+ if (!pAssociationMap) {
87+ _xml_check_result (tinyxml2::XML_ERROR_PARSING, pOverrideMapXML, wsOverMapPath ());
88+ return ;
89+ }
7590 }
7691}
7792
@@ -122,20 +137,6 @@ std::vector<tinyxml2::XMLElement*> OverrideMapUpdater::add_udl_assoc(std::map<st
122137 return vpAssoc;
123138}
124139
125- bool OverrideMapUpdater::experiment (void )
126- {
127- add_udl_assoc (" fake.xml" , " FakeUDL" );
128- std::map<std::wstring, std::wstring> myMap = {
129- {L" udl1.xml" , L" UDL 1" },
130- {L" udl2.xml" , L" UDL 2" },
131- {L" udl3.xml" , L" UDL 3" }
132- };
133- add_udl_assoc (myMap);
134- pOverrideMapXML->SaveFile (sOverMapPath ().c_str ());
135-
136- return true ;
137- }
138-
139140// private: case-insensitive std::string equality check
140141bool _string_insensitive_eq (std::string a, std::string b)
141142{
@@ -194,3 +195,44 @@ tinyxml2::XMLElement* OverrideMapUpdater::_find_element_with_attribute_value(tin
194195 }
195196 return pFoundElement;
196197}
198+
199+
200+ // compares the XMLError result to XML_SUCCESS, and returns a TRUE boolean to indicate failure
201+ // p_doc defaults to nullptr, wsFilePath to L""
202+ bool OverrideMapUpdater::_xml_check_result (tinyxml2::XMLError a_eResult, tinyxml2::XMLDocument* p_doc, std::wstring wsFilePath)
203+ {
204+ if (a_eResult != tinyxml2::XML_SUCCESS) {
205+ std::string sMsg = std::string (" XML Error #" ) + std::to_string (static_cast <int >(a_eResult));
206+ if (p_doc != NULL ) {
207+ sMsg += std::string (" : " ) + std::string (p_doc->ErrorStr ());
208+ if (p_doc->ErrorLineNum ()) {
209+ sMsg += " \n\n I will try to open the file near that error." ;
210+ }
211+ }
212+ ::MessageBoxA (NULL , sMsg .c_str(), "XML Error", MB_ICONWARNING | MB_OK);
213+ if (p_doc != NULL && p_doc->ErrorLineNum () && wsFilePath.size ()) {
214+ if (::SendMessage (gNppMetaInfo .hwnd ._nppHandle , NPPM_DOOPEN, 0 , reinterpret_cast <LPARAM>(wsFilePath.c_str ()))) {
215+ extern NppData nppData; // not in PluginDefinition.h
216+
217+ // Get the current scintilla
218+ int which = -1 ;
219+ ::SendMessage (nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0 , (LPARAM)&which);
220+ HWND curScintilla = (which < 1 ) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle ;
221+
222+ // SCI_GOTOLINE in the current scintilla instance
223+ WPARAM zeroLine = static_cast <WPARAM>(p_doc->ErrorLineNum () - 1 );
224+ ::SendMessage (curScintilla, SCI_GOTOLINE, zeroLine, 0 );
225+
226+ // do annotation
227+ ::SendMessage (curScintilla, SCI_ANNOTATIONCLEARALL, 0 , 0 );
228+ ::SendMessage (curScintilla, SCI_ANNOTATIONSETVISIBLE, ANNOTATION_BOXED, 0 );
229+ ::SendMessageA (curScintilla, SCI_ANNOTATIONSETTEXT, zeroLine, reinterpret_cast <LPARAM>(p_doc->ErrorStr ()));
230+
231+ // need to stop
232+ // TODO: DO I NEED?? _doAbort = true;
233+ };
234+ }
235+ return true ;
236+ }
237+ return false ;
238+ };
0 commit comments