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