~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-factory/bear-editor/src/bf/code/base_editor_application.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Bear Engine - Editor library
 
3
 
 
4
    Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
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.
 
10
 
 
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
 
14
    more details.
 
15
 
 
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
 
19
 
 
20
    contact: plee-the-bear@gamned.org
 
21
 
 
22
    Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file bf/code/base_editor_application.cpp
 
26
 * \brief Implementation of the bf::base_editor_application class.
 
27
 * \author Julien Jorge.
 
28
 */
 
29
#include "bf/base_editor_application.hpp"
 
30
 
 
31
#include "bf/path_configuration.hpp"
 
32
#include "bf/version.hpp"
 
33
#include "bf/wx_facilities.hpp"
 
34
 
 
35
#include <wx/tooltip.h>
 
36
 
 
37
#include <claw/exception.hpp>
 
38
#include <claw/logger.hpp>
 
39
 
 
40
/*----------------------------------------------------------------------------*/
 
41
/**
 
42
 * \brief Constructor.
 
43
 */
 
44
bf::base_editor_application::base_editor_application()
 
45
  : m_locale( wxLocale::GetSystemLanguage() )
 
46
{
 
47
  claw::logger.set( new claw::console_logger() );
 
48
  claw::logger.set_level( claw::log_verbose );
 
49
 
 
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()
 
53
 
 
54
/*----------------------------------------------------------------------------*/
 
55
/**
 
56
 * \brief Destructor.
 
57
 */
 
58
bf::base_editor_application::~base_editor_application()
 
59
{
 
60
  // frames are deleted by wxWidgets
 
61
 
 
62
  claw::logger.clear();
 
63
} // base_editor_application::~base_editor_application()
 
64
 
 
65
/*----------------------------------------------------------------------------*/
 
66
/**
 
67
 * \brief Method called when the application is initializing.
 
68
 */
 
69
bool bf::base_editor_application::OnInit()
 
70
{
 
71
  bool result = false;
 
72
 
 
73
  if ( !show_help() )
 
74
    if ( !show_version() )
 
75
      {
 
76
        const bool compile_f
 
77
          ( find_and_erase_option( wxT("--compile"), wxT("-c") ) );
 
78
        const bool update_f
 
79
          ( find_and_erase_option( wxT("--update"), wxT("-u") ) );
 
80
 
 
81
        if ( compile_f || update_f )
 
82
          {
 
83
            command_line_init();
 
84
 
 
85
            if ( update_f )
 
86
              update_arguments();
 
87
 
 
88
            if ( compile_f )
 
89
              compile_arguments();
 
90
          }
 
91
        else
 
92
          result = init_app();
 
93
      }
 
94
 
 
95
  return result;
 
96
} // base_editor_application::OnInit()
 
97
 
 
98
/*----------------------------------------------------------------------------*/
 
99
/**
 
100
 * \brief Compile a file.
 
101
 * \param path The path to the file.
 
102
 */
 
103
void bf::base_editor_application::compile( const wxString& path ) const
 
104
{
 
105
 
 
106
} // base_editor_application::compile()
 
107
 
 
108
/*----------------------------------------------------------------------------*/
 
109
/**
 
110
 * \brief Update a file.
 
111
 * \param path The path to the file.
 
112
 */
 
113
void bf::base_editor_application::update( const wxString& path ) const
 
114
{
 
115
 
 
116
} // base_editor_application::update()
 
117
 
 
118
/*----------------------------------------------------------------------------*/
 
119
/**
 
120
 * \brief Application-defined initialisation.
 
121
 */
 
122
bool bf::base_editor_application::do_init_app()
 
123
{
 
124
  return true;
 
125
} // base_editor_application::do_init_app()
 
126
 
 
127
/*----------------------------------------------------------------------------*/
 
128
/**
 
129
 * \brief Application-defined minimal initialisation, for command line usage.
 
130
 */
 
131
bool bf::base_editor_application::do_command_line_init()
 
132
{
 
133
  return true;
 
134
} // base_editor_application::do_command_line_init()
 
135
 
 
136
/*----------------------------------------------------------------------------*/
 
137
/**
 
138
 * \brief Initialise the application. minimal_init() is not called
 
139
 *        automatically.
 
140
 */
 
141
bool bf::base_editor_application::init_app()
 
142
{
 
143
  wxToolTip::Enable(true);
 
144
 
 
145
  return do_init_app();
 
146
} // base_editor_application::init_app()
 
147
 
 
148
/*----------------------------------------------------------------------------*/
 
149
/**
 
150
 * \brief Minimal initialisation of the application, for command line usage.
 
151
 */
 
152
bool bf::base_editor_application::command_line_init()
 
153
{
 
154
  return do_command_line_init();
 
155
} // base_editor_application::command_line_init()
 
156
 
 
157
/*----------------------------------------------------------------------------*/
 
158
/**
 
159
 * \brief Compile the files and exit.
 
160
 */
 
161
bool bf::base_editor_application::compile_arguments() const
 
162
{
 
163
  bool result(true);
 
164
 
 
165
  for (int i=1; i<argc; ++i)
 
166
    if ( wxString(argv[i]) != wxT("--") )
 
167
      try
 
168
        {
 
169
          claw::logger << claw::log_verbose << "Compiling "
 
170
                       << wx_to_std_string(argv[i]) << std::endl;
 
171
          compile(argv[i]);
 
172
        }
 
173
      catch(std::exception& e)
 
174
        {
 
175
          std::cerr << "Error when processing '" << argv[i] << "': "
 
176
                    << e.what() << std::endl;
 
177
          result = false;
 
178
        }
 
179
 
 
180
  return result;
 
181
} // base_editor_application::compile_arguments()
 
182
 
 
183
/*----------------------------------------------------------------------------*/
 
184
/**
 
185
 * \brief Update the files and exit.
 
186
 */
 
187
bool bf::base_editor_application::update_arguments() const
 
188
{
 
189
  bool result(true);
 
190
 
 
191
  for (int i=1; i<argc; ++i)
 
192
    if ( wxString(argv[i]) != wxT("--") )
 
193
      try
 
194
        {
 
195
          claw::logger << claw::log_verbose << "Updating "
 
196
                       << wx_to_std_string(argv[i]) << std::endl;
 
197
          update(argv[i]);
 
198
        }
 
199
      catch(std::exception& e)
 
200
        {
 
201
          std::cerr << "Error when processing '" << argv[i] << "': "
 
202
                    << e.what() << std::endl;
 
203
          result = false;
 
204
        }
 
205
 
 
206
  return result;
 
207
} // base_editor_application::update_arguments()
 
208
 
 
209
/*----------------------------------------------------------------------------*/
 
210
/**
 
211
 * \brief Show the command line usage.
 
212
 * \return true if the usage has been shown.
 
213
 */
 
214
bool bf::base_editor_application::show_help()
 
215
{
 
216
  if ( find_and_erase_option(wxT("--help"), wxT("-h")) )
 
217
    {
 
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."
 
225
                << std::endl;
 
226
      return true;
 
227
    }
 
228
  else
 
229
    return false;
 
230
} // base_editor_application::show_help()
 
231
 
 
232
/*----------------------------------------------------------------------------*/
 
233
/**
 
234
 * \brief Show the version of the program
 
235
 * \return true if the version has been shown.
 
236
 */
 
237
bool bf::base_editor_application::show_version()
 
238
{
 
239
  if ( find_and_erase_option(wxT("--version"), wxT("-v")) )
 
240
    {
 
241
      std::cout << BF_VERSION_STRING << std::endl;
 
242
      return true;
 
243
    }
 
244
  else
 
245
    return false;
 
246
} // base_editor_application::show_version()
 
247
 
 
248
/*----------------------------------------------------------------------------*/
 
249
/**
 
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.
 
253
 */
 
254
bool bf::base_editor_application::find_and_erase_option
 
255
( const wxString& long_name, const wxString& short_name )
 
256
{
 
257
  int index(0);
 
258
  bool stop(false);
 
259
 
 
260
  for (int i=1; !stop && (index==0) && (i<argc); ++i)
 
261
    if ( (argv[i] == long_name) || (argv[i] == short_name))
 
262
      index = i;
 
263
    else
 
264
      stop = wxString(argv[i]) == wxT("--");
 
265
 
 
266
  if ( index != 0 )
 
267
    {
 
268
      for ( int i=index; (i+1 != argc); ++i )
 
269
        argv[i] = argv[i+1];
 
270
 
 
271
      --argc;
 
272
      argv[argc] = NULL;
 
273
    }
 
274
 
 
275
  return index != 0;
 
276
} // base_editor_application::find_and_erase_option()