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_MODIFY, "", Noop },
{ LFUN_INSET_DIALOG_UPDATE, "", Noop }, { LFUN_INSET_DIALOG_UPDATE, "", Noop },
{ LFUN_INSET_SETTINGS, "inset-settings", ReadOnly }, { LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
{ LFUN_PARAGRAPH_PARAMS, "paragraph-params", Noop },
{ LFUN_PARAGRAPH_PARAMS_APPLY, "paragraph-params-apply", Noop }, { LFUN_PARAGRAPH_PARAMS_APPLY, "paragraph-params-apply", Noop },
{ LFUN_PARAGRAPH_UPDATE, "", Noop }, { LFUN_PARAGRAPH_UPDATE, "", Noop },
{ LFUN_EXTERNAL_EDIT, "external-edit", Noop }, { LFUN_EXTERNAL_EDIT, "external-edit", Noop },

View File

@ -37,19 +37,12 @@ using std::string;
namespace lyx { namespace lyx {
//NOTE The order of these MUST be the same as in Layout.h.
static char const * const string_align[] = { 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() ParagraphParameters::ParagraphParameters()
: noindent_(false), : noindent_(false),
start_of_appendix_(false), appendix_(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()) { while (lex.isOK()) {
lex.nextToken(); lex.nextToken();
string const token = lex.getString(); string const token = lex.getString();
@ -196,6 +200,12 @@ void ParagraphParameters::read(Lexer & lex)
if (token == "\\noindent") { if (token == "\\noindent") {
noindent(true); 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") { } else if (token == "\\leftindent") {
lex.next(); lex.next();
Length value(lex.getString()); Length value(lex.getString());
@ -205,7 +215,10 @@ void ParagraphParameters::read(Lexer & lex)
} else if (token == "\\paragraph_spacing") { } else if (token == "\\paragraph_spacing") {
lex.next(); lex.next();
string const tmp = rtrim(lex.getString()); 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)); spacing(Spacing(Spacing::Single));
} else if (tmp == "onehalf") { } else if (tmp == "onehalf") {
spacing(Spacing(Spacing::Onehalf)); spacing(Spacing(Spacing::Onehalf));
@ -220,7 +233,7 @@ void ParagraphParameters::read(Lexer & lex)
} }
} else if (token == "\\align") { } else if (token == "\\align") {
lex.next(); lex.next();
int tmpret = findToken(string_align, lex.getString()); int tmpret = support::findToken(string_align, lex.getString());
if (tmpret == -1) if (tmpret == -1)
++tmpret; ++tmpret;
align(LyXAlignment(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 void ParagraphParameters::write(ostream & os) const
{ {
// Maybe the paragraph has special spacing // Maybe the paragraph has special spacing

View File

@ -80,8 +80,17 @@ public:
/// ///
void leftIndent(Length const &); void leftIndent(Length const &);
/// read the parameters from a string
void read (std::string str, bool merge = true);
/// read the parameters from a lex /// 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 /// write out the parameters to a stream
void write(std::ostream & os) const; void write(std::ostream & os) const;

View File

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

View File

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

View File

@ -690,6 +690,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break; 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: { case LFUN_PARAGRAPH_SPACING: {
Paragraph & par = cur.paragraph(); Paragraph & par = cur.paragraph();
Spacing::Space cur_spacing = par.params().spacing().getSpace(); Spacing::Space cur_spacing = par.params().spacing().getSpace();
@ -1531,7 +1535,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
setLayout(cur, tclass.defaultLayoutName()); 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()))); insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
cur.posRight(); cur.posRight();
} else { } else {
@ -1569,17 +1574,21 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_PARAGRAPH_PARAMS_APPLY: { case LFUN_PARAGRAPH_PARAMS_APPLY: {
// Given data, an encoding of the ParagraphParameters // Given data, an encoding of the ParagraphParameters
// generated in the Paragraph dialog, this function sets // generated in the Paragraph dialog, this function sets
// the current paragraph appropriately. // the current paragraph, or currently selected paragraphs,
istringstream is(to_utf8(cmd.argument())); // appropriately.
Lexer lex(0, 0); // NOTE: This function overrides all existing settings.
lex.setStream(is); setParagraphs(cur, cmd.argument());
ParagraphParameters params; cur.message(_("Paragraph layout set"));
params.read(lex); break;
setParagraph(cur, }
params.spacing(),
params.align(), case LFUN_PARAGRAPH_PARAMS: {
params.labelWidthString(), // Given data, an encoding of the ParagraphParameters as we'd
params.noindent()); // 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")); cur.message(_("Paragraph layout set"));
break; break;
} }
@ -1997,6 +2006,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_ACCENT_OGONEK: case LFUN_ACCENT_OGONEK:
case LFUN_THESAURUS_ENTRY: case LFUN_THESAURUS_ENTRY:
case LFUN_PARAGRAPH_PARAMS_APPLY: case LFUN_PARAGRAPH_PARAMS_APPLY:
case LFUN_PARAGRAPH_PARAMS:
case LFUN_ESCAPE: case LFUN_ESCAPE:
case LFUN_BUFFER_END: case LFUN_BUFFER_END:
case LFUN_BUFFER_BEGIN: case LFUN_BUFFER_BEGIN:

View File

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

View File

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