mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-21 03:40:57 +00:00
Use ui::ListItem in ui::ComboBox widget
This commit is contained in:
parent
1d76e0d545
commit
b45dcf7d0d
@ -108,7 +108,7 @@ protected:
|
|||||||
void onSheetTypeChange()
|
void onSheetTypeChange()
|
||||||
{
|
{
|
||||||
bool state = false;
|
bool state = false;
|
||||||
switch (m_sheetType.getSelectedItem()) {
|
switch (m_sheetType.getSelectedItemIndex()) {
|
||||||
case Matrix:
|
case Matrix:
|
||||||
state = true;
|
state = true;
|
||||||
break;
|
break;
|
||||||
@ -130,7 +130,7 @@ protected:
|
|||||||
FrameNumber nframes = sprite->getTotalFrames();
|
FrameNumber nframes = sprite->getTotalFrames();
|
||||||
int columns;
|
int columns;
|
||||||
|
|
||||||
switch (m_sheetType.getSelectedItem()) {
|
switch (m_sheetType.getSelectedItemIndex()) {
|
||||||
case HorizontalStrip:
|
case HorizontalStrip:
|
||||||
columns = nframes;
|
columns = nframes;
|
||||||
break;
|
break;
|
||||||
@ -219,7 +219,7 @@ protected:
|
|||||||
bool undo = false;
|
bool undo = false;
|
||||||
|
|
||||||
// Do the "Export Action"
|
// Do the "Export Action"
|
||||||
switch (m_exportAction.getSelectedItem()) {
|
switch (m_exportAction.getSelectedItemIndex()) {
|
||||||
|
|
||||||
case SaveCopyAs:
|
case SaveCopyAs:
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ void OptionsCommand::onExecute(Context* context)
|
|||||||
m_checked_bg->addItem("8x8");
|
m_checked_bg->addItem("8x8");
|
||||||
m_checked_bg->addItem("4x4");
|
m_checked_bg->addItem("4x4");
|
||||||
m_checked_bg->addItem("2x2");
|
m_checked_bg->addItem("2x2");
|
||||||
m_checked_bg->setSelectedItem((int)RenderEngine::getCheckedBgType());
|
m_checked_bg->setSelectedItemIndex((int)RenderEngine::getCheckedBgType());
|
||||||
|
|
||||||
// Zoom checked background
|
// Zoom checked background
|
||||||
if (RenderEngine::getCheckedBgZoom())
|
if (RenderEngine::getCheckedBgZoom())
|
||||||
@ -154,7 +154,7 @@ void OptionsCommand::onExecute(Context* context)
|
|||||||
set_config_bool("Options", "MoveClick2", move_click2->isSelected());
|
set_config_bool("Options", "MoveClick2", move_click2->isSelected());
|
||||||
set_config_bool("Options", "DrawClick2", draw_click2->isSelected());
|
set_config_bool("Options", "DrawClick2", draw_click2->isSelected());
|
||||||
|
|
||||||
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)m_checked_bg->getSelectedItem());
|
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)m_checked_bg->getSelectedItemIndex());
|
||||||
RenderEngine::setCheckedBgZoom(m_checked_bg_zoom->isSelected());
|
RenderEngine::setCheckedBgZoom(m_checked_bg_zoom->isSelected());
|
||||||
RenderEngine::setCheckedBgColor1(m_checked_bg_color1->getColor());
|
RenderEngine::setCheckedBgColor1(m_checked_bg_color1->getColor());
|
||||||
RenderEngine::setCheckedBgColor2(m_checked_bg_color2->getColor());
|
RenderEngine::setCheckedBgColor2(m_checked_bg_color2->getColor());
|
||||||
|
@ -221,7 +221,7 @@ void SpriteSizeCommand::onExecute(Context* context)
|
|||||||
|
|
||||||
method->addItem("Nearest-neighbor");
|
method->addItem("Nearest-neighbor");
|
||||||
method->addItem("Bilinear");
|
method->addItem("Bilinear");
|
||||||
method->setSelectedItem(get_config_int("SpriteSize", "Method", RESIZE_METHOD_NEAREST_NEIGHBOR));
|
method->setSelectedItemIndex(get_config_int("SpriteSize", "Method", RESIZE_METHOD_NEAREST_NEIGHBOR));
|
||||||
|
|
||||||
window->remapWindow();
|
window->remapWindow();
|
||||||
window->centerWindow();
|
window->centerWindow();
|
||||||
@ -235,7 +235,7 @@ void SpriteSizeCommand::onExecute(Context* context)
|
|||||||
int new_width = m_widthPx->getTextInt();
|
int new_width = m_widthPx->getTextInt();
|
||||||
int new_height = m_heightPx->getTextInt();
|
int new_height = m_heightPx->getTextInt();
|
||||||
ResizeMethod resize_method =
|
ResizeMethod resize_method =
|
||||||
(ResizeMethod)method->getSelectedItem();
|
(ResizeMethod)method->getSelectedItemIndex();
|
||||||
|
|
||||||
set_config_int("SpriteSize", "Method", resize_method);
|
set_config_int("SpriteSize", "Method", resize_method);
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "gfx/size.h"
|
#include "gfx/size.h"
|
||||||
#include "ui/gui.h"
|
#include "ui/gui.h"
|
||||||
#include "ui/listitem.h"
|
|
||||||
#include "ui/preferred_size_event.h"
|
|
||||||
|
|
||||||
#include <allegro.h>
|
#include <allegro.h>
|
||||||
|
|
||||||
@ -49,7 +47,22 @@ class ComboBoxListBox : public ListBox
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ComboBoxListBox(ComboBox* comboBox)
|
ComboBoxListBox(ComboBox* comboBox)
|
||||||
: m_comboBox(comboBox) {
|
: m_comboBox(comboBox)
|
||||||
|
{
|
||||||
|
for (ComboBox::ListItems::iterator
|
||||||
|
it = comboBox->begin(), end = comboBox->end(); it != end; ++it)
|
||||||
|
addChild(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void clean()
|
||||||
|
{
|
||||||
|
// Remove all added items so ~Widget() don't delete them.
|
||||||
|
while (getLastChild())
|
||||||
|
removeChild(getLastChild());
|
||||||
|
|
||||||
|
ASSERT(getChildren().empty());
|
||||||
|
|
||||||
|
selectChild(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -64,14 +77,6 @@ private:
|
|||||||
ComboBox* m_comboBox;
|
ComboBox* m_comboBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ComboBox::Item
|
|
||||||
{
|
|
||||||
std::string text;
|
|
||||||
void* data;
|
|
||||||
|
|
||||||
Item() : data(NULL) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
ComboBox::ComboBox()
|
ComboBox::ComboBox()
|
||||||
: Widget(JI_COMBOBOX)
|
: Widget(JI_COMBOBOX)
|
||||||
{
|
{
|
||||||
@ -144,37 +149,55 @@ bool ComboBox::isCaseSensitive()
|
|||||||
return m_casesensitive;
|
return m_casesensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComboBox::addItem(const std::string& text)
|
int ComboBox::addItem(ListItem* item)
|
||||||
{
|
{
|
||||||
bool sel_first = m_items.empty();
|
bool sel_first = m_items.empty();
|
||||||
Item* item = new Item();
|
|
||||||
item->text = text;
|
|
||||||
|
|
||||||
m_items.push_back(item);
|
m_items.push_back(item);
|
||||||
|
|
||||||
if (sel_first)
|
if (sel_first)
|
||||||
setSelectedItem(0);
|
setSelectedItemIndex(0);
|
||||||
|
|
||||||
return m_items.size()-1;
|
return m_items.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComboBox::insertItem(int itemIndex, const std::string& text)
|
int ComboBox::addItem(const char* text)
|
||||||
|
{
|
||||||
|
return addItem(new ListItem(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboBox::insertItem(int itemIndex, ListItem* item)
|
||||||
{
|
{
|
||||||
bool sel_first = m_items.empty();
|
bool sel_first = m_items.empty();
|
||||||
Item* item = new Item();
|
|
||||||
item->text = text;
|
|
||||||
|
|
||||||
m_items.insert(m_items.begin() + itemIndex, item);
|
m_items.insert(m_items.begin() + itemIndex, item);
|
||||||
|
|
||||||
if (sel_first)
|
if (sel_first)
|
||||||
setSelectedItem(0);
|
setSelectedItemIndex(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboBox::insertItem(int itemIndex, const char* text)
|
||||||
|
{
|
||||||
|
insertItem(itemIndex, new ListItem(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboBox::removeItem(ListItem* item)
|
||||||
|
{
|
||||||
|
ListItems::iterator it = std::find(m_items.begin(), m_items.end(), item);
|
||||||
|
|
||||||
|
ASSERT(it != m_items.end());
|
||||||
|
|
||||||
|
if (it != m_items.end())
|
||||||
|
m_items.erase(it);
|
||||||
|
|
||||||
|
// Do not delete the given "item"
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComboBox::removeItem(int itemIndex)
|
void ComboBox::removeItem(int itemIndex)
|
||||||
{
|
{
|
||||||
ASSERT(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
ASSERT(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
||||||
|
|
||||||
Item* item = m_items[itemIndex];
|
ListItem* item = m_items[itemIndex];
|
||||||
|
|
||||||
m_items.erase(m_items.begin() + itemIndex);
|
m_items.erase(m_items.begin() + itemIndex);
|
||||||
delete item;
|
delete item;
|
||||||
@ -182,46 +205,55 @@ void ComboBox::removeItem(int itemIndex)
|
|||||||
|
|
||||||
void ComboBox::removeAllItems()
|
void ComboBox::removeAllItems()
|
||||||
{
|
{
|
||||||
std::vector<Item*>::iterator it, end = m_items.end();
|
ListItems::iterator it, end = m_items.end();
|
||||||
for (it = m_items.begin(); it != end; ++it)
|
for (it = m_items.begin(); it != end; ++it)
|
||||||
delete *it;
|
delete *it;
|
||||||
|
|
||||||
m_items.clear();
|
m_items.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComboBox::getItemCount()
|
int ComboBox::getItemCount() const
|
||||||
{
|
{
|
||||||
return m_items.size();
|
return m_items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ComboBox::getItemText(int itemIndex)
|
ListItem* ComboBox::getItem(int itemIndex)
|
||||||
{
|
{
|
||||||
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
||||||
Item* item = m_items[itemIndex];
|
return m_items[itemIndex];
|
||||||
return item->text;
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* ComboBox::getItemText(int itemIndex) const
|
||||||
|
{
|
||||||
|
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
||||||
|
ListItem* item = m_items[itemIndex];
|
||||||
|
return item->getText();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComboBox::setItemText(int itemIndex, const std::string& text)
|
void ComboBox::setItemText(int itemIndex, const char* text)
|
||||||
{
|
{
|
||||||
ASSERT(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
ASSERT(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
||||||
|
|
||||||
Item* item = m_items[itemIndex];
|
ListItem* item = m_items[itemIndex];
|
||||||
item->text = text;
|
item->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComboBox::findItemIndex(const std::string& text)
|
int ComboBox::findItemIndex(const char* text)
|
||||||
{
|
{
|
||||||
int itemIndex = 0;
|
int itemIndex = 0;
|
||||||
|
|
||||||
std::vector<Item*>::iterator it, end = m_items.end();
|
ListItems::iterator it, end = m_items.end();
|
||||||
for (it = m_items.begin(); it != end; ++it) {
|
for (it = m_items.begin(); it != end; ++it) {
|
||||||
Item* item = *it;
|
ListItem* item = *it;
|
||||||
|
|
||||||
if ((m_casesensitive && ustrcmp(item->text.c_str(), text.c_str()) == 0) ||
|
if ((m_casesensitive && ustrcmp(item->getText(), text) == 0) ||
|
||||||
(!m_casesensitive && ustricmp(item->text.c_str(), text.c_str()) == 0)) {
|
(!m_casesensitive && ustricmp(item->getText(), text) == 0)) {
|
||||||
return itemIndex;
|
return itemIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,40 +263,37 @@ int ComboBox::findItemIndex(const std::string& text)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComboBox::getSelectedItem()
|
ListItem* ComboBox::getSelectedItem() const
|
||||||
{
|
{
|
||||||
return !m_items.empty() ? m_selected: -1;
|
return (!m_items.empty() ? m_items[m_selected]: NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComboBox::setSelectedItem(int itemIndex)
|
void ComboBox::setSelectedItem(ListItem* item)
|
||||||
|
{
|
||||||
|
ListItems::iterator it = std::find(m_items.begin(), m_items.end(), item);
|
||||||
|
|
||||||
|
ASSERT(it != m_items.end());
|
||||||
|
|
||||||
|
if (it != m_items.end())
|
||||||
|
setSelectedItemIndex(std::distance(m_items.begin(), it));
|
||||||
|
}
|
||||||
|
|
||||||
|
int ComboBox::getSelectedItemIndex() const
|
||||||
|
{
|
||||||
|
return (!m_items.empty() ? m_selected: -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboBox::setSelectedItemIndex(int itemIndex)
|
||||||
{
|
{
|
||||||
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
||||||
m_selected = itemIndex;
|
m_selected = itemIndex;
|
||||||
|
|
||||||
std::vector<Item*>::iterator it = m_items.begin() + itemIndex;
|
ListItems::iterator it = m_items.begin() + itemIndex;
|
||||||
Item* item = *it;
|
ListItem* item = *it;
|
||||||
m_entry->setText(item->text.c_str());
|
m_entry->setText(item->getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* ComboBox::getItemData(int itemIndex)
|
|
||||||
{
|
|
||||||
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
|
||||||
Item* item = m_items[itemIndex];
|
|
||||||
return item->data;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ComboBox::setItemData(int itemIndex, void* data)
|
|
||||||
{
|
|
||||||
ASSERT(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
|
||||||
|
|
||||||
Item* item = m_items[itemIndex];
|
|
||||||
item->data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entry* ComboBox::getEntryWidget()
|
Entry* ComboBox::getEntryWidget()
|
||||||
{
|
{
|
||||||
return m_entry;
|
return m_entry;
|
||||||
@ -329,11 +358,11 @@ void ComboBox::onPreferredSize(PreferredSizeEvent& ev)
|
|||||||
Size entrySize = m_entry->getPreferredSize();
|
Size entrySize = m_entry->getPreferredSize();
|
||||||
|
|
||||||
// Get the text-length of every item and put in 'w' the maximum value
|
// Get the text-length of every item and put in 'w' the maximum value
|
||||||
std::vector<Item*>::iterator it, end = m_items.end();
|
ListItems::iterator it, end = m_items.end();
|
||||||
for (it = m_items.begin(); it != end; ++it) {
|
for (it = m_items.begin(); it != end; ++it) {
|
||||||
int item_w =
|
int item_w =
|
||||||
2*jguiscale()+
|
2*jguiscale()+
|
||||||
text_length(this->getFont(), (*it)->text.c_str())+
|
text_length(this->getFont(), (*it)->getText())+
|
||||||
10*jguiscale();
|
10*jguiscale();
|
||||||
|
|
||||||
reqSize.w = MAX(reqSize.w, item_w);
|
reqSize.w = MAX(reqSize.w, item_w);
|
||||||
@ -399,7 +428,7 @@ bool ComboBoxListBox::onProcessMessage(Message* msg)
|
|||||||
|
|
||||||
case JM_BUTTONRELEASED:
|
case JM_BUTTONRELEASED:
|
||||||
{
|
{
|
||||||
int index = m_comboBox->getSelectedItem();
|
int index = m_comboBox->getSelectedItemIndex();
|
||||||
if (isValidItem(index))
|
if (isValidItem(index))
|
||||||
m_comboBox->onChange();
|
m_comboBox->onChange();
|
||||||
|
|
||||||
@ -428,7 +457,7 @@ void ComboBoxListBox::onChangeSelectedItem()
|
|||||||
|
|
||||||
int index = getSelectedIndex();
|
int index = getSelectedIndex();
|
||||||
if (isValidItem(index))
|
if (isValidItem(index))
|
||||||
m_comboBox->setSelectedItem(index);
|
m_comboBox->setSelectedItemIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the mouse is clicked we switch the visibility-status of the list-box
|
// When the mouse is clicked we switch the visibility-status of the list-box
|
||||||
@ -443,13 +472,6 @@ void ComboBox::openListBox()
|
|||||||
m_window = new Window(false, NULL);
|
m_window = new Window(false, NULL);
|
||||||
View* view = new View();
|
View* view = new View();
|
||||||
m_listbox = new ComboBoxListBox(this);
|
m_listbox = new ComboBoxListBox(this);
|
||||||
|
|
||||||
std::vector<Item*>::iterator it, end = m_items.end();
|
|
||||||
for (it = m_items.begin(); it != end; ++it) {
|
|
||||||
Item* item = *it;
|
|
||||||
m_listbox->addChild(new ListItem(item->text.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_window->setOnTop(true);
|
m_window->setOnTop(true);
|
||||||
jwidget_noborders(m_window);
|
jwidget_noborders(m_window);
|
||||||
|
|
||||||
@ -483,6 +505,8 @@ void ComboBox::openListBox()
|
|||||||
void ComboBox::closeListBox()
|
void ComboBox::closeListBox()
|
||||||
{
|
{
|
||||||
if (m_window) {
|
if (m_window) {
|
||||||
|
m_listbox->clean();
|
||||||
|
|
||||||
m_window->closeWindow(this);
|
m_window->closeWindow(this);
|
||||||
delete m_window; // window, frame
|
delete m_window; // window, frame
|
||||||
m_window = NULL;
|
m_window = NULL;
|
||||||
|
@ -19,6 +19,7 @@ namespace ui {
|
|||||||
class Button;
|
class Button;
|
||||||
class Entry;
|
class Entry;
|
||||||
class ListBox;
|
class ListBox;
|
||||||
|
class ListItem;
|
||||||
class Window;
|
class Window;
|
||||||
|
|
||||||
class ComboBoxListBox;
|
class ComboBoxListBox;
|
||||||
@ -28,9 +29,14 @@ namespace ui {
|
|||||||
friend class ComboBoxListBox;
|
friend class ComboBoxListBox;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef std::vector<ListItem*> ListItems;
|
||||||
|
|
||||||
ComboBox();
|
ComboBox();
|
||||||
~ComboBox();
|
~ComboBox();
|
||||||
|
|
||||||
|
ListItems::iterator begin() { return m_items.begin(); }
|
||||||
|
ListItems::iterator end() { return m_items.end(); }
|
||||||
|
|
||||||
void setEditable(bool state);
|
void setEditable(bool state);
|
||||||
void setClickOpen(bool state);
|
void setClickOpen(bool state);
|
||||||
void setCaseSensitive(bool state);
|
void setCaseSensitive(bool state);
|
||||||
@ -39,22 +45,31 @@ namespace ui {
|
|||||||
bool isClickOpen();
|
bool isClickOpen();
|
||||||
bool isCaseSensitive();
|
bool isCaseSensitive();
|
||||||
|
|
||||||
int addItem(const std::string& text);
|
int addItem(ListItem* item);
|
||||||
void insertItem(int itemIndex, const std::string& text);
|
int addItem(const char* text);
|
||||||
|
void insertItem(int itemIndex, ListItem* item);
|
||||||
|
void insertItem(int itemIndex, const char* text);
|
||||||
|
|
||||||
|
// Removes the given item (you must delete it).
|
||||||
|
void removeItem(ListItem* item);
|
||||||
|
|
||||||
|
// Removes and deletes the given item.
|
||||||
void removeItem(int itemIndex);
|
void removeItem(int itemIndex);
|
||||||
|
|
||||||
void removeAllItems();
|
void removeAllItems();
|
||||||
|
|
||||||
int getItemCount();
|
int getItemCount() const;
|
||||||
|
|
||||||
std::string getItemText(int itemIndex);
|
ListItem* getItem(int itemIndex);
|
||||||
void setItemText(int itemIndex, const std::string& text);
|
const char* getItemText(int itemIndex) const;
|
||||||
int findItemIndex(const std::string& text);
|
void setItemText(int itemIndex, const char* text);
|
||||||
|
int findItemIndex(const char* text);
|
||||||
|
|
||||||
int getSelectedItem();
|
ListItem* getSelectedItem() const;
|
||||||
void setSelectedItem(int itemIndex);
|
void setSelectedItem(ListItem* item);
|
||||||
|
|
||||||
void* getItemData(int itemIndex);
|
int getSelectedItemIndex() const;
|
||||||
void setItemData(int itemIndex, void* data);
|
void setSelectedItemIndex(int itemIndex);
|
||||||
|
|
||||||
Entry* getEntryWidget();
|
Entry* getEntryWidget();
|
||||||
Button* getButtonWidget();
|
Button* getButtonWidget();
|
||||||
@ -75,13 +90,11 @@ namespace ui {
|
|||||||
private:
|
private:
|
||||||
void onButtonClick(Event& ev);
|
void onButtonClick(Event& ev);
|
||||||
|
|
||||||
struct Item;
|
|
||||||
|
|
||||||
Entry* m_entry;
|
Entry* m_entry;
|
||||||
Button* m_button;
|
Button* m_button;
|
||||||
Window* m_window;
|
Window* m_window;
|
||||||
ListBox* m_listbox;
|
ComboBoxListBox* m_listbox;
|
||||||
std::vector<Item*> m_items;
|
ListItems m_items;
|
||||||
int m_selected;
|
int m_selected;
|
||||||
bool m_editable : 1;
|
bool m_editable : 1;
|
||||||
bool m_clickopen : 1;
|
bool m_clickopen : 1;
|
||||||
|
@ -194,10 +194,13 @@ namespace ui {
|
|||||||
// Returns a list of children.
|
// Returns a list of children.
|
||||||
const WidgetsList& getChildren() const { return m_children; }
|
const WidgetsList& getChildren() const { return m_children; }
|
||||||
|
|
||||||
// Returns the first child or NULL if it doesn't exist.
|
// Returns the first/last child or NULL if it doesn't exist.
|
||||||
Widget* getFirstChild() {
|
Widget* getFirstChild() {
|
||||||
return (!m_children.empty() ? m_children.front(): NULL);
|
return (!m_children.empty() ? m_children.front(): NULL);
|
||||||
}
|
}
|
||||||
|
Widget* getLastChild() {
|
||||||
|
return (!m_children.empty() ? m_children.back(): NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the next or previous siblings.
|
// Returns the next or previous siblings.
|
||||||
Widget* getNextSibling();
|
Widget* getNextSibling();
|
||||||
|
@ -258,7 +258,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setInkType(InkType inkType) {
|
void setInkType(InkType inkType) {
|
||||||
setSelectedItem((int)inkType);
|
setSelectedItemIndex((int)inkType);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -268,7 +268,7 @@ protected:
|
|||||||
ISettings* settings = UIContext::instance()->getSettings();
|
ISettings* settings = UIContext::instance()->getSettings();
|
||||||
Tool* currentTool = settings->getCurrentTool();
|
Tool* currentTool = settings->getCurrentTool();
|
||||||
settings->getToolSettings(currentTool)
|
settings->getToolSettings(currentTool)
|
||||||
->setInkType((InkType)getSelectedItem());
|
->setInkType((InkType)getSelectedItemIndex());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -166,6 +166,30 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CustomFileNameItem : public ListItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CustomFileNameItem(const char* text, IFileItem* fileItem)
|
||||||
|
: ListItem(text)
|
||||||
|
, m_fileItem(fileItem)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
IFileItem* getFileItem() { return m_fileItem; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
IFileItem* m_fileItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CustomFolderNameItem : public ListItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CustomFolderNameItem(const char* text)
|
||||||
|
: ListItem(text)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
FileSelector::FileSelector()
|
FileSelector::FileSelector()
|
||||||
: Window(false, "")
|
: Window(false, "")
|
||||||
{
|
{
|
||||||
@ -422,7 +446,7 @@ again:
|
|||||||
// selected in the filetype combo-box
|
// selected in the filetype combo-box
|
||||||
if (base::get_file_extension(buf).empty()) {
|
if (base::get_file_extension(buf).empty()) {
|
||||||
buf += '.';
|
buf += '.';
|
||||||
buf += m_fileType->getItemText(m_fileType->getSelectedItem());
|
buf += m_fileType->getItemText(m_fileType->getSelectedItemIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
// duplicate the buffer to return a new string
|
// duplicate the buffer to return a new string
|
||||||
@ -470,8 +494,7 @@ void FileSelector::updateLocation()
|
|||||||
buf += fileItem->getDisplayName();
|
buf += fileItem->getDisplayName();
|
||||||
|
|
||||||
// Add the new location to the combo-box
|
// Add the new location to the combo-box
|
||||||
newItem = m_location->addItem(buf.c_str());
|
m_location->addItem(new CustomFileNameItem(buf.c_str(), fileItem));
|
||||||
m_location->setItemData(newItem, fileItem);
|
|
||||||
|
|
||||||
if (fileItem == currentFolder)
|
if (fileItem == currentFolder)
|
||||||
selected_index = level;
|
selected_index = level;
|
||||||
@ -487,12 +510,12 @@ void FileSelector::updateLocation()
|
|||||||
RecentFiles::const_iterator it = App::instance()->getRecentFiles()->paths_begin();
|
RecentFiles::const_iterator it = App::instance()->getRecentFiles()->paths_begin();
|
||||||
RecentFiles::const_iterator end = App::instance()->getRecentFiles()->paths_end();
|
RecentFiles::const_iterator end = App::instance()->getRecentFiles()->paths_end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
m_location->addItem(*it);
|
m_location->addItem(new CustomFolderNameItem(it->c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select the location
|
// Select the location
|
||||||
{
|
{
|
||||||
m_location->setSelectedItem(selected_index);
|
m_location->setSelectedItemIndex(selected_index);
|
||||||
m_location->getEntryWidget()->setText(currentFolder->getDisplayName().c_str());
|
m_location->getEntryWidget()->setText(currentFolder->getDisplayName().c_str());
|
||||||
m_location->getEntryWidget()->deselectText();
|
m_location->getEntryWidget()->deselectText();
|
||||||
}
|
}
|
||||||
@ -549,7 +572,7 @@ void FileSelector::selectFileTypeFromFileName()
|
|||||||
if (p && *p != 0) {
|
if (p && *p != 0) {
|
||||||
ustrcpy(buf, get_extension(filename));
|
ustrcpy(buf, get_extension(filename));
|
||||||
ustrlwr(buf);
|
ustrlwr(buf);
|
||||||
m_fileType->setSelectedItem(m_fileType->findItemIndex(buf));
|
m_fileType->setSelectedItemIndex(m_fileType->findItemIndex(buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,14 +618,19 @@ void FileSelector::onLocationChange()
|
|||||||
{
|
{
|
||||||
// When the user change the location we have to set the
|
// When the user change the location we have to set the
|
||||||
// current-folder in the 'fileview' widget
|
// current-folder in the 'fileview' widget
|
||||||
int itemIndex = m_location->getSelectedItem();
|
int itemIndex = m_location->getSelectedItemIndex();
|
||||||
IFileItem* fileItem = reinterpret_cast<IFileItem*>(m_location->getItemData(itemIndex));
|
CustomFileNameItem* comboFileItem = dynamic_cast<CustomFileNameItem*>(m_location->getSelectedItem());
|
||||||
|
IFileItem* fileItem = (comboFileItem != NULL ? comboFileItem->getFileItem(): NULL);
|
||||||
|
|
||||||
// Maybe the user selected a recent file path
|
// Maybe the user selected a recent file path
|
||||||
if (fileItem == NULL) {
|
if (fileItem == NULL) {
|
||||||
base::string path = m_location->getItemText(itemIndex);
|
CustomFolderNameItem* comboFolderItem =
|
||||||
if (!path.empty())
|
dynamic_cast<CustomFolderNameItem*>(m_location->getSelectedItem());
|
||||||
|
|
||||||
|
if (comboFolderItem != NULL) {
|
||||||
|
base::string path = comboFolderItem->getText();
|
||||||
fileItem = FileSystemModule::instance()->getFileItemFromPath(path);
|
fileItem = FileSystemModule::instance()->getFileItemFromPath(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileItem != NULL) {
|
if (fileItem != NULL) {
|
||||||
@ -618,7 +646,7 @@ void FileSelector::onLocationChange()
|
|||||||
// change the file-extension in the 'filename' entry widget
|
// change the file-extension in the 'filename' entry widget
|
||||||
void FileSelector::onFileTypeChange()
|
void FileSelector::onFileTypeChange()
|
||||||
{
|
{
|
||||||
std::string newExtension = m_fileType->getItemText(m_fileType->getSelectedItem());
|
std::string newExtension = m_fileType->getItemText(m_fileType->getSelectedItemIndex());
|
||||||
std::string fileName = m_fileName->getText();
|
std::string fileName = m_fileName->getText();
|
||||||
std::string currentExtension = base::get_file_extension(fileName);
|
std::string currentExtension = base::get_file_extension(fileName);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user