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"
23 #include "ControlInset.tmpl"
29 #include "insets/insetgraphics.h"
30 #include "insets/insetgraphicsParams.h" // need operator!=()
32 #include "support/FileInfo.h" // for FileInfo
33 #include "helper_funcs.h" // for browseFile
34 #include "support/filetools.h" // for AddName
35 #include "BufferView.h"
40 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
41 : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
43 d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset));
47 InsetGraphicsParams const ControlGraphics::getParams(string const &)
49 return InsetGraphicsParams();
53 InsetGraphicsParams const
54 ControlGraphics::getParams(InsetGraphics const & inset)
56 return inset.getParams();
60 void ControlGraphics::applyParamsToInset()
62 // Set the parameters in the inset, it also returns true if the new
63 // parameters are different from what was in the inset already.
64 bool changed = inset()->setParams(params());
65 // Tell LyX we've got a change, and mark the document dirty,
67 lv_.view()->updateInset(inset(), changed);
71 void ControlGraphics::applyParamsNoInset()
75 // We need these in the file browser.
76 extern string system_lyxdir;
77 extern string user_lyxdir;
79 string const ControlGraphics::Browse(string const & in_name)
81 string const title = N_("Graphics");
82 // FIXME: currently we need the second '|' to prevent mis-interpretation
83 string const pattern = "*.(ps|eps|png|jpeg|jpg|gif)|";
85 // Does user clipart directory exist?
86 string clipdir = AddName (user_lyxdir, "clipart");
87 FileInfo fileInfo(clipdir);
88 if (!(fileInfo.isOK() && fileInfo.isDir()))
89 // No - bail out to system clipart directory
90 clipdir = AddName (system_lyxdir, "clipart");
91 pair<string, string> dir1(N_("Clipart|#C#c"), clipdir);
93 // Show the file browser dialog
94 return browseFile(&lv_, in_name, title, pattern, dir1);