mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
(J��rgen Spitzm��ller): implement a BrowseDir capablility in the File Dialog.
Fixes bug 824. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5955 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
35cdea94bd
commit
fa6f44b0c7
@ -1,3 +1,7 @@
|
||||
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
|
||||
|
@ -77,6 +77,13 @@ public:
|
||||
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
|
||||
|
@ -1,3 +1,9 @@
|
||||
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
|
||||
|
@ -110,6 +110,12 @@ string const ControlPrefs::browse(string const & file, string const & title)
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
@ -47,6 +47,9 @@ public:
|
||||
|
||||
/// 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();
|
||||
|
@ -89,6 +89,40 @@ string const browseRelFile(LyXView * lv, string const & filename,
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
@ -58,6 +58,20 @@ browseRelFile(LyXView * lv, string const & filename,
|
||||
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();
|
||||
|
||||
|
@ -1,3 +1,9 @@
|
||||
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...
|
||||
@ -53,6 +59,7 @@
|
||||
|
||||
* QtView.h:
|
||||
* QtView.C:
|
||||
|
||||
2003-01-04 Juergen Spitzmueller <j.spitzmueller@gmx.de>
|
||||
|
||||
* QURL.C: isValid(): fix validation.
|
||||
|
@ -88,7 +88,7 @@ FileDialog::Result const FileDialog::open(string const & path,
|
||||
{
|
||||
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
|
||||
@ -108,3 +108,29 @@ FileDialog::Result const FileDialog::open(string const & 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;
|
||||
}
|
@ -545,7 +545,7 @@ void QPrefsDialog::select_dict()
|
||||
|
||||
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));
|
||||
}
|
||||
@ -553,7 +553,7 @@ void QPrefsDialog::select_templatedir()
|
||||
|
||||
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));
|
||||
}
|
||||
@ -561,7 +561,7 @@ void QPrefsDialog::select_tempdir()
|
||||
|
||||
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));
|
||||
}
|
||||
@ -569,7 +569,7 @@ void QPrefsDialog::select_backupdir()
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -54,6 +54,26 @@ FileDialog::Result const FileDialog::save(string const & path, string const & ma
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
@ -29,6 +29,7 @@ using std::sort;
|
||||
#include "gettext.h"
|
||||
#include "frontends/Dialogs.h"
|
||||
#include "forms_gettext.h"
|
||||
#include "xforms_helpers.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
@ -736,6 +737,7 @@ string const FileDialog::Private::Select(string const & title,
|
||||
|
||||
// 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);
|
||||
@ -767,3 +769,65 @@ string const FileDialog::Private::Select(string const & title,
|
||||
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_;
|
||||
}
|
||||
|
@ -69,6 +69,10 @@ public:
|
||||
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
|
||||
|
@ -2186,29 +2186,35 @@ bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
|
||||
}
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user