Added FileSystem::getRealPath (build not tested for VC).

Minor improvements to UIFileDialog.
Fixed close key on UIFileDialog and UIMessageBox.
This commit is contained in:
Martín Lucas Golini
2020-06-25 03:37:16 -03:00
parent f880a32a02
commit 71f974b7e8
9 changed files with 77 additions and 49 deletions

View File

@@ -101,6 +101,9 @@ class EE_API FileSystem {
/** Creates a new directory */
static bool makeDir( const std::string& path, const Uint16& mode = 0770 );
/** @return The absolute path of a relative path */
static std::string getRealPath( const std::string& path );
/** Convert a size represented in bytes, to a string converted in byes/kb/mb/tb.
* For example 10485760 -> "10.0 MB"
*/

View File

@@ -24,11 +24,11 @@ class EE_API UIFileDialog : public UIWindow {
static const Uint32 DefaultFlags = FoldersFirst | SortAlphabetically;
static UIFileDialog* New( Uint32 dialogFlags = DefaultFlags,
std::string defaultFilePattern = "*",
std::string defaultDirectory = Sys::getProcessPath() );
const std::string& defaultFilePattern = "*",
const std::string& defaultDirectory = Sys::getProcessPath() );
UIFileDialog( Uint32 dialogFlags = DefaultFlags, std::string defaultFilePattern = "*",
std::string defaultDirectory = Sys::getProcessPath() );
UIFileDialog( Uint32 dialogFlags = DefaultFlags, const std::string& defaultFilePattern = "*",
const std::string& defaultDirectory = Sys::getProcessPath() );
virtual ~UIFileDialog();
@@ -119,6 +119,8 @@ class EE_API UIFileDialog : public UIWindow {
void goFolderUp();
void updateClickStep();
void setCurPath( const std::string& path );
};
}} // namespace EE::UI

View File

