/**
* \file FormFiledialog.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
* \author unknown
- * \author John Levon, moz@compsoc.man.ac.uk
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
*/
#include <config.h>
#include <cstdlib>
#include <pwd.h>
#include <grp.h>
-//#include <cstring>
#include <map>
#include <algorithm>
DIR * dir = ::opendir(directory_.c_str());
if (!dir) {
Alert::err_alert(_("Warning! Couldn't open directory."),
- directory_);
+ directory_);
directory_ = lyx::getcwd();
dir = ::opendir(directory_.c_str());
}
// Splits complete directory name into directories and compute depth
depth_ = 0;
string line, Temp;
- char szMode[15];
+ string mode;
string File = directory_;
if (File != "/") {
File = split(File, Temp, '/');
}
while (!File.empty() || !Temp.empty()) {
- string dline = "@b"+line + Temp + '/';
+ string dline = "@b" + line + Temp + '/';
fl_add_browser_line(file_dlg_form_->List, dline.c_str());
File = split(File, Temp, '/');
line += ' ';
// Parses all entries of the given subdirectory
time_t curTime = time(0);
rewinddir(dir);
- while (dirent * pDirEntry = readdir(dir)) {
+ while (dirent * entry = readdir(dir)) {
bool isLink = false, isDir = false;
// If the pattern doesn't start with a dot, skip hidden files
if (!mask_.empty() && mask_[0] != '.' &&
- pDirEntry->d_name[0] == '.')
+ entry->d_name[0] == '.')
continue;
// Gets filename
- string fname = pDirEntry->d_name;
+ string fname = entry->d_name;
// Under all circumstances, "." and ".." are not wanted
if (fname == "." || fname == "..")
if (!fileInfo.isOK())
continue;
- fileInfo.modeString(szMode);
- unsigned int nlink = fileInfo.getNumberOfLinks();
- string user = lyxUserCache.find(fileInfo.getUid());
- string group = lyxGroupCache.find(fileInfo.getGid());
+ mode = fileInfo.modeString();
+ unsigned int const nlink = fileInfo.getNumberOfLinks();
+ string const user = lyxUserCache.find(fileInfo.getUid());
+ string const group = lyxGroupCache.find(fileInfo.getGid());
time_t modtime = fileInfo.getModificationTime();
string Time = ctime(&modtime);
Time.erase(16, string::npos);
}
- string Buffer = string(szMode) + ' ' +
+ string buffer = mode + ' ' +
tostr(nlink) + ' ' +
user + ' ' +
group + ' ' +
Time.substr(4, string::npos) + ' ';
- Buffer += pDirEntry->d_name;
- Buffer += fileInfo.typeIndicator();
+ buffer += entry->d_name;
+ buffer += fileInfo.typeIndicator();
- if ((isLink = fileInfo.isLink())) {
+ isLink = fileInfo.isLink();
+ if (isLink) {
string Link;
if (LyXReadLink(File, Link)) {
- Buffer += " -> ";
- Buffer += Link;
+ buffer += " -> ";
+ buffer += Link;
// This gives the FileType of the file that
// is really pointed too after resolving all
// JV 199902
fileInfo.newFile(File);
if (fileInfo.isOK())
- Buffer += fileInfo.typeIndicator();
+ buffer += fileInfo.typeIndicator();
else
continue;
}
DirEntry tmp;
// Note ls_entry_ is an string!
- tmp.ls_entry_ = Buffer;
+ tmp.ls_entry_ = buffer;
// creates used name
string temp = fname;
- if (isDir) temp += '/';
+ if (isDir)
+ temp += '/';
tmp.name_ = temp;
// creates displayed name
- temp = pDirEntry->d_name;
+ temp = entry->d_name;
if (isLink)
temp += '@';
else
fl_hide_object(file_dlg_form_->User1);
fl_hide_object(file_dlg_form_->User2);
- r_ = dia.redrawGUI.connect(boost::bind(&FileDialog::Private::redraw, this));
+ r_ = dia.redrawGUI().connect(boost::bind(&FileDialog::Private::redraw, this));
}
// SetButton: sets file selector user button action
-void FileDialog::Private::SetButton(int iIndex, string const & name_,
- string const & pszPath)
+void FileDialog::Private::SetButton(int index, string const & name,
+ string const & path)
{
FL_OBJECT * ob;
- string * pTemp;
+ string * tmp;
- if (iIndex == 0) {
+ if (index == 0) {
ob = file_dlg_form_->User1;
- pTemp = &user_path1_;
- } else if (iIndex == 1) {
+ tmp = &user_path1_;
+ } else if (index == 1) {
ob = file_dlg_form_->User2;
- pTemp = &user_path2_;
- } else return;
+ tmp = &user_path2_;
+ } else {
+ return;
+ }
- if (!name_.empty()) {
- fl_set_object_label(ob, idex(name_.c_str()));
- fl_set_button_shortcut(ob, scex(name_.c_str()), 1);
+ if (!name.empty()) {
+ fl_set_object_label(ob, idex(name.c_str()));
+ fl_set_button_shortcut(ob, scex(name.c_str()), 1);
fl_show_object(ob);
- *pTemp = pszPath;
+ *tmp = path;
} else {
fl_hide_object(ob);
- pTemp->erase();
+ tmp->erase();
}
}
if (HandleOK())
return x_sync_kludge(true);
- } else if (ob == file_dlg_form_->Cancel
- || force_cancel_)
+ } else if (ob == file_dlg_form_->Cancel || force_cancel_)
return x_sync_kludge(false);
else if (force_ok_)
// set info line
bool isDir = true;
int const select_ = fl_get_browser(file_dlg_form_->List);
- if (select_ > depth_) {
+ if (select_ > depth_) {
tmp = dir_entries_[select_ - depth_ - 1].name_;
SetInfoLine(dir_entries_[select_ - depth_ - 1].ls_entry_);
if (!suffixIs(tmp, '/')) {
if (!filename.empty()) {
for (int i = 0; i < fl_get_browser_maxline(file_dlg_form_->List); ++i) {
string s = fl_get_browser_line(file_dlg_form_->List, i + 1);
- s = strip(frontStrip(s));
+ s = trim(s);
if (s == filename) {
sel = i + 1;
break;
}
}
- if (sel != 0) fl_select_browser_line(file_dlg_form_->List, sel);
+ if (sel != 0)
+ fl_select_browser_line(file_dlg_form_->List, sel);
int const top = max(sel - 5, 1);
fl_set_browser_topline(file_dlg_form_->List, top);