mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
Use GuiLyXFiles also for ui, kbd and bind files in prefs
This commit is contained in:
parent
9a2c5b515a
commit
58c4c11c4c
@ -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");
|
||||
|
||||
FileDialog::Result result = dlg.open(examples ? toqstr(lyxrc.example_path)
|
||||
: toqstr(lyxrc.template_path),
|
||||
QStringList(qt_("LyX Documents (*.lyx)")));
|
||||
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(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,6 +580,10 @@ void GuiLyXFiles::dispatchParams()
|
||||
arg += fromqstr(file_);
|
||||
FuncCode const lfun = getLfun();
|
||||
|
||||
if (lfun == LFUN_NOACTION)
|
||||
// emit signal
|
||||
fileSelected(file_);
|
||||
else
|
||||
dispatch(FuncRequest(lfun, arg));
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
{
|
||||
return browseLibFile("bind", file, "bind", qt_("Choose bind file"),
|
||||
QStringList(qt_("LyX bind files (*.bind)")));
|
||||
uifile_ = file;
|
||||
}
|
||||
|
||||
|
||||
QString GuiPreferences::browseUI(QString const & file) const
|
||||
/** 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)
|
||||
{
|
||||
return browseLibFile("ui", file, "ui", qt_("Choose UI file"),
|
||||
QStringList(qt_("LyX UI files (*.ui)")));
|
||||
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::browsekbmap(QString const & file) const
|
||||
QString GuiPreferences::browsebind(QString const & file)
|
||||
{
|
||||
return browseLibFile("kbd", file, "kmap", qt_("Choose keyboard map"),
|
||||
QStringList(qt_("LyX keyboard maps (*.kmap)")));
|
||||
return browseLibFile("bind", file, "bind");
|
||||
}
|
||||
|
||||
|
||||
QString GuiPreferences::browseUI(QString const & file)
|
||||
{
|
||||
return browseLibFile("ui", file, "ui");
|
||||
}
|
||||
|
||||
|
||||
QString GuiPreferences::browsekbmap(QString const & file)
|
||||
{
|
||||
return browseLibFile("kbd", file, "kmap");
|
||||
}
|
||||
|
||||
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user