]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormFiledialog.C
Yet more dialog tweaking from Rob.
[lyx.git] / src / frontends / xforms / FormFiledialog.C
index 4e6063fc971012f783596ea319b6a23a1b1f9d88..64ff1a5da278f3890829960aee90de8c4a9a46fa 100644 (file)
@@ -1,10 +1,12 @@
 /**
  * \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>
@@ -13,7 +15,6 @@
 #include <cstdlib>
 #include <pwd.h>
 #include <grp.h>
-//#include <cstring>
 #include <map>
 #include <algorithm>
 
@@ -188,7 +189,7 @@ void FileDialog::Private::Reread()
        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());
        }
@@ -204,13 +205,13 @@ void FileDialog::Private::Reread()
        // 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 += ' ';
@@ -220,16 +221,16 @@ void FileDialog::Private::Reread()
        // 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 == "..")
@@ -244,10 +245,10 @@ void FileDialog::Private::Reread()
                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);
@@ -265,21 +266,22 @@ void FileDialog::Private::Reread()
                        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
@@ -289,7 +291,7 @@ void FileDialog::Private::Reread()
                                //                              JV 199902
                                fileInfo.newFile(File);
                                if (fileInfo.isOK())
-                                       Buffer += fileInfo.typeIndicator();
+                                       buffer += fileInfo.typeIndicator();
                                else
                                        continue;
                        }
@@ -308,14 +310,15 @@ void FileDialog::Private::Reread()
                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
@@ -415,7 +418,7 @@ FileDialog::Private::Private(Dialogs & dia)
        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));
 }
 
 
@@ -433,28 +436,30 @@ void FileDialog::Private::redraw()
 
 
 // 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();
        }
 }
 
@@ -490,8 +495,7 @@ bool FileDialog::Private::RunDialog()
                        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_)
@@ -579,7 +583,7 @@ bool FileDialog::Private::HandleDoubleClick()
        // 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, '/')) {
@@ -708,7 +712,7 @@ string const FileDialog::Private::Select(string const & title,
        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;
@@ -716,7 +720,8 @@ string const FileDialog::Private::Select(string const & title,
                }
        }
 
-       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);