A slightly buggy lfun all-insets-toggle.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8564 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-03-30 12:36:33 +00:00
parent 72dd20be15
commit 991b0ec589
21 changed files with 276 additions and 120 deletions

View File

@ -1,3 +1,10 @@
2004-03-30 Angus Leeming <leeming@lyx.org>
* bind/aqua.bind:
* bind/cua.bind:
* bind/emacs.bind:
* bind/xemacs.bind: s/inset_toggle/next-inset-toggle/.
2004-03-29 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* dco/LaTeXConfig.lyx.in: check for bibtopic.

View File

@ -77,7 +77,7 @@
\bind "M-~S-e s" "spellchecker"
\bind "M-~S-e h" "buffer-chktex"
\bind "M-~S-e e" "error-remove-all"
\bind "M-~S-e l" "inset-toggle"
\bind "M-~S-e l" "next-inset-toggle"
\bind "M-~S-e p" "dialog-preferences"
\bind "M-~S-e r" "reconfigure"

View File

@ -62,7 +62,7 @@
\bind "C-f" "dialog-show findreplace"
\bind "C-g" "error-next"
\bind "C-i" "inset-toggle" # 'i' for Inset
\bind "C-i" "next-inset-toggle" # 'i' for Inset
\bind "C-c" "copy"
\bind "C-x" "cut"

View File

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

View File

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

View File

@ -1,3 +1,25 @@
2004-03-30 Angus Leeming <leeming@lyx.org>
* lfuns.h:
* LyXAction.C (init): new lfuns, LFUN_KEYMAP_TOGGLE,
LFUN_NEXT_INSET_TOGGLE, LFUN_ALL_INSETS_TOGGLE.
* lyxfunc.C (dispatch): LFUN_ALL_INSETS_TOGGLE is used to toggle the
open/closed state of ollapsable insets. Usage:
all-inset-toggle <state> <name>, where
<state> == "open" || "closed" || "toggle" and
<name> is an identifier for a 'type' of inset. Eg "branch", "ert",...
* lyxtext.h, text2.C (toggleInset): removed.
* text3.C (dispatch): split the existing LFUN_INSET_TOGGLE in two,
LFUN_KEYMAP_TOGGLE and LFUN_NEXT_INSET_TOGGLE. LFUN_NEXT_INSET_TOGGLE
now passes LFUN_INSET_TOGGLE to the found inset.
* InsetList.[Ch] (insetsOpenCloseBranch): removed. Functionality
is now invoked as "all-insets-toggle toggle branch".
2004-03-30 Angus Leeming <leeming@lyx.org>
* dociterator.C:

View File

@ -135,23 +135,3 @@ void InsetList::decreasePosAfterPos(pos_type pos)
--it->pos;
}
}
void InsetList::insetsOpenCloseBranch(Buffer const & buf)
{
List::iterator it = list.begin();
List::iterator end = list.end();
for (; it != end; ++it) {
if (!it->inset)
continue;
if (it->inset->lyxCode() != InsetBase::BRANCH_CODE)
continue;
InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
if (inset->isBranchSelected(buf.params().branchlist())) {
inset->open();
} else {
inset->close();
}
}
}

View File

@ -67,8 +67,6 @@ public:
void increasePosAfterPos(lyx::pos_type pos);
///
void decreasePosAfterPos(lyx::pos_type pos);
///
void insetsOpenCloseBranch(Buffer const & buf);
private:
///

View File

@ -231,7 +231,9 @@ void LyXAction::init()
{ LFUN_INSERT_NOTE, "note-insert", Noop },
{ LFUN_INSERT_BOX, "box-insert", Noop },
{ LFUN_GOTONOTE, "note-next", ReadOnly },
{ LFUN_INSET_TOGGLE, "inset-toggle", ReadOnly },
{ LFUN_INSET_TOGGLE, "", ReadOnly },
{ LFUN_NEXT_INSET_TOGGLE, "next-inset-toggle", ReadOnly },
{ LFUN_ALL_INSETS_TOGGLE, "all-insets-toggle", ReadOnly },
{ LFUN_DOWN_PARAGRAPH, "paragraph-down", ReadOnly },
{ LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select", ReadOnly },
{ LFUN_GOTO_PARAGRAPH, "paragraph-goto", ReadOnly },
@ -326,6 +328,7 @@ void LyXAction::init()
{ LFUN_REPEAT, "repeat", NoBuffer },
{ LFUN_WORD_FIND, "word-find", Noop },
{ LFUN_WORD_REPLACE, "word-replace", Noop },
{ LFUN_KEYMAP_TOGGLE, "keymap-toggle", Noop },
{ LFUN_NOACTION, "", Noop }
};

