mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Allow semantic colors in branches and use semantic background color by default
Addresses most crucial part of #12075 File format change
This commit is contained in:
parent
ec387b6d65
commit
057753dc75
@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
|
||||
|
||||
-----------------------
|
||||
|
||||
2021-01-17 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 602: Allow semantic branch colors
|
||||
\color can now also take lyx names besides hexnames.
|
||||
|
||||
2021-01-05 Richard Kimberly Heck <rikiheck@lyx.org>
|
||||
* Format incremented to 601: Add refstyle support for mathed
|
||||
Use 'formatted' in the LyX file to indicate formatted references,
|
||||
|
@ -4025,7 +4025,47 @@ def revert_math_refs(document):
|
||||
if "\\labelonly" in document.body[i]:
|
||||
document.body[i] = re.sub("\\\\labelonly{([^}]+?)}", "\\1", document.body[i])
|
||||
i += 1
|
||||
|
||||
|
||||
|
||||
def convert_branch_colors(document):
|
||||
" Convert branch colors to semantic values "
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
i = find_token(document.header, "\\branch", i)
|
||||
if i == -1:
|
||||
break
|
||||
j = find_token(document.header, "\\end_branch", i)
|
||||
if j == -1:
|
||||
document.warning("Malformed LyX document. Can't find end of branch definition!")
|
||||
break
|
||||
# We only support the standard LyX background for now
|
||||
k = find_token(document.header, "\\color #faf0e6", i, j)
|
||||
if k != -1:
|
||||
document.header[k] = "\\color background"
|
||||
i += 1
|
||||
|
||||
|
||||
def revert_branch_colors(document):
|
||||
" Revert semantic branch colors "
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
i = find_token(document.header, "\\branch", i)
|
||||
if i == -1:
|
||||
break
|
||||
j = find_token(document.header, "\\end_branch", i)
|
||||
if j == -1:
|
||||
document.warning("Malformed LyX document. Can't find end of branch definition!")
|
||||
break
|
||||
k = find_token(document.header, "\\color", i, j)
|
||||
if k != -1:
|
||||
bcolor = get_value(document.header, "\\color", k)
|
||||
if bcolor[1] != "#":
|
||||
# this will be read as background by LyX 2.3
|
||||
document.header[k] = "\\color none"
|
||||
i += 1
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
@ -4089,10 +4129,13 @@ convert = [
|
||||
[598, []],
|
||||
[599, []],
|
||||
[600, []],
|
||||
[601, [convert_math_refs]]
|
||||
[601, [convert_math_refs]],
|
||||
[602, [convert_branch_colors]]
|
||||
]
|
||||
|
||||
revert = [[599, [revert_math_refs]],
|
||||
revert = [[601, [revert_branch_colors]],
|
||||
[600, []],
|
||||
[599, [revert_math_refs]],
|
||||
[598, [revert_hrquotes]],
|
||||
[598, [revert_nopagebreak]],
|
||||
[597, [revert_docbook_table_output]],
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "BranchList.h"
|
||||
#include "Color.h"
|
||||
#include "ColorSet.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
@ -28,11 +29,7 @@ namespace lyx {
|
||||
Branch::Branch()
|
||||
: selected_(false), filenameSuffix_(false)
|
||||
{
|
||||
// no theApp() with command line export
|
||||
if (theApp())
|
||||
theApp()->getRgbColor(Color_background, color_);
|
||||
else
|
||||
frontend::Application::getRgbColorUncached(Color_background, color_);
|
||||
color_ = "background";
|
||||
}
|
||||
|
||||
|
||||
@ -75,30 +72,15 @@ void Branch::setFileNameSuffix(bool b)
|
||||
}
|
||||
|
||||
|
||||
RGBColor const & Branch::color() const
|
||||
string const & Branch::color() const
|
||||
{
|
||||
return color_;
|
||||
}
|
||||
|
||||
|
||||
void Branch::setColor(RGBColor const & c)
|
||||
{
|
||||
color_ = c;
|
||||
}
|
||||
|
||||
|
||||
void Branch::setColor(string const & str)
|
||||
{
|
||||
if (str.size() == 7 && str[0] == '#')
|
||||
color_ = rgbFromHexName(str);
|
||||
else {
|
||||
// no color set or invalid color - use normal background
|
||||
// no theApp() with command line export
|
||||
if (theApp())
|
||||
theApp()->getRgbColor(Color_background, color_);
|
||||
else
|
||||
frontend::Application::getRgbColorUncached(Color_background, color_);
|
||||
}
|
||||
color_ = str;
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,9 +61,7 @@ public:
|
||||
/// Select/deselect filename suffix property.
|
||||
void setFileNameSuffix(bool);
|
||||
///
|
||||
RGBColor const & color() const;
|
||||
///
|
||||
void setColor(RGBColor const &);
|
||||
std::string const & color() const;
|
||||
/**
|
||||
* Set color from a string "#rrggbb".
|
||||
* Use Color:background if the string is no valid color.
|
||||
@ -80,7 +78,7 @@ private:
|
||||
///
|
||||
bool filenameSuffix_;
|
||||
///
|
||||
RGBColor color_;
|
||||
std::string color_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "BufferParams.h"
|
||||
#include "Bullet.h"
|
||||
#include "Chktex.h"
|
||||
#include "ColorSet.h"
|
||||
#include "Converter.h"
|
||||
#include "Counters.h"
|
||||
#include "Cursor.h"
|
||||
@ -2938,7 +2939,12 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
|
||||
undo().recordUndoBufferParams(CursorData());
|
||||
branch_list.add(branch_name);
|
||||
branch = branch_list.find(branch_name);
|
||||
string const x11hexname = X11hexname(branch->color());
|
||||
string x11hexname;
|
||||
string const bcolor = branch->color();
|
||||
if (bcolor.size() == 7 && bcolor[0] == '#')
|
||||
x11hexname = bcolor;
|
||||
else
|
||||
x11hexname = lcolor.getX11HexName(lcolor.getFromLyXName(bcolor));
|
||||
docstring const str = branch_name + ' ' + from_ascii(x11hexname);
|
||||
lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str));
|
||||
dr.setError(false);
|
||||
|
@ -991,11 +991,16 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
if (tok == "\\color") {
|
||||
lex.eatLine();
|
||||
string color = lex.getString();
|
||||
if (branch_ptr)
|
||||
if (branch_ptr) {
|
||||
branch_ptr->setColor(color);
|
||||
if (branch_ptr->color() == "none")
|
||||
color = lcolor.getX11HexName(Color_background);
|
||||
}
|
||||
// Update also the Color table:
|
||||
if (color == "none")
|
||||
color = lcolor.getX11HexName(Color_background);
|
||||
else if (color.size() != 7 || color[0] != '#')
|
||||
color = lcolor.getFromLyXName(color);
|
||||
// FIXME UNICODE
|
||||
lcolor.setColor(to_utf8(branch), color);
|
||||
}
|
||||
@ -1387,7 +1392,7 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
|
||||
os << "\\branch " << to_utf8(br.branch())
|
||||
<< "\n\\selected " << br.isSelected()
|
||||
<< "\n\\filename_suffix " << br.hasFileNameSuffix()
|
||||
<< "\n\\color " << lyx::X11hexname(br.color())
|
||||
<< "\n\\color " << br.color()
|
||||
<< "\n\\end_branch"
|
||||
<< "\n";
|
||||
}
|
||||
|
@ -134,7 +134,13 @@ void GuiBranches::updateView()
|
||||
newItem->setText(0, bname);
|
||||
newItem->setText(1, it->isSelected() ? qt_("Yes") : qt_("No"));
|
||||
|
||||
QColor const itemcolor = rgb2qcolor(it->color());
|
||||
std::string bcolor = it->color();
|
||||
RGBColor rgbcol;
|
||||
if (bcolor.size() == 7 && bcolor[0] == '#')
|
||||
rgbcol = lyx::rgbFromHexName(bcolor);
|
||||
else
|
||||
guiApp->getRgbColor(lcolor.getFromLyXName(bcolor), rgbcol);
|
||||
QColor const itemcolor = rgb2qcolor(rgbcol);
|
||||
if (itemcolor.isValid()) {
|
||||
QPixmap coloritem(30, 10);
|
||||
coloritem.fill(itemcolor);
|
||||
@ -153,6 +159,7 @@ void GuiBranches::updateView()
|
||||
removePB->setEnabled(have_sel);
|
||||
renamePB->setEnabled(have_sel);
|
||||
colorPB->setEnabled(have_sel);
|
||||
resetColorPB->setEnabled(have_sel);
|
||||
activatePB->setEnabled(have_sel);
|
||||
suffixPB->setEnabled(have_sel);
|
||||
// emit signal
|
||||
@ -264,6 +271,7 @@ void GuiBranches::on_branchesTW_itemSelectionChanged()
|
||||
removePB->setEnabled(have_sel);
|
||||
renamePB->setEnabled(have_sel);
|
||||
colorPB->setEnabled(have_sel);
|
||||
resetColorPB->setEnabled(have_sel);
|
||||
activatePB->setEnabled(have_sel);
|
||||
suffixPB->setEnabled(have_sel);
|
||||
}
|
||||
@ -292,6 +300,26 @@ void GuiBranches::on_colorPB_clicked()
|
||||
}
|
||||
|
||||
|
||||
void GuiBranches::on_resetColorPB_clicked()
|
||||
{
|
||||
QTreeWidgetItem * item = branchesTW->currentItem();
|
||||
if (item == 0)
|
||||
return;
|
||||
|
||||
QString sel_branch = item->text(0);
|
||||
if (sel_branch.isEmpty())
|
||||
return;
|
||||
|
||||
docstring current_branch = qstring_to_ucs4(sel_branch);
|
||||
Branch * branch = branchlist_.find(current_branch);
|
||||
if (!branch)
|
||||
return;
|
||||
branch->setColor("background");
|
||||
newBranchLE->clear();
|
||||
updateView();
|
||||
}
|
||||
|
||||
|
||||
void GuiBranches::toggleColor(QTreeWidgetItem * item)
|
||||
{
|
||||
if (item == 0)
|
||||
@ -306,7 +334,13 @@ void GuiBranches::toggleColor(QTreeWidgetItem * item)
|
||||
if (!branch)
|
||||
return;
|
||||
|
||||
QColor const initial = rgb2qcolor(branch->color());
|
||||
std::string bcolor = branch->color();
|
||||
RGBColor rgbcol;
|
||||
if (bcolor.size() == 7 && bcolor[0] == '#')
|
||||
rgbcol = lyx::rgbFromHexName(bcolor);
|
||||
else
|
||||
guiApp->getRgbColor(lcolor.getFromLyXName(bcolor), rgbcol);
|
||||
QColor const initial = rgb2qcolor(rgbcol);
|
||||
QColor ncol = QColorDialog::getColor(initial, qApp->focusWidget());
|
||||
if (!ncol.isValid())
|
||||
return;
|
||||
|
@ -71,6 +71,7 @@ protected Q_SLOTS:
|
||||
void on_branchesTW_itemDoubleClicked(QTreeWidgetItem *, int);
|
||||
void on_branchesTW_itemSelectionChanged();
|
||||
void on_colorPB_clicked();
|
||||
void on_resetColorPB_clicked();
|
||||
void on_suffixPB_pressed();
|
||||
void on_unknownPB_pressed();
|
||||
void addUnknown();
|
||||
|
@ -5008,7 +5008,13 @@ void GuiDocument::dispatchParams()
|
||||
for (; it != end; ++it) {
|
||||
docstring const & current_branch = it->branch();
|
||||
Branch const * branch = branchlist.find(current_branch);
|
||||
string const x11hexname = X11hexname(branch->color());
|
||||
string const bcolor = branch->color();
|
||||
RGBColor rgbcol;
|
||||
if (bcolor.size() == 7 && bcolor[0] == '#')
|
||||
rgbcol = lyx::rgbFromHexName(bcolor);
|
||||
else
|
||||
guiApp->getRgbColor(lcolor.getFromLyXName(bcolor), rgbcol);
|
||||
string const x11hexname = X11hexname(rgbcol);
|
||||
// display the new color
|
||||
docstring const str = current_branch + ' ' + from_ascii(x11hexname);
|
||||
dispatch(FuncRequest(LFUN_SET_COLOR, str));
|
||||
|
@ -1,53 +1,53 @@
|
||||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BranchesUi</class>
|
||||
<widget class="QWidget" name="BranchesUi" >
|
||||
<property name="geometry" >
|
||||
<widget class="QWidget" name="BranchesUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>401</width>
|
||||
<height>327</height>
|
||||
<height>346</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<layout class="QGridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="newBranchLA" >
|
||||
<property name="text" >
|
||||
<string>&New:[[branch]]</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>newBranchLE</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="3" >
|
||||
<widget class="QPushButton" name="suffixPB" >
|
||||
<property name="toolTip" >
|
||||
<item row="6" column="3">
|
||||
<widget class="QPushButton" name="suffixPB">
|
||||
<property name="toolTip">
|
||||
<string>Append the name of this branch to the output filename, given the branch is active.</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<property name="text">
|
||||
<string>Filename &Suffix</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="3" >
|
||||
<item row="7" column="3">
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>83</width>
|
||||
<height>51</height>
|
||||
@ -55,22 +55,107 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="8" column="2" colspan="2" >
|
||||
<widget class="QPushButton" name="unknownPB" >
|
||||
<property name="toolTip" >
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QLabel" name="availableLB">
|
||||
<property name="text">
|
||||
<string>A&vailable Branches:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>branchesTW</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="removePB">
|
||||
<property name="toolTip">
|
||||
<string>Remove the selected branch</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="unknownPB">
|
||||
<property name="toolTip">
|
||||
<string>Show undefined branches used in this document.</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<property name="text">
|
||||
<string>&Undefined Branches</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2" >
|
||||
<item row="2" column="0" rowspan="7" colspan="3">
|
||||
<widget class="QTreeWidget" name="branchesTW">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="3">
|
||||
<widget class="QPushButton" name="activatePB">
|
||||
<property name="toolTip">
|
||||
<string>Toggle the selected branch</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>(&De)activate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="addBranchPB">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add a new branch to the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QPushButton" name="colorPB">
|
||||
<property name="toolTip">
|
||||
<string>Define or change background color</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Alter Co&lor...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QPushButton" name="renamePB">
|
||||
<property name="toolTip">
|
||||
<string>Change the name of the selected branch</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Re&name...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="newBranchLA">
|
||||
<property name="text">
|
||||
<string>&New:[[branch]]</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>newBranchLE</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="newBranchLE"/>
|
||||
</item>
|
||||
<item row="9" column="0" colspan="2">
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>251</width>
|
||||
<height>20</height>
|
||||
@ -78,72 +163,13 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3" >
|
||||
<widget class="QLabel" name="availableLB" >
|
||||
<property name="text" >
|
||||
<string>A&vailable Branches:</string>
|
||||
<item row="5" column="3">
|
||||
<widget class="QPushButton" name="resetColorPB">
|
||||
<property name="statusTip">
|
||||
<string>Reset branch color to default (standard background)</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>branchesTW</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="3" >
|
||||
<widget class="QPushButton" name="activatePB" >
|
||||
<property name="toolTip" >
|
||||
<string>Toggle the selected branch</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>(&De)activate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item rowspan="6" row="2" column="0" colspan="3" >
|
||||
<widget class="QTreeWidget" name="branchesTW" />
|
||||
</item>
|
||||
<item row="0" column="3" >
|
||||
<widget class="QPushButton" name="addBranchPB" >
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Add a new branch to the list</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2" >
|
||||
<widget class="QLineEdit" name="newBranchLE" />
|
||||
</item>
|
||||
<item row="4" column="3" >
|
||||
<widget class="QPushButton" name="colorPB" >
|
||||
<property name="toolTip" >
|
||||
<string>Define or change background color</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Alter Co&lor...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3" >
|
||||
<widget class="QPushButton" name="removePB" >
|
||||
<property name="toolTip" >
|
||||
<string>Remove the selected branch</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>&Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3" >
|
||||
<widget class="QPushButton" name="renamePB" >
|
||||
<property name="toolTip" >
|
||||
<string>Change the name of the selected branch</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Re&name...</string>
|
||||
<property name="text">
|
||||
<string>R&eset Color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -161,7 +187,7 @@
|
||||
<tabstop>unknownPB</tabstop>
|
||||
</tabstops>
|
||||
<includes>
|
||||
<include location="local" >qt_i18n.h</include>
|
||||
<include location="local">qt_i18n.h</include>
|
||||
</includes>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// independent branches. Instead add your own.
|
||||
#define LYX_FORMAT_LYX 601 // rkh: refstyle in math
|
||||
#define LYX_FORMAT_TEX2LYX 601
|
||||
#define LYX_FORMAT_LYX 602 // spitz: semantic branch colors
|
||||
#define LYX_FORMAT_TEX2LYX 602
|
||||
|
||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||
#ifndef _MSC_VER
|
||||
|
Loading…
Reference in New Issue
Block a user