We currently have two mechanisms to apply a font change. LFUN layout-character is dispatched from the Layout->character menu item. It results in a call to Dialogs::showCharacter() which pops up the character dialog allowing us to manipulate the dialog's local LyXFont instance. 'Apply' results in the dialog manipulating the kernel direct with the contents of this variable.
LFUN font-free is dispatched from the toolbar. It results in a call to Dialogs::setUserFreeFont() which in turn calls the dialog's apply method direct. This then goes on to manipulate the kernel with the existing contents of the dialog's LyXFont variable. Clearly this is all a big mess. Here's what I propose to replace it. bufferview_funcs.C: namespace { LyXFont freefont(LyXFont::ALL_IGNORE); bool toggleall(false); } // Set data using font and toggle // If successful, returns true bool font2string(LyXFont const & font, bool toggle, string & data) { ... } // Set font and toggle using data // If successful, returns true bool string2font(string const & data, LyXFont & font, bool & toggle) { ... } string const freefont2string() { string data; if (font2string(freefont, toggleall, data)) return data; return string(); } void update_and_apply_freefont(BufferView * bv, string const & data) { LyXFont font; bool toggle; if (string2font(data, font, toggle)) { freefont = font; toggleall = toggle; applt_freefont(bv); } } void apply_freefont(BufferView * bv) { toggleAndShow(bv, freefont, toggleall); bv->owner()->view_state_changed(); bv->buffer()->markDirty(); bv->owner()->message(_("Character set")); } Now, LFUN layout-character will result in a call from LyXFunc::dispatch case LFUN_LAYOUT_CHARACTER: { string data = freefont2string(); if (!data.empty()) owner->getDialogs().show("character", data); break; } 'Apply' in the character dialog will result in: void ControlCharacter::dispatchParams() { string data; if (font2string(localfont, localtoggle, data)) { FuncRequest fr(LFUN_FREEFONT_UPDATE, data); kernel().dispatch(fr); } } Which is disentangled in LyXFunc::dispatch case LFUN_FREEFONT_UPDATE: update_and_apply_freefont(view(), argument); break; Finally, we have the toolbar's LFUN free-font: case LFUN_FREE: apply_freefont(view()); break; So all that remains to be done is to write the font2string and string2font functions. Does this sound like a coherent plan? -- Angus