[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] (no subject)
From: |
Greg Chicares |
Subject: |
[lmi-commits] (no subject) |
Date: |
Sun, 29 May 2016 23:16:41 +0000 (UTC) |
branch: master
commit ab6e11a59c58db5d1bdc9595a57f4e9439452ce9
Author: Vadim Zeitlin <address@hidden>
Date: Mon May 2 00:16:22 2016 +0200
Refactor: add helper function to load XRC file, throwing on error
Don't repeat the same code, made especially ugly by the presence of an
#if checking for wxWidgets version, 8 times but just put it in a
function and call this function 8 times instead.
---
skeleton.cpp | 103 ++++++++++++++++------------------------------------------
1 file changed, 28 insertions(+), 75 deletions(-)
diff --git a/skeleton.cpp b/skeleton.cpp
index 7dba971..697015d 100644
--- a/skeleton.cpp
+++ b/skeleton.cpp
@@ -106,6 +106,26 @@
#include <stdexcept>
#include <string>
+namespace
+{
+// Load the XRC file with the given base name from the data directory and call
+// fatal_error() if loading it failed.
+void load_xrc_file_from_data_directory
+ (wxXmlResource& xml_resources
+ ,char const* xrc_filename
+ )
+{
+#if wxCHECK_VERSION(2,9,0)
+ if(!xml_resources.LoadFile(wxFileName(AddDataDir(xrc_filename))))
+#else // !wxCHECK_VERSION(2,9,0)
+ if(!xml_resources.Load(AddDataDir(xrc_filename)))
+#endif // !wxCHECK_VERSION(2,9,0)
+ {
+ fatal_error() << "Unable to load xml resources." << LMI_FLUSH;
+ }
+}
+} // Unnamed namespace.
+
// Where a builtin wxID_X identifier exists, use it as such, even if
// it's used as the 'name=' attribute of an entity in an '.xrc' file.
// For example, write 'wxID_SAVE' here, not 'XRCID("wxID_SAVE")'.
@@ -688,81 +708,14 @@ bool Skeleton::OnInit()
xml_resources.AddHandler(new(wx) RoundingButtonsXmlHandler);
xml_resources.AddHandler(new(wx) InputSequenceEntryXmlHandler);
- DefaultView const v0;
-#if wxCHECK_VERSION(2,9,0)
-
if(!xml_resources.LoadFile(wxFileName(AddDataDir(v0.ResourceFileName()))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir(v0.ResourceFileName())))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load xml resources." << LMI_FLUSH;
- }
-
- PreferencesView const v1;
-#if wxCHECK_VERSION(2,9,0)
-
if(!xml_resources.LoadFile(wxFileName(AddDataDir(v1.ResourceFileName()))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir(v1.ResourceFileName())))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load xml resources." << LMI_FLUSH;
- }
-
- mec_mvc_view const v2;
-#if wxCHECK_VERSION(2,9,0)
-
if(!xml_resources.LoadFile(wxFileName(AddDataDir(v2.ResourceFileName()))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir(v2.ResourceFileName())))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load xml resources." << LMI_FLUSH;
- }
-
- gpt_mvc_view const v3;
-#if wxCHECK_VERSION(2,9,0)
-
if(!xml_resources.LoadFile(wxFileName(AddDataDir(v3.ResourceFileName()))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir(v3.ResourceFileName())))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load xml resources." << LMI_FLUSH;
- }
-
-#if wxCHECK_VERSION(2,9,0)
- if(!xml_resources.LoadFile(wxFileName(AddDataDir("menus.xrc"))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir("menus.xrc")))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load menubar." << LMI_FLUSH;
- }
-
-#if wxCHECK_VERSION(2,9,0)
- if(!xml_resources.LoadFile(wxFileName(AddDataDir("toolbar.xrc"))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir("toolbar.xrc")))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load toolbar." << LMI_FLUSH;
- }
-
-#if wxCHECK_VERSION(2,9,0)
-
if(!xml_resources.LoadFile(wxFileName(AddDataDir(PolicyView::resource_file_name()))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir(PolicyView::resource_file_name())))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load Policy resources." << LMI_FLUSH;
- }
-
-#if wxCHECK_VERSION(2,9,0)
-
if(!xml_resources.LoadFile(wxFileName(AddDataDir(RoundingView::resource_file_name()))))
-#else // !wxCHECK_VERSION(2,9,0)
- if(!xml_resources.Load(AddDataDir(RoundingView::resource_file_name())))
-#endif // !wxCHECK_VERSION(2,9,0)
- {
- fatal_error() << "Unable to load Rounding resources." << LMI_FLUSH;
- }
+ load_xrc_file_from_data_directory(xml_resources,
DefaultView().ResourceFileName());
+ load_xrc_file_from_data_directory(xml_resources,
PreferencesView().ResourceFileName());
+ load_xrc_file_from_data_directory(xml_resources,
mec_mvc_view().ResourceFileName());
+ load_xrc_file_from_data_directory(xml_resources,
gpt_mvc_view().ResourceFileName());
+ load_xrc_file_from_data_directory(xml_resources, "menus.xrc");
+ load_xrc_file_from_data_directory(xml_resources, "toolbar.xrc");
+ load_xrc_file_from_data_directory(xml_resources,
PolicyView::resource_file_name());
+ load_xrc_file_from_data_directory(xml_resources,
RoundingView::resource_file_name());
InitDocManager();