From cf8355990650f463a3f517aa2472592cc0913791 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 22 Mar 2019 14:11:46 +0100 Subject: [PATCH] Use GuiLyXFiles also for ui, kbd and bind files in prefs --- src/frontends/qt4/GuiLyXFiles.cpp | 69 +++++++++++++++++---- src/frontends/qt4/GuiLyXFiles.h | 6 ++ src/frontends/qt4/GuiPrefs.cpp | 99 ++++++++++++++++--------------- src/frontends/qt4/GuiPrefs.h | 15 ++++- 4 files changed, 126 insertions(+), 63 deletions(-) diff --git a/src/frontends/qt4/GuiLyXFiles.cpp b/src/frontends/qt4/GuiLyXFiles.cpp index 21d3653aab..bcb2dcd839 100644 --- a/src/frontends/qt4/GuiLyXFiles.cpp +++ b/src/frontends/qt4/GuiLyXFiles.cpp @@ -239,6 +239,8 @@ QString const GuiLyXFiles::getSuffix() { if (type_ == "bind" || type_ == "ui") return toqstr(".") + type_; + else if (type_ == "kbd") + return ".kmap"; return ".lyx"; } @@ -344,17 +346,43 @@ void GuiLyXFiles::setLanguage() void GuiLyXFiles::on_browsePB_pressed() { - bool const examples = (type_ == "examples"); - FileDialog dlg(qt_("Select template file")); - dlg.setButton1(qt_("D&ocuments"), toqstr(lyxrc.document_path)); - if (examples) - dlg.setButton2(qt_("&Examples"), toqstr(lyxrc.example_path)); - else - dlg.setButton2(qt_("&Templates"), toqstr(lyxrc.template_path)); + QString path1 = toqstr(lyxrc.document_path); + QString path2 = toqstr(lyxrc.example_path); + QString title = qt_("Select example file"); + QString filter = qt_("LyX Documents (*.lyx)"); + QString b1 = qt_("D&ocuments"); + QString b2 = qt_("&Examples"); + + if (type_ == "templates") { + path2 = toqstr(lyxrc.template_path); + title = qt_("Select template file"); + b1 = qt_("D&ocuments"); + b2 = qt_("&Templates"); + } + else if (type_ != "examples") { + path1 = toqstr(addName(package().user_support().absFileName(), fromqstr(type_))); + path2 = toqstr(addName(package().system_support().absFileName(), fromqstr(type_))); + b1 = qt_("&User files"); + b2 = qt_("&System files"); + } + if (type_ == "ui") { + title = qt_("Chose UI file"); + filter = qt_("LyX UI Files (*.ui)"); + } + if (type_ == "bind") { + title = qt_("Chose bind file"); + filter = qt_("LyX Bind Files (*.bind)"); + } + if (type_ == "kbd") { + title = qt_("Chose keyboard map"); + filter = qt_("LyX Keymap Files (*.kmap)"); + } + + FileDialog dlg(title); + dlg.setButton1(b1, path1); + dlg.setButton2(b2, path2); - FileDialog::Result result = dlg.open(examples ? toqstr(lyxrc.example_path) - : toqstr(lyxrc.template_path), - QStringList(qt_("LyX Documents (*.lyx)"))); + FileDialog::Result result = dlg.open(path2, QStringList(filter)); if (result.first != FileDialog::Later && !result.second.isEmpty()) { file_ = toqstr(FileName(fromqstr(result.second)).absFileName()); @@ -513,6 +541,21 @@ bool GuiLyXFiles::initialiseParams(string const & type) } +void GuiLyXFiles::passParams(string const & data) +{ + initialiseParams(data); + updateContents(); +} + + +void GuiLyXFiles::selectItem(QString const item) +{ + QList twi = filesLW->findItems(item, Qt::MatchExactly|Qt::MatchRecursive); + if (!twi.isEmpty()) + twi.first()->setSelected(true); +} + + void GuiLyXFiles::paramsToDialog() { if (type_ == "examples") @@ -537,7 +580,11 @@ void GuiLyXFiles::dispatchParams() arg += fromqstr(file_); FuncCode const lfun = getLfun(); - dispatch(FuncRequest(lfun, arg)); + if (lfun == LFUN_NOACTION) + // emit signal + fileSelected(file_); + else + dispatch(FuncRequest(lfun, arg)); } diff --git a/src/frontends/qt4/GuiLyXFiles.h b/src/frontends/qt4/GuiLyXFiles.h index e4213353b8..bc129139a7 100644 --- a/src/frontends/qt4/GuiLyXFiles.h +++ b/src/frontends/qt4/GuiLyXFiles.h @@ -32,6 +32,12 @@ class GuiLyXFiles : public GuiDialog, public Ui::LyXFilesUi public: GuiLyXFiles(GuiView & lv); + /// A way to pass params to the dialog directly + void passParams(std::string const & data); + /// A way to pass params to the dialog directly + void selectItem(QString const item); +Q_SIGNALS: + void fileSelected(QString const file); private Q_SLOTS: void changed_adaptor(); diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index be9e981ca7..44ed76a012 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -19,6 +19,8 @@ #include "GuiFontExample.h" #include "GuiFontLoader.h" #include "GuiKeySymbol.h" +#include "GuiLyXFiles.h" +#include "GuiView.h" #include "qt_helpers.h" #include "Validator.h" @@ -125,46 +127,6 @@ QString browseFile(QString const & filename, } -/** Wrapper around browseFile which tries to provide a filename -* relative to the user or system directory. The dir, name and ext -* parameters have the same meaning as in the -* support::LibFileSearch function. -*/ -QString browseLibFile(QString const & dir, - QString const & name, - QString const & ext, - QString const & title, - QStringList const & filters) -{ - // FIXME UNICODE - QString const label1 = qt_("&System files"); - QString const dir1 = - toqstr(addName(package().system_support().absFileName(), fromqstr(dir))); - - QString const label2 = qt_("&User files"); - QString const dir2 = - toqstr(addName(package().user_support().absFileName(), fromqstr(dir))); - - QString const result = browseFile(toqstr( - libFileSearch(dir, name, ext).absFileName()), - title, filters, false, dir1, dir2, QString(), QString(), dir1); - - // remove the extension if it is the default one - QString noextresult; - if (getExtension(result) == ext) - noextresult = removeExtension(result); - else - noextresult = result; - - // remove the directory, if it is the default one - QString const file = onlyFileName(noextresult); - if (toqstr(libFileSearch(dir, file, ext).absFileName()) == result) - return file; - else - return noextresult; -} - - /** Launch a file dialog and return the chosen directory. pathname: a suggested pathname. title: the title of the dialog. @@ -3493,6 +3455,10 @@ GuiPreferences::GuiPreferences(GuiView & lv) bc().setApply(buttonBox->button(QDialogButtonBox::Apply)); bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel)); bc().setRestore(buttonBox->button(QDialogButtonBox::Reset)); + + glf = new GuiLyXFiles(lv); + connect(glf, SIGNAL(fileSelected(QString)), + this, SLOT(slotFileSelected(QString))); } @@ -3593,24 +3559,59 @@ void GuiPreferences::setColor(ColorCode col, QString const & hex) } -QString GuiPreferences::browsebind(QString const & file) const +void GuiPreferences::slotFileSelected(QString const file) +{ + uifile_ = file; +} + + +/** Wrapper around browseFile which tries to provide a filename +* relative to the user or system directory. The dir, name and ext +* parameters have the same meaning as in the +* support::LibFileSearch function. +*/ +QString GuiPreferences::browseLibFile(QString const & dir, + QString const & name, QString const & ext) +{ + uifile_.clear(); + + glf->passParams(fromqstr(dir)); + glf->selectItem(name); + glf->exec(); + + QString const result = uifile_; + + // remove the extension if it is the default one + QString noextresult; + if (getExtension(result) == ext) + noextresult = removeExtension(result); + else + noextresult = result; + + // remove the directory, if it is the default one + QString const file = onlyFileName(noextresult); + if (toqstr(libFileSearch(dir, file, ext).absFileName()) == result) + return file; + else + return noextresult; +} + + +QString GuiPreferences::browsebind(QString const & file) { - return browseLibFile("bind", file, "bind", qt_("Choose bind file"), - QStringList(qt_("LyX bind files (*.bind)"))); + return browseLibFile("bind", file, "bind"); } -QString GuiPreferences::browseUI(QString const & file) const +QString GuiPreferences::browseUI(QString const & file) { - return browseLibFile("ui", file, "ui", qt_("Choose UI file"), - QStringList(qt_("LyX UI files (*.ui)"))); + return browseLibFile("ui", file, "ui"); } -QString GuiPreferences::browsekbmap(QString const & file) const +QString GuiPreferences::browsekbmap(QString const & file) { - return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"), - QStringList(qt_("LyX keyboard maps (*.kmap)"))); + return browseLibFile("kbd", file, "kmap"); } diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index ebf7a53f02..a20f3d028f 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -15,6 +15,7 @@ #define GUIPREFS_H #include "GuiDialog.h" +#include "GuiLyXFiles.h" #include "Converter.h" #include "Format.h" @@ -68,6 +69,7 @@ public: public Q_SLOTS: void change_adaptor(); + void slotFileSelected(QString); Q_SIGNALS: void prefsApplied(LyXRC const & rc); @@ -88,9 +90,9 @@ public: bool isBufferDependent() const { return false; } /// various file pickers - QString browsebind(QString const & file) const; - QString browseUI(QString const & file) const; - QString browsekbmap(QString const & file) const; + QString browsebind(QString const & file); + QString browseUI(QString const & file); + QString browsekbmap(QString const & file); /// general browse QString browse(QString const & file, QString const & title) const; @@ -106,6 +108,9 @@ public: private: /// void addModule(PrefModule * module); + /// + QString browseLibFile(QString const & dir, + QString const & name, QString const & ext); /// temporary lyxrc LyXRC rc_; @@ -118,6 +123,10 @@ private: /// A list of colors to be dispatched std::vector colors_; + /// UI file selector + GuiLyXFiles * glf; + /// Selected UI file + QString uifile_; }; -- 2.39.5