diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/gnuplot.cpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/gnuplot.cpp new file mode 100644 index 000000000..b4b3a7398 --- /dev/null +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/gnuplot.cpp @@ -0,0 +1,249 @@ +#include +#include + +namespace EE { namespace UI { namespace Doc { namespace Language { + +SyntaxDefinition& addGnuplot() { + + // Direct conversion from https://github.com/mammothb/vscode-gnuplot (MIT License) + + return SyntaxDefinitionManager::instance() + ->add( + + { "gnuplot", + { "%.gp$", "%.gnuplot$", "%.gnu$", "%.plot$", "%.plt$" }, + { + { { "include", "#number" }, "normal", "", SyntaxPatternMatchType::LuaPattern }, + { { "include", "#string_single" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { "include", "#string_double" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { "\\b(for)\\b\\s*(\\[)", "\\]" }, + { "normal", "keyword", "operator" }, + { "operator" }, + "", + SyntaxPatternMatchType::RegEx, + { + { { "include", "#number" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { "include", "#operator" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { "include", "#string_double" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { "include", "#string_single" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { ":" }, "operator", "", SyntaxPatternMatchType::RegEx }, + { { "\\b([a-zA-Z]\\w*)\\b\\s*(=|in)" }, + "normal", + "", + SyntaxPatternMatchType::RegEx }, + + } }, + { { "\\[", "\\]" }, + { "operator" }, + { "operator" }, + "", + SyntaxPatternMatchType::RegEx, + { + { { "include", "#number" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { "include", "#operator" }, + "normal", + "", + SyntaxPatternMatchType::LuaPattern }, + { { ":" }, "operator", "", SyntaxPatternMatchType::RegEx }, + + } }, + { { "\\\\." }, "string", "", SyntaxPatternMatchType::RegEx }, + { { "(?|>=|<|<=|&|&&|:|\\||\\|\\||\\+|-|\\*|\\.\\*|/|\\./" + "|\\\\|\\.\\\\|\\^|\\.\\^)\\s*" }, + "operator", + "", + SyntaxPatternMatchType::RegEx }, + + } }, + { "number", + { + { { "(?x: # turn on extended mode\n -? # an " + "optional minus\n (?:\n [0-9] # a 0-9 " + "character\n \\d* # followed by zero or more digits\n " + " )\n (?:\n \\. # a " + "period\n \\d+ # followed by one or more digits\n " + " )? # make decimal portion optional\n (?:\n " + " [eE] # an e character\n [+-]? # " + "followed by an option +/-\n \\d+ # followed by one or " + "more digits\n (?:\n \\. # a period\n " + " \\d+ # followed by one or more digits\n " + ")? # make decimal in exponent power optional\n )? " + "# make exponent optional\n )" }, + "number", + "", + SyntaxPatternMatchType::RegEx }, + + } }, + } ); +} + +}}}} // namespace EE::UI::Doc::Language diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/gnuplot.hpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/gnuplot.hpp new file mode 100644 index 000000000..635a6b48b --- /dev/null +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/gnuplot.hpp @@ -0,0 +1,11 @@ +#ifndef EE_UI_DOC_Gnuplot +#define EE_UI_DOC_Gnuplot +#include + +namespace EE { namespace UI { namespace Doc { namespace Language { + +extern SyntaxDefinition& addGnuplot(); + +}}}} // namespace EE::UI::Doc::Language + +#endif diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp index fccc68e38..612f2f043 100644 --- a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languagessyntaxhighlighting.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -354,6 +355,10 @@ void LanguagesSyntaxHighlighting::load() { sdm->addPreDefinition( { "GN", []() -> SyntaxDefinition& { return addGn(); }, { "%.gn$" } } ); + sdm->addPreDefinition( { "gnuplot", + []() -> SyntaxDefinition& { return addGnuplot(); }, + { "%.gp$", "%.gnuplot$", "%.gnu$", "%.plot$", "%.plt$" } } ); + sdm->addPreDefinition( { "Go", []() -> SyntaxDefinition& { return addGo(); }, { "%.go$" } } ); sdm->addPreDefinition( { diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index d19294264..fe2c2359e 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2254,8 +2254,8 @@ void App::loadImageFromPath( const std::string& path ) { void App::openFileFromPath( const std::string& path ) { std::string ext = FileSystem::fileExtension( path ); - bool canOpenBinaryFile = PathHelper::isOpenExternalExtension( ext ); - if ( !canOpenBinaryFile && TextDocument::fileMightBeBinary( path ) ) { + if ( !Image::isImageExtension( path ) && !PathHelper::isOpenExternalExtension( ext ) && + TextDocument::fileMightBeBinary( path ) ) { auto msgBox = UIMessageBox::New( UIMessageBox::YES_NO, i18n( "open_binary_file_warning", @@ -2297,10 +2297,10 @@ bool App::loadFileFromPath( return false; } - if ( !openBinaryAsDocument && PathHelper::isOpenExternalExtension( ext ) ) { - Engine::instance()->openURI( path ); - } else if ( Image::isImageExtension( path ) && Image::isImage( path ) && ext != "svg" ) { + if ( Image::isImageExtension( path ) && Image::isImage( path ) && ext != "svg" ) { loadImageFromPath( path ); + } else if ( !openBinaryAsDocument && PathHelper::isOpenExternalExtension( ext ) ) { + Engine::instance()->openURI( path ); } else { UITab* tab = mSplitter->isDocumentOpen( path ); diff --git a/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp b/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp index adcdd2a31..a3a63c35d 100644 --- a/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp +++ b/src/tools/ecode/plugins/spellchecker/spellcheckerplugin.cpp @@ -1,6 +1,7 @@ #include "spellcheckerplugin.hpp" #include "eepp/ui/abstract/uiabstractview.hpp" #include "eepp/ui/models/itemlistmodel.hpp" +#include "eepp/window/engine.hpp" #include #include #include @@ -109,6 +110,7 @@ void SpellCheckerPlugin::load( PluginManager* pluginManager ) { } subscribeFileSystemListener(); + mTyposFound = !Sys::which( SPELL_CHECKER_CMD ).empty(); mReady = true; fireReadyCbs(); setReady( clock.getElapsedTime() ); @@ -520,8 +522,29 @@ void SpellCheckerPlugin::replaceMatchWithText( const TextRange& range, const std bool SpellCheckerPlugin::onCreateContextMenu( UICodeEditor* editor, UIPopUpMenu* menu, const Vector2i& position, const Uint32& /*flags*/ ) { - if ( !mTyposFound ) + + auto addFn = [this]( UIPopUpMenu* subMenu, const std::string& txtKey, const std::string& txtVal, + const std::string& icon = "" ) { + subMenu + ->add( i18n( txtKey, txtVal ), + !icon.empty() ? findIcon( icon )->getSize( PixelDensity::dpToPxI( 12 ) ) + : nullptr, + KeyBindings::keybindFormat( mKeyBindings[txtKey] ) ) + ->setId( txtKey ); + }; + + if ( !mTyposFound ) { + menu->addSeparator(); + auto* subMenu = UIPopUpMenu::New(); + subMenu->addClass( "spellchecker_menu" ); + subMenu->on( Event::OnItemClicked, []( const Event* ) { + Engine::instance()->openURI( "https://github.com/crate-ci/typos/" ); + } ); + addFn( subMenu, "spell-checker-not-installed", + "Install the typos tool to have spell-checking (click to open typos site)" ); + menu->addSubMenu( i18n( "spell-checker", "Spell Checker" ), nullptr, subMenu ); return false; + } auto pickedMatch = getMatchFromScreenPos( editor, position.asFloat() ); if ( !pickedMatch ) @@ -538,18 +561,8 @@ bool SpellCheckerPlugin::onCreateContextMenu( UICodeEditor* editor, UIPopUpMenu* replaceMatchWithText( range, id, editor ); } ); - auto addFn = [this, subMenu]( const std::string& txtKey, const std::string& txtVal, - const std::string& icon = "" ) { - subMenu - ->add( i18n( txtKey, txtVal ), - !icon.empty() ? findIcon( icon )->getSize( PixelDensity::dpToPxI( 12 ) ) - : nullptr, - KeyBindings::keybindFormat( mKeyBindings[txtKey] ) ) - ->setId( txtKey ); - }; - for ( const auto& alt : pickedMatch->alternatives ) - addFn( alt, alt ); + addFn( subMenu, alt, alt ); menu->addSubMenu( i18n( "spell-checker", "Spell Checker" ), nullptr, subMenu );