Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: Bat on October 31, 2014, 11:26:58 pm

Title: Codesnippets
Post by: Bat on October 31, 2014, 11:26:58 pm
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);
}

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 ?
Title: Re: Codesnippets
Post by: oBFusCATed on November 01, 2014, 05:39:09 pm
I'm not sure I understand what you are talking about.
Title: Re: Codesnippets
Post by: Pecan on November 01, 2014, 06:45:27 pm
What version of CB are you using, and what version of CodeSnippets?
Title: Re: Codesnippets
Post by: Bat on November 01, 2014, 07:18:12 pm
Actual source code (codesnippetstreectrl.cpp) have :
Quote
   
//-wrong--SetItemText(snippetID, pcbEditor->GetName());
//-SetFileChanged(true);
}

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]
Title: Re: Codesnippets
Post by: Bat on November 01, 2014, 07:19:31 pm
What version of CB are you using, and what version of CodeSnippets?
I'm with clean SVN head version 10020
Title: Re: Codesnippets
Post by: Pecan on November 05, 2014, 07:27:58 pm
Thanks for the explanation. I'll try to re-create the situation and fix it.
Title: Re: Codesnippets
Post by: Bat on November 05, 2014, 08:23:51 pm
Thanks !
If other information are needed, don't hesitate
Title: Re: Codesnippets
Post by: Pecan on December 21, 2014, 05:22:34 am
Fixed svn 10051
Title: Re: Codesnippets
Post by: Bat on December 21, 2014, 12:14:32 pm
After a quick try it seems ok