Skip to content

Commit

Permalink
Trigger "New Sprite" double clicking tabs background (fix #912)
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Sep 28, 2017
1 parent 331e09b commit a674f5a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/app/ui/main_window.cpp
Expand Up @@ -430,6 +430,34 @@ void MainWindow::onContextMenuTab(Tabs* tabs, TabView* tabView)
view->onTabPopup(m_workspace);
}

void MainWindow::onTabsContainerDoubleClicked(Tabs* tabs)
{
WorkspacePanel* mainPanel = m_workspace->mainPanel();
WorkspaceView* oldActiveView = mainPanel->activeView();
app::Document* oldDoc = static_cast<app::Document*>(UIContext::instance()->activeDocument());

Command* command = CommandsModule::instance()->getCommandByName(CommandId::NewFile);
UIContext::instance()->executeCommand(command);

app::Document* newDoc = static_cast<app::Document*>(UIContext::instance()->activeDocument());
if (newDoc != oldDoc) {
WorkspacePanel* doubleClickedPanel =
static_cast<WorkspaceTabs*>(tabs)->panel();

// TODO move this code to workspace?
// Put the new sprite in the double-clicked tabs control
if (doubleClickedPanel != mainPanel) {
WorkspaceView* newView = m_workspace->activeView();
m_workspace->removeView(newView);
m_workspace->addViewToPanel(doubleClickedPanel, newView, false, -1);

// Re-activate the old view in the main panel
mainPanel->setActiveView(oldActiveView);
doubleClickedPanel->setActiveView(newView);
}
}
}

void MainWindow::onMouseOverTab(Tabs* tabs, TabView* tabView)
{
// Note: tabView can be NULL
Expand Down
1 change: 1 addition & 0 deletions src/app/ui/main_window.h
Expand Up @@ -89,6 +89,7 @@ namespace app {
void onCloseTab(Tabs* tabs, TabView* tabView) override;
void onCloneTab(Tabs* tabs, TabView* tabView, int pos) override;
void onContextMenuTab(Tabs* tabs, TabView* tabView) override;
void onTabsContainerDoubleClicked(Tabs* tabs) override;
void onMouseOverTab(Tabs* tabs, TabView* tabView) override;
DropViewPreviewResult onFloatingTab(Tabs* tabs, TabView* tabView, const gfx::Point& pos) override;
void onDockingTab(Tabs* tabs, TabView* tabView) override;
Expand Down
7 changes: 7 additions & 0 deletions src/app/ui/tabs.cpp
Expand Up @@ -440,6 +440,13 @@ bool Tabs::onProcessMessage(Message* msg)
updateMouseCursor();
return true;

case kDoubleClickMessage:
// When we double-click outside tabs (!m_hot), we trigger the
// double-click in tabs container to show the "New Sprite" dialog.
if (!m_hot && m_delegate)
m_delegate->onTabsContainerDoubleClicked(this);
return true;

}

return Widget::onProcessMessage(msg);
Expand Down
3 changes: 3 additions & 0 deletions src/app/ui/tabs.h
Expand Up @@ -89,6 +89,9 @@ namespace app {
// When the right-click is pressed in the tab.
virtual void onContextMenuTab(Tabs* tabs, TabView* tabView) = 0;

// When the tab bar background is double-clicked.
virtual void onTabsContainerDoubleClicked(Tabs* tabs) = 0;

// Called when the mouse is over a tab (the data can be null if the
// mouse just leave all tabs)
virtual void onMouseOverTab(Tabs* tabs, TabView* tabView) = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/app/ui/workspace.h
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
Expand Down Expand Up @@ -71,6 +71,8 @@ namespace app {
bool onClear(Context* ctx) override;
void onCancel(Context* ctx) override;

WorkspacePanel* mainPanel() { return &m_mainPanel; }

obs::signal<void()> ActiveViewChanged;

protected:
Expand Down

0 comments on commit a674f5a

Please sign in to comment.