From 4fa35ffa833a083d8c756023c99a8280dd5f4b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 8 Feb 2023 19:53:33 -0300 Subject: [PATCH] Closes SpartanJ/ecode#33. --- include/eepp/config.hpp | 11 ++++++----- include/eepp/ui/doc/textdocument.hpp | 6 ++++-- include/eepp/ui/tools/uicodeeditorsplitter.hpp | 8 +++++++- premake5.lua | 2 +- projects/linux/ee.creator.user | 2 +- src/eepp/ui/doc/textdocument.cpp | 8 ++++++-- src/eepp/ui/tools/uicodeeditorsplitter.cpp | 5 ++++- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/include/eepp/config.hpp b/include/eepp/config.hpp index 87c6b98cc..df062351d 100644 --- a/include/eepp/config.hpp +++ b/include/eepp/config.hpp @@ -145,11 +145,12 @@ #ifndef EE_ENDIAN -#if defined( __386__ ) || defined( i386 ) || defined( __i386__ ) || defined( __X86 ) || \ - defined( _M_IX86 ) || defined( _M_X64 ) || defined( __x86_64__ ) || defined( alpha ) || \ - defined( __alpha ) || defined( __alpha__ ) || defined( _M_ALPHA ) || defined( ARM ) || \ - defined( _ARM ) || defined( __arm__ ) || defined( WIN32 ) || defined( _WIN32 ) || \ - defined( __WIN32__ ) || defined( _WIN32_WCE ) || defined( __NT__ ) || defined( __MIPSEL__ ) +#if defined( __386__ ) || defined( i386 ) || defined( __i386__ ) || defined( __X86 ) || \ + defined( _M_IX86 ) || defined( _M_X64 ) || defined( __x86_64__ ) || defined( alpha ) || \ + defined( __alpha ) || defined( __alpha__ ) || defined( _M_ALPHA ) || defined( ARM ) || \ + defined( _ARM ) || defined( __arm__ ) || defined( WIN32 ) || defined( _WIN32 ) || \ + defined( __WIN32__ ) || defined( _WIN32_WCE ) || defined( __NT__ ) || defined( __MIPSEL__ ) || \ + defined( EE_ARM ) #define EE_ENDIAN EE_LITTLE_ENDIAN #else #define EE_ENDIAN EE_BIG_ENDIAN diff --git a/include/eepp/ui/doc/textdocument.hpp b/include/eepp/ui/doc/textdocument.hpp index 12c370688..a9d63db11 100644 --- a/include/eepp/ui/doc/textdocument.hpp +++ b/include/eepp/ui/doc/textdocument.hpp @@ -92,9 +92,11 @@ class EE_API TextDocument { bool isNonWord( String::StringBaseType ch ) const; - bool hasFilepath(); + bool hasFilepath() const; - bool isEmpty(); + bool isEmpty() const; + + bool isUntitledEmpty() const; void reset(); diff --git a/include/eepp/ui/tools/uicodeeditorsplitter.hpp b/include/eepp/ui/tools/uicodeeditorsplitter.hpp index 46206ed84..dc32abef0 100644 --- a/include/eepp/ui/tools/uicodeeditorsplitter.hpp +++ b/include/eepp/ui/tools/uicodeeditorsplitter.hpp @@ -200,7 +200,13 @@ class EE_API UICodeEditorSplitter { t.setCommand( "close-tab", [&] { tryTabClose( mCurWidget ); } ); t.setCommand( "create-new", [&] { auto d = createCodeEditorInTabWidget( tabWidgetFromWidget( mCurWidget ) ); - d.first->getTabWidget()->setTabSelected( d.first ); + if ( d.first != nullptr && d.second != nullptr ) { + d.first->getTabWidget()->setTabSelected( d.first ); + } else if ( !mTabWidgets.empty() ) { + d = createCodeEditorInTabWidget( mTabWidgets[0] ); + } + if ( d.first == nullptr || d.second == nullptr ) + Log::error( "Couldn't createCodeEditorInTabWidget in create-new command" ); } ); t.setCommand( "next-tab", [&] { UITabWidget* tabWidget = tabWidgetFromWidget( mCurWidget ); diff --git a/premake5.lua b/premake5.lua index 68b86af4d..cbe5d32bb 100644 --- a/premake5.lua +++ b/premake5.lua @@ -366,7 +366,7 @@ end function generate_os_links() if os.istarget("linux") then - multiple_insert( os_links, { "rt", "pthread", "GL", "Xcursor" } ) + multiple_insert( os_links, { "rt", "pthread", "GL" } ) if _OPTIONS["with-static-eepp"] then table.insert( os_links, "dl" ) diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index b9af487d0..c6387f05f 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 9ac05f1ab..ea0f2ddfa 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -48,14 +48,18 @@ TextDocument::~TextDocument() { FileSystem::fileRemove( mFilePath ); } -bool TextDocument::hasFilepath() { +bool TextDocument::hasFilepath() const { return mDefaultFileName != mFilePath; } -bool TextDocument::isEmpty() { +bool TextDocument::isEmpty() const { return linesCount() == 1 && line( 0 ).size() == 1; } +bool TextDocument::isUntitledEmpty() const { + return isEmpty() && !hasFilepath(); +} + void TextDocument::reset() { mFilePath = mDefaultFileName; mFileRealPath = FileInfo(); diff --git a/src/eepp/ui/tools/uicodeeditorsplitter.cpp b/src/eepp/ui/tools/uicodeeditorsplitter.cpp index e0e63bc28..4a7ee7f72 100644 --- a/src/eepp/ui/tools/uicodeeditorsplitter.cpp +++ b/src/eepp/ui/tools/uicodeeditorsplitter.cpp @@ -835,8 +835,11 @@ void UICodeEditorSplitter::closeTab( UIWidget* widget ) { if ( tabWidget ) { if ( !( editor->getDocument().isEmpty() && !tabWidget->getParent()->isType( UI_TYPE_SPLITTER ) && - tabWidget->getTabCount() == 1 ) ) { + tabWidget->getTabCount() == 1 ) || + !editor->getDocument().isUntitledEmpty() ) { tabWidget->removeTab( (UITab*)editor->getData() ); + } else { + return; } } } else {