2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2017-04-08 11:06:25 +08:00
|
|
|
// Copyright (C) 2001-2017 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-06-16 10:37:59 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifndef APP_UI_FILE_LIST_H_INCLUDED
|
|
|
|
#define APP_UI_FILE_LIST_H_INCLUDED
|
2014-03-30 06:40:17 +08:00
|
|
|
#pragma once
|
2012-06-16 10:37:59 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/file_system.h"
|
2016-03-30 03:19:23 +08:00
|
|
|
#include "base/time.h"
|
2016-09-14 02:02:00 +08:00
|
|
|
#include "obs/signal.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/timer.h"
|
|
|
|
#include "ui/widget.h"
|
2012-06-16 10:37:59 +08:00
|
|
|
|
2014-04-21 06:53:27 +08:00
|
|
|
#include <string>
|
2017-04-08 11:06:25 +08:00
|
|
|
#include <vector>
|
2014-04-21 06:53:27 +08:00
|
|
|
|
2016-01-06 03:37:52 +08:00
|
|
|
namespace she {
|
|
|
|
class Surface;
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2012-06-16 10:37:59 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class FileList : public ui::Widget {
|
2012-06-16 10:37:59 +08:00
|
|
|
public:
|
|
|
|
FileList();
|
|
|
|
virtual ~FileList();
|
|
|
|
|
2015-05-29 05:59:12 +08:00
|
|
|
const std::string& extensions() const { return m_exts; }
|
2012-06-16 10:37:59 +08:00
|
|
|
void setExtensions(const char* extensions);
|
|
|
|
|
2017-04-08 11:06:25 +08:00
|
|
|
IFileItem* currentFolder() const { return m_currentFolder; }
|
2012-06-16 10:37:59 +08:00
|
|
|
void setCurrentFolder(IFileItem* folder);
|
|
|
|
|
2017-04-08 11:06:25 +08:00
|
|
|
IFileItem* selectedFileItem() const { return m_selected; }
|
|
|
|
const FileItemList& fileList() const { return m_list; }
|
|
|
|
FileItemList selectedFileItems() const;
|
|
|
|
void deselectedFileItems();
|
|
|
|
|
|
|
|
bool multipleSelection() { return m_multiselect; }
|
|
|
|
void setMultipleSelection(bool multiple);
|
2012-06-16 10:37:59 +08:00
|
|
|
|
|
|
|
void goUp();
|
|
|
|
|
2016-01-06 03:37:52 +08:00
|
|
|
gfx::Rect thumbnailBounds();
|
|
|
|
|
2016-09-14 02:02:00 +08:00
|
|
|
obs::signal<void()> FileSelected;
|
|
|
|
obs::signal<void()> FileAccepted;
|
|
|
|
obs::signal<void()> CurrentFolderChanged;
|
2012-06-16 10:37:59 +08:00
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
virtual bool onProcessMessage(ui::Message* msg) override;
|
|
|
|
virtual void onPaint(ui::PaintEvent& ev) override;
|
2015-12-04 08:50:05 +08:00
|
|
|
virtual void onSizeHint(ui::SizeHintEvent& ev) override;
|
2012-06-16 10:37:59 +08:00
|
|
|
virtual void onFileSelected();
|
|
|
|
virtual void onFileAccepted();
|
|
|
|
virtual void onCurrentFolderChanged();
|
|
|
|
|
|
|
|
private:
|
2012-07-06 12:06:00 +08:00
|
|
|
void onGenerateThumbnailTick();
|
|
|
|
void onMonitoringTick();
|
2012-06-16 10:37:59 +08:00
|
|
|
gfx::Size getFileItemSize(IFileItem* fi) const;
|
|
|
|
void makeSelectedFileitemVisible();
|
|
|
|
void regenerateList();
|
2017-04-08 11:06:25 +08:00
|
|
|
int selectedIndex() const;
|
2012-06-16 10:37:59 +08:00
|
|
|
void selectIndex(int index);
|
|
|
|
void generatePreviewOfSelectedItem();
|
2016-01-06 03:37:52 +08:00
|
|
|
int thumbnailY();
|
2012-06-16 10:37:59 +08:00
|
|
|
|
|
|
|
IFileItem* m_currentFolder;
|
|
|
|
FileItemList m_list;
|
2017-04-08 11:06:25 +08:00
|
|
|
|
2012-06-16 10:37:59 +08:00
|
|
|
bool m_req_valid;
|
|
|
|
int m_req_w, m_req_h;
|
|
|
|
IFileItem* m_selected;
|
2017-04-08 11:06:25 +08:00
|
|
|
std::vector<bool> m_selectedItems;
|
2014-04-21 06:53:27 +08:00
|
|
|
std::string m_exts;
|
2012-06-16 10:37:59 +08:00
|
|
|
|
|
|
|
// Incremental-search
|
|
|
|
std::string m_isearch;
|
2016-03-30 03:19:23 +08:00
|
|
|
base::tick_t m_isearchClock;
|
2012-06-16 10:37:59 +08:00
|
|
|
|
2012-07-06 12:06:00 +08:00
|
|
|
// Timer to start generating the thumbnail after an item is
|
|
|
|
// selected.
|
|
|
|
ui::Timer m_generateThumbnailTimer;
|
|
|
|
|
|
|
|
// Monitoring the progress of each thumbnail.
|
|
|
|
ui::Timer m_monitoringTimer;
|
|
|
|
|
|
|
|
// Used keep the last-selected item in the list so we know
|
|
|
|
// thumbnail to generate when the m_generateThumbnailTimer ticks.
|
2012-06-16 10:37:59 +08:00
|
|
|
IFileItem* m_itemToGenerateThumbnail;
|
|
|
|
|
2016-01-06 03:37:52 +08:00
|
|
|
she::Surface* m_thumbnail;
|
2017-04-08 11:06:25 +08:00
|
|
|
|
|
|
|
// True if this listbox accepts selecting multiple items at the
|
|
|
|
// same time.
|
|
|
|
bool m_multiselect;
|
2012-06-16 10:37:59 +08:00
|
|
|
};
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|
2012-06-16 10:37:59 +08:00
|
|
|
|
|
|
|
#endif
|