On Tuesday 03 May 2011 07:11:04 ext Michael Klank wrote:
> I'm developing a QtCreator plug-in, which should generates/removes (a lot)
> source code. I have problems with add/remove source code and the document
> sync, probably.
> 
> In details, I have to remove a method from a class (*.h, *.cpp) as next I
> have to add new methods. The problem is that some code is not removed from
> class, probably the document is out of sync?!?! I tried
> CPlusPlus::CppModelManagerInterface::instance()->updateModifiedSourceFiles(
> ); to get sync but it doesn't work.
> 
> How can I handle add/remove source code to a "Document::Ptr" in a save way,
> without losing sync?

I strongly recommend you use CppTools::CppRefactoringChanges for applying 
changes to source files. Not only does it take care of triggering the right 
update signals, it also does the right thing if the document you want to 
modify is currently opened in Creator.

Short (untested) example:

{
CppRefactoringChanges changes(modelManager->snapshot());
CppRefactoringFile file = changes.file("/path/to/myfile.cpp");

ChangeSet changeSet;
// use file.document() (QTextDocument)
// and file.cppDocument() (Document::Ptr) and fill changeSet
file.change(changeSet);

} // changes are applied as the Refactoring classes are destroyed

Also look at cppquickfixes.cpp for some more examples.

Regards,
Christian
_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-creator

Reply via email to