@@ -36,9 +36,9 @@ class EE_API UIMessageBox : public UIWindow {
virtual bool show();
const KeyBindings::Shortcut& getCloseWithKey() const;
const KeyBindings::Shortcut& getCloseShortcut() const;
void setCloseWithKey( const KeyBindings::Shortcut& closeWithKey );
void setCloseShortcut( const KeyBindings::Shortcut& closeWithKey );
UITextInput* getTextInput() const;
@@ -48,7 +48,7 @@ class EE_API UIMessageBox : public UIWindow {
UIPushButton* mButtonOK;
UIPushButton* mButtonCancel;
UITextInput* mTextInput;
KeyBindings::Shortcut mCloseWithKey;
KeyBindings::Shortcut mCloseShortcut;
UIWidget* mLayoutCont;
virtual void onWindowReady();

View File

@@ -17,8 +17,6 @@ namespace EE {
bool PrintDebugInLog = true;
#ifdef EE_DEBUG
void eeREPORT_ASSERT( const char* File, int Line, const char* Exp ) {
#ifdef EE_COMPILER_MSVC
@@ -46,8 +44,6 @@ void eeREPORT_ASSERT( const char* File, int Line, const char* Exp ) {
#endif
}
#endif
#ifndef EE_SILENT
static void print_buffer( std::string& buf, bool newLine ) {

View File

@@ -279,6 +279,29 @@ bool FileSystem::makeDir( const std::string& path, const Uint16& mode ) {
return v == 0;
}
std::string FileSystem::getRealPath( const std::string& path ) {
std::string realPath;
#ifdef EE_PLATFORM_POSIX
char dir[PATH_MAX];
realpath( path.c_str(), &dir[0] );
realPath = std::string( dir );
#elif EE_PLATFORM == EE_PLATFORM_WIN
#if defined( UNICODE ) && !defined( EE_NO_WIDECHAR )
wchar_t dir[_MAX_PATH + 1];
GetFullPathName( String::fromUtf8( path.c_str() ).toWideString().c_str(), _MAX_PATH, &dir[0],
nullptr );
realPath = String( dir ).toUtf8();
#else
char dir[_MAX_PATH + 1];
GetFullPathName( path.c_str(), _MAX_PATH, &dir[0], nullptr );
realPath = std::string( dir );
#endif
#else
#warning FileSystem::getRealPath() not implemented on this platform.
#endif
return realPath;
}
std::vector<String> FileSystem::filesGetInPath( const String& path, const bool& sortByName,
const bool& foldersFirst ) {
std::vector<String> files;

View File

@@ -416,7 +416,7 @@ Uint32 Sys::getTicks() {
return ( ticks );
#endif
#else
#warning eeGetTicks not implemented in this platform.
#warning Sys::getTicks() not implemented in this platform.
#endif
}
@@ -452,7 +452,7 @@ void Sys::sleep( const Time& time ) {
while ( ( nanosleep( &ti, &ti ) == -1 ) && ( errno == EINTR ) ) {
}
#else
#warning Sys::Sleep not implemented in this platform.
#warning Sys::sleep() not implemented in this platform.
#endif
}
@@ -655,11 +655,11 @@ std::string Sys::getConfigPath( std::string appname ) {
snprintf( path, EE_MAX_CFG_PATH_LEN, "%s/.config/%s", home, appname.c_str() );
}
#elif EE_PLATFORM == EE_PLATFORM_IOS
return getProcessPath() + "config";
return getProcessPath() + "config";
#elif EE_PLATFORM == EE_PLATFORM_ANDROID
return Window::Engine::instance()->getPlatformHelper()->getInternalStoragePath() + "/";
#else
#warning Sys::GetConfigPath not implemented for this platform ( it will use HOME directory + /.appname )
#warning Sys::getConfigPath not implemented for this platform ( it will use HOME directory + /.appname )
char* home = getenv( "HOME" );
@@ -738,7 +738,7 @@ int Sys::getCPUCount() {
nprocs = info.cpu_count;
}
#else
#warning Sys::GetCPUCount not implemented on this platform ( it will return 1 ).
#warning Sys::getCPUCount not implemented on this platform ( it will return 1 ).
#endif
if ( nprocs < 1 )
@@ -781,7 +781,7 @@ void* Sys::loadObject( const std::string& sofile ) {
}
return handle;
#else
#warning Sys::LoadObject not implemented in this platform
#warning Sys::loadObject not implemented in this platform
#endif
}
@@ -795,7 +795,7 @@ void Sys::unloadObject( void* handle ) {
FreeLibrary( (HMODULE)handle );
}
#else
#warning Sys::UnloadObject not implemented in this platform
#warning Sys::unloadObject not implemented in this platform
#endif
}
@@ -824,7 +824,7 @@ void* Sys::loadFunction( void* handle, const std::string& name ) {
return symbol;
#else
#warning Sys::LoadFunction not implemented in this platform
#warning Sys::loadFunction not implemented in this platform
#endif
}

View File

@@ -12,17 +12,17 @@ namespace EE { namespace UI {
#define FDLG_MIN_WIDTH 420
#define FDLG_MIN_HEIGHT 320
UIFileDialog* UIFileDialog::New( Uint32 dialogFlags, std::string defaultFilePattern,
std::string defaultDirectory ) {
UIFileDialog* UIFileDialog::New( Uint32 dialogFlags, const std::string& defaultFilePattern,
const std::string& defaultDirectory ) {
return eeNew( UIFileDialog, ( dialogFlags, defaultFilePattern, defaultDirectory ) );
}
UIFileDialog::UIFileDialog( Uint32 dialogFlags, std::string defaultFilePattern,
std::string defaultDirectory ) :
UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePattern,
const std::string& defaultDirectory ) :
UIWindow(),
mCurPath( defaultDirectory ),
mCurPath( FileSystem::getRealPath( defaultDirectory ) ),
mDialogFlags( dialogFlags ),
mCloseShortcut( KEY_UNKNOWN ) {
mCloseShortcut( KEY_ESCAPE ) {
if ( getSize().getWidth() < FDLG_MIN_WIDTH ) {
mDpSize.x = FDLG_MIN_WIDTH;
mSize.x = PixelDensity::dpToPxI( FDLG_MIN_WIDTH );
@@ -68,6 +68,8 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, std::string defaultFilePattern,
->setParent( hLayout )
->setEnabled( false );
FileSystem::dirPathAddSlashAtEnd( mCurPath );
mPath = UITextInput::New();
mPath->setText( mCurPath )
->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent )
@@ -153,6 +155,8 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, std::string defaultFilePattern,
->setSize( 80, 0 )
->setParent( hLayout );
mList->setFocus();
applyDefaultTheme();
mUISceneNode->setIsLoading( loading );
@@ -194,6 +198,7 @@ void UIFileDialog::setTheme( UITheme* Theme ) {
}
void UIFileDialog::refreshFolder() {
FileSystem::dirPathAddSlashAtEnd( mCurPath );
std::vector<String> flist = FileSystem::filesGetInPath( String( mCurPath ) );
std::vector<String> files;
std::vector<String> folders;
@@ -256,6 +261,13 @@ void UIFileDialog::updateClickStep() {
}
}
void UIFileDialog::setCurPath( const std::string& path ) {
mCurPath = path;
FileSystem::dirPathAddSlashAtEnd( mCurPath );
mPath->setText( mCurPath );
refreshFolder();
}
void UIFileDialog::openSaveClick() {
if ( isSaveDialog() ) {
save();
@@ -287,18 +299,14 @@ void UIFileDialog::openFileOrFolder() {
std::string newPath = mCurPath + mList->getItemSelectedText();
if ( FileSystem::isDirectory( newPath ) ) {
mCurPath = newPath + FileSystem::getOSSlash();
mPath->setText( mCurPath );
refreshFolder();
setCurPath( newPath );
} else {
open();
}
}
void UIFileDialog::goFolderUp() {
mCurPath = FileSystem::removeLastFolderFromPath( mCurPath );
mPath->setText( mCurPath );
refreshFolder();
setCurPath( FileSystem::removeLastFolderFromPath( mCurPath ) );
}
Uint32 UIFileDialog::onMessage( const NodeMessage* Msg ) {
@@ -382,11 +390,7 @@ void UIFileDialog::open() {
void UIFileDialog::onPressEnter( const Event* ) {
if ( FileSystem::isDirectory( mPath->getText() ) ) {
std::string tpath = mPath->getText();
FileSystem::dirPathAddSlashAtEnd( tpath );
mPath->setText( tpath );
mCurPath = mPath->getText();
refreshFolder();
setCurPath( mPath->getText() );
}
}
@@ -489,15 +493,15 @@ UIDropDownList* UIFileDialog::getFiletypeList() const {
return mFiletype;
}
Uint32 UIFileDialog::onKeyUp( const KeyEvent& Event ) {
if ( mCloseShortcut && Event.getKeyCode() == mCloseShortcut &&
( Event.getMod() & mCloseShortcut.mod ) ) {
Uint32 UIFileDialog::onKeyUp( const KeyEvent& event ) {
if ( mCloseShortcut && event.getKeyCode() == mCloseShortcut &&
( mCloseShortcut.mod == 0 || ( event.getMod() & mCloseShortcut.mod ) ) ) {
disableButtons();
closeWindow();
}
return 1;
return UIWindow::onKeyUp( event );
}
const KeyBindings::Shortcut& UIFileDialog::getCloseShortcut() const {

View File

@@ -12,7 +12,7 @@ UIMessageBox* UIMessageBox::New( const Type& type, const String& message,
}
UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint32& windowFlags ) :
UIWindow(), mMsgBoxType( type ), mTextInput( NULL ), mCloseWithKey( KEY_UNKNOWN ) {
UIWindow(), mMsgBoxType( type ), mTextInput( NULL ), mCloseShortcut( KEY_UNKNOWN ) {
mStyleConfig.WinFlags = windowFlags;
updateWinFlags();
@@ -150,8 +150,8 @@ UIPushButton* UIMessageBox::getButtonCancel() const {
}
Uint32 UIMessageBox::onKeyUp( const KeyEvent& event ) {
if ( mCloseWithKey && event.getKeyCode() == mCloseWithKey &&
( event.getMod() & mCloseWithKey.mod ) ) {
if ( mCloseShortcut && event.getKeyCode() == mCloseShortcut &&
( mCloseShortcut.mod == 0 || ( event.getMod() & mCloseShortcut.mod ) ) ) {
sendCommonEvent( Event::MsgBoxCancelClick );
closeWindow();
}
@@ -169,12 +169,12 @@ bool UIMessageBox::show() {
return b;
}
const KeyBindings::Shortcut& UIMessageBox::getCloseWithKey() const {
return mCloseWithKey;
const KeyBindings::Shortcut& UIMessageBox::getCloseShortcut() const {
return mCloseShortcut;
}
void UIMessageBox::setCloseWithKey( const KeyBindings::Shortcut& closeWithKey ) {
mCloseWithKey = closeWithKey;
void UIMessageBox::setCloseShortcut( const KeyBindings::Shortcut& closeWithKey ) {
mCloseShortcut = closeWithKey;
}
UITextInput* UIMessageBox::getTextInput() const {

View File

@@ -645,7 +645,7 @@ void App::setCurrentEditor( UICodeEditor* editor ) {
}
void App::openFileDialog() {
UIFileDialog* dialog = UIFileDialog::New();
UIFileDialog* dialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*", "." );
dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
dialog->setTitle( "Open File" );
dialog->setCloseShortcut( KEY_ESCAPE );
@@ -662,7 +662,7 @@ void App::openFileDialog() {
void App::saveFileDialog() {
UIFileDialog* dialog =
UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog );
UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "." );
dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
dialog->setTitle( "Save File As" );
dialog->setCloseShortcut( KEY_ESCAPE );