Added support to load documents asynchronously.
Added FileSystem::isRelativePath.
Added TextPosition::fromString and TextRange::fromString.
UICodeEditor: don't show currently loaded content until document load is complete.
Added UICodeEditorSplitter::loadAsyncFileFromPath and UICodeEditorSplitter::loadAsyncFileFromPathInNewTab.

ecode:
ecode now load documents async.
Fix: detect when an open document is open and has been moved in the file system, update the new location and name.
Remember document position and last focused document on project load.
This commit is contained in:
Martín Lucas Golini
2022-03-25 19:26:04 -03:00
parent 0ee4fa1bd7
commit 20b84171e9
18 changed files with 312 additions and 47 deletions

View File

@@ -79,6 +79,7 @@ class EE_API Event {
OnActiveWidgetChange,
OnWindowReady,
OnCreateContextMenu,
OnDocumentMoved,
UserEvent,
NoEvent = eeINDEX_NOT_FOUND
};

View File

@@ -150,6 +150,9 @@ class EE_API FileSystem {
const std::string& fileName,
const std::string& separator = ".",
const std::string& fileExtension = "" );
/** @returns True if the path provided is relative. */
static bool isRelativePath( const std::string& path );
};
}} // namespace EE::System

View File

@@ -8,6 +8,7 @@
#include <eepp/system/fileinfo.hpp>
#include <eepp/system/iostreamfile.hpp>
#include <eepp/system/pack.hpp>
#include <eepp/system/threadpool.hpp>
#include <eepp/system/time.hpp>
#include <eepp/ui/doc/syntaxdefinition.hpp>
#include <eepp/ui/doc/textdocumentline.hpp>
@@ -49,6 +50,7 @@ class EE_API TextDocument {
virtual void onDocumentSaved( TextDocument* ) = 0;
virtual void onDocumentClosed( TextDocument* ) = 0;
virtual void onDocumentDirtyOnFileSystem( TextDocument* ) = 0;
virtual void onDocumentMoved( TextDocument* ) = 0;
};
TextDocument( bool verbose = true );
@@ -67,6 +69,10 @@ class EE_API TextDocument {
bool loadFromFile( const std::string& path );
bool loadAsyncFromFile( const std::string& path, std::shared_ptr<ThreadPool> pool,
std::function<void( TextDocument*, bool )> onLoaded =
std::function<void( TextDocument*, bool success )>() );
bool loadFromMemory( const Uint8* data, const Uint32& size );
bool loadFromPack( Pack* pack, std::string filePackPath );
@@ -404,6 +410,8 @@ class EE_API TextDocument {
bool hasSyntaxDefinition() const;
void notifyDocumentMoved( const std::string& newPath );
protected:
friend class UndoStack;
UndoStack mUndoStack;
@@ -457,6 +465,8 @@ class EE_API TextDocument {
void notifyDirtyOnFileSystem();
void notifyDocumentMoved();
void insertAtStartOfSelectedLines( const String& text, bool skipEmpty );
void removeFromStartOfSelectedLines( const String& text, bool skipEmpty );

View File

@@ -48,26 +48,40 @@ class EE_API TextPosition {
}
TextPosition operator+( const TextPosition& other ) const {
return {mLine + other.line(), mColumn + other.column()};
return { mLine + other.line(), mColumn + other.column() };
}
TextPosition operator+=( const TextPosition& other ) const {
return {mLine + other.line(), mColumn + other.column()};
return { mLine + other.line(), mColumn + other.column() };
}
TextPosition operator-( const TextPosition& other ) const {
return {mLine - other.line(), mColumn - other.column()};
return { mLine - other.line(), mColumn - other.column() };
}
TextPosition operator-=( const TextPosition& other ) const {
return {mLine - other.line(), mColumn - other.column()};
return { mLine - other.line(), mColumn - other.column() };
}
std::string toString() { return String::format( "L%lld,C%lld", mLine, mColumn ); }
std::string toString() const { return String::format( "L%lld,C%lld", mLine, mColumn ); }
static TextPosition fromString( const std::string& pos ) {
auto split = String::split( pos, ',' );
if ( split.size() == 2 && !split[0].empty() && !split[1].empty() ) {
if ( split[0][0] == 'L' || split[0][0] == 'l' )
split[0] = split[0].substr( 1 );
if ( split[1][0] == 'C' || split[0][0] == 'c' )
split[1] = split[1].substr( 1 );
Int64 l, c;
if ( String::fromString( l, split[0] ) && String::fromString( c, split[1] ) )
return TextPosition( l, c );
}
return {};
}
private:
Int64 mLine{0xffffffff};
Int64 mColumn{0xffffffff};
Int64 mLine{ 0xffffffff };
Int64 mColumn{ 0xffffffff };
};
}}} // namespace EE::UI::Doc

