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