Skip to content

Commit

Permalink
ecode: Added an option to configure the default shell used by ecode t…
Browse files Browse the repository at this point in the history
…erminal.

Closes SpartanJ/ecode#70.
  • Loading branch information
SpartanJ committed Mar 5, 2023
1 parent d2caa0d commit 7d7a97e
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 24 deletions.
2 changes: 2 additions & 0 deletions include/eepp/ui/uicombobox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class EE_API UIComboBox : public UIWidget {

const String& getText();

void setText( const String& text );

virtual bool applyProperty( const StyleSheetProperty& attribute );

virtual std::string getPropertyString( const PropertyDefinition* propertyDef,
Expand Down
2 changes: 1 addition & 1 deletion include/eepp/ui/uilistbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EE_API UIListBox : public UITouchDraggableWidget {

void clear();

void addListBoxItems( std::vector<String> Texts );
void addListBoxItems( std::vector<String> texts );

Uint32 addListBoxItem( const String& Text );

Expand Down
2 changes: 1 addition & 1 deletion include/eepp/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define EEPP_MAJOR_VERSION 2
#define EEPP_MINOR_VERSION 5
#define EEPP_PATCH_LEVEL 8
#define EEPP_PATCH_LEVEL 9
#define EEPP_CODENAME "Bindu"

/** The compiled version of the library */
Expand Down
4 changes: 4 additions & 0 deletions src/eepp/ui/uicombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const String& UIComboBox::getText() {
return mDropDownList->getText();
}

void UIComboBox::setText( const String& text ) {
mDropDownList->setText( text );
}

void UIComboBox::loadFromXmlNode( const pugi::xml_node& node ) {
beginAttributesTransaction();

Expand Down
10 changes: 5 additions & 5 deletions src/eepp/ui/uilistbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ UIScrollBar* UIListBox::getHorizontalScrollBar() const {
return mHScrollBar;
}

void UIListBox::addListBoxItems( std::vector<String> Texts ) {
mItems.reserve( mItems.size() + Texts.size() );
mTexts.reserve( mTexts.size() + Texts.size() );
void UIListBox::addListBoxItems( std::vector<String> texts ) {
mItems.reserve( mItems.size() + texts.size() );
mTexts.reserve( mTexts.size() + texts.size() );

for ( Uint32 i = 0; i < Texts.size(); i++ ) {
mTexts.push_back( Texts[i] );
for ( Uint32 i = 0; i < texts.size(); i++ ) {
mTexts.push_back( std::move( texts[i] ) );
mItems.push_back( NULL );
}

Expand Down
3 changes: 1 addition & 2 deletions src/eepp/ui/uipushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ bool UIPushButton::applyProperty( const StyleSheetProperty& attribute ) {
switch ( attribute.getPropertyDefinition()->getPropertyId() ) {
case PropertyId::Text:
if ( NULL != mSceneNode && mSceneNode->isUISceneNode() )
setText( static_cast<UISceneNode*>( mSceneNode )
->getTranslatorString( attribute.asString() ) );
setText( getUISceneNode()->getTranslatorString( attribute.asString() ) );
break;
case PropertyId::Icon: {
std::string val = attribute.asString();
Expand Down
2 changes: 1 addition & 1 deletion src/eepp/ui/uiwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ bool UIWindow::applyProperty( const StyleSheetProperty& attribute ) {
setSize( getSize().getWidth(), attribute.asDpDimension( this ) );
break;
case PropertyId::WindowTitle:
setTitle( attribute.asString() );
setTitle( getUISceneNode()->getTranslatorString( attribute.asString() ) );
break;
case PropertyId::WindowOpacity:
setWindowOpacity( (Uint8)eemin<Uint32>( (Uint32)attribute.asFloat() * 255.f, 255u ) );
Expand Down
2 changes: 1 addition & 1 deletion src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ TerminalDisplay::create( EE::Window::Window* window, Font* font, const Float& fo
if ( program.empty() ) {
const char* shellenv = getenv( "SHELL" );
#ifdef _WIN32
program = shellenv != nullptr ? shellenv : "cmd.exe";
program = shellenv != nullptr ? shellenv : "powershell.exe";
#else
#if EE_PLATFORM == EE_PLATFORM_ANDROID
program = shellenv != nullptr ? shellenv : "/bin/sh";
Expand Down
2 changes: 2 additions & 0 deletions src/tools/ecode/appconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath,
globalSearchBarConfig.escapeSequence =
ini.getValueB( "global_search_bar", "escape_sequence", false );

term.shell = ini.getValue( "terminal", "shell" );
term.fontSize = ini.getValue( "terminal", "font_size", "11dp" );
term.colorScheme = ini.getValue( "terminal", "colorscheme", "eterm" );

Expand Down Expand Up @@ -246,6 +247,7 @@ void AppConfig::save( const std::vector<std::string>& recentFiles,
ini.setValueB( "global_search_bar", "whole_word", globalSearchBarConfig.wholeWord );
ini.setValueB( "global_search_bar", "escape_sequence", globalSearchBarConfig.escapeSequence );

ini.setValue( "terminal", "shell", term.shell );
ini.setValue( "terminal", "font_size", term.fontSize.toString() );
ini.setValue( "terminal", "colorscheme", term.colorScheme );

Expand Down
1 change: 1 addition & 0 deletions src/tools/ecode/appconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct ProjectDocumentConfig {
};

struct TerminalConfig {
std::string shell;
std::string colorScheme{ "eterm" };
StyleSheetLength fontSize{ 11, StyleSheetLength::Dp };
};
Expand Down
5 changes: 3 additions & 2 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,8 @@ std::string App::getCurrentWorkingDir() const {
if ( !mCurrentProject.empty() )
return mCurrentProject;

if ( mSplitter && mSplitter->curEditorIsNotNull() && mSplitter->getCurEditor()->hasDocument() &&
if ( mSplitter && mSplitter->curEditorIsNotNull() && mSplitter->curEditorExists() &&
mSplitter->getCurEditor()->hasDocument() &&
mSplitter->getCurEditor()->getDocument().hasFilepath() ) {
return mSplitter->getCurEditor()->getDocument().getFileInfo().getDirectoryPath();
}
Expand Down Expand Up @@ -3084,7 +3085,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe
{ "cursor-pointer", 0xec09 },
{ "drive", 0xedf8 },
{ "refresh", 0xf064 },
};
{ "hearth-pulse", 0xee10 } };
for ( const auto& icon : icons )
iconTheme->add( UIGlyphIcon::New( icon.first, iconFont, icon.second ) );

Expand Down
4 changes: 4 additions & 0 deletions src/tools/ecode/ecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ class App : public UICodeEditorSplitter::Client {
t.setCommand( "fallback-font", [&] { openFontDialog( mConfig.ui.fallbackFont, false ); } );
t.setCommand( "tree-view-configure-ignore-files", [&] { treeViewConfigureIgnoreFiles(); } );
t.setCommand( "check-languages-health", [&] { checkLanguagesHealth(); } );
t.setCommand( "configure-terminal-shell", [&] {
if ( mTerminalManager )
mTerminalManager->configureTerminalShell();
} );
mSplitter->registerSplitterCommands( t );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AutoCompletePlugin : public UICodeEditorPlugin {
"Auto complete shows the completion popup as you type, so you can fill "
"in long words by typing only a few characters.",
AutoCompletePlugin::New,
{ 0, 1, 0 } };
{ 0, 2, 0 } };
}

static UICodeEditorPlugin* New( PluginManager* pluginManager );
Expand Down
2 changes: 1 addition & 1 deletion src/tools/ecode/plugins/formatter/formatterplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FormatterPlugin : public UICodeEditorPlugin {
static PluginDefinition Definition() {
return {
"autoformatter", "Auto Formatter", "Enables the code formatter/prettifier plugin.",
FormatterPlugin::New, { 0, 1, 0 }, FormatterPlugin::NewSync };
FormatterPlugin::New, { 0, 2, 0 }, FormatterPlugin::NewSync };
}

static UICodeEditorPlugin* New( PluginManager* pluginManager );
Expand Down
2 changes: 1 addition & 1 deletion src/tools/ecode/plugins/linter/linterplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LinterPlugin : public UICodeEditorPlugin {
"Use static code analysis tool used to flag programming errors, bugs, "
"stylistic errors, and suspicious constructs.",
LinterPlugin::New,
{ 0, 1, 0 },
{ 0, 2, 0 },
LinterPlugin::NewSync };
}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/ecode/plugins/lsp/lspclientplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LSPClientPlugin : public UICodeEditorPlugin {
public:
static PluginDefinition Definition() {
return { "lspclient", "LSP Client", "Language Server Protocol Client.",
LSPClientPlugin::New, { 0, 0, 2 }, LSPClientPlugin::NewSync };
LSPClientPlugin::New, { 0, 2, 0 }, LSPClientPlugin::NewSync };
}

static UICodeEditorPlugin* New( PluginManager* pluginManager );
Expand Down
18 changes: 16 additions & 2 deletions src/tools/ecode/settingsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,13 @@ UIMenu* SettingsMenu::createTerminalMenu() {
getKeybind( "terminal-rename" ) )
->setId( "terminal-rename" );

mTerminalMenu->addSeparator();

mTerminalMenu
->add( i18n( "configure_terminal_shell", "Configure Terminal Shell" ),
findIcon( "terminal" ), getKeybind( "configure-terminal-shell" ) )
->setId( "configure-terminal-shell" );

mTerminalMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) {
const std::string& id( event->getNode()->getId() );
if ( mSplitter->getCurWidget() && mSplitter->getCurWidget()->isType( UI_TYPE_TERMINAL ) ) {
Expand Down Expand Up @@ -1222,12 +1229,19 @@ UIPopUpMenu* SettingsMenu::createToolsMenu() {
mToolsMenu->addSeparator();

mToolsMenu
->add( i18n( "check_languages_health", "Check Languages Health" ), nullptr,
getKeybind( "check-languages-health" ) )
->add( i18n( "check_languages_health", "Check Languages Health" ),
findIcon( "hearth-pulse" ), getKeybind( "check-languages-health" ) )
->setId( "check-languages-health" );

mToolsMenu->addSeparator();

mToolsMenu
->add( i18n( "configure_terminal_shell", "Configure Terminal Shell" ),
findIcon( "terminal" ), getKeybind( "configure-terminal-shell" ) )
->setId( "configure-terminal-shell" );

mToolsMenu->addSeparator();

mToolsMenu
->add( i18n( "load_cur_dir_as_folder", "Load current document directory as folder" ),
findIcon( "folder" ), getKeybind( "load-current-dir" ) )
Expand Down
72 changes: 70 additions & 2 deletions src/tools/ecode/terminalmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,72 @@ void TerminalManager::setUseFrameBuffer( bool useFrameBuffer ) {
mUseFrameBuffer = useFrameBuffer;
}

void TerminalManager::configureTerminalShell() {
const std::string layout( R"xml(
<window layout_width="300dp" layout_height="150dp" window-flags="default|shadow" window-title='@string(shell_configuration, "Shell Configuration")'>
<vbox lw="mp" lh="mp" padding="4dp">
<vbox lw="mp" lh="0" lw8="1">
<textview text='@string(configure_default_shell, "Configure default shell")' font-size="14dp" margin-bottom="8dp" />
<ComboBox id="shell_combo" layout_width="match_parent" layout_height="wrap_content" selectedIndex="0" popup-to-root="true"></ComboBox>
</vbox>
<hbox layout_gravity="right">
<pushbutton id="ok" text="@string(msg_box_ok, Ok)" icon="ok" />
<pushbutton id="cancel" text="@string(msg_box_cancel, Cancel)" margin-left="8dp" icon="cancel" />
</hbox>
</vbox>
</window>
)xml" );
UIWindow* window = mApp->getUISceneNode()->loadLayoutFromString( layout )->asType<UIWindow>();
UIComboBox* shellCombo = window->find<UIComboBox>( "shell_combo" );
UIPushButton* ok = window->find<UIPushButton>( "ok" );
UIPushButton* cancel = window->find<UIPushButton>( "cancel" );
const std::vector<std::string> list{
"bash", "sh", "zsh", "fish", "nu", "csh", "tcsh", "ksh", "dash", "cmd", "powershell",
};
std::vector<String> found;
for ( const auto& i : list ) {
std::string f( Sys::which( i ) );
if ( !f.empty() )
found.emplace_back( std::move( f ) );
}
shellCombo->getListBox()->addListBoxItems( found );
const char* shellEnv = std::getenv( "SHELL" );
if ( !mApp->termConfig().shell.empty() ) {
shellCombo->getListBox()->setSelected( mApp->termConfig().shell );
shellCombo->setText( mApp->termConfig().shell );
} else if ( shellEnv ) {
std::string shellEnvStr( FileSystem::fileExists( shellEnv ) ? shellEnv
: Sys::which( shellEnv ) );
if ( !shellEnvStr.empty() )
shellCombo->getListBox()->setSelected( shellEnvStr );
}
auto setShellFn = []( App* app, UIWindow* window, UIComboBox* shellCombo ) {
std::string shell( shellCombo->getText().toUtf8() );
if ( !Sys::which( shell ).empty() || FileSystem::fileExists( shell ) ) {
app->getConfig().term.shell = shell;
window->closeWindow();
} else {
app->errorMsgBox( app->i18n(
"shell_not_found", "The shell selected was not found in the file system.\nMake "
"sure that the shell is visible in your PATH" ) );
}
};
ok->setFocus();
ok->addMouseClickListener(
[&, window, shellCombo]( const MouseEvent* ) { setShellFn( mApp, window, shellCombo ); },
MouseButton::EE_BUTTON_LEFT );
cancel->addMouseClickListener( [window]( const MouseEvent* ) { window->closeWindow(); },
EE_BUTTON_LEFT );
window->on( Event::KeyDown, [window]( const Event* event ) {
if ( event->asKeyEvent()->getKeyCode() == KEY_ESCAPE )
window->closeWindow();
} );
window->center();
window->on( Event::OnWindowReady, [ok] ( const Event* ) {
ok->setFocus();
} );
}

UIMenu* TerminalManager::createColorSchemeMenu() {
mColorSchemeMenuesCreatedWithHeight = mApp->uiSceneNode()->getPixelsSize().getHeight();
size_t maxItems = 19;
Expand Down Expand Up @@ -140,8 +206,7 @@ void TerminalManager::updateMenuColorScheme( UIMenuSubMenu* colorSchemeMenu ) {
}

UITerminal* TerminalManager::createNewTerminal( const std::string& title, UITabWidget* inTabWidget,
const std::string& workingDir,
const std::string& program,
const std::string& workingDir, std::string program,
const std::vector<std::string>& args ) {
#if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN
UIMessageBox* msgBox = UIMessageBox::New(
Expand Down Expand Up @@ -179,6 +244,9 @@ UITerminal* TerminalManager::createNewTerminal( const std::string& title, UITabW
}
}

if ( program.empty() && !mApp->termConfig().shell.empty() )
program = mApp->termConfig().shell;

UITerminal* term = UITerminal::New(
mApp->getTerminalFont() ? mApp->getTerminalFont() : mApp->getFontMono(),
mApp->termConfig().fontSize.asPixels( 0, Sizef(), mApp->getDisplayDPI() ), initialSize,
Expand Down
5 changes: 3 additions & 2 deletions src/tools/ecode/terminalmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class TerminalManager {

UITerminal* createNewTerminal( const std::string& title = "",
UITabWidget* inTabWidget = nullptr,
const std::string& workingDir = "",
const std::string& program = "",
const std::string& workingDir = "", std::string program = "",
const std::vector<std::string>& args = {} );

void applyTerminalColorScheme( const TerminalColorScheme& colorScheme );
Expand Down Expand Up @@ -47,6 +46,8 @@ class TerminalManager {

void setUseFrameBuffer( bool useFrameBuffer );

void configureTerminalShell();

protected:
App* mApp;
std::string mTerminalColorSchemesPath;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/ecode/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace EE;

#define ECODE_MAJOR_VERSION 0
#define ECODE_MINOR_VERSION 4
#define ECODE_PATCH_LEVEL 6
#define ECODE_PATCH_LEVEL 7
#define ECODE_CODENAME "Vajra"

/** The compiled version of the library */
Expand Down

0 comments on commit 7d7a97e

Please sign in to comment.