#187554 - "Save As" is not enabled for .html or .tpl files with activated Smarty plugin
1.1 --- a/php.smarty/manifest.mf Thu Mar 03 00:03:37 2011 +0100
1.2 +++ b/php.smarty/manifest.mf Wed Mar 16 15:35:52 2011 +0100
1.3 @@ -2,5 +2,5 @@
1.4 OpenIDE-Module: org.netbeans.modules.php.smarty
1.5 OpenIDE-Module-Layer: org/netbeans/modules/php/smarty/resources/layer.xml
1.6 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/smarty/resources/Bundle.properties
1.7 -OpenIDE-Module-Specification-Version: 1.39
1.8 +OpenIDE-Module-Specification-Version: 1.40
1.9
2.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/TplDataObject.java Thu Mar 03 00:03:37 2011 +0100
2.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/TplDataObject.java Wed Mar 16 15:35:52 2011 +0100
2.3 @@ -11,11 +11,13 @@
2.4 import org.openide.loaders.DataObjectExistsException;
2.5 import org.openide.loaders.MultiDataObject;
2.6 import org.openide.loaders.MultiFileLoader;
2.7 +import org.openide.loaders.SaveAsCapable;
2.8 import org.openide.nodes.CookieSet;
2.9 import org.openide.nodes.Node;
2.10 import org.openide.nodes.Children;
2.11 import org.openide.util.Lookup;
2.12 import org.openide.text.DataEditorSupport;
2.13 +import org.openide.util.UserCancelException;
2.14
2.15 public class TplDataObject extends MultiDataObject implements CookieSet.Factory {
2.16
2.17 @@ -23,9 +25,20 @@
2.18
2.19 public TplDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
2.20 super(pf, loader);
2.21 - CookieSet cookies = getCookieSet();
2.22 - cookies.add(TplEditorSupport.class, this);
2.23 -// cookies.add((Node.Cookie) DataEditorSupport.create(this, getPrimaryEntry(), cookies));
2.24 + CookieSet set = getCookieSet();
2.25 + set.add(TplEditorSupport.class, this);
2.26 + set.assign(SaveAsCapable.class, new SaveAsCapable() {
2.27 +
2.28 + @Override
2.29 + public void saveAs( FileObject folder, String fileName ) throws IOException {
2.30 + TplEditorSupport es = getCookie( TplEditorSupport.class );
2.31 + try {
2.32 + es.saveAs( folder, fileName );
2.33 + } catch (UserCancelException e) {
2.34 + //ignore, just not save anything
2.35 + }
2.36 + }
2.37 + });
2.38 }
2.39
2.40 @Override
3.1 --- a/php.smarty/src/org/netbeans/modules/php/smarty/editor/TplEditorSupport.java Thu Mar 03 00:03:37 2011 +0100
3.2 +++ b/php.smarty/src/org/netbeans/modules/php/smarty/editor/TplEditorSupport.java Wed Mar 16 15:35:52 2011 +0100
3.3 @@ -43,6 +43,11 @@
3.4
3.5 import java.io.IOException;
3.6 import java.io.ObjectInput;
3.7 +import java.io.OutputStream;
3.8 +import java.io.OutputStreamWriter;
3.9 +import java.io.Writer;
3.10 +import java.nio.charset.Charset;
3.11 +import javax.swing.text.BadLocationException;
3.12 import javax.swing.text.EditorKit;
3.13 import javax.swing.text.StyledDocument;
3.14 import org.openide.cookies.EditCookie;
3.15 @@ -99,6 +104,20 @@
3.16 TplEditorSupport.this.getDataObject().setModified(false);
3.17 }
3.18
3.19 + /**
3.20 + * @inheritDoc
3.21 + */
3.22 + @Override
3.23 + protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, BadLocationException {
3.24 + final Charset c = Charset.forName("UTF-8");
3.25 + final Writer w = new OutputStreamWriter(stream, c);
3.26 + try {
3.27 + kit.write(w, doc, 0, doc.getLength());
3.28 + } finally {
3.29 + w.close();
3.30 + }
3.31 + }
3.32 +
3.33 @Override
3.34 protected StyledDocument createStyledDocument(EditorKit kit) {
3.35 StyledDocument doc = super.createStyledDocument(kit);