Proper save handling for the shader editor.
This commit is contained in:
parent
3a61032575
commit
06e9618a4b
sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor
@ -67,9 +67,6 @@
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="header">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="66" green="66" id="TabbedPane.focus" palette="3" red="66" type="palette"/>
|
||||
</Property>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
|
||||
<EtchetBorder/>
|
||||
@ -99,9 +96,6 @@
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="headerText">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="66" green="66" id="TabbedPane.focus" palette="3" red="66" type="palette"/>
|
||||
</Property>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Tahoma" size="11" style="1"/>
|
||||
</Property>
|
||||
|
@ -12,11 +12,12 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.List;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.text.EditorKit;
|
||||
import org.openide.cookies.EditorCookie;
|
||||
import org.openide.filesystems.FileLock;
|
||||
import org.openide.filesystems.FileObject;
|
||||
import org.openide.loaders.DataObject;
|
||||
import org.openide.loaders.DataObjectNotFoundException;
|
||||
@ -41,21 +42,20 @@ public class ShaderEditPanel extends JPanel {
|
||||
EditorKit ek = CloneableEditorSupport.getEditorKit(mime);
|
||||
shaderEditorPane.setEditorKit(ek);
|
||||
shaderEditorPane.setContentType(mime);
|
||||
|
||||
shaderEditorPane.addKeyListener(new KeyListener() {
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
currentDataObject.setModified(true);
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
|
||||
saveCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public class ShaderEditPanel extends JPanel {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
saveCurrent();
|
||||
try {
|
||||
shaderEditorPane.setText(b.dataObject.getPrimaryFile().asText());
|
||||
shaderEditorPane.setDocument(b.dataObject.getLookup().lookup(EditorCookie.class).openDocument());
|
||||
} catch (IOException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
}
|
||||
@ -93,7 +93,7 @@ public class ShaderEditPanel extends JPanel {
|
||||
|
||||
});
|
||||
if (firstItem) {
|
||||
shaderEditorPane.setText(fo.asText());
|
||||
shaderEditorPane.setDocument(b.dataObject.getLookup().lookup(EditorCookie.class).openDocument());
|
||||
currentDataObject = b.dataObject;
|
||||
b.setSelected(true);
|
||||
firstItem = false;
|
||||
@ -109,10 +109,10 @@ public class ShaderEditPanel extends JPanel {
|
||||
|
||||
public void saveCurrent() {
|
||||
if (currentDataObject != null && currentDataObject.isModified()) {
|
||||
FileLock lock = null;
|
||||
|
||||
try {
|
||||
OutputStreamWriter out = new OutputStreamWriter(currentDataObject.getPrimaryFile().getOutputStream());
|
||||
out.write(shaderEditorPane.getText(), 0, shaderEditorPane.getText().length());
|
||||
out.close();
|
||||
currentDataObject.getLookup().lookup(EditorCookie.class).saveDocument();
|
||||
currentDataObject.setModified(false);
|
||||
if(currentDataObject.getPrimaryFile().getExt().equalsIgnoreCase("j3sn")){
|
||||
parent.reload();
|
||||
@ -122,6 +122,10 @@ public class ShaderEditPanel extends JPanel {
|
||||
Exceptions.printStackTrace(ex);
|
||||
} catch (IOException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
}finally{
|
||||
if (lock!=null){
|
||||
lock.releaseLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,10 +159,8 @@ public class ShaderEditPanel extends JPanel {
|
||||
shaderEditorPane.setText(org.openide.util.NbBundle.getMessage(ShaderEditPanel.class, "ShaderEditPanel.shaderEditorPane.text")); // NOI18N
|
||||
jScrollPane1.setViewportView(shaderEditorPane);
|
||||
|
||||
header.setBackground(javax.swing.UIManager.getDefaults().getColor("TabbedPane.focus"));
|
||||
header.setBorder(javax.swing.BorderFactory.createEtchedBorder());
|
||||
|
||||
headerText.setBackground(javax.swing.UIManager.getDefaults().getColor("TabbedPane.focus"));
|
||||
headerText.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
|
||||
headerText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||
headerText.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/materialdefinition/icons/fragment.png"))); // NOI18N
|
||||
|
Loading…
x
Reference in New Issue
Block a user