1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
/*
Bear Engine - Editor library
Copyright (C) 20052011 Julien Jorge, Sebastien Angibaud
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: plee-the-bear@gamned.org
Please add the tag [Bear] in the subject of your mails.
*/
/**
* \file bf/code/base_editor_application.cpp
* \brief Implementation of the bf::base_editor_application class.
* \author Julien Jorge.
*/
#include "bf/base_editor_application.hpp"
#include "bf/path_configuration.hpp"
#include "bf/version.hpp"
#include "bf/wx_facilities.hpp"
#include <wx/tooltip.h>
#include <iostream>
#include <claw/exception.hpp>
#include <claw/logger.hpp>
#include <boost/preprocessor/stringize.hpp>
/*----------------------------------------------------------------------------*/
/**
* \brief Constructor.
*/
bf::base_editor_application::base_editor_application()
: m_locale( wxLocale::GetSystemLanguage() )
{
claw::logger.set( new claw::console_logger() );
claw::logger.set_level( claw::log_verbose );
#ifdef BEAR_FACTORY_TEXT_DOMAIN_PATH
m_locale.AddCatalogLookupPathPrefix
( L"" BOOST_PP_STRINGIZE(BEAR_FACTORY_TEXT_DOMAIN_PATH) );
#endif
m_locale.AddCatalog( wxT("bear-factory") );
} // base_editor_application::base_editor_application()
/*----------------------------------------------------------------------------*/
/**
* \brief Destructor.
*/
bf::base_editor_application::~base_editor_application()
{
// frames are deleted by wxWidgets
claw::logger.clear();
} // base_editor_application::~base_editor_application()
/*----------------------------------------------------------------------------*/
/**
* \brief Method called when the application is initializing.
*/
bool bf::base_editor_application::OnInit()
{
bool result = false;
if ( !show_help() )
if ( !show_version() )
{
const bool compile_f
( find_and_erase_option( wxT("--compile"), wxT("-c") ) );
const bool update_f
( find_and_erase_option( wxT("--update"), wxT("-u") ) );
if ( compile_f || update_f )
{
command_line_init();
if ( update_f )
update_arguments();
if ( compile_f )
compile_arguments();
}
else
result = init_app();
}
return result;
} // base_editor_application::OnInit()
/*----------------------------------------------------------------------------*/
/**
* \brief Compile a file.
* \param path The path to the file.
*/
void bf::base_editor_application::compile( const wxString& path ) const
{
} // base_editor_application::compile()
/*----------------------------------------------------------------------------*/
/**
* \brief Update a file.
* \param path The path to the file.
*/
void bf::base_editor_application::update( const wxString& path ) const
{
} // base_editor_application::update()
/*----------------------------------------------------------------------------*/
/**
* \brief Application-defined initialisation.
*/
bool bf::base_editor_application::do_init_app()
{
return true;
} // base_editor_application::do_init_app()
/*----------------------------------------------------------------------------*/
/**
* \brief Application-defined minimal initialisation, for command line usage.
*/
bool bf::base_editor_application::do_command_line_init()
{
return true;
} // base_editor_application::do_command_line_init()
/*----------------------------------------------------------------------------*/
/**
* \brief Initialise the application. minimal_init() is not called
* automatically.
*/
bool bf::base_editor_application::init_app()
{
wxToolTip::Enable(true);
return do_init_app();
} // base_editor_application::init_app()
/*----------------------------------------------------------------------------*/
/**
* \brief Minimal initialisation of the application, for command line usage.
*/
bool bf::base_editor_application::command_line_init()
{
return do_command_line_init();
} // base_editor_application::command_line_init()
/*----------------------------------------------------------------------------*/
/**
* \brief Compile the files and exit.
*/
bool bf::base_editor_application::compile_arguments() const
{
bool result(true);
for (int i=1; i<argc; ++i)
if ( wxString(argv[i]) != wxT("--") )
try
{
claw::logger << claw::log_verbose << "Compiling "
<< wx_to_std_string(argv[i]) << std::endl;
compile(argv[i]);
}
catch(std::exception& e)
{
std::cerr << "Error when processing '" << argv[i] << "': "
<< e.what() << std::endl;
result = false;
}
return result;
} // base_editor_application::compile_arguments()
/*----------------------------------------------------------------------------*/
/**
* \brief Update the files and exit.
*/
bool bf::base_editor_application::update_arguments() const
{
bool result(true);
for (int i=1; i<argc; ++i)
if ( wxString(argv[i]) != wxT("--") )
try
{
claw::logger << claw::log_verbose << "Updating "
<< wx_to_std_string(argv[i]) << std::endl;
update(argv[i]);
}
catch(std::exception& e)
{
std::cerr << "Error when processing '" << argv[i] << "': "
<< e.what() << std::endl;
result = false;
}
return result;
} // base_editor_application::update_arguments()
/*----------------------------------------------------------------------------*/
/**
* \brief Show the command line usage.
* \return true if the usage has been shown.
*/
bool bf::base_editor_application::show_help()
{
if ( find_and_erase_option(wxT("--help"), wxT("-h")) )
{
std::cout << "usage:\n" << wx_to_std_string(argv[0])
<< " [option] [file...]\n"
"Where the options are:\n\n"
"\t--compile, -c\tCompile the files and exit, \n"
"\t--update, -u\tUpdate the files and exit, \n"
"\t--help, -h\tDisplay this help and exit, \n"
"\t--version, -v\tDisplay the version of the program and exit."
<< std::endl;
return true;
}
else
return false;
} // base_editor_application::show_help()
/*----------------------------------------------------------------------------*/
/**
* \brief Show the version of the program
* \return true if the version has been shown.
*/
bool bf::base_editor_application::show_version()
{
if ( find_and_erase_option(wxT("--version"), wxT("-v")) )
{
std::cout << BF_VERSION_STRING << std::endl;
return true;
}
else
return false;
} // base_editor_application::show_version()
/*----------------------------------------------------------------------------*/
/**
* \brief Check if an option is present on the command line and remove it.
* \param long_name The long name of the option.
* \param short_name The short name of the option.
*/
bool bf::base_editor_application::find_and_erase_option
( const wxString& long_name, const wxString& short_name )
{
int index(0);
bool stop(false);
for (int i=1; !stop && (index==0) && (i<argc); ++i)
if ( (argv[i] == long_name) || (argv[i] == short_name))
index = i;
else
stop = wxString(argv[i]) == wxT("--");
if ( index != 0 )
{
for ( int i=index; (i != argc); ++i )
argv[i] = argv[i+1];
--argc;
}
return index != 0;
} // base_editor_application::find_and_erase_option()
|