1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file ControlGraphics.C
11 * \author Angus Leeming <a.leeming@ic.ac.uk>
17 #pragma implementation
21 #include "ButtonControllerBase.h"
22 #include "ControlGraphics.h"
28 #include "insets/insetgraphics.h"
29 #include "insets/insetgraphicsParams.h" // need operator!=()
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"
39 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
40 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
42 d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
46 InsetGraphicsParams const ControlGraphics::getParams(string const &)
48 return InsetGraphicsParams();
52 InsetGraphicsParams const
53 ControlGraphics::getParams(InsetGraphics const & inset)
55 return inset.getParams();
59 void ControlGraphics::applyParamsToInset()
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,
66 lv_.view()->updateInset(inset(), changed);
70 void ControlGraphics::applyParamsNoInset()
74 // We need these in the file browser.
75 extern string system_lyxdir;
76 extern string user_lyxdir;
78 string const ControlGraphics::Browse(string const & in_name)
80 string const title = N_("Graphics");
81 // FIXME: currently we need the second '|' to prevent mis-interpretation
82 string const pattern = "*.(ps|png)|";
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"), clipdir);
92 // Show the file browser dialog
93 return browseFile(&lv_, in_name, title, pattern, dir1,
94 make_pair(string(), string()));