| 
| Custom Editor Saving File causes cursor position to be reset [message #333303] | Wed, 03 December 2008 12:26 |  | 
| Eclipse User  |  |  |  |  | I my custom editor CMakeEditor which extends from TextEditor (cmakeed.sourceforge.net) when the user "saves" the document, the
 cursor is reset to the top of the file which isn't exactly friendly. I
 have some code to stop this from happening but it seems awfully like a
 "kludge" rather than doing it the "correct" way.
 
 Here is my current code foe the doSave(IProgressMonitor prog) method:
 
 public void doSave(IProgressMonitor prog)
 {
 super.doSave(prog);
 UIPlugin.getDefault().getCMakePartitionScanner().setDefaultS cannerRules();
 IDocument document = this.getSourceViewer().getDocument();
 if (document instanceof IDocumentExtension3) {
 IDocumentExtension3 extension3 = (IDocumentExtension3) document;
 IDocumentPartitioner partitioner =
 extension3.getDocumentPartitioner(UIPlugin.CMAKE_PARTITIONIN G);
 if (partitioner != null)
 {
 partitioner.disconnect();
 partitioner.connect(document);
 // Reinit the syntax coloring
 final SourceViewer sourceViewer = (SourceViewer)getSourceViewer();
 int line = sourceViewer.getTopIndex();
 ITextSelection sel = (ITextSelection)sourceViewer.getSelection();
 sourceViewer.unconfigure();
 final CMakeEditorConfiguration config =
 new CMakeEditorConfiguration(this.colorMgr);
 sourceViewer.configure(config);
 sourceViewer.refresh();
 sourceViewer.setTopIndex(line);
 sourceViewer.setSelectedRange(sel.getOffset(), sel.getLength()	);
 }
 
 }
 UIPlugin.getDefault().getCMakePartitionScanner().removeUserV ariableRule();
 }
 
 Any help would be greatly appreciated. Or point me to an example that
 has the desired behavior and I can try an work from that.
 
 Mike Jackson
 BlueQuartz Software
 www.bluequartz.net
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.03678 seconds