I'm moved this into the core (patch attached):

void ControlDocument::setLanguage()
{
        Language const * oldL = buffer()->params().language;
        Language const * newL = bp_->language;

        if (oldL != newL) {

                if (oldL->RightToLeft() == newL->RightToLeft()
                    && !lv_.buffer()->isMultiLingual())
                        lv_.buffer()->changeLanguage(oldL, newL);
                else
                    lv_.buffer()->updateDocLang(newL);
        }
}

which requires a new LFUN_LANGUAGE_BUFFER (we already have a
LFUN_LANGUAGE used to set the language of some text snippet):

void ControlDocument::setLanguage()
{
        Language const * const oldL = buffer()->params().language;
        Language const * const newL = bp_->language;

        // This comparison is an optimization.
        // It will be repeated in the core.
        if (oldL != newL) {
                string const lang_name = newL->lang();
                lv_.getLyXFunc().dispatch(
                        FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
        }
}

Any thoughts on names better than LFUN_LANGUAGE_BUFFER? We seem to
avoid using 'BUFFER' or 'DOC' in LFUNs.

-- 
Angus
Index: src/LyXAction.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v
retrieving revision 1.194
diff -u -p -r1.194 LyXAction.C
--- src/LyXAction.C	28 Mar 2004 14:12:30 -0000	1.194
+++ src/LyXAction.C	28 Mar 2004 16:17:10 -0000
@@ -191,6 +191,7 @@ void LyXAction::init()
 		{ LFUN_INSERT_LINE, "line-insert", Noop },
 		{ LFUN_INSERT_PAGEBREAK, "pagebreak-insert", Noop },
 		{ LFUN_LANGUAGE, "language", Noop },
+		{ LFUN_LANGUAGE_BUFFER, "buffer-language", Noop },
 		{ LFUN_LAYOUT, "layout", Noop },
 		{ LFUN_LAYOUT_PARAGRAPH, "layout-paragraph", ReadOnly },
 		{ LFUN_LAYOUT_TABULAR, "layout-tabular", Noop },
Index: src/lfuns.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lfuns.h,v
retrieving revision 1.31
diff -u -p -r1.31 lfuns.h
--- src/lfuns.h	28 Mar 2004 14:12:31 -0000	1.31
+++ src/lfuns.h	28 Mar 2004 16:17:11 -0000
@@ -337,6 +337,7 @@ enum kb_action {
 	// 255
 	LFUN_EXPORT_CUSTOM,
 	LFUN_PRINT,
+	LFUN_LANGUAGE_BUFFER,
 
 	LFUN_LASTACTION                  // end of the table
 };
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.591
diff -u -p -r1.591 lyxfunc.C
--- src/lyxfunc.C	28 Mar 2004 14:12:31 -0000	1.591
+++ src/lyxfunc.C	28 Mar 2004 16:17:12 -0000
@@ -39,6 +39,7 @@
 #include "intl.h"
 #include "iterators.h"
 #include "kbmap.h"
+#include "language.h"
 #include "LColor.h"
 #include "lyx_cb.h"
 #include "LyXAction.h"
@@ -494,6 +495,7 @@ FuncStatus LyXFunc::getStatus(FuncReques
 	case LFUN_FILE_INSERT:
 	case LFUN_FILE_INSERT_ASCII:
 	case LFUN_FILE_INSERT_ASCII_PARA:
+	case LFUN_LANGUAGE_BUFFER:
 		// these are handled in our dispatch()
 		break;
 
@@ -688,6 +690,21 @@ void LyXFunc::dispatch(FuncRequest const
 			owner->buffer()->runChktex();
 			view()->showErrorList(_("ChkTeX"));
 			break;
+
+		case LFUN_LANGUAGE_BUFFER: {
+			Buffer & buffer = *owner->buffer();
+			Language const * oldL = buffer.params().language;
+			Language const * newL = languages.getLanguage(argument);
+			if (!newL || oldL == newL)
+				break;
+
+			if (oldL->RightToLeft() == newL->RightToLeft()
+			    && !buffer.isMultiLingual())
+				buffer.changeLanguage(oldL, newL);
+			else
+				buffer.updateDocLang(newL);
+			break;
+		}
 
 		case LFUN_EXPORT:
 			if (argument == "custom")
Index: src/frontends/controllers/ControlDocument.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlDocument.C,v
retrieving revision 1.45
diff -u -p -r1.45 ControlDocument.C
--- src/frontends/controllers/ControlDocument.C	25 Mar 2004 09:16:27 -0000	1.45
+++ src/frontends/controllers/ControlDocument.C	28 Mar 2004 16:17:12 -0000
@@ -20,14 +20,14 @@
 #include "BufferView.h"
 #include "CutAndPaste.h"
 #include "errorlist.h"
+#include "funcrequest.h"
 #include "gettext.h"
 #include "iterators.h"
 #include "language.h"
 #include "LColor.h"
+#include "lyxfunc.h"
 #include "lyxtextclasslist.h"
 #include "paragraph.h"
-#include "funcrequest.h"
-#include "lfuns.h"
 
 #include "frontends/Alert.h"
 #include "frontends/LyXView.h"
@@ -124,16 +124,15 @@ void ControlDocument::setParams()
 
 void ControlDocument::setLanguage()
 {
-	Language const * oldL = buffer()->params().language;
-	Language const * newL = bp_->language;
+	Language const * const oldL = buffer()->params().language;
+	Language const * const newL = bp_->language;
 
+	// This comparison is an optimization.
+	// It will be repeated in the core.
 	if (oldL != newL) {
-
-		if (oldL->RightToLeft() == newL->RightToLeft()
-		    && !lv_.buffer()->isMultiLingual())
-			lv_.buffer()->changeLanguage(oldL, newL);
-		else
-		    lv_.buffer()->updateDocLang(newL);
+		string const lang_name = newL->lang();
+		lv_.getLyXFunc().dispatch(
+			FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
 	}
 }
 

Reply via email to