-// -*- C++ -*-
/**
* \file ControlInclude.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
- * \author John Levon, moz@compsoc.man.ac.uk
- * \author Angus Leeming, a.leeming@.ac.uk
+ * \author John Levon
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include <utility>
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-#include "ViewBase.h"
-#include "ButtonControllerBase.h"
#include "ControlInclude.h"
+#include "helper_funcs.h"
+#include "Kernel.h"
+
#include "buffer.h"
-#include "Dialogs.h"
-#include "LyXView.h"
+#include "format.h"
+#include "funcrequest.h"
#include "gettext.h"
-
-#include "helper_funcs.h"
#include "lyxrc.h"
+#include "insets/insetinclude.h"
+
+#include "support/filefilterlist.h"
+#include "support/filetools.h"
+
+#include <utility>
+
using std::pair;
-using std::make_pair;
-using SigC::slot;
+using std::string;
+
+namespace lyx {
+
+using support::FileFilterList;
+using support::IsFileReadable;
+using support::MakeAbsPath;
+using support::OnlyPath;
+
+namespace frontend {
+
+ControlInclude::ControlInclude(Dialog & parent)
+ : Dialog::Controller(parent)
+{}
+
+
+bool ControlInclude::initialiseParams(string const & data)
+{
+ InsetIncludeMailer::string2params(data, params_);
+ return true;
+}
+
+
+void ControlInclude::clearParams()
+{
+ params_ = InsetCommandParams();
+}
+
-ControlInclude::ControlInclude(LyXView & lv, Dialogs & d)
- : ControlInset<InsetInclude, InsetInclude::Params>(lv, d)
+void ControlInclude::dispatchParams()
{
- d_.showInclude.connect(slot(this, &ControlInclude::showInset));
+ string const lfun = InsetIncludeMailer::params2string(params_);
+ kernel().dispatch(FuncRequest(getLfun(), lfun));
}
-void ControlInclude::applyParamsToInset()
+void ControlInclude::setParams(InsetCommandParams const & params)
{
- inset()->set(params());
- lv_.view()->updateInset(inset(), true);
+ params_ = params;
}
-string const ControlInclude::Browse(string const & in_name, Type in_type)
+string const ControlInclude::browse(string const & in_name, Type in_type) const
{
- string const title = N_("Select document to include");
+ string const title = _("Select document to include");
- string pattern;
-
// input TeX, verbatim, or LyX file ?
+ FileFilterList filters;
switch (in_type) {
+ case INCLUDE:
case INPUT:
- pattern = _("*.tex| LaTeX Documents (*.tex)");
+ filters = FileFilterList(_("LaTeX/LyX Documents (*.tex *.lyx)"));
break;
-
case VERBATIM:
- pattern = _("*| All files ");
- break;
-
- case INCLUDE:
- pattern = _("*.lyx| LyX Documents (*.lyx)");
break;
}
-
- pair<string, string> dir1(N_("Documents"), string(lyxrc.document_path));
- return browseFile(&lv_, in_name, title, pattern, dir1,
- make_pair(string(), string()));
+ pair<string, string> dir1(N_("Documents|#o#O"),
+ string(lyxrc.document_path));
+
+ string const docpath = OnlyPath(kernel().buffer().fileName());
+
+ return browseRelFile(in_name, docpath, title,
+ filters, false, dir1);
}
+
+
+void ControlInclude::load(string const & file)
+{
+ string const ext = support::GetExtension(file);
+ if (ext == "lyx")
+ kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
+ else
+ // tex file or other text file in verbatim mode
+ formats.edit(kernel().buffer(), file, "text");
+}
+
+
+bool ControlInclude::fileExists(string const & file)
+{
+ string const fileWithAbsPath
+ = MakeAbsPath(file,
+ OnlyPath(kernel().buffer().fileName()));
+
+ if (IsFileReadable(fileWithAbsPath))
+ return true;
+
+ return false;
+}
+
+} // namespace frontend
+} // namespace lyx