1 20 21 package org.apache.directory.ldapstudio.ldifeditor.editor.text; 22 23 24 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile; 25 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart; 26 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifChangeModifyRecord; 27 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer; 28 import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifModSpec; 29 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifAttrValLine; 30 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifModSpecTypeLine; 31 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants; 32 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator; 33 import org.apache.directory.ldapstudio.ldifeditor.editor.ILdifEditor; 34 35 import org.eclipse.jface.text.DocumentCommand; 36 import org.eclipse.jface.text.IAutoEditStrategy; 37 import org.eclipse.jface.text.IDocument; 38 import org.eclipse.jface.text.TextUtilities; 39 40 41 public class LdifAutoEditStrategy implements IAutoEditStrategy 42 { 43 44 private ILdifEditor editor; 45 46 47 public LdifAutoEditStrategy( ILdifEditor editor ) 48 { 49 this.editor = editor; 50 } 51 52 53 public void customizeDocumentCommand( IDocument d, DocumentCommand c ) 54 { 55 56 LdifFile model = editor.getLdifModel(); 57 LdifContainer container = LdifFile.getContainer( model, c.offset ); 58 LdifContainer innerContainer = container != null ? LdifFile.getInnerContainer( container, c.offset ) : null; 59 LdifPart part = container != null ? LdifFile.getContainerContent( container, c.offset ) : null; 60 61 boolean smartInsertAttributeInModSpec = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean( 62 LdifEditorConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC ); 63 if ( smartInsertAttributeInModSpec ) 64 { 65 if ( c.length == 0 && c.text != null && TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 ) 66 { 67 68 if ( container instanceof LdifChangeModifyRecord && innerContainer instanceof LdifModSpec 69 && ( part instanceof LdifAttrValLine || part instanceof LdifModSpecTypeLine ) ) 70 { 71 LdifModSpec modSpec = ( LdifModSpec ) innerContainer; 72 String att = modSpec.getModSpecType().getUnfoldedAttributeDescription(); 73 c.text += att + ": "; 74 } 75 } 76 } 77 78 boolean autoWrap = LdifEditorActivator.getDefault().getPreferenceStore().getBoolean( 79 LdifEditorConstants.PREFERENCE_LDIFEDITOR_FORMATTER_AUTOWRAP ); 80 81 if ( autoWrap ) 82 { 83 84 } 85 86 } 87 88 } 89 | Popular Tags |