View File

@ -1,3 +1,9 @@
2004-03-30 Angus Leeming <leeming@lyx.org>
* ControlDocument.C (apply): replace the loop over paragraphs
invoking insetsOpenCloseBranch with
LFUN_ALL_INSETS_TOGGLE, "toggle branch".
2004-03-29 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* ControlBibtex.[Ch]: add member usingBibtopic().

View File

@ -28,7 +28,6 @@
#include "lfuns.h"
#include "paragraph.h"
#include "ParagraphList_fwd.h"
#include "pariterator.h"
#include "frontends/Alert.h"
#include "frontends/LyXView.h"
@ -104,12 +103,7 @@ void ControlDocument::apply()
}
// Open insets of selected branches, close deselected ones
// Currently only top-level insets in buffer handled (bug).
ParIterator pit = buffer()->par_iterator_begin();
ParIterator pend = buffer()->par_iterator_end();
for (; pit != pend; ++pit) {
pit->insetlist.insetsOpenCloseBranch(*buffer());
}
lv_.dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE, "toggle branch"));
}

View File

@ -1,3 +1,13 @@
2004-03-30 Angus Leeming <leeming@lyx.org>
* insetbase.[Ch] (translate): new static member function, returns
an InsetBase::Code corresponding to the input string.
* insetcollapsable.C (priv_dispatch): handle LFUN_INSET_TOGGLE.
* insetbranch.C(priv_dispatch): specialize LFUN_INSET_TOGGLE
so that it opens the inset if it refers to the currently active
branch.
2004-03-30 Alfredo Braunstein <abraunst@lyx.org>

View File

@ -25,6 +25,88 @@
#include "frontends/Painter.h"
#include <map>
namespace {
struct InsetName {
InsetName(std::string const & n, InsetBase::Code c)
: name(n), code(c) {}
std::string name;
InsetBase::Code code;
};
typedef std::map<std::string, InsetBase::Code> TranslatorMap;
TranslatorMap const build_translator()
{
InsetName const insetnames[] = {
InsetName("toc", InsetBase::TOC_CODE),
InsetName("quote", InsetBase::QUOTE_CODE),
InsetName("ref", InsetBase::REF_CODE),
InsetName("url", InsetBase::URL_CODE),
InsetName("htmlurl", InsetBase::HTMLURL_CODE),
InsetName("separator", InsetBase::SEPARATOR_CODE),
InsetName("ending", InsetBase::ENDING_CODE),
InsetName("label", InsetBase::LABEL_CODE),
InsetName("note", InsetBase::NOTE_CODE),
InsetName("accent", InsetBase::ACCENT_CODE),
InsetName("math", InsetBase::MATH_CODE),
InsetName("index", InsetBase::INDEX_CODE),
InsetName("include", InsetBase::INCLUDE_CODE),
InsetName("graphics", InsetBase::GRAPHICS_CODE),
InsetName("bibitem", InsetBase::BIBITEM_CODE),
InsetName("bibtex", InsetBase::BIBTEX_CODE),
InsetName("text", InsetBase::TEXT_CODE),
InsetName("ert", InsetBase::ERT_CODE),
InsetName("foot", InsetBase::FOOT_CODE),
InsetName("margin", InsetBase::MARGIN_CODE),
InsetName("float", InsetBase::FLOAT_CODE),
InsetName("wrap", InsetBase::WRAP_CODE),
InsetName("specialchar", InsetBase::SPECIALCHAR_CODE),
InsetName("tabular", InsetBase::TABULAR_CODE),
InsetName("external", InsetBase::EXTERNAL_CODE),
InsetName("caption", InsetBase::CAPTION_CODE),
InsetName("mathmacro", InsetBase::MATHMACRO_CODE),
InsetName("error", InsetBase::ERROR_CODE),
InsetName("cite", InsetBase::CITE_CODE),
InsetName("float_list", InsetBase::FLOAT_LIST_CODE),
InsetName("index_print", InsetBase::INDEX_PRINT_CODE),
InsetName("optarg", InsetBase::OPTARG_CODE),
InsetName("environment", InsetBase::ENVIRONMENT_CODE),
InsetName("hfill", InsetBase::HFILL_CODE),
InsetName("newline", InsetBase::NEWLINE_CODE),
InsetName("line", InsetBase::LINE_CODE),
InsetName("branch", InsetBase::BRANCH_CODE),
InsetName("box", InsetBase::BOX_CODE),
InsetName("charstyle", InsetBase::CHARSTYLE_CODE),
InsetName("vspace", InsetBase::VSPACE_CODE),
InsetName("mathgrid", InsetBase::MATHGRID_CODE),
InsetName("mathhull", InsetBase::MATHHULL_CODE)
};
std::size_t const insetnames_size =
sizeof(insetnames) / sizeof(insetnames[0]);
std::map<std::string, InsetBase::Code> data;
for (std::size_t i = 0; i != insetnames_size; ++i) {
InsetName const & var = insetnames[i];
data[var.name] = var.code;
}
return data;
}
} // namespace anon
InsetBase::Code InsetBase::translate(std::string const & name)
{
static TranslatorMap const translator = build_translator();
TranslatorMap::const_iterator it = translator.find(name);
return it == translator.end() ? NO_CODE : it->second;
}
void InsetBase::dispatch(LCursor & cur, FuncRequest & cmd)
@ -229,5 +311,3 @@ bool isHighlyEditableInset(InsetBase const * inset)
{
return inset && inset->editable() == InsetBase::HIGHLY_EDITABLE;
}

