/** Saves the displayed text. */ private void save() { final BaseXFileChooser fc = new BaseXFileChooser(SAVE_AS, gui.gopts.get(GUIOptions.WORKPATH), gui).suffix(IO.XMLSUFFIX); final IO file = fc.select(Mode.FSAVE); if (file == null) return; gui.gopts.set(GUIOptions.WORKPATH, file.path()); gui.cursor(CURSORWAIT, true); final MainOptions opts = gui.context.options; final int mh = opts.get(MainOptions.MAXHITS); opts.set(MainOptions.MAXHITS, -1); opts.set(MainOptions.CACHEQUERY, false); try (final PrintOutput out = new PrintOutput(file.toString())) { if (cmd != null) { cmd.execute(gui.context, out); } else if (ns != null) { ns.serialize(Serializer.get(out)); } else { final byte[] txt = text.getText(); for (final byte t : txt) if (t < 0 || t > ' ' || ws(t)) out.write(t); } } catch (final IOException ex) { BaseXDialog.error(gui, Util.info(FILE_NOT_SAVED_X, file)); } finally { opts.set(MainOptions.MAXHITS, mh); opts.set(MainOptions.CACHEQUERY, true); gui.cursor(CURSORARROW, true); } }
/** * Serializes the specified nodes. * * @param n nodes to display */ private void setText(final DBNodes n) { if (visible()) { try { final ArrayOutput ao = new ArrayOutput(); ao.setLimit(gui.gopts.get(GUIOptions.MAXTEXT)); if (n != null) n.serialize(Serializer.get(ao)); setText(ao); cmd = null; ns = ao.finished() ? n : null; } catch (final IOException ex) { Util.debug(ex); } } else { home.setEnabled(gui.context.data() != null); } }
@Override public void action(final Object comp) { final String pth = path(); final IOFile io = new IOFile(pth); String inf = io.isDir() && io.children().length > 0 ? DIR_NOT_EMPTY : null; ok = !pth.isEmpty(); final SerialMethod mth = SerialMethod.valueOf(method.getSelectedItem()); final OptionsOption<? extends Options> opts = mth == SerialMethod.JSON ? SerializerOptions.JSON : mth == SerialMethod.CSV ? SerializerOptions.CSV : null; final boolean showmparams = opts != null; mparams.setEnabled(showmparams); if (ok) { gui.gopts.set(GUIOptions.INPUTPATH, pth); try { if (comp == method) { if (showmparams) { final Options mopts = options(null).get(opts); mparams.setToolTipText(tooltip(mopts)); mparams.setText(mopts.toString()); } else { mparams.setToolTipText(null); mparams.setText(""); } } Serializer.get(new ArrayOutput(), options(mth)); } catch (final IOException ex) { ok = false; inf = ex.getMessage(); } } info.setText(inf, ok ? Msg.WARN : Msg.ERROR); enableOK(buttons, B_OK, ok); }