]> git.lyx.org Git - lyx.git/commitdiff
Use GuiLyXFiles also for ui, kbd and bind files in prefs
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 22 Mar 2019 13:11:46 +0000 (14:11 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 22 Mar 2019 13:14:33 +0000 (14:14 +0100)
src/frontends/qt4/GuiLyXFiles.cpp
src/frontends/qt4/GuiLyXFiles.h
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrefs.h

index 21d3653aab57bd1dfd82c9bde20913755c184957..bcb2dcd839c850263c83f883a53480230033aa77 100644 (file)
@@ -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<QTreeWidgetItem *> 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));
 }
 
 
index e4213353b8cb058e7f8e04620a7520e3825904d9..bc129139a706c6c1ae243f97fe1fab484f864ca8 100644 (file)
@@ -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();
index be9e981ca7a1ea6eeaa2372daff385f65a5af431..44ed76a012ab38cee542ac91a152b9612b517cb1 100644 (file)
@@ -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");
 }
 
 
index ebf7a53f02e5dcd32b1db2dcd763f55a5c9b57fb..a20f3d028faa579231294da4364b58260b4374a2 100644 (file)
@@ -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<std::string> colors_;
+       /// UI file selector
+       GuiLyXFiles * glf;
+       /// Selected UI file
+       QString uifile_;
 };