View File

@ -298,6 +298,12 @@ public:
///
MATHHULL_CODE
};
/** returns the Code corresponding to the \c name.
* Eg, translate("branch") == BRANCH_CODE
*/
static Code translate(std::string const & name);
/// returns true the inset can hold an inset of given type
virtual bool insetAllowed(Code) const { return false; }
// if this inset has paragraphs should they be output all as default

View File

@ -13,6 +13,7 @@
#include "insetbranch.h"
#include "buffer.h"
#include "BufferView.h"
#include "bufferparams.h"
#include "BranchList.h"
#include "cursor.h"
@ -139,6 +140,35 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
InsetCollapsable::priv_dispatch(cur, cmd);
break;
case LFUN_INSET_TOGGLE:
// We assume that this lfun is indeed going to be dispatched.
cur.dispatched();
if (cmd.argument == "open")
setStatus(Open);
else if (cmd.argument == "close")
setStatus(Collapsed);
// The branch inset specialises its behaviour on "toggle".
else if (cmd.argument == "toggle"
|| cmd.argument.empty()) {
BranchList const & branchlist =
cur.bv().buffer()->params().branchlist();
if (isBranchSelected(branchlist)) {
if (status() != Open)
setStatus(Open);
else
cur.undispatched();
} else {
if (status() != Collapsed)
setStatus(Collapsed);
else
cur.undispatched();
}
}
break;
default:
InsetCollapsable::priv_dispatch(cur, cmd);
break;

View File

@ -250,70 +250,73 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
//lyxerr << "\nInsetCollapsable::priv_dispatch (begin): cmd: " << cmd
// << " button y: " << button_dim.y2 << endl;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
if (status_ == Inlined)
InsetText::priv_dispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd))
InsetText::priv_dispatch(cur, cmd);
case LFUN_MOUSE_PRESS:
if (status_ == Inlined)
InsetText::priv_dispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd))
InsetText::priv_dispatch(cur, cmd);
break;
case LFUN_MOUSE_MOTION:
if (status_ == Inlined)
InsetText::priv_dispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd))
InsetText::priv_dispatch(cur, cmd);
break;
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3) {
showInsetDialog(&cur.bv());
break;
}
switch (status_) {
case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
setStatus(Open);
edit(cur, true);
break;
case LFUN_MOUSE_MOTION:
if (status_ == Inlined)
case Open: {
FuncRequest cmd1 = cmd;
if (hitButton(cmd1)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
setStatus(Collapsed);
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
} else {
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
InsetText::priv_dispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd))
InsetText::priv_dispatch(cur, cmd);
break;
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3) {
showInsetDialog(&cur.bv());
break;
}
switch (status_) {
case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
setStatus(Open);
edit(cur, true);
break;
case Open: {
FuncRequest cmd1 = cmd;
if (hitButton(cmd1)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
setStatus(Collapsed);
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
} else {
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
InsetText::priv_dispatch(cur, cmd);
}
break;
}
case Inlined:
lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
InsetText::priv_dispatch(cur, cmd);
break;
}
break;
}
case LFUN_INSET_TOGGLE:
if (InsetText::text_.toggleInset(cur))
break;
if (status_ == Open) {
setStatus(Inlined);
break;
}
setStatus(Collapsed);
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
break;
default:
case Inlined:
lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
InsetText::priv_dispatch(cur, cmd);
break;
}
break;
case LFUN_INSET_TOGGLE:
if (cmd.argument == "open")
setStatus(Open);
else if (cmd.argument == "close")
setStatus(Collapsed);
else if (cmd.argument == "toggle"
|| cmd.argument.empty()) {
if (isOpen())
setStatus(Collapsed);
else
setStatus(Open);
}
cur.dispatched();
break;
default:
InsetText::priv_dispatch(cur, cmd);
break;
}
}

