diff -r db41f88fcafd csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java --- a/csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java Thu Sep 15 09:09:55 2011 +0200 +++ b/csl.api/src/org/netbeans/modules/csl/core/GsfDataObject.java Thu Sep 15 09:11:38 2011 +0200 @@ -51,6 +51,7 @@ import org.netbeans.api.actions.Openable; import org.netbeans.api.lexer.InputAttributes; import org.netbeans.core.api.multiview.MultiViews; +import org.netbeans.modules.csl.api.GsfLanguage; import org.netbeans.modules.editor.NbEditorUtilities; import org.openide.cookies.CloseCookie; import org.openide.cookies.EditCookie; @@ -116,6 +117,17 @@ return 1; } + @Override + public void setModified(boolean modif) { + super.setModified(modif); + if (!modif) { + GenericEditorSupport ges = getLookup().lookup(GenericEditorSupport.class); + ges.removeSaveCookie(); + } + } + + + public @Override T getCookie(Class type) { return getCookieSet().getCookie(type); } @@ -265,6 +277,10 @@ protected @Override void notifyUnmodified() { super.notifyUnmodified(); + removeSaveCookie(); + } + + final void removeSaveCookie() { ((Environment)this.env).removeSaveCookie(); } @@ -282,7 +298,10 @@ // Enter the file object in to InputAtrributes. It can be used by lexer. InputAttributes attributes = new InputAttributes(); FileObject fileObject = NbEditorUtilities.getFileObject(doc); - attributes.setValue(language.getGsfLanguage().getLexerLanguage(), FileObject.class, fileObject, false); + final GsfLanguage lng = language.getGsfLanguage(); + if (lng != null) { + attributes.setValue(lng.getLexerLanguage(), FileObject.class, fileObject, false); + } doc.putProperty(InputAttributes.class, attributes); return doc; } diff -r db41f88fcafd csl.api/test/unit/src/org/netbeans/modules/csl/core/GsfDataObjectTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/csl.api/test/unit/src/org/netbeans/modules/csl/core/GsfDataObjectTest.java Thu Sep 15 09:11:38 2011 +0200 @@ -0,0 +1,71 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development and + * Distribution License("CDDL") (collectively, the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy of + * the License at http://www.netbeans.org/cddl-gplv2.html or + * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language + * governing permissions and limitations under the License. When distributing + * the software, include this License Header Notice in each file and include + * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided by + * Oracle in the GPL Version 2 section of the License file that accompanied + * this code. If applicable, add the following below the License Header, with + * the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you do not indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to its + * licensees as provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the option applies only + * if the new code is made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.csl.core; + +import org.netbeans.junit.NbTestCase; +import org.openide.cookies.EditorCookie; +import org.openide.cookies.SaveCookie; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; + +public class GsfDataObjectTest extends NbTestCase { + static { + FileUtil.setMIMEType("test", "text/x-test"); + } + + public GsfDataObjectTest(String name) { + super(name); + } + + public void testSetModifiedRemovesSaveCookie() throws Exception { + FileSystem fs = FileUtil.createMemoryFileSystem(); + FileObject f = fs.getRoot().createData("index.test"); + DataObject dob = DataObject.find(f); + assertEquals("The right object", GsfDataObject.class, dob.getClass()); + + dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0, + "modified", null); + assertTrue("Should be modified.", dob.isModified()); + dob.setModified(false); + assertFalse("Should not be modified.", dob.isModified()); + assertNull("Should not have SaveCookie.", + dob.getLookup().lookup(SaveCookie.class)); + } +} diff -r db41f88fcafd csl.api/test/unit/src/org/netbeans/modules/csl/spi/LanguageRegistrationTest.java --- a/csl.api/test/unit/src/org/netbeans/modules/csl/spi/LanguageRegistrationTest.java Thu Sep 15 09:09:55 2011 +0200 +++ b/csl.api/test/unit/src/org/netbeans/modules/csl/spi/LanguageRegistrationTest.java Thu Sep 15 09:11:38 2011 +0200 @@ -42,9 +42,15 @@ package org.netbeans.modules.csl.spi; +import java.util.Collection; +import java.util.EnumSet; +import org.netbeans.api.lexer.TokenId; import org.netbeans.junit.NbTestCase; import org.netbeans.modules.csl.core.Language; import org.netbeans.modules.csl.core.LanguageRegistry; +import org.netbeans.spi.lexer.LanguageHierarchy; +import org.netbeans.spi.lexer.Lexer; +import org.netbeans.spi.lexer.LexerRestartInfo; /** * @@ -71,13 +77,52 @@ @Override public org.netbeans.api.lexer.Language getLexerLanguage() { - throw new UnsupportedOperationException("Not supported yet."); + return new Lang("text/x-test").language(); } @Override public String getDisplayName() { - throw new UnsupportedOperationException("Not supported yet."); + return "test language"; } } + + private static enum TestTokenId implements TokenId { + + TOKEN_ID1, + TOKEN_ID2; + + private TestTokenId() { + } + + @Override + public String primaryCategory() { + return null; + } + } // End of TestTokenId + + private static final class Lang extends LanguageHierarchy { + + private String mimeType; + + public Lang(String mimeType) { + this.mimeType = mimeType; + } + + @Override + protected Lexer createLexer(LexerRestartInfo info) { + return null; + } + + @Override + protected Collection createTokenIds() { + return EnumSet.allOf(TestTokenId.class); + } + + @Override + public String mimeType() { + return mimeType; + } + } // End of Lang class + }