]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormToc.C
More pref work from Angus
[lyx.git] / src / frontends / xforms / FormToc.C
index 07befefa14de3eb01f4ea4dc2a2d55ef779ccb27..40ca12b59567fa5dde0ab9848f1c7adbaf55da20 100644 (file)
 #endif
 
 
-#include "gettext.h"
 #include "Dialogs.h"
 #include "FormToc.h"
 #include "LyXView.h"
 #include "form_toc.h"
 #include "lyxtext.h"
+#include "lyxfunc.h"
+#include "support/lstrings.h"
 
+// The current code uses the apply() for handling the Update button and the
+// type-of-table selection and cancel() for the close button.  This is a little
+// confusing to the button controller so I've made an IgnorantPolicy to cover
+// this situation since the dialog doesn't care about buttons. ARRae 20001013
 FormToc::FormToc(LyXView * lv, Dialogs * d)
-       : FormCommand(lv, d, _("Table of Contents")), dialog_(0)
+       : FormCommand(lv, d, _("Table of Contents"), new IgnorantPolicy),
+         dialog_(0)
 {
        // let the dialog be shown
        // These are permanent connections so we won't bother
@@ -39,33 +45,36 @@ FormToc::FormToc(LyXView * lv, Dialogs * d)
 
 FormToc::~FormToc()
 {
-       free();
        delete dialog_;
 }
 
 
-void FormToc::clearStore()
+FL_FORM * FormToc::form() const
+{
+       if ( dialog_ ) return dialog_->form;
+       return 0;
+}
+
+
+void FormToc::disconnect()
 {
        toclist.clear();
+       FormCommand::disconnect();
 }
 
 
 void FormToc::build()
 {
        dialog_ = build_toc();
+
        fl_addto_choice(dialog_->type,
                        _(" TOC | LOF | LOT | LOA "));
 
        // Don't need to limit size of this dialog
-}
-
-
-FL_FORM * const FormToc::form() const
-{
-       if( dialog_ ) // no need to test for dialog_->form_toc
-               return dialog_->form_toc;
-       else
-               return 0;
+       // (but fixing min size is a GOOD thing).
+       // Workaround dumb xforms sizing bug
+       minw_ = form()->w;
+       minh_ = form()->h;
 }
 
 
@@ -73,13 +82,13 @@ void FormToc::update()
 {
        Buffer::TocType type;
 
-       if( params.getCmdName() == "tableofcontents" )
+       if ( params.getCmdName() == "tableofcontents" )
                type = Buffer::TOC_TOC;
 
-       else if( params.getCmdName() == "listofalgorithms" )
+       else if ( params.getCmdName() == "listofalgorithms" )
                type = Buffer::TOC_LOA;
 
-       else if( params.getCmdName() == "listoffigures" )
+       else if ( params.getCmdName() == "listoffigures" )
                type = Buffer::TOC_LOF;
 
        else
@@ -96,7 +105,8 @@ void FormToc::updateToc()
        if (!lv_->view()->available()) {
                toclist.clear();
                fl_clear_browser( dialog_->browser );
-               fl_add_browser_line( dialog_->browser, _("*** No Document ***"));
+               fl_add_browser_line( dialog_->browser,
+                                    _("*** No Document ***"));
                return;
        }
 
@@ -131,7 +141,8 @@ void FormToc::updateToc()
        for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
             it != toclist.end(); ++it)
                fl_add_browser_line( dialog_->browser,
-                                    (string(4*(*it).depth,' ')+(*it).str).c_str());
+                                    (string(4 * (*it).depth, ' ')
+                                     + (*it).str).c_str());
 
        fl_set_browser_topline( dialog_->browser, topline );
        fl_select_browser_line( dialog_->browser, line );
@@ -145,12 +156,9 @@ void FormToc::apply()
 
        updateToc();
 
-       unsigned int choice = fl_get_browser( dialog_->browser );
+       unsigned int const 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 const tmp = tostr(toclist[choice-1].par->id());
+               lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);
        }
 }