]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlGraphics.C
move more support functions into namespace lyx, small other changes
[lyx.git] / src / frontends / controllers / ControlGraphics.C
1 /* This file is part of
2  * ====================================================== 
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file ControlGraphics.C
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #include <config.h> 
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif 
19
20 #include "ControlGraphics.h"
21 #include "buffer.h"
22 #include "Dialogs.h"
23 #include "lyxfunc.h"
24 #include "LyXView.h"
25 #include "gettext.h"
26
27 #include "insets/insetgraphics.h"
28
29 #include "support/FileInfo.h"  // for FileInfo
30 #include "helper_funcs.h"      // for browseFile
31 #include "support/filetools.h" // for AddName
32
33 using std::pair;
34 using std::make_pair;
35
36 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
37         : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
38 {
39         d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
40 }
41
42
43 InsetGraphicsParams const ControlGraphics::getParams(string const &)
44 {
45         return InsetGraphicsParams();
46 }
47
48
49 InsetGraphicsParams const
50 ControlGraphics::getParams(InsetGraphics const & inset)
51 {
52         return inset.getParams();
53 }
54
55
56 void ControlGraphics::applyParamsToInset()
57 {
58         // Set the parameters in the inset, it also returns true if the new
59         // parameters are different from what was in the inset already.
60         bool changed = inset()->setParams(params());
61         // Tell LyX we've got a change, and mark the document dirty,
62         // if it changed.
63         lv_.view()->updateInset(inset(), changed);
64 }
65
66
67 void ControlGraphics::applyParamsNoInset()
68 {}
69
70
71 // We need these in the file browser.
72 extern string system_lyxdir;
73 extern string user_lyxdir;
74
75 string const ControlGraphics::Browse(string const & in_name)
76 {
77         string const title = N_("Graphics");
78         // FIXME: currently we need the second '|' to prevent mis-interpretation 
79         string const pattern = "*.(ps|png)|";
80
81         // Does user clipart directory exist?
82         string clipdir = AddName (user_lyxdir, "clipart");
83         FileInfo fileInfo(clipdir);
84         if (!(fileInfo.isOK() && fileInfo.isDir()))
85                 // No - bail out to system clipart directory
86                 clipdir = AddName (system_lyxdir, "clipart");
87         pair<string, string> dir1(N_("Clipart"), clipdir);
88         
89         // Show the file browser dialog
90         return browseFile(&lv_, in_name, title, pattern, dir1,
91                           make_pair(string(), string()));
92 }