From f439fef46dd71f5bda051038bc1d2466b7d48396 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 27 Apr 2004 12:48:45 +0000 Subject: [PATCH] Search the src tree for glade files, so preventing an unnecessary crash in the gtk frontend. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8699 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 17 ++++++++++++ src/frontends/gtk/GAboutlyx.C | 5 ++-- src/frontends/gtk/GMathDelim.C | 7 ++--- src/frontends/gtk/GMathPanel.C | 6 ++--- src/frontends/gtk/GPrint.C | 5 ++-- src/frontends/gtk/GTableCreate.C | 5 ++-- src/frontends/gtk/GText.C | 5 ++-- src/frontends/gtk/GUrl.C | 5 ++-- src/frontends/gtk/Makefile.am | 2 ++ src/frontends/gtk/ghelpers.C | 46 ++++++++++++++++++++++++++++++++ src/frontends/gtk/ghelpers.h | 22 +++++++++++++++ src/support/ChangeLog | 5 ++++ src/support/path_defines.C.in | 18 ++++++------- src/support/path_defines.h | 5 ++++ 14 files changed, 124 insertions(+), 29 deletions(-) create mode 100644 src/frontends/gtk/ghelpers.C create mode 100644 src/frontends/gtk/ghelpers.h diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 1dc055a67c..10df8f91dd 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,20 @@ +2004-04-27 Angus Leeming + + * ghelpers.[Ch]: new files. + (findGladeFile): search the top_srcdir() as welll as LibFileSearch + when looking for glade files. + + * Makefile.am: add new files. + + * GAboutlyx.C (doBuild): + * GMathDelim.C (doBuild): + * GMathPanel.C (doBuild): + * GPrint.C (doBuild): + * GTableCreate.C (doBuild): + * GText.C (doBuild): + * GUrl.C (doBuild): use findGladeFile in preference to LibFileSearch. + Prevents crash when using a not-installed lyx executable. + 2004-04-20 Angus Leeming * Makefile.am (SUBDIRS): add gimages. diff --git a/src/frontends/gtk/GAboutlyx.C b/src/frontends/gtk/GAboutlyx.C index 38a39e9e02..7ebad4eada 100644 --- a/src/frontends/gtk/GAboutlyx.C +++ b/src/frontends/gtk/GAboutlyx.C @@ -16,7 +16,7 @@ #include "ControlAboutlyx.h" #include "GAboutlyx.h" -#include "support/filetools.h" +#include "ghelpers.h" #include "version.h" using std::ostringstream; @@ -145,8 +145,7 @@ GAboutlyx::GAboutlyx(Dialog & parent) void GAboutlyx::doBuild() { - string const gladeName = - lyx::support::LibFileSearch("glade", "aboutlyx", "glade"); + string const gladeName = findGladeFile("aboutlyx"); xml_ = Gnome::Glade::Xml::create(gladeName); Gtk::Label * version; Gtk::Label * credits; diff --git a/src/frontends/gtk/GMathDelim.C b/src/frontends/gtk/GMathDelim.C index 0685bb0730..6ddd519207 100644 --- a/src/frontends/gtk/GMathDelim.C +++ b/src/frontends/gtk/GMathDelim.C @@ -15,8 +15,10 @@ #include "ControlMath.h" #include "GMathDelim.h" -#include "support/filetools.h" +#include "ghelpers.h" + #include "support/lstrings.h" + #include "delim.xbm" #include "delim0.xpm" @@ -88,8 +90,7 @@ GMathDelim::GMathDelim(Dialog & parent) : void GMathDelim::doBuild() { - string const gladeName = - lyx::support::LibFileSearch("glade", "mathDelim", "glade"); + string const gladeName = findGladeFile("mathDelim"); xml_ = Gnome::Glade::Xml::create(gladeName); Gtk::Button * ok; Gtk::Button * apply; diff --git a/src/frontends/gtk/GMathPanel.C b/src/frontends/gtk/GMathPanel.C index a1c450b459..eb16e49d08 100644 --- a/src/frontends/gtk/GMathPanel.C +++ b/src/frontends/gtk/GMathPanel.C @@ -15,7 +15,8 @@ #include "ControlMath.h" #include "GMathPanel.h" -#include "support/filetools.h" +#include "ghelpers.h" + #include "support/lstrings.h" #include "deco.xpm" @@ -98,8 +99,7 @@ GMathPanel::GMathPanel(Dialog & parent) void GMathPanel::doBuild() { - string const gladeName = - lyx::support::LibFileSearch("glade", "mathPanel", "glade"); + string const gladeName = findGladeFile("mathPanel"); xml_ = Gnome::Glade::Xml::create(gladeName); Gtk::Button * close; Gtk::VBox * vbox; diff --git a/src/frontends/gtk/GPrint.C b/src/frontends/gtk/GPrint.C index 4cd4f7b9e3..d43be55f73 100644 --- a/src/frontends/gtk/GPrint.C +++ b/src/frontends/gtk/GPrint.C @@ -14,7 +14,8 @@ #include "GPrint.h" #include "ControlPrint.h" -#include "support/filetools.h" +#include "ghelpers.h" + #include "PrinterParams.h" #include "support/lstrings.h" @@ -122,7 +123,7 @@ void GPrint::onFromToEdit() void GPrint::doBuild() { - string const gladeName = LibFileSearch("glade", "print", "glade"); + string const gladeName = findGladeFile("print"); xml_ = Gnome::Glade::Xml::create(gladeName); xml_->get_widget("Printer", printer_); xml_->get_widget("File", file_); diff --git a/src/frontends/gtk/GTableCreate.C b/src/frontends/gtk/GTableCreate.C index c69d695ea1..98ecf8a1cc 100644 --- a/src/frontends/gtk/GTableCreate.C +++ b/src/frontends/gtk/GTableCreate.C @@ -15,7 +15,7 @@ #include "ControlTabularCreate.h" #include "GTableCreate.h" -#include "support/filetools.h" +#include "ghelpers.h" #include "support/lstrings.h" using std::string; @@ -27,8 +27,7 @@ GTableCreate::GTableCreate(Dialog & parent) void GTableCreate::doBuild() { - string const gladeName = - lyx::support::LibFileSearch("glade", "tableCreate", "glade"); + string const gladeName = findGladeFile("tableCreate"); xml_ = Gnome::Glade::Xml::create(gladeName); Gtk::Button * ok; Gtk::Button * apply; diff --git a/src/frontends/gtk/GText.C b/src/frontends/gtk/GText.C index 8944ec227f..6ffb00ba74 100644 --- a/src/frontends/gtk/GText.C +++ b/src/frontends/gtk/GText.C @@ -13,9 +13,9 @@ #include #include "support/lstrings.h" -#include "support/filetools.h" #include "ControlCommand.h" #include "GText.h" +#include "ghelpers.h" #include "IdSc.h" using std::string; @@ -42,8 +42,7 @@ void GText::update() void GText::doBuild() { - string const gladeName = - lyx::support::LibFileSearch("glade", "text", "glade"); + string const gladeName = findGladeFile("text"); xml_ = Gnome::Glade::Xml::create(gladeName); Gtk::Label * label; Gtk::Button * restore; diff --git a/src/frontends/gtk/GUrl.C b/src/frontends/gtk/GUrl.C index f9033075b1..1822b6e158 100644 --- a/src/frontends/gtk/GUrl.C +++ b/src/frontends/gtk/GUrl.C @@ -15,7 +15,7 @@ #include "ControlCommand.h" #include "GUrl.h" -#include "support/filetools.h" +#include "ghelpers.h" #include "support/lstrings.h" using std::string; @@ -28,8 +28,7 @@ GUrl::GUrl(Dialog & parent) void GUrl::doBuild() { - string const gladeName = - lyx::support::LibFileSearch("glade", "url", "glade"); + string const gladeName = findGladeFile("url"); xml_ = Gnome::Glade::Xml::create(gladeName); Gtk::Button * restore; Gtk::Button * ok; diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 63fcc5441d..9d585327e7 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -15,6 +15,8 @@ libgtk_la_LIBADD = xforms.lo @GTK_FRONTEND_LIBS@ @XFORMS_LIBS@ # Alphabetical order please. It makes it easier to figure out what's missing. libgtk_la_SOURCES = \ + ghelpers.C \ + ghelpers.h \ lyx_gui.C \ GtkmmX.h \ xftFontLoader.C \ diff --git a/src/frontends/gtk/ghelpers.C b/src/frontends/gtk/ghelpers.C new file mode 100644 index 0000000000..e2008f6cd1 --- /dev/null +++ b/src/frontends/gtk/ghelpers.C @@ -0,0 +1,46 @@ +/** + * \file ghelpers.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "ghelpers.h" + +#include "debug.h" + +#include "support/filetools.h" +#include "support/path_defines.h" + +using std::string; + +string const findGladeFile(string const & name) +{ + // First, search in the installation directories. + + string filename = + lyx::support::LibFileSearch("glade", name, "glade"); + + if (!filename.empty()) + return filename; + + // Second, search in the src tree. + string const dir = + lyx::support::AddPath(lyx::support::top_srcdir(), + "src/frontends/gtk/glade"); + + filename = lyx::support::ChangeExtension(name, ".glade"); + filename = lyx::support::AddName(dir, filename); + + if (!lyx::support::IsFileReadable(filename)) { + lyxerr << "Unable to find glade file \"" << name + << "\". libglade is going to crash..." << std::endl; + } + + return filename; +} diff --git a/src/frontends/gtk/ghelpers.h b/src/frontends/gtk/ghelpers.h new file mode 100644 index 0000000000..873e269f67 --- /dev/null +++ b/src/frontends/gtk/ghelpers.h @@ -0,0 +1,22 @@ +// -*- C++ -*- +/** + * \file ghelpers.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GHELPERS_H +#define GHELPERS_H + +#include + +/** name is the name of the glade file, without path or extension. + * Eg, "aboutlyx", "tableCreate". + */ +std::string const findGladeFile(std::string const & name); + +#endif // NOT GHELPERS_H diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 01dafe8de7..be363b7e23 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2004-04-27 Angus Leeming + + * path_defines.{h,C.in}: expose top_srcdir, renamed from + lyx_top_srcdir. + 2004-04-05 Angus Leeming * filetools.C: diff --git a/src/support/path_defines.C.in b/src/support/path_defines.C.in index 7cc73345ac..ec81554802 100644 --- a/src/support/path_defines.C.in +++ b/src/support/path_defines.C.in @@ -50,22 +50,22 @@ string const & lyx_dir() return ld; } +} // namespace anon + + +namespace lyx { +namespace support { + /* The absolute path to the top of the lyx build tree. * (Make-time value.) */ -string const & lyx_top_srcdir() +string const & top_srcdir() { static string const lts = "%TOP_SRCDIR%"; return lts; } -} // namespace anon - - -namespace lyx { -namespace support { - /* The absolute path to the system-level lyx locale directory. * (Make-time value.) @@ -149,7 +149,7 @@ bool setLyxPaths() string const buildlyxdir = MakeAbsPath("../lib", binpath); if (!FileSearch(buildlyxdir, "lyxrc.defaults").empty()) { - searchpath += AddPath(lyx_top_srcdir(), "lib") + ';'; + searchpath += AddPath(top_srcdir(), "lib") + ';'; build_lyxdir(buildlyxdir); lyxerr[Debug::INIT] << "Checking whether LyX is run in " "place... yes" << endl; @@ -233,7 +233,7 @@ bool setLyxPaths() } while (followlink); // /lib - searchpath += AddPath(lyx_top_srcdir(), "lib") + ';'; + searchpath += AddPath(top_srcdir(), "lib") + ';'; // Hardcoded dir searchpath += lyx_dir(); diff --git a/src/support/path_defines.h b/src/support/path_defines.h index 9c7a3f0942..97dfc3a8ca 100644 --- a/src/support/path_defines.h +++ b/src/support/path_defines.h @@ -20,6 +20,11 @@ namespace support { std::string const & lyx_localedir(); +/* The absolute path to the top of the lyx build tree. + * (Make-time value.) + */ +std::string const & top_srcdir(); + /// The absolute path to the lyx support files we're actually going to use. std::string const & system_lyxdir(); -- 2.39.5