X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyx_cb.C;h=22d31e4fbc617e5a43e3859a5ac36cd0cad2699c;hb=09383c6e55612a7268efc7222cbe266b13fe2b43;hp=ea272c971624056f5d2e2f903a6e61286d9af8f5;hpb=a32d2c972f88e771a326e011bc16b6d38d6e9082;p=lyx.git diff --git a/src/lyx_cb.C b/src/lyx_cb.C index ea272c9716..22d31e4fbc 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -53,19 +53,13 @@ extern Combox * combo_language; extern Combox * combo_language2; extern BufferList bufferlist; extern void show_symbols_form(); -extern FD_form_title * fd_form_title; extern FD_form_character * fd_form_character; -extern FD_form_preamble * fd_form_preamble; extern FD_form_figure * fd_form_figure; extern BufferView * current_view; // called too many times in this file... extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */ -#if 0 -extern bool send_fax(string const & fname, string const & sendcmd); -#endif - extern void MenuSendto(); // this should be static, but I need it in buffer.C @@ -301,40 +295,16 @@ int MenuRunChktex(Buffer * buffer) } -#if 0 -void MenuFax(Buffer * buffer) -{ - // Generate postscript file - if (!Exporter::Export(buffer, "ps", true)) - return; - - // Send fax - string const ps = OnlyFilename(ChangeExtension(buffer->fileName(), - ".ps")); - - string path = OnlyPath (buffer->fileName()); - if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { - path = buffer->tmppath; - } - Path p(path); - if (!lyxrc.fax_program.empty()) { - string help2 = subst(lyxrc.fax_program, "$$FName", ps); - help2 += " &"; - Systemcalls one(Systemcalls::System, help2); - } else - send_fax(ps, lyxrc.fax_command); -} -#endif - - void QuitLyX() { lyxerr.debug() << "Running QuitLyX." << endl; - if (!bufferlist.QwriteAll()) - return; + if (lyxrc.use_gui) { + if (!bufferlist.QwriteAll()) + return; - lastfiles->writeFile(lyxrc.lastfiles); + lastfiles->writeFile(lyxrc.lastfiles); + } // Set a flag that we do quitting from the program, // so no refreshes are necessary. @@ -385,11 +355,11 @@ void AutoSave(BufferView * bv) // anyway. bool failed = false; - string const tmp_ret = lyx::tempName(); + string const tmp_ret = lyx::tempName(string(), "lyxauto"); if (!tmp_ret.empty()) { bv->buffer()->writeFile(tmp_ret, 1); // assume successful write of tmp_ret - if (lyx::rename(tmp_ret, fname)) { + if (!lyx::rename(tmp_ret, fname)) { failed = true; // most likely couldn't move between filesystems // unless write of tmp_ret failed @@ -491,7 +461,7 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) // We use this until the compilers get better... vector tmp; copy(ii, end, back_inserter(tmp)); - string tmpstr(tmp.begin(), tmp.end()); + string const tmpstr(tmp.begin(), tmp.end()); #else // This is what we want to use and what we will use once the // compilers get good enough. @@ -504,12 +474,12 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) bv->hideCursor(); // clear the selection - bv->beforeChange(); + bv->beforeChange(bv->text); if (!asParagraph) bv->text->InsertStringA(bv, tmpstr); else bv->text->InsertStringB(bv, tmpstr); - bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); } @@ -518,8 +488,70 @@ void MenuInsertLabel(BufferView * bv, string const & arg) string label(arg); ProhibitInput(bv); if (label.empty()) { - pair - result = askForText(_("Enter new label to insert:")); +#ifndef NEW_INSETS + LyXParagraph * par = + bv->text->cursor.par()->FirstPhysicalPar(); +#else + LyXParagraph * par = bv->text->cursor.par(); +#endif + LyXLayout const * layout = + &textclasslist.Style(bv->buffer()->params.textclass, + par->GetLayout()); + + if (layout->latextype == LATEX_PARAGRAPH && par->previous) { +#ifndef NEW_INSETS + LyXParagraph * par2 = par->previous->FirstPhysicalPar(); +#else + LyXParagraph * par2 = par->previous; +#endif + LyXLayout const * layout2 = + &textclasslist.Style(bv->buffer()->params.textclass, + par2->GetLayout()); + if (layout2->latextype != LATEX_PARAGRAPH) { + par = par2; + layout = layout2; + } + } + string text = layout->latexname().substr(0, 3); + if (layout->latexname() == "theorem") + text = "thm"; // Create a correct prefix for prettyref +#ifndef NEW_INSETS + if (par->footnoteflag==LyXParagraph::OPEN_FOOTNOTE) + switch (par->footnotekind) { + case LyXParagraph::FIG: + case LyXParagraph::WIDE_FIG: + text = "fig"; + break; + case LyXParagraph::TAB: + case LyXParagraph::WIDE_TAB: + text = "tab"; + break; + case LyXParagraph::ALGORITHM: + text = "alg"; + break; + case LyXParagraph::FOOTNOTE: + case LyXParagraph::MARGIN: + break; + } +#endif + text += ":"; + if (layout->latextype == LATEX_PARAGRAPH || + lyxrc.label_init_length < 0) + text.erase(); + string par_text = par->String(bv->buffer(), false); + for (int i = 0; i < lyxrc.label_init_length; ++i) { + if (par_text.empty()) + break; + string head; + par_text = split(par_text, head, ' '); + if (i > 0) + text += '-'; // Is it legal to use spaces in + // labels ? + text += head; + } + + pair result = + askForText(_("Enter new label to insert:"), text); if (result.first) { label = frontStrip(strip(result.second)); } @@ -562,58 +594,6 @@ void MenuLayoutCharacter() } -bool UpdateLayoutPreamble(BufferView * bv) -{ - bool update = true; - if (!bv->available()) - update = false; - - if (update) { - fl_set_input(fd_form_preamble->input_preamble, - bv->buffer()->params.preamble.c_str()); - - if (bv->buffer()->isReadonly()) { - fl_deactivate_object(fd_form_preamble->input_preamble); - fl_deactivate_object(fd_form_preamble->button_ok); - fl_deactivate_object(fd_form_preamble->button_apply); - fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE); - fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE); - } else { - fl_activate_object(fd_form_preamble->input_preamble); - fl_activate_object(fd_form_preamble->button_ok); - fl_activate_object(fd_form_preamble->button_apply); - fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK); - fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK); - } - } else if (fd_form_preamble->form_preamble->visible) { - fl_hide_form(fd_form_preamble->form_preamble); - } - return update; -} - - -void MenuLayoutPreamble() -{ - static int ow = -1, oh; - - if (UpdateLayoutPreamble(current_view)) { - if (fd_form_preamble->form_preamble->visible) { - fl_raise_form(fd_form_preamble->form_preamble); - } else { - fl_show_form(fd_form_preamble->form_preamble, - FL_PLACE_MOUSE | FL_FREE_SIZE, - FL_TRANSIENT, - _("LaTeX Preamble")); - if (ow < 0) { - ow = fd_form_preamble->form_preamble->w; - oh = fd_form_preamble->form_preamble->h; - } - fl_set_form_minsize(fd_form_preamble->form_preamble, - ow, oh); - } - } -} - void MenuLayoutSave(BufferView * bv) { @@ -723,23 +703,6 @@ LyXFont const UserFreeFont(BufferParams const & params) } -/* callbacks for form form_title */ -extern "C" -void TimerCB(FL_OBJECT *, long) -{ - // only if the form still exists - if (lyxrc.show_banner - && fd_form_title - && fd_form_title->form_title) { - if (fd_form_title->form_title->visible) { - fl_hide_form(fd_form_title->form_title); - } - fl_free_form(fd_form_title->form_title); - fd_form_title->form_title = 0; - } -} - - /* callbacks for form form_character */ extern "C" @@ -769,35 +732,6 @@ void CharacterOKCB(FL_OBJECT * ob, long data) } -/* callbacks for form form_preamble */ - -extern "C" -void PreambleCancelCB(FL_OBJECT *, long) -{ - fl_hide_form(fd_form_preamble->form_preamble); -} - - -extern "C" -void PreambleApplyCB(FL_OBJECT *, long) -{ - if (!current_view->available()) - return; - - current_view->buffer()->params.preamble = - fl_get_input(fd_form_preamble->input_preamble); - current_view->buffer()->markDirty(); - current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set")); -} - - -extern "C" -void PreambleOKCB(FL_OBJECT * ob, long data) -{ - PreambleApplyCB(ob, data); - PreambleCancelCB(ob, data); -} - void Figure() { @@ -832,20 +766,20 @@ void FigureApplyCB(FL_OBJECT *, long) } current_view->hideCursor(); - current_view->update(BufferView::SELECT|BufferView::FITCUR); - current_view->beforeChange(); + current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR); + current_view->beforeChange(current_view->text); current_view->text->SetCursorParUndo(current_view->buffer()); current_view->text->FreezeUndo(); current_view->text->BreakParagraph(current_view); - current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); if (current_view->text->cursor.par()->Last()) { current_view->text->CursorLeft(current_view); current_view->text->BreakParagraph(current_view); - current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); } // The standard layout should always be numer 0; @@ -876,12 +810,12 @@ void FigureApplyCB(FL_OBJECT *, long) } #endif - current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); Inset * new_inset = new InsetFig(100, 100, *buffer); current_view->insertInset(new_inset); new_inset->Edit(current_view, 0, 0, 0); - current_view->update(BufferView::SELECT|BufferView::FITCUR); + current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR); current_view->owner()->getMiniBuffer()->Set(_("Figure inserted")); current_view->text->UnFreezeUndo(); current_view->setState();