mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 04:59:24 +00:00
Add support to close any kind of WorkspaceView (HomeView and DevConsoleView)
* Add WorkspaceView::onCloseView() member function * Now DevConsoleView is inside MainWindow (just like HomeView)
This commit is contained in:
parent
e850c8dbb0
commit
6064debe13
@ -575,6 +575,7 @@
|
||||
</item>
|
||||
<item command="TogglePreview" text="Previe&w" />
|
||||
<item command="FullscreenPreview" text="&Fullscreen Preview" />
|
||||
<item command="Home" text="&Home" />
|
||||
<separator />
|
||||
<item command="Refresh" text="&Refresh && Reload Skin" />
|
||||
</menu>
|
||||
|
@ -149,6 +149,7 @@ add_library(app-lib
|
||||
commands/cmd_goto_layer.cpp
|
||||
commands/cmd_goto_tab.cpp
|
||||
commands/cmd_grid.cpp
|
||||
commands/cmd_home.cpp
|
||||
commands/cmd_import_sprite_sheet.cpp
|
||||
commands/cmd_invert_mask.cpp
|
||||
commands/cmd_keyboard_shortcuts.cpp
|
||||
|
@ -11,15 +11,7 @@
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/context.h"
|
||||
#include "app/document.h"
|
||||
#include "app/ui/devconsole_view.h"
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/workspace.h"
|
||||
#include "ui/box.h"
|
||||
#include "ui/button.h"
|
||||
#include "ui/combobox.h"
|
||||
#include "ui/window.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -32,8 +24,6 @@ public:
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context);
|
||||
|
||||
DevConsoleView* m_devConsole;
|
||||
};
|
||||
|
||||
DeveloperConsoleCommand::DeveloperConsoleCommand()
|
||||
@ -41,24 +31,15 @@ DeveloperConsoleCommand::DeveloperConsoleCommand()
|
||||
"Developer Console",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
m_devConsole = NULL;
|
||||
}
|
||||
|
||||
DeveloperConsoleCommand::~DeveloperConsoleCommand()
|
||||
{
|
||||
delete m_devConsole;
|
||||
}
|
||||
|
||||
void DeveloperConsoleCommand::onExecute(Context* context)
|
||||
{
|
||||
if (!m_devConsole) {
|
||||
m_devConsole = new DevConsoleView();
|
||||
|
||||
App::instance()->getMainWindow()->getWorkspace()->addView(m_devConsole);
|
||||
}
|
||||
|
||||
App::instance()->getMainWindow()->getTabsBar()->selectTab(m_devConsole);
|
||||
App::instance()->getMainWindow()->getWorkspace()->setActiveView(m_devConsole);
|
||||
App::instance()->getMainWindow()->showDevConsole();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createDeveloperConsoleCommand()
|
||||
|
50
src/app/commands/cmd_home.cpp
Normal file
50
src/app/commands/cmd_home.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/ui/main_window.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
class HomeCommand : public Command {
|
||||
public:
|
||||
HomeCommand();
|
||||
~HomeCommand();
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context);
|
||||
};
|
||||
|
||||
HomeCommand::HomeCommand()
|
||||
: Command("Home",
|
||||
"Home",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
HomeCommand::~HomeCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void HomeCommand::onExecute(Context* context)
|
||||
{
|
||||
App::instance()->getMainWindow()->showHome();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createHomeCommand()
|
||||
{
|
||||
return new HomeCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -48,6 +48,7 @@ FOR_EACH_COMMAND(GotoPreviousFrame)
|
||||
FOR_EACH_COMMAND(GotoPreviousLayer)
|
||||
FOR_EACH_COMMAND(GotoPreviousTab)
|
||||
FOR_EACH_COMMAND(GridSettings)
|
||||
FOR_EACH_COMMAND(Home)
|
||||
FOR_EACH_COMMAND(ImportSpriteSheet)
|
||||
FOR_EACH_COMMAND(InvertColor)
|
||||
FOR_EACH_COMMAND(InvertMask)
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "app/ui/devconsole_view.h"
|
||||
|
||||
#include "app/ui/workspace.h"
|
||||
#include "ui/entry.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/textbox.h"
|
||||
@ -102,6 +103,11 @@ void DevConsoleView::onClonedFrom(WorkspaceView* from)
|
||||
{
|
||||
}
|
||||
|
||||
void DevConsoleView::onCloseView(Workspace* workspace)
|
||||
{
|
||||
workspace->removeView(this);
|
||||
}
|
||||
|
||||
bool DevConsoleView::onProcessMessage(Message* msg)
|
||||
{
|
||||
return Box::onProcessMessage(msg);
|
||||
|
@ -33,6 +33,7 @@ namespace app {
|
||||
WorkspaceView* cloneWorkspaceView() override;
|
||||
void onWorkspaceViewSelected() override;
|
||||
void onClonedFrom(WorkspaceView* from) override;
|
||||
void onCloseView(Workspace* workspace) override;
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "app/ui/document_view.h"
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/modules/editors.h"
|
||||
#include "app/modules/palettes.h"
|
||||
#include "app/ui/editor/editor.h"
|
||||
@ -21,6 +22,7 @@
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/preview_editor.h"
|
||||
#include "app/ui/workspace.h"
|
||||
#include "app/ui_context.h"
|
||||
#include "base/path.h"
|
||||
#include "doc/document_event.h"
|
||||
#include "doc/layer.h"
|
||||
@ -222,6 +224,18 @@ void DocumentView::onClonedFrom(WorkspaceView* from)
|
||||
->setViewScroll(View::getView(srcEditor)->getViewScroll());
|
||||
}
|
||||
|
||||
void DocumentView::onCloseView(Workspace* workspace)
|
||||
{
|
||||
UIContext* context = UIContext::instance();
|
||||
context->setActiveView(this);
|
||||
context->updateFlags();
|
||||
|
||||
Command* close_file_cmd =
|
||||
CommandsModule::instance()->getCommandByName(CommandId::CloseFile);
|
||||
|
||||
context->executeCommand(close_file_cmd, NULL);
|
||||
}
|
||||
|
||||
bool DocumentView::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type()) {
|
||||
|
@ -49,6 +49,7 @@ namespace app {
|
||||
WorkspaceView* cloneWorkspaceView() override;
|
||||
void onWorkspaceViewSelected() override;
|
||||
void onClonedFrom(WorkspaceView* from) override;
|
||||
void onCloseView(Workspace* workspace) override;
|
||||
|
||||
// DocumentObserver implementation
|
||||
void onGeneralUpdate(doc::DocumentEvent& ev) override;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "app/ui/home_view.h"
|
||||
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
#include "app/ui/workspace.h"
|
||||
#include "ui/label.h"
|
||||
#include "ui/textbox.h"
|
||||
#include "ui/view.h"
|
||||
@ -58,6 +59,11 @@ void HomeView::onClonedFrom(WorkspaceView* from)
|
||||
ASSERT(false); // Never called
|
||||
}
|
||||
|
||||
void HomeView::onCloseView(Workspace* workspace)
|
||||
{
|
||||
workspace->removeView(this);
|
||||
}
|
||||
|
||||
void HomeView::onWorkspaceViewSelected()
|
||||
{
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ namespace app {
|
||||
ui::Widget* getContentWidget() override { return this; }
|
||||
WorkspaceView* cloneWorkspaceView() override;
|
||||
void onClonedFrom(WorkspaceView* from) override;
|
||||
void onCloseView(Workspace* workspace) override;
|
||||
void onWorkspaceViewSelected() override;
|
||||
};
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "app/settings/settings.h"
|
||||
#include "app/ui/color_bar.h"
|
||||
#include "app/ui/context_bar.h"
|
||||
#include "app/ui/devconsole_view.h"
|
||||
#include "app/ui/document_view.h"
|
||||
#include "app/ui/editor/editor.h"
|
||||
#include "app/ui/editor/editor_view.h"
|
||||
@ -50,7 +51,8 @@ MainWindow::MainWindow()
|
||||
, m_lastSplitterPos(0.0)
|
||||
, m_lastTimelineSplitterPos(75.0)
|
||||
, m_mode(NormalMode)
|
||||
, m_homeView(NULL)
|
||||
, m_homeView(nullptr)
|
||||
, m_devConsoleView(nullptr)
|
||||
{
|
||||
setId("main_window");
|
||||
|
||||
@ -122,8 +124,14 @@ MainWindow::MainWindow()
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
if (m_devConsoleView) {
|
||||
if (m_devConsoleView->getParent())
|
||||
m_workspace->removeView(m_devConsoleView);
|
||||
delete m_devConsoleView;
|
||||
}
|
||||
if (m_homeView) {
|
||||
m_workspace->removeView(m_homeView);
|
||||
if (m_homeView->getParent())
|
||||
m_workspace->removeView(m_homeView);
|
||||
delete m_homeView;
|
||||
}
|
||||
delete m_contextBar;
|
||||
@ -154,6 +162,28 @@ void MainWindow::showNotification(INotificationDelegate* del)
|
||||
m_notifications->getParent()->layout();
|
||||
}
|
||||
|
||||
void MainWindow::showHome()
|
||||
{
|
||||
if (!m_homeView)
|
||||
m_homeView = new HomeView;
|
||||
|
||||
if (!m_homeView->getParent()) {
|
||||
m_workspace->addView(m_homeView);
|
||||
m_tabsBar->selectTab(m_homeView);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showDevConsole()
|
||||
{
|
||||
if (!m_devConsoleView)
|
||||
m_devConsoleView = new DevConsoleView;
|
||||
|
||||
if (!m_devConsoleView->getParent()) {
|
||||
m_workspace->addView(m_devConsoleView);
|
||||
m_tabsBar->selectTab(m_devConsoleView);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setMode(Mode mode)
|
||||
{
|
||||
// Check if we already are in the given mode.
|
||||
@ -219,11 +249,8 @@ void MainWindow::popTimeline()
|
||||
|
||||
bool MainWindow::onProcessMessage(ui::Message* msg)
|
||||
{
|
||||
if (msg->type() == kOpenMessage) {
|
||||
m_homeView = new HomeView;
|
||||
m_workspace->addView(m_homeView);
|
||||
m_tabsBar->selectTab(m_homeView);
|
||||
}
|
||||
if (msg->type() == kOpenMessage)
|
||||
showHome();
|
||||
|
||||
return Window::onProcessMessage(msg);
|
||||
}
|
||||
@ -287,27 +314,16 @@ void MainWindow::clickTab(Tabs* tabs, TabView* tabView, ui::MouseButtons buttons
|
||||
}
|
||||
// Middle-button: close the sprite
|
||||
else if (buttons & kButtonMiddle) {
|
||||
Command* close_file_cmd =
|
||||
CommandsModule::instance()->getCommandByName(CommandId::CloseFile);
|
||||
|
||||
context->executeCommand(close_file_cmd, NULL);
|
||||
docView->onCloseView(m_workspace);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::clickClose(Tabs* tabs, TabView* tabView)
|
||||
{
|
||||
DocumentView* docView = dynamic_cast<DocumentView*>(tabView);
|
||||
if (!docView)
|
||||
return;
|
||||
|
||||
UIContext* context = UIContext::instance();
|
||||
context->setActiveView(docView);
|
||||
context->updateFlags();
|
||||
|
||||
Command* close_file_cmd =
|
||||
CommandsModule::instance()->getCommandByName(CommandId::CloseFile);
|
||||
|
||||
context->executeCommand(close_file_cmd, NULL);
|
||||
WorkspaceView* view = dynamic_cast<WorkspaceView*>(tabView);
|
||||
ASSERT(view);
|
||||
if (view)
|
||||
view->onCloseView(m_workspace);
|
||||
}
|
||||
|
||||
void MainWindow::mouseOverTab(Tabs* tabs, TabView* tabView)
|
||||
|
@ -20,6 +20,7 @@ namespace app {
|
||||
|
||||
class ColorBar;
|
||||
class ContextBar;
|
||||
class DevConsoleView;
|
||||
class HomeView;
|
||||
class INotificationDelegate;
|
||||
class MainMenuBar;
|
||||
@ -52,6 +53,8 @@ namespace app {
|
||||
void start();
|
||||
void reloadMenus();
|
||||
void showNotification(INotificationDelegate* del);
|
||||
void showHome();
|
||||
void showDevConsole();
|
||||
|
||||
Mode getMode() const { return m_mode; }
|
||||
void setMode(Mode mode);
|
||||
@ -87,6 +90,7 @@ namespace app {
|
||||
Workspace* m_workspace;
|
||||
PreviewEditorWindow* m_previewEditor;
|
||||
HomeView* m_homeView;
|
||||
DevConsoleView* m_devConsoleView;
|
||||
Notifications* m_notifications;
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace ui {
|
||||
}
|
||||
|
||||
namespace app {
|
||||
class Workspace;
|
||||
|
||||
class WorkspaceView {
|
||||
public:
|
||||
@ -27,6 +28,8 @@ namespace app {
|
||||
// the workspace. It can be used to copy/clone scroll position
|
||||
// from the original view.
|
||||
virtual void onClonedFrom(WorkspaceView* from) = 0;
|
||||
|
||||
virtual void onCloseView(Workspace* workspace) = 0;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
Loading…
Reference in New Issue
Block a user