Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Codesnippets
Bat:
I use it with small snippet directly in snippet data file (no external file). Theses snippets are opened in a temporary file. During save command, data are save back on XML data but not saved on disk
I've tracked down and it's related to end of function
--- Code: ---// ----------------------------------------------------------------------------
void CodeSnippetsTreeCtrl::SaveEditorsXmlData(cbEditor* pcbEditor)
// ----------------------------------------------------------------------------
{//asm("int3"); /*trap*/
int idx = m_EditorPtrArray.Index(pcbEditor);
if (wxNOT_FOUND == idx)
return;
wxTreeItemId snippetID = m_EditorSnippetIdArray[idx];
//Is this an XML snippet, as opposed to a FileLink or URL snippet
SnippetTreeItemData* pSnippetTreeItemData = (SnippetTreeItemData*)(GetItemData(snippetID));
//-if (pSnippetTreeItemData->IsSnippetFile())
//- return;
pSnippetTreeItemData->SetSnippetString(pcbEditor->GetControl()->GetText());
//-wrong--SetItemText(snippetID, pcbEditor->GetName());
// Must be set to ensure file is correctly saved
SetFileChanged(true);
}
--- End code ---
SetFileChanged was commented out. It's the problem, but there is probably a another case (that I don't see), where it should be commented ?
oBFusCATed:
I'm not sure I understand what you are talking about.
Pecan:
What version of CB are you using, and what version of CodeSnippets?
Bat:
Actual source code (codesnippetstreectrl.cpp) have :
--- Quote ---
//-wrong--SetItemText(snippetID, pcbEditor->GetName());
//-SetFileChanged(true);
}
--- End quote ---
I understand that SetItemText and SetFileChanged are commented out for some reason (I don't know)
1)I create a new snippet, made modifications, save it and close C::B
I reopen C::B, snippet is here with data. Good.
2)I open this existant snippet (it open in a cbEditor window), made some change, hit close. I have question "Do you want to save temp_directory\snippet name.txt ?". I say Yes.
Next I close codeblocks. I reopen C::B, snippet modifications are lost.
If I uncomment SetFileChanged(true); it works correctly in second "edit only" case.
In my understanding, save of snippet data is a 2 step process. First, save edited snippet to internal XML data (attached to CodeSnippet treeview). Here it goes well. Second stage is saving whole XML code snippets to file.This is done on app closing.
But If this SetFileChanged(true); have been commented I suppose there is others usages where it's a problem ...
Note even with this modification, there is another race case. If I edit a snippet, but I don't save cbEditor window before closing C::B, OnClose of cbEditor will be called after CodeSnippet one. So here too, data will be lost.
I don't know which method is best to solve this :
-I can't postpone saving XML data on second OnRelease call, as window treeview that handled data would have been destroyed at this time
-If CodeSnippet have an internal list of cbEditor that it handle probably a solution is to request a close of them before saving XML data in OnRelease()
[Minor editing for better understanting]
Bat:
--- Quote from: Pecan on November 01, 2014, 06:45:27 pm ---What version of CB are you using, and what version of CodeSnippets?
--- End quote ---
I'm with clean SVN head version 10020
Navigation
[0] Message Index
[#] Next page
Go to full version