[aseprite] 72/134: Fix crash changing ConfigureTools options when activeDoc == NULL
Tobias Hansen
thansen at moszumanska.debian.org
Sat Mar 14 17:10:08 UTC 2015
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit a00a3b2a83e70ea438df1200123cc3840624857c
Author: David Capello <davidcapello at gmail.com>
Date: Mon Nov 24 20:52:52 2014 -0300
Fix crash changing ConfigureTools options when activeDoc == NULL
---
data/widgets/tools_configuration.xml | 4 +-
src/app/commands/cmd_configure_tools.cpp | 274 +++++++++++++------------------
2 files changed, 120 insertions(+), 158 deletions(-)
diff --git a/data/widgets/tools_configuration.xml b/data/widgets/tools_configuration.xml
index fcce211..d905710 100644
--- a/data/widgets/tools_configuration.xml
+++ b/data/widgets/tools_configuration.xml
@@ -1,7 +1,7 @@
<!-- ASEPRITE -->
-<!-- Copyright (C) 2001-2013 by David Capello -->
+<!-- Copyright (C) 2001-2014 by David Capello -->
<gui>
-<window text="Tools Configuration" id="configure_tool">
+<window text="Tools Configuration" id="tools_configuration">
<box vertical="true" childspacing="0">
<box horizontal="true" expansive="true">
<box vertical="true" childspacing="2">
diff --git a/src/app/commands/cmd_configure_tools.cpp b/src/app/commands/cmd_configure_tools.cpp
index a4375be..517296a 100644
--- a/src/app/commands/cmd_configure_tools.cpp
+++ b/src/app/commands/cmd_configure_tools.cpp
@@ -1,5 +1,5 @@
/* Aseprite
- * Copyright (C) 2001-2013 David Capello
+ * Copyright (C) 2001-2014 David Capello
*
* 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
@@ -41,206 +41,168 @@
#include "raster/mask.h"
#include "ui/ui.h"
+#include "generated_tools_configuration.h"
+
namespace app {
using namespace gfx;
using namespace ui;
using namespace app::tools;
-static Window* window = NULL;
-
-// Slot for App::Exit signal
-static void on_exit_delete_this_widget()
-{
- ASSERT(window != NULL);
- delete window;
-}
-
-class ConfigureTools : public Command,
- public doc::ContextObserver {
+class ToolsConfigurationWindow : public app::gen::ToolsConfiguration,
+ public doc::ContextObserver {
public:
- ConfigureTools();
- Command* clone() const override { return new ConfigureTools(*this); }
+ ToolsConfigurationWindow(Context* ctx) : m_ctx(ctx) {
+ m_ctx->addObserver(this);
-protected:
- void onExecute(Context* context) override;
- void onSetActiveDocument(doc::Document* document) override;
+ // Slots
+ this->Close.connect(Bind<void>(&ToolsConfigurationWindow::onWindowClose, this));
+ tiled()->Click.connect(Bind<void>(&ToolsConfigurationWindow::onTiledClick, this));
+ tiledX()->Click.connect(Bind<void>(&ToolsConfigurationWindow::onTiledXYClick, this, filters::TILED_X_AXIS, tiledX()));
+ tiledY()->Click.connect(Bind<void>(&ToolsConfigurationWindow::onTiledXYClick, this, filters::TILED_Y_AXIS, tiledY()));
+ viewGrid()->Click.connect(Bind<void>(&ToolsConfigurationWindow::onViewGridClick, this));
+ pixelGrid()->Click.connect(Bind<void>(&ToolsConfigurationWindow::onPixelGridClick, this));
+ setGrid()->Click.connect(Bind<void>(&ToolsConfigurationWindow::onSetGridClick, this));
+ snapToGrid()->Click.connect(Bind<void>(&ToolsConfigurationWindow::onSnapToGridClick, this));
+
+ remapWindow();
+ centerWindow();
+ load_window_pos(this, "ConfigureTool");
+
+ onSetActiveDocument(m_ctx->activeDocument());
+ }
-private:
- CheckBox* m_tiled;
- CheckBox* m_tiledX;
- CheckBox* m_tiledY;
- CheckBox* m_pixelGrid;
- CheckBox* m_snapToGrid;
- CheckBox* m_viewGrid;
- ISettings* m_settings;
- IDocumentSettings* m_docSettings;
-
- void onWindowClose();
- void onTiledClick();
- void onTiledXYClick(int tiled_axis, CheckBox* checkbox);
- void onViewGridClick();
- void onPixelGridClick();
- void onSetGridClick();
- void onSnapToGridClick();
-};
+ ~ToolsConfigurationWindow() {
+ m_ctx->removeObserver(this);
+ }
-ConfigureTools::ConfigureTools()
- : Command("ConfigureTools",
- "Configure Tools",
- CmdUIOnlyFlag)
-{
- m_settings = NULL;
- m_docSettings = NULL;
-}
+private:
+ ISettings* settings() {
+ ASSERT(m_ctx);
+ return m_ctx->settings();
+ }
-void ConfigureTools::onExecute(Context* context)
-{
- m_settings = context->settings();
- m_docSettings = NULL;
+ IDocumentSettings* docSettings() {
+ ASSERT(settings());
+ return settings()->getDocumentSettings(m_ctx->activeDocument());
+ }
- Button* set_grid;
- bool first_time = false;
+ void onSetActiveDocument(doc::Document* document) override {
+ IDocumentSettings* docSettings = this->docSettings();
- if (!window) {
- window = app::load_widget<Window>("tools_configuration.xml", "configure_tool");
- first_time = true;
+ tiled()->setSelected(docSettings->getTiledMode() != filters::TILED_NONE);
+ tiledX()->setSelected(docSettings->getTiledMode() & filters::TILED_X_AXIS ? true: false);
+ tiledY()->setSelected(docSettings->getTiledMode() & filters::TILED_Y_AXIS ? true: false);
+ snapToGrid()->setSelected(docSettings->getSnapToGrid());
+ viewGrid()->setSelected(docSettings->getGridVisible());
+ pixelGrid()->setSelected(docSettings->getPixelGridVisible());
}
- // If the window is opened, close it
- else if (window->isVisible()) {
- context->removeObserver(this);
- window->closeWindow(NULL);
- return;
+
+ void onWindowClose() {
+ save_window_pos(this, "ConfigureTool");
}
- context->addObserver(this);
+ void onTiledClick() {
+ bool flag = tiled()->isSelected();
- try {
- m_tiled = app::find_widget<CheckBox>(window, "tiled");
- m_tiledX = app::find_widget<CheckBox>(window, "tiled_x");
- m_tiledY = app::find_widget<CheckBox>(window, "tiled_y");
- m_snapToGrid = app::find_widget<CheckBox>(window, "snap_to_grid");
- m_viewGrid = app::find_widget<CheckBox>(window, "view_grid");
- m_pixelGrid = app::find_widget<CheckBox>(window, "pixel_grid");
- set_grid = app::find_widget<Button>(window, "set_grid");
- }
- catch (...) {
- delete window;
- window = NULL;
- throw;
+ docSettings()->setTiledMode(
+ flag ? filters::TILED_BOTH:
+ filters::TILED_NONE);
+
+ tiledX()->setSelected(flag);
+ tiledY()->setSelected(flag);
}
- onSetActiveDocument(context->activeDocument());
+ void onTiledXYClick(int tiled_axis, CheckBox* checkbox) {
+ int tiled_mode = docSettings()->getTiledMode();
- if (first_time) {
- // Slots
- window->Close.connect(Bind<void>(&ConfigureTools::onWindowClose, this));
- m_tiled->Click.connect(Bind<void>(&ConfigureTools::onTiledClick, this));
- m_tiledX->Click.connect(Bind<void>(&ConfigureTools::onTiledXYClick, this, filters::TILED_X_AXIS, m_tiledX));
- m_tiledY->Click.connect(Bind<void>(&ConfigureTools::onTiledXYClick, this, filters::TILED_Y_AXIS, m_tiledY));
- m_viewGrid->Click.connect(Bind<void>(&ConfigureTools::onViewGridClick, this));
- m_pixelGrid->Click.connect(Bind<void>(&ConfigureTools::onPixelGridClick, this));
- set_grid->Click.connect(Bind<void>(&ConfigureTools::onSetGridClick, this));
- m_snapToGrid->Click.connect(Bind<void>(&ConfigureTools::onSnapToGridClick, this));
+ if (checkbox->isSelected())
+ tiled_mode |= tiled_axis;
+ else
+ tiled_mode &= ~tiled_axis;
- App::instance()->Exit.connect(&on_exit_delete_this_widget);
- }
+ checkbox->findSibling("tiled")->setSelected(tiled_mode != filters::TILED_NONE);
- // Default position
- window->remapWindow();
- window->centerWindow();
+ docSettings()->setTiledMode((filters::TiledMode)tiled_mode);
+ }
- // Load window configuration
- load_window_pos(window, "ConfigureTool");
+ void onViewGridClick() {
+ docSettings()->setGridVisible(viewGrid()->isSelected());
+ }
- window->openWindow();
-}
+ void onPixelGridClick() {
+ docSettings()->setPixelGridVisible(pixelGrid()->isSelected());
+ }
-void ConfigureTools::onWindowClose()
-{
- save_window_pos(window, "ConfigureTool");
-}
+ void onSetGridClick() {
+ try {
+ // TODO use the same context as in ConfigureTools::onExecute
+ const ContextReader reader(UIContext::instance());
+ const Document* document = reader.document();
-void ConfigureTools::onTiledClick()
-{
- bool flag = m_tiled->isSelected();
+ if (document && document->isMaskVisible()) {
+ const Mask* mask(document->mask());
- m_docSettings->setTiledMode(flag ? filters::TILED_BOTH:
- filters::TILED_NONE);
+ docSettings()->setGridBounds(mask->bounds());
+ }
+ else {
+ Command* grid_settings_cmd =
+ CommandsModule::instance()->getCommandByName(CommandId::GridSettings);
- m_tiledX->setSelected(flag);
- m_tiledY->setSelected(flag);
-}
+ UIContext::instance()->executeCommand(grid_settings_cmd, NULL);
+ }
+ }
+ catch (LockedDocumentException& e) {
+ Console::showException(e);
+ }
+ }
-void ConfigureTools::onTiledXYClick(int tiled_axis, CheckBox* checkbox)
-{
- int tiled_mode = m_docSettings->getTiledMode();
+ void onSnapToGridClick() {
+ docSettings()->setSnapToGrid(snapToGrid()->isSelected());
+ }
- if (checkbox->isSelected())
- tiled_mode |= tiled_axis;
- else
- tiled_mode &= ~tiled_axis;
+ Context* m_ctx;
+};
- checkbox->findSibling("tiled")->setSelected(tiled_mode != filters::TILED_NONE);
+class ConfigureTools : public Command {
+public:
+ ConfigureTools();
+ Command* clone() const override { return new ConfigureTools(*this); }
- m_docSettings->setTiledMode((filters::TiledMode)tiled_mode);
-}
+protected:
+ void onExecute(Context* context) override;
+};
-void ConfigureTools::onSnapToGridClick()
-{
- m_docSettings->setSnapToGrid(m_snapToGrid->isSelected());
-}
+static ToolsConfigurationWindow* window;
-void ConfigureTools::onViewGridClick()
+ConfigureTools::ConfigureTools()
+ : Command("ConfigureTools",
+ "Configure Tools",
+ CmdUIOnlyFlag)
{
- m_docSettings->setGridVisible(m_viewGrid->isSelected());
}
-void ConfigureTools::onPixelGridClick()
+// Slot for App::Exit signal
+static void on_exit_delete_this_widget()
{
- m_docSettings->setPixelGridVisible(m_pixelGrid->isSelected());
+ ASSERT(window != NULL);
+ delete window;
}
-void ConfigureTools::onSetGridClick()
+void ConfigureTools::onExecute(Context* context)
{
- try {
- // TODO use the same context as in ConfigureTools::onExecute
- const ContextReader reader(UIContext::instance());
- const Document* document = reader.document();
-
- if (document && document->isMaskVisible()) {
- const Mask* mask(document->mask());
-
- m_docSettings->setGridBounds(mask->bounds());
- }
- else {
- Command* grid_settings_cmd =
- CommandsModule::instance()->getCommandByName(CommandId::GridSettings);
+ if (!window) {
+ window = new ToolsConfigurationWindow(context);
- UIContext::instance()->executeCommand(grid_settings_cmd, NULL);
- }
- }
- catch (LockedDocumentException& e) {
- Console::showException(e);
+ App::instance()->Exit.connect(&on_exit_delete_this_widget);
}
-}
-
-void ConfigureTools::onSetActiveDocument(doc::Document* document)
-{
- if (!document)
- return;
-
- m_docSettings = m_settings->getDocumentSettings(document);
- ASSERT(m_docSettings);
- if (!m_docSettings)
+ // If the window is opened, close it
+ else if (window->isVisible()) {
+ window->closeWindow(NULL);
return;
+ }
- m_tiled->setSelected(m_docSettings->getTiledMode() != filters::TILED_NONE);
- m_tiledX->setSelected(m_docSettings->getTiledMode() & filters::TILED_X_AXIS ? true: false);
- m_tiledY->setSelected(m_docSettings->getTiledMode() & filters::TILED_Y_AXIS ? true: false);
- m_snapToGrid->setSelected(m_docSettings->getSnapToGrid());
- m_viewGrid->setSelected(m_docSettings->getGridVisible());
- m_pixelGrid->setSelected(m_docSettings->getPixelGridVisible());
+ window->openWindow();
}
Command* CommandFactory::createConfigureToolsCommand()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list