Author Topic: Codesnippets  (Read 10289 times)

Offline Bat

  • Multiple posting newcomer
  • *
  • Posts: 48
Codesnippets
« 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 ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Codesnippets
« Reply #1 on: November 01, 2014, 05:39:09 pm »
I'm not sure I understand what you are talking about.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Codesnippets
« Reply #2 on: November 01, 2014, 06:45:27 pm »
What version of CB are you using, and what version of CodeSnippets?

Offline Bat

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: Codesnippets
« Reply #3 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]
« Last Edit: November 01, 2014, 07:24:58 pm by Bat »

Offline Bat

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: Codesnippets
« Reply #4 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

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Codesnippets
« Reply #5 on: November 05, 2014, 07:27:58 pm »
Thanks for the explanation. I'll try to re-create the situation and fix it.

Offline Bat

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: Codesnippets
« Reply #6 on: November 05, 2014, 08:23:51 pm »
Thanks !
If other information are needed, don't hesitate

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Codesnippets
« Reply #7 on: December 21, 2014, 05:22:34 am »
Fixed svn 10051

Offline Bat

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: Codesnippets
« Reply #8 on: December 21, 2014, 12:14:32 pm »
After a quick try it seems ok