From 765db1102d7edf01d2fd7b667c75095f843ab476 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Wed, 7 Mar 2001 14:25:31 +0000 Subject: [PATCH] Applied John's FileDialog patch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1702 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 5 + lib/bind/cua.bind | 4 +- lib/bind/de_menus.bind | 6 +- lib/bind/emacs.bind | 4 +- lib/bind/fr_menus.bind | 2 +- lib/bind/hu_menus.bind | 2 +- lib/bind/pt_menus.bind | 6 +- lib/bind/sciword.bind | 2 +- lib/bind/sv_menus.bind | 2 +- lib/bind/xemacs.bind | 4 +- lib/images/{buffer-open.xpm => file-open.xpm} | 0 lib/ui/default.ui | 10 +- po/POTFILES.in | 5 +- src/BufferView_pimpl.C | 35 +-- src/ChangeLog | 20 ++ src/LyXAction.C | 8 +- src/Makefile.am | 2 - src/ToolbarDefaults.C | 2 +- src/bufferlist.C | 4 +- src/commandtags.h | 6 +- src/form1.C | 57 ---- src/form1.h | 20 -- src/frontends/ChangeLog | 5 + src/frontends/FileDialog.h | 96 +++++++ src/frontends/Makefile.am | 1 + src/frontends/kde/ChangeLog | 12 + src/frontends/kde/Dialogs.C | 2 + src/frontends/kde/FileDialog.C | 79 ++++++ src/frontends/kde/FileDialog_private.C | 39 +++ src/frontends/kde/FileDialog_private.h | 38 +++ src/frontends/kde/FormCitation.h | 2 +- src/frontends/kde/FormCopyright.h | 2 +- src/frontends/kde/FormDocument.h | 2 +- src/frontends/kde/FormIndex.h | 2 +- src/frontends/kde/FormLog.h | 2 +- src/frontends/kde/FormParagraph.h | 2 +- src/frontends/kde/FormPrint.h | 2 +- src/frontends/kde/FormRef.h | 2 +- src/frontends/kde/FormTabularCreate.h | 2 +- src/frontends/kde/FormToc.h | 2 +- src/frontends/kde/FormUrl.h | 2 +- src/frontends/kde/FormVCLog.h | 2 +- src/frontends/kde/Makefile.am | 4 + src/frontends/kde/docdlg.C | 3 - src/frontends/kde/moc/Makefile.am | 5 +- src/frontends/xforms/ChangeLog | 20 ++ src/frontends/xforms/FileDialog.C | 80 ++++++ .../xforms/FormFiledialog.C} | 125 +++++---- .../xforms/FormFiledialog.h} | 56 ++-- src/frontends/xforms/FormGraphics.C | 5 +- src/frontends/xforms/FormInclude.C | 41 ++- src/frontends/xforms/FormPreferences.C | 2 +- src/frontends/xforms/FormPrint.C | 2 +- src/frontends/xforms/Makefile.am | 5 + src/frontends/xforms/Toolbar_pimpl.C | 22 +- src/frontends/xforms/Toolbar_pimpl.h | 5 + src/frontends/xforms/form_filedialog.C | 108 ++++++++ src/frontends/xforms/form_filedialog.h | 29 ++ src/frontends/xforms/forms/fdfix.sh | 11 +- src/frontends/xforms/forms/form_filedialog.fd | 250 ++++++++++++++++++ src/frontends/xforms/forms/makefile | 1 + src/frontends/xforms/xforms_helpers.C | 54 ++-- src/frontends/xforms/xforms_helpers.h | 4 +- src/insets/ChangeLog | 5 + src/insets/figinset.C | 30 +-- src/insets/insetexternal.C | 30 ++- src/lyx_cb.C | 119 ++++----- src/lyx_cb.h | 6 +- src/lyxfunc.C | 130 ++++----- src/lyxfunc.h | 2 +- 70 files changed, 1202 insertions(+), 454 deletions(-) rename lib/images/{buffer-open.xpm => file-open.xpm} (100%) create mode 100644 src/frontends/FileDialog.h create mode 100644 src/frontends/kde/FileDialog.C create mode 100644 src/frontends/kde/FileDialog_private.C create mode 100644 src/frontends/kde/FileDialog_private.h create mode 100644 src/frontends/xforms/FileDialog.C rename src/{filedlg.C => frontends/xforms/FormFiledialog.C} (85%) rename src/{filedlg.h => frontends/xforms/FormFiledialog.h} (68%) create mode 100644 src/frontends/xforms/form_filedialog.C create mode 100644 src/frontends/xforms/form_filedialog.h create mode 100644 src/frontends/xforms/forms/form_filedialog.fd diff --git a/lib/ChangeLog b/lib/ChangeLog index d442ed8f12..22222b36bc 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2001-03-06 John Levon + + * ui/default.ui: + * bind/: update for file dialog change + 2001-03-06 Chanop Silpa-Anan * encodings: diff --git a/lib/bind/cua.bind b/lib/bind/cua.bind index 113586ac7f..9778500cd3 100644 --- a/lib/bind/cua.bind +++ b/lib/bind/cua.bind @@ -31,7 +31,7 @@ \bind "C-n" "buffer-new" \bind "C-S-N" "buffer-new-template" -\bind "C-o" "buffer-open" +\bind "C-o" "file-open" \bind "C-r" "buffer-reload" \bind "C-w" "buffer-close" \bind "C-s" "buffer-write" @@ -77,7 +77,7 @@ #bind "F1" "help" # Not yet implemented! #bind "C-F1" "help-context" # Not yet implemented! \bind "F2" "buffer-write" -\bind "F3" "buffer-open" +\bind "F3" "file-open" \bind "C-F4" "buffer-close" \bind "F5" "screen-recenter" \bind "M-F4" "lyx-quit" diff --git a/lib/bind/de_menus.bind b/lib/bind/de_menus.bind index e3c1a5ce03..098febedd5 100644 --- a/lib/bind/de_menus.bind +++ b/lib/bind/de_menus.bind @@ -47,7 +47,7 @@ # #\bind "M-d n" "buffer-new" #\bind "M-d v" "buffer-new-template" -#\bind "M-d o" "buffer-open" +#\bind "M-d o" "file-open" #\bind "M-d c" "buffer-close" #\bind "M-d s" "buffer-write" #\bind "M-d u" "buffer-write-as" @@ -131,8 +131,8 @@ #\bind "M-e a" "figure-insert" #\bind "M-e t" "table-insert" #\bind "M-e d" "buffer-child-insert" -#\bind "M-e c z" "file-insert-ascii line" -#\bind "M-e c a" "file-insert-ascii paragraph" +#\bind "M-e c z" "file-insert-ascii" +#\bind "M-e c a" "file-insert-ascii-para" #\bind "M-e l" "file-insert" #\bind "M-e f" "footnote-insert" #\bind "M-e r" "marginpar-insert" diff --git a/lib/bind/emacs.bind b/lib/bind/emacs.bind index 5b72ee63fa..b967d29178 100644 --- a/lib/bind/emacs.bind +++ b/lib/bind/emacs.bind @@ -91,7 +91,7 @@ \bind "C-x C-b" "menu-open documents" \bind "C-x C-c" "lyx-quit" \bind "C-x C-d" "buffer-new" -\bind "C-x C-f" "buffer-open" +\bind "C-x C-f" "file-open" \bind "C-x C-g" "buffer-view ps" \bind "C-x C-p" "buffer-view dvi" \bind "C-x C-q" "buffer-toggle-read-only" @@ -118,7 +118,7 @@ #bind "F1" "help" # Not yet implemented! #bind "C-F1" "help-context" # Not yet implemented! #\bind "F2" "buffer-write" -#\bind "F3" "buffer-open" +#\bind "F3" "file-open" #bind "F4" "------" #bind "F5" "------" #bind "F6" "------" diff --git a/lib/bind/fr_menus.bind b/lib/bind/fr_menus.bind index 4fc125a88a..1ffdd44396 100644 --- a/lib/bind/fr_menus.bind +++ b/lib/bind/fr_menus.bind @@ -29,7 +29,7 @@ #\bind "M-f n" "buffer-new" #Nouveau #\bind "M-f m" "buffer-new-template" #... Modèle -#\bind "M-f o" "buffer-open" #Ouvrir +#\bind "M-f o" "file-open" #Ouvrir #\bind "M-f f" "buffer-close" #Fermer #\bind "M-f e" "buffer-write" #Enregistrer #\bind "M-f s" "buffer-write-as" #Enregistrer Sous diff --git a/lib/bind/hu_menus.bind b/lib/bind/hu_menus.bind index 0967ede760..ef7184102c 100644 --- a/lib/bind/hu_menus.bind +++ b/lib/bind/hu_menus.bind @@ -30,7 +30,7 @@ #\bind "M-f space" "menu-open Fájl" #\bind "M-f j" "buffer-new" #\bind "M-f a" "buffer-new-template" -#\bind "M-f n" "buffer-open" +#\bind "M-f n" "file-open" #\bind "M-f z" "buffer-close" #\bind "M-f m" "buffer-write" #\bind "M-f t" "buffer-write-as" diff --git a/lib/bind/pt_menus.bind b/lib/bind/pt_menus.bind index 2afeb2a3d3..3116621dc9 100644 --- a/lib/bind/pt_menus.bind +++ b/lib/bind/pt_menus.bind @@ -33,7 +33,7 @@ #\bind "M-a n" "buffer-new" #\bind "M-a m" "buffer-new-template" -#\bind "M-a a" "buffer-open" +#\bind "M-a a" "file-open" #\bind "M-a f" "buffer-close" #\bind "M-a l" "buffer-write" #\bind "M-a c" "buffer-write-as" @@ -107,8 +107,8 @@ #\bind "M-i g" "figure-insert" #\bind "M-i b" "table-insert" #\bind "M-i a" "buffer-child-insert" -#\bind "M-i i l" "file-insert-ascii line" -#\bind "M-i i p" "file-insert-ascii paragraph" +#\bind "M-i i l" "file-insert-ascii" +#\bind "M-i i p" "file-insert-ascii-para" #\bind "M-i x" "file-insert" #\bind "M-i r" "footnote-insert" #\bind "M-i m" "marginpar-insert" diff --git a/lib/bind/sciword.bind b/lib/bind/sciword.bind index 5bb71c2d3b..e6eafa41d0 100644 --- a/lib/bind/sciword.bind +++ b/lib/bind/sciword.bind @@ -249,7 +249,7 @@ #\bind "M-f c" "buffer-close" #\bind "M-f n" "buffer-new" #\bind "M-f l" "file-last" # Not yet implemented. -#\bind "M-f o" "buffer-open" +#\bind "M-f o" "file-open" #\bind "M-f p" "buffer-print" #\bind "M-f q" "lyx-quit" #\bind "M-f r" "buffer-update dvi" diff --git a/lib/bind/sv_menus.bind b/lib/bind/sv_menus.bind index f83e671122..edaf1b2e1a 100644 --- a/lib/bind/sv_menus.bind +++ b/lib/bind/sv_menus.bind @@ -39,7 +39,7 @@ #\bind "M-f n" "buffer-new" #\bind "M-f m" "buffer-new-template" -#\bind "M-f p" "buffer-open" +#\bind "M-f p" "file-open" #\bind "M-f g" "buffer-close" #\bind "M-f s" "buffer-write" #\bind "M-f o" "buffer-write-as" diff --git a/lib/bind/xemacs.bind b/lib/bind/xemacs.bind index 3e211275b8..668d73d210 100644 --- a/lib/bind/xemacs.bind +++ b/lib/bind/xemacs.bind @@ -96,7 +96,7 @@ \bind "C-x C-b" "menu-open documents" # list all buffers \bind "C-x C-c" "lyx-quit" \bind "C-x C-d" "buffer-new" -\bind "C-x C-f" "buffer-open" +\bind "C-x C-f" "file-open" \bind "C-x C-g" "buffer-view ps" \bind "C-x C-l" "word-lowcase" # downcase-region! \bind "C-x C-p" "buffer-view dvi" @@ -121,7 +121,7 @@ #bind "F1" "help" # Not yet implemented! #bind "C-F1" "help-context" # Not yet implemented! #\bind "F2" "buffer-write" -#\bind "F3" "buffer-open" +#\bind "F3" "file-open" #bind "F4" "------" #bind "F5" "------" #bind "F6" "------" diff --git a/lib/images/buffer-open.xpm b/lib/images/file-open.xpm similarity index 100% rename from lib/images/buffer-open.xpm rename to lib/images/file-open.xpm diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 2d7192e665..50ead52ec3 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -28,7 +28,7 @@ Menuset Menu "file_nobuffer" Item "New...|N" "buffer-new" Item "New from Template...|T" "buffer-new-template" - Item "Open...|O" "buffer-open" + Item "Open...|O" "file-open" Separator Submenu "Import|I" "file_import" Separator @@ -40,7 +40,7 @@ Menuset Menu "file" Item "New...|N" "buffer-new" Item "New from Template...|T" "buffer-new-template" - Item "Open...|O" "buffer-open" + Item "Open...|O" "file-open" Separator Item "Close|C" "buffer-close" Item "Save|S" "buffer-write" @@ -219,8 +219,8 @@ Menuset Menu "insert_file" Item "LyX Document...|X" "file-insert" - Item "Ascii as Lines...|L" "file-insert-ascii lines" - Item "Ascii as Paragraphs...|P" "file-insert-ascii paragraphs" + Item "Ascii as Lines...|L" "file-insert-ascii" + Item "Ascii as Paragraphs...|P" "file-insert-ascii-para" End # @@ -335,7 +335,7 @@ End Toolbar Layouts - Icon "buffer-open" + Icon "file-open" Icon "buffer-write" Icon "buffer-print" Separator diff --git a/po/POTFILES.in b/po/POTFILES.in index 61022eaf3d..023141b20f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -13,7 +13,6 @@ src/CutAndPaste.C src/debug.C src/exporter.C src/ext_l10n.h -src/filedlg.C src/FontLoader.C src/form1.C src/frontends/gnome/FormCitation.C @@ -43,6 +42,7 @@ src/frontends/kde/dlg/parageneraldlgdata.C src/frontends/kde/dlg/printdlgdata.C src/frontends/kde/dlg/tabcreatedlgdata.C src/frontends/kde/docdlg.C +src/frontends/kde/FileDialog.C src/frontends/kde/FormCitation.C src/frontends/kde/FormCopyright.C src/frontends/kde/FormDocument.C @@ -72,6 +72,7 @@ src/frontends/qt2/FormSearch.C src/frontends/qt2/FormTabularCreate.C src/frontends/qt2/paragraphdlgimpl.C src/frontends/qt2/tabularcreatedlgimpl.C +src/frontends/xforms/FileDialog.C src/frontends/xforms/FormBase.h src/frontends/xforms/form_bibitem.C src/frontends/xforms/FormBibitem.C @@ -88,6 +89,8 @@ src/frontends/xforms/form_document.C src/frontends/xforms/FormDocument.C src/frontends/xforms/form_error.C src/frontends/xforms/FormError.C +src/frontends/xforms/form_filedialog.C +src/frontends/xforms/FormFiledialog.C src/frontends/xforms/form_graphics.C src/frontends/xforms/FormGraphics.C src/frontends/xforms/form_include.C diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index ef248328b9..152a5bf0c5 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -30,7 +30,7 @@ #include "insets/insettext.h" /// added for Dispatch functions #include "lyx_cb.h" -#include "filedlg.h" +#include "frontends/FileDialog.h" #include "lyx_main.h" #include "FloatList.h" #include "support/filetools.h" @@ -1424,7 +1424,6 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen) if (filename.empty()) { // Launch a file browser string initpath = lyxrc.document_path; - LyXFileDlg fileDlg; if (available()) { string const trypath = owner_->buffer()->filepath; @@ -1433,21 +1432,24 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen) initpath = trypath; } - // launches dialog - ProhibitInput(bv_); - fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); - fileDlg.SetButton(1, _("Examples"), - AddPath(system_lyxdir, "examples")); - filename = fileDlg.Select(_("Select Document to Insert"), - initpath, "*.lyx"); - AllowInput(bv_); + FileDialog fileDlg(bv_->owner(), _("Select LyX document to insert"), + LFUN_FILE_INSERT, + make_pair(string(_("Documents")), string(lyxrc.document_path)), + make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples")))); + + FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx| LyX Documents (*.lyx)")); + + if (result.first == FileDialog::Later) + return; + + filename = result.second; // check selected filename if (filename.empty()) { owner_->getMiniBuffer()->Set(_("Canceled.")); return; } - } + } // get absolute path of file and make sure the filename ends // with .lyx @@ -1618,12 +1620,13 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) } break; + case LFUN_FILE_INSERT_ASCII_PARA: + InsertAsciiFile(bv_, argument, true); + break; + case LFUN_FILE_INSERT_ASCII: - { - bool asPara = (argument == "paragraph"); - InsertAsciiFile(bv_, string(), asPara); - } - break; + InsertAsciiFile(bv_, argument, false); + break; case LFUN_LAYOUT: { diff --git a/src/ChangeLog b/src/ChangeLog index fd8057f05a..e0eb0352e6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2001-03-06 John Levon + + * Makefile.am: + * filedlg.h: + * filedlg.C: + * LyXAction.C: + * ToolbarDefaults.C: + * bufferlist.C: + * commandtags.h: + * form1.C: + * form1.h: + * lyx_cb.C: + * lyx_cb.h: + * lyxfunc.h: + * lyxfunc.C: + * BufferView_pimpl.C: use new file dialog in GUII + + * lyx_cb.h: + * lyx_cb.C: remove LayoutsCB to Toolbar + 2001-03-07 Jean-Marc Lasgouttes * ShareContainer.h (get): add std:: qualifier diff --git a/src/LyXAction.C b/src/LyXAction.C index ee540e3fa8..e2ff7d3b71 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -140,7 +140,6 @@ void LyXAction::init() { LFUN_MENUNEW, "buffer-new", N_("New document") , NoBuffer }, { LFUN_MENUNEWTMPLT,"buffer-new-template", N_("New document from template"), NoBuffer }, - { LFUN_MENUOPEN, "buffer-open", N_("Open"), NoBuffer }, { LFUN_MENUPRINT, "buffer-print", N_("Print"), ReadOnly }, { LFUN_MENURELOAD, "buffer-reload", N_("Revert to saved"), ReadOnly }, @@ -151,7 +150,7 @@ void LyXAction::init() { LFUN_UPDATE, "buffer-update", N_("Update"), ReadOnly }, { LFUN_PREVIEW, "buffer-view", N_("View") , ReadOnly }, { LFUN_MENUWRITE, "buffer-write", N_("Save"), ReadOnly }, - { LFUN_MENUWRITEAS, "buffer-write-as", N_("Save As"), + { LFUN_WRITEAS, "buffer-write-as", N_("Save As"), ReadOnly }, { LFUN_CANCEL, "cancel", N_("Cancel"), NoBuffer }, { LFUN_INSET_CAPTION, "caption-insert", "", Noop }, @@ -197,9 +196,10 @@ void LyXAction::init() { LFUN_INSET_GRAPHICS, "graphics-insert", N_("Insert Graphics"), Noop }, { LFUN_FILE_INSERT, "file-insert", "", Noop }, - { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", "", Noop }, + { LFUN_FILE_INSERT_ASCII, "file-insert-ascii", _("Insert ASCII files as lines"), Noop }, + { LFUN_FILE_INSERT_ASCII_PARA, "file-insert-ascii-para", _("Insert ASCII file as a paragraph"), Noop }, { LFUN_FILE_NEW, "file-new", "", NoBuffer }, - { LFUN_FILE_OPEN, "file-open", "", NoBuffer }, + { LFUN_FILE_OPEN, "file-open", _("Open a file"), NoBuffer }, { LFUN_MENUSEARCH, "find-replace", N_("Find & Replace"), ReadOnly }, { LFUN_INSET_FLOAT, "float-insert", "", Noop }, diff --git a/src/Makefile.am b/src/Makefile.am index e35a6bf740..57a8ffc175 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -117,8 +117,6 @@ lyx_SOURCES = \ exporter.h \ ext_l10n.h \ figure.h \ - filedlg.C \ - filedlg.h \ font.C \ font.h \ form1.C \ diff --git a/src/ToolbarDefaults.C b/src/ToolbarDefaults.C index d92b09e86f..656949e45e 100644 --- a/src/ToolbarDefaults.C +++ b/src/ToolbarDefaults.C @@ -46,7 +46,7 @@ void ToolbarDefaults::add(int action) void ToolbarDefaults::init() { add(LAYOUTS); - add(LFUN_MENUOPEN); + add(LFUN_FILE_OPEN); //add(LFUN_CLOSEBUFFER); add(LFUN_MENUWRITE); add(LFUN_MENUPRINT); diff --git a/src/bufferlist.C b/src/bufferlist.C index 3f44776364..900cda89df 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -113,7 +113,7 @@ bool BufferList::QwriteAll() _("Save document?"))) { case 1: // Yes if ((*it)->isUnnamed()) - reask = !MenuWriteAs(current_view, (*it)); + reask = !WriteAs(current_view, (*it)); else { reask = !MenuWrite(current_view, (*it)); } @@ -189,7 +189,7 @@ bool BufferList::close(Buffer * buf) _("Save document?"))){ case 1: // Yes if (buf->isUnnamed()) - reask = !MenuWriteAs(current_view, buf); + reask = !WriteAs(current_view, buf); else if (buf->save()) { lastfiles->newFile(buf->fileName()); reask = false; diff --git a/src/commandtags.h b/src/commandtags.h index e5c81a2a2b..308ae4f6ca 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -16,15 +16,15 @@ Please add new functions at the end of the enum, right before LFUN_LASTACTION. */ + enum kb_action { LFUN_UNKNOWN_ACTION = -1, LFUN_NOACTION = 0, LFUN_PREFIX, LFUN_CENTER, LFUN_MENUNEW, - LFUN_MENUOPEN, LFUN_MENUWRITE, - LFUN_MENUWRITEAS, + LFUN_WRITEAS, LFUN_MENUPRINT, LFUN_MENUSENDTO, LFUN_BUILDPROG, @@ -177,6 +177,7 @@ enum kb_action { LFUN_EXEC_COMMAND, LFUN_FILE_INSERT, LFUN_FILE_INSERT_ASCII, // CFO-G 1997-11-19 + LFUN_FILE_INSERT_ASCII_PARA, // Levon 2001-02-14 LFUN_FILE_NEW, LFUN_FILE_OPEN, // 160 LFUN_UP_PARAGRAPH, // Asger 1996-10-01 @@ -274,6 +275,7 @@ enum kb_action { LFUN_BOOKMARK_SAVE, // Dekel 20010127 LFUN_BOOKMARK_GOTO, // Dekel 20010127 LFUN_CHILD_CREATE, // Levon 20010207 + LFUN_SELECT_FILE_SYNC, // Levon 20010214 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/form1.C b/src/form1.C index e05c888575..55194284a9 100644 --- a/src/form1.C +++ b/src/form1.C @@ -217,60 +217,3 @@ FD_Figure *create_form_Figure(void) return fdui; } /*---------------------------------------*/ - -FD_FileDlg *create_form_FileDlg(void) -{ - FL_OBJECT *obj; - FD_FileDlg *fdui = (FD_FileDlg *) fl_calloc(1, sizeof(FD_FileDlg)); - - fdui->FileDlg = fl_bgn_form(FL_NO_BOX, 440, 380); - obj = fl_add_box(FL_UP_BOX, 0, 0, 440, 380, ""); - fdui->FileInfo = obj = fl_add_text(FL_NORMAL_TEXT, 10, 260, 420, 30, ""); - fl_set_object_boxtype(obj, FL_SHADOW_BOX); - fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE); - fl_set_object_gravity(obj, FL_SouthWest, FL_SouthEast); - fl_set_object_resize(obj, FL_RESIZE_X); - fdui->DirBox = obj = fl_add_input(FL_NORMAL_INPUT, 100, 10, 330, 30, idex(_("Directory:|#D")));fl_set_button_shortcut(obj, scex(_("Directory:|#D")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); - fl_set_object_resize(obj, FL_RESIZE_X); - fdui->PatBox = obj = fl_add_input(FL_NORMAL_INPUT, 100, 40, 330, 30, idex(_("Pattern:|#P")));fl_set_button_shortcut(obj, scex(_("Pattern:|#P")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); - fl_set_object_resize(obj, FL_RESIZE_X); - fdui->List = obj = fl_add_browser(FL_HOLD_BROWSER, 10, 80, 320, 170, ""); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_lalign(obj, FL_ALIGN_TOP); - fl_set_object_gravity(obj, FL_NorthWest, FL_SouthEast); - fdui->Filename = obj = fl_add_input(FL_NORMAL_INPUT, 100, 300, 330, 30, idex(_("Filename:|#F")));fl_set_button_shortcut(obj, scex(_("Filename:|#F")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthWest, FL_SouthEast); - fl_set_object_resize(obj, FL_RESIZE_X); - fdui->Rescan = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 80, 90, 30, idex(_("Rescan|#R#r")));fl_set_button_shortcut(obj, scex(_("Rescan|#R#r")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); - fdui->Home = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 120, 90, 30, idex(_("Home|#H#h")));fl_set_button_shortcut(obj, scex(_("Home|#H#h")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); - fdui->User1 = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 160, 90, 30, idex(_("User1|#1")));fl_set_button_shortcut(obj, scex(_("User1|#1")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); - fdui->User2 = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 200, 90, 30, idex(_("User2|#2")));fl_set_button_shortcut(obj, scex(_("User2|#2")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); - fdui->Ready = obj = fl_add_button(FL_RETURN_BUTTON, 220, 340, 100, 30, _("OK")); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); - fdui->Cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 330, 340, 100, 30, idex(_("Cancel|^[")));fl_set_button_shortcut(obj, scex(_("Cancel|^[")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); - fdui->timer = obj = fl_add_timer(FL_HIDDEN_TIMER, 10, 350, 20, 20, ""); - fl_set_object_gravity(obj, FL_SouthWest, FL_SouthWest); - fl_end_form(); - - fdui->FileDlg->fdui = fdui; - - return fdui; -} -/*---------------------------------------*/ - diff --git a/src/form1.h b/src/form1.h index ed1ecd820c..b713abc5f9 100644 --- a/src/form1.h +++ b/src/form1.h @@ -67,26 +67,6 @@ typedef struct { } FD_Figure; extern FD_Figure * create_form_Figure(void); -typedef struct { - FL_FORM *FileDlg; - void *vdata; - char *cdata; - long ldata; - FL_OBJECT *FileInfo; - FL_OBJECT *DirBox; - FL_OBJECT *PatBox; - FL_OBJECT *List; - FL_OBJECT *Filename; - FL_OBJECT *Rescan; - FL_OBJECT *Home; - FL_OBJECT *User1; - FL_OBJECT *User2; - FL_OBJECT *Ready; - FL_OBJECT *Cancel; - FL_OBJECT *timer; -} FD_FileDlg; - -extern FD_FileDlg * create_form_FileDlg(void); typedef struct { FL_FORM *form_search; void *vdata; diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 910130f8c7..b5d61f7184 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,8 @@ +2001-02-26 John Levon + + * Makefile.am + * FileDialog.h: new GUII FileDialog + 2001-02-23 Edwin Leuven +#include + +#include "commandtags.h" + +#include "LString.h" + +class LyXView; + +/** + * \class FileDialog + * \brief GUI-I definition of file dialog interface + */ +class FileDialog +{ +public: + /// label, directory path button + typedef std::pair Button; + + /// result type + enum ResultType { + Later, /**< modeless chooser, no result */ + Chosen /**< string contains filename */ + }; + + /// result return + typedef std::pair Result; + + /** + * 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(), + * otherwise a callback Dispatch() will be invoked with the filename as + * argument, of action \param a. + * + * Up to two optional extra buttons are allowed for specifying addtional + * directories in the navigation. + */ + FileDialog(LyXView * lv, string const & title, kb_action a = LFUN_SELECT_FILE_SYNC, + Button b1 = Button(string(), string()), + Button b2 = Button(string(), string())); + + + ~FileDialog(); + + /** + * Choose a file for selection, 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)". + * + * FIXME: should support multiple lines of these for different file types. + */ + Result const Select(string const & path = string(), + string const & mask = string(), + string const & suggested = string()); + + + /* This *has* to be public because there is no way to specify extern "C" functions + * as friends of Private implementation for the xforms implementation ... grr + */ + class Private; + friend class Private; + Private * private_; + +private: + /// our LyXView + LyXView * lv_; + + /// the dialog title + string title_; + + /// success action to perform if not synchronous + kb_action success_; + +}; + +#endif // FILEDIALOG_H diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index 841350c66c..7dc63a1892 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -15,6 +15,7 @@ libfrontends_la_SOURCES=\ ButtonPolicies.h \ Dialogs.h \ DialogBase.h \ + FileDialog.h \ GUIRunTime.h \ Liason.C \ Liason.h \ diff --git a/src/frontends/kde/ChangeLog b/src/frontends/kde/ChangeLog index 86a6d05db6..6eaca56be5 100644 --- a/src/frontends/kde/ChangeLog +++ b/src/frontends/kde/ChangeLog @@ -1,3 +1,15 @@ +2001-02-26 John Levon + + * : remove noncopyable (now inherited from DialogBase) + + * Makefile.am: + * FileDialog.C: + * FileDialog_private.C: + * moc/Makefile.am: + * FileDialog_private.h: add File Dialog + + * docdlg.C: remove DEFAULT_LANGUAGE stuff + 2001-02-26 Dekel Tsur * FormRef.C (apply): Update bookmark #0 after inserting a reference. diff --git a/src/frontends/kde/Dialogs.C b/src/frontends/kde/Dialogs.C index d2e932df8f..90c6d83dd7 100644 --- a/src/frontends/kde/Dialogs.C +++ b/src/frontends/kde/Dialogs.C @@ -46,6 +46,7 @@ Signal0 Dialogs::redrawGUI; Dialogs::Dialogs(LyXView * lv) { +/* dialogs_.push_back(new FormBibitem(lv, this)); dialogs_.push_back(new FormBibtex(lv, this)); dialogs_.push_back(new FormCitation(lv, this)); @@ -72,6 +73,7 @@ Dialogs::Dialogs(LyXView * lv) // reduce the number of connections needed in // dialogs by a simple connection here. hideAll.connect(hideBufferDependent.slot()); +*/ } diff --git a/src/frontends/kde/FileDialog.C b/src/frontends/kde/FileDialog.C new file mode 100644 index 0000000000..83bf5cea4f --- /dev/null +++ b/src/frontends/kde/FileDialog.C @@ -0,0 +1,79 @@ +/** + * \file FileDialog.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include +#include + +#include "commandtags.h" + +#include "LString.h" + +#include "frontends/FileDialog.h" + +#include "FileDialog_private.h" + +#include "debug.h" + +using std::make_pair; +using std::pair; +using std::endl; + +FileDialog::FileDialog(LyXView *lv, string const &t, kb_action s, Button b1, Button b2) + : private_(0), lv_(lv), title_(t), success_(s) +{ + // FIXME +} + + +FileDialog::~FileDialog() +{ +} + + +FileDialog::Result const FileDialog::Select(string const & path, string const & mask, string const & suggested) +{ + string filter = mask; + + if (mask.empty()) + filter = _("*|All files"); + + LyXKFileDialog * dlg = new LyXKFileDialog(lv_, success_, path, filter, title_); + + lyxerr[Debug::GUI] << "Select with path \"" << path << "\", mask \"" << filter << "\", suggested \"" << suggested << endl; + + if (!suggested.empty()) + dlg->setSelection(suggested.c_str()); + + 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()); + + delete dlg; + + return result; + } + + dlg->show(); + + return make_pair(FileDialog::Later, string()); +} diff --git a/src/frontends/kde/FileDialog_private.C b/src/frontends/kde/FileDialog_private.C new file mode 100644 index 0000000000..8fec50f9a4 --- /dev/null +++ b/src/frontends/kde/FileDialog_private.C @@ -0,0 +1,39 @@ +/** + * \file FileDialog_private.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#include + +#include "LString.h" + +#include +#include + +#include "QtLyXView.h" +#include "debug.h" + +#include "FileDialog_private.h" + +LyXKFileDialog::LyXKFileDialog(LyXView * lv, kb_action a, string const & p, string const & m, string const & t) + : KFileDialog(p.c_str(), m.c_str(), KApplication::getKApplication()->topWidget(), t.c_str(), a == LFUN_SELECT_FILE_SYNC, false), + lv_(lv), action_(a) +{ + setCaption(t.c_str()); +} + + +void LyXKFileDialog::done(int what) +{ + lyxerr[Debug::GUI] << "Done FileDialog, value " << what << endl; + + if (action_ == LFUN_SELECT_FILE_SYNC) { + QDialog::done(what); + return; + } else if (what == QDialog::Accepted) + lv_->getLyXFunc()->Dispatch(action_, selectedFile().data()); + delete this; +} diff --git a/src/frontends/kde/FileDialog_private.h b/src/frontends/kde/FileDialog_private.h new file mode 100644 index 0000000000..b055981315 --- /dev/null +++ b/src/frontends/kde/FileDialog_private.h @@ -0,0 +1,38 @@ +/** + * \file FileDialog_private.h + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#ifndef FILEDIALOG_PRIVATE_H +#define FILEDIALOG_PRIVATE_H + +#include + +#include + +#include "LString.h" +#include "lyxfunc.h" + +#include "frontends/FileDialog.h" + +class LyXView; + +class LyXKFileDialog : public KFileDialog +{ +public: + LyXKFileDialog(LyXView * lv, kb_action a, string const & p, string const & m, string const & t); + + friend class FileDialog; + +protected: + virtual void done(int); + +private: + LyXView * lv_; + int action_; +}; + +#endif // FILEDIALOG_PRIVATE_H diff --git a/src/frontends/kde/FormCitation.h b/src/frontends/kde/FormCitation.h index 3b7fc4b9d4..8c8c11c071 100644 --- a/src/frontends/kde/FormCitation.h +++ b/src/frontends/kde/FormCitation.h @@ -20,7 +20,7 @@ class Dialogs; class LyXView; class CitationDialog; -class FormCitation : public DialogBase, public noncopyable { +class FormCitation : public DialogBase { public: FormCitation(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormCopyright.h b/src/frontends/kde/FormCopyright.h index abcecbc0d0..da1a4dea46 100644 --- a/src/frontends/kde/FormCopyright.h +++ b/src/frontends/kde/FormCopyright.h @@ -15,7 +15,7 @@ class Dialogs; class LyXView; class CopyrightDialog; -class FormCopyright : public DialogBase, public noncopyable { +class FormCopyright : public DialogBase { public: FormCopyright(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormDocument.h b/src/frontends/kde/FormDocument.h index dd0f74710d..921f27a9df 100644 --- a/src/frontends/kde/FormDocument.h +++ b/src/frontends/kde/FormDocument.h @@ -22,7 +22,7 @@ class BufferParams; /** * \brief the LyXian side of the complex Document dialog */ -class FormDocument : public DialogBase, public noncopyable { +class FormDocument : public DialogBase { public: FormDocument(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormIndex.h b/src/frontends/kde/FormIndex.h index f413e2dc81..65c15b966d 100644 --- a/src/frontends/kde/FormIndex.h +++ b/src/frontends/kde/FormIndex.h @@ -18,7 +18,7 @@ class Dialogs; class LyXView; class IndexDialog; -class FormIndex : public DialogBase, public noncopyable { +class FormIndex : public DialogBase { public: FormIndex(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormLog.h b/src/frontends/kde/FormLog.h index 1ca8e5e0b9..eeb9005cc8 100644 --- a/src/frontends/kde/FormLog.h +++ b/src/frontends/kde/FormLog.h @@ -18,7 +18,7 @@ class Dialogs; class LyXView; class LogDialog; -class FormLog : public DialogBase, public noncopyable { +class FormLog : public DialogBase { public: FormLog(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormParagraph.h b/src/frontends/kde/FormParagraph.h index b00dde16fe..c822b6b92b 100644 --- a/src/frontends/kde/FormParagraph.h +++ b/src/frontends/kde/FormParagraph.h @@ -17,7 +17,7 @@ class Dialogs; class LyXView; class ParaDialog; -class FormParagraph : public DialogBase, public noncopyable { +class FormParagraph : public DialogBase { public: FormParagraph(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormPrint.h b/src/frontends/kde/FormPrint.h index 4d640873e2..b27e9518e0 100644 --- a/src/frontends/kde/FormPrint.h +++ b/src/frontends/kde/FormPrint.h @@ -20,7 +20,7 @@ class PrintDialog; using SigC::Connection; #endif -class FormPrint : public DialogBase, public noncopyable { +class FormPrint : public DialogBase { public: FormPrint(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormRef.h b/src/frontends/kde/FormRef.h index 110a8d1ed3..969cab5b27 100644 --- a/src/frontends/kde/FormRef.h +++ b/src/frontends/kde/FormRef.h @@ -18,7 +18,7 @@ class Dialogs; class LyXView; class RefDialog; -class FormRef : public DialogBase, public noncopyable { +class FormRef : public DialogBase { public: FormRef(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormTabularCreate.h b/src/frontends/kde/FormTabularCreate.h index d250aaf999..1339fcebde 100644 --- a/src/frontends/kde/FormTabularCreate.h +++ b/src/frontends/kde/FormTabularCreate.h @@ -15,7 +15,7 @@ class Dialogs; class LyXView; class TabularCreateDialog; -class FormTabularCreate : public DialogBase, public noncopyable { +class FormTabularCreate : public DialogBase { public: FormTabularCreate(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormToc.h b/src/frontends/kde/FormToc.h index 426ddfd203..2cc6d6b7a5 100644 --- a/src/frontends/kde/FormToc.h +++ b/src/frontends/kde/FormToc.h @@ -18,7 +18,7 @@ class Dialogs; class TocDialog; -class FormToc : public DialogBase, public noncopyable { +class FormToc : public DialogBase { public: FormToc(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormUrl.h b/src/frontends/kde/FormUrl.h index c882722d9a..fa91ed977a 100644 --- a/src/frontends/kde/FormUrl.h +++ b/src/frontends/kde/FormUrl.h @@ -18,7 +18,7 @@ class Dialogs; class LyXView; class UrlDialog; -class FormUrl : public DialogBase, public noncopyable { +class FormUrl : public DialogBase { public: FormUrl(LyXView *, Dialogs *); diff --git a/src/frontends/kde/FormVCLog.h b/src/frontends/kde/FormVCLog.h index 1fc349650f..193a550e67 100644 --- a/src/frontends/kde/FormVCLog.h +++ b/src/frontends/kde/FormVCLog.h @@ -18,7 +18,7 @@ class Dialogs; class LyXView; class LogDialog; -class FormVCLog : public DialogBase, public noncopyable { +class FormVCLog : public DialogBase { public: FormVCLog(LyXView *, Dialogs *); diff --git a/src/frontends/kde/Makefile.am b/src/frontends/kde/Makefile.am index 35adde245c..804c6222aa 100644 --- a/src/frontends/kde/Makefile.am +++ b/src/frontends/kde/Makefile.am @@ -48,6 +48,9 @@ LDFLAGS= $(libkde_la_OBJADD) ETAGS_ARGS = --lang=c++ libkde_la_SOURCES = \ Dialogs.C \ + FileDialog.C \ + FileDialog_private.C \ + FileDialog_private.h \ GUIRunTime.C \ QtLyXView.h \ Timeout_pimpl.C \ @@ -103,6 +106,7 @@ libkde_la_SOURCES = \ urldlg.C \ urldlg.h +moc/FileDialog_private_moc.C: FileDialog_private.C FileDialog_private.h moc/citationdlg_moc.C: citationdlg.C citationdlg.h moc/copyrightdlg_moc.C: copyrightdlg.C copyrightdlg.h moc/docdlg_moc.C: docdlg.C docdlg.h diff --git a/src/frontends/kde/docdlg.C b/src/frontends/kde/docdlg.C index 5d4d0278e4..db47b2a4cc 100644 --- a/src/frontends/kde/docdlg.C +++ b/src/frontends/kde/docdlg.C @@ -138,9 +138,6 @@ DocDialog::DocDialog(FormDocument * form, QWidget * parent, char const * name, b geometry->margins->insertItem(_("A4 very wide margins")); setSizeHint(geometry->margins); -#ifdef DO_USE_DEFAULT_LANGUAGE - language->language->insertItem(_("default")); -#endif for (Languages::const_iterator cit = languages.begin(); cit != languages.end(); ++cit) language->language->insertItem((*cit).second.lang().c_str()); diff --git a/src/frontends/kde/moc/Makefile.am b/src/frontends/kde/moc/Makefile.am index 418c2473ac..57b76e12e2 100644 --- a/src/frontends/kde/moc/Makefile.am +++ b/src/frontends/kde/moc/Makefile.am @@ -5,7 +5,8 @@ BOOST_INCLUDES = -I$(top_srcdir)/boost INCLUDES = -I${top_srcdir}/src/ -I${top_srcdir}/src/frontends/ \ ${SIGC_CFLAGS} ${FRONTEND_INCLUDES} ${BOOST_INCLUDES} -libkdemoc_la_SOURCES = citationdlg_moc.C \ +libkdemoc_la_SOURCES = FileDialog_private_moc.C \ + citationdlg_moc.C \ copyrightdlg_moc.C \ docdlg_moc.C \ indexdlg_moc.C \ @@ -24,6 +25,8 @@ DISTCLEANFILES = $(libkdemoc_la_SOURCES) *.orig *.rej *~ *.bak core LIBS= ETAGS_ARGS = --lang=c++ +FileDialog_private_moc.C: ../FileDialog_private.h + $(MOC) $< -o $@ citationdlg_moc.C: ../citationdlg.h $(MOC) $< -o $@ copyrightdlg_moc.C: ../copyrightdlg.h diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 3fc29337b4..2dddf0be2a 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,23 @@ +2001-03-06 John Levon + + * Makefile.am: + * FileDialog.C: + * FormFiledialog.C: + * FormFiledialog.h: + * form_filedialog.C: + * form_filedialog.h: + * FormGraphics.C: + * FormInclude.C: + * FormPreferences.C: + * FormPrint.C: + * xforms_helpers.C: + * xforms_helpers.h: + * forms/fdfix.sh: + * forms/makefile: + * form/form_filedialog.fd: add File Dialog + * Toolbar_pimpl.h: + * Toolbar_pimpl.C: move LayoutsCB to here + 2001-03-06 Lars Gullik Bjønnes * FormParagraph.C: changes because of ParagraphParameters. diff --git a/src/frontends/xforms/FileDialog.C b/src/frontends/xforms/FileDialog.C new file mode 100644 index 0000000000..d64f0e9a61 --- /dev/null +++ b/src/frontends/xforms/FileDialog.C @@ -0,0 +1,80 @@ +/** + * \file FileDialog.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include +#include + +#include "commandtags.h" + +#include "support/lstrings.h" + +// temp. hack until Allow/ProhibitInput is not +// needed any more in src/ - for now it's simplest +// to leave it there +#include "LyXView.h" +#include "bufferview_funcs.h" + +#include "frontends/FileDialog.h" + +#include "FormFiledialog.h" + +#include "debug.h" + +using std::make_pair; +using std::pair; +using std::endl; + +FileDialog::FileDialog(LyXView *lv, string const &t, kb_action s, Button b1, Button b2) + : private_(0), lv_(lv), title_(t), success_(s) +{ + private_ = new FileDialog::Private(); + + private_->SetButton(0, b1.first, b1.second); + private_->SetButton(1, b2.first, b2.second); +} + + +FileDialog::~FileDialog() +{ + delete private_; + private_ = 0; +} + + +FileDialog::Result const FileDialog::Select(string const & path, string const & mask, string const & suggested) +{ + string filter = mask; + + if (mask.empty()) + filter = _("*"); + else { + rsplit(mask, filter, '|'); + if (filter.empty()) + filter = mask; + } + + lyxerr[Debug::GUI] << "Select with path \"" << path << "\", mask \"" << filter << "\", suggested \"" << suggested << "\"" << endl; + + // no support for asynchronous selection yet + + ProhibitInput(lv_->view()); + + FileDialog::Result result; + + result.first = FileDialog::Chosen; + result.second = private_->Select(title_, path, filter, suggested); + + AllowInput(lv_->view()); + + return result; +} diff --git a/src/filedlg.C b/src/frontends/xforms/FormFiledialog.C similarity index 85% rename from src/filedlg.C rename to src/frontends/xforms/FormFiledialog.C index 2b6949034a..c9a9700e5e 100644 --- a/src/filedlg.C +++ b/src/frontends/xforms/FormFiledialog.C @@ -1,13 +1,11 @@ -// -*- C++ -*- -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. +/** + * \file FormFiledialog.C + * Copyright 2001 the LyX Team + * Read the file COPYING * - * ====================================================== */ + * \author unknown + * \author John Levon + */ #include @@ -23,7 +21,7 @@ using std::map; using std::max; using std::sort; -#include "lyx_gui_misc.h" // CancelCloseCB +#include "lyx_gui_misc.h" // for WriteFSAlert #include "support/FileInfo.h" #include "support/lyxlib.h" #include "gettext.h" @@ -61,6 +59,7 @@ using std::sort; # endif #endif +// FIXME: should be autoconfiscated #ifdef BROKEN_HEADERS extern "C" int gettimeofday(struct timeval *, struct timezone *); #endif @@ -70,7 +69,7 @@ extern "C" int gettimeofday(struct timeval *, struct timezone *); #endif #include "support/filetools.h" -#include "filedlg.h" +#include "FormFiledialog.h" #ifdef SIGC_CXX_NAMESPACES using SigC::slot; @@ -103,7 +102,7 @@ private: }; -void UserCache::add(uid_t ID) const +void UserCache::add(uid_t ID) const { string pszNewName; struct passwd * pEntry; @@ -135,7 +134,7 @@ private: }; -string const & GroupCache::find(gid_t ID) const +string const & GroupCache::find(gid_t ID) const { Groups::const_iterator cit = groups.find(ID); if (cit == groups.end()) { @@ -146,7 +145,7 @@ string const & GroupCache::find(gid_t ID) const } -void GroupCache::add(gid_t ID) const +void GroupCache::add(gid_t ID) const { string pszNewName; struct group * pEntry; @@ -166,20 +165,14 @@ static UserCache lyxUserCache; static GroupCache lyxGroupCache; -// some "C" wrappers around callbacks -extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT *, long lArgument); -extern "C" void C_LyXFileDlg_DoubleClickCB(FL_OBJECT *, long); -extern "C" int C_LyXFileDlg_CancelCB(FL_FORM *, void *); - - // compares two LyXDirEntry objects content (used for sort) class comp_direntry { public: - int operator()(LyXDirEntry const & r1, - LyXDirEntry const & r2) const ; + int operator()(DirEntry const & r1, + DirEntry const & r2) const ; }; - int comp_direntry::operator()(LyXDirEntry const & r1, - LyXDirEntry const & r2) const { + int comp_direntry::operator()(DirEntry const & r1, + DirEntry const & r2) const { bool r1d = suffixIs(r1.pszName, '/'); bool r2d = suffixIs(r2.pszName, '/'); if (r1d && !r2d) return 1; @@ -188,20 +181,20 @@ public: } -// *** LyXFileDlg class implementation +// *** FileDialog::Private class implementation // static members -FD_FileDlg * LyXFileDlg::pFileDlgForm = 0; -LyXFileDlg * LyXFileDlg::pCurrentDlg = 0; +FD_form_filedialog * FileDialog::Private::pFileDlgForm = 0; +FileDialog::Private * FileDialog::Private::pCurrentDlg = 0; // Reread: updates dialog list to match class directory -void LyXFileDlg::Reread() +void FileDialog::Private::Reread() { // Opens directory DIR * pDirectory = ::opendir(pszDirectory.c_str()); if (!pDirectory) { - WriteFSAlert(_("Warning! Couldn't open directory."), + WriteFSAlert(_("Warning! Couldn't open directory."), pszDirectory); pszDirectory = lyx::getcwd(); pDirectory = ::opendir(pszDirectory.c_str()); @@ -240,7 +233,7 @@ void LyXFileDlg::Reread() bool isLink = false, isDir = false; // If the pattern doesn't start with a dot, skip hidden files - if (!pszMask.empty() && pszMask[0] != '.' && + if (!pszMask.empty() && pszMask[0] != '.' && pDirEntry->d_name[0] == '.') continue; @@ -314,7 +307,7 @@ void LyXFileDlg::Reread() } else if (!(isDir = fileInfo.isDir())) continue; - LyXDirEntry tmp; + DirEntry tmp; // Note pszLsEntry is an string! tmp.pszLsEntry = Buffer; @@ -352,7 +345,7 @@ void LyXFileDlg::Reread() // SetDirectory: sets dialog current directory -void LyXFileDlg::SetDirectory(string const & Path) +void FileDialog::Private::SetDirectory(string const & Path) { if (!pszDirectory.empty()) { string TempPath = ExpandPath(Path); // Expand ~/ @@ -363,7 +356,7 @@ void LyXFileDlg::SetDirectory(string const & Path) // SetMask: sets dialog file mask -void LyXFileDlg::SetMask(string const & NewMask) +void FileDialog::Private::SetMask(string const & NewMask) { pszMask = NewMask; fl_set_input(pFileDlgForm->PatBox, pszMask.c_str()); @@ -371,21 +364,21 @@ void LyXFileDlg::SetMask(string const & NewMask) // SetInfoLine: sets dialog information line -void LyXFileDlg::SetInfoLine(string const & Line) +void FileDialog::Private::SetInfoLine(string const & Line) { pszInfoLine = Line; fl_set_object_label(pFileDlgForm->FileInfo, pszInfoLine.c_str()); } -LyXFileDlg::LyXFileDlg() +FileDialog::Private::Private() { pszDirectory = MakeAbsPath(string(".")); pszMask = '*'; - // Creates form if necessary. + // Creates form if necessary. if (!pFileDlgForm) { - pFileDlgForm = create_form_FileDlg(); + pFileDlgForm = build_filedialog(); // Set callbacks. This means that we don't need a patch file fl_set_object_callback(pFileDlgForm->DirBox, C_LyXFileDlg_FileDlgCB, 0); @@ -405,7 +398,7 @@ LyXFileDlg::LyXFileDlg() C_LyXFileDlg_FileDlgCB, 13); // Make sure pressing the close box doesn't crash LyX. (RvdK) - fl_set_form_atclose(pFileDlgForm->FileDlg, + fl_set_form_atclose(pFileDlgForm->form, C_LyXFileDlg_CancelCB, 0); // Register doubleclick callback fl_set_browser_dblclick_callback(pFileDlgForm->List, @@ -415,25 +408,25 @@ LyXFileDlg::LyXFileDlg() fl_hide_object(pFileDlgForm->User1); fl_hide_object(pFileDlgForm->User2); - r_ = Dialogs::redrawGUI.connect(slot(this, &LyXFileDlg::redraw)); + r_ = Dialogs::redrawGUI.connect(slot(this, &FileDialog::Private::redraw)); } -LyXFileDlg::~LyXFileDlg() +FileDialog::Private::~Private() { r_.disconnect(); } -void LyXFileDlg::redraw() +void FileDialog::Private::redraw() { - if (pFileDlgForm->FileDlg && pFileDlgForm->FileDlg->visible) - fl_redraw_form(pFileDlgForm->FileDlg); + if (pFileDlgForm->form && pFileDlgForm->form->visible) + fl_redraw_form(pFileDlgForm->form); } // SetButton: sets file selector user button action -void LyXFileDlg::SetButton(int iIndex, string const & pszName, +void FileDialog::Private::SetButton(int iIndex, string const & pszName, string const & pszPath) { FL_OBJECT * pObject; @@ -459,7 +452,7 @@ void LyXFileDlg::SetButton(int iIndex, string const & pszName, // GetDirectory: gets last dialog directory -string const LyXFileDlg::GetDirectory() const +string const FileDialog::Private::GetDirectory() const { if (!pszDirectory.empty()) return pszDirectory; @@ -469,7 +462,7 @@ string const LyXFileDlg::GetDirectory() const // RunDialog: handle dialog during file selection -bool LyXFileDlg::RunDialog() +bool FileDialog::Private::RunDialog() { force_cancel = false; force_ok = false; @@ -481,8 +474,8 @@ bool LyXFileDlg::RunDialog() if (pObject == pFileDlgForm->Ready) { if (HandleOK()) return true; - } else if (pObject == pFileDlgForm->Cancel - || force_cancel) + } else if (pObject == pFileDlgForm->Cancel + || force_cancel) return false; else if (force_ok) return true; @@ -491,7 +484,7 @@ bool LyXFileDlg::RunDialog() // XForms objects callback (static) -void LyXFileDlg::FileDlgCB(FL_OBJECT *, long lArgument) +void FileDialog::Private::FileDlgCB(FL_OBJECT *, long lArgument) { if (!pCurrentDlg) return; @@ -545,14 +538,14 @@ void LyXFileDlg::FileDlgCB(FL_OBJECT *, long lArgument) } -extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT * ob, long data) +extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT * ob, long data) { - LyXFileDlg::FileDlgCB(ob, data); + FileDialog::Private::FileDlgCB(ob, data); } // Handle callback from list -void LyXFileDlg::HandleListHit() +void FileDialog::Private::HandleListHit() { // set info line int const iSelect = fl_get_browser(pFileDlgForm->List); @@ -565,7 +558,7 @@ void LyXFileDlg::HandleListHit() // Callback for double click in list -void LyXFileDlg::DoubleClickCB(FL_OBJECT *, long) +void FileDialog::Private::DoubleClickCB(FL_OBJECT *, long) { if (pCurrentDlg->HandleDoubleClick()) // Simulate click on OK button @@ -575,12 +568,12 @@ void LyXFileDlg::DoubleClickCB(FL_OBJECT *, long) extern "C" void C_LyXFileDlg_DoubleClickCB(FL_OBJECT * ob, long data) { - LyXFileDlg::DoubleClickCB(ob, data); + FileDialog::Private::DoubleClickCB(ob, data); } // Handle double click from list -bool LyXFileDlg::HandleDoubleClick() +bool FileDialog::Private::HandleDoubleClick() { string pszTemp; @@ -631,7 +624,7 @@ bool LyXFileDlg::HandleDoubleClick() // Handle OK button call -bool LyXFileDlg::HandleOK() +bool FileDialog::Private::HandleOK() { // mask was changed string pszTemp = fl_get_input(pFileDlgForm->PatBox); @@ -670,7 +663,7 @@ bool LyXFileDlg::HandleOK() // Handle Cancel CB from WM close -int LyXFileDlg::CancelCB(FL_FORM *, void *) +int FileDialog::Private::CancelCB(FL_FORM *, void *) { // Simulate a click on the cancel button pCurrentDlg->Force(true); @@ -680,12 +673,12 @@ int LyXFileDlg::CancelCB(FL_FORM *, void *) extern "C" int C_LyXFileDlg_CancelCB(FL_FORM *fl, void *xev) { - return LyXFileDlg::CancelCB(fl, xev); + return FileDialog::Private::CancelCB(fl, xev); } // Simulates a click on OK/Cancel -void LyXFileDlg::Force(bool cancel) +void FileDialog::Private::Force(bool cancel) { if (cancel) { force_cancel = true; @@ -700,7 +693,7 @@ void LyXFileDlg::Force(bool cancel) // Select: launches dialog and returns selected file -string const LyXFileDlg::Select(string const & title, string const & path, +string const FileDialog::Private::Select(string const & title, string const & path, string const & mask, string const & suggested) { // handles new mask and path @@ -719,7 +712,7 @@ string const LyXFileDlg::Select(string const & title, string const & path, int sel = 0; string const filename = OnlyFilename(suggested); if (!filename.empty()) { - for (int i = 0; + for (int i = 0; i < fl_get_browser_maxline(pFileDlgForm->List); ++i) { string s = fl_get_browser_line(pFileDlgForm->List, i + 1); @@ -744,15 +737,15 @@ string const LyXFileDlg::Select(string const & title, string const & path, fl_set_input(pFileDlgForm->Filename, suggested.c_str()); fl_set_button(pFileDlgForm->Cancel, 0); fl_set_button(pFileDlgForm->Ready, 0); - fl_set_focus_object(pFileDlgForm->FileDlg, pFileDlgForm->Filename); + fl_set_focus_object(pFileDlgForm->form, pFileDlgForm->Filename); fl_deactivate_all_forms(); - fl_show_form(pFileDlgForm->FileDlg, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + fl_show_form(pFileDlgForm->form, + FL_PLACE_MOUSE | FL_FREE_SIZE, 0, title.c_str()); isOk = RunDialog(); - fl_hide_form(pFileDlgForm->FileDlg); + fl_hide_form(pFileDlgForm->form); fl_activate_all_forms(); pCurrentDlg = 0; @@ -762,7 +755,7 @@ string const LyXFileDlg::Select(string const & title, string const & path, pszFileName = fl_get_input(pFileDlgForm->Filename); if (!AbsolutePath(pszFileName)) { - pszFileName = AddName(fl_get_input(pFileDlgForm->DirBox), + pszFileName = AddName(fl_get_input(pFileDlgForm->DirBox), pszFileName); } return pszFileName; diff --git a/src/filedlg.h b/src/frontends/xforms/FormFiledialog.h similarity index 68% rename from src/filedlg.h rename to src/frontends/xforms/FormFiledialog.h index 2633d70882..cae5ab4727 100644 --- a/src/filedlg.h +++ b/src/frontends/xforms/FormFiledialog.h @@ -1,35 +1,37 @@ -// -*- C++ -*- -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. +/** + * \file FormFiledialog.h + * Copyright 2001 the LyX Team + * Read the file COPYING * - * ====================================================== */ + * \author unknown + * \author John Levon + */ -#ifndef FILEDLG_H -#define FILEDLG_H +#ifndef FORMFILEDIALOG_H +#define FORMFILEDIALOG_H #ifdef __GNUG__ #pragma interface #endif +#include + #include #include #include "LString.h" #include FORMS_H_LOCATION -#include "form1.h" +#include "form_filedialog.h" + +#include "frontends/FileDialog.h" #ifdef SIGC_CXX_NAMESPACES using SigC::Object; using SigC::Connection; #endif -/// LyXDirEntry internal structure definition -class LyXDirEntry { +/// DirEntry internal structure definition +class DirEntry { public: /// string pszName; @@ -39,25 +41,27 @@ public: string pszLsEntry; }; +extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT * ob, long data); +extern "C" void C_LyXFileDlg_DoubleClickCB(FL_OBJECT * ob, long data); +extern "C" int C_LyXFileDlg_CancelCB(FL_FORM *fl, void *xev); -/// FileDlg class definition -class LyXFileDlg : public Object +class FileDialog::Private : public Object { public: /// - LyXFileDlg(); + Private(); /// - ~LyXFileDlg(); + ~Private(); /// sets file selector user button action - void SetButton(int iIndex, string const & pszName = string(), + void SetButton(int iIndex, string const & pszName = string(), string const & pszPath = string()); /// gets last dialog directory string const GetDirectory() const; /// launches dialog and returns selected file string const Select(string const & pszTitle = string(), string const & pszPath = string(), - string const & pszMask = string(), + string const & pszMask = string(), string const & pszSuggested = string()); /// XForms objects callback (static) static void FileDlgCB(FL_OBJECT *, long); @@ -65,11 +69,12 @@ public: static void DoubleClickCB(FL_OBJECT *, long); /// Handle Cancel CB from WM close static int CancelCB(FL_FORM *, void *); + private: /// data - static FD_FileDlg * pFileDlgForm; + static FD_form_filedialog * pFileDlgForm; /// - static LyXFileDlg * pCurrentDlg; + static FileDialog::Private * pCurrentDlg; /// string pszUserPath1; /// @@ -89,7 +94,7 @@ private: /// string pszInfoLine; /// - typedef std::vector DirEntries; + typedef std::vector DirEntries; /// DirEntries direntries; /// @@ -97,6 +102,9 @@ private: /// bool force_ok; + /// build the dialog + FD_form_filedialog * build_filedialog(); + /** Redraw the form (on receipt of a Signal indicating, for example, that the xform colors have been re-mapped). */ @@ -123,4 +131,4 @@ private: Connection r_; }; -#endif +#endif // FORMFILEDIALOG_H diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index d37fad399d..3d781b1b59 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -357,7 +357,8 @@ void FormGraphics::browse() string const filename = fl_get_input(dialog_->input_filename); string const title = N_("Graphics"); - string const pattern = "*(ps|png)"; + // we need the second '|' to prevent mis-interpretation + string const pattern = "*.(ps|png)|"; // Does user clipart directory exist? string clipdir = AddName (user_lyxdir, "clipart"); @@ -369,7 +370,7 @@ void FormGraphics::browse() // Show the file browser dialog string const new_filename = - browseFile(filename, title, pattern, dir1, + browseFile(lv_, filename, title, pattern, dir1, make_pair(string(), string())); // Save the filename to the dialog diff --git a/src/frontends/xforms/FormInclude.C b/src/frontends/xforms/FormInclude.C index 8abf18ccf8..8389ff38b1 100644 --- a/src/frontends/xforms/FormInclude.C +++ b/src/frontends/xforms/FormInclude.C @@ -8,7 +8,7 @@ */ #include #include -#include +#include #ifdef __GNUG__ #pragma implementation @@ -17,9 +17,9 @@ #include "Dialogs.h" #include "FormInclude.h" #include "insets/insetinclude.h" -#include "filedlg.h" -#include "support/filetools.C" -#include "support/lstrings.h" +#include "frontends/FileDialog.h" +#include "support/filetools.h" +#include "support/lstrings.h" #include "LyXView.h" #include "buffer.h" #include "lyxrc.h" @@ -28,15 +28,13 @@ #include "form_include.h" -using std::cout; +using std::make_pair; +using std::pair; FormInclude::FormInclude(LyXView * lv, Dialogs * d) : FormCommand(lv, d, _("Include file"), new OkCancelPolicy), dialog_(0) { - // let the dialog be shown - // These are permanent connections so we won't bother - // storing a copy because we won't be disconnecting. d->showInclude.connect(slot(this, &FormInclude::showInset)); d->createInclude.connect(slot(this, &FormInclude::createInset)); } @@ -125,7 +123,7 @@ void FormInclude::apply() //inset_->setNoLoad(fl_get_button(dialog_->flag1)); params.setContents(fl_get_input(dialog_->filename)); - cout << params.getContents() << endl; + if (fl_get_button(dialog_->flag2)) params.setCmdName("input"); else if (fl_get_button(dialog_->flag3)) @@ -156,19 +154,19 @@ bool FormInclude::input(FL_OBJECT *, long data) switch (state) { case BROWSE: { // Should browsing too be disabled in RO-mode? - LyXFileDlg fileDlg; + FileDialog fileDlg(lv_, _("Select document to include"), + LFUN_SELECT_FILE_SYNC, + make_pair(string(_("Documents")), string(lyxrc.document_path))); string ext; - fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); - /* input TeX, verbatim, or LyX file ? */ if (fl_get_button(dialog_->flag2)) - ext = "*.tex"; + ext = _("*.tex| LaTeX Documents (*.tex)"); else if (fl_get_button(dialog_->flag4)) - ext = "*"; + ext = _("*| All files "); else - ext = "*.lyx"; + ext = _("*.lyx| LyX Documents (*.lyx)"); string mpath; @@ -176,18 +174,16 @@ bool FormInclude::input(FL_OBJECT *, long data) //if (inset_) // mpath = OnlyPath(inset_->getMasterFilename()); - string const filename = fileDlg.Select(_("Select Child Document"), - mpath, ext, fl_get_input(dialog_->filename)); - XFlush(fl_get_display()); + FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->filename)); // check selected filename - if (filename.empty()) + if (result.second.empty()) break; - string const filename2 = MakeRelPath(filename, mpath); + string const filename2 = MakeRelPath(result.second, mpath); if (prefixIs(filename2, "..")) - fl_set_input(dialog_->filename, filename.c_str()); + fl_set_input(dialog_->filename, result.second.c_str()); else fl_set_input(dialog_->filename, filename2.c_str()); @@ -203,8 +199,7 @@ bool FormInclude::input(FL_OBJECT *, long data) break; case INPUTINCLUDE: - cout << "inputinclude" << endl; - /* huh ? why doesn't this work ? */ + /* FIXME: huh ? why doesn't this work ? */ setEnabled(dialog_->flag41, false); fl_set_button(dialog_->flag41, 0); break; diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 783abb3498..dbeaae8e33 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -2931,7 +2931,7 @@ void FormPreferences::browse(FL_OBJECT * inpt, // Show the file browser dialog string const new_filename = - browseFile(filename, title, pattern, dir1, dir2); + browseFile(lv_, filename, title, pattern, dir1, dir2); // Save the filename to the dialog if (new_filename != filename && !new_filename.empty()) { diff --git a/src/frontends/xforms/FormPrint.C b/src/frontends/xforms/FormPrint.C index e7881bc39d..b9d9542b24 100644 --- a/src/frontends/xforms/FormPrint.C +++ b/src/frontends/xforms/FormPrint.C @@ -263,7 +263,7 @@ void FormPrint::browse() // Show the file browser dialog string const new_filename = - browseFile(filename, title, pattern, + browseFile(lv_, filename, title, pattern, make_pair(string(), string()), make_pair(string(), string())); diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index a4489c5259..95d4205ce7 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -17,6 +17,11 @@ libxforms_la_SOURCES = \ Color.C \ Color.h \ Dialogs.C \ + FileDialog.C \ + FormFiledialog.h \ + FormFiledialog.C \ + form_filedialog.C \ + form_filedialog.h \ GUIRunTime.C \ FormBase.C \ FormBase.h \ diff --git a/src/frontends/xforms/Toolbar_pimpl.C b/src/frontends/xforms/Toolbar_pimpl.C index f86ea7f5ea..6d18cbdc87 100644 --- a/src/frontends/xforms/Toolbar_pimpl.C +++ b/src/frontends/xforms/Toolbar_pimpl.C @@ -27,12 +27,11 @@ #include "buffer.h" #include "LyXAction.h" #include "support/filetools.h" +#include "support/lstrings.h" #include "gettext.h" using std::endl; -// this one is not "C" because combox callbacks are really C++ %-| -extern void LayoutsCB(int, void *, Combox *); extern char const ** get_pixmap_from_symbol(char const * arg, int, int); extern LyXAction lyxaction; @@ -115,7 +114,7 @@ extern "C" void C_Toolbar_BubbleTimerCB(FL_OBJECT * ob, long data) static int BubblePost(FL_OBJECT *ob, int event, FL_Coord /*mx*/, FL_Coord /*my*/, - int /*key*/, void */*xev*/) + int /*key*/, void * /*xev*/) { FL_OBJECT * bubble_timer = reinterpret_cast(ob->u_cdata); @@ -142,6 +141,21 @@ extern "C" int C_Toolbar_BubblePost(FL_OBJECT * ob, int event, } #endif +// this one is not "C" because combox callbacks are really C++ %-| +void Toolbar::Pimpl::layoutSelectedCB(int sel, void * arg, Combox *) +{ + Toolbar::Pimpl * tb = reinterpret_cast(arg); + + tb->layoutSelected(sel); +} + + +void Toolbar::Pimpl::layoutSelected(int sel) +{ + string const tmp = tostr(sel); + owner->getLyXFunc()->Dispatch(LFUN_LAYOUTNO, tmp); +} + void Toolbar::Pimpl::activate() { @@ -361,7 +375,7 @@ void Toolbar::Pimpl::set(bool doingmain) if (!combox) combox = new Combox(FL_COMBOX_DROPLIST); combox->add(xpos, ypos, 135, height, 400); - combox->setcallback(LayoutsCB); + combox->setcallback(layoutSelectedCB, this); combox->resize(FL_RESIZE_ALL); combox->gravity(NorthWestGravity, NorthWestGravity); xpos += 135; diff --git a/src/frontends/xforms/Toolbar_pimpl.h b/src/frontends/xforms/Toolbar_pimpl.h index d9af62d54a..bbafe2373c 100644 --- a/src/frontends/xforms/Toolbar_pimpl.h +++ b/src/frontends/xforms/Toolbar_pimpl.h @@ -30,6 +30,8 @@ */ struct Toolbar::Pimpl { public: + /// called when user selects a layout from combox + static void layoutSelectedCB(int, void *, Combox *); /// Pimpl(LyXView * o, int x, int y); @@ -61,6 +63,7 @@ public: /// update the state of the icons void update(); + /// select the right layout in the combox void setLayout(int layout); /// Populate the layout combox; re-do everything if force is true. @@ -69,6 +72,8 @@ public: void openLayoutList(); /// Erase the layout list void clearLayoutList(); + /// and the non-static version + void layoutSelected(int); /// struct toolbarItem diff --git a/src/frontends/xforms/form_filedialog.C b/src/frontends/xforms/form_filedialog.C new file mode 100644 index 0000000000..3753d0046c --- /dev/null +++ b/src/frontends/xforms/form_filedialog.C @@ -0,0 +1,108 @@ +// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext +#include +#include "lyx_gui_misc.h" +#include "gettext.h" + +/* Form definition file generated with fdesign. */ + +#include FORMS_H_LOCATION +#include +#include "form_filedialog.h" +#include "FormFiledialog.h" + +FD_form_filedialog::~FD_form_filedialog() +{ + if ( form->visible ) fl_hide_form( form ); + fl_free_form( form ); +} + + +FD_form_filedialog * FileDialog::Private::build_filedialog() +{ + FL_OBJECT *obj; + FD_form_filedialog *fdui = new FD_form_filedialog; + + fdui->form = fl_bgn_form(FL_NO_BOX, 440, 380); + fdui->form->u_vdata = this; + obj = fl_add_box(FL_UP_BOX, 0, 0, 440, 380, ""); + fdui->FileInfo = obj = fl_add_text(FL_NORMAL_TEXT, 10, 260, 420, 30, ""); + fl_set_object_boxtype(obj, FL_SHADOW_BOX); + fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE); + fl_set_object_gravity(obj, FL_SouthWest, FL_SouthEast); + fl_set_object_resize(obj, FL_RESIZE_X); + { + char const * const dummy = N_("Directory:|#D"); + fdui->DirBox = obj = fl_add_input(FL_NORMAL_INPUT, 100, 10, 330, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); + fl_set_object_resize(obj, FL_RESIZE_X); + { + char const * const dummy = N_("Pattern:|#P"); + fdui->PatBox = obj = fl_add_input(FL_NORMAL_INPUT, 100, 40, 330, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); + fl_set_object_resize(obj, FL_RESIZE_X); + fdui->List = obj = fl_add_browser(FL_HOLD_BROWSER, 10, 80, 320, 170, ""); + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_lalign(obj, FL_ALIGN_TOP); + fl_set_object_gravity(obj, FL_NorthWest, FL_SouthEast); + { + char const * const dummy = N_("Filename:|#F"); + fdui->Filename = obj = fl_add_input(FL_NORMAL_INPUT, 100, 300, 330, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthWest, FL_SouthEast); + fl_set_object_resize(obj, FL_RESIZE_X); + { + char const * const dummy = N_("Rescan|#R#r"); + fdui->Rescan = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 80, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); + { + char const * const dummy = N_("Home|#H#h"); + fdui->Home = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 120, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); + { + char const * const dummy = N_("User1|#1"); + fdui->User1 = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 160, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); + { + char const * const dummy = N_("User2|#2"); + fdui->User2 = obj = fl_add_button(FL_NORMAL_BUTTON, 340, 200, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); + fdui->Ready = obj = fl_add_button(FL_RETURN_BUTTON, 220, 340, 100, 30, _("OK")); + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); + { + char const * const dummy = N_("Cancel|^["); + fdui->Cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 330, 340, 100, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); + fdui->timer = obj = fl_add_timer(FL_HIDDEN_TIMER, 10, 350, 20, 20, ""); + fl_set_object_gravity(obj, FL_SouthWest, FL_SouthWest); + fl_end_form(); + + fdui->form->fdui = fdui; + + return fdui; +} +/*---------------------------------------*/ + diff --git a/src/frontends/xforms/form_filedialog.h b/src/frontends/xforms/form_filedialog.h new file mode 100644 index 0000000000..ebb8c5ab45 --- /dev/null +++ b/src/frontends/xforms/form_filedialog.h @@ -0,0 +1,29 @@ +// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext +/** Header file generated with fdesign **/ + +#ifndef FD_form_filedialog_h_ +#define FD_form_filedialog_h_ + +/** Callbacks, globals and object handlers **/ + + +/**** Forms and Objects ****/ +struct FD_form_filedialog { + ~FD_form_filedialog(); + + FL_FORM *form; + FL_OBJECT *FileInfo; + FL_OBJECT *DirBox; + FL_OBJECT *PatBox; + FL_OBJECT *List; + FL_OBJECT *Filename; + FL_OBJECT *Rescan; + FL_OBJECT *Home; + FL_OBJECT *User1; + FL_OBJECT *User2; + FL_OBJECT *Ready; + FL_OBJECT *Cancel; + FL_OBJECT *timer; +}; + +#endif /* FD_form_filedialog_h_ */ diff --git a/src/frontends/xforms/forms/fdfix.sh b/src/frontends/xforms/forms/fdfix.sh index 294422fba4..e788b620b4 100644 --- a/src/frontends/xforms/forms/fdfix.sh +++ b/src/frontends/xforms/forms/fdfix.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/sh -x # # NOTE: This is NOT the same fdfix.sh as in ${top_srcdir}/forms # It is a modified version to suit use for gui-indep. @@ -73,6 +73,15 @@ echo >> $COUT sed -f $FDFIXC_MOD < $CIN >> $COUT +# hack for file dialog +if [ "$CLASSNAME" = "FormFiledialog" ] ; then + ed $COUT >/dev/null 2>/dev/null << EOF +/FormFiledialog::build_filedialog +s/FormFiledialog/FileDialog::Private/ +wq +EOF +fi + # Patch the .C file if a patch exists if [ -f "$COUT.patch" ] ; then echo "Patching $COUT with $COUT.patch" diff --git a/src/frontends/xforms/forms/form_filedialog.fd b/src/frontends/xforms/forms/form_filedialog.fd new file mode 100644 index 0000000000..541b521a9d --- /dev/null +++ b/src/frontends/xforms/forms/form_filedialog.fd @@ -0,0 +1,250 @@ +Magic: 13000 + +Internal Form Definition File + (do not change) + +Number of forms: 1 +Unit of measure: FL_COORD_PIXEL + +=============== FORM =============== +Name: form_filedialog +Width: 440 +Height: 380 +Number of Objects: 13 + +-------------------- +class: FL_BOX +type: UP_BOX +box: 0 0 440 380 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_TEXT +type: NORMAL_TEXT +box: 10 260 420 30 +boxtype: FL_SHADOW_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT|FL_ALIGN_INSIDE +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_X +gravity: FL_SouthWest FL_SouthEast +name: FileInfo +callback: +argument: + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 100 10 330 30 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Directory:|#D +shortcut: +resize: FL_RESIZE_X +gravity: FL_NorthWest FL_NorthEast +name: DirBox +callback: +argument: + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 100 40 330 30 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Pattern:|#P +shortcut: +resize: FL_RESIZE_X +gravity: FL_NorthWest FL_NorthEast +name: PatBox +callback: +argument: + +-------------------- +class: FL_BROWSER +type: HOLD_BROWSER +box: 10 80 320 170 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_TOP +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NorthWest FL_SouthEast +name: List +callback: +argument: + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 100 300 330 30 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Filename:|#F +shortcut: +resize: FL_RESIZE_X +gravity: FL_SouthWest FL_SouthEast +name: Filename +callback: +argument: + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 340 80 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Rescan|#R#r +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_NorthEast FL_NorthEast +name: Rescan +callback: +argument: + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 340 120 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Home|#H#h +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_NorthEast FL_NorthEast +name: Home +callback: +argument: + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 340 160 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: User1|#1 +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_NorthEast FL_NorthEast +name: User1 +callback: +argument: + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 340 200 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: User2|#2 +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_NorthEast FL_NorthEast +name: User2 +callback: +argument: + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 220 340 100 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: OK +shortcut: ^M +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: Ready +callback: +argument: + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 330 340 100 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Cancel|^[ +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: Cancel +callback: +argument: + +-------------------- +class: FL_TIMER +type: HIDDEN_TIMER +box: 10 350 20 20 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_RED +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthWest FL_SouthWest +name: timer +callback: +argument: + +============================== +-------------------- diff --git a/src/frontends/xforms/forms/makefile b/src/frontends/xforms/forms/makefile index 2d0782e3a7..d8cf2eca41 100644 --- a/src/frontends/xforms/forms/makefile +++ b/src/frontends/xforms/forms/makefile @@ -24,6 +24,7 @@ SRCS := form_bibitem.fd \ form_copyright.fd \ form_document.fd \ form_error.fd \ + form_filedialog.fd \ form_graphics.fd \ form_include.fd \ form_index.fd \ diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index 72d346f4ac..02d3a69e36 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -11,10 +11,10 @@ #ifdef __GNUG_ #pragma implementation #endif - + #include "xforms_helpers.h" #include "lyxlex.h" -#include "filedlg.h" // LyXFileDlg +#include "frontends/FileDialog.h" #include "support/FileInfo.h" #include "support/filetools.h" #include "lyx_gui_misc.h" // WriteAlert @@ -83,7 +83,7 @@ string formatted(string const & sin, int w, int size, int style) } -string const browseFile(string const & filename, +string const browseFile(LyXView * lv, string const & filename, string const & title, string const & pattern, pair const & dir1, @@ -92,43 +92,27 @@ string const browseFile(string const & filename, string lastPath = "."; if (!filename.empty()) lastPath = OnlyPath(filename); - LyXFileDlg fileDlg; - - if (!dir1.second.empty()) { - FileInfo fileInfo(dir1.second); - if (fileInfo.isOK() && fileInfo.isDir()) - fileDlg.SetButton(0, _(dir1.first), dir1.second); - } - - if (!dir2.second.empty()) { - FileInfo fileInfo(dir2.second); - if (fileInfo.isOK() && fileInfo.isDir()) - fileDlg.SetButton(1, _(dir2.first), dir2.second); - } + FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2); - bool error = false; - string buf; - do { - string p = fileDlg.Select(_(title), - lastPath, - pattern, OnlyFilename(filename)); + FileDialog::Result result; + + while (1) { + result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename)); - if (p.empty()) return p; + if (result.second.empty()) + return result.second; - lastPath = OnlyPath(p); + lastPath = OnlyPath(result.second); - if (p.find_first_of("#~$% ") != string::npos) { - WriteAlert(_("Filename can't contain any " - "of these characters:"), - _("space, '#', '~', '$' or '%'.")); - error = true; - } else { - error = false; - buf = p; - } - } while (error); + if (result.second.find_first_of("#~$% ") == string::npos) + break; + + WriteAlert(_("Filename can't contain any " + "of these characters:"), + _("space, '#', '~', '$' or '%'.")); + } - return buf; + return result.second; } diff --git a/src/frontends/xforms/xforms_helpers.h b/src/frontends/xforms/xforms_helpers.h index 531b26a724..0781cd1c9e 100644 --- a/src/frontends/xforms/xforms_helpers.h +++ b/src/frontends/xforms/xforms_helpers.h @@ -16,13 +16,15 @@ void setEnabled(FL_OBJECT *, bool enable); // Take a string and add breaks so that it fits into a desired label width, w string formatted(string const &label, int w, int size, int style); +class LyXView; + /** Launch a file dialog and return the chosen file. filename: a suggested filename. title: the title of the dialog. pattern: *.ps etc. dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog. */ -string const browseFile(string const & filename, +string const browseFile(LyXView *lv, string const & filename, string const & title, string const & pattern, std::pair const & dir1, diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 779456aef0..971c5960f0 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2001-03-06 John Levon + + * insetexternal.C: + * figinset.C: use new File Dialog + 2001-03-06 Lars Gullik Bjønnes * insettext.C: changes becuase of ParagraphParameters. diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 53405c0ef3..2b8a109d49 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -47,7 +48,7 @@ #include "lyx.h" #include "lyx_main.h" #include "buffer.h" -#include "filedlg.h" +#include "frontends/FileDialog.h" #include "support/filetools.h" #include "LyXView.h" // just because of form_main #include "debug.h" @@ -80,6 +81,8 @@ using std::flush; using std::endl; using std::ostringstream; using std::copy; +using std::pair; +using std::make_pair; extern BufferView * current_view; extern FL_OBJECT * figinset_canvas; @@ -1931,7 +1934,6 @@ void InsetFig::BrowseFile() { static string current_figure_path; static int once = 0; - LyXFileDlg fileDlg; if (lyxerr.debugging()) { lyxerr << "Filename: " @@ -1956,23 +1958,21 @@ void InsetFig::BrowseFile() bufclip = AddName (system_lyxdir, "clipart"); - fileDlg.SetButton(0, _("Clipart"), bufclip); - fileDlg.SetButton(1, _("Document"), buf); + FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"), + LFUN_SELECT_FILE_SYNC, + make_pair(string(_("Clip art")), string(bufclip)), + make_pair(string(_("Documents")), string(buf))); bool error = false; do { - ProhibitInput(current_view); - if (once) { - p = fileDlg.Select(_("EPS Figure"), - current_figure_path, - "*ps", string()); - } else { - p = fileDlg.Select(_("EPS Figure"), buf, - "*ps", string()); - } - AllowInput(current_view); + string const path = (once) ? current_figure_path : buf; + + FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents")); - if (p.empty()) return; + string const p = result.second; + + if (p.empty()) + return; buf = MakeRelPath(p, buf2); current_figure_path = OnlyPath(p); diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index b15178ee38..8bddd24839 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -16,13 +16,14 @@ #include FORMS_H_LOCATION #include +#include #include "insetexternal.h" #include "ExternalTemplate.h" #include "lyx_gui_misc.h" // CancelCloseBoxCB #include "BufferView.h" #include "buffer.h" -#include "filedlg.h" +#include "frontends/FileDialog.h" #include "lyx_main.h" #include "LaTeXFeatures.h" #include "support/filetools.h" @@ -36,7 +37,8 @@ using SigC::slot; #endif using std::endl; - +using std::pair; +using std::make_pair; InsetExternal::InsetExternal() : form_external(0) @@ -128,7 +130,6 @@ void InsetExternal::browseCB(FL_OBJECT * ob, long) static string current_path; static int once = 0; - LyXFileDlg fileDlg; string p = inset->filename; string buf = MakeAbsPath(holder->view->buffer()->fileName()); @@ -140,7 +141,11 @@ void InsetExternal::browseCB(FL_OBJECT * ob, long) buf = OnlyPath(holder->view->buffer()->fileName()); } - fileDlg.SetButton(0, _("Document"), buf); + FileDialog fileDlg(holder->view->owner(), _("Select external file"), + LFUN_SELECT_FILE_SYNC, + make_pair(string(_("Document")), string(buf))); + + // FIXME: should have "nice name" for file type e.g. "Xfig files" /// Determine the template file extension ExternalTemplate et = inset->getTemplate(inset->getCurrentTemplate()); @@ -149,18 +154,17 @@ void InsetExternal::browseCB(FL_OBJECT * ob, long) regexp = "*"; } + regexp += "|"; + bool error = false; do { - if (once) { - p = fileDlg.Select(_("External inset file"), - current_path, - regexp, string()); - } else { - p = fileDlg.Select(_("External inset file"), buf, - regexp, string()); - } + string const path = (once) ? current_path : buf; + FileDialog::Result result = fileDlg.Select(path, regexp); + + if (result.second.empty()) + return; - if (p.empty()) return; + string p = result.second; buf = MakeRelPath(p, buf2); current_path = OnlyPath(p); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 601f6a6f2a..1763bb328c 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -12,6 +12,7 @@ #include #include +#include #include #include FORMS_H_LOCATION @@ -24,7 +25,7 @@ #include "minibuffer.h" #include "combox.h" #include "bufferlist.h" -#include "filedlg.h" +#include "frontends/FileDialog.h" #include "lyx_gui_misc.h" #include "LyXView.h" #include "lastfiles.h" @@ -44,6 +45,7 @@ using std::cout; using std::ios; using std::istream_iterator; using std::pair; +using std::make_pair; using std::vector; using std::sort; using std::equal; @@ -146,103 +148,102 @@ void ShowMessage(Buffer const * buf, // // File menu // - // should be moved to lyxfunc.C bool MenuWrite(BufferView * bv, Buffer * buffer) { + // FIXME: needed ? XFlush(fl_get_display()); + if (!buffer->save()) { string const fname = buffer->fileName(); string const s = MakeAbsPath(fname); if (AskQuestion(_("Save failed. Rename and try again?"), MakeDisplayPath(s, 50), _("(If not, document is not saved.)"))) { - return MenuWriteAs(bv, buffer); + return WriteAs(bv, buffer); } return false; - } else { + } else lastfiles->newFile(buffer->fileName()); - } return true; } + // should be moved to BufferView.C // Half of this func should be in LyXView, the rest in BufferView. -bool MenuWriteAs(BufferView * bv, Buffer * buffer) +bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename) { - // Why do we require BufferView::text to be able to write a - // document? I see no point in that. (Lgb) - //if (!bv->text) return; - string fname = buffer->fileName(); string oldname = fname; - LyXFileDlg fileDlg; - ProhibitInput(bv); - fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); - fileDlg.SetButton(1, _("Templates"), lyxrc.template_path); + if (filename.empty()) { - if (!IsLyXFilename(fname)) - fname += ".lyx"; + FileDialog fileDlg(bv->owner(), _("Choose a filename to save document as"), + LFUN_WRITEAS, + make_pair(string(_("Documents")), string(lyxrc.document_path)), + make_pair(string(_("Templates")), string(lyxrc.template_path))); - fname = fileDlg.Select(_("Enter Filename to Save Document as"), - OnlyPath(fname), - "*.lyx", - OnlyFilename(fname)); + if (!IsLyXFilename(fname)) + fname += ".lyx"; - AllowInput(bv); + FileDialog::Result result = fileDlg.Select(OnlyPath(fname), _("*.lyx|LyX Documents (*.lyx)"), OnlyFilename(fname)); - if (fname.empty()) - return false; + if (result.first == FileDialog::Later) + return false; + + fname = result.second; + + if (fname.empty()) + return false; + + // Make sure the absolute filename ends with appropriate suffix + fname = MakeAbsPath(fname); + if (!IsLyXFilename(fname)) + fname += ".lyx"; + } else + fname = filename; - // Make sure the absolute filename ends with appropriate suffix - string s = MakeAbsPath(fname); - if (!IsLyXFilename(s)) - s += ".lyx"; // Same name as we have already? - if (!buffer->isUnnamed() && s == oldname) { + if (!buffer->isUnnamed() && fname == oldname) { if (!AskQuestion(_("Same name as document already has:"), - MakeDisplayPath(s, 50), + MakeDisplayPath(fname, 50), _("Save anyway?"))) return false; // Falls through to name change and save } // No, but do we have another file with this name open? - else if (!buffer->isUnnamed() && bufferlist.exists(s)) { + else if (!buffer->isUnnamed() && bufferlist.exists(fname)) { if (AskQuestion(_("Another document with same name open!"), - MakeDisplayPath(s, 50), + MakeDisplayPath(fname, 50), _("Replace with current document?"))) { - bufferlist.close(bufferlist.getBuffer(s)); + bufferlist.close(bufferlist.getBuffer(fname)); // Ok, change the name of the buffer, but don't save! - buffer->setFileName(s); + buffer->setFileName(fname); buffer->markDirty(); ShowMessage(buffer, _("Document renamed to '"), - MakeDisplayPath(s), _("', but not saved...")); - } + MakeDisplayPath(fname), _("', but not saved...")); + } return false; } // Check whether the file exists else { - FileInfo const myfile(s); + FileInfo const myfile(fname); if (myfile.isOK() && !AskQuestion(_("Document already exists:"), - MakeDisplayPath(s, 50), + MakeDisplayPath(fname, 50), _("Replace file?"))) return false; } // Ok, change the name of the buffer - buffer->setFileName(s); + buffer->setFileName(fname); buffer->markDirty(); bool unnamed = buffer->isUnnamed(); buffer->setUnnamed(false); - // And save - // Small bug: If the save fails, we have irreversible changed the name - // of the document. - // Hope this is fixed this way! (Jug) + if (!MenuWrite(bv, buffer)) { buffer->setFileName(oldname); buffer->setUnnamed(unnamed); @@ -418,17 +419,23 @@ Buffer * NewLyxFile(string const & filename) void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) { string fname = f; - LyXFileDlg fileDlg; - - if (!bv->available()) return; + + if (!bv->available()) + return; if (fname.empty()) { - ProhibitInput(bv); - fname = fileDlg.Select(_("File to Insert"), - bv->owner()->buffer()->filepath, - "*"); - AllowInput(bv); - if (fname.empty()) return; + 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); + + if (result.first == FileDialog::Later) + return; + + fname = result.second; + + if (fname.empty()) + return; } FileInfo fi(fname); @@ -557,16 +564,6 @@ void MenuInsertLabel(BufferView * bv, string const & arg) } -// This is _only_ used in Toolbar_pimpl.C, move it there and get rid of -// current_view. (Lgb) -void LayoutsCB(int sel, void *, Combox *) -{ - string const tmp = tostr(sel); - current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO, - tmp); -} - - void MenuLayoutSave(BufferView * bv) { if (!bv->available()) diff --git a/src/lyx_cb.h b/src/lyx_cb.h index 362f9b0d18..619d399e42 100644 --- a/src/lyx_cb.h +++ b/src/lyx_cb.h @@ -25,8 +25,8 @@ void ShowMessage(Buffer const * buf, string const & msg3 = string(), int delay = 6); /// bool MenuWrite(BufferView * bv, Buffer * buffer); -/// -bool MenuWriteAs(BufferView * bv, Buffer * buffer); +/// write the given file, or ask if no name given +bool WriteAs(BufferView * bv, Buffer * buffer, const string & filename = string()); /// int MenuRunChktex(Buffer * buffer); /// @@ -40,8 +40,6 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph); /// void MenuInsertLabel(BufferView * bv, string const & arg); /// -void LayoutsCB(int sel, void *, Combox *); -/// void MenuLayoutCharacter(); /// void MenuLayoutSave(BufferView * bv); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 2b1f9e03b6..ce6ff5a939 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -14,6 +14,8 @@ #include #include +#include +#include #include #include @@ -60,7 +62,6 @@ #include "minibuffer.h" #include "vspace.h" #include "LyXView.h" -#include "filedlg.h" #include "lyx_gui_misc.h" #include "support/filetools.h" #include "support/FileInfo.h" @@ -76,6 +77,7 @@ #include "layout.h" #include "WorkArea.h" #include "bufferview_funcs.h" +#include "frontends/FileDialog.h" #include "frontends/Dialogs.h" #include "frontends/Toolbar.h" #include "frontends/Menubar.h" @@ -88,6 +90,7 @@ #include "lyxfind.h" using std::pair; +using std::make_pair; using std::endl; using std::find_if; @@ -692,6 +695,8 @@ string const LyXFunc::Dispatch(int ac, } } + Assert(action != LFUN_SELECT_FILE_SYNC); + switch (action) { // --- Misc ------------------------------------------- case LFUN_WORDFINDFORWARD : @@ -793,10 +798,6 @@ string const LyXFunc::Dispatch(int ac, MenuNew(true); break; - case LFUN_MENUOPEN: - MenuOpen(); - break; - case LFUN_CLOSEBUFFER: CloseBuffer(); break; @@ -807,19 +808,12 @@ string const LyXFunc::Dispatch(int ac, MakeDisplayPath(owner->buffer()->fileName()), "..."); MenuWrite(owner->view(), owner->buffer()); - //owner->getMiniBuffer()-> { - // Set(_("Document saved as"), - // MakeDisplayPath(owner->buffer()->fileName())); - //} else { - //owner->getMiniBuffer()->Set(_("Save failed!")); - //} - } else { - MenuWriteAs(owner->view(), owner->buffer()); - } + } else + WriteAs(owner->view(), owner->buffer()); break; - case LFUN_MENUWRITEAS: - MenuWriteAs(owner->view(), owner->buffer()); + case LFUN_WRITEAS: + WriteAs(owner->view(), owner->buffer(), argument); break; case LFUN_MENURELOAD: @@ -1114,7 +1108,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_FILE_OPEN: - owner->view()->buffer(bufferlist.loadLyXFile(argument)); + Open(argument); break; case LFUN_LATEX_LOG: @@ -1146,11 +1140,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_LAYOUT_PARAGRAPH: -#ifdef USE_OLD_PARAGRAPH_LAYOUT - MenuLayoutParagraph(); -#else owner->getDialogs()->showLayoutParagraph(); -#endif break; case LFUN_LAYOUT_CHARACTER: @@ -1537,7 +1527,6 @@ void LyXFunc::setupLocalKeymap() void LyXFunc::MenuNew(bool fromTemplate) { string initpath = lyxrc.document_path; - LyXFileDlg fileDlg; if (owner->view()->available()) { string const trypath = owner->buffer()->filepath; @@ -1550,14 +1539,14 @@ void LyXFunc::MenuNew(bool fromTemplate) string s; if (lyxrc.new_ask_filename) { - ProhibitInput(owner->view()); - fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); - fileDlg.SetButton(1, _("Templates"), lyxrc.template_path); - string fname = fileDlg.Select(_("Enter Filename for new document"), - initpath, "*.lyx", _("newfile")); - AllowInput(owner->view()); + FileDialog fileDlg(owner, _("Enter filename for new document"), + LFUN_SELECT_FILE_SYNC, + make_pair(string(_("Documents")), string(lyxrc.document_path)), + make_pair(string(_("Templates")), string(lyxrc.template_path))); + + FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx|LyX Documents (*.lyx)"), _("newfile")); - if (fname.empty()) { + if (result.second.empty()) { owner->getMiniBuffer()->Set(_("Canceled.")); lyxerr.debug() << "New Document Cancelled." << endl; return; @@ -1565,7 +1554,7 @@ void LyXFunc::MenuNew(bool fromTemplate) // get absolute path of file and make sure the filename ends // with .lyx - s = MakeAbsPath(fname); + s = MakeAbsPath(result.second); if (!IsLyXFilename(s)) s += ".lyx"; @@ -1624,12 +1613,20 @@ void LyXFunc::MenuNew(bool fromTemplate) // The template stuff string templname; if (fromTemplate) { - ProhibitInput(owner->view()); - string const fname = fileDlg.Select(_("Choose template"), - lyxrc.template_path, - "*.lyx"); - AllowInput(owner->view()); - if (fname.empty()) return; + FileDialog fileDlg(owner, _("Select template file"), + LFUN_SELECT_FILE_SYNC, + make_pair(string(_("Documents")), string(lyxrc.document_path)), + make_pair(string(_("Templates")), string(lyxrc.template_path))); + + FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx|LyX Documents (*.lyx)")); + + if (result.first == FileDialog::Later) + return; + + string const fname = result.second; + + if (fname.empty()) + return; templname = fname; } @@ -1639,10 +1636,9 @@ void LyXFunc::MenuNew(bool fromTemplate) } -void LyXFunc::MenuOpen() +void LyXFunc::Open(string const & fname) { string initpath = lyxrc.document_path; - LyXFileDlg fileDlg; if (owner->view()->available()) { string const trypath = owner->buffer()->filepath; @@ -1651,20 +1647,28 @@ void LyXFunc::MenuOpen() initpath = trypath; } - // launches dialog - ProhibitInput(owner->view()); - fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); - fileDlg.SetButton(1, _("Examples"), - AddPath(system_lyxdir, "examples")); - string filename = fileDlg.Select(_("Select Document to Open"), - initpath, "*.lyx"); - AllowInput(owner->view()); + string filename; - // check selected filename - if (filename.empty()) { - owner->getMiniBuffer()->Set(_("Canceled.")); - return; - } + if (fname.empty()) { + FileDialog fileDlg(owner, _("Select document to open"), + LFUN_FILE_OPEN, + make_pair(string(_("Documents")), string(lyxrc.document_path)), + make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples")))); + + FileDialog::Result result = fileDlg.Select(initpath, "*.lyx|LyX Documents (*.lyx)"); + + if (result.first == FileDialog::Later) + return; + + filename = result.second; + + // check selected filename + if (filename.empty()) { + owner->getMiniBuffer()->Set(_("Canceled.")); + return; + } + } else + filename = fname; // get absolute path of file and make sure the filename ends // with .lyx @@ -1698,7 +1702,6 @@ void LyXFunc::doImport(string const & argument) if (filename.empty()) { // need user interaction string initpath = lyxrc.document_path; - LyXFileDlg fileDlg; if (owner->view()->available()) { string const trypath = owner->buffer()->filepath; @@ -1707,16 +1710,23 @@ void LyXFunc::doImport(string const & argument) initpath = trypath; } - // launches dialog - ProhibitInput(owner->view()); - fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); - fileDlg.SetButton(1, _("Examples"), - AddPath(system_lyxdir, "examples")); string const text = _("Select ") + formats.PrettyName(format) + _(" file to import"); - string const extension = "*." + formats.Extension(format); - filename = fileDlg.Select(text, initpath, extension); - AllowInput(owner->view()); + + FileDialog fileDlg(owner, text, + LFUN_IMPORT, + make_pair(string(_("Documents")), string(lyxrc.document_path)), + make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples")))); + + string const extension = "*." + formats.Extension(format) + "| " + + formats.PrettyName(format) + " (*." + formats.Extension(format) + ")"; + + FileDialog::Result result = fileDlg.Select(initpath, extension); + + if (result.first == FileDialog::Later) + return; + + filename = result.second; // check selected filename if (filename.empty()) diff --git a/src/lyxfunc.h b/src/lyxfunc.h index 0f796b768e..b4948a56c7 100644 --- a/src/lyxfunc.h +++ b/src/lyxfunc.h @@ -118,7 +118,7 @@ private: void MenuNew(bool fromTemplate); /// - void MenuOpen(); + void Open(string const &); /// void doImport(string const &); -- 2.39.5