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
20 #include "ControlGraphics.h"
26 #include "insets/insetgraphics.h"
28 #include "support/FileInfo.h" // for FileInfo
29 #include "helper_funcs.h" // for browseFile
30 #include "support/filetools.h" // for AddName
35 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
36 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
38 d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
42 InsetGraphicsParams const ControlGraphics::getParams(string const &)
44 return InsetGraphicsParams();
48 InsetGraphicsParams const
49 ControlGraphics::getParams(InsetGraphics const & inset)
51 return inset.getParams();
55 void ControlGraphics::applyParamsToInset()
57 // Set the parameters in the inset, it also returns true if the new
58 // parameters are different from what was in the inset already.
59 bool changed = inset()->setParams(params());
60 // Tell LyX we've got a change, and mark the document dirty,
62 lv_.view()->updateInset(inset(), changed);
66 void ControlGraphics::applyParamsNoInset()
70 // We need these in the file browser.
71 extern string system_lyxdir;
72 extern string user_lyxdir;
74 string const ControlGraphics::Browse(string const & in_name)
76 string const title = N_("Graphics");
77 // FIXME: currently we need the second '|' to prevent mis-interpretation
78 string const pattern = "*.(ps|png)|";
80 // Does user clipart directory exist?
81 string clipdir = AddName (user_lyxdir, "clipart");
82 FileInfo fileInfo(clipdir);
83 if (!(fileInfo.isOK() && fileInfo.isDir()))
84 // No - bail out to system clipart directory
85 clipdir = AddName (system_lyxdir, "clipart");
86 pair<string, string> dir1(N_("Clipart"), clipdir);
88 // Show the file browser dialog
89 return browseFile(&lv_, in_name, title, pattern, dir1,
90 make_pair(string(), string()));