]> git.lyx.org Git - features.git/commitdiff
Search the src tree for glade files, so preventing an unnecessary crash
authorAngus Leeming <leeming@lyx.org>
Tue, 27 Apr 2004 12:48:45 +0000 (12:48 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 27 Apr 2004 12:48:45 +0000 (12:48 +0000)
in the gtk frontend.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8699 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/frontends/gtk/ChangeLog
src/frontends/gtk/GAboutlyx.C
src/frontends/gtk/GMathDelim.C
src/frontends/gtk/GMathPanel.C
src/frontends/gtk/GPrint.C
src/frontends/gtk/GTableCreate.C
src/frontends/gtk/GText.C
src/frontends/gtk/GUrl.C
src/frontends/gtk/Makefile.am
src/frontends/gtk/ghelpers.C [new file with mode: 0644]
src/frontends/gtk/ghelpers.h [new file with mode: 0644]
src/support/ChangeLog
src/support/path_defines.C.in
src/support/path_defines.h

index 1dc055a67c09ebd7ea859b7946594c7d0679f152..10df8f91dddb6a120d2e35aed97914b0ff91b0d9 100644 (file)
@@ -1,3 +1,20 @@
+2004-04-27  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * Makefile.am (SUBDIRS): add gimages.
index 38a39e9e02ad480ea31eaee44765f011b96a5142..7ebad4eada988259eab6d6a2395dce348d22618a 100644 (file)
@@ -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;
index 0685bb07304bc719b6da461a50d34a45f30e3fd4..6ddd51920778d88c236d90d9d4b12d209924e45d 100644 (file)
 
 #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;
index a1c450b459afa5e0fa8571e94f3d5770e7b7919f..eb16e49d08d534c922563efc58e2c7ed8486c10f 100644 (file)
@@ -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;
index 4cd4f7b9e33ad4554e7324cd3bad10930a4f3313..d43be55f7323d87231415439c02d5ce7f186d424 100644 (file)
@@ -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_);
index c69d695ea1685fded2b5e793797cb3bd56a4a8ec..98ecf8a1ccdb5672c95bfe3e0cd39f910e7bab89 100644 (file)
@@ -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;
index 8944ec227fc8c2bdfdac752de4c12d91b3d2808c..6ffb00ba74ee2f7ffedd6e5c75bc515e517b2c43 100644 (file)
@@ -13,9 +13,9 @@
 #include <libglademm.h>
 
 #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;
index f9033075b1be31dbbf5229f53c076c1223137635..1822b6e158f6a592cd2f5152f1c6ba4f654e36b5 100644 (file)
@@ -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;
index 63fcc5441d75180b0ea8e6e45e5709b05971bdc3..9d585327e75e3ef42eb1678bebbb9f6b726e3f01 100644 (file)
@@ -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 (file)
index 0000000..e2008f6
--- /dev/null
@@ -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 <config.h>
+
+#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 (file)
index 0000000..873e269
--- /dev/null
@@ -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 <string>
+
+/** 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
index 01dafe8de76889c86497a8acb2be8ce7e0f585c0..be363b7e2390b187126398b746338abe5c39f90a 100644 (file)
@@ -1,3 +1,8 @@
+2004-04-27  Angus Leeming  <leeming@lyx.org>
+
+       * path_defines.{h,C.in}: expose top_srcdir, renamed from
+       lyx_top_srcdir.
+
 2004-04-05  Angus Leeming  <leeming@lyx.org>
 
        * filetools.C:
index 7cc73345ac08afda5b9d796ff93ba54cc599ee88..ec81554802081e91423bf5fa64515d27db878b72 100644 (file)
@@ -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);
 
        // <absolute top srcdir>/lib
-       searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
+       searchpath += AddPath(top_srcdir(), "lib") + ';';
        // Hardcoded dir
        searchpath += lyx_dir();
 
index 9c7a3f0942e8706f3045403f32ae0f5c7db8be52..97dfc3a8ca46d14db1350b6a81164d521f9d207d 100644 (file)
@@ -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();