mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-06 11:23:45 +00:00
GuiBibTeX: introduce way to toggle between absolute and relative local paths (#13097)
This commit is contained in:
parent
b7e4cc9a37
commit
124f441a00
@ -91,6 +91,8 @@ GuiBibtex::GuiBibtex(GuiView & lv)
|
|||||||
this, SLOT(browseBibPressed()));
|
this, SLOT(browseBibPressed()));
|
||||||
connect(inheritPB, SIGNAL(clicked()),
|
connect(inheritPB, SIGNAL(clicked()),
|
||||||
this, SLOT(inheritPressed()));
|
this, SLOT(inheritPressed()));
|
||||||
|
connect(relAbsPB, SIGNAL(clicked()),
|
||||||
|
this, SLOT(relAbsPressed()));
|
||||||
|
|
||||||
selected_model_.insertColumns(0, 1);
|
selected_model_.insertColumns(0, 1);
|
||||||
selectionManager = new GuiSelectionManager(this, availableLV, selectedLV,
|
selectionManager = new GuiSelectionManager(this, availableLV, selectedLV,
|
||||||
@ -123,6 +125,7 @@ GuiBibtex::GuiBibtex(GuiView & lv)
|
|||||||
bc().addReadOnly(styleCB);
|
bc().addReadOnly(styleCB);
|
||||||
bc().addReadOnly(bibtocCB);
|
bc().addReadOnly(bibtocCB);
|
||||||
bc().addReadOnly(bibEncodingCO);
|
bc().addReadOnly(bibEncodingCO);
|
||||||
|
bc().addReadOnly(relAbsPB);
|
||||||
|
|
||||||
selectedLV->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
selectedLV->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||||
|
|
||||||
@ -180,6 +183,7 @@ void GuiBibtex::selUpdated()
|
|||||||
{
|
{
|
||||||
selectionManager->update();
|
selectionManager->update();
|
||||||
editPB->setEnabled(deletePB->isEnabled());
|
editPB->setEnabled(deletePB->isEnabled());
|
||||||
|
updateReAbs();
|
||||||
changed();
|
changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +238,23 @@ void GuiBibtex::browseBibPressed()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GuiBibtex::LocalPath GuiBibtex::localPathSelected()
|
||||||
|
{
|
||||||
|
QModelIndexList selIdx =
|
||||||
|
selectedLV->selectionModel()->selectedIndexes();
|
||||||
|
if (selIdx.isEmpty())
|
||||||
|
return LP_None;
|
||||||
|
QModelIndex idx = selIdx.first();
|
||||||
|
QString sel = idx.data().toString();
|
||||||
|
string const texfile = support::changeExtension(fromqstr(sel), "bib");
|
||||||
|
if (FileName::isAbsolute(texfile))
|
||||||
|
return LP_Absolute;
|
||||||
|
FileName const file = support::makeAbsPath(texfile, buffer().filePath());
|
||||||
|
if (file.exists())
|
||||||
|
return LP_Relative;
|
||||||
|
return LP_None;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GuiBibtex::hasInherits()
|
bool GuiBibtex::hasInherits()
|
||||||
{
|
{
|
||||||
@ -278,6 +299,38 @@ void GuiBibtex::inheritPressed()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiBibtex::relAbsPressed()
|
||||||
|
{
|
||||||
|
LocalPath const p = localPathSelected();
|
||||||
|
|
||||||
|
if (p == LP_None)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QModelIndexList selIdx =
|
||||||
|
selectedLV->selectionModel()->selectedIndexes();
|
||||||
|
QModelIndex idx = selIdx.first();
|
||||||
|
QString const qf = idx.data().toString();
|
||||||
|
string f = fromqstr(qf);
|
||||||
|
FileName const file = (p == LP_Absolute) ?
|
||||||
|
FileName(f)
|
||||||
|
: support::makeAbsPath(f, buffer().filePath());
|
||||||
|
QString const new_item = (p == LP_Absolute)
|
||||||
|
? toqstr(file.relPath(buffer().filePath()))
|
||||||
|
: toqstr(file.absoluteFilePath());
|
||||||
|
QStringList sb;
|
||||||
|
for (QString s : selected_bibs_) {
|
||||||
|
if (s == qf)
|
||||||
|
sb << new_item;
|
||||||
|
else
|
||||||
|
sb << s;
|
||||||
|
}
|
||||||
|
selected_bibs_ = sb;
|
||||||
|
setSelectedBibs(selected_bibs_);
|
||||||
|
selectedLV->selectRow(selected_bibs_.indexOf(new_item));
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiBibtex::on_editPB_clicked()
|
void GuiBibtex::on_editPB_clicked()
|
||||||
{
|
{
|
||||||
QModelIndexList selIdx =
|
QModelIndexList selIdx =
|
||||||
@ -305,6 +358,25 @@ void GuiBibtex::clearSelection()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiBibtex::updateReAbs()
|
||||||
|
{
|
||||||
|
switch (localPathSelected()) {
|
||||||
|
case LP_Absolute:
|
||||||
|
relAbsPB->setText(qt_("&Make Relative"));
|
||||||
|
relAbsPB->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case LP_Relative:
|
||||||
|
relAbsPB->setText(qt_("&Make Absolute"));
|
||||||
|
relAbsPB->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case LP_None:
|
||||||
|
default:
|
||||||
|
relAbsPB->setEnabled(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiBibtex::setSelectedBibs(QStringList const & sl)
|
void GuiBibtex::setSelectedBibs(QStringList const & sl)
|
||||||
{
|
{
|
||||||
selected_model_.clear();
|
selected_model_.clear();
|
||||||
@ -349,6 +421,7 @@ void GuiBibtex::setSelectedBibs(QStringList const & sl)
|
|||||||
selectedLV->setIndexWidget(selected_model_.index(i, 1), cb);
|
selectedLV->setIndexWidget(selected_model_.index(i, 1), cb);
|
||||||
}
|
}
|
||||||
editPB->setEnabled(deletePB->isEnabled());
|
editPB->setEnabled(deletePB->isEnabled());
|
||||||
|
updateReAbs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -446,6 +519,7 @@ void GuiBibtex::updateContents()
|
|||||||
|
|
||||||
setFileEncodings(getVectorFromString(params_["file_encodings"], from_ascii("\t")));
|
setFileEncodings(getVectorFromString(params_["file_encodings"], from_ascii("\t")));
|
||||||
editPB->setEnabled(deletePB->isEnabled());
|
editPB->setEnabled(deletePB->isEnabled());
|
||||||
|
updateReAbs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ private Q_SLOTS:
|
|||||||
void on_buttonBox_accepted();
|
void on_buttonBox_accepted();
|
||||||
void browseBstPressed();
|
void browseBstPressed();
|
||||||
void browseBibPressed();
|
void browseBibPressed();
|
||||||
|
void relAbsPressed();
|
||||||
void inheritPressed();
|
void inheritPressed();
|
||||||
void on_editPB_clicked();
|
void on_editPB_clicked();
|
||||||
void databaseChanged();
|
void databaseChanged();
|
||||||
@ -101,6 +102,16 @@ private:
|
|||||||
bool isBufferDependent() const override { return true; }
|
bool isBufferDependent() const override { return true; }
|
||||||
/// Is his a child which can inherit bibs from its master?
|
/// Is his a child which can inherit bibs from its master?
|
||||||
bool hasInherits();
|
bool hasInherits();
|
||||||
|
/// Is an item with local path selected?
|
||||||
|
/// returns which (none, absolute, relative)
|
||||||
|
enum LocalPath {
|
||||||
|
LP_None,
|
||||||
|
LP_Absolute,
|
||||||
|
LP_Relative
|
||||||
|
};
|
||||||
|
LocalPath localPathSelected();
|
||||||
|
///
|
||||||
|
void updateReAbs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
|
@ -85,6 +85,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="relAbsPB">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Transfer an absolute local path to a relative one or vice versa</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>&Make Relative</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="inheritPB">
|
<widget class="QPushButton" name="inheritPB">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
|
Loading…
Reference in New Issue
Block a user