]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Herbert's latest graphics patch.
[lyx.git] / src / lyxfunc.C
index 26c1f9fa9d3399273bfc4e7b6146e363ccb39461..5ca26ab25748ad788cd2e22aa87d8b57d28eb4ae 100644 (file)
@@ -379,6 +379,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                }
        }
 
+       UpdatableInset * tli = owner->view()->theLockingInset();
+       
        // I would really like to avoid having this switch and rather try to
        // encode this in the function itself.
         bool disable = false;
@@ -413,27 +415,30 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
 
        case LFUN_LAYOUT_TABULAR:
-               disable = true;
-               if (owner->view()->theLockingInset()) {
-                       disable = (owner->view()->theLockingInset()->lyxCode() != Inset::TABULAR_CODE) &&
-                               !owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
-               }
+               disable = !tli
+                       || (tli->lyxCode() != Inset::TABULAR_CODE
+                           && !tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
+               break;
+
+       case LFUN_LAYOUT:
+       case LFUN_LAYOUT_PARAGRAPH: {
+               Inset * inset = TEXT(false)->cursor.par()->inInset();
+               disable = inset && inset->forceDefaultParagraphs(inset);
                break;
+       }
 
        case LFUN_TABULAR_FEATURE:
                disable = true;
-               if (owner->view()->theLockingInset()) {
+               if (tli) {
                        FuncStatus ret;
                        //ret.disabled(true);
-                       if (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) {
-                               ret = static_cast<InsetTabular *>
-                                       (owner->view()->theLockingInset())->
-                                       getStatus(argument);
-                       } else if (owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
+                       if (tli->lyxCode() == Inset::TABULAR_CODE) {
+                               ret = static_cast<InsetTabular *>(tli)
+                                       ->getStatus(argument);
+                       } else if (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
                                ret = static_cast<InsetTabular *>
-                                       (owner->view()->theLockingInset()->
-                                        getFirstLockingInsetOfType(Inset::TABULAR_CODE))->
-                                       getStatus(argument);
+                                       (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE))
+                                       ->getStatus(argument);
                        }
                        flag |= ret;
                        disable = false;
@@ -443,7 +448,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
 
                        disable = true;
                        ret = inset.getStatus(argument);
-                       if (ret.onoff(true) || ret.onoff(false)) flag.setOnOff(false);
+                       if (ret.onoff(true) || ret.onoff(false))
+                               flag.setOnOff(false);
                }
                break;
 
@@ -471,13 +477,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                disable = (TEXT(false)->getInset() == 0);
                break;
 
-       case LFUN_MATH_VALIGN: {
-    // I think this test can be simplified (Andre')
-               // mathcursor is != 0  iff we are in math mode
-               //Inset * tli = owner->view()->theLockingInset();
-               //if (tli && (tli->lyxCode() == Inset::MATH_CODE 
-               //          || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
-               //
+       case LFUN_MATH_VALIGN: 
                if (mathcursor) {
                        char align = mathcursor->valign();
                        if (align == '\0') {
@@ -496,11 +496,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                } else
                        disable = true;
                break;
-       }
-       case LFUN_MATH_HALIGN: {
-               //Inset * tli = owner->view()->theLockingInset();
-               //if (tli && (tli->lyxCode() == Inset::MATH_CODE 
-               //          || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
+
+       case LFUN_MATH_HALIGN: 
                if (mathcursor) {
                        char align = mathcursor->halign();
                        if (align == '\0') {
@@ -519,9 +516,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                } else
                        disable = true;
                break;
-       }
-       case LFUN_MATH_MUTATE: {
-               Inset * tli = owner->view()->theLockingInset();
+
+       case LFUN_MATH_MUTATE: 
                if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
                        MathInsetTypes type = mathcursor->formula()->getType();
                        if (argument == "inline") {
@@ -538,7 +534,6 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                } else
                        disable = true;
                break;
-       }
 
        // we just need to be in math mode to enable that
        case LFUN_MATH_SIZE: 
@@ -663,9 +658,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        default:
                break;
        }
-       if (code != Inset::NO_CODE 
-           && owner->view()->theLockingInset()
-           && !owner->view()->theLockingInset()->insetAllowed(code)) {
+       if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) {
                disable = true;
        }
 
@@ -754,7 +747,7 @@ void LyXFunc::miniDispatch(string const & s)
 }
 
 
-void const LyXFunc::verboseDispatch(string const & s, bool show_sc) 
+void LyXFunc::verboseDispatch(string const & s, bool show_sc) 
 {
        int action = lyxaction.LookupFunc(frontStrip(s));
  
@@ -768,7 +761,7 @@ void const LyXFunc::verboseDispatch(string const & s, bool show_sc)
 }
 
 
-void const LyXFunc::verboseDispatch(int ac, bool show_sc) 
+void LyXFunc::verboseDispatch(int ac, bool show_sc) 
 {
        string argument;
        kb_action action;
@@ -781,8 +774,8 @@ void const LyXFunc::verboseDispatch(int ac, bool show_sc)
 
 
 
-void const LyXFunc::verboseDispatch(kb_action action,
-                                   string const & argument, bool show_sc)
+void LyXFunc::verboseDispatch(kb_action action,
+                             string const & argument, bool show_sc)
 {
        string res = dispatch(action, argument);
 
@@ -1397,7 +1390,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
 
        case LFUN_GOTO_PARAGRAPH:
        {
-                istringstream istr(argument.c_str());
+               istringstream istr(argument.c_str());
 
                int id;
                istr >> id;
@@ -1411,8 +1404,13 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                               << " found." << endl;
                }
 
+               if (owner->view()->theLockingInset())
+                       owner->view()->unlockInset(owner->view()->theLockingInset());
+               if (par->inInset()) {
+                       par->inInset()->edit(owner->view());
+               }
                // Set the cursor
-               owner->view()->text->setCursor(owner->view(), par, 0);
+               owner->view()->getLyXText()->setCursor(owner->view(), par, 0);
                owner->view()->setState();
                owner->showState();
 
@@ -1508,7 +1506,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        {
                string const filename =
                        MakeAbsPath(argument, 
-                                   OnlyPath(owner->buffer()->fileName()));
+                                   owner->buffer()->filePath());
                setMessage(N_("Opening child document ") +
                           MakeDisplayPath(filename) + "...");
                owner->view()->savePosition(0);
@@ -1647,7 +1645,7 @@ void LyXFunc::menuNew(bool fromTemplate)
        string initpath = lyxrc.document_path;
 
        if (owner->view()->available()) {
-               string const trypath = owner->buffer()->filepath;
+               string const trypath = owner->buffer()->filePath();
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath))
                        initpath = trypath;
@@ -1773,7 +1771,7 @@ void LyXFunc::open(string const & fname)
        string initpath = lyxrc.document_path;
   
        if (owner->view()->available()) {
-               string const trypath = owner->buffer()->filepath;
+               string const trypath = owner->buffer()->filePath();
                // If directory is writeable, use this as default.
                if (IsDirWriteable(trypath))
                        initpath = trypath;
@@ -1850,7 +1848,7 @@ void LyXFunc::doImport(string const & argument)
                string initpath = lyxrc.document_path;
                
                if (owner->view()->available()) {
-                       string const trypath = owner->buffer()->filepath;
+                       string const trypath = owner->buffer()->filePath();
                        // If directory is writeable, use this as default.
                        if (IsDirWriteable(trypath))
                                initpath = trypath;