Fix crash in "go to" commands, don't access to null layer

This commit is contained in:
David Capello 2014-03-16 21:56:18 -03:00
parent c4605ad513
commit fabb58e0ea

View File

@ -32,7 +32,22 @@
namespace app { namespace app {
class GotoPreviousLayerCommand : public Command { class GotoCommand : public Command {
public:
GotoCommand(const char* short_name, const char* friendly_name, CommandFlags flags)
: Command(short_name, friendly_name, flags) {
}
protected:
void updateStatusBar(DocumentLocation& location) {
if (location.layer() != NULL)
StatusBar::instance()
->setStatusText(1000, "Layer `%s' selected",
location.layer()->getName().c_str());
}
};
class GotoPreviousLayerCommand : public GotoCommand {
public: public:
GotoPreviousLayerCommand(); GotoPreviousLayerCommand();
Command* clone() { return new GotoPreviousLayerCommand(*this); } Command* clone() { return new GotoPreviousLayerCommand(*this); }
@ -43,9 +58,9 @@ protected:
}; };
GotoPreviousLayerCommand::GotoPreviousLayerCommand() GotoPreviousLayerCommand::GotoPreviousLayerCommand()
: Command("GotoPreviousLayer", : GotoCommand("GotoPreviousLayer",
"Goto Previous Layer", "Goto Previous Layer",
CmdUIOnlyFlag) CmdUIOnlyFlag)
{ {
} }
@ -71,12 +86,10 @@ void GotoPreviousLayerCommand::onExecute(Context* context)
current_editor->setLayer(location.layer()); current_editor->setLayer(location.layer());
current_editor->flashCurrentLayer(); current_editor->flashCurrentLayer();
StatusBar::instance() updateStatusBar(location);
->setStatusText(1000, "Layer `%s' selected",
location.layer()->getName().c_str());
} }
class GotoNextLayerCommand : public Command { class GotoNextLayerCommand : public GotoCommand {
public: public:
GotoNextLayerCommand(); GotoNextLayerCommand();
Command* clone() { return new GotoNextLayerCommand(*this); } Command* clone() { return new GotoNextLayerCommand(*this); }
@ -87,9 +100,9 @@ protected:
}; };
GotoNextLayerCommand::GotoNextLayerCommand() GotoNextLayerCommand::GotoNextLayerCommand()
: Command("GotoNextLayer", : GotoCommand("GotoNextLayer",
"Goto Next Layer", "Goto Next Layer",
CmdUIOnlyFlag) CmdUIOnlyFlag)
{ {
} }
@ -115,9 +128,7 @@ void GotoNextLayerCommand::onExecute(Context* context)
current_editor->setLayer(location.layer()); current_editor->setLayer(location.layer());
current_editor->flashCurrentLayer(); current_editor->flashCurrentLayer();
StatusBar::instance() updateStatusBar(location);
->setStatusText(1000, "Layer `%s' selected",
location.layer()->getName().c_str());
} }
Command* CommandFactory::createGotoPreviousLayerCommand() Command* CommandFactory::createGotoPreviousLayerCommand()