Add mechanism to change icons in RTL mode

When the cursor in RTL text, icons for "depth-increment" or
"layout-toggle Enumerate" look wrong.

To fix this, the lfun "bidi" is introduced. "bidi ltr func" behaves
like "func" in LTR text, but is unknown in RTL text. "bidi rtl" does
the opposite. This allows to add two icons, but only have one icon
available. When no document is available, only LTR is assumed.

To make this work, the handling of unknown functions in toolbar has
been changed so this these functions can change dynamically their
existence.

The icon themes `default', `oxygen' and `classic' have been updated
accordingly.

Fixes bug #4451.
This commit is contained in:
Jean-Marc Lasgouttes 2019-07-22 01:20:30 +02:00
parent 3f0e27e169
commit 2898c335be
49 changed files with 106 additions and 10 deletions

View File

@ -516,6 +516,20 @@ dist_images_DATA1X = \
images/all-changes-accept.svgz \
images/all-changes-reject.svgz \
images/banner.svgz \
images/bidi_ltr_depth-decrement.svgz \
images/bidi_ltr_depth-increment.svgz \
images/bidi_ltr_layout-toggle_Description.svgz \
images/bidi_ltr_layout-toggle_Enumerate.svgz \
images/bidi_ltr_layout-toggle_Itemize.svgz \
images/bidi_ltr_layout-toggle_List.svgz \
images/bidi_ltr_layout-toggle_Section.svgz \
images/bidi_rtl_depth-decrement.svgz \
images/bidi_rtl_depth-increment.svgz \
images/bidi_rtl_layout-toggle_Description.svgz \
images/bidi_rtl_layout-toggle_Enumerate.svgz \
images/bidi_rtl_layout-toggle_Itemize.svgz \
images/bidi_rtl_layout-toggle_List.svgz \
images/bidi_rtl_layout-toggle_Section.svgz \
images/bookmark-goto.svgz \
images/bookmark-goto_0.svgz \
images/bookmark-save.svgz \
@ -1802,6 +1816,20 @@ imagesoxygendir = $(imagesdir)/oxygen
dist_imagesoxygen_DATA1X = \
images/oxygen/all-changes-accept.svgz \
images/oxygen/all-changes-reject.svgz \
images/oxygen/bidi_ltr_depth-decrement.svgz \
images/oxygen/bidi_ltr_depth-increment.svgz \
images/oxygen/bidi_ltr_layout-toggle_Description.svgz \
images/oxygen/bidi_ltr_layout-toggle_Enumerate.svgz \
images/oxygen/bidi_ltr_layout-toggle_Itemize.svgz \
images/oxygen/bidi_ltr_layout-toggle_List.svgz \
images/oxygen/bidi_ltr_layout-toggle_Section.svgz \
images/oxygen/bidi_rtl_depth-decrement.svgz \
images/oxygen/bidi_rtl_depth-increment.svgz \
images/oxygen/bidi_rtl_layout-toggle_Description.svgz \
images/oxygen/bidi_rtl_layout-toggle_Enumerate.svgz \
images/oxygen/bidi_rtl_layout-toggle_Itemize.svgz \
images/oxygen/bidi_rtl_layout-toggle_List.svgz \
images/oxygen/bidi_rtl_layout-toggle_Section.svgz \
images/oxygen/bookmark-goto.svgz \
images/oxygen/bookmark-goto_0.svgz \
images/oxygen/bookmark-save.svgz \
@ -2005,6 +2033,20 @@ imagesclassicdir = $(imagesdir)/classic
dist_imagesclassic_DATA = \
images/classic/all-changes-accept.png \
images/classic/all-changes-reject.png \
images/classic/bidi_ltr_depth-decrement.png \
images/classic/bidi_ltr_depth-increment.png \
images/classic/bidi_ltr_layout-toggle_Description.png \
images/classic/bidi_ltr_layout-toggle_Enumerate.png \
images/classic/bidi_ltr_layout-toggle_Itemize.png \
images/classic/bidi_ltr_layout-toggle_List.png \
images/classic/bidi_ltr_layout-toggle_Section.png \
images/classic/bidi_rtl_depth-decrement.png \
images/classic/bidi_rtl_depth-increment.png \
images/classic/bidi_rtl_layout-toggle_Description.png \
images/classic/bidi_rtl_layout-toggle_Enumerate.png \
images/classic/bidi_rtl_layout-toggle_Itemize.png \
images/classic/bidi_rtl_layout-toggle_List.png \
images/classic/bidi_rtl_layout-toggle_Section.png \
images/classic/bookmark-goto.png \
images/classic/bookmark-goto_0.png \
images/classic/bookmark-save.png \

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -113,12 +113,20 @@ ToolbarSet
Toolbar "extra" "Extra"
Item "Default" "layout"
Item "Numbered list" "layout-toggle Enumerate"
Item "Itemized list" "layout-toggle Itemize"
Item "List" "layout-toggle List"
Item "Description" "layout-toggle Description"
Item "Increase depth" "depth-increment"
Item "Decrease depth" "depth-decrement"
# The bidi function is used here to select a different
# icon depending on the direction of the current text.
Item "Numbered list" "bidi ltr layout-toggle Enumerate"
Item "Numbered list" "bidi rtl layout-toggle Enumerate"
Item "Itemized list" "bidi ltr layout-toggle Itemize"
Item "Itemized list" "bidi rtl layout-toggle Itemize"
Item "List" "bidi ltr layout-toggle List"
Item "List" "bidi rtl layout-toggle List"
Item "Description" "bidi ltr layout-toggle Description"
Item "Description" "bidi rtl layout-toggle Description"
Item "Increase depth" "bidi ltr depth-increment"
Item "Increase depth" "bidi rtl depth-increment"
Item "Decrease depth" "bidi ltr depth-decrement"
Item "Decrease depth" "bidi rtl depth-decrement"
Separator
Item "Insert figure float" "float-insert figure"
Item "Insert table float" "float-insert table"

