]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlGraphics.C
167d2ad14083f4bc8cb840908c0efcbe4a5becd9
[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 "ViewBase.h"
21 #include "ButtonControllerBase.h"
22 #include "ControlGraphics.h"
23 #include "buffer.h"
24 #include "Dialogs.h"
25 #include "LyXView.h"
26 #include "gettext.h"
27
28 #include "insets/insetgraphics.h"
29 #include "insets/insetgraphicsParams.h" // need operator!=()
30
31 #include "support/FileInfo.h"  // for FileInfo
32 #include "helper_funcs.h"      // for browseFile
33 #include "support/filetools.h" // for AddName
34
35 using std::pair;
36 using std::make_pair;
37
38 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
39         : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
40 {
41         d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
42 }
43
44
45 InsetGraphicsParams const ControlGraphics::getParams(string const &)
46 {
47         return InsetGraphicsParams();
48 }
49
50
51 InsetGraphicsParams const
52 ControlGraphics::getParams(InsetGraphics const & inset)
53 {
54         return inset.getParams();
55 }
56
57
58 void ControlGraphics::applyParamsToInset()
59 {
60         // Set the parameters in the inset, it also returns true if the new
61         // parameters are different from what was in the inset already.
62         bool changed = inset()->setParams(params());
63         // Tell LyX we've got a change, and mark the document dirty,
64         // if it changed.
65         lv_.view()->updateInset(inset(), changed);
66 }
67
68
69 void ControlGraphics::applyParamsNoInset()
70 {}
71
72
73 // We need these in the file browser.
74 extern string system_lyxdir;
75 extern string user_lyxdir;
76
77 string const ControlGraphics::Browse(string const & in_name)
78 {
79         string const title = N_("Graphics");
80         // FIXME: currently we need the second '|' to prevent mis-interpretation 
81         string const pattern = "*.(ps|png)|";
82
83         // Does user clipart directory exist?
84         string clipdir = AddName (user_lyxdir, "clipart");
85         FileInfo fileInfo(clipdir);
86         if (!(fileInfo.isOK() && fileInfo.isDir()))
87                 // No - bail out to system clipart directory
88                 clipdir = AddName (system_lyxdir, "clipart");
89         pair<string, string> dir1(N_("Clipart"), clipdir);
90         
91         // Show the file browser dialog
92         return browseFile(&lv_, in_name, title, pattern, dir1,
93                           make_pair(string(), string()));
94 }