mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 13:09:27 +00:00
Add Ctrl+Tab and Ctrl+Shift+Tab keys to switch between tabs.
This commit is contained in:
parent
ab333ff02b
commit
bc32ded8a5
@ -78,6 +78,9 @@
|
||||
<key command="PaletteEditor" shortcut="F4">
|
||||
<param name="switch" value="true" />
|
||||
</key>
|
||||
<!-- Tabs -->
|
||||
<key command="GotoNextTab" shortcut="Ctrl+Tab" />
|
||||
<key command="GotoPreviousTab" shortcut="Ctrl+Shift+Tab" />
|
||||
<!-- Others -->
|
||||
<key command="SwitchColors" shortcut="X" />
|
||||
<key command="ChangeColor" shortcut="9">
|
||||
|
@ -148,6 +148,7 @@ add_library(aseprite-library
|
||||
commands/cmd_frame_properties.cpp
|
||||
commands/cmd_goto_frame.cpp
|
||||
commands/cmd_goto_layer.cpp
|
||||
commands/cmd_goto_tab.cpp
|
||||
commands/cmd_grid.cpp
|
||||
commands/cmd_import_sprite_sheet.cpp
|
||||
commands/cmd_invert_mask.cpp
|
||||
|
89
src/commands/cmd_goto_tab.cpp
Normal file
89
src/commands/cmd_goto_tab.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "commands/command.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "widgets/tabs.h"
|
||||
|
||||
class GotoNextTabCommand : public Command
|
||||
{
|
||||
public:
|
||||
GotoNextTabCommand();
|
||||
Command* clone() { return new GotoNextTabCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context);
|
||||
};
|
||||
|
||||
GotoNextTabCommand::GotoNextTabCommand()
|
||||
: Command("GotoNextTab",
|
||||
"Goto Next Tab",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
void GotoNextTabCommand::onExecute(Context* context)
|
||||
{
|
||||
Tabs* tabs = app_get_tabsbar();
|
||||
tabs->selectNextTab();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// goto_previous_tab
|
||||
|
||||
class GotoPreviousTabCommand : public Command
|
||||
|
||||
{
|
||||
public:
|
||||
GotoPreviousTabCommand();
|
||||
Command* clone() { return new GotoPreviousTabCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context);
|
||||
};
|
||||
|
||||
GotoPreviousTabCommand::GotoPreviousTabCommand()
|
||||
: Command("GotoPreviousTab",
|
||||
"Goto Previous tab",
|
||||
CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
void GotoPreviousTabCommand::onExecute(Context* context)
|
||||
{
|
||||
Tabs* tabs = app_get_tabsbar();
|
||||
tabs->selectPreviousTab();
|
||||
|
||||
void* data = tabs->getSelectedTab();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CommandFactory
|
||||
|
||||
Command* CommandFactory::createGotoNextTabCommand()
|
||||
{
|
||||
return new GotoNextTabCommand;
|
||||
}
|
||||
|
||||
Command* CommandFactory::createGotoPreviousTabCommand()
|
||||
{
|
||||
return new GotoPreviousTabCommand;
|
||||
}
|
@ -56,6 +56,8 @@ FOR_EACH_COMMAND(GotoNextFrame)
|
||||
FOR_EACH_COMMAND(GotoNextLayer)
|
||||
FOR_EACH_COMMAND(GotoPreviousFrame)
|
||||
FOR_EACH_COMMAND(GotoPreviousLayer)
|
||||
FOR_EACH_COMMAND(GotoNextTab)
|
||||
FOR_EACH_COMMAND(GotoPreviousTab)
|
||||
FOR_EACH_COMMAND(GridSettings)
|
||||
FOR_EACH_COMMAND(ImportSpriteSheet)
|
||||
FOR_EACH_COMMAND(InvertColor)
|
||||
|
@ -96,7 +96,7 @@ Tabs::~Tabs()
|
||||
stopAni();
|
||||
|
||||
// Remove all tabs
|
||||
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
||||
TabsListIterator it, end = m_list_of_tabs.end();
|
||||
for (it = m_list_of_tabs.begin(); it != end; ++it)
|
||||
delete *it; // tab
|
||||
m_list_of_tabs.clear();
|
||||
@ -129,7 +129,7 @@ void Tabs::removeTab(void* data)
|
||||
if (m_hot == tab) m_hot = NULL;
|
||||
if (m_selected == tab) m_selected = NULL;
|
||||
|
||||
std::vector<Tab*>::iterator it =
|
||||
TabsListIterator it =
|
||||
std::find(m_list_of_tabs.begin(), m_list_of_tabs.end(), tab);
|
||||
|
||||
ASSERT(it != m_list_of_tabs.end() && "Removing a tab that is not part of the Tabs widget");
|
||||
@ -176,11 +176,47 @@ void Tabs::setTabText(const char* text, void* data)
|
||||
void Tabs::selectTab(void* data)
|
||||
{
|
||||
Tab *tab = getTabByData(data);
|
||||
if (tab != NULL)
|
||||
selectTabInternal(tab);
|
||||
}
|
||||
|
||||
if (tab != NULL) {
|
||||
m_selected = tab;
|
||||
makeTabVisible(tab);
|
||||
invalidate();
|
||||
void Tabs::selectNextTab()
|
||||
{
|
||||
TabsListIterator currentTabIt = getTabIteratorByData(m_selected->data);
|
||||
TabsListIterator it = currentTabIt;
|
||||
if (it != m_list_of_tabs.end()) {
|
||||
// If we are at the end of the list, cycle to the first tab.
|
||||
if (it == --m_list_of_tabs.end())
|
||||
it = m_list_of_tabs.begin();
|
||||
// Go to next tab.
|
||||
else
|
||||
++it;
|
||||
|
||||
if (it != currentTabIt) {
|
||||
selectTabInternal(*it);
|
||||
if (m_delegate)
|
||||
m_delegate->clickTab(this, m_selected->data, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tabs::selectPreviousTab()
|
||||
{
|
||||
TabsListIterator currentTabIt = getTabIteratorByData(m_selected->data);
|
||||
TabsListIterator it = currentTabIt;
|
||||
if (it != m_list_of_tabs.end()) {
|
||||
// If we are at the beginning of the list, cycle to the last tab.
|
||||
if (it == m_list_of_tabs.begin())
|
||||
it = --m_list_of_tabs.end();
|
||||
// Go to previous tab.
|
||||
else
|
||||
--it;
|
||||
|
||||
if (it != currentTabIt) {
|
||||
selectTabInternal(*it);
|
||||
if (m_delegate)
|
||||
m_delegate->clickTab(this, m_selected->data, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +265,7 @@ bool Tabs::onProcessMessage(Message* msg)
|
||||
box->x1 = box->x2;
|
||||
|
||||
// For each tab...
|
||||
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
||||
TabsListIterator it, end = m_list_of_tabs.end();
|
||||
|
||||
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
||||
Tab* tab = *it;
|
||||
@ -390,7 +426,7 @@ bool Tabs::onProcessMessage(Message* msg)
|
||||
m_button_right->setBgColor(theme->get_tab_selected_face_color());
|
||||
}
|
||||
else if (msg->signal.num == JI_SIGNAL_SET_FONT) {
|
||||
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
||||
TabsListIterator it, end = m_list_of_tabs.end();
|
||||
|
||||
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
||||
Tab* tab = *it;
|
||||
@ -408,6 +444,13 @@ bool Tabs::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Tabs::selectTabInternal(Tab* tab)
|
||||
{
|
||||
m_selected = tab;
|
||||
makeTabVisible(tab);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void Tabs::drawTab(BITMAP* bmp, JRect box, Tab* tab, int y_delta, bool selected)
|
||||
{
|
||||
// Is the tab outside the bounds of the widget?
|
||||
@ -461,22 +504,30 @@ void Tabs::drawTab(BITMAP* bmp, JRect box, Tab* tab, int y_delta, bool selected)
|
||||
#endif
|
||||
}
|
||||
|
||||
Tabs::Tab* Tabs::getTabByData(void* data)
|
||||
Tabs::TabsListIterator Tabs::getTabIteratorByData(void* data)
|
||||
{
|
||||
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
||||
TabsListIterator it, end = m_list_of_tabs.end();
|
||||
|
||||
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
||||
Tab* tab = *it;
|
||||
if (tab->data == data)
|
||||
return tab;
|
||||
if ((*it)->data == data)
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return it;
|
||||
}
|
||||
|
||||
Tabs::Tab* Tabs::getTabByData(void* data)
|
||||
{
|
||||
TabsListIterator it = getTabIteratorByData(data);
|
||||
if (it != m_list_of_tabs.end())
|
||||
return *it;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Tabs::getMaxScrollX()
|
||||
{
|
||||
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
||||
TabsListIterator it, end = m_list_of_tabs.end();
|
||||
int x = 0;
|
||||
|
||||
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
||||
@ -496,7 +547,7 @@ void Tabs::makeTabVisible(Tab* make_visible_this_tab)
|
||||
{
|
||||
int x = 0;
|
||||
int extra_x = getMaxScrollX() > 0 ? ARROW_W*2: 0;
|
||||
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
||||
TabsListIterator it, end = m_list_of_tabs.end();
|
||||
|
||||
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
||||
Tab* tab = *it;
|
||||
@ -566,7 +617,7 @@ void Tabs::calculateHot()
|
||||
JRect rect = jwidget_get_rect(this);
|
||||
JRect box = jrect_new(rect->x1-m_scrollX, rect->y1, 0, rect->y2-1);
|
||||
Tab *hot = NULL;
|
||||
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
||||
TabsListIterator it, end = m_list_of_tabs.end();
|
||||
|
||||
// For each tab
|
||||
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
||||
|
@ -63,6 +63,9 @@ class Tabs : public Widget
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::vector<Tab*> TabsList;
|
||||
typedef TabsList::iterator TabsListIterator;
|
||||
|
||||
enum Ani { ANI_NONE,
|
||||
ANI_ADDING_TAB,
|
||||
ANI_REMOVING_TAB,
|
||||
@ -79,6 +82,8 @@ public:
|
||||
void setTabText(const char* text, void* data);
|
||||
|
||||
void selectTab(void* data);
|
||||
void selectNextTab();
|
||||
void selectPreviousTab();
|
||||
void* getSelectedTab();
|
||||
|
||||
void startScrolling();
|
||||
@ -91,7 +96,9 @@ private:
|
||||
void startAni(Ani ani);
|
||||
void stopAni();
|
||||
|
||||
void selectTabInternal(Tab* tab);
|
||||
void drawTab(BITMAP* bmp, JRect box, Tab* tab, int y_delta, bool selected);
|
||||
TabsListIterator getTabIteratorByData(void* data);
|
||||
Tab* getTabByData(void* data);
|
||||
int getMaxScrollX();
|
||||
void makeTabVisible(Tab* tab);
|
||||
@ -99,7 +106,7 @@ private:
|
||||
void calculateHot();
|
||||
int calcTabWidth(Tab* tab);
|
||||
|
||||
std::vector<Tab*> m_list_of_tabs;
|
||||
TabsList m_list_of_tabs;
|
||||
Tab *m_hot;
|
||||
Tab *m_selected;
|
||||
int m_scrollX;
|
||||
|
Loading…
Reference in New Issue
Block a user