View File

@ -485,6 +485,7 @@ enum FuncCode
LFUN_BUFFER_WRITE_AS_TEMPLATE, // spitz, 20190323
LFUN_TABULAR_STYLE_INSERT, // spitz, 20190325
LFUN_PARAGRAPH_SELECT, // Kornel, 20190416
LFUN_BIDI,
LFUN_LASTACTION // end of the table
};

View File

@ -332,6 +332,20 @@ void LyXAction::init()
{ LFUN_BIBTEX_DATABASE_DEL, "bibtex-database-del", Noop, Edit },
/*!
* \var lyx::FuncCode lyx::LFUN_BIDI
* \li Action: Helper function for bidirectional toolbar icons
* \li Notion: In a text, the function is marked as `unknown' when the
current direction does not correspond to DIRECTION (ltr
or rtl). Otherwise the function behaves exactly as
ACTION. The result is that ACTION will be associated to
a different icon depending on text direction.
* \li Syntax: bidi <DIRECTION> <ACTION>
* \li Origin: JMarc, 21 July 2019
* \endvar
*/
{ LFUN_BIDI, "bidi", Noop, System },
/*!
* \var lyx::FuncCode lyx::LFUN_BOOKMARK_CLEAR
* \li Action: Clears the list of saved bookmarks.

View File

@ -76,6 +76,7 @@ void Action::update()
setCheckable(false);
}
setVisible(!status.unknown());
setEnabled(status.enabled());
}

View File

@ -70,11 +70,11 @@
#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h" // sorted
#include "support/textutils.h"
#include "support/Messages.h"
#include "support/os.h"
#include "support/Package.h"
#include "support/TempFile.h"
#include "support/textutils.h"
#ifdef Q_OS_MAC
#include "support/AppleScript.h"
@ -928,7 +928,7 @@ public:
struct GuiApplication::Private
{
Private(): language_model_(0), meta_fake_bit(NoModifier),
global_menubar_(0)
global_menubar_(0)
{
#if (QT_VERSION < 0x050000) || (QT_VERSION >= 0x050400)
#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
@ -1292,6 +1292,24 @@ bool GuiApplication::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
break;
}
case LFUN_BIDI: {
string const dir = cmd.getArg(0);
string const lfun = cmd.getLongArg(1);
BufferView const * bv =
current_view_ ? current_view_->currentBufferView() : nullptr;
bool rtl = bv ? bv->cursor().innerParagraph().isRTL(bv->buffer().params())
: layoutDirection() == Qt::RightToLeft;
if (((rtl && dir != "rtl") || (!rtl && dir != "ltr"))) {
flag.setUnknown(true);
flag.setEnabled(false);
} else {
FuncRequest func(lyxaction.lookupFunc(lfun));
func.setOrigin(cmd.origin());
flag = getStatus(func);
}
break;
}
case LFUN_CURSOR_FOLLOWS_SCROLLBAR_TOGGLE:
case LFUN_REPEAT:
case LFUN_PREFERENCES_SAVE:
@ -1869,6 +1887,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
break;
// --- syntax commands ----------------------------
case LFUN_REPEAT: {
// repeat command
string countstr;
@ -2020,6 +2039,18 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break;
}
case LFUN_BIDI: {
string const lfun = cmd.getLongArg(1);
FuncRequest func(lyxaction.lookupFunc(cmd.getLongArg(1)));
func.setOrigin(cmd.origin());
FuncStatus const stat = getStatus(func);
if (stat.enabled()) {
dispatch(func);
break;
}
break;
}
case LFUN_PREFERENCES_SAVE:
lyxrc.write(support::makeAbsPath("preferences",
package().user_support().absFileName()), false);

View File

@ -519,8 +519,7 @@ void GuiToolbar::add(ToolbarItem const & item)
break;
}
case ToolbarItem::COMMAND: {
if (!getStatus(*item.func_).unknown())
addAction(addItem(item));
addAction(addItem(item));
break;
}
default: