Add LFUN_PARAGRAPH_PARAMS (= paragraph-params), used for changing a paragraph's alignment, spacing, etc. This is complementary to LFUN_PARAGRAPH_PARAMS_APPLY, which sets the parameters. The difference is that APPLY over-rides all existing parameters, setting any not given to the default, whereas this one simply changes those that are given. So

paragraph-params \align right
will align the paragraph right, leaving spacing, etc, as they were, whereas
  paragraph-params-apply \align right
will align the paragraph right but also reset all other parameters to defaults. Note, by the way, that this means that
  paragraph-params-apply
sets everything to default.

Some new arguments have also been introduced. These are:
  \indent
  \indent-toggle
  \spacing default
Of course, none of these are found in valid LyX files, but they are useful in menu bindings, etc.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@19583 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2007-08-15 04:47:30 +00:00
parent d715b0dccf
commit 94476add67
8 changed files with 114 additions and 47 deletions

View File

@ -336,6 +336,7 @@ void LyXAction::init()
{ LFUN_INSET_MODIFY, "", Noop },
{ LFUN_INSET_DIALOG_UPDATE, "", Noop },
{ LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
{ LFUN_PARAGRAPH_PARAMS, "paragraph-params", Noop },
{ LFUN_PARAGRAPH_PARAMS_APPLY, "paragraph-params-apply", Noop },
{ LFUN_PARAGRAPH_UPDATE, "", Noop },
{ LFUN_EXTERNAL_EDIT, "external-edit", Noop },

View File

@ -37,19 +37,12 @@ using std::string;
namespace lyx {
//NOTE The order of these MUST be the same as in Layout.h.
static char const * const string_align[] = {
"block", "left", "right", "center", ""
"block", "left", "right", "center", "default", ""
};
static int findToken(char const * const str[], string const & search_token)
{
return search_token == "default" ?
0 :
support::findToken(str, search_token);
}
ParagraphParameters::ParagraphParameters()
: noindent_(false),
start_of_appendix_(false), appendix_(false),
@ -180,8 +173,19 @@ void ParagraphParameters::leftIndent(Length const & li)
}
void ParagraphParameters::read(Lexer & lex)
void ParagraphParameters::read(std::string str, bool merge)
{
std::istringstream is(str);
Lexer lex(0, 0);
lex.setStream(is);
read(lex, merge);
}
void ParagraphParameters::read(Lexer & lex, bool merge)
{
if (!merge)
clear();
while (lex.isOK()) {
lex.nextToken();
string const token = lex.getString();
@ -196,6 +200,12 @@ void ParagraphParameters::read(Lexer & lex)
if (token == "\\noindent") {
noindent(true);
} else if (token == "\\indent") {
//not found in LyX files but can be used with lfuns
noindent(false);
} else if (token == "\\indent-toggle") {
//not found in LyX files but can be used with lfuns
noindent(!noindent());
} else if (token == "\\leftindent") {
lex.next();
Length value(lex.getString());
@ -205,7 +215,10 @@ void ParagraphParameters::read(Lexer & lex)
} else if (token == "\\paragraph_spacing") {
lex.next();
string const tmp = rtrim(lex.getString());
if (tmp == "single") {
if (tmp == "default") {
//not found in LyX files but can be used with lfuns
spacing(Spacing(Spacing::Default));
} else if (tmp == "single") {
spacing(Spacing(Spacing::Single));
} else if (tmp == "onehalf") {
spacing(Spacing(Spacing::Onehalf));
@ -220,7 +233,7 @@ void ParagraphParameters::read(Lexer & lex)
}
} else if (token == "\\align") {
lex.next();
int tmpret = findToken(string_align, lex.getString());
int tmpret = support::findToken(string_align, lex.getString());
if (tmpret == -1)
++tmpret;
align(LyXAlignment(1 << tmpret));
@ -235,6 +248,28 @@ void ParagraphParameters::read(Lexer & lex)
}
void ParagraphParameters::apply(
ParagraphParameters const & p, Layout const & layout)
{
spacing(p.spacing());
// does the layout allow the new alignment?
if ((p.align() == LYX_ALIGN_LAYOUT) ||
(p.align() & layout.alignpossible))
align(p.align());
labelWidthString(p.labelWidthString());
noindent(p.noindent());
}
//FIXME This needs to be made a real method, so that getStatus()
//can return sensible information.
bool ParagraphParameters::canApply(
ParagraphParameters const & /*params*/, Layout const & /*layout*/)
{
return true;
}
void ParagraphParameters::write(ostream & os) const
{
// Maybe the paragraph has special spacing

View File

@ -80,8 +80,17 @@ public:
///
void leftIndent(Length const &);
/// read the parameters from a string
void read (std::string str, bool merge = true);
/// read the parameters from a lex
void read(Lexer & lex);
void read(Lexer & lex, bool merge = true);
///
void apply(ParagraphParameters const & params, Layout const & layout);
///
bool canApply(ParagraphParameters const & params, Layout const & layout);
/// write out the parameters to a stream
void write(std::ostream & os) const;

View File

@ -269,12 +269,11 @@ public:
always in the first physical paragraph, the bottom settings in the
last. When a paragraph is broken, the top settings rest, the bottom
settings are given to the new one.
This function will handle a multi-paragraph selection.
*/
void setParagraph(Cursor & cur,
Spacing const & spacing,
LyXAlignment align,
docstring const & labelwidthstring,
bool noindent);
void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
/// Sets parameters for current or selected paragraphs
void setParagraphs(Cursor & cur, ParagraphParameters const & p);
/* these things are for search and replace */

View File

@ -29,6 +29,7 @@
#include "BufferView.h"
#include "bufferview_funcs.h"
#include "Bullet.h"
#include "Color.h"
#include "CoordCache.h"
#include "Cursor.h"
#include "CutAndPaste.h"
@ -38,7 +39,7 @@
#include "FuncRequest.h"
#include "gettext.h"
#include "Language.h"
#include "Color.h"
#include "Lexer.h"
#include "LyXFunc.h"
#include "LyXRC.h"
#include "Row.h"
@ -72,7 +73,7 @@ using std::ostringstream;
using std::string;
using std::max;
using std::min;
using std::istringstream;
Text::Text()
: current_font(Font::ALL_INHERIT),
@ -633,9 +634,7 @@ docstring Text::getStringToIndex(Cursor const & cur)
}
void Text::setParagraph(Cursor & cur,
Spacing const & spacing, LyXAlignment align,
docstring const & labelwidthstring, bool noindent)
void Text::setParagraphs(Cursor & cur, docstring arg, bool merge)
{
BOOST_ASSERT(cur.text());
// make sure that the depth behind the selection are restored, too
@ -645,22 +644,33 @@ void Text::setParagraph(Cursor & cur,
for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
pit <= end; ++pit) {
Paragraph & par = pars_[pit];
ParagraphParameters & params = par.params();
params.spacing(spacing);
// does the layout allow the new alignment?
//FIXME The reason we need the first check is because
//LYX_ALIGN_LAYOUT isn't required to be possible. It
//should be...and will be.
if ((align == LYX_ALIGN_LAYOUT) ||
(align & par.layout()->alignpossible))
params.align(align);
par.setLabelWidthString(labelwidthstring);
params.noindent(noindent);
ParagraphParameters params = par.params();
params.read(to_utf8(arg), merge);
Layout const & layout = *(par.layout());
par.params().apply(params, layout);
}
}
//FIXME This is a little redundant now, but it's probably worth keeping,
//especially if we're going to go away from using serialization internally
//quite so much.
void Text::setParagraphs(Cursor & cur, ParagraphParameters const & p)
{
BOOST_ASSERT(cur.text());
// make sure that the depth behind the selection are restored, too
pit_type undopit = undoSpan(cur.selEnd().pit());
recUndo(cur, cur.selBegin().pit(), undopit - 1);
for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
pit <= end; ++pit) {
Paragraph & par = pars_[pit];
Layout const & layout = *(par.layout());
par.params().apply(p, layout);
}
}
// this really should just insert the inset and not move the cursor.
void Text::insertInset(Cursor & cur, Inset * inset)
{

View File

@ -690,6 +690,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break;
}
// TODO
// With the creation of LFUN_PARAGRAPH_PARAMS, this is now redundant,
// as its duties can be performed there. Should it be removed??
// FIXME For now, it can just dispatch LFUN_PARAGRAPH_PARAMS...
case LFUN_PARAGRAPH_SPACING: {
Paragraph & par = cur.paragraph();
Spacing::Space cur_spacing = par.params().spacing().getSpace();
@ -1531,7 +1535,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
setLayout(cur, tclass.defaultLayoutName());
setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
ParagraphParameters p;
setParagraphs(cur, p);
insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
cur.posRight();
} else {
@ -1569,17 +1574,21 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_PARAGRAPH_PARAMS_APPLY: {
// Given data, an encoding of the ParagraphParameters
// generated in the Paragraph dialog, this function sets
// the current paragraph appropriately.
istringstream is(to_utf8(cmd.argument()));
Lexer lex(0, 0);
lex.setStream(is);
ParagraphParameters params;
params.read(lex);
setParagraph(cur,
params.spacing(),
params.align(),
params.labelWidthString(),
params.noindent());
// the current paragraph, or currently selected paragraphs,
// appropriately.
// NOTE: This function overrides all existing settings.
setParagraphs(cur, cmd.argument());
cur.message(_("Paragraph layout set"));
break;
}
case LFUN_PARAGRAPH_PARAMS: {
// Given data, an encoding of the ParagraphParameters as we'd
// find them in a LyX file, this function modifies the current paragraph,
// or currently selected paragraphs.
// NOTE: This function only modifies, and does not override, existing
// settings.
setParagraphs(cur, cmd.argument(), true);
cur.message(_("Paragraph layout set"));
break;
}
@ -1997,6 +2006,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_ACCENT_OGONEK:
case LFUN_THESAURUS_ENTRY:
case LFUN_PARAGRAPH_PARAMS_APPLY:
case LFUN_PARAGRAPH_PARAMS:
case LFUN_ESCAPE:
case LFUN_BUFFER_END:
case LFUN_BUFFER_BEGIN:

View File

@ -349,6 +349,7 @@ bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_URL_INSERT:
case LFUN_FLOAT_LIST:
case LFUN_INSET_INSERT:
case LFUN_PARAGRAPH_PARAMS:
case LFUN_PARAGRAPH_PARAMS_APPLY:
case LFUN_PARAGRAPH_UPDATE:
case LFUN_NOMENCL_INSERT:

View File

@ -379,6 +379,8 @@ enum kb_action {
LFUN_LISTING_INSERT, // Herbert 20011110, bpeng 20070502
LFUN_TOOLBAR_TOGGLE, // Edwin 20070521
LFUN_BUFFER_WRITE_ALL, // rgh, gpothier 200707XX
//290
LFUN_PARAGRAPH_PARAMS, // rgh, 200708XX
LFUN_LASTACTION // end of the table
};