예제 #1
0
tree
connection_handlers (string name) {
  static hashmap<string,tree> handlers (tuple ());
  if (!handlers->contains (name))
    handlers (name)= stree_to_tree (call ("connection-get-handlers", name));
  return handlers[name];
}
예제 #2
0
void
edit_select_rep::selection_paste (string key) {
  tree t; string s;
  (void) ::get_selection (key, t, s, selection_import);
  if (inside_active_graphics ()) {
    if (is_tuple (t, "texmacs", 3))
      call ("graphics-paste", t[1]);
    return;
  }
  if (is_tuple (t, "extern", 1)) {
    string mode= get_env_string (MODE);
    string lan = get_env_string (MODE_LANGUAGE (mode));
    if ((selection_import == "latex") && (mode == "prog")) mode= "verbatim";
    if ((selection_import == "latex") && (mode == "math")) mode= "latex-math";
    if ((selection_import == "html") && (mode == "prog")) mode= "verbatim";
    string fm= selection_import * "-snippet";
    tree doc= generic_to_tree (selection_decode(lan, as_string(t[1])), fm);
    if (is_func (doc, DOCUMENT, 1)) doc= doc[0]; // temporary fix
    insert_tree (doc);
  }
  if (is_tuple (t, "texmacs", 3)) {
    string mode= get_env_string (MODE);
    string lan = get_env_string (MODE_LANGUAGE (mode));
    if (is_compound (t[1], "text", 1) && mode == "text")
      t= tuple ("texmacs", t[1][0], "text", lan);
    if (is_compound (t[1], "math", 1) && mode == "math")
      t= tuple ("texmacs", t[1][0], "math", lan);
    if (mode == "math" && t[2] == "text")
      set_message ("Error: invalid paste of text into a formula", "paste");
    else if (mode == "prog" && t[2] == "math") {
      tree in= tuple (lan, t[1]);
      tree r= stree_to_tree (call ("plugin-math-input", tree_to_stree (in)));
      insert_tree (r);
    }
    else {
      if ((t[2] != mode) && (t[2] != "src") && (mode != "src") &&
	  ((t[2] == "math") || (mode == "math"))) {
        if (t[2] == "math")
          insert_tree (compound ("math", ""), path (0, 0));
        else if (t[2] == "text")
          insert_tree (compound ("text", ""), path (0, 0));
        else
          insert_tree (tree (WITH, copy (MODE), copy (t[2]), ""), path (2, 0));
      }
      if (is_func (t[1], TFORMAT) || is_func (t[1], TABLE)) {
	int row, col;
	path fp= search_format (row, col);
	if (is_nil (fp)) insert_tree (compound (copy (TABULAR), t[1]));
	else table_write_subtable (fp, row, col, t[1]);
      }
      else insert_tree (t[1]);
    }
  }
}
예제 #3
0
tree
connection_info (string name, string session) {
  return stree_to_tree (call ("connection-info", name, session));
}
예제 #4
0
file_chooser_widget_rep::file_chooser_widget_rep (
  command cmd2, string type2):
  attribute_widget_rep (1), cmd (cmd2), type (type2)
{
  ref_count++;

  tree t= stree_to_tree (call ("format-get-suffixes*", type));
  int i, n= N(t);
  for (i=0; i<n; i++)
    suffix << ("." * as_string (t[i]));
  if (n == 0) suffix << string ("");

  SI sep= 3*PIXEL;
  int cw2n= 5;
  if (type == "directory") cw2n= 3;
  array<wk_widget> cw2 (cw2n);
  array<string> cn2 (cw2n);
  cw2[0]= glue_wk_widget (false, true, sep);
  cw2[1]= canvas_widget (wk_widget (tm_new<file_list_widget_rep> (this, suffix, true)));
  cn2[1]= "directories";
  cw2[2]= glue_wk_widget (false, true, sep);
  if (type != "directory") {
    cw2[3]= canvas_widget (wk_widget (tm_new<file_list_widget_rep> (this, suffix, false)));
    cn2[3]= "files";
    cw2[4]= glue_wk_widget (false, true, sep-PIXEL);
  }

#ifdef OS_WIN32
  wk_widget drive_menu = vertical_menu (array<wk_widget> ());
  unsigned int driveMask = XGetDrivesMask();
  char driveString[4] = "A:\\";
  for (char x = 'A'; x <= 'Z'; x++)
    if(driveMask & (1 << (x - 'A'))) {
      driveString[0] = x;
      drive_menu << emit_insert (driveString,
	command_button (text_wk_widget (driveString),
			tm_new<drive_menu_command_rep> (this, driveString)));
    }
  array<wk_widget> drw (2);
  drw[0] = pullright_button (text_wk_widget (translate ("Drive")), drive_menu);
  drw[1] = text_wk_widget ("");
  // drw[1]= glue_wk_widget (false, true, sep);
#endif

  int BUTTON_OK= BUTTON_FILE_OK;
  if (type == "directory") BUTTON_OK= BUTTON_DIR_OK;

#ifdef OS_WIN32
  array<wk_widget> cw3 (11);
  cw3[0]= glue_wk_widget (false, false, sep);
  cw3[1]= pulldown_button (text_wk_widget (translate ("Drive")),
			   drive_menu, true);
  cw3[2]= glue_wk_widget (false, false, sep);
  cw3[3]= button_widget ("Home", BUTTON_HOME);
  cw3[4]= glue_wk_widget (false, false, sep);
  cw3[5]= button_widget ("Texts", BUTTON_TEXTS);
  cw3[6]= glue_wk_widget (true, false);
  cw3[7]= button_widget ("Ok", BUTTON_OK);
  cw3[8]= glue_wk_widget (false, false, sep);
  cw3[9]= button_widget ("Cancel", BUTTON_CANCEL);
  cw3[10]= glue_wk_widget (false, false, sep);
#else
  array<wk_widget> cw3 (9);
  cw3[0]= glue_wk_widget (false, false, sep);
  cw3[1]= button_widget ("Home", BUTTON_HOME);
  cw3[2]= glue_wk_widget (false, false, sep);
  cw3[3]= button_widget ("Texts", BUTTON_TEXTS);
  cw3[4]= glue_wk_widget (true, false);
  cw3[5]= button_widget ("Ok", BUTTON_OK);
  cw3[6]= glue_wk_widget (false, false, sep);
  cw3[7]= button_widget ("Cancel", BUTTON_CANCEL);
#ifdef OS_MACOS
  cw3[8]= glue_wk_widget (false, false, sep + 14*PIXEL);
#else
  cw3[8]= glue_wk_widget (false, false, sep);
#endif
#endif

  int cwn= 11;
  if (type == "image") cwn= 16;
  if (type == "directory") cwn= 7;
  array<wk_widget> cw (cwn);
  array<string> cn (cwn);
  cw[0]= glue_wk_widget (true, false, 0, sep);
  cw[1]= input_widget ("Directory:", "Directory:", CHANGE_DIR);
  cn[1]= "directory";
  cw[2]= glue_wk_widget (true, false, 0, sep);

  if (type == "directory") {
    cw[3]= horizontal_list (cw2, cn2);
    cn[3]= "list";
  }

  if (type != "directory") {
    cw[3]= input_widget ("File:", "Directory:", CHANGE_FILE);
    cn[3]= "file";
    cw[4]= glue_wk_widget (true, false, 0, sep);
    cw[5]= input_widget ("Suffixes:", "Directory:", CHANGE_SUFFIXES);
    cn[5]= "suffixes";
    cw[6]= glue_wk_widget (true, false, 0, sep);
    cw[7]= horizontal_list (cw2, cn2);
    cn[7]= "list";
  }

  if (type == "image") {
    array<wk_widget> imw (7);
    array<string> ims (7);
    imw[ 0]= input_widget ("width:", "y-position:", IMAGE_HSIZE);
    ims[ 0]= "hsize";
    imw[ 1]= glue_wk_widget (true, false, 0, sep);
    imw[ 2]= input_widget ("height:", "y-position:", IMAGE_VSIZE);
    ims[ 2]= "vsize";
    imw[ 3]= glue_wk_widget (true, false, 0, sep);
    imw[ 4]= input_widget ("x-position:", "y-position:", IMAGE_XPOS);
    ims[ 4]= "xpos";
    imw[ 5]= glue_wk_widget (true, false, 0, sep);
    imw[ 6]= input_widget ("y-position:", "y-position:", IMAGE_YPOS);
    ims[ 6]= "ypos";

    array<wk_widget> cw4 (5);
    array<string> cn4 (5);
    cw4[0] = glue_wk_widget (false, false, sep);
    cw4[1] = vertical_list (imw, ims);
    cn4[1] = "parameters";
    cw4[2] = glue_wk_widget (false, false, sep);
    cw4[3] = tm_new<image_widget_rep> ();
    cn4[3] = "image";
    cw4[4] = glue_wk_widget (false, false, sep);

    //cw[ 8] = glue_wk_widget (true, false, 0, sep);
    //cw[ 9] = separator_wk_widget ();
    cw[ 8] = glue_wk_widget (true, false, 0, sep);
    cw[ 9] = horizontal_list (cw4, cn4);
    cn[ 9] = "image";
    cw[10] = glue_wk_widget (true, false, 0, sep);
    cw[11] = separator_wk_widget ();
    cw[12] = glue_wk_widget (true, false, 0, sep);
  }

  cw[cwn-3]= glue_wk_widget (true, false, 0, sep);
  cw[cwn-2]= horizontal_list (cw3);
  cn[cwn-2]= "buttons";
  cw[cwn-1]= glue_wk_widget (true, false, 0, sep);

  a[0]= vertical_list (cw, cn);

  if (type != "directory") {
    string s;
    for (i=0; i<N(suffix); ++i) {
      if (i) s << " ";
      s << suffix[i];
    }
    a[0]["suffixes"]["input"] << set_string ("input", s);
  }

  ref_count--;
}
예제 #5
0
void
edit_process_rep::generate_bibliography (
  string bib, string style, string fname)
{
  system_wait ("Generating bibliography, ", "please wait");
  if (DEBUG_AUTO)
    debug_automatic << "Generating bibliography"
                    << " [" << bib << ", " << style << ", " << fname << "]\n";
  tree bib_t= buf->data->aux[bib];
  if (buf->prj != NULL) bib_t= buf->prj->data->aux[bib];
  tree t;
  url bib_file= find_bib_file (buf->buf->name, fname);
  //cout << fname << " -> " << concretize (bib_file) << "\n";
  if (is_none (bib_file)) {
    url bbl_file= find_bib_file (buf->buf->name, fname, ".bbl");
    if (is_none (bbl_file)) {
      if (supports_db ()) {
        t= as_tree (call (string ("bib-compile"), bib, style, bib_t));
        call (string ("bib-attach"), bib, bib_t);
      }
      else {
	std_error << "Could not load BibTeX file " << fname;
        set_message ("Could not find bibliography file",
                     "compile bibliography");
        return;
      }
    }
    else t= bibtex_load_bbl (bib, bbl_file);
  }
  else {
    if (!bibtex_present () && !starts (style, "tm-")) {
      if (style == "abbrv") style= "tm-abbrv";
      else if (style == "acm") style= "tm-acm";
      else if (style == "alpha") style= "tm-alpha";
      else if (style == "elsart-num") style= "tm-elsart-num";
      else if (style == "ieeetr") style= "tm-ieeetr";
      else if (style == "siam") style= "tm-siam";
      else if (style == "unsrt") style= "tm-unsrt";
      else style= "tm-plain";
    }
    if (supports_db () && !is_rooted (bib_file))
      bib_file= find_bib_file (buf->buf->name, fname, ".bib", true);
    if (supports_db ()) {
      //(void) call (string ("bib-import-bibtex"), bib_file);
      t= as_tree (call (string ("bib-compile"), bib, style, bib_t, bib_file));
    }
    else if (starts (style, "tm-")) {
      string sbib;
      if (load_string (bib_file, sbib, false))
	std_error << "Could not load BibTeX file " << fname;
      tree te= bib_entries (parse_bib (sbib), bib_t);
      object ot= tree_to_stree (te);
      eval ("(use-modules (bibtex " * style (3, N(style)) * "))");
      t= stree_to_tree (call (string ("bib-process"),
                              bib, style (3, N(style)), ot));
    }
    else
      t= bibtex_run (bib, style, bib_file, bib_t);
    if (supports_db ())
      (void) call (string ("bib-attach"), bib, bib_t, bib_file);
  }
  if (is_atomic (t) && starts (t->label, "Error:"))
    set_message (t->label, "compile bibliography");
  else if (is_compound (t) && N(t) > 0) insert_tree (t);
}