View File

@@ -61,10 +61,19 @@ class EE_API TextRange {
bool inSameLine() const { return isValid() && mStart.line() == mEnd.line(); }
std::string toString() {
std::string toString() const {
return String::format( "%s - %s", mStart.toString().c_str(), mEnd.toString().c_str() );
}
static TextRange fromString( const std::string& range ) {
auto split = String::split( range, "-" );
if ( split.size() == 2 ) {
return { TextPosition::fromString( String::trim( split[0] ) ),
TextPosition::fromString( String::trim( split[1] ) ) };
}
return {};
}
private:
TextPosition mStart;
TextPosition mEnd;

View File

@@ -75,8 +75,18 @@ class EE_API UICodeEditorSplitter {
bool loadFileFromPath( const std::string& path, UICodeEditor* codeEditor = nullptr );
void loadAsyncFileFromPath( const std::string& path, std::shared_ptr<ThreadPool> pool,
UICodeEditor* codeEditor = nullptr,
std::function<void( UICodeEditor*, const std::string& )> onLoaded =
std::function<void( UICodeEditor*, const std::string& )>() );
void loadFileFromPathInNewTab( const std::string& path );
void loadAsyncFileFromPathInNewTab(
const std::string& path, std::shared_ptr<ThreadPool> pool,
std::function<void( UICodeEditor*, const std::string& )> onLoaded =
std::function<void( UICodeEditor*, const std::string& )>() );
void removeUnusedTab( UITabWidget* tabWidget );
UITabWidget* createEditorWithTabWidget( Node* parent );
@@ -129,6 +139,8 @@ class EE_API UICodeEditorSplitter {
void setHideTabBarOnSingleTab( bool hideTabBarOnSingleTab );
const std::vector<UITabWidget*>& getTabWidgets() const;
protected:
UISceneNode* mUISceneNode{ nullptr };
UICodeEditor* mCurEditor{ nullptr };

View File

@@ -114,6 +114,10 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
bool loadFromFile( const std::string& path );
bool loadAsyncFromFile( const std::string& path, std::shared_ptr<ThreadPool> pool,
std::function<void( std::shared_ptr<TextDocument>, bool )> onLoaded =
std::function<void( std::shared_ptr<TextDocument>, bool )>() );
bool loadFromURL(
const std::string& url,
const EE::Network::Http::Request::FieldTable& headers = Http::Request::FieldTable() );
@@ -417,6 +421,10 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
void copyFilePath();
void scrollToCursor( bool centered = true );
void scrollToMakeVisible( const TextPosition& position, bool centered = false );
protected:
struct LastXOffset {
TextPosition position;
@@ -547,6 +555,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
virtual void onDocumentSaved( TextDocument* );
virtual void onDocumentMoved( TextDocument* );
void onDocumentClosed( TextDocument* doc );
virtual void onDocumentDirtyOnFileSystem( TextDocument* doc );
@@ -555,8 +565,6 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
int getVisibleLinesCount();
void scrollToMakeVisible( const TextPosition& position, bool centered = false );
void setScrollX( const Float& val, bool emmitEvent = true );
void setScrollY( const Float& val, bool emmitEvent = true );

View File

@@ -177,6 +177,8 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client {
virtual void onDocumentSaved( TextDocument* );
virtual void onDocumentMoved( TextDocument* );
void onDocumentClosed( TextDocument* ){};
void onDocumentDirtyOnFileSystem( TextDocument* ){};