From: Lars Gullik Bjønnes Date: Thu, 31 Aug 2000 11:51:59 +0000 (+0000) Subject: patch from dekel and patch from angus X-Git-Tag: 1.6.10~22013 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e1cd322547158c885f3fa3543331a98f70800ba0;p=features.git patch from dekel and patch from angus git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@994 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 6a8fd9b7da..6951623b1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,44 @@ +2000-08-31 Angus Leeming + + * src/converter.C: added some using directives + + * src/frontends/ButtonPolicies.C: changes to overcome + "need lvalue" error with DEC c++ + + * src/frontends/xforms/FormDocument.C (c-tor): use C callback + to WMHideCB for DEC c++ + + * src/frontends/xforms/Menubar_pimpl.C: added using directive + + * src/frontends/xforms/forms/form_document.C.patch: use C callback + to BulletBMTableCB for DEC c++ + 2000-08-31 Allan Rae * src/lyx_gui.C (create_forms): build combo_language2 which is part of character dialog separately from old document dialogs combo_language. Stops a segfault. +2000-08-30 Dekel Tsur + + * src/commandtags.h: Added LFUN_GOTO_PARAGRAPH. + Removed LFUN_REF_CREATE. + + * src/MenuBackend.C: Added new tags: toc and references + + * src/frontends/xforms/Menubar_pimpl.C: Removed the use of StrPool + (add_lastfiles, add_documents, add_formats): Removed the unused smn + parameter. + (add_toc, add_references): New methods. + (create_submenu): Handle correctly the case when there is a + seperator after optional menu items. + + * src/lyxfunc.C (getStatus): Handle LFUN_REF_BACK. + (dispatch): Combined the code for LFUN_REF_CREATE and LFUN_REF_INSERT. + (dispatch): New code for LFUN_GOTO_PARAGRAPH. + + * src/frontends/xforms/FormToc.C (apply): Use Dispatch. + 2000-08-30 Dekel Tsur * src/converter.[Ch]: New file for converting between different diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 3e3ab07dce..bfdcbe851c 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -8,6 +8,8 @@ Menuset Menubar "main" Submenu "File|F" "file" Submenu "Edit|E" "edit" + Submenu "Toc|T" "toc" + Submenu "Refs|R" "refs" Submenu "Layout|L" "layout" Submenu "Insert|I" "insert" Submenu "Math|M" "math" @@ -153,6 +155,16 @@ Menuset OptItem "Show History|H" "vc-history" End + Menu toc + Toc + End + + Menu refs + References + Separator + Item "Go Back|B" "reference-back" + End + Menu "layout" Item "Character...|C" "layout-character" Item "Paragraph...|P" "layout-paragraph" diff --git a/src/LyXAction.C b/src/LyXAction.C index 685cd8599c..6cac5aee5c 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -343,6 +343,8 @@ void LyXAction::init() N_("Go one paragraph down"), ReadOnly }, { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select", N_("Select next paragraph"), ReadOnly }, + { LFUN_GOTO_PARAGRAPH, "paragraph-goto", + N_("Go to paragraph"), ReadOnly }, { LFUN_UP_PARAGRAPH, "paragraph-up", N_("Go one paragraph up"), ReadOnly }, { LFUN_UP_PARAGRAPHSEL, "paragraph-up-select", @@ -362,7 +364,7 @@ void LyXAction::init() { LFUN_REDO, "redo", N_("Redo"), Noop }, { LFUN_REF_BACK, "reference-back", "", ReadOnly }, { LFUN_REF_GOTO, "reference-goto", "", ReadOnly }, - { LFUN_REF_CREATE, "reference-insert", + { LFUN_REF_INSERT, "reference-insert", N_("Insert cross reference"), ReadOnly }, { LFUN_NEXT, "screen-down", "", ReadOnly }, { LFUN_NEXTSEL, "screen-down-select", "", ReadOnly }, diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 3d3360853b..6e6b2c7282 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -38,6 +38,8 @@ MenuItem::MenuItem(Kind kind, string const & label, case Separator: case Documents: case Lastfiles: + case Toc: + case References: case ViewFormats: case UpdateFormats: case ExportFormats: @@ -76,8 +78,10 @@ Menu & Menu::read(LyXLex & lex) md_exportformats, md_lastfiles, md_optitem, - md_submenu, + md_references, md_separator, + md_submenu, + md_toc, md_updateformats, md_viewformats, md_last @@ -90,8 +94,10 @@ Menu & Menu::read(LyXLex & lex) { "item", md_item }, { "lastfiles", md_lastfiles }, { "optitem", md_optitem }, + { "references", md_references }, { "separator", md_separator }, { "submenu", md_submenu }, + { "toc", md_toc }, { "updateformats", md_updateformats }, { "viewformats", md_viewformats } }; @@ -120,24 +126,39 @@ Menu & Menu::read(LyXLex & lex) optional = false; break; } + case md_separator: add(MenuItem(MenuItem::Separator)); break; + case md_lastfiles: add(MenuItem(MenuItem::Lastfiles)); break; + case md_documents: add(MenuItem(MenuItem::Documents)); break; + + case md_toc: + add(MenuItem(MenuItem::Toc)); + break; + + case md_references: + add(MenuItem(MenuItem::References)); + break; + case md_viewformats: add(MenuItem(MenuItem::ViewFormats)); break; + case md_updateformats: add(MenuItem(MenuItem::UpdateFormats)); break; + case md_exportformats: add(MenuItem(MenuItem::ExportFormats)); break; + case md_submenu: { lex.next(); char * tmp = strdup(lex.GetString().c_str()); @@ -148,9 +169,11 @@ Menu & Menu::read(LyXLex & lex) add(MenuItem(MenuItem::Submenu, mlabel, mname)); break; } + case md_endmenu: quit = true; break; + default: lex.printError("menubar::read: " "Unknown menu tag: `$$Token'"); diff --git a/src/MenuBackend.h b/src/MenuBackend.h index c5621a3c39..d0a3e1e8dd 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -41,6 +41,10 @@ public: /** This is the list of opened Documents, typically for the Documents menu. */ Documents, + /// + Toc, + /// + References, /** This is a list of viewable formats typically for the Documents menu. */ ViewFormats, @@ -102,6 +106,8 @@ public: string const & name() const { return name_; } /// bool empty() const { return items_.empty(); } + /// + ItemList::size_type size() const { return items_.size(); } /// const_iterator begin() const { return items_.begin(); diff --git a/src/commandtags.h b/src/commandtags.h index 18b5e8a834..e67f605eaf 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -282,9 +282,9 @@ enum kb_action { LFUN_SCROLL_INSET, // Jug 20000801 LFUN_UPDATE, // Dekel 20000805 LFUN_INDEX_INSERT, // Angus 20000803 - LFUN_REF_CREATE, // Angus 20000807 LFUN_SCREEN_FONT_UPDATE, // ARRae 20000813 LFUN_DIALOG_TABULAR_INSERT, // Jug 20000825 (old table-insert) + LFUN_GOTO_PARAGRAPH, // Dekel 20000826 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/converter.C b/src/converter.C index c1af3b5872..99580fe06f 100644 --- a/src/converter.C +++ b/src/converter.C @@ -36,7 +36,10 @@ using std::map; using std::vector; using std::queue; +using std::pair; +using std::sort; using std::stack; +using std::endl; ////////////////////////////////////////////////////////////////////////////// diff --git a/src/frontends/ButtonPolicies.C b/src/frontends/ButtonPolicies.C index 3295c8d6ed..46952e3e11 100644 --- a/src/frontends/ButtonPolicies.C +++ b/src/frontends/ButtonPolicies.C @@ -20,6 +20,13 @@ #include "ButtonPolicies.h" #include "debug.h" +// These shenanigans needed or DEC c++ complains that expression must +// be an lvalue +static const int sum_ = ( PreferencesPolicy::OKAY | + PreferencesPolicy::APPLY | + PreferencesPolicy::CANCEL | + PreferencesPolicy::UNDO_ALL ); +static const PreferencesPolicy::State bogus_ = PreferencesPolicy::BOGUS; // Helper function inline void nextState(ButtonPolicy::State & state, @@ -47,10 +54,10 @@ inline void nextState(ButtonPolicy::State & state, PreferencesPolicy::PreferencesPolicy() : state_(INITIAL), outputs_(APPLIED+1, - static_cast(OKAY | APPLY | CANCEL | UNDO_ALL)), + static_cast( sum_ )), state_machine_(APPLIED+1, StateArray(SMI_TOTAL, - static_cast(BOGUS))) + static_cast( bogus_ ))) { // Build the state output map outputs_[INITIAL] = CLOSE; @@ -122,10 +129,10 @@ void PreferencesPolicy::input(SMInput input) OkCancelPolicy::OkCancelPolicy() : state_(INITIAL), outputs_(INVALID+1, - static_cast(OKAY | APPLY | CANCEL | UNDO_ALL)), - state_machine_(INVALID+1, + static_cast( sum_ )), + state_machine_(INVALID+1, StateArray(SMI_TOTAL, - static_cast(BOGUS))) + static_cast( bogus_ ))) { // Build the state output map outputs_[INITIAL] = CLOSE; @@ -177,10 +184,10 @@ void OkCancelPolicy::input(SMInput input) OkCancelReadOnlyPolicy::OkCancelReadOnlyPolicy() : state_(INITIAL), outputs_(RO_INVALID+1, - static_cast(OKAY | APPLY | CANCEL | UNDO_ALL)), + static_cast( sum_ )), state_machine_(RO_INVALID+1, StateArray(SMI_TOTAL, - static_cast(BOGUS))) + static_cast( bogus_ ))) { // Build the state output map outputs_[INITIAL] = CLOSE; @@ -254,10 +261,10 @@ void OkCancelReadOnlyPolicy::input(SMInput input) NoRepeatedApplyReadOnlyPolicy::NoRepeatedApplyReadOnlyPolicy() : state_(INITIAL), outputs_(RO_INVALID+1, - static_cast(OKAY | APPLY | CANCEL | UNDO_ALL)), + static_cast( sum_ )), state_machine_(RO_INVALID+1, StateArray(SMI_TOTAL, - static_cast(BOGUS))) + static_cast( bogus_ ))) { // Build the state output map outputs_[INITIAL] = CLOSE; @@ -332,10 +339,10 @@ void NoRepeatedApplyReadOnlyPolicy::input(SMInput input) OkApplyCancelReadOnlyPolicy::OkApplyCancelReadOnlyPolicy() : state_(INITIAL), outputs_(RO_APPLIED+1, - static_cast(OKAY | APPLY | CANCEL | UNDO_ALL)), + static_cast( sum_ )), state_machine_(RO_APPLIED+1, StateArray(SMI_TOTAL, - static_cast(BOGUS))) + static_cast( bogus_ ))) { // Build the state output map outputs_[INITIAL] = CLOSE; @@ -424,10 +431,10 @@ void OkApplyCancelReadOnlyPolicy::input(SMInput input) OkApplyCancelPolicy::OkApplyCancelPolicy() : state_(INITIAL), outputs_(APPLIED+1, - static_cast(OKAY | APPLY | CANCEL | UNDO_ALL)), + static_cast( sum_ )), state_machine_(APPLIED+1, StateArray(SMI_TOTAL, - static_cast(BOGUS))) + static_cast( bogus_ ))) { // Build the state output map outputs_[INITIAL] = CLOSE; @@ -490,10 +497,10 @@ void OkApplyCancelPolicy::input(SMInput input) NoRepeatedApplyPolicy::NoRepeatedApplyPolicy() : state_(INITIAL), outputs_(INVALID+1, - static_cast(OKAY | APPLY | CANCEL | UNDO_ALL)), + static_cast( sum_ )), state_machine_(INVALID+1, StateArray(SMI_TOTAL, - static_cast(BOGUS))) + static_cast( bogus_ ))) { // Build the state output map outputs_[INITIAL] = CLOSE; diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index cff406f22f..c382dfceb0 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -224,7 +224,7 @@ void FormDocument::build() fl_set_input_maxchars(bullets_->input_bullet_latex, 80); fl_set_form_atclose(dialog_->form, - FormDocument::WMHideCB, 0); + C_FormDocumentWMHideCB, 0); fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"), class_->form); fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"), diff --git a/src/frontends/xforms/FormToc.C b/src/frontends/xforms/FormToc.C index fc237bedf7..3b0d4ca8d4 100644 --- a/src/frontends/xforms/FormToc.C +++ b/src/frontends/xforms/FormToc.C @@ -25,6 +25,8 @@ #include "LyXView.h" #include "form_toc.h" #include "lyxtext.h" +#include "lyxfunc.h" +#include "support/lstrings.h" FormToc::FormToc(LyXView * lv, Dialogs * d) : FormCommand(lv, d, _("Table of Contents")), dialog_(0) @@ -146,10 +148,7 @@ void FormToc::apply() unsigned int choice = fl_get_browser( dialog_->browser ); if (0 < choice && choice - 1 < toclist.size()) { - lv_->view()->beforeChange(); - lv_->view()->text->SetCursor( lv_->view(), toclist[choice-1].par, 0 ); - lv_->view()->text->sel_cursor = - lv_->view()->text->cursor; - lv_->view()->update(BufferView::SELECT|BufferView::FITCUR); + string tmp = tostr(toclist[choice-1].par->id()); + lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp.c_str()); } } diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C index 54ce4c9f70..9f01bd3348 100644 --- a/src/frontends/xforms/Menubar_pimpl.C +++ b/src/frontends/xforms/Menubar_pimpl.C @@ -17,7 +17,6 @@ #include #include "support/lstrings.h" #include "support/filetools.h" -#include "support/StrPool.h" #include "support/LAssert.h" #include "debug.h" #include "LyXAction.h" @@ -30,7 +29,11 @@ #include "Menubar_pimpl.h" #include "exporter.h" +using std::pair; using std::endl; +using std::vector; + +typedef vector::size_type size_type; extern kb_keymap * toplevel_keymap; extern LyXAction lyxaction; @@ -219,9 +222,7 @@ void Menubar::Pimpl::openByName(string const & name) } -void Menubar::Pimpl::add_lastfiles(int menu, string const & extra_label, - std::vector & /*smn*/, - StrPool & strpool) +void Menubar::Pimpl::add_lastfiles(int menu, string const & extra_label) { int ii = 1; for (LastFiles::const_iterator cit = lastfiles->begin(); @@ -238,23 +239,21 @@ void Menubar::Pimpl::add_lastfiles(int menu, string const & extra_label, lyxerr[Debug::GUI] << "shortcut is " << shortcut << endl; - fl_addtopup(menu, strpool.add(label), strpool.add(shortcut)); + fl_addtopup(menu, label.c_str(), shortcut.c_str()); } } -void Menubar::Pimpl::add_documents(int menu, string const & extra_label, - std::vector & /*smn*/, - StrPool & strpool) +void Menubar::Pimpl::add_documents(int menu, string const & extra_label) { - std::vector names = bufferlist.getFileNames(); + vector names = bufferlist.getFileNames(); if (names.empty()) { fl_addtopup(menu,_("No Documents Open!%i")); return; } - for (std::vector::const_iterator cit = names.begin(); + for (vector::const_iterator cit = names.begin(); cit != names.end() ; ++cit) { int action = lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *cit); @@ -263,23 +262,285 @@ void Menubar::Pimpl::add_documents(int menu, string const & extra_label, if ((cit + 1) == names.end()) label += extra_label; - fl_addtopup(menu, strpool.add(label)); + fl_addtopup(menu, label.c_str()); } } +string limit_string_length(string const & str) +{ + string::size_type const max_item_length = 45; + + if (str.size() > max_item_length) + return str.substr(0, max_item_length-3) + "..."; + else + return str; +} + +size_type const max_number_of_menus = 32; +size_type const max_number_of_items = 25; + +void add_toc2(int menu, string const & extra_label, + vector & smn, Window win, + vector const & toc_list, + size_type from, size_type to, int depth) +{ + if (to - from <= max_number_of_items) { + for (size_type i = from; i < to; ++i) { + int action = lyxaction. + getPseudoAction(LFUN_GOTO_PARAGRAPH, + tostr(toc_list[i].par->id())); + string label(4 * max(0, toc_list[i].depth - depth),' '); + label += toc_list[i].str; + label = limit_string_length(label); + label += "%x" + tostr(action); + if (i == to - 1 && depth == 0) + label += extra_label; + fl_addtopup(menu, label.c_str()); + } + } else { + size_type pos = from; + size_type count = 0; + while (pos < to) { + ++count; + if (count > max_number_of_items) { + fl_addtopup(menu, ". . .%d"); + break; + } + size_type new_pos = pos+1; + while (new_pos < to && + toc_list[new_pos].depth > depth) + ++new_pos; + + int action = lyxaction. + getPseudoAction(LFUN_GOTO_PARAGRAPH, + tostr(toc_list[pos].par->id())); + string label(4 * max(0, toc_list[pos].depth - depth), ' '); + label += toc_list[pos].str; + label = limit_string_length(label); + if (new_pos == to && depth == 0) + label += extra_label; + + if (new_pos == pos + 1) { + label += "%x" + tostr(action); + fl_addtopup(menu, label.c_str()); + } else if (smn.size() < max_number_of_menus) { + int menu2 = fl_newpup(win); + smn.push_back(menu2); + add_toc2(menu2, extra_label, smn, win, + toc_list, pos, new_pos, depth+1); + label += "%m"; + fl_addtopup(menu, label.c_str(), menu2); + } else { + label += "%d"; + fl_addtopup(menu, label.c_str()); + } + pos = new_pos; + } + } +} + +void Menubar::Pimpl::add_toc(int menu, string const & extra_label, + vector & smn, Window win) +{ + //xgettext:no-c-format + static char const * MenuNames[3] = { N_("List of Figures%m"), + //xgettext:no-c-format + N_("List of Tables%m"), + //xgettext:no-c-format + N_("List of Algorithms%m") }; + + vector > toc_list = + owner_->buffer()->getTocList(); + + // Handle LOF/LOT/LOA + int max_nonempty = 0; + for (int i = 1; i <= 3; ++i) + if (!toc_list[i].empty()) + max_nonempty = i; + + for (int j = 1; j <= 3; ++j) + if (!toc_list[j].empty()) { + int menu2 = fl_newpup(win); + smn.push_back(menu2); + for (size_type i = 0; i < toc_list[j].size(); ++i) { + if (i > max_number_of_items) { + fl_addtopup(menu2, ". . .%d"); + break; + } + int action = lyxaction. + getPseudoAction(LFUN_GOTO_PARAGRAPH, + tostr(toc_list[j][i].par->id())); + string label = + limit_string_length(toc_list[j][i].str); + label += "%x" + tostr(action); + fl_addtopup(menu2, label.c_str()); + } + if (j == max_nonempty) { + string label = _(MenuNames[j-1]); + label += "%l"; + fl_addtopup(menu, label.c_str(), menu2); + } else + fl_addtopup(menu, _(MenuNames[j-1]), menu2); + } + + // Handle normal TOC + if (max_nonempty == 0 && toc_list[0].empty()) { + fl_addtopup(menu,_("No Table of Contents%i")); + return; + } + + add_toc2(menu, extra_label, smn, win, + toc_list[0], 0, toc_list[0].size(), 0); + +} + +void add_references2(int menu, vector & smn, Window win, + vector const & label_list, string const & type) +{ + size_type const max_number_of_items = 25; + size_type const max_number_of_items2 = 20; + string::size_type const max_item_length = 40; + string::size_type const max_item_length2 = 20; + + if (label_list.size() <= max_number_of_items) + for (size_type i = 0; i < label_list.size(); ++i) { + int action = (type == "goto") + ? lyxaction.getPseudoAction(LFUN_REF_GOTO, + label_list[i]) + : lyxaction.getPseudoAction(LFUN_REF_INSERT, + type + "|++||++|" + + label_list[i]); + string label = label_list[i]; + if (label.size() > max_item_length) + label = label.substr(0, max_item_length-1) + "$"; + label += "%x" + tostr(action); + fl_addtopup(menu, label.c_str()); + } + else { + size_type count = 0; + for (size_type i = 0; i < label_list.size(); + i += max_number_of_items2) { + ++count; + if (count > max_number_of_items) { + fl_addtopup(menu, ". . .%d"); + break; + } + size_type j = min(label_list.size(), + i+max_number_of_items2); + + string label; + label += (label_list[i].size() > max_item_length2) + ? label_list[i].substr(0, max_item_length2-1) + "$" + : label_list[i]; + label += ".."; + label += (label_list[j-1].size() > max_item_length2) + ? label_list[j-1].substr(0, max_item_length2-1) + "$" + : label += label_list[j-1]; + + if (smn.size() < max_number_of_menus) { + int menu2 = fl_newpup(win); + smn.push_back(menu2); + for (size_type k = i; k < j; ++k) { + int action = (type == "goto") + ? lyxaction.getPseudoAction(LFUN_REF_GOTO, + label_list[k]) + : lyxaction.getPseudoAction(LFUN_REF_INSERT, + type + "|++||++|" + + label_list[k]); + string label2 = label_list[k]; + if (label2.size() > max_item_length) + label2 = label2.substr(0, max_item_length-1) + "$"; + label2 += "%x" + tostr(action); + fl_addtopup(menu2, label2.c_str()); + } + label += "%m"; + fl_addtopup(menu, label.c_str(), menu2); + } else { + label += "%d"; + fl_addtopup(menu, label.c_str()); + } + } + } +} + + +void Menubar::Pimpl::add_references(int menu, string const & extra_label, + vector & smn, Window win) +{ + //xgettext:no-c-format + static char const * MenuNames[6] = { N_("Insert Reference%m"), + //xgettext:no-c-format + N_("Insert Page Number%m"), + //xgettext:no-c-format + N_("Insert vref%m"), + //xgettext:no-c-format + N_("Insert vpageref%m"), + //xgettext:no-c-format + N_("Insert Pretty Ref%m"), + //xgettext:no-c-format + N_("Goto Reference%m") }; + + int const EMPTY = 1; + int const SGML = 2; + int const READONLY = 4; + + static int MenuFlags[6] = { + EMPTY | READONLY, + EMPTY | READONLY, + EMPTY | READONLY | SGML, + EMPTY | READONLY | SGML, + EMPTY | READONLY | SGML, + EMPTY }; + + static string const MenuTypes[6] = { + "ref", "pageref", "vref", "vpageref", "prettyref", "goto" }; + + vector label_list = owner_->buffer()->getLabelList(); + + int flag = 0; + if (label_list.empty()) + flag += EMPTY; + if (owner_->buffer()->isSGML()) + flag += SGML; + if (owner_->buffer()->isReadonly()) + flag += READONLY; + + int max_nonempty = -1; + for (int i = 0; i < 6; ++i) + if ((MenuFlags[i] & flag) == 0) + max_nonempty = i; + + for (int i = 0; i < 6; ++i) { + if ((MenuFlags[i] & flag) == 0) { + string label = _(MenuNames[i]); + if (i == max_nonempty) + label += extra_label; + if (smn.size() < max_number_of_menus) { + int menu2 = fl_newpup(win); + smn.push_back(menu2); + add_references2(menu2, smn, win, label_list, + MenuTypes[i]); + fl_addtopup(menu, label.c_str(), menu2); + } else { + label += "%d"; + fl_addtopup(menu, label.c_str()); + } + } + } +} + + void Menubar::Pimpl::add_formats(int menu, string const & extra_label, - std::vector & /*smn*/, - StrPool & strpool, kb_action action, bool viewable) { - std::vector > names = + vector > names = viewable ? Exporter::GetViewableFormats(owner_->buffer()) : Exporter::GetExportableFormats(owner_->buffer()); - for (std::vector >::const_iterator cit = names.begin(); + for (vector >::const_iterator cit = names.begin(); cit != names.end() ; ++cit) { int action2 = lyxaction.getPseudoAction(action, (*cit).first); @@ -288,14 +549,14 @@ void Menubar::Pimpl::add_formats(int menu, string const & extra_label, if ((cit + 1) == names.end()) label += extra_label; - fl_addtopup(menu, strpool.add(label)); + fl_addtopup(menu, label.c_str()); } } int Menubar::Pimpl::create_submenu(Window win, LyXView * view, string const & menu_name, - std::vector & smn, StrPool & strpool) + vector & smn) { if (!menubackend_->hasMenu(menu_name)){ lyxerr << "ERROR:create_submenu: Unknown menu `" @@ -317,7 +578,7 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, string widest_label; Menu::const_iterator end = md.end(); for (Menu::const_iterator i = md.begin(); i != end; ++i) { - MenuItem item = (*i); + MenuItem const & item = (*i); if (item.kind() == MenuItem::Command) { string label = item.label() + '\t'; int width = string_width(label); @@ -331,13 +592,21 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, << ", widest_label=`" << widest_label << "'" << endl; - for (Menu::const_iterator i = md.begin(); i != end; ++i) { - MenuItem item = (*i); - // Is there a separator after this item? - string extra_label; - if ((i+1) != end - && (i+1)->kind() == MenuItem::Separator) - extra_label = "%l"; + // Compute where to put separators + vector extra_labels(md.size()); + vector::iterator it = extra_labels.begin(); + vector::iterator last = it; + for (Menu::const_iterator i = md.begin(); i != end; ++i, ++it) + if (i->kind() == MenuItem::Separator) + *last = "%l"; + else if (!i->optional() || + !(view->getLyXFunc()->getStatus(i->action()) & LyXFunc::Disabled)) + last = it; + + it = extra_labels.begin(); + for (Menu::const_iterator i = md.begin(); i != end; ++i, ++it) { + MenuItem const & item = (*i); + string & extra_label = *it; switch(item.kind()) { case MenuItem::Command: { @@ -384,10 +653,10 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, if (!shortcut.empty()) { shortcut += lowercase(shortcut[0]); label += "%h"; - fl_addtopup(menu, strpool.add(label), - strpool.add(shortcut)); + fl_addtopup(menu, label.c_str(), + shortcut.c_str()); } else - fl_addtopup(menu, strpool.add(label)); + fl_addtopup(menu, label.c_str()); lyxerr[Debug::GUI] << "Command: \"" << lyxaction.getActionName(item.action()) @@ -401,8 +670,7 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, case MenuItem::Submenu: { int submenu = create_submenu(win, view, - item.submenu(), - smn, strpool); + item.submenu(), smn); if (submenu == -1) return -1; string label = item.label(); @@ -410,11 +678,11 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, string shortcut = item.shortcut(); if (!shortcut.empty()) { shortcut += lowercase(shortcut[0]); - fl_addtopup(menu, strpool.add(label + "%h"), - submenu, strpool.add(shortcut)); + fl_addtopup(menu, (label + "%h").c_str(), + submenu, shortcut.c_str()); } else { - fl_addtopup(menu, strpool.add(label), submenu); + fl_addtopup(menu, label.c_str(), submenu); } break; } @@ -425,26 +693,31 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, break; case MenuItem::Documents: - add_documents(menu, extra_label, smn, strpool); + add_documents(menu, extra_label); break; case MenuItem::Lastfiles: - add_lastfiles(menu, extra_label, smn, strpool); + add_lastfiles(menu, extra_label); + break; + + case MenuItem::Toc: + add_toc(menu, extra_label, smn, win); + break; + + case MenuItem::References: + add_references(menu, extra_label, smn, win); break; case MenuItem::ViewFormats: - add_formats(menu, extra_label, smn, strpool, - LFUN_PREVIEW, true); + add_formats(menu, extra_label, LFUN_PREVIEW, true); break; case MenuItem::UpdateFormats: - add_formats(menu, extra_label, smn, strpool, - LFUN_UPDATE, true); + add_formats(menu, extra_label, LFUN_UPDATE, true); break; case MenuItem::ExportFormats: - add_formats(menu, extra_label, smn, strpool, - LFUN_EXPORT, false); + add_formats(menu, extra_label, LFUN_EXPORT, false); break; } @@ -482,12 +755,10 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button) // set tabstop length fl_set_tabstop(menu_tabstop); - std::vector submenus; - StrPool strpool; + vector submenus; int menu = iteminfo->pimpl_-> create_submenu(FL_ObjWin(ob), view, - item->submenu(), - submenus, strpool); + item->submenu(), submenus); if (menu != -1) { // place popup fl_setpup_position(view->getForm()->x + ob->x, diff --git a/src/frontends/xforms/Menubar_pimpl.h b/src/frontends/xforms/Menubar_pimpl.h index 2a54412bed..24c2606006 100644 --- a/src/frontends/xforms/Menubar_pimpl.h +++ b/src/frontends/xforms/Menubar_pimpl.h @@ -26,7 +26,6 @@ class LyXView; class MenuBackend; class MenuItem; -class StrPool; #include "debug.h" @@ -50,26 +49,28 @@ public: /** Add to "menu" the list of last opened files (add "extra_label" to the last entry) */ - void add_lastfiles(int menu, string const & extra_label, - std::vector & smn, StrPool & strpool); + void add_lastfiles(int menu, string const & extra_label); /** Add to "menu" the list of opened documents (add "extra_label" to the last entry) */ - void add_documents(int menu, string const & extra_label, - std::vector & smn, StrPool & strpool); + void add_documents(int menu, string const & extra_label); /// Add to "menu" the list of exportable/viewable formats /// (add "extra_label" to the last entry) void add_formats(int menu, string const & extra_label, - std::vector & smn, StrPool & strpool, kb_action action, bool viewable); /// - int create_submenu(Window win, LyXView * view, - string const & menuname, - std::vector & smn, StrPool & strpool); + void add_toc(int menu, string const & extra_label, + std::vector & smn, Window win); + /// + void add_references(int menu, string const & extra_label, + std::vector & smn, Window win); + /// + int create_submenu(Window win, LyXView * view, + string const & menuname, + std::vector & smn); /// update the state of the menuitems void update() {} - private: /// FL_OBJECT * frame_; diff --git a/src/frontends/xforms/form_document.C b/src/frontends/xforms/form_document.C index aecbb3b83f..732b4a076a 100644 --- a/src/frontends/xforms/form_document.C +++ b/src/frontends/xforms/form_document.C @@ -11,6 +11,9 @@ #include "FormDocument.h" #include "bmtable.h" #include "support/filetools.h" +#include "xform_macros.h" + +C_GENERICCB(FormDocument, BulletBMTableCB) FD_form_tabbed_document::~FD_form_tabbed_document() { @@ -396,7 +399,7 @@ FD_form_doc_bullet * FormDocument::build_doc_bullet() obj = fl_add_box(FL_FLAT_BOX, 0, 0, 440, 345, ""); fl_set_border_width(-3); fdui->bmtable_bullet_panel = obj = fl_add_bmtable(1, 90, 105, 265, 180, ""); - fl_set_object_callback(obj, BulletBMTableCB, 0); + fl_set_object_callback(obj, C_FormDocumentBulletBMTableCB, 0); fl_set_object_lcol(obj, FL_BLUE); fl_set_object_boxtype(obj, FL_UP_BOX); fl_set_bmtable_pixmap_file(obj, 6, 6, diff --git a/src/frontends/xforms/forms/form_document.C.patch b/src/frontends/xforms/forms/form_document.C.patch index 58abaf2d86..908594f7eb 100644 --- a/src/frontends/xforms/forms/form_document.C.patch +++ b/src/frontends/xforms/forms/form_document.C.patch @@ -1,11 +1,14 @@ --- form_document.C.orig Mon Aug 14 13:17:32 2000 +++ form_document.C Mon Aug 14 13:22:59 2000 -@@ -9,6 +9,8 @@ +@@ -9,6 +9,11 @@ #include #include "form_document.h" #include "FormDocument.h" +#include "bmtable.h" +#include "support/filetools.h" ++#include "xform_macros.h" ++ ++C_GENERICCB(FormDocument, BulletBMTableCB) FD_form_tabbed_document::~FD_form_tabbed_document() { @@ -20,7 +23,7 @@ - fl_set_pixmapbutton_file(obj, _("/nfs/sinco/source/lyx/lyx-devel/lib/images/psnfss2.xpm")); + fl_set_border_width(-3); + fdui->bmtable_bullet_panel = obj = fl_add_bmtable(1, 90, 105, 265, 180, ""); -+ fl_set_object_callback(obj, BulletBMTableCB, 0); ++ fl_set_object_callback(obj, C_FormDocumentBulletBMTableCB, 0); + fl_set_object_lcol(obj, FL_BLUE); + fl_set_object_boxtype(obj, FL_UP_BOX); + fl_set_bmtable_pixmap_file(obj, 6, 6, diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 79d0dc66a0..0d9c79a790 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -612,6 +612,9 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const case LFUN_VC_HISTORY: disable = !buf->lyxvc.inUse(); break; + case LFUN_REF_BACK: + disable = owner->view()->NoSavedPositions(); + break; default: break; } @@ -1584,26 +1587,22 @@ string LyXFunc::Dispatch(int ac, MenuInsertLabel(argument.c_str()); break; - case LFUN_REF_CREATE: - { - InsetCommandParams p( "ref" ); - owner->getDialogs()->createRef( p.getAsString() ); - } - break; - case LFUN_REF_INSERT: - { - InsetCommandParams p; - p.setFromString( argument ); + if (argument.empty()) { + InsetCommandParams p("ref"); + owner->getDialogs()->createRef(p.getAsString()); + } else { + InsetCommandParams p; + p.setFromString(argument); + + InsetRef * inset = new InsetRef(p); + if (!owner->view()->insertInset(inset)) + delete inset; + else + owner->view()->updateInset(inset, true); + } + break; - InsetRef * inset = new InsetRef( p ); - if (!owner->view()->insertInset(inset)) - delete inset; - else - owner->view()->updateInset( inset, true ); - } - break; - case LFUN_REF_BACK: { owner->view()->restorePosition(); @@ -2533,6 +2532,28 @@ string LyXFunc::Dispatch(int ac, } break; + case LFUN_GOTO_PARAGRAPH: + { +#ifdef HAVE_SSTREAM + istringstream istr(argument); +#else + istrstream istr(argument.c_str()); +#endif + + int id; + istr >> id; + LyXParagraph * par = owner->view()->text->GetParFromID(id); + + // Set the cursor + owner->view()->text->SetCursor(owner->view(), par, 0); + owner->view()->setState(); + owner->showState(); + + // Recenter screen + owner->view()->center(); + } + break; + case LFUN_APROPOS: case LFUN_GETTIP: { diff --git a/src/menus.C b/src/menus.C index b6c24b3b59..a34dbdce26 100644 --- a/src/menus.C +++ b/src/menus.C @@ -1905,7 +1905,7 @@ void Menus::ShowInsertMenu(FL_OBJECT * ob, long) case 12: tmpfunc->Dispatch(LFUN_INSERT_NOTE); break; case 13: tmpfunc->Dispatch(LFUN_INSERT_LABEL); break; - case 14: tmpfunc->Dispatch(LFUN_REF_CREATE); break; + case 14: tmpfunc->Dispatch(LFUN_REF_INSERT); break; case 15: tmpfunc->Dispatch(LFUN_CITATION_CREATE); break; case 16: tmpfunc->Dispatch(LFUN_INDEX_CREATE); break; case 17: tmpfunc->Dispatch(LFUN_INDEX_INSERT_LAST); break;