mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-27 08:37:58 +03:00
Native file dialogs support WIP (SpartanJ/ecode#653).
This commit is contained in:
@@ -112,6 +112,7 @@
|
||||
|
||||
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS || \
|
||||
( EE_PLATFORM == EE_PLATFORM_WIN && defined( EE_COMPILER_MSVC ) )
|
||||
#define EE_OVERRIDES_MAIN
|
||||
#if defined( EE_BACKEND_SDL_ACTIVE )
|
||||
#if EE_PLATFORM == EE_PLATFORM_WIN && defined( EE_COMPILER_MSVC )
|
||||
#define main SDL_main
|
||||
@@ -121,7 +122,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined( __cplusplus ) && defined( EE_OVERRIDES_MAIN )
|
||||
#define EE_MAIN_FUNC extern "C"
|
||||
#else
|
||||
#define EE_MAIN_FUNC
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
struct NativeFileDialogHandler;
|
||||
|
||||
class EE_API UIFileDialog : public UIWindow {
|
||||
public:
|
||||
enum Flags {
|
||||
@@ -25,6 +27,8 @@ class EE_API UIFileDialog : public UIWindow {
|
||||
ShowOnlyFolders = ( 1 << 4 ),
|
||||
ShowHidden = ( 1 << 5 ),
|
||||
AllowMultiFileSelection = ( 1 << 6 ),
|
||||
UseNativeFileDialog =
|
||||
( 1 << 7 ), //< Uses the OS native file dialog if exists and it's available
|
||||
};
|
||||
|
||||
static const Uint32 DefaultFlags = UIFileDialog::Flags::FoldersFirst |
|
||||
@@ -107,18 +111,6 @@ class EE_API UIFileDialog : public UIWindow {
|
||||
|
||||
void setCloseShortcut( const KeyBindings::Shortcut& closeWithKey );
|
||||
|
||||
UIIcon* getIconNewFolder() const;
|
||||
|
||||
void setIconNewFolder( UIIcon* iconNewFolder );
|
||||
|
||||
UIIcon* getIconListView() const;
|
||||
|
||||
void setIconListView( UIIcon* iconListView );
|
||||
|
||||
UIIcon* getIconTableView() const;
|
||||
|
||||
void setIconTableView( UIIcon* iconTableView );
|
||||
|
||||
void setViewMode( const UIMultiModelView::ViewMode& viewMode );
|
||||
|
||||
const UIMultiModelView::ViewMode& getViewMode() const;
|
||||
@@ -129,8 +121,17 @@ class EE_API UIFileDialog : public UIWindow {
|
||||
|
||||
void setSingleClickNavigation( bool singleClickNavigation );
|
||||
|
||||
virtual bool show();
|
||||
|
||||
virtual bool hide();
|
||||
|
||||
bool usingNativeFileDialog() const;
|
||||
|
||||
virtual void scheduledUpdate( const Time& time );
|
||||
|
||||
protected:
|
||||
std::string mCurPath;
|
||||
std::string mFilePatterns;
|
||||
UIPushButton* mButtonOpen;
|
||||
UIPushButton* mButtonCancel;
|
||||
UIPushButton* mButtonUp;
|
||||
@@ -140,6 +141,7 @@ class EE_API UIFileDialog : public UIWindow {
|
||||
UIMultiModelView* mMultiView;
|
||||
UITextInput* mPath;
|
||||
UITextInput* mFile;
|
||||
std::string mFileName;
|
||||
UIDropDownList* mFiletype;
|
||||
Uint32 mDialogFlags;
|
||||
KeyBindings::Shortcut mCloseShortcut;
|
||||
@@ -147,6 +149,8 @@ class EE_API UIFileDialog : public UIWindow {
|
||||
std::shared_ptr<FileSystemModel> mModel;
|
||||
std::shared_ptr<DiskDrivesModel> mDiskDrivesModel;
|
||||
bool mDisplayingDrives{ false };
|
||||
NativeFileDialogHandler* mHandler{ nullptr };
|
||||
std::vector<std::string> mRes;
|
||||
|
||||
UIFileDialog( Uint32 dialogFlags = UIFileDialog::DefaultFlags,
|
||||
const std::string& defaultFilePattern = "*",
|
||||
|
||||
+3
-3
@@ -662,11 +662,11 @@ function generate_os_links()
|
||||
table.insert( os_links, "dl" )
|
||||
end
|
||||
elseif os.is_real("windows") then
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32", "uuid" } )
|
||||
elseif os.is_real("mingw32") then
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32", "uuid" } )
|
||||
elseif os.is_real("mingw64") then
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32", "uuid" } )
|
||||
elseif os.is_real("macosx") then
|
||||
multiple_insert( os_links, { "OpenGL.framework", "CoreFoundation.framework" } )
|
||||
elseif os.is_real("freebsd") then
|
||||
|
||||
+2
-2
@@ -484,9 +484,9 @@ function generate_os_links()
|
||||
table.insert( os_links, "dl" )
|
||||
end
|
||||
elseif os.istarget("windows") then
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32", "uuid" } )
|
||||
elseif os.istarget("mingw32") then
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
|
||||
multiple_insert( os_links, { "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32", "uuid" } )
|
||||
elseif os.istarget("macosx") then
|
||||
multiple_insert( os_links, { "OpenGL.framework", "CoreFoundation.framework" } )
|
||||
elseif os.istarget("bsd") then
|
||||
|
||||
@@ -152,6 +152,9 @@ void SceneNode::update( const Time& time ) {
|
||||
mScheduledUpdateRemove.clear();
|
||||
}
|
||||
|
||||
// TODO: Handle the case where one of the nodes updated generates the deletion of any of the
|
||||
// following nodes. As a rule user should always delete elements with a `close()` call.
|
||||
// But it's still allowed to just delete any running node.
|
||||
if ( !mScheduledUpdate.empty() ) {
|
||||
for ( auto& node : mScheduledUpdate )
|
||||
node->scheduledUpdate( time );
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
#include <portable-file-dialogs/portable-file-dialogs.h>
|
||||
#ifdef UUID
|
||||
#undef UUID
|
||||
#endif
|
||||
#ifdef KEY_EXECUTE
|
||||
#undef KEY_EXECUTE
|
||||
#endif
|
||||
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/system/log.hpp>
|
||||
#include <eepp/ui/models/filesystemmodel.hpp>
|
||||
@@ -16,6 +24,20 @@ namespace EE { namespace UI {
|
||||
#define FDLG_MIN_HEIGHT 400
|
||||
#define FDLG_DRIVE_PATH "drives://"
|
||||
|
||||
struct NativeFileDialogHandler {
|
||||
~NativeFileDialogHandler() {
|
||||
if ( saveFile )
|
||||
saveFile->kill();
|
||||
if ( openFile )
|
||||
openFile->kill();
|
||||
if ( selectFolder )
|
||||
selectFolder->kill();
|
||||
}
|
||||
std::unique_ptr<pfd::save_file> saveFile;
|
||||
std::unique_ptr<pfd::open_file> openFile;
|
||||
std::unique_ptr<pfd::select_folder> selectFolder;
|
||||
};
|
||||
|
||||
UIFileDialog* UIFileDialog::New( Uint32 dialogFlags, const std::string& defaultFilePattern,
|
||||
const std::string& defaultDirectory ) {
|
||||
return eeNew( UIFileDialog, ( dialogFlags, defaultFilePattern, defaultDirectory ) );
|
||||
@@ -25,8 +47,18 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa
|
||||
const std::string& defaultDirectory ) :
|
||||
UIWindow(),
|
||||
mCurPath( FileSystem::getRealPath( defaultDirectory ) ),
|
||||
mFilePatterns( defaultFilePattern ),
|
||||
mDialogFlags( dialogFlags ),
|
||||
mCloseShortcut( KEY_ESCAPE ) {
|
||||
|
||||
if ( usingNativeFileDialog() ) {
|
||||
mHandler = eeNew( NativeFileDialogHandler, () );
|
||||
String::replaceAll( mFilePatterns, ";", "" );
|
||||
setVisible( false );
|
||||
subscribeScheduledUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( getSize().getWidth() < FDLG_MIN_WIDTH ) {
|
||||
mDpSize.x = FDLG_MIN_WIDTH;
|
||||
mSize.x = PixelDensity::dpToPxI( FDLG_MIN_WIDTH );
|
||||
@@ -247,7 +279,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa
|
||||
->setLayoutWeight( 1 )
|
||||
->setParent( hLayout );
|
||||
mFiletype->setPopUpToRoot( true );
|
||||
mFiletype->getListBox()->addListBoxItem( defaultFilePattern );
|
||||
mFiletype->getListBox()->addListBoxItem( mFilePatterns );
|
||||
mFiletype->getListBox()->setSelected( 0 );
|
||||
mFiletype->setLayoutMargin( Rectf( 0, 0, 4, 0 ) );
|
||||
|
||||
@@ -270,9 +302,13 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa
|
||||
mUISceneNode->setIsLoading( loading );
|
||||
}
|
||||
|
||||
UIFileDialog::~UIFileDialog() {}
|
||||
UIFileDialog::~UIFileDialog() {
|
||||
eeSAFE_DELETE( mHandler );
|
||||
}
|
||||
|
||||
void UIFileDialog::onWindowReady() {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
updateClickStep();
|
||||
if ( isSaveDialog() ) {
|
||||
mFile->getDocument().selectAll();
|
||||
@@ -290,6 +326,8 @@ bool UIFileDialog::isType( const Uint32& type ) const {
|
||||
}
|
||||
|
||||
void UIFileDialog::setTheme( UITheme* Theme ) {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
UIWindow::setTheme( Theme );
|
||||
|
||||
mButtonOpen->setTheme( Theme );
|
||||
@@ -328,6 +366,9 @@ void UIFileDialog::setTheme( UITheme* Theme ) {
|
||||
}
|
||||
|
||||
void UIFileDialog::refreshFolder( bool resetScroll ) {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
FileSystem::dirAddSlashAtEnd( mCurPath );
|
||||
|
||||
if ( mCurPath == FDLG_DRIVE_PATH ) {
|
||||
@@ -379,6 +420,9 @@ void UIFileDialog::refreshFolder( bool resetScroll ) {
|
||||
}
|
||||
|
||||
void UIFileDialog::updateClickStep() {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
if ( mMultiView->getListView()->getVerticalScrollBar() ) {
|
||||
mMultiView->getListView()->getVerticalScrollBar()->setClickStep(
|
||||
1.f /
|
||||
@@ -398,6 +442,8 @@ void UIFileDialog::updateClickStep() {
|
||||
void UIFileDialog::setCurPath( const std::string& path ) {
|
||||
mCurPath = path;
|
||||
FileSystem::dirAddSlashAtEnd( mCurPath );
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
mPath->setText( mCurPath );
|
||||
if ( !isSaveDialog() )
|
||||
mFile->setText( "" );
|
||||
@@ -442,6 +488,9 @@ void UIFileDialog::onPressFileEnter( const Event* ) {
|
||||
}
|
||||
|
||||
void UIFileDialog::disableButtons() {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
mButtonOpen->setEnabled( false );
|
||||
mButtonCancel->setEnabled( false );
|
||||
mButtonUp->setEnabled( false );
|
||||
@@ -560,6 +609,9 @@ Uint32 UIFileDialog::onMessage( const NodeMessage* Msg ) {
|
||||
}
|
||||
|
||||
void UIFileDialog::save() {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
sendCommonEvent( Event::SaveFile );
|
||||
|
||||
disableButtons();
|
||||
@@ -568,6 +620,9 @@ void UIFileDialog::save() {
|
||||
}
|
||||
|
||||
void UIFileDialog::open() {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
auto fullPath( getFullPath() );
|
||||
|
||||
if ( mMultiView->getSelection().isEmpty() &&
|
||||
@@ -628,6 +683,9 @@ void UIFileDialog::onPressEnter( const Event* ) {
|
||||
}
|
||||
|
||||
void UIFileDialog::addFilePattern( std::string pattern, bool select ) {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
Uint32 index = mFiletype->getListBox()->addListBoxItem( pattern );
|
||||
|
||||
if ( select ) {
|
||||
@@ -691,11 +749,16 @@ void UIFileDialog::setShowHidden( const bool& showHidden ) {
|
||||
|
||||
void UIFileDialog::setAllowsMultiFileSelect( bool allow ) {
|
||||
BitOp::setBitFlagValue( &mDialogFlags, AllowMultiFileSelection, allow ? 1 : 0 );
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
mMultiView->setMultiSelect( allow );
|
||||
mFile->setEnabled( !allow );
|
||||
}
|
||||
|
||||
std::string UIFileDialog::getFullPath( size_t index ) const {
|
||||
if ( usingNativeFileDialog() )
|
||||
return index < mRes.size() ? mRes[index] : ( !mRes.empty() ? mRes[0] : "" );
|
||||
|
||||
if ( mDisplayingDrives )
|
||||
return getCurFile();
|
||||
|
||||
@@ -706,10 +769,15 @@ std::string UIFileDialog::getFullPath( size_t index ) const {
|
||||
}
|
||||
|
||||
std::string UIFileDialog::getFullPath() const {
|
||||
if ( usingNativeFileDialog() )
|
||||
return !mRes.empty() ? mRes[0] : "";
|
||||
return getFullPath( 0 );
|
||||
}
|
||||
|
||||
std::vector<std::string> UIFileDialog::getFullPaths() const {
|
||||
if ( usingNativeFileDialog() )
|
||||
return mRes;
|
||||
|
||||
if ( mDisplayingDrives )
|
||||
return { getCurFile() };
|
||||
|
||||
@@ -731,6 +799,9 @@ std::string UIFileDialog::getCurPath() const {
|
||||
}
|
||||
|
||||
std::string UIFileDialog::getCurFile( size_t index ) const {
|
||||
if ( usingNativeFileDialog() )
|
||||
return "";
|
||||
|
||||
if ( mDialogFlags & SaveDialog )
|
||||
return mFile->getText();
|
||||
if ( mMultiView->getSelection().isEmpty() )
|
||||
@@ -784,7 +855,7 @@ Uint32 UIFileDialog::onKeyDown( const KeyEvent& event ) {
|
||||
( mOpenShortut.mod == 0 || ( event.getMod() & mOpenShortut.mod ) ) ) {
|
||||
open();
|
||||
} else if ( mCloseShortcut && event.getKeyCode() == mCloseShortcut.key &&
|
||||
( mCloseShortcut.mod == 0 || ( event.getMod() & mCloseShortcut.mod ) ) ) {
|
||||
( mCloseShortcut.mod == 0 || ( event.getMod() & mCloseShortcut.mod ) ) ) {
|
||||
disableButtons();
|
||||
|
||||
closeWindow();
|
||||
@@ -798,6 +869,9 @@ const KeyBindings::Shortcut& UIFileDialog::getCloseShortcut() const {
|
||||
}
|
||||
|
||||
void UIFileDialog::setFileName( const std::string& name ) {
|
||||
mFileName = name;
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
if ( mFile )
|
||||
mFile->setText( name );
|
||||
}
|
||||
@@ -807,6 +881,9 @@ void UIFileDialog::setCloseShortcut( const KeyBindings::Shortcut& closeWithKey )
|
||||
}
|
||||
|
||||
void UIFileDialog::setViewMode( const UIMultiModelView::ViewMode& viewMode ) {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
mMultiView->setViewMode( viewMode );
|
||||
switch ( viewMode ) {
|
||||
case UIMultiModelView::ViewMode::Table:
|
||||
@@ -834,7 +911,117 @@ void UIFileDialog::setOpenShortut( const KeyBindings::Shortcut& newOpenShortut )
|
||||
}
|
||||
|
||||
void UIFileDialog::setSingleClickNavigation( bool singleClickNavigation ) {
|
||||
if ( usingNativeFileDialog() )
|
||||
return;
|
||||
mMultiView->setSingleClickNavigation( singleClickNavigation );
|
||||
}
|
||||
|
||||
bool UIFileDialog::show() {
|
||||
if ( usingNativeFileDialog() ) {
|
||||
if ( isSaveDialog() ) {
|
||||
std::string savePath( mCurPath );
|
||||
if ( !savePath.empty() ) {
|
||||
if ( FileSystem::isDirectory( savePath ) ) {
|
||||
FileSystem::dirAddSlashAtEnd( savePath );
|
||||
savePath += mFileName;
|
||||
}
|
||||
} else if ( !mFileName.empty() )
|
||||
savePath = mFileName;
|
||||
|
||||
mHandler->saveFile = std::make_unique<pfd::save_file>(
|
||||
getTitle().toUtf8(), savePath, std::vector<std::string>{ mFilePatterns } );
|
||||
} else {
|
||||
pfd::opt opt = pfd::opt::none;
|
||||
if ( mDialogFlags & UIFileDialog::AllowMultiFileSelection )
|
||||
opt = pfd::opt::multiselect;
|
||||
|
||||
if ( mDialogFlags & UIFileDialog::ShowOnlyFolders ) {
|
||||
mHandler->selectFolder =
|
||||
std::make_unique<pfd::select_folder>( getTitle().toUtf8(), mCurPath, opt );
|
||||
} else {
|
||||
mHandler->openFile = std::make_unique<pfd::open_file>(
|
||||
getTitle().toUtf8(), mCurPath, std::vector<std::string>{ mFilePatterns }, opt );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return UIWindow::show();
|
||||
}
|
||||
|
||||
bool UIFileDialog::hide() {
|
||||
if ( usingNativeFileDialog() ) {
|
||||
eeSAFE_DELETE( mHandler );
|
||||
mHandler = eeNew( NativeFileDialogHandler, () );
|
||||
return true;
|
||||
}
|
||||
return UIWindow::hide();
|
||||
}
|
||||
|
||||
bool UIFileDialog::usingNativeFileDialog() const {
|
||||
return ( mDialogFlags & Flags::UseNativeFileDialog ) && pfd::settings::available();
|
||||
}
|
||||
|
||||
void UIFileDialog::scheduledUpdate( const Time& time ) {
|
||||
if ( !usingNativeFileDialog() )
|
||||
return;
|
||||
|
||||
if ( mHandler->saveFile == nullptr && mHandler->openFile == nullptr &&
|
||||
mHandler->selectFolder == nullptr )
|
||||
return;
|
||||
|
||||
// Events are sent with delay because it must be sent outside the scheduledUpdate function
|
||||
// given that the even can generate a deletion of an element that will be removed during the
|
||||
// scheduledUpdate.
|
||||
if ( isSaveDialog() ) {
|
||||
if ( mHandler->saveFile && mHandler->saveFile->ready( 1 ) ) {
|
||||
if ( mHandler->saveFile->result().empty() ) {
|
||||
runOnMainThread( [this] {
|
||||
sendCommonEvent( Event::OnWindowClose );
|
||||
close();
|
||||
} );
|
||||
} else {
|
||||
mRes = { mHandler->saveFile->result() };
|
||||
runOnMainThread( [this] {
|
||||
sendCommonEvent( Event::SaveFile );
|
||||
close();
|
||||
} );
|
||||
}
|
||||
mHandler->saveFile.reset();
|
||||
}
|
||||
} else {
|
||||
if ( ( mDialogFlags & UIFileDialog::ShowOnlyFolders ) && mHandler->selectFolder &&
|
||||
mHandler->selectFolder->ready( 1 ) ) {
|
||||
if ( mHandler->selectFolder->result().empty() ) {
|
||||
runOnMainThread( [this] {
|
||||
sendCommonEvent( Event::OnWindowClose );
|
||||
close();
|
||||
} );
|
||||
} else {
|
||||
mRes = { mHandler->selectFolder->result() };
|
||||
|
||||
runOnMainThread( [this] {
|
||||
sendCommonEvent( Event::OpenFile );
|
||||
close();
|
||||
} );
|
||||
}
|
||||
mHandler->selectFolder.reset();
|
||||
} else if ( mHandler->openFile && mHandler->openFile->ready( 1 ) ) {
|
||||
if ( mHandler->openFile->result().empty() ) {
|
||||
runOnMainThread( [this] {
|
||||
sendCommonEvent( Event::OnWindowClose );
|
||||
close();
|
||||
} );
|
||||
} else {
|
||||
mRes = mHandler->openFile->result();
|
||||
|
||||
runOnMainThread( [this] {
|
||||
sendCommonEvent( Event::OpenFile );
|
||||
close();
|
||||
} );
|
||||
}
|
||||
mHandler->openFile.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace EE::UI
|
||||
|
||||
@@ -429,9 +429,7 @@ struct EngineInitializer {
|
||||
~EngineInitializer() { Engine::destroySingleton(); }
|
||||
};
|
||||
|
||||
#if EE_PLATFORM != EE_PLATFORM_ANDROID && EE_PLATFORM != EE_PLATFORM_IOS
|
||||
|
||||
#else
|
||||
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS
|
||||
|
||||
extern "C" int EE_SDL_main( int argc, char* argv[] );
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -124,6 +124,7 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath,
|
||||
ui.welcomeScreen = ini.getValueB( "ui", "welcome_screen", true );
|
||||
ui.openFilesInNewWindow = ini.getValueB( "ui", "open_files_in_new_window", false );
|
||||
ui.openProjectInNewWindow = ini.getValueB( "ui", "open_project_in_new_window", false );
|
||||
ui.nativeFileDialogs = ini.getValueB( "ui", "native_file_dialogs", false );
|
||||
ui.panelPosition = panelPositionFromString( ini.getValue( "ui", "panel_position", "left" ) );
|
||||
ui.serifFont = ini.getValue( "ui", "serif_font", "fonts/NotoSans-Regular.ttf" );
|
||||
ui.monospaceFont = ini.getValue( "ui", "monospace_font", "fonts/DejaVuSansMono.ttf" );
|
||||
@@ -307,6 +308,7 @@ void AppConfig::save( const std::vector<std::string>& recentFiles,
|
||||
ini.setValueB( "ui", "welcome_screen", ui.welcomeScreen );
|
||||
ini.setValueB( "ui", "open_files_in_new_window", ui.openFilesInNewWindow );
|
||||
ini.setValueB( "ui", "open_project_in_new_window", ui.openProjectInNewWindow );
|
||||
ini.setValueB( "ui", "native_file_dialogs", ui.nativeFileDialogs );
|
||||
ini.setValue( "ui", "panel_position", panelPositionToString( ui.panelPosition ) );
|
||||
ini.setValue( "ui", "serif_font", ui.serifFont );
|
||||
ini.setValue( "ui", "monospace_font", ui.monospaceFont );
|
||||
|
||||
@@ -34,6 +34,7 @@ struct UIConfig {
|
||||
bool welcomeScreen{ true };
|
||||
bool openFilesInNewWindow{ false };
|
||||
bool openProjectInNewWindow{ false };
|
||||
bool nativeFileDialogs{ false };
|
||||
PanelPosition panelPosition{ PanelPosition::Left };
|
||||
std::string serifFont;
|
||||
std::string monospaceFont;
|
||||
|
||||
+22
-14
@@ -348,8 +348,10 @@ void App::onDocumentUndoRedo( UICodeEditor* editor, TextDocument& doc ) {
|
||||
}
|
||||
|
||||
void App::openFileDialog() {
|
||||
UIFileDialog* dialog =
|
||||
UIFileDialog::New( UIFileDialog::DefaultFlags, "*", getDefaultFileDialogFolder() );
|
||||
UIFileDialog* dialog = UIFileDialog::New(
|
||||
UIFileDialog::DefaultFlags |
|
||||
( mConfig.ui.nativeFileDialogs ? UIFileDialog::UseNativeFileDialog : 0 ),
|
||||
"*", getDefaultFileDialogFolder() );
|
||||
dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
|
||||
dialog->setTitle( i18n( "open_file", "Open File" ) );
|
||||
dialog->setCloseShortcut( KEY_ESCAPE );
|
||||
@@ -400,10 +402,11 @@ void App::refreshFolderView() {
|
||||
}
|
||||
|
||||
void App::openFolderDialog() {
|
||||
UIFileDialog* dialog =
|
||||
UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect |
|
||||
UIFileDialog::ShowOnlyFolders,
|
||||
"*", getLastUsedFolder() );
|
||||
UIFileDialog* dialog = UIFileDialog::New(
|
||||
UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect |
|
||||
UIFileDialog::ShowOnlyFolders |
|
||||
( mConfig.ui.nativeFileDialogs ? UIFileDialog::UseNativeFileDialog : 0 ),
|
||||
"*", getLastUsedFolder() );
|
||||
dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
|
||||
dialog->setTitle( i18n( "open_folder", "Open Folder" ) );
|
||||
dialog->setCloseShortcut( KEY_ESCAPE );
|
||||
@@ -426,9 +429,11 @@ void App::openFontDialog( std::string& fontPath, bool loadingMonoFont, bool term
|
||||
std::string absoluteFontPath( fontPath );
|
||||
if ( FileSystem::isRelativePath( absoluteFontPath ) )
|
||||
absoluteFontPath = mResPath + fontPath;
|
||||
UIFileDialog* dialog =
|
||||
UIFileDialog::New( UIFileDialog::DefaultFlags, "*.ttf; *.otf; *.wolff; *.otb; *.bdf; *.ttc",
|
||||
FileSystem::fileRemoveFileName( absoluteFontPath ) );
|
||||
UIFileDialog* dialog = UIFileDialog::New(
|
||||
UIFileDialog::DefaultFlags |
|
||||
( mConfig.ui.nativeFileDialogs ? UIFileDialog::UseNativeFileDialog : 0 ),
|
||||
"*.ttf; *.otf; *.wolff; *.otb; *.bdf; *.ttc",
|
||||
FileSystem::fileRemoveFileName( absoluteFontPath ) );
|
||||
ModelIndex index = dialog->getMultiView()->getListView()->findRowWithText(
|
||||
FileSystem::fileNameFromPath( fontPath ), true, true );
|
||||
if ( index.isValid() )
|
||||
@@ -536,8 +541,11 @@ UIFileDialog* App::saveFileDialog( UICodeEditor* editor, bool focusOnClose ) {
|
||||
std::string folderPath( FileSystem::fileRemoveFileName( editor->getDocument().getFilePath() ) );
|
||||
if ( !FileSystem::isDirectory( folderPath ) )
|
||||
folderPath = getLastUsedFolder();
|
||||
UIFileDialog* dialog =
|
||||
UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "*", folderPath );
|
||||
UIFileDialog* dialog = UIFileDialog::New(
|
||||
UIFileDialog::DefaultFlags |
|
||||
( mConfig.ui.nativeFileDialogs ? UIFileDialog::UseNativeFileDialog : 0 ) |
|
||||
UIFileDialog::SaveDialog,
|
||||
"*", folderPath );
|
||||
dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
|
||||
dialog->setTitle( i18n( "save_file_as", "Save File As" ) );
|
||||
dialog->setCloseShortcut( KEY_ESCAPE );
|
||||
@@ -4340,8 +4348,8 @@ void App::init( InitParameters& params ) {
|
||||
Log::info( "Complete UI took: %.2f ms", globalClock.getElapsedTime().asMilliseconds() );
|
||||
|
||||
#if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
|
||||
if ( file == "./this.program" )
|
||||
file = "";
|
||||
if ( params.file == "./this.program" )
|
||||
params.file = "";
|
||||
#endif
|
||||
|
||||
if ( params.terminal && params.file.empty() && params.fileToOpen.empty() ) {
|
||||
@@ -4358,7 +4366,7 @@ void App::init( InitParameters& params ) {
|
||||
globalClock.getElapsedTime().asMilliseconds() );
|
||||
|
||||
#if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
|
||||
if ( file.empty() || !mFileToOpen.empty() )
|
||||
if ( params.file.empty() || !mFileToOpen.empty() )
|
||||
downloadFileWeb(
|
||||
mFileToOpen.empty()
|
||||
? "https://raw.githubusercontent.com/SpartanJ/eepp/develop/README.md"
|
||||
|
||||
@@ -1836,7 +1836,10 @@ void DebuggerPlugin::resolveInputsBeforeRun(
|
||||
} );
|
||||
} else if ( input.type == "pickfile" ) {
|
||||
UIFileDialog* dialog = UIFileDialog::New(
|
||||
UIFileDialog::DefaultFlags, "*", getPluginContext()->getDefaultFileDialogFolder() );
|
||||
UIFileDialog::DefaultFlags | ( getPluginContext()->getConfig().ui.nativeFileDialogs
|
||||
? UIFileDialog::UseNativeFileDialog
|
||||
: 0 ),
|
||||
"*", getPluginContext()->getDefaultFileDialogFolder() );
|
||||
dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL );
|
||||
dialog->setTitle( i18n( "open_file", "Open File" ) );
|
||||
dialog->setCloseShortcut( KEY_ESCAPE );
|
||||
|
||||
@@ -1285,6 +1285,16 @@ UIMenu* SettingsMenu::createWindowMenu() {
|
||||
"of the current window unless no project is currently loaded." ) )
|
||||
->setId( "open-project-in-new-window" );
|
||||
|
||||
mWindowMenu
|
||||
->addCheckBox( i18n( "use_native_file_dialogs", "Enable Native File Dialogs" ),
|
||||
mApp->getConfig().ui.nativeFileDialogs )
|
||||
->setTooltipText(
|
||||
i18n( "use_native_file_dialogs_tooltip",
|
||||
"Try to use the OS native file dialogs if they are available." ) )
|
||||
->setId( "native-file-dialogs" );
|
||||
|
||||
mWindowMenu->addSeparator();
|
||||
|
||||
mWindowMenu
|
||||
->addCheckBox( i18n( "welcome_screen_enable", "Enable Welcome Screen" ),
|
||||
mApp->getConfig().ui.welcomeScreen )
|
||||
@@ -1303,6 +1313,7 @@ UIMenu* SettingsMenu::createWindowMenu() {
|
||||
} else if ( "welcome-screen-enable" == item->getId() ) {
|
||||
bool active = item->asType<UIMenuCheckBox>()->isActive();
|
||||
mApp->getConfig().ui.welcomeScreen = active;
|
||||
mApp->saveConfig();
|
||||
} else if ( "open-files-in-new-window-enable" == item->getId() ) {
|
||||
bool active = item->asType<UIMenuCheckBox>()->isActive();
|
||||
mApp->getConfig().ui.openFilesInNewWindow = active;
|
||||
@@ -1311,6 +1322,10 @@ UIMenu* SettingsMenu::createWindowMenu() {
|
||||
bool active = item->asType<UIMenuCheckBox>()->isActive();
|
||||
mApp->getConfig().ui.openProjectInNewWindow = active;
|
||||
mApp->saveConfig();
|
||||
} else if ( "native-file-dialogs" == item->getId() ) {
|
||||
bool active = item->asType<UIMenuCheckBox>()->isActive();
|
||||
mApp->getConfig().ui.nativeFileDialogs = active;
|
||||
mApp->saveConfig();
|
||||
} else {
|
||||
String text = String( event->getNode()->asType<UIMenuItem>()->getId() ).toLower();
|
||||
String::replaceAll( text, " ", "-" );
|
||||
|
||||
Reference in New Issue
Block a user