From 0d5b17b05819f325c44a9c55275ad96e527d462d Mon Sep 17 00:00:00 2001 From: John Levon Date: Sun, 17 Nov 2002 08:32:09 +0000 Subject: [PATCH] qt filedialog fix git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5652 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 2 +- src/ChangeLog | 6 + src/frontends/ChangeLog | 5 + src/frontends/FileDialog.h | 19 ++- src/frontends/controllers/ChangeLog | 4 + src/frontends/controllers/ControlBibtex.C | 2 +- src/frontends/controllers/ControlExternal.C | 2 +- src/frontends/controllers/ControlGraphics.C | 2 +- src/frontends/controllers/ControlInclude.C | 2 +- src/frontends/controllers/ControlPrefs.C | 8 +- src/frontends/controllers/ControlPrint.C | 2 +- src/frontends/controllers/helper_funcs.C | 12 +- src/frontends/controllers/helper_funcs.h | 6 +- src/frontends/qt2/ChangeLog | 5 + src/frontends/qt2/FileDialog.C | 36 +++-- src/frontends/qt2/QPrefsDialog.C | 3 +- src/frontends/qt2/ui/QPrefColorsModule.ui | 137 ++++++++++++++------ src/frontends/xforms/ChangeLog | 4 + src/frontends/xforms/FileDialog.C | 11 +- src/lyx_cb.C | 4 +- src/lyxfunc.C | 6 +- 21 files changed, 203 insertions(+), 75 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a191d219d9..bf2e53f2c7 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -857,7 +857,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen) string(AddPath(system_lyxdir, "examples")))); FileDialog::Result result = - fileDlg.Select(initpath, + fileDlg.open(initpath, _("*.lyx| LyX Documents (*.lyx)")); if (result.first == FileDialog::Later) diff --git a/src/ChangeLog b/src/ChangeLog index 460fea54ca..af15a4c52b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2002-11-17 John Levon + + * BufferView_pimpl.C: + * lyx_cb.C: + * lyxfunc.C: split filedialog into open/save + 2002-11-08 Juergen Vigna * undo_funcs.C (textHandleUndo): fixed problems with undo introduced diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index ae4c266f2d..6029d41772 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,8 @@ +2002-11-17 John Levon + + * FileDialog.h: split Select() into open()/save() for + benefit of Qt + 2002-11-01 Herbert Voss * ControlGraphics.C: "Default" is now a part of the rotate-list diff --git a/src/frontends/FileDialog.h b/src/frontends/FileDialog.h index 40f154f055..633eba4401 100644 --- a/src/frontends/FileDialog.h +++ b/src/frontends/FileDialog.h @@ -47,7 +47,7 @@ public: /** * Constructs a file dialog attached to LyXView \param lv, with * title \param title. If \param a is \const LFUN_SELECT_FILE_SYNC - * then a value will be returned immediately upon performing a Select(), + * then a value will be returned immediately upon performing a open(), * otherwise a callback Dispatch() will be invoked with the filename as * argument, of action \param a. * @@ -64,7 +64,7 @@ public: ~FileDialog(); /** - * Choose a file for selection, starting in directory \param + * Choose a file for opening, starting in directory \param * path, with the file selection \param mask. The \param mask * string is of the form : * @@ -74,7 +74,20 @@ public: * * FIXME: should support multiple lines of these for different file types. */ - Result const Select(string const & path = string(), + Result const open(string const & path = string(), + string const & mask = string(), + string const & suggested = string()); + + /** + * Choose a file for saving, starting in directory \param + * path, with the file selection \param mask. The \param mask + * string is of the form : + * + * | + * + * for example, "*.ps | PostScript files (*.ps)". + */ + Result const save(string const & path = string(), string const & mask = string(), string const & suggested = string()); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 508fadbc94..1fcb51d51c 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2002-11-17 John Levon + + * helper_funcs.C and users: specify save/open in file dialog + 2002-11-15 John Levon * ControlPrefs.h: diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index a6833fca29..96e4507cb8 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -63,7 +63,7 @@ string const ControlBibtex::Browse(string const & in_name, pair dir1(_("Documents|#o#O"), string(lyxrc.document_path)); return browseRelFile(&lv_, in_name, buffer()->filePath(), - title, pattern, dir1); + title, pattern, false, dir1); } diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index 3c613af023..e66829189f 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -154,5 +154,5 @@ string const ControlExternal::Browse(string const & input) const std::pair dir1(N_("Documents|#o#O"), string(lyxrc.document_path)); - return browseRelFile(&lv_, input, bufpath, title, pattern, dir1); + return browseRelFile(&lv_, input, bufpath, title, pattern, false, dir1); } diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index a6f9713c03..9faad1ccba 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -93,7 +93,7 @@ string const ControlGraphics::Browse(string const & in_name) pair dir2(_("Documents|#o#O"), string(lyxrc.document_path)); // Show the file browser dialog return browseRelFile(&lv_, in_name, buffer()->filePath(), - title, "*.*", dir1, dir2); + title, "*.*", false, dir1, dir2); } diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index d1c8c123f2..078b91d23b 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -72,7 +72,7 @@ string const ControlInclude::Browse(string const & in_name, Type in_type) string const docpath = OnlyPath(params().masterFilename_); - return browseRelFile(&lv_, in_name, docpath, title, pattern, dir1); + return browseRelFile(&lv_, in_name, docpath, title, pattern, false, dir1); } diff --git a/src/frontends/controllers/ControlPrefs.C b/src/frontends/controllers/ControlPrefs.C index b36d2ee2fc..00ea4f672e 100644 --- a/src/frontends/controllers/ControlPrefs.C +++ b/src/frontends/controllers/ControlPrefs.C @@ -70,7 +70,7 @@ string const ControlPrefs::browsebind(string const & file) name = _("User Bind|#U#u"); pair dir2(name, dir); - return browseFile(&lv_, file, _("Choose bind file"), "*.bind", dir1, dir2); + return browseFile(&lv_, file, _("Choose bind file"), "*.bind", false, dir1, dir2); } @@ -86,7 +86,7 @@ string const ControlPrefs::browseUI(string const & file) name = _("User UI|#U#u"); pair dir2(name, dir); - return browseFile(&lv_, file, _("Choose UI file"), "*.ui", dir1, dir2); + return browseFile(&lv_, file, _("Choose UI file"), "*.ui", false, dir1, dir2); } @@ -96,7 +96,7 @@ string const ControlPrefs::browsekbmap(string const & file) string const name = _("Key maps|#K#k"); pair dir1(name, dir); - return browseFile(&lv_, file, _("Choose keyboard map"), "*.kmap", dir1); + return browseFile(&lv_, file, _("Choose keyboard map"), "*.kmap", false, dir1); } @@ -108,7 +108,7 @@ string const ControlPrefs::browsedict(string const & file) string const ControlPrefs::browse(string const & file, string const & title) { - return browseFile(&lv_, file, title, "*"); + return browseFile(&lv_, file, title, "*", true); } diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index 53f303e090..2b151bc4f3 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -80,7 +80,7 @@ string const ControlPrint::Browse(string const & in_name) // Show the file browser dialog return browseRelFile(&lv_, in_name, buffer()->filePath(), - title, pattern); + title, pattern, true); } diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index f189856d6d..7802000490 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -32,6 +32,7 @@ using std::make_pair; string const browseFile(LyXView * lv, string const & filename, string const & title, string const & pattern, + bool save, pair const & dir1, pair const & dir2) { @@ -44,8 +45,12 @@ string const browseFile(LyXView * lv, string const & filename, FileDialog::Result result; while (true) { - result = fileDlg.Select(lastPath, pattern, - OnlyFilename(filename)); + if (save) + result = fileDlg.save(lastPath, pattern, + OnlyFilename(filename)); + else + result = fileDlg.open(lastPath, pattern, + OnlyFilename(filename)); if (result.second.empty()) return result.second; @@ -68,12 +73,13 @@ string const browseRelFile(LyXView * lv, string const & filename, string const & refpath, string const & title, string const & pattern, + bool save = false, pair const & dir1, pair const & dir2) { string const fname = MakeAbsPath(filename, refpath); - string const outname = browseFile(lv, fname, title, pattern, + string const outname = browseFile(lv, fname, title, pattern, save, dir1, dir2); string const reloutname = MakeRelPath(outname, refpath); if (prefixIs(reloutname, "../")) diff --git a/src/frontends/controllers/helper_funcs.h b/src/frontends/controllers/helper_funcs.h index 440ebca3fe..fa1e689e05 100644 --- a/src/frontends/controllers/helper_funcs.h +++ b/src/frontends/controllers/helper_funcs.h @@ -30,9 +30,10 @@ class LyXView; dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog. */ string const -browseFile(LyXView *lv, string const & filename, +browseFile(LyXView * lv, string const & filename, string const & title, string const & pattern, + bool save = false, std::pair const & dir1 = std::make_pair(string(), string()), std::pair const & dir2 = @@ -46,10 +47,11 @@ browseFile(LyXView *lv, string const & filename, intended to be useful for insets which encapsulate files/ */ string const -browseRelFile(LyXView *lv, string const & filename, +browseRelFile(LyXView * lv, string const & filename, string const & refpath, string const & title, string const & pattern, + bool save = false, std::pair const & dir1 = std::make_pair(string(), string()), std::pair const & dir2 = diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index e005efade6..045a88bb64 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2002-11-17 John Levon + + * FileDialog.C: split into open/save so open + no longer says "Save" ! + 2002-11-17 John Levon * QPrefsDialog.h: diff --git a/src/frontends/qt2/FileDialog.C b/src/frontends/qt2/FileDialog.C index 48c726bc23..e3fbc5ffdb 100644 --- a/src/frontends/qt2/FileDialog.C +++ b/src/frontends/qt2/FileDialog.C @@ -51,7 +51,7 @@ FileDialog::~FileDialog() } -FileDialog::Result const FileDialog::Select(string const & path, +FileDialog::Result const FileDialog::save(string const & path, string const & mask, string const & suggested) { @@ -69,9 +69,33 @@ FileDialog::Result const FileDialog::Select(string const & path, if (!suggested.empty()) dlg.setSelection(suggested.c_str()); - // This code relies on DestructiveClose which is broken - // in Qt < 3.0.5. So we just don't allow it for now. - //if (success_ == LFUN_SELECT_FILE_SYNC) { + FileDialog::Result result; + lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl; + result.first = FileDialog::Chosen; + int res = dlg.exec(); + lyxerr[Debug::GUI] << "result " << res << endl; + if (res == QDialog::Accepted) + result.second = string(dlg.selectedFile().data()); + dlg.hide(); + return result; +} + + +FileDialog::Result const FileDialog::open(string const & path, + string const & mask, + string const & suggested) +{ + string filter(mask); + if (mask.empty()) + filter = _("*|All files"); + + LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2); + lyxerr[Debug::GUI] << "Select with path \"" << path + << "\", mask \"" << filter + << "\", suggested \"" << suggested << endl; + + if (!suggested.empty()) + dlg.setSelection(suggested.c_str()); FileDialog::Result result; lyxerr[Debug::GUI] << "Synchronous FileDialog : " << endl; @@ -82,8 +106,4 @@ FileDialog::Result const FileDialog::Select(string const & path, result.second = string(dlg.selectedFile().data()); dlg.hide(); return result; -#if 0 - dlg->show(); - return make_pair(FileDialog::Later, string()); -#endif } diff --git a/src/frontends/qt2/QPrefsDialog.C b/src/frontends/qt2/QPrefsDialog.C index f7f3db00ad..95f4803446 100644 --- a/src/frontends/qt2/QPrefsDialog.C +++ b/src/frontends/qt2/QPrefsDialog.C @@ -312,7 +312,7 @@ void QPrefsDialog::switch_converter(int nr) } -// FIXME: we would like to highlight the new entry ... also user must +// FIXME: user must // specify unique from/to or it doesn't appear. This is really bad UI void QPrefsDialog::new_converter() { @@ -325,6 +325,7 @@ void QPrefsDialog::new_converter() form_->converters_.updateLast(form_->formats_); } updateConverters(); + convertersModule->convertersLB->setCurrentItem(convertersModule->convertersLB->count() - 1); } diff --git a/src/frontends/qt2/ui/QPrefColorsModule.ui b/src/frontends/qt2/ui/QPrefColorsModule.ui index 8e33e07471..5914f49d44 100644 --- a/src/frontends/qt2/ui/QPrefColorsModule.ui +++ b/src/frontends/qt2/ui/QPrefColorsModule.ui @@ -13,7 +13,7 @@ 0 0 - 305 + 301 259 @@ -21,7 +21,7 @@ caption Colors - + margin 11 @@ -30,53 +30,108 @@ spacing 6 - - QListBox - - - text - New Item - - - - name - lyxObjectsLB - - - - QLabel + + QLayoutWidget name - lyxObjectsLA - - - text - LyX &Objects: - - - buddy - lyxObjectsLB - - - - QPushButton - - name - colorChangePB - - - text - Chan&ge Color... + Layout2 + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + lyxObjectsLA + + + text + &Colors + + + buddy + lyxObjectsLB + + + + QListBox + + + text + New Item + + + + name + lyxObjectsLB + + + + QLayoutWidget + + name + Layout1 + + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + colorChangePB + + + text + &Alter ... + + + + + name + Spacer3 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + - + name - Spacer6 + Spacer2 orientation - Vertical + Horizontal sizeType @@ -90,6 +145,6 @@ - + diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 4fb76ab589..683b0c7aa5 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2002-11-17 John Levon + + * FileDialog.C: open/save name change + 2002-11-15 John Levon * Dialogs2.C: diff --git a/src/frontends/xforms/FileDialog.C b/src/frontends/xforms/FileDialog.C index b7021cd25d..3dad836369 100644 --- a/src/frontends/xforms/FileDialog.C +++ b/src/frontends/xforms/FileDialog.C @@ -48,7 +48,13 @@ FileDialog::~FileDialog() } -FileDialog::Result const FileDialog::Select(string const & path, string const & mask, string const & suggested) +FileDialog::Result const FileDialog::save(string const & path, string const & mask, string const & suggested) +{ + open(path, mask, suggested); +} + + +FileDialog::Result const FileDialog::open(string const & path, string const & mask, string const & suggested) { string filter = mask; @@ -60,7 +66,8 @@ FileDialog::Result const FileDialog::Select(string const & path, string const & filter = mask; } - lyxerr[Debug::GUI] << "Select with path \"" << path << "\", mask \"" << filter << "\", suggested \"" << suggested << "\"" << endl; + lyxerr[Debug::GUI] << "filedialog open with path \"" << path << "\", mask \"" + << filter << "\", suggested \"" << suggested << "\"" << endl; // no support for asynchronous selection yet diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 040f63f29d..3e41b36bff 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -115,7 +115,7 @@ bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename) fname += ".lyx"; FileDialog::Result result = - fileDlg.Select(OnlyPath(fname), + fileDlg.save(OnlyPath(fname), _("*.lyx|LyX Documents (*.lyx)"), OnlyFilename(fname)); @@ -419,7 +419,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap FileDialog fileDlg(bv->owner(), _("Select file to insert"), (asParagraph) ? LFUN_FILE_INSERT_ASCII_PARA : LFUN_FILE_INSERT_ASCII); - FileDialog::Result result = fileDlg.Select(bv->owner()->buffer()->filePath()); + FileDialog::Result result = fileDlg.open(bv->owner()->buffer()->filePath()); if (result.first == FileDialog::Later) return string(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index f4208f820c..79fd0e8efd 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1594,7 +1594,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) string(lyxrc.template_path))); FileDialog::Result result = - fileDlg.Select(lyxrc.template_path, + fileDlg.open(lyxrc.template_path, _("*.lyx|LyX Documents (*.lyx)")); if (result.first == FileDialog::Later) @@ -1633,7 +1633,7 @@ void LyXFunc::open(string const & fname) string(AddPath(system_lyxdir, "examples")))); FileDialog::Result result = - fileDlg.Select(initpath, + fileDlg.open(initpath, "*.lyx|LyX Documents (*.lyx)"); if (result.first == FileDialog::Later) @@ -1722,7 +1722,7 @@ void LyXFunc::doImport(string const & argument) + "| " + formats.prettyName(format) + " (*." + formats.extension(format) + ")"; - FileDialog::Result result = fileDlg.Select(initpath, + FileDialog::Result result = fileDlg.open(initpath, extension); if (result.first == FileDialog::Later) -- 2.39.2