2
Bear Engine - Editor library
4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
25
* \file bf/code/base_editor_application.cpp
26
* \brief Implementation of the bf::base_editor_application class.
27
* \author Julien Jorge.
29
#include "bf/base_editor_application.hpp"
31
#include "bf/path_configuration.hpp"
32
#include "bf/version.hpp"
33
#include "bf/wx_facilities.hpp"
35
#include <wx/tooltip.h>
37
#include <claw/exception.hpp>
38
#include <claw/logger.hpp>
40
/*----------------------------------------------------------------------------*/
44
bf::base_editor_application::base_editor_application()
45
: m_locale( wxLocale::GetSystemLanguage() )
47
claw::logger.set( new claw::console_logger() );
48
claw::logger.set_level( claw::log_verbose );
50
if ( !m_locale.AddCatalog( wxT("bear-factory") ) )
51
claw::logger << "Can't add catalog 'bear-factory' to locale." << std::endl;
52
} // base_editor_application::base_editor_application()
54
/*----------------------------------------------------------------------------*/
58
bf::base_editor_application::~base_editor_application()
60
// frames are deleted by wxWidgets
63
} // base_editor_application::~base_editor_application()
65
/*----------------------------------------------------------------------------*/
67
* \brief Method called when the application is initializing.
69
bool bf::base_editor_application::OnInit()
74
if ( !show_version() )
77
( find_and_erase_option( wxT("--compile"), wxT("-c") ) );
79
( find_and_erase_option( wxT("--update"), wxT("-u") ) );
81
if ( compile_f || update_f )
96
} // base_editor_application::OnInit()
98
/*----------------------------------------------------------------------------*/
100
* \brief Compile a file.
101
* \param path The path to the file.
103
void bf::base_editor_application::compile( const wxString& path ) const
106
} // base_editor_application::compile()
108
/*----------------------------------------------------------------------------*/
110
* \brief Update a file.
111
* \param path The path to the file.
113
void bf::base_editor_application::update( const wxString& path ) const
116
} // base_editor_application::update()
118
/*----------------------------------------------------------------------------*/
120
* \brief Application-defined initialisation.
122
bool bf::base_editor_application::do_init_app()
125
} // base_editor_application::do_init_app()
127
/*----------------------------------------------------------------------------*/
129
* \brief Application-defined minimal initialisation, for command line usage.
131
bool bf::base_editor_application::do_command_line_init()
134
} // base_editor_application::do_command_line_init()
136
/*----------------------------------------------------------------------------*/
138
* \brief Initialise the application. minimal_init() is not called
141
bool bf::base_editor_application::init_app()
143
wxToolTip::Enable(true);
145
return do_init_app();
146
} // base_editor_application::init_app()
148
/*----------------------------------------------------------------------------*/
150
* \brief Minimal initialisation of the application, for command line usage.
152
bool bf::base_editor_application::command_line_init()
154
return do_command_line_init();
155
} // base_editor_application::command_line_init()
157
/*----------------------------------------------------------------------------*/
159
* \brief Compile the files and exit.
161
bool bf::base_editor_application::compile_arguments() const
165
for (int i=1; i<argc; ++i)
166
if ( wxString(argv[i]) != wxT("--") )
169
claw::logger << claw::log_verbose << "Compiling "
170
<< wx_to_std_string(argv[i]) << std::endl;
173
catch(std::exception& e)
175
std::cerr << "Error when processing '" << argv[i] << "': "
176
<< e.what() << std::endl;
181
} // base_editor_application::compile_arguments()
183
/*----------------------------------------------------------------------------*/
185
* \brief Update the files and exit.
187
bool bf::base_editor_application::update_arguments() const
191
for (int i=1; i<argc; ++i)
192
if ( wxString(argv[i]) != wxT("--") )
195
claw::logger << claw::log_verbose << "Updating "
196
<< wx_to_std_string(argv[i]) << std::endl;
199
catch(std::exception& e)
201
std::cerr << "Error when processing '" << argv[i] << "': "
202
<< e.what() << std::endl;
207
} // base_editor_application::update_arguments()
209
/*----------------------------------------------------------------------------*/
211
* \brief Show the command line usage.
212
* \return true if the usage has been shown.
214
bool bf::base_editor_application::show_help()
216
if ( find_and_erase_option(wxT("--help"), wxT("-h")) )
218
std::cout << "usage:\n" << wx_to_std_string(argv[0])
219
<< " [option] [file...]\n"
220
"Where the options are:\n\n"
221
"\t--compile, -c\tCompile the files and exit,\n"
222
"\t--update, -u\tUpdate the files and exit,\n"
223
"\t--help, -h\tDisplay this help and exit,\n"
224
"\t--version, -v\tDisplay the version of the program and exit."
230
} // base_editor_application::show_help()
232
/*----------------------------------------------------------------------------*/
234
* \brief Show the version of the program
235
* \return true if the version has been shown.
237
bool bf::base_editor_application::show_version()
239
if ( find_and_erase_option(wxT("--version"), wxT("-v")) )
241
std::cout << BF_VERSION_STRING << std::endl;
246
} // base_editor_application::show_version()
248
/*----------------------------------------------------------------------------*/
250
* \brief Check if an option is present on the command line and remove it.
251
* \param long_name The long name of the option.
252
* \param short_name The short name of the option.
254
bool bf::base_editor_application::find_and_erase_option
255
( const wxString& long_name, const wxString& short_name )
260
for (int i=1; !stop && (index==0) && (i<argc); ++i)
261
if ( (argv[i] == long_name) || (argv[i] == short_name))
264
stop = wxString(argv[i]) == wxT("--");
268
for ( int i=index; (i+1 != argc); ++i )
276
} // base_editor_application::find_and_erase_option()