partial inset toggling ; insetAllowed stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2277 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2001-07-19 08:52:59 +00:00
parent 7d4d2f9a1a
commit b15e539c68
29 changed files with 245 additions and 134 deletions

View File

@ -1,3 +1,11 @@
2001-07-19 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* bind/xemacs.bind:
* bind/sciword.bind:
* bind/emacs.bind:
* bind/cua.bind:
* ui/default.ui: use inset-toggle instead of open-stuff
2001-07-12 Kayvan A. Sylvan <kayvan@camel.internal.sylvan.com>
* layouts/literate-scrap.inc: Added PassThru tag

View File

@ -55,7 +55,7 @@
\bind "C-f" "find-replace"
\bind "C-g" "error-next"
\bind "C-i" "open-stuff" # 'i' for Inset
\bind "C-i" "inset-toggle" # 'i' for Inset
\bind "C-c" "copy"
\bind "C-x" "cut"

View File

@ -38,7 +38,7 @@
\bind "C-l" "screen-recenter"
\bind "C-m" "mark-toggle"
\bind "C-n" "down"
\bind "C-o" "open-stuff"
\bind "C-o" "inset-toggle"
\bind "C-p" "up"
# this is "quoted-insert" a total different meaning from "quote-insert"

View File

@ -42,7 +42,7 @@
# Numbering equations. Should perhaps simplify math-number and math-nonumber into one command since they are used in very different contexts. This and also math-macro stuff should be available in the Lyx menus!
\bind "C-n" "math-number"
\bind "S-C-n" "math-nonumber"
\bind "C-o" "open-stuff"
\bind "C-o" "inset-toggle"
# Insert a quote character. Do I need this?
\bind "C-q" "quote-insert"

View File

@ -39,7 +39,7 @@
\bind "C-l" "screen-recenter"
\bind "C-m" "mark-toggle"
\bind "C-n" "down"
\bind "C-o" "open-stuff"
\bind "C-o" "inset-toggle"
\bind "C-p" "up"
# this is "quoted-insert" a total different meaning from "quote-insert"

View File

@ -114,7 +114,7 @@ Menuset
End
Menu "edit_floats"
Item "Open/Close|O" "open-stuff"
Item "Open/Close|O" "inset-toggle"
# Item "Melt|M" "melt"
# Item "Open All Figures/Tables|F" "floats-operate openfig"
# Item "Close All Figures/Tables|T" "floats-operate closefig"

View File

@ -2637,13 +2637,13 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
}
break;
case LFUN_OPENSTUFF:
case LFUN_INSET_TOGGLE:
{
LyXText * lt = bv_->getLyXText();
hideCursor();
beforeChange(lt);
update(lt, BufferView::SELECT|BufferView::FITCUR);
lt->openStuff(bv_);
lt->toggleInset(bv_);
update(lt, BufferView::SELECT|BufferView::FITCUR);
setState();
}
@ -3343,7 +3343,7 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
// if we are in a locking inset we should try to insert the
// inset there otherwise this is a illegal function now
if (bv_->theLockingInset()) {
if (bv_->theLockingInset()->insertInsetAllowed(inset))
if (bv_->theLockingInset()->insetAllowed(inset))
return bv_->theLockingInset()->insertInset(bv_, inset);
return false;
}

View File

@ -1,3 +1,26 @@
2001-07-19 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lyxfunc.C (getStatus): add support for all the inset insertion
commands.
* text2.C (insertInset):
* paragraph.C (insetAllowed):
* BufferView_pimpl.C (insertInset): update to take in account the
renaming of insertInsetAllowed
* lyxfunc.C (getStatus): add support for LFUN_INSET_TOGGLE.
* text2.C (getInset): new method. returns inset at cursor position.
* BufferView_pimpl.C (Dispatch): changes because of this.
* LyXAction.C (init): rename open-stuff to inset-toggle.
* commandtags.h: rename LFUN_OPENSTUFF to LFUN_INSET_TOGGLE.
* text2.C (toggleInset): renamed from openStuff; use
Inset::open().
2001-07-13 Yves Bastide <stid@libd-pc11.univ-bpclermont.fr>
* lyxrc.C (set_font_norm_type): recognise ISO_8859_15.

View File

