+2001-03-06 John Levon <moz@compsoc.man.ac.uk>
+
+ * ui/default.ui:
+ * bind/<various>: update for file dialog change
+
2001-03-06 Chanop Silpa-Anan <chanop@debian.org>
* encodings:
\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"
#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"
#
#\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"
#\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"
\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"
#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" "------"
#\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
#\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"
#\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"
#\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"
#\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"
#\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"
\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"
#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" "------"
+++ /dev/null
-/* XPM */
-static char const * open_xpm[] = {
-"20 20 5 1",
-" c None",
-". c navy",
-"X c #000000000000",
-"o c #9A9A94949494",
-"O c #E5E5E0E0E1E1",
-" ",
-" ... ",
-" . . .",
-" XXXXX . .",
-"XXooooX ..",
-"XooooooXXXXXXXX ....",
-"XoooooooooooooX ",
-"XoooooooooooooX ",
-"XoooooooooooooX ",
-"XooooXXXXXXXXXXXXXXX",
-"XooooXOOOOOOOOOOOOOX",
-"XoooXOOOOOOOOOOOOOX ",
-"XoooXOOOOOOOOOOOOOX ",
-"XooXOOOOOOOOOOOOOX ",
-"XooXOOOOOOOOOOOOOX ",
-"XoXOOOOOOOOOOOOOX ",
-"XoXOOOOOOOOOOOOOX ",
-"XXOOOOOOOOOOOOOX ",
-"XXOOOOOOOOOOOOOX ",
-"XXXXXXXXXXXXXXX "};
-
-
--- /dev/null
+/* XPM */
+static char const * open_xpm[] = {
+"20 20 5 1",
+" c None",
+". c navy",
+"X c #000000000000",
+"o c #9A9A94949494",
+"O c #E5E5E0E0E1E1",
+" ",
+" ... ",
+" . . .",
+" XXXXX . .",
+"XXooooX ..",
+"XooooooXXXXXXXX ....",
+"XoooooooooooooX ",
+"XoooooooooooooX ",
+"XoooooooooooooX ",
+"XooooXXXXXXXXXXXXXXX",
+"XooooXOOOOOOOOOOOOOX",
+"XoooXOOOOOOOOOOOOOX ",
+"XoooXOOOOOOOOOOOOOX ",
+"XooXOOOOOOOOOOOOOX ",
+"XooXOOOOOOOOOOOOOX ",
+"XoXOOOOOOOOOOOOOX ",
+"XoXOOOOOOOOOOOOOX ",
+"XXOOOOOOOOOOOOOX ",
+"XXOOOOOOOOOOOOOX ",
+"XXXXXXXXXXXXXXX "};
+
+
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
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"
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
#
Toolbar
Layouts
- Icon "buffer-open"
+ Icon "file-open"
Icon "buffer-write"
Icon "buffer-print"
Separator
src/debug.C
src/exporter.C
src/ext_l10n.h
-src/filedlg.C
src/FontLoader.C
src/form1.C
src/frontends/gnome/FormCitation.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
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
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
#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"
if (filename.empty()) {
// Launch a file browser
string initpath = lyxrc.document_path;
- LyXFileDlg fileDlg;
if (available()) {
string const trypath = owner_->buffer()->filepath;
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
}
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:
{
+2001-03-06 John Levon <moz@compsoc.man.ac.uk>
+
+ * 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 <Jean-Marc.Lasgouttes@inria.fr>
* ShareContainer.h (get): add std:: qualifier
{ 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 },
{ 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 },
{ 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 },
exporter.h \
ext_l10n.h \
figure.h \
- filedlg.C \
- filedlg.h \
font.C \
font.h \
form1.C \
void ToolbarDefaults::init()
{
add(LAYOUTS);
- add(LFUN_MENUOPEN);
+ add(LFUN_FILE_OPEN);
//add(LFUN_CLOSEBUFFER);
add(LFUN_MENUWRITE);
add(LFUN_MENUPRINT);
_("Save document?"))) {
case 1: // Yes
if ((*it)->isUnnamed())
- reask = !MenuWriteAs(current_view, (*it));
+ reask = !WriteAs(current_view, (*it));
else {
reask = !MenuWrite(current_view, (*it));
}
_("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;
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,
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
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 */
};
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
- *
- * ====================================================== */
-
-#include <config.h>
-
-#include <unistd.h>
-#include <cstdlib>
-#include <pwd.h>
-#include <grp.h>
-#include <cstring>
-#include <map>
-#include <algorithm>
-
-using std::map;
-using std::max;
-using std::sort;
-
-#include "lyx_gui_misc.h" // CancelCloseCB
-#include "support/FileInfo.h"
-#include "support/lyxlib.h"
-#include "gettext.h"
-#include "frontends/Dialogs.h"
-
-#ifdef HAVE_ERRNO_H
-#include <cerrno>
-#endif
-
-#if HAVE_DIRENT_H
-# include <dirent.h>
-# define NAMLEN(dirent) strlen((dirent)->d_name)
-#else
-# define dirent direct
-# define NAMLEN(dirent) (dirent)->d_namlen
-# if HAVE_SYS_NDIR_H
-# include <sys/ndir.h>
-# endif
-# if HAVE_SYS_DIR_H
-# include <sys/dir.h>
-# endif
-# if HAVE_NDIR_H
-# include <ndir.h>
-# endif
-#endif
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <ctime>
-#else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <ctime>
-# endif
-#endif
-
-#ifdef BROKEN_HEADERS
-extern "C" int gettimeofday(struct timeval *, struct timezone *);
-#endif
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "support/filetools.h"
-#include "filedlg.h"
-
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::slot;
-#endif
-
-// six months, in seconds
-static const long SIX_MONTH_SEC = 6L * 30L * 24L * 60L * 60L;
-static const long ONE_HOUR_SEC = 60L * 60L;
-
-// *** User cache class implementation
-/// User cache class definition
-class UserCache {
-public:
- /// seeks user name from group ID
- string const & find(uid_t ID) const {
- Users::const_iterator cit = users.find(ID);
- if (cit == users.end()) {
- add(ID);
- return users[ID];
- }
- return (*cit).second;
- }
-private:
- ///
- void add(uid_t ID) const;
- ///
- typedef map<uid_t, string> Users;
- ///
- mutable Users users;
-};
-
-
-void UserCache::add(uid_t ID) const
-{
- string pszNewName;
- struct passwd * pEntry;
-
- // gets user name
- if ((pEntry = getpwuid(ID)))
- pszNewName = pEntry->pw_name;
- else {
- pszNewName = tostr(ID);
- }
-
- // adds new node
- users[ID] = pszNewName;
-}
-
-
-/// Group cache class definition
-class GroupCache {
-public:
- /// seeks group name from group ID
- string const & find(gid_t ID) const ;
-private:
- ///
- void add(gid_t ID) const;
- ///
- typedef map<gid_t, string> Groups;
- ///
- mutable Groups groups;
-};
-
-
-string const & GroupCache::find(gid_t ID) const
-{
- Groups::const_iterator cit = groups.find(ID);
- if (cit == groups.end()) {
- add(ID);
- return groups[ID];
- }
- return (*cit).second;
-}
-
-
-void GroupCache::add(gid_t ID) const
-{
- string pszNewName;
- struct group * pEntry;
-
- // gets user name
- if ((pEntry = getgrgid(ID))) pszNewName = pEntry->gr_name;
- else {
- pszNewName = tostr(ID);
- }
- // adds new node
- groups[ID] = pszNewName;
-}
-
-
-// static instances
-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 comp_direntry::operator()(LyXDirEntry const & r1,
- LyXDirEntry const & r2) const {
- bool r1d = suffixIs(r1.pszName, '/');
- bool r2d = suffixIs(r2.pszName, '/');
- if (r1d && !r2d) return 1;
- if (!r1d && r2d) return 0;
- return r1.pszName < r2.pszName;
- }
-
-
-// *** LyXFileDlg class implementation
-
-// static members
-FD_FileDlg * LyXFileDlg::pFileDlgForm = 0;
-LyXFileDlg * LyXFileDlg::pCurrentDlg = 0;
-
-
-// Reread: updates dialog list to match class directory
-void LyXFileDlg::Reread()
-{
- // Opens directory
- DIR * pDirectory = ::opendir(pszDirectory.c_str());
- if (!pDirectory) {
- WriteFSAlert(_("Warning! Couldn't open directory."),
- pszDirectory);
- pszDirectory = lyx::getcwd();
- pDirectory = ::opendir(pszDirectory.c_str());
- }
-
- // Clear the present namelist
- direntries.clear();
-
- // Updates display
- fl_hide_object(pFileDlgForm->List);
- fl_clear_browser(pFileDlgForm->List);
- fl_set_input(pFileDlgForm->DirBox, pszDirectory.c_str());
-
- // Splits complete directory name into directories and compute depth
- iDepth = 0;
- string line, Temp;
- char szMode[15];
- FileInfo fileInfo;
- string File = pszDirectory;
- if (File != "/") {
- File = split(File, Temp, '/');
- }
- while (!File.empty() || !Temp.empty()) {
- string dline = "@b"+line + Temp + '/';
- fl_add_browser_line(pFileDlgForm->List, dline.c_str());
- File = split(File, Temp, '/');
- line += ' ';
- ++iDepth;
- }
-
- // Parses all entries of the given subdirectory
- time_t curTime = time(0);
- rewinddir(pDirectory);
- struct dirent * pDirEntry;
- while ((pDirEntry = readdir(pDirectory))) {
- bool isLink = false, isDir = false;
-
- // If the pattern doesn't start with a dot, skip hidden files
- if (!pszMask.empty() && pszMask[0] != '.' &&
- pDirEntry->d_name[0] == '.')
- continue;
-
- // Gets filename
- string fname = pDirEntry->d_name;
-
- // Under all circumstances, "." and ".." are not wanted
- if (fname == "." || fname == "..")
- continue;
-
- // gets file status
- File = AddName(pszDirectory, fname);
-
- fileInfo.newFile(File, true);
- fileInfo.modeString(szMode);
- unsigned int nlink = fileInfo.getNumberOfLinks();
- string user = lyxUserCache.find(fileInfo.getUid());
- string group = lyxGroupCache.find(fileInfo.getGid());
-
- time_t modtime = fileInfo.getModificationTime();
- string Time = ctime(&modtime);
-
- if (curTime > fileInfo.getModificationTime() + SIX_MONTH_SEC
- || curTime < fileInfo.getModificationTime()
- + ONE_HOUR_SEC) {
- // The file is fairly old or in the future. POSIX says
- // the cutoff is 6 months old. Allow a 1 hour slop
- // factor for what is considered "the future", to
- // allow for NFS server/client clock disagreement.
- // Show the year instead of the time of day.
- Time.erase(10, 9);
- Time.erase(15, string::npos);
- } else {
- Time.erase(16, string::npos);
- }
-
- string Buffer = string(szMode) + ' ' +
- tostr(nlink) + ' ' +
- user + ' ' +
- group + ' ' +
- Time.substr(4, string::npos) + ' ';
-
- Buffer += pDirEntry->d_name;
- Buffer += fileInfo.typeIndicator();
-
- if ((isLink = fileInfo.isLink())) {
- string Link;
-
- if (LyXReadLink(File, Link)) {
- Buffer += " -> ";
- Buffer += Link;
-
- // This gives the FileType of the file that
- // is really pointed too after resolving all
- // symlinks. This is not necessarily the same
- // as the type of Link (which could again be a
- // link). Is that intended?
- // JV 199902
- fileInfo.newFile(File);
- Buffer += fileInfo.typeIndicator();
- }
- }
-
- // filters files according to pattern and type
- if (fileInfo.isRegular()
- || fileInfo.isChar()
- || fileInfo.isBlock()
- || fileInfo.isFifo()) {
- if (!regexMatch(fname, pszMask))
- continue;
- } else if (!(isDir = fileInfo.isDir()))
- continue;
-
- LyXDirEntry tmp;
-
- // Note pszLsEntry is an string!
- tmp.pszLsEntry = Buffer;
- // creates used name
- string temp = fname;
- if (isDir) temp += '/';
-
- tmp.pszName = temp;
- // creates displayed name
- temp = pDirEntry->d_name;
- if (isLink)
- temp += '@';
- else
- temp += fileInfo.typeIndicator();
- tmp.pszDisplayed = temp;
-
- direntries.push_back(tmp);
- }
-
- closedir(pDirectory);
-
- // Sort the names
- sort(direntries.begin(), direntries.end(), comp_direntry());
-
- // Add them to directory box
- for (DirEntries::const_iterator cit = direntries.begin();
- cit != direntries.end(); ++cit) {
- string const temp = line + (*cit).pszDisplayed;
- fl_add_browser_line(pFileDlgForm->List, temp.c_str());
- }
- fl_set_browser_topline(pFileDlgForm->List, iDepth);
- fl_show_object(pFileDlgForm->List);
- iLastSel = -1;
-}
-
-
-// SetDirectory: sets dialog current directory
-void LyXFileDlg::SetDirectory(string const & Path)
-{
- if (!pszDirectory.empty()) {
- string TempPath = ExpandPath(Path); // Expand ~/
- TempPath = MakeAbsPath(TempPath, pszDirectory);
- pszDirectory = MakeAbsPath(TempPath);
- } else pszDirectory = MakeAbsPath(Path);
-}
-
-
-// SetMask: sets dialog file mask
-void LyXFileDlg::SetMask(string const & NewMask)
-{
- pszMask = NewMask;
- fl_set_input(pFileDlgForm->PatBox, pszMask.c_str());
-}
-
-
-// SetInfoLine: sets dialog information line
-void LyXFileDlg::SetInfoLine(string const & Line)
-{
- pszInfoLine = Line;
- fl_set_object_label(pFileDlgForm->FileInfo, pszInfoLine.c_str());
-}
-
-
-LyXFileDlg::LyXFileDlg()
-{
- pszDirectory = MakeAbsPath(string("."));
- pszMask = '*';
-
- // Creates form if necessary.
- if (!pFileDlgForm) {
- pFileDlgForm = create_form_FileDlg();
- // Set callbacks. This means that we don't need a patch file
- fl_set_object_callback(pFileDlgForm->DirBox,
- C_LyXFileDlg_FileDlgCB, 0);
- fl_set_object_callback(pFileDlgForm->PatBox,
- C_LyXFileDlg_FileDlgCB, 1);
- fl_set_object_callback(pFileDlgForm->List,
- C_LyXFileDlg_FileDlgCB, 2);
- fl_set_object_callback(pFileDlgForm->Filename,
- C_LyXFileDlg_FileDlgCB, 3);
- fl_set_object_callback(pFileDlgForm->Rescan,
- C_LyXFileDlg_FileDlgCB, 10);
- fl_set_object_callback(pFileDlgForm->Home,
- C_LyXFileDlg_FileDlgCB, 11);
- fl_set_object_callback(pFileDlgForm->User1,
- C_LyXFileDlg_FileDlgCB, 12);
- fl_set_object_callback(pFileDlgForm->User2,
- C_LyXFileDlg_FileDlgCB, 13);
-
- // Make sure pressing the close box doesn't crash LyX. (RvdK)
- fl_set_form_atclose(pFileDlgForm->FileDlg,
- C_LyXFileDlg_CancelCB, 0);
- // Register doubleclick callback
- fl_set_browser_dblclick_callback(pFileDlgForm->List,
- C_LyXFileDlg_DoubleClickCB,
- 0);
- }
- fl_hide_object(pFileDlgForm->User1);
- fl_hide_object(pFileDlgForm->User2);
-
- r_ = Dialogs::redrawGUI.connect(slot(this, &LyXFileDlg::redraw));
-}
-
-
-LyXFileDlg::~LyXFileDlg()
-{
- r_.disconnect();
-}
-
-
-void LyXFileDlg::redraw()
-{
- if (pFileDlgForm->FileDlg && pFileDlgForm->FileDlg->visible)
- fl_redraw_form(pFileDlgForm->FileDlg);
-}
-
-
-// SetButton: sets file selector user button action
-void LyXFileDlg::SetButton(int iIndex, string const & pszName,
- string const & pszPath)
-{
- FL_OBJECT * pObject;
- string * pTemp;
-
- if (iIndex == 0) {
- pObject = pFileDlgForm->User1;
- pTemp = &pszUserPath1;
- } else if (iIndex == 1) {
- pObject = pFileDlgForm->User2;
- pTemp = &pszUserPath2;
- } else return;
-
- if (!pszName.empty() && !pszPath.empty()) {
- fl_set_object_label(pObject, pszName.c_str());
- fl_show_object(pObject);
- *pTemp = pszPath;
- } else {
- fl_hide_object(pObject);
- (*pTemp).erase();
- }
-}
-
-
-// GetDirectory: gets last dialog directory
-string const LyXFileDlg::GetDirectory() const
-{
- if (!pszDirectory.empty())
- return pszDirectory;
- else
- return string(".");
-}
-
-
-// RunDialog: handle dialog during file selection
-bool LyXFileDlg::RunDialog()
-{
- force_cancel = false;
- force_ok = false;
-
- // event loop
- while(true) {
- FL_OBJECT * pObject = fl_do_forms();
-
- if (pObject == pFileDlgForm->Ready) {
- if (HandleOK())
- return true;
- } else if (pObject == pFileDlgForm->Cancel
- || force_cancel)
- return false;
- else if (force_ok)
- return true;
- }
-}
-
-
-// XForms objects callback (static)
-void LyXFileDlg::FileDlgCB(FL_OBJECT *, long lArgument)
-{
- if (!pCurrentDlg) return;
-
- switch (lArgument) {
-
- case 0: // get directory
- pCurrentDlg->SetDirectory(fl_get_input(pFileDlgForm->DirBox));
- pCurrentDlg->Reread();
- break;
-
- case 1: // get mask
- pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
- pCurrentDlg->Reread();
- break;
-
- case 2: // list
- pCurrentDlg->HandleListHit();
- break;
-
- case 10: // rescan
- pCurrentDlg->SetDirectory(fl_get_input(pFileDlgForm->DirBox));
- pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
- pCurrentDlg->Reread();
- break;
-
- case 11: // home
- pCurrentDlg->SetDirectory(GetEnvPath("HOME"));
- pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
- pCurrentDlg->Reread();
- break;
-
- case 12: // user button 1
- if (!pCurrentDlg->pszUserPath1.empty()) {
- pCurrentDlg->SetDirectory(pCurrentDlg->pszUserPath1);
- pCurrentDlg->SetMask(fl_get_input(pFileDlgForm
- ->PatBox));
- pCurrentDlg->Reread();
- }
- break;
-
- case 13: // user button 2
- if (!pCurrentDlg->pszUserPath2.empty()) {
- pCurrentDlg->SetDirectory(pCurrentDlg->pszUserPath2);
- pCurrentDlg->SetMask(fl_get_input(pFileDlgForm
- ->PatBox));
- pCurrentDlg->Reread();
- }
- break;
-
- }
-}
-
-
-extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT * ob, long data)
-{
- LyXFileDlg::FileDlgCB(ob, data);
-}
-
-
-// Handle callback from list
-void LyXFileDlg::HandleListHit()
-{
- // set info line
- int const iSelect = fl_get_browser(pFileDlgForm->List);
- if (iSelect > iDepth) {
- SetInfoLine(direntries[iSelect - iDepth - 1].pszLsEntry);
- } else {
- SetInfoLine(string());
- }
-}
-
-
-// Callback for double click in list
-void LyXFileDlg::DoubleClickCB(FL_OBJECT *, long)
-{
- if (pCurrentDlg->HandleDoubleClick())
- // Simulate click on OK button
- pCurrentDlg->Force(false);
-}
-
-
-extern "C" void C_LyXFileDlg_DoubleClickCB(FL_OBJECT * ob, long data)
-{
- LyXFileDlg::DoubleClickCB(ob, data);
-}
-
-
-// Handle double click from list
-bool LyXFileDlg::HandleDoubleClick()
-{
- string pszTemp;
-
- // set info line
- bool isDir = true;
- int const iSelect = fl_get_browser(pFileDlgForm->List);
- if (iSelect > iDepth) {
- pszTemp = direntries[iSelect - iDepth - 1].pszName;
- SetInfoLine(direntries[iSelect - iDepth - 1].pszLsEntry);
- if (!suffixIs(pszTemp, '/')) {
- isDir = false;
- fl_set_input(pFileDlgForm->Filename, pszTemp.c_str());
- }
- } else if (iSelect != 0) {
- SetInfoLine(string());
- } else
- return true;
-
- // executes action
- if (isDir) {
- string Temp;
-
- // builds new directory name
- if (iSelect > iDepth) {
- // Directory deeper down
- // First, get directory with trailing /
- Temp = fl_get_input(pFileDlgForm->DirBox);
- if (!suffixIs(Temp, '/'))
- Temp += '/';
- Temp += pszTemp;
- } else {
- // Directory higher up
- Temp.erase();
- for (int i = 0; i < iSelect; ++i) {
- string piece = fl_get_browser_line(pFileDlgForm->List, i+1);
- // The '+2' is here to count the '@b' (JMarc)
- Temp += piece.substr(i + 2);
- }
- }
-
- // assigns it
- SetDirectory(Temp);
- Reread();
- return false;
- }
- return true;
-}
-
-
-// Handle OK button call
-bool LyXFileDlg::HandleOK()
-{
- // mask was changed
- string pszTemp = fl_get_input(pFileDlgForm->PatBox);
- if (pszTemp != pszMask) {
- SetMask(pszTemp);
- Reread();
- return false;
- }
-
- // directory was changed
- pszTemp = fl_get_input(pFileDlgForm->DirBox);
- if (pszTemp!= pszDirectory) {
- SetDirectory(pszTemp);
- Reread();
- return false;
- }
-
- // Handle return from list
- int const select = fl_get_browser(pFileDlgForm->List);
- if (select > iDepth) {
- string const temp = direntries[select - iDepth - 1].pszName;
- if (!suffixIs(temp, '/')) {
- // If user didn't type anything, use browser
- string const name =
- fl_get_input(pFileDlgForm->Filename);
- if (name.empty()) {
- fl_set_input(pFileDlgForm->Filename, temp.c_str());
- }
- return true;
- }
- }
-
- // Emulate a doubleclick
- return HandleDoubleClick();
-}
-
-
-// Handle Cancel CB from WM close
-int LyXFileDlg::CancelCB(FL_FORM *, void *)
-{
- // Simulate a click on the cancel button
- pCurrentDlg->Force(true);
- return FL_IGNORE;
-}
-
-
-extern "C" int C_LyXFileDlg_CancelCB(FL_FORM *fl, void *xev)
-{
- return LyXFileDlg::CancelCB(fl, xev);
-}
-
-
-// Simulates a click on OK/Cancel
-void LyXFileDlg::Force(bool cancel)
-{
- if (cancel) {
- force_cancel = true;
- fl_set_button(pFileDlgForm->Cancel, 1);
- } else {
- force_ok = true;
- fl_set_button(pFileDlgForm->Ready, 1);
- }
- // Start timer to break fl_do_forms loop soon
- fl_set_timer(pFileDlgForm->timer, 0.1);
-}
-
-
-// Select: launches dialog and returns selected file
-string const LyXFileDlg::Select(string const & title, string const & path,
- string const & mask, string const & suggested)
-{
- // handles new mask and path
- bool isOk = true;
- if (!mask.empty()) {
- SetMask(mask);
- isOk = false;
- }
- if (!path.empty()) {
- SetDirectory(path);
- isOk = false;
- }
- if (!isOk) Reread();
-
- // highlight the suggested file in the browser, if it exists.
- int sel = 0;
- string const filename = OnlyFilename(suggested);
- if (!filename.empty()) {
- for (int i = 0;
- i < fl_get_browser_maxline(pFileDlgForm->List); ++i) {
- string s =
- fl_get_browser_line(pFileDlgForm->List, i + 1);
- s = strip(frontStrip(s));
- if (s == filename) {
- sel = i + 1;
- break;
- }
- }
- }
-
- if (sel != 0) fl_select_browser_line(pFileDlgForm->List, sel);
- int const top = max(sel - 5, 1);
- fl_set_browser_topline(pFileDlgForm->List, top);
-
- // checks whether dialog can be started
- if (pCurrentDlg) return string();
- pCurrentDlg = this;
-
- // runs dialog
- SetInfoLine(string());
- 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_deactivate_all_forms();
- fl_show_form(pFileDlgForm->FileDlg,
- FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
- title.c_str());
-
- isOk = RunDialog();
-
- fl_hide_form(pFileDlgForm->FileDlg);
- fl_activate_all_forms();
- pCurrentDlg = 0;
-
- // Returns filename or string() if no valid selection was made
- if (!isOk || !fl_get_input(pFileDlgForm->Filename)[0]) return string();
-
- pszFileName = fl_get_input(pFileDlgForm->Filename);
-
- if (!AbsolutePath(pszFileName)) {
- pszFileName = AddName(fl_get_input(pFileDlgForm->DirBox),
- pszFileName);
- }
- return pszFileName;
-}
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
- *
- * ====================================================== */
-
-#ifndef FILEDLG_H
-#define FILEDLG_H
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include <vector>
-#include <sigc++/signal_system.h>
-
-#include "LString.h"
-#include FORMS_H_LOCATION
-#include "form1.h"
-
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::Object;
-using SigC::Connection;
-#endif
-
-/// LyXDirEntry internal structure definition
-class LyXDirEntry {
-public:
- ///
- string pszName;
- ///
- string pszDisplayed;
- ///
- string pszLsEntry;
-};
-
-
-/// FileDlg class definition
-class LyXFileDlg : public Object
-{
-public:
- ///
- LyXFileDlg();
- ///
- ~LyXFileDlg();
-
- /// sets file selector user button action
- 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 & pszSuggested = string());
- /// XForms objects callback (static)
- static void FileDlgCB(FL_OBJECT *, long);
- /// Callback for double click in list
- 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 LyXFileDlg * pCurrentDlg;
- ///
- string pszUserPath1;
- ///
- string pszUserPath2;
- ///
- string pszDirectory;
- ///
- string pszMask;
- ///
- string pszFileName;
- ///
- int iDepth;
- ///
- int iLastSel;
- ///
- long lLastTime;
- ///
- string pszInfoLine;
- ///
- typedef std::vector<LyXDirEntry> DirEntries;
- ///
- DirEntries direntries;
- ///
- bool force_cancel;
- ///
- bool force_ok;
-
- /** Redraw the form (on receipt of a Signal indicating, for example,
- that the xform colors have been re-mapped).
- */
- void redraw();
- /// updates dialog list to match class directory
- void Reread();
- /// sets dialog current directory
- void SetDirectory(string const & pszPath);
- /// sets dialog file mask
- void SetMask(string const & pszNewMask);
- /// sets dialog information line
- void SetInfoLine(string const & pszLine);
- /// handle dialog during file selection
- bool RunDialog();
- /// Handle callback from list
- void HandleListHit();
- /// Handle double click from list
- bool HandleDoubleClick();
- /// Handle OK button call
- bool HandleOK();
- /// Simulates a click on OK/Cancel
- void Force(bool);
- /// Redraw connection.
- Connection r_;
-};
-
-#endif
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;
-}
-/*---------------------------------------*/
-
} 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;
+2001-02-26 John Levon <moz@compsoc.man.ac.uk>
+
+ * Makefile.am
+ * FileDialog.h: new GUII FileDialog
+
2001-02-23 Edwin Leuven <leuven@fee.uva.nl)
* Dialogs.h: setUserFreeFont, showLayoutCharacter
--- /dev/null
+/**
+ * \file FileDialog.h
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author unknown
+ * \author John Levon
+ */
+
+#ifndef FILEDIALOG_H
+#define FILEDIALOG_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <config.h>
+#include <utility>
+
+#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<string, string> Button;
+
+ /// result type
+ enum ResultType {
+ Later, /**< modeless chooser, no result */
+ Chosen /**< string contains filename */
+ };
+
+ /// result return
+ typedef std::pair<FileDialog::ResultType, string> 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 :
+ *
+ * <regular expression to match> | <description>
+ *
+ * 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
ButtonPolicies.h \
Dialogs.h \
DialogBase.h \
+ FileDialog.h \
GUIRunTime.h \
Liason.C \
Liason.h \
+2001-02-26 John Levon <moz@compsoc.man.ac.uk>
+
+ * <various>: 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 <dekelts@tau.ac.il>
* FormRef.C (apply): Update bookmark #0 after inserting a reference.
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));
// reduce the number of connections needed in
// dialogs by a simple connection here.
hideAll.connect(hideBufferDependent.slot());
+*/
}
--- /dev/null
+/**
+ * \file FileDialog.C
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon
+ */
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <config.h>
+#include <gettext.h>
+#include <utility>
+
+#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());
+}
--- /dev/null
+/**
+ * \file FileDialog_private.C
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon
+ */
+
+#include <config.h>
+
+#include "LString.h"
+
+#include <kapp.h>
+#include <kfiledialog.h>
+
+#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;
+}
--- /dev/null
+/**
+ * \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 <config.h>
+
+#include <kfiledialog.h>
+
+#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
class LyXView;
class CitationDialog;
-class FormCitation : public DialogBase, public noncopyable {
+class FormCitation : public DialogBase {
public:
FormCitation(LyXView *, Dialogs *);
class LyXView;
class CopyrightDialog;
-class FormCopyright : public DialogBase, public noncopyable {
+class FormCopyright : public DialogBase {
public:
FormCopyright(LyXView *, Dialogs *);
/**
* \brief the LyXian side of the complex Document dialog
*/
-class FormDocument : public DialogBase, public noncopyable {
+class FormDocument : public DialogBase {
public:
FormDocument(LyXView *, Dialogs *);
class LyXView;
class IndexDialog;
-class FormIndex : public DialogBase, public noncopyable {
+class FormIndex : public DialogBase {
public:
FormIndex(LyXView *, Dialogs *);
class LyXView;
class LogDialog;
-class FormLog : public DialogBase, public noncopyable {
+class FormLog : public DialogBase {
public:
FormLog(LyXView *, Dialogs *);
class LyXView;
class ParaDialog;
-class FormParagraph : public DialogBase, public noncopyable {
+class FormParagraph : public DialogBase {
public:
FormParagraph(LyXView *, Dialogs *);
using SigC::Connection;
#endif
-class FormPrint : public DialogBase, public noncopyable {
+class FormPrint : public DialogBase {
public:
FormPrint(LyXView *, Dialogs *);
class LyXView;
class RefDialog;
-class FormRef : public DialogBase, public noncopyable {
+class FormRef : public DialogBase {
public:
FormRef(LyXView *, Dialogs *);
class LyXView;
class TabularCreateDialog;
-class FormTabularCreate : public DialogBase, public noncopyable {
+class FormTabularCreate : public DialogBase {
public:
FormTabularCreate(LyXView *, Dialogs *);
class Dialogs;
class TocDialog;
-class FormToc : public DialogBase, public noncopyable {
+class FormToc : public DialogBase {
public:
FormToc(LyXView *, Dialogs *);
class LyXView;
class UrlDialog;
-class FormUrl : public DialogBase, public noncopyable {
+class FormUrl : public DialogBase {
public:
FormUrl(LyXView *, Dialogs *);
class LyXView;
class LogDialog;
-class FormVCLog : public DialogBase, public noncopyable {
+class FormVCLog : public DialogBase {
public:
FormVCLog(LyXView *, Dialogs *);
ETAGS_ARGS = --lang=c++
libkde_la_SOURCES = \
Dialogs.C \
+ FileDialog.C \
+ FileDialog_private.C \
+ FileDialog_private.h \
GUIRunTime.C \
QtLyXView.h \
Timeout_pimpl.C \
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
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());
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 \
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
+2001-03-06 John Levon <moz@compsoc.man.ac.uk>
+
+ * 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 <larsbj@trylle.birdstep.com>
* FormParagraph.C: changes because of ParagraphParameters.
--- /dev/null
+/**
+ * \file FileDialog.C
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author John Levon
+ */
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <config.h>
+#include <gettext.h>
+#include <utility>
+
+#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;
+}
--- /dev/null
+/**
+ * \file FormFiledialog.C
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author unknown
+ * \author John Levon
+ */
+
+#include <config.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <pwd.h>
+#include <grp.h>
+#include <cstring>
+#include <map>
+#include <algorithm>
+
+using std::map;
+using std::max;
+using std::sort;
+
+#include "lyx_gui_misc.h" // for WriteFSAlert
+#include "support/FileInfo.h"
+#include "support/lyxlib.h"
+#include "gettext.h"
+#include "frontends/Dialogs.h"
+
+#ifdef HAVE_ERRNO_H
+#include <cerrno>
+#endif
+
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+# include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+# include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+# include <ndir.h>
+# endif
+#endif
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <ctime>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <ctime>
+# endif
+#endif
+
+// FIXME: should be autoconfiscated
+#ifdef BROKEN_HEADERS
+extern "C" int gettimeofday(struct timeval *, struct timezone *);
+#endif
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "support/filetools.h"
+#include "FormFiledialog.h"
+
+#ifdef SIGC_CXX_NAMESPACES
+using SigC::slot;
+#endif
+
+// six months, in seconds
+static const long SIX_MONTH_SEC = 6L * 30L * 24L * 60L * 60L;
+static const long ONE_HOUR_SEC = 60L * 60L;
+
+// *** User cache class implementation
+/// User cache class definition
+class UserCache {
+public:
+ /// seeks user name from group ID
+ string const & find(uid_t ID) const {
+ Users::const_iterator cit = users.find(ID);
+ if (cit == users.end()) {
+ add(ID);
+ return users[ID];
+ }
+ return (*cit).second;
+ }
+private:
+ ///
+ void add(uid_t ID) const;
+ ///
+ typedef map<uid_t, string> Users;
+ ///
+ mutable Users users;
+};
+
+
+void UserCache::add(uid_t ID) const
+{
+ string pszNewName;
+ struct passwd * pEntry;
+
+ // gets user name
+ if ((pEntry = getpwuid(ID)))
+ pszNewName = pEntry->pw_name;
+ else {
+ pszNewName = tostr(ID);
+ }
+
+ // adds new node
+ users[ID] = pszNewName;
+}
+
+
+/// Group cache class definition
+class GroupCache {
+public:
+ /// seeks group name from group ID
+ string const & find(gid_t ID) const ;
+private:
+ ///
+ void add(gid_t ID) const;
+ ///
+ typedef map<gid_t, string> Groups;
+ ///
+ mutable Groups groups;
+};
+
+
+string const & GroupCache::find(gid_t ID) const
+{
+ Groups::const_iterator cit = groups.find(ID);
+ if (cit == groups.end()) {
+ add(ID);
+ return groups[ID];
+ }
+ return (*cit).second;
+}
+
+
+void GroupCache::add(gid_t ID) const
+{
+ string pszNewName;
+ struct group * pEntry;
+
+ // gets user name
+ if ((pEntry = getgrgid(ID))) pszNewName = pEntry->gr_name;
+ else {
+ pszNewName = tostr(ID);
+ }
+ // adds new node
+ groups[ID] = pszNewName;
+}
+
+
+// static instances
+static UserCache lyxUserCache;
+static GroupCache lyxGroupCache;
+
+
+// compares two LyXDirEntry objects content (used for sort)
+class comp_direntry {
+public:
+ int operator()(DirEntry const & r1,
+ DirEntry 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;
+ if (!r1d && r2d) return 0;
+ return r1.pszName < r2.pszName;
+ }
+
+
+// *** FileDialog::Private class implementation
+
+// static members
+FD_form_filedialog * FileDialog::Private::pFileDlgForm = 0;
+FileDialog::Private * FileDialog::Private::pCurrentDlg = 0;
+
+
+// Reread: updates dialog list to match class directory
+void FileDialog::Private::Reread()
+{
+ // Opens directory
+ DIR * pDirectory = ::opendir(pszDirectory.c_str());
+ if (!pDirectory) {
+ WriteFSAlert(_("Warning! Couldn't open directory."),
+ pszDirectory);
+ pszDirectory = lyx::getcwd();
+ pDirectory = ::opendir(pszDirectory.c_str());
+ }
+
+ // Clear the present namelist
+ direntries.clear();
+
+ // Updates display
+ fl_hide_object(pFileDlgForm->List);
+ fl_clear_browser(pFileDlgForm->List);
+ fl_set_input(pFileDlgForm->DirBox, pszDirectory.c_str());
+
+ // Splits complete directory name into directories and compute depth
+ iDepth = 0;
+ string line, Temp;
+ char szMode[15];
+ FileInfo fileInfo;
+ string File = pszDirectory;
+ if (File != "/") {
+ File = split(File, Temp, '/');
+ }
+ while (!File.empty() || !Temp.empty()) {
+ string dline = "@b"+line + Temp + '/';
+ fl_add_browser_line(pFileDlgForm->List, dline.c_str());
+ File = split(File, Temp, '/');
+ line += ' ';
+ ++iDepth;
+ }
+
+ // Parses all entries of the given subdirectory
+ time_t curTime = time(0);
+ rewinddir(pDirectory);
+ struct dirent * pDirEntry;
+ while ((pDirEntry = readdir(pDirectory))) {
+ bool isLink = false, isDir = false;
+
+ // If the pattern doesn't start with a dot, skip hidden files
+ if (!pszMask.empty() && pszMask[0] != '.' &&
+ pDirEntry->d_name[0] == '.')
+ continue;
+
+ // Gets filename
+ string fname = pDirEntry->d_name;
+
+ // Under all circumstances, "." and ".." are not wanted
+ if (fname == "." || fname == "..")
+ continue;
+
+ // gets file status
+ File = AddName(pszDirectory, fname);
+
+ fileInfo.newFile(File, true);
+ fileInfo.modeString(szMode);
+ unsigned int nlink = fileInfo.getNumberOfLinks();
+ string user = lyxUserCache.find(fileInfo.getUid());
+ string group = lyxGroupCache.find(fileInfo.getGid());
+
+ time_t modtime = fileInfo.getModificationTime();
+ string Time = ctime(&modtime);
+
+ if (curTime > fileInfo.getModificationTime() + SIX_MONTH_SEC
+ || curTime < fileInfo.getModificationTime()
+ + ONE_HOUR_SEC) {
+ // The file is fairly old or in the future. POSIX says
+ // the cutoff is 6 months old. Allow a 1 hour slop
+ // factor for what is considered "the future", to
+ // allow for NFS server/client clock disagreement.
+ // Show the year instead of the time of day.
+ Time.erase(10, 9);
+ Time.erase(15, string::npos);
+ } else {
+ Time.erase(16, string::npos);
+ }
+
+ string Buffer = string(szMode) + ' ' +
+ tostr(nlink) + ' ' +
+ user + ' ' +
+ group + ' ' +
+ Time.substr(4, string::npos) + ' ';
+
+ Buffer += pDirEntry->d_name;
+ Buffer += fileInfo.typeIndicator();
+
+ if ((isLink = fileInfo.isLink())) {
+ string Link;
+
+ if (LyXReadLink(File, Link)) {
+ Buffer += " -> ";
+ Buffer += Link;
+
+ // This gives the FileType of the file that
+ // is really pointed too after resolving all
+ // symlinks. This is not necessarily the same
+ // as the type of Link (which could again be a
+ // link). Is that intended?
+ // JV 199902
+ fileInfo.newFile(File);
+ Buffer += fileInfo.typeIndicator();
+ }
+ }
+
+ // filters files according to pattern and type
+ if (fileInfo.isRegular()
+ || fileInfo.isChar()
+ || fileInfo.isBlock()
+ || fileInfo.isFifo()) {
+ if (!regexMatch(fname, pszMask))
+ continue;
+ } else if (!(isDir = fileInfo.isDir()))
+ continue;
+
+ DirEntry tmp;
+
+ // Note pszLsEntry is an string!
+ tmp.pszLsEntry = Buffer;
+ // creates used name
+ string temp = fname;
+ if (isDir) temp += '/';
+
+ tmp.pszName = temp;
+ // creates displayed name
+ temp = pDirEntry->d_name;
+ if (isLink)
+ temp += '@';
+ else
+ temp += fileInfo.typeIndicator();
+ tmp.pszDisplayed = temp;
+
+ direntries.push_back(tmp);
+ }
+
+ closedir(pDirectory);
+
+ // Sort the names
+ sort(direntries.begin(), direntries.end(), comp_direntry());
+
+ // Add them to directory box
+ for (DirEntries::const_iterator cit = direntries.begin();
+ cit != direntries.end(); ++cit) {
+ string const temp = line + (*cit).pszDisplayed;
+ fl_add_browser_line(pFileDlgForm->List, temp.c_str());
+ }
+ fl_set_browser_topline(pFileDlgForm->List, iDepth);
+ fl_show_object(pFileDlgForm->List);
+ iLastSel = -1;
+}
+
+
+// SetDirectory: sets dialog current directory
+void FileDialog::Private::SetDirectory(string const & Path)
+{
+ if (!pszDirectory.empty()) {
+ string TempPath = ExpandPath(Path); // Expand ~/
+ TempPath = MakeAbsPath(TempPath, pszDirectory);
+ pszDirectory = MakeAbsPath(TempPath);
+ } else pszDirectory = MakeAbsPath(Path);
+}
+
+
+// SetMask: sets dialog file mask
+void FileDialog::Private::SetMask(string const & NewMask)
+{
+ pszMask = NewMask;
+ fl_set_input(pFileDlgForm->PatBox, pszMask.c_str());
+}
+
+
+// SetInfoLine: sets dialog information line
+void FileDialog::Private::SetInfoLine(string const & Line)
+{
+ pszInfoLine = Line;
+ fl_set_object_label(pFileDlgForm->FileInfo, pszInfoLine.c_str());
+}
+
+
+FileDialog::Private::Private()
+{
+ pszDirectory = MakeAbsPath(string("."));
+ pszMask = '*';
+
+ // Creates form if necessary.
+ if (!pFileDlgForm) {
+ 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);
+ fl_set_object_callback(pFileDlgForm->PatBox,
+ C_LyXFileDlg_FileDlgCB, 1);
+ fl_set_object_callback(pFileDlgForm->List,
+ C_LyXFileDlg_FileDlgCB, 2);
+ fl_set_object_callback(pFileDlgForm->Filename,
+ C_LyXFileDlg_FileDlgCB, 3);
+ fl_set_object_callback(pFileDlgForm->Rescan,
+ C_LyXFileDlg_FileDlgCB, 10);
+ fl_set_object_callback(pFileDlgForm->Home,
+ C_LyXFileDlg_FileDlgCB, 11);
+ fl_set_object_callback(pFileDlgForm->User1,
+ C_LyXFileDlg_FileDlgCB, 12);
+ fl_set_object_callback(pFileDlgForm->User2,
+ C_LyXFileDlg_FileDlgCB, 13);
+
+ // Make sure pressing the close box doesn't crash LyX. (RvdK)
+ fl_set_form_atclose(pFileDlgForm->form,
+ C_LyXFileDlg_CancelCB, 0);
+ // Register doubleclick callback
+ fl_set_browser_dblclick_callback(pFileDlgForm->List,
+ C_LyXFileDlg_DoubleClickCB,
+ 0);
+ }
+ fl_hide_object(pFileDlgForm->User1);
+ fl_hide_object(pFileDlgForm->User2);
+
+ r_ = Dialogs::redrawGUI.connect(slot(this, &FileDialog::Private::redraw));
+}
+
+
+FileDialog::Private::~Private()
+{
+ r_.disconnect();
+}
+
+
+void FileDialog::Private::redraw()
+{
+ if (pFileDlgForm->form && pFileDlgForm->form->visible)
+ fl_redraw_form(pFileDlgForm->form);
+}
+
+
+// SetButton: sets file selector user button action
+void FileDialog::Private::SetButton(int iIndex, string const & pszName,
+ string const & pszPath)
+{
+ FL_OBJECT * pObject;
+ string * pTemp;
+
+ if (iIndex == 0) {
+ pObject = pFileDlgForm->User1;
+ pTemp = &pszUserPath1;
+ } else if (iIndex == 1) {
+ pObject = pFileDlgForm->User2;
+ pTemp = &pszUserPath2;
+ } else return;
+
+ if (!pszName.empty() && !pszPath.empty()) {
+ fl_set_object_label(pObject, pszName.c_str());
+ fl_show_object(pObject);
+ *pTemp = pszPath;
+ } else {
+ fl_hide_object(pObject);
+ (*pTemp).erase();
+ }
+}
+
+
+// GetDirectory: gets last dialog directory
+string const FileDialog::Private::GetDirectory() const
+{
+ if (!pszDirectory.empty())
+ return pszDirectory;
+ else
+ return string(".");
+}
+
+
+// RunDialog: handle dialog during file selection
+bool FileDialog::Private::RunDialog()
+{
+ force_cancel = false;
+ force_ok = false;
+
+ // event loop
+ while(true) {
+ FL_OBJECT * pObject = fl_do_forms();
+
+ if (pObject == pFileDlgForm->Ready) {
+ if (HandleOK())
+ return true;
+ } else if (pObject == pFileDlgForm->Cancel
+ || force_cancel)
+ return false;
+ else if (force_ok)
+ return true;
+ }
+}
+
+
+// XForms objects callback (static)
+void FileDialog::Private::FileDlgCB(FL_OBJECT *, long lArgument)
+{
+ if (!pCurrentDlg) return;
+
+ switch (lArgument) {
+
+ case 0: // get directory
+ pCurrentDlg->SetDirectory(fl_get_input(pFileDlgForm->DirBox));
+ pCurrentDlg->Reread();
+ break;
+
+ case 1: // get mask
+ pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
+ pCurrentDlg->Reread();
+ break;
+
+ case 2: // list
+ pCurrentDlg->HandleListHit();
+ break;
+
+ case 10: // rescan
+ pCurrentDlg->SetDirectory(fl_get_input(pFileDlgForm->DirBox));
+ pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
+ pCurrentDlg->Reread();
+ break;
+
+ case 11: // home
+ pCurrentDlg->SetDirectory(GetEnvPath("HOME"));
+ pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
+ pCurrentDlg->Reread();
+ break;
+
+ case 12: // user button 1
+ if (!pCurrentDlg->pszUserPath1.empty()) {
+ pCurrentDlg->SetDirectory(pCurrentDlg->pszUserPath1);
+ pCurrentDlg->SetMask(fl_get_input(pFileDlgForm
+ ->PatBox));
+ pCurrentDlg->Reread();
+ }
+ break;
+
+ case 13: // user button 2
+ if (!pCurrentDlg->pszUserPath2.empty()) {
+ pCurrentDlg->SetDirectory(pCurrentDlg->pszUserPath2);
+ pCurrentDlg->SetMask(fl_get_input(pFileDlgForm
+ ->PatBox));
+ pCurrentDlg->Reread();
+ }
+ break;
+
+ }
+}
+
+
+extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT * ob, long data)
+{
+ FileDialog::Private::FileDlgCB(ob, data);
+}
+
+
+// Handle callback from list
+void FileDialog::Private::HandleListHit()
+{
+ // set info line
+ int const iSelect = fl_get_browser(pFileDlgForm->List);
+ if (iSelect > iDepth) {
+ SetInfoLine(direntries[iSelect - iDepth - 1].pszLsEntry);
+ } else {
+ SetInfoLine(string());
+ }
+}
+
+
+// Callback for double click in list
+void FileDialog::Private::DoubleClickCB(FL_OBJECT *, long)
+{
+ if (pCurrentDlg->HandleDoubleClick())
+ // Simulate click on OK button
+ pCurrentDlg->Force(false);
+}
+
+
+extern "C" void C_LyXFileDlg_DoubleClickCB(FL_OBJECT * ob, long data)
+{
+ FileDialog::Private::DoubleClickCB(ob, data);
+}
+
+
+// Handle double click from list
+bool FileDialog::Private::HandleDoubleClick()
+{
+ string pszTemp;
+
+ // set info line
+ bool isDir = true;
+ int const iSelect = fl_get_browser(pFileDlgForm->List);
+ if (iSelect > iDepth) {
+ pszTemp = direntries[iSelect - iDepth - 1].pszName;
+ SetInfoLine(direntries[iSelect - iDepth - 1].pszLsEntry);
+ if (!suffixIs(pszTemp, '/')) {
+ isDir = false;
+ fl_set_input(pFileDlgForm->Filename, pszTemp.c_str());
+ }
+ } else if (iSelect != 0) {
+ SetInfoLine(string());
+ } else
+ return true;
+
+ // executes action
+ if (isDir) {
+ string Temp;
+
+ // builds new directory name
+ if (iSelect > iDepth) {
+ // Directory deeper down
+ // First, get directory with trailing /
+ Temp = fl_get_input(pFileDlgForm->DirBox);
+ if (!suffixIs(Temp, '/'))
+ Temp += '/';
+ Temp += pszTemp;
+ } else {
+ // Directory higher up
+ Temp.erase();
+ for (int i = 0; i < iSelect; ++i) {
+ string piece = fl_get_browser_line(pFileDlgForm->List, i+1);
+ // The '+2' is here to count the '@b' (JMarc)
+ Temp += piece.substr(i + 2);
+ }
+ }
+
+ // assigns it
+ SetDirectory(Temp);
+ Reread();
+ return false;
+ }
+ return true;
+}
+
+
+// Handle OK button call
+bool FileDialog::Private::HandleOK()
+{
+ // mask was changed
+ string pszTemp = fl_get_input(pFileDlgForm->PatBox);
+ if (pszTemp != pszMask) {
+ SetMask(pszTemp);
+ Reread();
+ return false;
+ }
+
+ // directory was changed
+ pszTemp = fl_get_input(pFileDlgForm->DirBox);
+ if (pszTemp!= pszDirectory) {
+ SetDirectory(pszTemp);
+ Reread();
+ return false;
+ }
+
+ // Handle return from list
+ int const select = fl_get_browser(pFileDlgForm->List);
+ if (select > iDepth) {
+ string const temp = direntries[select - iDepth - 1].pszName;
+ if (!suffixIs(temp, '/')) {
+ // If user didn't type anything, use browser
+ string const name =
+ fl_get_input(pFileDlgForm->Filename);
+ if (name.empty()) {
+ fl_set_input(pFileDlgForm->Filename, temp.c_str());
+ }
+ return true;
+ }
+ }
+
+ // Emulate a doubleclick
+ return HandleDoubleClick();
+}
+
+
+// Handle Cancel CB from WM close
+int FileDialog::Private::CancelCB(FL_FORM *, void *)
+{
+ // Simulate a click on the cancel button
+ pCurrentDlg->Force(true);
+ return FL_IGNORE;
+}
+
+
+extern "C" int C_LyXFileDlg_CancelCB(FL_FORM *fl, void *xev)
+{
+ return FileDialog::Private::CancelCB(fl, xev);
+}
+
+
+// Simulates a click on OK/Cancel
+void FileDialog::Private::Force(bool cancel)
+{
+ if (cancel) {
+ force_cancel = true;
+ fl_set_button(pFileDlgForm->Cancel, 1);
+ } else {
+ force_ok = true;
+ fl_set_button(pFileDlgForm->Ready, 1);
+ }
+ // Start timer to break fl_do_forms loop soon
+ fl_set_timer(pFileDlgForm->timer, 0.1);
+}
+
+
+// Select: launches dialog and returns selected file
+string const FileDialog::Private::Select(string const & title, string const & path,
+ string const & mask, string const & suggested)
+{
+ // handles new mask and path
+ bool isOk = true;
+ if (!mask.empty()) {
+ SetMask(mask);
+ isOk = false;
+ }
+ if (!path.empty()) {
+ SetDirectory(path);
+ isOk = false;
+ }
+ if (!isOk) Reread();
+
+ // highlight the suggested file in the browser, if it exists.
+ int sel = 0;
+ string const filename = OnlyFilename(suggested);
+ if (!filename.empty()) {
+ for (int i = 0;
+ i < fl_get_browser_maxline(pFileDlgForm->List); ++i) {
+ string s =
+ fl_get_browser_line(pFileDlgForm->List, i + 1);
+ s = strip(frontStrip(s));
+ if (s == filename) {
+ sel = i + 1;
+ break;
+ }
+ }
+ }
+
+ if (sel != 0) fl_select_browser_line(pFileDlgForm->List, sel);
+ int const top = max(sel - 5, 1);
+ fl_set_browser_topline(pFileDlgForm->List, top);
+
+ // checks whether dialog can be started
+ if (pCurrentDlg) return string();
+ pCurrentDlg = this;
+
+ // runs dialog
+ SetInfoLine(string());
+ 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->form, pFileDlgForm->Filename);
+ fl_deactivate_all_forms();
+ fl_show_form(pFileDlgForm->form,
+ FL_PLACE_MOUSE | FL_FREE_SIZE, 0,
+ title.c_str());
+
+ isOk = RunDialog();
+
+ fl_hide_form(pFileDlgForm->form);
+ fl_activate_all_forms();
+ pCurrentDlg = 0;
+
+ // Returns filename or string() if no valid selection was made
+ if (!isOk || !fl_get_input(pFileDlgForm->Filename)[0]) return string();
+
+ pszFileName = fl_get_input(pFileDlgForm->Filename);
+
+ if (!AbsolutePath(pszFileName)) {
+ pszFileName = AddName(fl_get_input(pFileDlgForm->DirBox),
+ pszFileName);
+ }
+ return pszFileName;
+}
--- /dev/null
+/**
+ * \file FormFiledialog.h
+ * Copyright 2001 the LyX Team
+ * Read the file COPYING
+ *
+ * \author unknown
+ * \author John Levon
+ */
+
+#ifndef FORMFILEDIALOG_H
+#define FORMFILEDIALOG_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <config.h>
+
+#include <vector>
+#include <sigc++/signal_system.h>
+
+#include "LString.h"
+#include FORMS_H_LOCATION
+#include "form_filedialog.h"
+
+#include "frontends/FileDialog.h"
+
+#ifdef SIGC_CXX_NAMESPACES
+using SigC::Object;
+using SigC::Connection;
+#endif
+
+/// DirEntry internal structure definition
+class DirEntry {
+public:
+ ///
+ string pszName;
+ ///
+ string pszDisplayed;
+ ///
+ 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);
+
+class FileDialog::Private : public Object
+{
+public:
+ ///
+ Private();
+ ///
+ ~Private();
+
+ /// sets file selector user button action
+ 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 & pszSuggested = string());
+ /// XForms objects callback (static)
+ static void FileDlgCB(FL_OBJECT *, long);
+ /// Callback for double click in list
+ static void DoubleClickCB(FL_OBJECT *, long);
+ /// Handle Cancel CB from WM close
+ static int CancelCB(FL_FORM *, void *);
+
+private:
+ /// data
+ static FD_form_filedialog * pFileDlgForm;
+ ///
+ static FileDialog::Private * pCurrentDlg;
+ ///
+ string pszUserPath1;
+ ///
+ string pszUserPath2;
+ ///
+ string pszDirectory;
+ ///
+ string pszMask;
+ ///
+ string pszFileName;
+ ///
+ int iDepth;
+ ///
+ int iLastSel;
+ ///
+ long lLastTime;
+ ///
+ string pszInfoLine;
+ ///
+ typedef std::vector<DirEntry> DirEntries;
+ ///
+ DirEntries direntries;
+ ///
+ bool force_cancel;
+ ///
+ 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).
+ */
+ void redraw();
+ /// updates dialog list to match class directory
+ void Reread();
+ /// sets dialog current directory
+ void SetDirectory(string const & pszPath);
+ /// sets dialog file mask
+ void SetMask(string const & pszNewMask);
+ /// sets dialog information line
+ void SetInfoLine(string const & pszLine);
+ /// handle dialog during file selection
+ bool RunDialog();
+ /// Handle callback from list
+ void HandleListHit();
+ /// Handle double click from list
+ bool HandleDoubleClick();
+ /// Handle OK button call
+ bool HandleOK();
+ /// Simulates a click on OK/Cancel
+ void Force(bool);
+ /// Redraw connection.
+ Connection r_;
+};
+
+#endif // FORMFILEDIALOG_H
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");
// 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
*/
#include <config.h>
#include <algorithm>
-#include <iostream>
+#include <utility>
#ifdef __GNUG__
#pragma implementation
#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"
#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));
}
//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))
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;
//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());
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;
// 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()) {
// 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()));
Color.C \
Color.h \
Dialogs.C \
+ FileDialog.C \
+ FormFiledialog.h \
+ FormFiledialog.C \
+ form_filedialog.C \
+ form_filedialog.h \
GUIRunTime.C \
FormBase.C \
FormBase.h \
#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;
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<FL_OBJECT *>(ob->u_cdata);
}
#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<Toolbar::Pimpl *>(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()
{
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;
*/
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);
/// 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.
void openLayoutList();
/// Erase the layout list
void clearLayoutList();
+ /// and the non-static version
+ void layoutSelected(int);
///
struct toolbarItem
--- /dev/null
+// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext
+#include <config.h>
+#include "lyx_gui_misc.h"
+#include "gettext.h"
+
+/* Form definition file generated with fdesign. */
+
+#include FORMS_H_LOCATION
+#include <stdlib.h>
+#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;
+}
+/*---------------------------------------*/
+
--- /dev/null
+// 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_ */
-#! /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.
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"
--- /dev/null
+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:
+
+==============================
+--------------------
form_copyright.fd \
form_document.fd \
form_error.fd \
+ form_filedialog.fd \
form_graphics.fd \
form_include.fd \
form_index.fd \
#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
}
-string const browseFile(string const & filename,
+string const browseFile(LyXView * lv, string const & filename,
string const & title,
string const & pattern,
pair<string,string> const & dir1,
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;
}
// 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<string,string> const & dir1,
+2001-03-06 John Levon <moz@compsoc.man.ac.uk>
+
+ * insetexternal.C:
+ * figinset.C: use new File Dialog
+
2001-03-06 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* insettext.C: changes becuase of ParagraphParameters.
#include <list>
#include <algorithm>
#include <vector>
+#include <utility>
#include <unistd.h>
#include <csignal>
#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"
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;
{
static string current_figure_path;
static int once = 0;
- LyXFileDlg fileDlg;
if (lyxerr.debugging()) {
lyxerr << "Filename: "
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);
#include FORMS_H_LOCATION
#include <cstdio>
+#include <utility>
#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"
#endif
using std::endl;
-
+using std::pair;
+using std::make_pair;
InsetExternal::InsetExternal()
: form_external(0)
static string current_path;
static int once = 0;
- LyXFileDlg fileDlg;
string p = inset->filename;
string buf = MakeAbsPath(holder->view->buffer()->fileName());
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());
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);
#include <fstream>
#include <algorithm>
+#include <utility>
#include <iostream>
#include FORMS_H_LOCATION
#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"
using std::ios;
using std::istream_iterator;
using std::pair;
+using std::make_pair;
using std::vector;
using std::sort;
using std::equal;
//
// 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);
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);
}
-// 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())
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);
///
///
void MenuInsertLabel(BufferView * bv, string const & arg);
///
-void LayoutsCB(int sel, void *, Combox *);
-///
void MenuLayoutCharacter();
///
void MenuLayoutSave(BufferView * bv);
#include <time.h>
#include <locale.h>
+#include <utility>
+#include <algorithm>
#include <cstdlib>
#include <cctype>
#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"
#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"
#include "lyxfind.h"
using std::pair;
+using std::make_pair;
using std::endl;
using std::find_if;
}
}
+ Assert(action != LFUN_SELECT_FILE_SYNC);
+
switch (action) {
// --- Misc -------------------------------------------
case LFUN_WORDFINDFORWARD :
MenuNew(true);
break;
- case LFUN_MENUOPEN:
- MenuOpen();
- break;
-
case LFUN_CLOSEBUFFER:
CloseBuffer();
break;
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:
break;
case LFUN_FILE_OPEN:
- owner->view()->buffer(bufferlist.loadLyXFile(argument));
+ Open(argument);
break;
case LFUN_LATEX_LOG:
break;
case LFUN_LAYOUT_PARAGRAPH:
-#ifdef USE_OLD_PARAGRAPH_LAYOUT
- MenuLayoutParagraph();
-#else
owner->getDialogs()->showLayoutParagraph();
-#endif
break;
case LFUN_LAYOUT_CHARACTER:
void LyXFunc::MenuNew(bool fromTemplate)
{
string initpath = lyxrc.document_path;
- LyXFileDlg fileDlg;
if (owner->view()->available()) {
string const trypath = owner->buffer()->filepath;
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;
// 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";
// 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;
}
}
-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;
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
if (filename.empty()) { // need user interaction
string initpath = lyxrc.document_path;
- LyXFileDlg fileDlg;
if (owner->view()->available()) {
string const trypath = owner->buffer()->filepath;
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())
void MenuNew(bool fromTemplate);
///
- void MenuOpen();
+ void Open(string const &);
///
void doImport(string const &);