]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FileDialog_private.C
Lots and lots of little trivial bits.
[lyx.git] / src / frontends / qt2 / FileDialog_private.C
1 /**
2  * \file FileDialog_private.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include <qapplication.h>
18 #include <qtoolbutton.h>
19
20 #include "FileDialog_private.h"
21
22 #include "QtLyXView.h"
23 #include "debug.h"
24 #include "funcrequest.h"
25 #include "lyxfunc.h"
26 #include "support/lstrings.h"
27
28 namespace {
29         /// return the Qt form of the label
30         string const getLabel(string const & str) {
31                 string label;
32                 string sc(split(str, label, '|'));
33                 if (sc.length() < 2)
34                         return label;
35                 string::size_type pos = label.find(sc[1]);
36                 if (pos == string::npos)
37                         return label;
38                 label.insert(pos, "&");
39                 return label;
40         }
41 }
42
43 LyXFileDialog::LyXFileDialog(string const & p, string const & m, string const & t,
44                 FileDialog::Button const & b1, FileDialog::Button const & b2)
45         : QFileDialog(p.c_str(), m.c_str(), qApp->mainWidget(), t.c_str(), true),
46           b1_(0), b2_(0)
47 {
48         setCaption(t.c_str());
49
50         if (!b1.first.empty()) {
51                 b1_dir_ = b1.second;
52                 b1_ = new QToolButton(this);
53                 connect(b1_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
54                 b1_->setText(getLabel(b1.first).c_str());
55                 addToolButton(b1_, true);
56         }
57
58         if (!b2.first.empty()) {
59                 b2_dir_ = b2.second;
60                 b2_ = new QToolButton(this);
61                 connect(b2_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
62                 b2_->setText(getLabel(b2.first).c_str());
63                 addToolButton(b2_);
64         }
65 }
66
67
68 void LyXFileDialog::buttonClicked()
69 {
70         if (sender() == b1_)
71                 setDir(b1_dir_.c_str());
72         else if (sender() == b2_)
73                 setDir(b2_dir_.c_str());
74 }