@ -310,7 +310,8 @@ void LyXAction::init()
{ LFUN_INSET_MINIPAGE, "minipage-insert", "", Noop },
{ LFUN_INSERT_NOTE, "note-insert", "", Noop },
{ LFUN_GOTONOTE, "note-next", "", ReadOnly },
{ LFUN_OPENSTUFF, "open-stuff", "", ReadOnly },
{ LFUN_INSET_TOGGLE, "inset-toggle",
N_("toggle inset"), ReadOnly },
{ LFUN_DOWN_PARAGRAPH, "paragraph-down",
N_("Go one paragraph down"), ReadOnly },
{ LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select",

View File

@ -49,7 +49,7 @@ enum kb_action {
LFUN_COPY,
LFUN_GOTOERROR,
LFUN_GOTONOTE,
LFUN_OPENSTUFF,
LFUN_INSET_TOGGLE,
LFUN_HYPHENATION,
LFUN_HFILL,
LFUN_DEPTH,
@ -233,7 +233,10 @@ enum kb_action {
LFUN_VC_UNDO, // Lgb 97-07-01
LFUN_VC_HISTORY, // Lgb 97-07-01
LFUN_EXPORT, // Lgb 97-07-29
#if 0
LFUN_INSERTFOOTNOTE, // Bernhard 97-08-07
// schedule for deletion
#endif
LFUN_REF_GOTO, // 200 // Ale 970806
//LFUN_REF_BACK, // Ale 970806
LFUN_PARENTINSERT, // Ale 970813

View File

@ -1,3 +1,17 @@
2001-07-18 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* many files: update to match the change below
* inset.h (insetAllowed): renamed from insertInsetAllowed;
implement the version which takes an inset here.
* insetcollapsable.[Ch]: implement open and isOpen
* inset.h: remove insertInsetAllowed from Inset
(open): new method, to open or close an inset
(isOpen): returns the status of an inset
(isCollapsable, colapse): removed
2001-07-13 Yves Bastide <stid@libd-pc11.univ-bpclermont.fr>
* insetquotes.C (dispString): display french guillemets when using

View File

@ -161,6 +161,12 @@ public:
virtual bool doClearArea() const { return true; }
///
virtual bool autoDelete() const;
/// returns true the inset can hold an inset of given type
virtual bool insetAllowed(Inset::Code) const { return false; }
/// wrapper around the above
bool insetAllowed(Inset * in) const {
return insetAllowed(in->lyxCode());
}
///
virtual void write(Buffer const *, std::ostream &) const = 0;
///
@ -207,8 +213,6 @@ public:
///
virtual bool needFullRow() const { return false; }
///
virtual bool insertInsetAllowed(Inset *) const { return false; }
///
void setInsetName(string const & s) { name = s; }
///
string const getInsetName() const { return name; }
@ -258,6 +262,11 @@ public:
int id() const;
void id(int id_arg);
/// used to toggle insets
// is the inset open?
virtual bool isOpen() const { return false; }
// open or close the inset, depending on the bool
virtual void open(BufferView *, bool) {}
protected:
///
mutable int top_x;
@ -367,9 +376,6 @@ public:
///
virtual bool insertInset(BufferView *, Inset *) { return false; }
///
virtual bool insertInsetAllowed(Inset *) const { return false; }
virtual bool insertInsetAllowed(Inset::Code) const { return false; }
///
virtual UpdatableInset * getLockingInset() const {
return const_cast<UpdatableInset *>(this);
}
@ -410,11 +416,6 @@ public:
return block_drawing_;
}
///
virtual bool isCollapsable() const { return false; }
///
virtual bool collapsed() const { return false; }
virtual void collapsed(BufferView *, bool) {}
///
// needed for spellchecking text
///
virtual string selectNextWord(BufferView *, float & value) const;

View File

@ -51,7 +51,7 @@ InsetCollapsable::InsetCollapsable()
bool InsetCollapsable::insertInset(BufferView * bv, Inset * in)
{
if (!insertInsetAllowed(in)) {
if (!insetAllowed(in->lyxCode())) {
lyxerr << "InsetCollapsable::InsertInset: "
"Unable to insert inset." << endl;
return false;
@ -524,10 +524,10 @@ Inset * InsetCollapsable::getInsetFromID(int id_arg) const
return inset.getInsetFromID(id_arg);
}
void InsetCollapsable::collapsed(BufferView * bv, bool flag)
void InsetCollapsable::open(BufferView * bv, bool flag)
{
if (flag == collapsed_)
if (flag == !collapsed_)
return;
collapsed_ = flag;
collapsed_ = !flag;
bv->updateInset(this, false);
}

View File

@ -64,11 +64,8 @@ public:
///
bool insertInset(BufferView *, Inset * inset);
///
bool insertInsetAllowed(Inset * in) const {
return inset.insertInsetAllowed(in);
}
bool insertInsetAllowed(Inset::Code code) const {
return inset.insertInsetAllowed(code);
bool insetAllowed(Inset::Code code) const {
return inset.insetAllowed(code);
}
///
bool isTextInset() const { return true; }
@ -157,9 +154,8 @@ public:
///
LyXCursor const & cursor(BufferView *) const;
///
bool isCollapsable() const { return true; }
bool collapsed() const { return collapsed_; }
void collapsed(BufferView *, bool);
bool isOpen() const { return !collapsed_; }
void open(BufferView *, bool);
///
string selectNextWord(BufferView * bv, float & value) const {
return inset.selectNextWord(bv, value);

View File

@ -40,7 +40,7 @@ public:
///
virtual bool insertInset(BufferView *, Inset *);
///
virtual bool insertInsetAllowed(Inset *) const { return false; }
virtual bool insetAllowed(Inset::Code) const { return false; }
///
virtual void setFont(BufferView *, LyXFont const &,
bool toggleall = false, bool selectall = false);

View File

@ -234,18 +234,12 @@ int InsetFloat::docBook(Buffer const * buf, ostream & os) const
}
bool InsetFloat::insertInsetAllowed(Inset * in) const
{
return insertInsetAllowed(in->lyxCode());
}
bool InsetFloat::insertInsetAllowed(Inset::Code code) const
bool InsetFloat::insetAllowed(Inset::Code code) const
{
if (code == Inset::FLOAT_CODE)
return false;
if (inset.getLockingInset() != const_cast<InsetFloat *>(this))
return inset.insertInsetAllowed(code);
return inset.insetAllowed(code);
if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE))
return false;
return true;

View File

@ -44,8 +44,7 @@ public:
///
string const editMessage() const;
///
bool insertInsetAllowed(Inset * inset) const;
bool insertInsetAllowed(Inset::Code) const;
bool insetAllowed(Inset::Code) const;
///
void insetButtonRelease(BufferView * bv, int x, int y, int button);
///

View File

@ -40,14 +40,9 @@ void InsetFootlike::write(Buffer const * buf, std::ostream & os) const
}
bool InsetFootlike::insertInsetAllowed(Inset * in) const
{
return insertInsetAllowed(in->lyxCode());
}
bool InsetFootlike::insertInsetAllowed(Inset::Code code) const
bool InsetFootlike::insetAllowed(Inset::Code code) const
{
if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE))
return false;
return InsetCollapsable::insertInsetAllowed(code);
return InsetCollapsable::insetAllowed(code);
}

View File

@ -32,8 +32,7 @@ public:
///
void write(Buffer const * buf, std::ostream & os) const;
///
bool insertInsetAllowed(Inset * inset) const;
bool insertInsetAllowed(Inset::Code) const;
bool insetAllowed(Inset::Code) const;
};
#endif

