19 package org.turro.zkoss.text;
22 import java.io.IOException;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.amic.util.file.FileUtil;
26 import org.turro.command.Command;
27 import org.turro.command.Context;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.i18n.I_;
30 import org.turro.zkoss.dialog.InputDialog;
31 import org.turro.zkoss.dialog.InputField;
32 import org.zkoss.codemirror.Codemirror;
33 import org.zkoss.lang.Strings;
34 import org.zkoss.zk.ui.ext.AfterCompose;
43 protected String
encoding =
null, forcedSyntax =
null;
62 this.forcedSyntax = forcedSyntax;
75 if(!
file.getParentFile().exists()) {
76 file.getParentFile().mkdirs();
78 if(
FileUtil.getExtension(
file).toLowerCase().equals(
"properties")) {
83 }
catch (IOException ex) {
88 public void saveAs(
final Command command)
throws IOException {
93 new InputField(
"Name", getFile().getName(), null, 0),
94 new InputField(
"Override", Boolean.valueOf(Boolean.TRUE), null, 0)
97 public Object execute(Context context) {
99 if(fields.length > 0) {
101 boolean override =
false;
103 if(
"Name".equals(f.getLabel())) {
105 }
else if(
"Override".equals(f.getLabel())) {
106 override = (Boolean) f.getValue();
109 if(!Strings.isBlank(name)) {
110 String path =
FileUtil.getParentPath(
file.getAbsolutePath());
112 if(
override && !path.contains(
"/site")) {
115 file =
new File(path +
"/" + name);
117 context.put(
"file",
file);
118 if(command !=
null) command.execute(context);
127 public void newFile(
final File folder,
final Command command)
throws IOException {
132 new InputField(
"Name",
"", null, 0)
135 public Object execute(Context context) {
137 if(fields.length > 0) {
139 if(
"Name".equals(f.getLabel())) {
140 String path = folder.getAbsolutePath();
142 file =
new File(path +
"/" + f.getValue());
144 context.put(
"file",
file);
145 if(command !=
null) command.execute(context);
159 setSyntax(!Strings.isBlank(forcedSyntax) ? forcedSyntax :
FileUtil.getExtension(
file).toLowerCase());
160 if(
FileUtil.getExtension(
file).toLowerCase().equals(
"properties")) {
166 }
catch (IOException ex) {
static String logMsg(String msg)
static String getEncoding()
static void setContent(File file, String value)
static String getContent(File file)
static String get(String msg)
void setDisabled(boolean value)
void setForcedSyntax(String forcedSyntax)
void saveAs(final Command command)
void newFile(final File folder, final Command command)
void setText(String value)
void setEncoding(String encoding)