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