+2003-01-11 Juergen Spitzmueller <j.spitzmueller@gmx.de>
+
+ * FileDialog.h: implement opendir (browse directory) [bug 824]
+
2003-01-12 Lars Gullik Bjønnes <larsbj@gullik.net>
* Makefile.am (LIBS): delete
Result const open(string const & path = string(),
string const & mask = string(),
string const & suggested = string());
+
+ /**
+ * Choose a directory, starting in directory \param
+ * path.
+ */
+ Result const opendir(string const & path = string(),
+ string const & suggested = string());
/**
* Choose a file for saving, starting in directory \param
+2003-01-11 Juergen Spitzmueller <j.spitzmueller@gmx.de>
+
+ * helper_funcs.[Ch]: implement browseDir (browse directory) [bug 824]
+
+ * ControlPrefs.[Ch]: implement browsedir for the use of use browseDir.
+
2002-12-02 Lars Gullik Bjønnes <larsbj@gullik.net>
* ControlDocument.C: use BoostFormat.h instead of boost/format.hpp
}
+string const ControlPrefs::browsedir(string const & path, string const & title)
+{
+ return browseDir(&lv_, path, title);
+}
+
+
void ControlPrefs::redrawGUI()
{
// we must be sure to get the new values first
/// general browse
string const browse(string const & file, string const & title);
+
+ /// browse directory
+ string const browsedir(string const & path, string const & title);
/// redraw widgets (for xforms color change)
void redrawGUI();
}
+string const browseDir(LyXView * lv, string const & pathname,
+ string const & title,
+ pair<string,string> const & dir1,
+ pair<string,string> const & dir2)
+{
+ string lastPath(".");
+ if (!pathname.empty())
+ lastPath = OnlyPath(pathname);
+
+ FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
+
+ FileDialog::Result result;
+
+ while (true) {
+ result = fileDlg.opendir(lastPath,
+ OnlyFilename(pathname));
+
+ if (result.second.empty())
+ return result.second;
+
+ lastPath = OnlyPath(result.second);
+
+ if (result.second.find_first_of("#~$% ") == string::npos)
+ break;
+
+ Alert::alert(_("directory name can't contain any "
+ "of these characters:"),
+ _("space, '#', '~', '$' or '%'."));
+ }
+
+ return result.second;
+}
+
+
// sorry this is just a temporary hack we should include vspace.h! (Jug)
extern const char * stringFromUnit(int);
std::make_pair(string(), string()));
+/** Launch a file dialog and return the chosen directory.
+ pathname: a suggested pathname.
+ title: the title of the dialog.
+ dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
+*/
+string const
+browseDir(LyXView * lv, string const & pathname,
+ string const & title,
+ std::pair<string,string> const & dir1 =
+ std::make_pair(string(), string()),
+ std::pair<string,string> const & dir2 =
+ std::make_pair(string(), string()));
+
+
/// Returns a vector of units that can be used to create a valid LaTeX length.
std::vector<string> const getLatexUnits();
+2003-01-11 Juergen Spitzmueller <j.spitzmueller@gmx.de>
+
+ * FileDialog.C: implement opendir [bug 824], fix mask.
+
+ * QPrefsDialog.C: use browsedir for paths [bug 824]
+
2003-01-13 Lars Gullik Bjønnes <larsbj@gullik.net>
* qgridview.cpp: rename to...
* QtView.h:
* QtView.C:
+
2003-01-04 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* QURL.C: isValid(): fix validation.
{
string filter(mask);
if (mask.empty())
- filter = _("*|All files");
+ filter = _("All files (*)");
LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
lyxerr[Debug::GUI] << "Select with path \"" << path
dlg.hide();
return result;
}
+
+
+FileDialog::Result const FileDialog::opendir(string const & path,
+ string const & suggested)
+{
+ string filter = _("Directories");
+
+ LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
+ lyxerr[Debug::GUI] << "Select with path \"" << path
+ << "\", suggested \"" << suggested << endl;
+
+ dlg.setMode(QFileDialog::DirectoryOnly);
+
+ if (!suggested.empty())
+ dlg.setSelection(toqstr(suggested));
+
+ FileDialog::Result result;
+ lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
+ result.first = FileDialog::Chosen;
+ int res = dlg.exec();
+ lyxerr[Debug::GUI] << "result " << res << endl;
+ if (res == QDialog::Accepted)
+ result.second = string(dlg.selectedFile().data());
+ dlg.hide();
+ return result;
+}
\ No newline at end of file
void QPrefsDialog::select_templatedir()
{
- string file(form_->controller().browse(fromqstr(pathsModule->templateDirED->text()), _("Select a document templates directory")));
+ string file(form_->controller().browsedir(fromqstr(pathsModule->templateDirED->text()), _("Select a document templates directory")));
if (!file.empty())
pathsModule->templateDirED->setText(toqstr(file));
}
void QPrefsDialog::select_tempdir()
{
- string file(form_->controller().browse(fromqstr(pathsModule->tempDirED->text()), _("Select a temporary directory")));
+ string file(form_->controller().browsedir(fromqstr(pathsModule->tempDirED->text()), _("Select a temporary directory")));
if (!file.empty())
pathsModule->tempDirED->setText(toqstr(file));
}
void QPrefsDialog::select_backupdir()
{
- string file(form_->controller().browse(fromqstr(pathsModule->backupDirED->text()), _("Select a backups directory")));
+ string file(form_->controller().browsedir(fromqstr(pathsModule->backupDirED->text()), _("Select a backups directory")));
if (!file.empty())
pathsModule->backupDirED->setText(toqstr(file));
}
void QPrefsDialog::select_workingdir()
{
- string file(form_->controller().browse(fromqstr(pathsModule->workingDirED->text()), _("Select a document directory")));
+ string file(form_->controller().browsedir(fromqstr(pathsModule->workingDirED->text()), _("Select a document directory")));
if (!file.empty())
pathsModule->workingDirED->setText(toqstr(file));
}
}
+FileDialog::Result const FileDialog::opendir(string const & path, string const & suggested)
+{
+ lyxerr[Debug::GUI] << "filedialog open with path \"" << path << "\", suggested \""
+ << suggested << '"' << endl;
+
+ // no support for asynchronous selection yet
+
+ lv_->prohibitInput();
+
+ FileDialog::Result result;
+
+ result.first = FileDialog::Chosen;
+ result.second = private_->SelectDir(title_, path, suggested);
+
+ lv_->allowInput();
+
+ return result;
+}
+
+
FileDialog::Result const FileDialog::open(string const & path, string const & mask, string const & suggested)
{
string filter = mask;
#include "gettext.h"
#include "frontends/Dialogs.h"
#include "forms_gettext.h"
+#include "xforms_helpers.h"
#include <boost/bind.hpp>
// runs dialog
SetInfoLine(string());
+ setEnabled(file_dlg_form_->Filename, true);
fl_set_input(file_dlg_form_->Filename, suggested.c_str());
fl_set_button(file_dlg_form_->Cancel, 0);
fl_set_button(file_dlg_form_->Ready, 0);
file_name_ = AddName(fl_get_input(file_dlg_form_->DirBox), file_name_);
return file_name_;
}
+
+
+// SelectDir: launches dialog and returns selected directory
+string const FileDialog::Private::SelectDir(string const & title,
+ string const & path,
+ string const & suggested)
+{
+ SetMask("*/");
+ // handles new path
+ bool isOk = true;
+ if (!path.empty()) {
+ // handle case where path does not end with "/"
+ // remerge path+suggested and check if it is a valid path
+ if (!suggested.empty()) {
+ string tmp = suggested;
+ if (!suffixIs(tmp, '/'))
+ tmp += '/';
+ string full_path = path;
+ full_path += tmp;
+ // check if this is really a directory
+ DIR * dir = ::opendir(full_path.c_str());
+ if (dir)
+ SetDirectory(full_path);
+ else
+ SetDirectory(path);
+ } else
+ SetDirectory(path);
+ isOk = false;
+ }
+ if (!isOk)
+ Reread();
+
+ // checks whether dialog can be started
+ if (current_dlg_)
+ return string();
+ current_dlg_ = this;
+
+ // runs dialog
+ SetInfoLine(string());
+ fl_set_input(file_dlg_form_->Filename, "");
+ setEnabled(file_dlg_form_->Filename, false);
+ fl_set_button(file_dlg_form_->Cancel, 0);
+ fl_set_button(file_dlg_form_->Ready, 0);
+ fl_set_focus_object(file_dlg_form_->form, file_dlg_form_->DirBox);
+ fl_deactivate_all_forms();
+ fl_show_form(file_dlg_form_->form,
+ FL_PLACE_MOUSE | FL_FREE_SIZE, 0,
+ title.c_str());
+
+ isOk = RunDialog();
+
+ fl_hide_form(file_dlg_form_->form);
+ fl_activate_all_forms();
+ current_dlg_ = 0;
+
+ // Returns directory or string() if no valid selection was made
+ if (!isOk)
+ return string();
+
+ file_name_ = fl_get_input(file_dlg_form_->DirBox);
+ return file_name_;
+}
string const & pszPath = string(),
string const & pszMask = string(),
string const & pszSuggested = string());
+ /// launches dialog and returns selected directory
+ string const SelectDir(string const & pszTitle = string(),
+ string const & pszPath = string(),
+ string const & pszSuggested = string());
/// XForms objects callback (static)
static void FileDlgCB(FL_OBJECT *, long);
/// Callback for double click in list
}
if (ob == dialog_->button_default_path_browse) {
- string f = parent_.controller().browse(
+ string f = parent_.controller().browsedir(
fl_get_input(dialog_->input_default_path), _("Default path"));
- fl_set_input(dialog_->input_default_path, f.c_str());
+ if (!f.empty())
+ fl_set_input(dialog_->input_default_path, f.c_str());
} else if (ob == dialog_->button_template_path_browse) {
- string f = parent_.controller().browse(
+ string f = parent_.controller().browsedir(
fl_get_input(dialog_->input_template_path), _("Template path"));
- fl_set_input(dialog_->input_template_path, f.c_str());
+ if (!f.empty())
+ fl_set_input(dialog_->input_template_path, f.c_str());
} else if (ob == dialog_->button_temp_dir_browse) {
- string f = parent_.controller().browse(
+ string f = parent_.controller().browsedir(
fl_get_input(dialog_->input_temp_dir), _("Temporary dir"));
- fl_set_input(dialog_->input_temp_dir, f.c_str());
+ if (!f.empty())
+ fl_set_input(dialog_->input_temp_dir, f.c_str());
} else if (ob == dialog_->button_lastfiles_browse) {
string f = parent_.controller().browse(
fl_get_input(dialog_->input_lastfiles), _("Last files"));
- fl_set_input(dialog_->input_lastfiles, f.c_str());
+ if (!f.empty())
+ fl_set_input(dialog_->input_lastfiles, f.c_str());
} else if (ob == dialog_->button_backup_path_browse) {
- string f = parent_.controller().browse(
+ string f = parent_.controller().browsedir(
fl_get_input(dialog_->input_backup_path), _("Backup path"));
- fl_set_input(dialog_->input_backup_path, f.c_str());
+ if (!f.empty())
+ fl_set_input(dialog_->input_backup_path, f.c_str());
} else if (ob == dialog_->button_serverpipe_browse) {
string f = parent_.controller().browse(
fl_get_input(dialog_->input_serverpipe), _("LyX server pipes"));
- fl_set_input(dialog_->input_serverpipe, f.c_str());
+ if (!f.empty())
+ fl_set_input(dialog_->input_serverpipe, f.c_str());
}
return activate;