Replace Type combo, which was considered irritating, with a Type filter

The new one allows to display only user or system files.
This commit is contained in:
Juergen Spitzmueller 2019-03-21 19:23:33 +01:00
parent e170051909
commit 7403fd2f88
3 changed files with 100 additions and 86 deletions

View File

@ -39,8 +39,9 @@ namespace lyx {
namespace frontend {
void GuiLyXFiles::getFiles(QMap<QString, QString> & in, QString const type)
QMap<QString, QString> GuiLyXFiles::getFiles()
{
QMap<QString, QString> result;
// We look for lyx files in the subdirectory dir of
// 1) user_lyxdir
// 2) build_lyxdir (if not empty)
@ -52,16 +53,20 @@ void GuiLyXFiles::getFiles(QMap<QString, QString> & in, QString const type)
QStringList relpaths;
// The three locations to look at.
string const user = addPath(package().user_support().absFileName(), fromqstr(type));
string const build = addPath(package().build_support().absFileName(), fromqstr(type));
string const system = addPath(package().system_support().absFileName(), fromqstr(type));
string const user = addPath(package().user_support().absFileName(), fromqstr(type_));
string const build = addPath(package().build_support().absFileName(), fromqstr(type_));
string const system = addPath(package().system_support().absFileName(), fromqstr(type_));
available_languages_.insert(toqstr("en"), qt_("English"));
// Search in the base path
dirs << toqstr(user)
<< toqstr(build)
<< toqstr(system);
QString const type = fileTypeCO->itemData(fileTypeCO->currentIndex()).toString();
// Search in the base paths
if (type == "all" || type == "user")
dirs << toqstr(user);
if (type == "all" || type == "system")
dirs << toqstr(build)
<< toqstr(system);
for (int i = 0; i < dirs.size(); ++i) {
QString const dir = dirs.at(i);
@ -103,7 +108,7 @@ void GuiLyXFiles::getFiles(QMap<QString, QString> & in, QString const type)
if (localization != "en")
// strip off lang/
relpath = relpath.mid(relpath.indexOf('/') + 1);
in.insert(relpath, cat);
result.insert(relpath, cat);
QMap<QString, QString> lm;
if (localizations_.contains(relpath))
@ -139,6 +144,7 @@ void GuiLyXFiles::getFiles(QMap<QString, QString> & in, QString const type)
}
setLanguage();
languageLA->setText(qt_("Preferred &Language:"));
return result;
}
@ -210,6 +216,12 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
//filesLW->setViewMode(QListView::ListMode);
filesLW->setIconSize(QSize(22, 22));
QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
fileTypeCO->addItem(qt_("User and System Files"), toqstr("all"));
fileTypeCO->addItem(user_icon, qt_("User Files Only"), toqstr("user"));
fileTypeCO->addItem(system_icon, qt_("System Files Only"), toqstr("system"));
setFocusProxy(filter_);
}
@ -342,10 +354,8 @@ void GuiLyXFiles::on_browsePB_pressed()
void GuiLyXFiles::updateContents()
{
QString type = fileTypeCO->itemData(fileTypeCO->currentIndex()).toString();
QMap<QString, QString> files;
languageCO->clear();
getFiles(files, type);
QMap<QString, QString> files = getFiles();
languageCO->model()->sort(0);
filesLW->clear();
@ -494,20 +504,6 @@ bool GuiLyXFiles::initialiseParams(string const & type)
void GuiLyXFiles::paramsToDialog()
{
fileTypeCO->clear();
if (type_ == "examples" || type_ == "templates") {
fileTypeCO->addItem(qt_("Templates"), toqstr("templates"));
fileTypeCO->addItem(qt_("Examples"), toqstr("examples"));
} else if (type_ == "ui")
fileTypeCO->addItem(qt_("User Interface Files"), toqstr("ui"));
else if (type_ == "bind")
fileTypeCO->addItem(qt_("Key Binding Files"), toqstr("bind"));
if (!type_.isEmpty()) {
int i = fileTypeCO->findData(type_);
if (i != -1)
fileTypeCO->setCurrentIndex(i);
}
if (type_ == "examples")
setTitle(qt_("Open Example File"));
else if (type_ == "templates")

View File

@ -69,7 +69,7 @@ private:
///
bool translateName() const;
///
void getFiles(QMap<QString, QString> &, QString const);
QMap<QString, QString> getFiles();
/// Get the full file path in the selected localization
QString const getRealPath(QString relpath = QString());
///

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>381</width>
<height>474</height>
<width>284</width>
<height>479</height>
</rect>
</property>
<property name="windowTitle">
@ -18,28 +18,71 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="filesTypeLA">
<property name="text">
<string>&amp;Type:</string>
</property>
<property name="buddy">
<cstring>fileTypeCO</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="fileTypeCO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="filterGB">
<property name="title">
<string>Filter</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="filesTypeLA">
<property name="text">
<string>&amp;Type:</string>
</property>
<property name="buddy">
<cstring>fileTypeCO</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="fileTypeCO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Determines whether only personal user files, system files or all files are displayed</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="findKeysLA">
<property name="text">
<string>&amp;Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QHBoxLayout" name="filterBarL"/>
</item>
<item>
<widget class="QCheckBox" name="csFindCB">
<property name="toolTip">
<string>Filter case-sensitively</string>
</property>
<property name="text">
<string>Case Sensiti&amp;ve</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="languageLA">
<property name="toolTip">
<string/>
@ -52,47 +95,22 @@
</property>
</widget>
</item>
<item row="1" column="2">
<item>
<widget class="QComboBox" name="languageCO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The available language(s) of the selected file will be displayed here</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="findKeysLA">
<property name="text">
<string>&amp;Filter:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QHBoxLayout" name="filterBarL"/>
</item>
<item>
<widget class="QCheckBox" name="csFindCB">
<property name="toolTip">
<string>Filter case-sensitively</string>
</property>
<property name="text">
<string>Case Sensiti&amp;ve</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QTreeWidget" name="filesLW">
<property name="rootIsDecorated">
<bool>true</bool>
@ -110,7 +128,7 @@
</column>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
@ -134,7 +152,7 @@
</item>
</layout>
</item>
<item row="3" column="0">
<item row="4" column="0">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>