| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //
- // Urho3D Engine
- // Copyright (c) 2008-2011 Lasse Öörni
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #pragma once
- #include "Object.h"
- class Button;
- class DropDownList;
- class Font;
- class LineEdit;
- class ListView;
- class ResourceCache;
- class Text;
- class UI;
- class UIElement;
- class Window;
- class XMLFile;
- /// File selector's list entry (file or directory)
- struct FileSelectorEntry
- {
- /// Name
- std::string name_;
- /// Directory flag
- bool directory_;
- };
- /// File selector dialog
- class FileSelector : public Object
- {
- OBJECT(FileSelector);
-
- public:
- /// Construct
- FileSelector(Context* context);
- /// Destruct
- virtual ~FileSelector();
- /// Register object factory
- static void RegisterObject(Context* context);
-
- /// Set fileselector UI style
- void SetStyle(XMLFile* style);
- /// Set title text
- void SetTitle(const std::string& text);
- /// Set button texts
- void SetButtonTexts(const std::string& okText, const std::string& cancelText);
- /// Set current path
- void SetPath(const std::string& path);
- /// Set current filename
- void SetFileName(const std::string& fileName);
- /// Set filters
- void SetFilters(const std::vector<std::string>& filters, unsigned defaultIndex);
- /// Set directory selection mode. Default false
- void SetDirectoryMode(bool enable);
- /// Update elements to layout properly. Call this after manually adjusting the sub-elements
- void UpdateElements();
-
- /// Return the UI style file
- XMLFile* GetStyle() const { return style_; }
- /// Return fileselector window
- Window* GetWindow() const { return window_; }
- /// Return window title text
- Text* GetTitleText() const { return titleText_; }
- /// Return file list
- ListView* GetFileList() const { return fileList_; }
- /// Return path editor
- LineEdit* GetPathEdit() const { return pathEdit_; }
- /// Return filename editor
- LineEdit* GetFileNameEdit() const { return fileNameEdit_; }
- /// Return filter dropdown
- DropDownList* GetFilterList() const { return filterList_; }
- /// Return OK button
- Button* GetOKButton() const { return okButton_; }
- /// Return cancel button
- Button* GetCancelButton() const { return cancelButton_; }
- /// Return close button
- Button* GetCloseButton() const { return closeButton_; }
- /// Return current path
- const std::string& GetPath() const { return path_; }
- /// Return current filename
- const std::string& GetFileName() const;
- /// Return current filter
- const std::string& GetFilter() const;
- /// Return current filter index
- unsigned GetFilterIndex() const;
- /// Return directory mode flag
- bool GetDirectoryMode() const { return directoryMode_; }
-
- private:
- /// Set the text of an edit field and ignore the resulting event
- void SetLineEditText(LineEdit* edit, const std::string& text);
- /// Refresh the directory listing
- void RefreshFiles();
- /// Enter a directory or confirm a file. Return true if a directory entered
- bool EnterFile();
- /// Handle filter changed
- void HandleFilterChanged(StringHash eventType, VariantMap& eventData);
- /// Handle path edited
- void HandlePathChanged(StringHash eventType, VariantMap& eventData);
- /// Handle file selected from the list
- void HandleFileSelected(StringHash eventType, VariantMap& eventData);
- /// Handle file doubleclicked from the list (enter directory / OK the file selection)
- void HandleFileDoubleClicked(StringHash eventType, VariantMap& eventData);
- /// Handle file list key pressed
- void HandleFileListKey(StringHash eventType, VariantMap& eventData);
- /// Handle OK button pressed
- void HandleOKPressed(StringHash eventType, VariantMap& eventData);
- /// Handle cancel button pressed
- void HandleCancelPressed(StringHash eventType, VariantMap& eventData);
-
- /// UI subsystem
- SharedPtr<UI> ui_;
- /// UI style file
- SharedPtr<XMLFile> style_;
- /// Fileselector window
- SharedPtr<Window> window_;
- /// Title layout
- SharedPtr<UIElement> titleLayout;
- /// Window title text
- SharedPtr<Text> titleText_;
- /// File list
- SharedPtr<ListView> fileList_;
- /// Path editor
- SharedPtr<LineEdit> pathEdit_;
- /// Filename editor
- SharedPtr<LineEdit> fileNameEdit_;
- /// Filter dropdown
- SharedPtr<DropDownList> filterList_;
- /// OK button
- SharedPtr<Button> okButton_;
- /// OK button text
- SharedPtr<Text> okButtonText_;
- /// Cancel button
- SharedPtr<Button> cancelButton_;
- /// Cancel button text
- SharedPtr<Text> cancelButtonText_;
- /// Close button
- SharedPtr<Button> closeButton_;
- /// Filename and filter layout
- SharedPtr<UIElement> fileNameLayout_;
- /// Button layout
- SharedPtr<UIElement> buttonLayout_;
- /// Current path
- std::string path_;
- /// Filters
- std::vector<std::string> filters_;
- /// File entries
- std::vector<FileSelectorEntry> fileEntries_;
- /// Filter used to get the file list
- std::string lastUsedFilter_;
- /// Directory mode flag
- bool directoryMode_;
- /// Ignore events flag, used when changing line edits manually
- bool ignoreEvents_;
- };
|