Пример #1
0
int App::run()
{
#ifdef ENABLE_UPDATER
  app::CheckUpdateThreadLauncher checkUpdate;
#endif

  // Initialize GUI interface
  if (isGui()) {
    View* view;
    Editor* editor;

    PRINTF("GUI mode\n");

    // Setup the GUI screen
    jmouse_set_cursor(JI_CURSOR_NORMAL);
    gui::Manager::getDefault()->invalidate();

    // Load main window
    top_window = static_cast<Frame*>(load_widget("main_window.xml", "main_window"));

    box_menubar = top_window->findChild("menubar");
    box_editors = top_window->findChild("editor");
    box_colorbar = top_window->findChild("colorbar");
    box_toolbar = top_window->findChild("toolbar");
    box_statusbar = top_window->findChild("statusbar");
    box_tabsbar = top_window->findChild("tabsbar");

    menubar = new MenuBar();
    statusbar = new StatusBar();
    colorbar = new ColorBar(box_colorbar->getAlign());
    toolbar = toolbar_new();
    tabsbar = new Tabs(m_tabsDelegate = new AppTabsDelegate());
    view = new EditorView(EditorView::CurrentEditorMode);
    editor = create_new_editor();

    // configure all widgets to expansives
    menubar->setExpansive(true);
    statusbar->setExpansive(true);
    colorbar->setExpansive(true);
    toolbar->setExpansive(true);
    tabsbar->setExpansive(true);
    view->setExpansive(true);

    /* prepare the first editor */
    view->attachToView(editor);

    /* setup the menus */
    menubar->setMenu(get_root_menu());

    /* start text of status bar */
    app_default_statusbar_message();

    /* add the widgets in the boxes */
    if (box_menubar) box_menubar->addChild(menubar);
    if (box_editors) box_editors->addChild(view);
    if (box_colorbar) box_colorbar->addChild(colorbar);
    if (box_toolbar) box_toolbar->addChild(toolbar);
    if (box_statusbar) box_statusbar->addChild(statusbar);
    if (box_tabsbar) box_tabsbar->addChild(tabsbar);

    /* prepare the window */
    top_window->remap_window();

    // Create the list of tabs
    app_rebuild_documents_tabs();
    app_rebuild_recent_list();

    // Set current editor
    set_current_editor(editor);

    // Open the window
    top_window->open_window();

    // Redraw the whole screen.
    gui::Manager::getDefault()->invalidate();
  }

  /* set background mode for non-GUI modes */
/*   if (!(ase_mode & MODE_GUI)) */
/*     set_display_switch_mode(SWITCH_BACKAMNESIA); */
    set_display_switch_mode(SWITCH_BACKGROUND);

    // procress options
  PRINTF("Processing options...\n");

  ASSERT(m_checkArgs != NULL);
  {
    Console console;
    for (CheckArgs::iterator
           it  = m_checkArgs->begin();
         it != m_checkArgs->end(); ++it) {
      CheckArgs::Option* option = *it;

      switch (option->type()) {

        case CheckArgs::Option::OpenSprite: {
          // Load the sprite
          Document* document = load_document(option->data().c_str());
          if (!document) {
            if (!isGui())
              console.printf("Error loading file \"%s\"\n", option->data().c_str());
          }
          else {
            // Mount and select the sprite
            UIContext* context = UIContext::instance();
            context->addDocument(document);
            context->setActiveDocument(document);

            if (isGui()) {
              // Show it
              set_document_in_more_reliable_editor(context->getFirstDocument());

              // Recent file
              getRecentFiles()->addRecentFile(option->data().c_str());
            }
          }
          break;
        }
      }
    }
    delete m_checkArgs;
    m_checkArgs = NULL;
  }

  // Run the GUI
  if (isGui()) {
    // Support to drop files from Windows explorer
    install_drop_files();

#ifdef ENABLE_UPDATER
    // Launch the thread to check for updates.
    checkUpdate.launch();
#endif

    // Run the GUI main message loop
    gui_run();

    // Uninstall support to drop files
    uninstall_drop_files();

    // Remove the root-menu from the menu-bar (because the rootmenu
    // module should destroy it).
    menubar->setMenu(NULL);

    // Delete all editors first because they used signals from other
    // widgets (e.g. color bar).
    delete box_editors;

    // Destroy mini-editor.
    exit_module_editors();

    // Destroy the top-window
    delete top_window;
    top_window = NULL;
  }

  return 0;
}