mirror of https://github.com/aseprite/aseprite.git
Use generated widget in app::FileSelector from file_selector.xml
This commit is contained in:
parent
3c95bd57ee
commit
726013e0bd
|
|
@ -1,24 +1,25 @@
|
||||||
<!-- ASEPRITE -->
|
<!-- ASEPRITE -->
|
||||||
<!-- Copyright (C) 2001-2013, 2015 by David Capello -->
|
<!-- Copyright (C) 2001-2013, 2015 by David Capello -->
|
||||||
<gui>
|
<gui>
|
||||||
|
<window id="file_selector" text="">
|
||||||
<vbox id="main">
|
<vbox id="main">
|
||||||
<box horizontal="true">
|
<box horizontal="true">
|
||||||
<box horizontal="true" noborders="true">
|
<box horizontal="true" noborders="true">
|
||||||
<button text="" id="goback" bevel="2 0 2 0" tooltip="Go back one folder" />
|
<button text="" id="go_back_button" bevel="2 0 2 0" tooltip="Go back one folder" />
|
||||||
<button text="" id="goforward" bevel="0 2 0 2" tooltip="Go forward one folder" />
|
<button text="" id="go_forward_button" bevel="0 2 0 2" tooltip="Go forward one folder" />
|
||||||
</box>
|
</box>
|
||||||
<button text="" id="goup" tooltip="Up to parent folder (Backspace)" />
|
<button text="" id="go_up_button" tooltip="Up to parent folder (Backspace)" />
|
||||||
<button text="" id="newfolder" tooltip="New folder" />
|
<button text="" id="new_folder_button" tooltip="New folder" />
|
||||||
<combobox id="location" expansive="true" />
|
<combobox id="location" expansive="true" />
|
||||||
</box>
|
</box>
|
||||||
<view id="fileview_container" expansive="true"></view>
|
<view id="file_view" expansive="true" />
|
||||||
<grid columns="2">
|
<grid columns="2">
|
||||||
<label text="File name:" />
|
<label text="File name:" />
|
||||||
<filenameentry id="filename" cell_align="horizontal" magnet="true" />
|
<box id="file_name_placeholder" cell_align="horizontal" />
|
||||||
|
|
||||||
<label text="File type:" />
|
<label text="File type:" />
|
||||||
<hbox cell_align="horizontal">
|
<hbox cell_align="horizontal">
|
||||||
<combobox id="filetype" minwidth="70" />
|
<combobox id="file_type" minwidth="70" />
|
||||||
<boxfiller />
|
<boxfiller />
|
||||||
<box horizontal="true" homogeneous="true">
|
<box horizontal="true" homogeneous="true">
|
||||||
<button text="&OK" closewindow="true" id="ok" magnet="true" width="60" />
|
<button text="&OK" closewindow="true" id="ok" magnet="true" width="60" />
|
||||||
|
|
@ -27,6 +28,7 @@
|
||||||
</hbox>
|
</hbox>
|
||||||
</grid>
|
</grid>
|
||||||
</vbox>
|
</vbox>
|
||||||
|
</window>
|
||||||
|
|
||||||
<window text="New Folder" id="newfolder_dialog">
|
<window text="New Folder" id="newfolder_dialog">
|
||||||
<vbox>
|
<vbox>
|
||||||
|
|
|
||||||
|
|
@ -140,16 +140,6 @@ private:
|
||||||
FileList* m_fileList;
|
FileList* m_fileList;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class to create CustomFileNameEntries.
|
|
||||||
class CustomFileNameEntryCreator : public app::WidgetLoader::IWidgetTypeCreator {
|
|
||||||
public:
|
|
||||||
~CustomFileNameEntryCreator() { }
|
|
||||||
void dispose() override { delete this; }
|
|
||||||
Widget* createWidgetFromXml(const TiXmlElement* xmlElem) override {
|
|
||||||
return new CustomFileNameEntry();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CustomFileNameItem : public ListItem
|
class CustomFileNameItem : public ListItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -242,71 +232,57 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
FileSelector::FileSelector(FileSelectorType type)
|
FileSelector::FileSelector(FileSelectorType type)
|
||||||
: Window(WithTitleBar, "")
|
: m_type(type)
|
||||||
, m_type(type)
|
|
||||||
, m_navigationLocked(false)
|
, m_navigationLocked(false)
|
||||||
{
|
{
|
||||||
app::WidgetLoader loader;
|
|
||||||
loader.addWidgetType("filenameentry", new CustomFileNameEntryCreator);
|
|
||||||
|
|
||||||
// Load the main widget.
|
|
||||||
Box* box = loader.loadWidgetT<Box>("file_selector.xml", "main");
|
|
||||||
addChild(box);
|
|
||||||
addChild(new ArrowNavigator(this));
|
addChild(new ArrowNavigator(this));
|
||||||
|
|
||||||
View* view;
|
m_fileName = new CustomFileNameEntry;
|
||||||
app::finder(this)
|
m_fileName->setFocusMagnet(true);
|
||||||
>> "fileview_container" >> view
|
fileNamePlaceholder()->addChild(m_fileName);
|
||||||
>> "goback" >> m_goBack
|
|
||||||
>> "goforward" >> m_goForward
|
|
||||||
>> "goup" >> m_goUp
|
|
||||||
>> "newfolder" >> m_newFolder
|
|
||||||
>> "location" >> m_location
|
|
||||||
>> "filetype" >> m_fileType
|
|
||||||
>> "filename" >> m_fileName;
|
|
||||||
|
|
||||||
m_goBack->setFocusStop(false);
|
goBackButton()->setFocusStop(false);
|
||||||
m_goForward->setFocusStop(false);
|
goForwardButton()->setFocusStop(false);
|
||||||
m_goUp->setFocusStop(false);
|
goUpButton()->setFocusStop(false);
|
||||||
m_newFolder->setFocusStop(false);
|
newFolderButton()->setFocusStop(false);
|
||||||
|
|
||||||
set_gfxicon_to_button(m_goBack,
|
set_gfxicon_to_button(goBackButton(),
|
||||||
PART_COMBOBOX_ARROW_LEFT,
|
PART_COMBOBOX_ARROW_LEFT,
|
||||||
PART_COMBOBOX_ARROW_LEFT_SELECTED,
|
PART_COMBOBOX_ARROW_LEFT_SELECTED,
|
||||||
PART_COMBOBOX_ARROW_LEFT_DISABLED,
|
PART_COMBOBOX_ARROW_LEFT_DISABLED,
|
||||||
JI_CENTER | JI_MIDDLE);
|
JI_CENTER | JI_MIDDLE);
|
||||||
set_gfxicon_to_button(m_goForward,
|
set_gfxicon_to_button(goForwardButton(),
|
||||||
PART_COMBOBOX_ARROW_RIGHT,
|
PART_COMBOBOX_ARROW_RIGHT,
|
||||||
PART_COMBOBOX_ARROW_RIGHT_SELECTED,
|
PART_COMBOBOX_ARROW_RIGHT_SELECTED,
|
||||||
PART_COMBOBOX_ARROW_RIGHT_DISABLED,
|
PART_COMBOBOX_ARROW_RIGHT_DISABLED,
|
||||||
JI_CENTER | JI_MIDDLE);
|
JI_CENTER | JI_MIDDLE);
|
||||||
set_gfxicon_to_button(m_goUp,
|
set_gfxicon_to_button(goUpButton(),
|
||||||
PART_COMBOBOX_ARROW_UP,
|
PART_COMBOBOX_ARROW_UP,
|
||||||
PART_COMBOBOX_ARROW_UP_SELECTED,
|
PART_COMBOBOX_ARROW_UP_SELECTED,
|
||||||
PART_COMBOBOX_ARROW_UP_DISABLED,
|
PART_COMBOBOX_ARROW_UP_DISABLED,
|
||||||
JI_CENTER | JI_MIDDLE);
|
JI_CENTER | JI_MIDDLE);
|
||||||
set_gfxicon_to_button(m_newFolder,
|
set_gfxicon_to_button(newFolderButton(),
|
||||||
PART_NEWFOLDER,
|
PART_NEWFOLDER,
|
||||||
PART_NEWFOLDER_SELECTED,
|
PART_NEWFOLDER_SELECTED,
|
||||||
PART_NEWFOLDER,
|
PART_NEWFOLDER,
|
||||||
JI_CENTER | JI_MIDDLE);
|
JI_CENTER | JI_MIDDLE);
|
||||||
|
|
||||||
setup_mini_look(m_goBack);
|
setup_mini_look(goBackButton());
|
||||||
setup_mini_look(m_goForward);
|
setup_mini_look(goForwardButton());
|
||||||
setup_mini_look(m_goUp);
|
setup_mini_look(goUpButton());
|
||||||
setup_mini_look(m_newFolder);
|
setup_mini_look(newFolderButton());
|
||||||
|
|
||||||
m_fileList = new FileList();
|
m_fileList = new FileList();
|
||||||
m_fileList->setId("fileview");
|
m_fileList->setId("fileview");
|
||||||
view->attachToView(m_fileList);
|
fileView()->attachToView(m_fileList);
|
||||||
m_fileName->setAssociatedFileList(m_fileList);
|
m_fileName->setAssociatedFileList(m_fileList);
|
||||||
|
|
||||||
m_goBack->Click.connect(Bind<void>(&FileSelector::onGoBack, this));
|
goBackButton()->Click.connect(Bind<void>(&FileSelector::onGoBack, this));
|
||||||
m_goForward->Click.connect(Bind<void>(&FileSelector::onGoForward, this));
|
goForwardButton()->Click.connect(Bind<void>(&FileSelector::onGoForward, this));
|
||||||
m_goUp->Click.connect(Bind<void>(&FileSelector::onGoUp, this));
|
goUpButton()->Click.connect(Bind<void>(&FileSelector::onGoUp, this));
|
||||||
m_newFolder->Click.connect(Bind<void>(&FileSelector::onNewFolder, this));
|
newFolderButton()->Click.connect(Bind<void>(&FileSelector::onNewFolder, this));
|
||||||
m_location->CloseListBox.connect(Bind<void>(&FileSelector::onLocationCloseListBox, this));
|
location()->CloseListBox.connect(Bind<void>(&FileSelector::onLocationCloseListBox, this));
|
||||||
m_fileType->Change.connect(Bind<void>(&FileSelector::onFileTypeChange, this));
|
fileType()->Change.connect(Bind<void>(&FileSelector::onFileTypeChange, this));
|
||||||
m_fileList->FileSelected.connect(Bind<void>(&FileSelector::onFileListFileSelected, this));
|
m_fileList->FileSelected.connect(Bind<void>(&FileSelector::onFileListFileSelected, this));
|
||||||
m_fileList->FileAccepted.connect(Bind<void>(&FileSelector::onFileListFileAccepted, this));
|
m_fileList->FileAccepted.connect(Bind<void>(&FileSelector::onFileListFileAccepted, this));
|
||||||
m_fileList->CurrentFolderChanged.connect(Bind<void>(&FileSelector::onFileListCurrentFolderChanged, this));
|
m_fileList->CurrentFolderChanged.connect(Bind<void>(&FileSelector::onFileListCurrentFolderChanged, this));
|
||||||
|
|
@ -410,7 +386,7 @@ std::string FileSelector::show(
|
||||||
updateNavigationButtons();
|
updateNavigationButtons();
|
||||||
|
|
||||||
// fill file-type combo-box
|
// fill file-type combo-box
|
||||||
m_fileType->removeAllItems();
|
fileType()->removeAllItems();
|
||||||
|
|
||||||
// Get the default extension from the given initial file name
|
// Get the default extension from the given initial file name
|
||||||
m_defExtension = initialExtension;
|
m_defExtension = initialExtension;
|
||||||
|
|
@ -419,7 +395,7 @@ std::string FileSelector::show(
|
||||||
{
|
{
|
||||||
ListItem* item = new ListItem("All formats");
|
ListItem* item = new ListItem("All formats");
|
||||||
item->setValue(showExtensions);
|
item->setValue(showExtensions);
|
||||||
m_fileType->addItem(item);
|
fileType()->addItem(item);
|
||||||
}
|
}
|
||||||
// One file type for each supported image format
|
// One file type for each supported image format
|
||||||
std::vector<std::string> tokens;
|
std::vector<std::string> tokens;
|
||||||
|
|
@ -431,19 +407,19 @@ std::string FileSelector::show(
|
||||||
|
|
||||||
ListItem* item = new ListItem(tok + " files");
|
ListItem* item = new ListItem(tok + " files");
|
||||||
item->setValue(tok);
|
item->setValue(tok);
|
||||||
m_fileType->addItem(item);
|
fileType()->addItem(item);
|
||||||
}
|
}
|
||||||
// All files
|
// All files
|
||||||
{
|
{
|
||||||
ListItem* item = new ListItem("All files");
|
ListItem* item = new ListItem("All files");
|
||||||
item->setValue(""); // Empty extensions means "*.*"
|
item->setValue(""); // Empty extensions means "*.*"
|
||||||
m_fileType->addItem(item);
|
fileType()->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// file name entry field
|
// file name entry field
|
||||||
m_fileName->setValue(base::get_file_name(initialPath).c_str());
|
m_fileName->setValue(base::get_file_name(initialPath).c_str());
|
||||||
m_fileName->getEntryWidget()->selectText(0, -1);
|
m_fileName->getEntryWidget()->selectText(0, -1);
|
||||||
m_fileType->setValue(exts);
|
fileType()->setValue(exts);
|
||||||
|
|
||||||
// setup the title of the window
|
// setup the title of the window
|
||||||
setText(title.c_str());
|
setText(title.c_str());
|
||||||
|
|
@ -612,7 +588,7 @@ void FileSelector::updateLocation()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear all the items from the combo-box
|
// Clear all the items from the combo-box
|
||||||
m_location->removeAllItems();
|
location()->removeAllItems();
|
||||||
|
|
||||||
// Add item by item (from root to the specific current folder)
|
// Add item by item (from root to the specific current folder)
|
||||||
int level = 0;
|
int level = 0;
|
||||||
|
|
@ -629,7 +605,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
|
||||||
m_location->addItem(new CustomFileNameItem(buf.c_str(), fileItem));
|
location()->addItem(new CustomFileNameItem(buf.c_str(), fileItem));
|
||||||
|
|
||||||
if (fileItem == currentFolder)
|
if (fileItem == currentFolder)
|
||||||
selected_index = level;
|
selected_index = level;
|
||||||
|
|
@ -639,20 +615,20 @@ void FileSelector::updateLocation()
|
||||||
|
|
||||||
// Add paths from recent files list
|
// Add paths from recent files list
|
||||||
{
|
{
|
||||||
m_location->addItem("");
|
location()->addItem("");
|
||||||
m_location->addItem("-------- Recent Paths --------");
|
location()->addItem("-------- Recent Paths --------");
|
||||||
|
|
||||||
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(new CustomFolderNameItem(it->c_str()));
|
location()->addItem(new CustomFolderNameItem(it->c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select the location
|
// Select the location
|
||||||
{
|
{
|
||||||
m_location->setSelectedItemIndex(selected_index);
|
location()->setSelectedItemIndex(selected_index);
|
||||||
m_location->getEntryWidget()->setText(currentFolder->getDisplayName().c_str());
|
location()->getEntryWidget()->setText(currentFolder->getDisplayName().c_str());
|
||||||
m_location->getEntryWidget()->deselectText();
|
location()->getEntryWidget()->deselectText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -660,21 +636,21 @@ void FileSelector::updateNavigationButtons()
|
||||||
{
|
{
|
||||||
// Update the state of the go back button: if the navigation-history
|
// Update the state of the go back button: if the navigation-history
|
||||||
// has two elements and the navigation-position isn't the first one.
|
// has two elements and the navigation-position isn't the first one.
|
||||||
m_goBack->setEnabled(navigation_history->size() > 1 &&
|
goBackButton()->setEnabled(navigation_history->size() > 1 &&
|
||||||
(navigation_position.isNull() ||
|
(navigation_position.isNull() ||
|
||||||
navigation_position.getIterator() != navigation_history->begin()));
|
navigation_position.getIterator() != navigation_history->begin()));
|
||||||
|
|
||||||
// Update the state of the go forward button: if the
|
// Update the state of the go forward button: if the
|
||||||
// navigation-history has two elements and the navigation-position
|
// navigation-history has two elements and the navigation-position
|
||||||
// isn't the last one.
|
// isn't the last one.
|
||||||
m_goForward->setEnabled(navigation_history->size() > 1 &&
|
goForwardButton()->setEnabled(navigation_history->size() > 1 &&
|
||||||
(navigation_position.isNull() ||
|
(navigation_position.isNull() ||
|
||||||
navigation_position.getIterator() != navigation_history->end()-1));
|
navigation_position.getIterator() != navigation_history->end()-1));
|
||||||
|
|
||||||
// Update the state of the go up button: if the current-folder isn't
|
// Update the state of the go up button: if the current-folder isn't
|
||||||
// the root-item.
|
// the root-item.
|
||||||
IFileItem* currentFolder = m_fileList->getCurrentFolder();
|
IFileItem* currentFolder = m_fileList->getCurrentFolder();
|
||||||
m_goUp->setEnabled(currentFolder != FileSystemModule::instance()->getRootFileItem());
|
goUpButton()->setEnabled(currentFolder != FileSystemModule::instance()->getRootFileItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSelector::addInNavigationHistory(IFileItem* folder)
|
void FileSelector::addInNavigationHistory(IFileItem* folder)
|
||||||
|
|
@ -776,13 +752,13 @@ void FileSelector::onLocationCloseListBox()
|
||||||
{
|
{
|
||||||
// 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
|
||||||
CustomFileNameItem* comboFileItem = dynamic_cast<CustomFileNameItem*>(m_location->getSelectedItem());
|
CustomFileNameItem* comboFileItem = dynamic_cast<CustomFileNameItem*>(location()->getSelectedItem());
|
||||||
IFileItem* fileItem = (comboFileItem != NULL ? comboFileItem->getFileItem(): NULL);
|
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) {
|
||||||
CustomFolderNameItem* comboFolderItem =
|
CustomFolderNameItem* comboFolderItem =
|
||||||
dynamic_cast<CustomFolderNameItem*>(m_location->getSelectedItem());
|
dynamic_cast<CustomFolderNameItem*>(location()->getSelectedItem());
|
||||||
|
|
||||||
if (comboFolderItem != NULL) {
|
if (comboFolderItem != NULL) {
|
||||||
std::string path = comboFolderItem->getText();
|
std::string path = comboFolderItem->getText();
|
||||||
|
|
@ -803,15 +779,15 @@ void FileSelector::onLocationCloseListBox()
|
||||||
// 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 exts = m_fileType->getValue();
|
std::string exts = fileType()->getValue();
|
||||||
if (exts != m_fileList->extensions()) {
|
if (exts != m_fileList->extensions()) {
|
||||||
m_navigationLocked = true;
|
m_navigationLocked = true;
|
||||||
m_fileList->setExtensions(exts.c_str());
|
m_fileList->setExtensions(exts.c_str());
|
||||||
m_navigationLocked = false;
|
m_navigationLocked = false;
|
||||||
|
|
||||||
if (m_type == FileSelectorType::Open) {
|
if (m_type == FileSelectorType::Open) {
|
||||||
std::string origShowExtensions = m_fileType->getItem(0)->getValue();
|
std::string origShowExtensions = fileType()->getItem(0)->getValue();
|
||||||
preferred_open_extensions[origShowExtensions] = m_fileType->getValue();
|
preferred_open_extensions[origShowExtensions] = fileType()->getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -855,7 +831,7 @@ void FileSelector::onFileListCurrentFolderChanged()
|
||||||
|
|
||||||
std::string FileSelector::getSelectedExtension() const
|
std::string FileSelector::getSelectedExtension() const
|
||||||
{
|
{
|
||||||
std::string ext = m_fileType->getValue();
|
std::string ext = fileType()->getValue();
|
||||||
if (ext.empty() || ext.find(',') != std::string::npos)
|
if (ext.empty() || ext.find(',') != std::string::npos)
|
||||||
ext = m_defExtension;
|
ext = m_defExtension;
|
||||||
return ext;
|
return ext;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
#include "ui/window.h"
|
#include "ui/window.h"
|
||||||
|
|
||||||
|
#include "generated_file_selector.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
@ -26,7 +28,7 @@ namespace app {
|
||||||
class FileList;
|
class FileList;
|
||||||
class IFileItem;
|
class IFileItem;
|
||||||
|
|
||||||
class FileSelector : public ui::Window {
|
class FileSelector : public app::gen::FileSelector {
|
||||||
public:
|
public:
|
||||||
FileSelector(FileSelectorType type);
|
FileSelector(FileSelectorType type);
|
||||||
|
|
||||||
|
|
@ -57,12 +59,6 @@ namespace app {
|
||||||
|
|
||||||
FileSelectorType m_type;
|
FileSelectorType m_type;
|
||||||
std::string m_defExtension;
|
std::string m_defExtension;
|
||||||
ui::Button* m_goBack;
|
|
||||||
ui::Button* m_goForward;
|
|
||||||
ui::Button* m_goUp;
|
|
||||||
ui::Button* m_newFolder;
|
|
||||||
ui::ComboBox* m_location;
|
|
||||||
ui::ComboBox* m_fileType;
|
|
||||||
CustomFileNameEntry* m_fileName;
|
CustomFileNameEntry* m_fileName;
|
||||||
FileList* m_fileList;
|
FileList* m_fileList;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue