diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/curry.cpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/curry.cpp index e8ffc4d64..edace6fb6 100644 --- a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/curry.cpp +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/curry.cpp @@ -36,7 +36,7 @@ SyntaxDefinition& addCurry() { "--", {} - } ); + } ).setBlockComment( { "{-", "-}" } ); } }}}} // namespace EE::UI::Doc::Language diff --git a/src/tools/ecode/applayout.xml.hpp b/src/tools/ecode/applayout.xml.hpp index 3a2a5f14f..aa9ef5a95 100644 --- a/src/tools/ecode/applayout.xml.hpp +++ b/src/tools/ecode/applayout.xml.hpp @@ -466,6 +466,13 @@ Anchor.error:hover { foreground-size: 10dp 10dp; foreground-position: center; } +#code_container Tab { + text-decoration: none; +} +#code_container Tab.tab_file_deleted { + color: var(--theme-error); + text-decoration: strikethrough; +} #code_container TabWidget::TabBar ScrollBarMini { opacity: 0; transition: opacity 0.15; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index bffe69857..ed99f8400 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2500,20 +2500,42 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { if ( !editor->getDocument().hasSyntaxDefinition() ) { editor->setSyntaxDefinition( editor->getDocument().guessSyntax() ); } + if ( editor->getData() ) { + UITab* tab = (UITab*)editor->getData(); + tab->removeClass( "tab_file_deleted" ); + } } ); editor->on( Event::OnDocumentDirtyOnFileSysten, [this, editor]( const Event* event ) { const DocEvent* docEvent = static_cast( event ); FileInfo file( docEvent->getDoc()->getFileInfo().getFilepath() ); TextDocument* doc = docEvent->getDoc(); - if ( doc->getFileInfo() != file ) { - if ( !mConfig.editor.autoReloadOnDiskChange || doc->isDirty() ) { - editor->runOnMainThread( [this, editor]() { createDocDirtyAlert( editor ); } ); - } else { - auto hash = String::hash( "OnDocumentDirtyOnFileSysten-" + - docEvent->getDoc()->getFilePath() ); - editor->removeActionsByTag( hash ); - editor->runOnMainThread( [doc]() { doc->reload(); }, Seconds( 0.5f ), hash ); + if ( FileSystem::fileExists( doc->getFileInfo().getFilepath() ) ) { // File modified! + if ( doc->getFileInfo() != file ) { + if ( !mConfig.editor.autoReloadOnDiskChange || doc->isDirty() ) { + editor->runOnMainThread( [this, editor]() { createDocDirtyAlert( editor ); } ); + } else { + auto hash = String::hash( "OnDocumentDirtyOnFileSysten-" + + docEvent->getDoc()->getFilePath() ); + editor->removeActionsByTag( hash ); + editor->runOnMainThread( + [doc, this]() { + auto docRef = mSplitter->getTextDocumentRef( doc ); + if ( docRef ) + docRef->reload(); + }, + Seconds( 0.5f ), hash ); + } + } + } else { // File deleted! + if ( editor->getData() ) { + UITab* tab = (UITab*)editor->getData(); + tab->ensureMainThread( [this, tab, doc] { + tab->addClass( "tab_file_deleted" ); + auto docRef = mSplitter->getTextDocumentRef( doc ); + if ( docRef ) + docRef->setDirtyUntilSave(); + } ); } } } ); @@ -2616,6 +2638,12 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { editor->on( Event::OnDocumentChanged, docChanged ); editor->on( Event::OnDocumentSave, docChanged ); editor->on( Event::OnEditorTabReady, docChanged ); + editor->on( Event::OnDocumentReloaded, [editor]( const Event* event ) { + if ( editor->getData() ) { + UITab* tab = (UITab*)editor->getData(); + tab->removeClass( "tab_file_deleted" ); + } + } ); editor->on( Event::OnCursorPosChangeInteresting, [this, editor]( auto ) { mSplitter->addEditorPositionToNavigationHistory( editor ); diff --git a/src/tools/ecode/filesystemlistener.cpp b/src/tools/ecode/filesystemlistener.cpp index 9df59a519..cb84de30d 100644 --- a/src/tools/ecode/filesystemlistener.cpp +++ b/src/tools/ecode/filesystemlistener.cpp @@ -71,6 +71,8 @@ void FileSystemListener::handleFileAction( efsw::WatchID, const std::string& dir if ( isFileOpen( oldFile ) ) notifyMove( oldFile, file ); } + } else if ( action == efsw::Actions::Delete ) { + notifyDelete( file ); } if ( file.isLink() ) @@ -145,7 +147,7 @@ void FileSystemListener::notifyChange( const FileInfo& file ) { file.getModificationTime() != doc.getFileInfo().getModificationTime() && !doc.isSaving() ) { MD5::Digest curHash = MD5::fromFile( file.getFilepath() ).digest; - if ( curHash != doc.getHash() ) { + if ( curHash != doc.getHash() || doc.isDirty() ) { Log::notice( "Document: \"%s\" has changed on the file system:", file.getFilepath().c_str() ); Log::notice( "Modification time on file system: %u vs %u in memory", @@ -166,6 +168,13 @@ void FileSystemListener::notifyMove( const FileInfo& oldFile, const FileInfo& ne } ); } +void FileSystemListener::notifyDelete( const FileInfo& file ) { + mSplitter->forEachDoc( [&]( TextDocument& doc ) { + if ( file.getFilepath() == doc.getFileInfo().getFilepath() ) + doc.setDirtyOnFileSystem( true ); + } ); +} + bool FileSystemListener::isIgnored( const std::string& path ) { return std::find( mIgnoredFiles.begin(), mIgnoredFiles.end(), path ) != mIgnoredFiles.end(); } diff --git a/src/tools/ecode/filesystemlistener.hpp b/src/tools/ecode/filesystemlistener.hpp index b9786c28a..985cbb5fd 100644 --- a/src/tools/ecode/filesystemlistener.hpp +++ b/src/tools/ecode/filesystemlistener.hpp @@ -53,6 +53,8 @@ class FileSystemListener : public efsw::FileWatchListener { void notifyMove( const FileInfo& oldFile, const FileInfo& newFile ); + void notifyDelete( const FileInfo& file ); + bool isIgnored( const std::string& path ); };