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
38 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
39 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
41 d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
45 InsetGraphicsParams const ControlGraphics::getParams(string const &)
47 return InsetGraphicsParams();
51 InsetGraphicsParams const
52 ControlGraphics::getParams(InsetGraphics const & inset)
54 return inset.getParams();
58 void ControlGraphics::applyParamsToInset()
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,
65 lv_.view()->updateInset(inset(), changed);
69 void ControlGraphics::applyParamsNoInset()
73 // We need these in the file browser.
74 extern string system_lyxdir;
75 extern string user_lyxdir;
77 string const ControlGraphics::Browse(string const & in_name)
79 string const title = N_("Graphics");
80 // FIXME: currently we need the second '|' to prevent mis-interpretation
81 string const pattern = "*.(ps|png)|";
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);
91 // Show the file browser dialog
92 return browseFile(&lv_, in_name, title, pattern, dir1,
93 make_pair(string(), string()));