View File

@ -269,17 +269,12 @@ int InsetMinipage::latex(Buffer const * buf,
}
bool InsetMinipage::insertInsetAllowed(Inset * in) const
{
return insertInsetAllowed(in->lyxCode());
}
bool InsetMinipage::insertInsetAllowed(Inset::Code code) const
bool InsetMinipage::insetAllowed(Inset::Code code) const
{
if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
return false;
return InsetCollapsable::insertInsetAllowed(code);
return InsetCollapsable::insetAllowed(code);
}

View File

@ -59,8 +59,7 @@ public:
///
string const editMessage() const;
///
bool insertInsetAllowed(Inset * inset) const;
bool insertInsetAllowed(Inset::Code) const;
bool insetAllowed(Inset::Code) const;
///
Position pos() const;
///

View File

@ -123,7 +123,7 @@ public:
///
bool insertInset(BufferView *, Inset *);
///
bool insertInsetAllowed(Inset *) const {
bool insetAllowed(Inset::Code) const {
return the_locking_inset != 0;
}
///

View File

@ -1410,7 +1410,7 @@ InsetText::moveDown(BufferView * bv)
bool InsetText::insertInset(BufferView * bv, Inset * inset)
{
if (the_locking_inset) {
if (the_locking_inset->insertInsetAllowed(inset))
if (the_locking_inset->insetAllowed(inset))
return the_locking_inset->insertInset(bv, inset);
return false;
}
@ -1435,17 +1435,10 @@ bool InsetText::insertInset(BufferView * bv, Inset * inset)
}
bool InsetText::insertInsetAllowed(Inset * in) const
bool InsetText::insetAllowed(Inset::Code code) const
{
if (the_locking_inset)
return the_locking_inset->insertInsetAllowed(in);
return true;
}
bool InsetText::insertInsetAllowed(Inset::Code code) const
{
if (the_locking_inset)
return the_locking_inset->insertInsetAllowed(code);
return the_locking_inset->insetAllowed(code);
return true;
}

View File

@ -152,8 +152,7 @@ public:
///
bool insertInset(BufferView *, Inset *);
///
bool insertInsetAllowed(Inset *) const;
bool insertInsetAllowed(Inset::Code) const;
bool insetAllowed(Inset::Code) const;
///
UpdatableInset * getLockingInset() const;
///

View File

@ -428,15 +428,6 @@ func_status::value_type LyXFunc::getStatus(int ac,
disable = !Exporter::IsExportable(buf, "program");
break;
case LFUN_INSERTFOOTNOTE:
// Disable insertion of floats in a tabular.
disable = false;
if (owner->view()->theLockingInset()) {
disable = (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) ||
owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
}
break;
case LFUN_LAYOUT_TABULAR:
disable = true;
if (owner->view()->theLockingInset()) {
@ -490,6 +481,12 @@ func_status::value_type LyXFunc::getStatus(int ac,
case LFUN_BOOKMARK_GOTO:
disable = !owner->view()->
isSavedPosition(strToUnsignedInt(argument));
break;
case LFUN_INSET_TOGGLE:
disable = (TEXT(false)->getInset() == 0);
break;
case LFUN_MATH_VALIGN: {
// I think this test can be simplified (Andre')
@ -592,44 +589,128 @@ func_status::value_type LyXFunc::getStatus(int ac,
default:
break;
}
if (disable)
flag |= func_status::Disabled;
if (buf) {
func_status::value_type box = func_status::ToggleOff;
LyXFont const & font =
TEXT(false)->real_current_font;
switch (action) {
case LFUN_EMPH:
if (font.emph() == LyXFont::ON)
box = func_status::ToggleOn;
break;
case LFUN_NOUN:
if (font.noun() == LyXFont::ON)
box = func_status::ToggleOn;
break;
case LFUN_BOLD:
if (font.series() == LyXFont::BOLD_SERIES)
box = func_status::ToggleOn;
break;
#ifndef NO_LATEX
case LFUN_TEX:
if (font.latex() == LyXFont::ON)
box = func_status::ToggleOn;
break;
#endif
case LFUN_READ_ONLY_TOGGLE:
if (buf->isReadonly())
box = func_status::ToggleOn;
break;
default:
box = func_status::OK;
break;
}
flag |= box;
}
// the functions which insert insets
Inset::Code code = Inset::NO_CODE;
switch (action) {
case LFUN_INSET_TEXT:
code = Inset::TEXT_CODE;
break;
case LFUN_INSET_ERT:
code = Inset::ERT_CODE;
break;
case LFUN_INSET_GRAPHICS:
code = Inset::GRAPHICS_CODE;
break;
case LFUN_INSET_FOOTNOTE:
code = Inset::FOOT_CODE;
break;
case LFUN_INSET_TABULAR:
code = Inset::TABULAR_CODE;
break;
case LFUN_INSET_EXTERNAL:
code = Inset::EXTERNAL_CODE;
break;
case LFUN_INSET_MARGINAL:
code = Inset::MARGIN_CODE;
break;
case LFUN_INSET_MINIPAGE:
code = Inset::MINIPAGE_CODE;
break;
case LFUN_INSET_FLOAT:
case LFUN_INSET_WIDE_FLOAT:
code = Inset::FLOAT_CODE;
break;
#if 0
case LFUN_INSET_LIST:
code = Inset::LIST_CODE;
break;
#endif
case LFUN_INSET_THEOREM:
code = Inset::THEOREM_CODE;
break;
case LFUN_INSET_CAPTION:
code = Inset::CAPTION_CODE;
break;
case LFUN_INSERT_NOTE:
code = Inset::IGNORE_CODE;
break;
case LFUN_INSERT_LABEL:
code = Inset::LABEL_CODE;
break;
case LFUN_REF_INSERT:
code = Inset::REF_CODE;
break;
case LFUN_CITATION_INSERT:
code = Inset::CITE_CODE;
break;
case LFUN_INSERT_BIBTEX:
code = Inset::BIBTEX_CODE;
break;
case LFUN_INDEX_INSERT:
case LFUN_INDEX_INSERT_LAST:
code = Inset::INDEX_CODE;
break;
#if 0
case LFUN_CHILD_INSERT:
code = Inset::CHILD_CODE;
break;
#endif
case LFUN_TOC_INSERT:
code = Inset::TOC_CODE;
break;
case LFUN_PARENTINSERT:
code = Inset::PARENT_CODE;
break;
case LFUN_INSERT_URL:
code = Inset::URL_CODE;
break;
default:
break;
}
if (code != Inset::NO_CODE
&& owner->view()->theLockingInset()
&& !owner->view()->theLockingInset()->insetAllowed(code)) {
disable = true;
}
if (disable)
flag |= func_status::Disabled;
// the font related functions
func_status::value_type box = func_status::ToggleOff;
LyXFont const & font =
TEXT(false)->real_current_font;
switch (action) {
case LFUN_EMPH:
if (font.emph() == LyXFont::ON)
box = func_status::ToggleOn;
break;
case LFUN_NOUN:
if (font.noun() == LyXFont::ON)
box = func_status::ToggleOn;
break;
case LFUN_BOLD:
if (font.series() == LyXFont::BOLD_SERIES)
box = func_status::ToggleOn;
break;
#ifndef NO_LATEX
case LFUN_TEX:
if (font.latex() == LyXFont::ON)
box = func_status::ToggleOn;
break;
#endif
case LFUN_READ_ONLY_TOGGLE:
if (buf->isReadonly())
box = func_status::ToggleOn;
break;
default:
box = func_status::OK;
break;
}
flag |= box;
return flag;
}

View File

@ -271,6 +271,8 @@ public:
void getWord(LyXCursor & from, LyXCursor & to, word_location) const;
/// just selects the word the cursor is in
void selectWord(BufferView *);
/// returns the inset at cursor (if it exists), 0 otherwise
Inset * getInset() const;
/** 'selects" the next word, where the cursor is not in
and returns this word as string. THe cursor will be moved
@ -377,7 +379,7 @@ public:
Row * row_ptr, int y, bool cleared=false);
///
void openStuff(BufferView *);
void toggleInset(BufferView *);
///
void cutSelection(BufferView *, bool = true);
///

View File

@ -430,7 +430,7 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams,
bool Paragraph::insertFromMinibuffer(Paragraph::size_type pos)
{
if ((minibuffer_char == Paragraph::META_INSET) &&
!insertInsetAllowed(minibuffer_inset))
!insetAllowed(minibuffer_inset->lyxCode()))
return false;
if (minibuffer_char == Paragraph::META_INSET)
insertInset(pos, minibuffer_inset, minibuffer_font);
@ -489,12 +489,12 @@ void Paragraph::insertInset(Paragraph::size_type pos,
}
bool Paragraph::insertInsetAllowed(Inset * inset)
bool Paragraph::insetAllowed(Inset::Code code)
{
//lyxerr << "Paragraph::InsertInsetAllowed" << endl;
if (pimpl_->inset_owner)
return pimpl_->inset_owner->insertInsetAllowed(inset);
return pimpl_->inset_owner->insetAllowed(code);
return true;
}

View File

@ -274,7 +274,7 @@ public:
///
void insertInset(size_type pos, Inset * inset, LyXFont const &);
///
bool insertInsetAllowed(Inset * inset);
bool insetAllowed(Inset::Code code);
///
Inset * getInset(size_type pos);
///

View File

@ -360,20 +360,29 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
}
}
void LyXText::openStuff(BufferView * bview)
Inset * LyXText::getInset() const
{
Inset * inset = 0;
if (cursor.pos() == 0 && cursor.par()->bibkey){
cursor.par()->bibkey->edit(bview, 0, 0, 0);
inset = cursor.par()->bibkey;
} else if (cursor.pos() < cursor.par()->size()
&& cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
Inset * inset = cursor.par()->getInset(cursor.pos());
if (!inset->editable())
return;
bview->owner()->message(inset->editMessage());
if (inset->editable() != Inset::HIGHLY_EDITABLE)
setCursorParUndo(bview);
inset->edit(bview, 0, 0, 0);
inset = cursor.par()->getInset(cursor.pos());
}
return inset;
}
void LyXText::toggleInset(BufferView * bview)
{
Inset * inset = getInset();
if (!inset->editable())
return;
//bview->owner()->message(inset->editMessage());
// do we want to keep this?? (JMarc)
if (inset->editable() != Inset::HIGHLY_EDITABLE)
setCursorParUndo(bview);
inset->open(bview, !inset->isOpen());
}
@ -1534,7 +1543,7 @@ void LyXText::updateCounters(BufferView * bview, Row * row) const
void LyXText::insertInset(BufferView * bview, Inset * inset)
{
if (!cursor.par()->insertInsetAllowed(inset))
if (!cursor.par()->insetAllowed(inset->lyxCode()))
return;
setUndo(bview, Undo::INSERT,
cursor.par(), cursor.par()->next());