View File

@ -337,6 +337,9 @@ enum kb_action {
// 255
LFUN_EXPORT_CUSTOM,
LFUN_PRINT,
LFUN_KEYMAP_TOGGLE,
LFUN_NEXT_INSET_TOGGLE,
LFUN_ALL_INSETS_TOGGLE,
LFUN_LASTACTION // end of the table
};

View File

@ -36,6 +36,7 @@
#include "funcrequest.h"
#include "gettext.h"
#include "importer.h"
#include "insetiterator.h"
#include "intl.h"
#include "kbmap.h"
#include "LColor.h"
@ -494,6 +495,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
case LFUN_FILE_INSERT:
case LFUN_FILE_INSERT_ASCII:
case LFUN_FILE_INSERT_ASCII_PARA:
case LFUN_ALL_INSETS_TOGGLE:
// these are handled in our dispatch()
break;
@ -1242,6 +1244,31 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
case LFUN_BREAKLINE: {
#warning swallow 'Return' if the minibuffer is focused. But how?
break;
}
case LFUN_ALL_INSETS_TOGGLE: {
string action;
string const name = split(argument, action, ' ');
InsetBase::Code const inset_code =
InsetBase::translate(name);
LCursor & cur = view()->cursor();
FuncRequest fr(LFUN_INSET_TOGGLE, action);
InsetBase & inset = owner->buffer()->inset();
InsetIterator it = inset_iterator_begin(inset);
InsetIterator const end = inset_iterator_end(inset);
for (; it != end; ++it) {
if (inset_code == InsetBase::NO_CODE
|| inset_code == it->lyxCode()) {
it->dispatch(cur, fr);
if (&cur.inset() == &*it
&& cur.disp_.dispatched())
cur.pop();
}
}
break;
}
default: {

View File

@ -231,8 +231,6 @@ public:
};
/// Change the case of the word at cursor position.
void changeCase(LCursor & cur, TextCase action);
/// returns success
bool toggleInset(LCursor & cur);
/** the DTP switches for paragraphs. LyX will store the top settings
always in the first physical paragraph, the bottom settings in the

View File

@ -1413,26 +1413,6 @@ void LyXText::recUndo(par_type par) const
}
bool LyXText::toggleInset(LCursor & cur)
{
InsetBase * inset = cur.nextInset();
// is there an editable inset at cursor position?
if (!isEditableInset(inset))
return false;
cur.message(inset->editMessage());
// do we want to keep this?? (JMarc)
if (!isHighlyEditableInset(inset))
recordUndo(cur);
if (inset->isOpen())
inset->close();
else
inset->open();
return true;
}
int defaultRowHeight()
{
return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) * 1.2);

View File

@ -787,12 +787,20 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
cur.inset().asUpdatableInset()->showInsetDialog(bv);
break;
case LFUN_INSET_TOGGLE:
case LFUN_NEXT_INSET_TOGGLE: {
InsetBase * inset = cur.nextInset();
if (inset) {
cur.clearSelection();
FuncRequest fr = cmd;
fr.action = LFUN_INSET_TOGGLE;
inset->dispatch(cur, fr);
}
break;
}
case LFUN_KEYMAP_TOGGLE:
cur.clearSelection();
if (!toggleInset(cur))
cur.undispatched();
else
bv->switchKeyMap();
bv->switchKeyMap();
break;
case LFUN_SPACE_INSERT:
@ -1815,7 +1823,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
case LFUN_PARAGRAPH_SPACING:
case LFUN_INSET_APPLY:
case LFUN_INSET_INSERT:
case LFUN_INSET_TOGGLE:
case LFUN_NEXT_INSET_TOGGLE:
case LFUN_UPCASE_WORD:
case LFUN_LOWCASE_WORD:
case LFUN_CAPITALIZE_WORD:
@ -1884,6 +1892,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
case LFUN_THESAURUS_ENTRY:
case LFUN_PARAGRAPH_APPLY:
case LFUN_ESCAPE:
case LFUN_KEYMAP_TOGGLE:
// these are handled in our dispatch()
enable = true;
break;