]> git.lyx.org Git - features.git/blobdiff - src/frontends/controllers/ControlDocument.cpp
Remove warnings reported with gcc 4.3:
[features.git] / src / frontends / controllers / ControlDocument.cpp
index 3eabeed4415159e127c70c044a361f765cfb2562..d21f1d3aa75756dd2d1bb2bc6bfd6cbd0cb551d4 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Edwin Leuven
+ * \author Richard Heck (modules)
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "ControlDocument.h"
-#include "Kernel.h"
 
 #include "BranchList.h"
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "buffer_funcs.h"
+#include "Color.h"
 #include "FuncRequest.h"
 #include "gettext.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
-#include "Color.h"
+#include "ModuleList.h"
 #include "OutputParams.h"
 #include "TextClassList.h"
 
@@ -34,7 +35,9 @@
 #include <sstream>
 
 using std::ostringstream;
+using std::sort;
 using std::string;
+using std::vector;
 
 namespace lyx {
 namespace frontend {
@@ -50,7 +53,7 @@ char const * ControlDocument::fontfamilies_gui[5] = {
 
 
 ControlDocument::ControlDocument(Dialog & parent)
-       : Dialog::Controller(parent)
+       : Controller(parent)
 {}
 
 
@@ -58,10 +61,11 @@ ControlDocument::~ControlDocument()
 {}
 
 
-bool ControlDocument::initialiseParams(std::string const &)
+bool ControlDocument::initialiseParams(string const &)
 {
        bp_.reset(new BufferParams);
-       *bp_ = kernel().buffer().params();
+       *bp_ = buffer().params();
+       loadModuleNames();
        return true;
 }
 
@@ -81,54 +85,68 @@ BufferParams & ControlDocument::params() const
 
 BufferId ControlDocument::id() const
 {
-       return &kernel().buffer();
+       return &buffer();
 }
 
 
-TextClass const & ControlDocument::textClass() const
+vector<string> ControlDocument::getModuleNames()
 {
-       return textclasslist[bp_->textclass];
+       return moduleNames_;
 }
 
 
-namespace {
+vector<string> const & ControlDocument::getSelectedModules()
+{
+       return params().getModules();
+}
 
-void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
-                          kb_action lfun)
+
+string ControlDocument::getModuleDescription(string const & modName) const
+{
+       LyXModule const * const mod = moduleList[modName];
+       if (!mod)
+               return string("Module unavailable!");
+       return mod->description;
+}
+
+
+vector<string>
+ControlDocument::getPackageList(string const & modName) const
+{
+       LyXModule const * const mod = moduleList[modName];
+       if (!mod)
+               return vector<string>(); //empty such thing
+       return mod->packageList;
+}
+
+
+TextClass const & ControlDocument::textClass() const
+{
+       return textclasslist[bp_->getBaseClass()];
+}
+
+
+static void dispatch_bufferparams(Controller const & controller,
+       BufferParams const & bp, kb_action lfun)
 {
        ostringstream ss;
        ss << "\\begin_header\n";
        bp.writeFile(ss);
        ss << "\\end_header\n";
-       kernel.dispatch(FuncRequest(lfun, ss.str()));
+       controller.dispatch(FuncRequest(lfun, ss.str()));
 }
 
-} // namespace anon
-
 
 void ControlDocument::dispatchParams()
 {
        // This must come first so that a language change is correctly noticed
        setLanguage();
 
-       // Set the document class.
-       textclass_type const old_class =
-               kernel().buffer().params().textclass;
-       textclass_type const new_class = bp_->textclass;
-       if (new_class != old_class) {
-               string const name = textclasslist[new_class].name();
-               kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
-       }
-
-       int const old_secnumdepth = kernel().buffer().params().secnumdepth;
-       int const new_secnumdepth = bp_->secnumdepth;
-
-       // Apply the BufferParams.
-       dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
-
-       // redo the numbering if necessary
-       if (new_secnumdepth != old_secnumdepth)
-               updateLabels(kernel().buffer());
+       // Apply the BufferParams. Note that this will set the base class
+       // and then update the buffer's layout.
+       //FIXME Could this be done last? Then, I think, we'd get the automatic
+       //update mentioned in the next FIXME...
+       dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
 
        // Generate the colours requested by each new branch.
        BranchList & branchlist = params().branchlist();
@@ -142,48 +160,37 @@ void ControlDocument::dispatchParams()
                                        lyx::X11hexname(branch->getColor());
                        // display the new color
                        docstring const str = current_branch + ' ' + from_ascii(x11hexname);
-                       kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
+                       dispatch(FuncRequest(LFUN_SET_COLOR, str));
                }
 
                // Open insets of selected branches, close deselected ones
-               kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
+               dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
                        "assign branch"));
        }
        // FIXME: If we used an LFUN, we would not need those two lines:
-       kernel().bufferview()->update();
-       kernel().lyxview().currentWorkArea()->redraw();
+       bufferview()->update();
+       lyxview().currentWorkArea()->redraw();
 }
 
 
 void ControlDocument::setLanguage() const
 {
        Language const * const newL = bp_->language;
-       if (kernel().buffer().params().language == newL)
+       if (buffer().params().language == newL)
                return;
 
-       string const lang_name = newL->lang();
-       kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
-}
-
-
-bool ControlDocument::loadTextclass(textclass_type tc) const
-{
-       string const name = textclasslist[tc].name();
-       kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
-
-       // Report back whether we were able to change the class.
-       bool const success = textclasslist[tc].loaded();
-       return success;
+       string const & lang_name = newL->lang();
+       dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
 }
 
 
 void ControlDocument::saveAsDefault() const
 {
-       dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
+       dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
 }
 
 
-bool const ControlDocument::isFontAvailable(std::string const & font) const
+bool ControlDocument::isFontAvailable(string const & font) const
 {
        if (font == "default" || font == "cmr"
            || font == "cmss" || font == "cmtt")
@@ -207,7 +214,7 @@ bool const ControlDocument::isFontAvailable(std::string const & font) const
 }
 
 
-bool const ControlDocument::providesOSF(std::string const & font) const
+bool ControlDocument::providesOSF(string const & font) const
 {
        if (font == "cmr")
                return isFontAvailable("eco");
@@ -218,7 +225,7 @@ bool const ControlDocument::providesOSF(std::string const & font) const
 }
 
 
-bool const ControlDocument::providesSC(std::string const & font) const
+bool ControlDocument::providesSC(string const & font) const
 {
        if (font == "palatino")
                return isFontAvailable("mathpazo");
@@ -229,12 +236,23 @@ bool const ControlDocument::providesSC(std::string const & font) const
 }
 
 
-bool const ControlDocument::providesScale(std::string const & font) const
+bool ControlDocument::providesScale(string const & font) const
 {
        return (font == "helvet" || font == "luximono"
                || font == "berasans"  || font == "beramono");
 }
 
 
+void ControlDocument::loadModuleNames ()
+{
+       moduleNames_.clear();
+       LyXModuleList::const_iterator it = moduleList.begin();
+       for (; it != moduleList.end(); ++it)
+               moduleNames_.push_back(it->name);
+       if (!moduleNames_.empty())
+               sort(moduleNames_.begin(), moduleNames_.end());
+}
+
+
 } // namespace frontend
 } // namespace lyx