mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-09-30 02:00:27 +03:00
Refactor how App is exposed. Expose more functionality to the Plugins.
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
#include "notificationcenter.hpp"
|
||||
#include "plugins/plugincontextprovider.hpp"
|
||||
#include "projectdirectorytree.hpp"
|
||||
#include "statusbuildoutputcontroller.hpp"
|
||||
#include "ecode.hpp"
|
||||
#include "widgetcommandexecuter.hpp"
|
||||
#include <eepp/ui/uicodeeditor.hpp>
|
||||
|
||||
namespace ecode {
|
||||
|
||||
StatusBuildOutputController::StatusBuildOutputController( UISplitter* mainSplitter,
|
||||
UISceneNode* uiSceneNode, App* app ) :
|
||||
StatusBarElement( mainSplitter, uiSceneNode, app ) {}
|
||||
UISceneNode* uiSceneNode,
|
||||
PluginContextProvider* pluginContext ) :
|
||||
StatusBarElement( mainSplitter, uiSceneNode, pluginContext ) {}
|
||||
|
||||
static std::string getProjectOutputParserTypeToString( const ProjectOutputParserTypes& type ) {
|
||||
switch ( type ) {
|
||||
@@ -20,18 +24,18 @@ static std::string getProjectOutputParserTypeToString( const ProjectOutputParser
|
||||
return "notice";
|
||||
}
|
||||
|
||||
UIPushButton* StatusBuildOutputController::getBuildButton( App* app ) {
|
||||
if ( app->getSidePanel() ) {
|
||||
UIWidget* tab = app->getSidePanel()->find<UIWidget>( "build_tab_view" );
|
||||
UIPushButton* StatusBuildOutputController::getBuildButton() {
|
||||
if ( mContext->getSidePanel() ) {
|
||||
UIWidget* tab = mContext->getSidePanel()->find<UIWidget>( "build_tab_view" );
|
||||
if ( tab )
|
||||
return tab->find<UIPushButton>( "build_button" );
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UIPushButton* StatusBuildOutputController::getCleanButton( App* app ) {
|
||||
if ( app->getSidePanel() ) {
|
||||
UIWidget* tab = app->getSidePanel()->find<UIWidget>( "build_tab_view" );
|
||||
UIPushButton* StatusBuildOutputController::getCleanButton() {
|
||||
if ( mContext->getSidePanel() ) {
|
||||
UIWidget* tab = mContext->getSidePanel()->find<UIWidget>( "build_tab_view" );
|
||||
if ( tab )
|
||||
return tab->find<UIPushButton>( "clean_button" );
|
||||
}
|
||||
@@ -105,10 +109,10 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
|
||||
const ProjectBuildOutputParser& outputParser,
|
||||
bool isClean,
|
||||
std::function<void( int exitStatus )> doneFn ) {
|
||||
if ( nullptr == mApp->getProjectBuildManager() )
|
||||
if ( nullptr == mContext->getProjectBuildManager() )
|
||||
return;
|
||||
|
||||
auto pbm = mApp->getProjectBuildManager();
|
||||
auto pbm = mContext->getProjectBuildManager();
|
||||
|
||||
show();
|
||||
showBuildOutput();
|
||||
@@ -153,8 +157,8 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
|
||||
|
||||
mScrollLocked = true;
|
||||
|
||||
UIPushButton* buildButton = getBuildButton( mApp );
|
||||
UIPushButton* cleanButton = getCleanButton( mApp );
|
||||
UIPushButton* buildButton = getBuildButton();
|
||||
UIPushButton* cleanButton = getCleanButton();
|
||||
|
||||
bool enableBuildButton = false;
|
||||
bool enableCleanButton = false;
|
||||
@@ -171,27 +175,29 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
|
||||
|
||||
if ( isClean ) {
|
||||
if ( cleanButton )
|
||||
cleanButton->setText( mApp->i18n( "cancel_clean", "Cancel Clean" ) );
|
||||
cleanButton->setText( mContext->i18n( "cancel_clean", "Cancel Clean" ) );
|
||||
} else {
|
||||
if ( buildButton )
|
||||
buildButton->setText( mApp->i18n( "cancel_build", "Cancel Build" ) );
|
||||
buildButton->setText( mContext->i18n( "cancel_build", "Cancel Build" ) );
|
||||
}
|
||||
|
||||
mBuildButton->setEnabled( false );
|
||||
mStopButton->setEnabled( true );
|
||||
|
||||
const auto updateBuildButton = [this, isClean, enableBuildButton, enableCleanButton]() {
|
||||
UIPushButton* buildButton = getBuildButton( mApp );
|
||||
UIPushButton* cleanButton = getCleanButton( mApp );
|
||||
UIPushButton* buildButton = getBuildButton();
|
||||
UIPushButton* cleanButton = getCleanButton();
|
||||
|
||||
if ( !isClean && buildButton ) {
|
||||
buildButton->runOnMainThread(
|
||||
[this, buildButton] { buildButton->setText( mApp->i18n( "build", "Build" ) ); } );
|
||||
buildButton->runOnMainThread( [this, buildButton] {
|
||||
buildButton->setText( mContext->i18n( "build", "Build" ) );
|
||||
} );
|
||||
}
|
||||
|
||||
if ( isClean && cleanButton ) {
|
||||
cleanButton->runOnMainThread(
|
||||
[this, cleanButton] { cleanButton->setText( mApp->i18n( "clean", "Clean" ) ); } );
|
||||
cleanButton->runOnMainThread( [this, cleanButton] {
|
||||
cleanButton->setText( mContext->i18n( "clean", "Clean" ) );
|
||||
} );
|
||||
}
|
||||
|
||||
if ( enableBuildButton && buildButton )
|
||||
@@ -205,7 +211,8 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
|
||||
};
|
||||
|
||||
auto res = pbm->build(
|
||||
buildName, [this]( const auto& key, const auto& def ) { return mApp->i18n( key, def ); },
|
||||
buildName,
|
||||
[this]( const auto& key, const auto& def ) { return mContext->i18n( key, def ); },
|
||||
buildType,
|
||||
[this]( auto, std::string buffer, const ProjectBuildCommand* cmd ) {
|
||||
mBuildOutput->runOnMainThread( [this, buffer]() {
|
||||
@@ -237,13 +244,14 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
|
||||
String buffer;
|
||||
|
||||
if ( EXIT_SUCCESS == exitCode ) {
|
||||
buffer = Sys::getDateTimeStr() + ": " +
|
||||
( isClean ? mApp->i18n( "clean_successful", "Clean run successfully\n" )
|
||||
: mApp->i18n( "build_successful", "Build run successfully\n" ) );
|
||||
buffer =
|
||||
Sys::getDateTimeStr() + ": " +
|
||||
( isClean ? mContext->i18n( "clean_successful", "Clean run successfully\n" )
|
||||
: mContext->i18n( "build_successful", "Build run successfully\n" ) );
|
||||
} else {
|
||||
buffer = Sys::getDateTimeStr() + ": " +
|
||||
( isClean ? mApp->i18n( "clean_failed", "Clean run with errors\n" )
|
||||
: mApp->i18n( "build_failed", "Build run with errors\n" ) );
|
||||
( isClean ? mContext->i18n( "clean_failed", "Clean run with errors\n" )
|
||||
: mContext->i18n( "build_failed", "Build run with errors\n" ) );
|
||||
}
|
||||
|
||||
mBuildOutput->runOnMainThread( [this, buffer]() {
|
||||
@@ -254,9 +262,10 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
|
||||
|
||||
updateBuildButton();
|
||||
|
||||
if ( !mApp->getWindow()->hasFocus() ) {
|
||||
mApp->getUISceneNode()->runOnMainThread(
|
||||
[this] { mApp->getWindow()->flash( WindowFlashOperation::UntilFocused ); } );
|
||||
if ( !mContext->getWindow()->hasFocus() ) {
|
||||
mContext->getUISceneNode()->runOnMainThread( [this] {
|
||||
mContext->getWindow()->flash( WindowFlashOperation::UntilFocused );
|
||||
} );
|
||||
}
|
||||
|
||||
if ( doneFn )
|
||||
@@ -265,7 +274,7 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
|
||||
isClean );
|
||||
|
||||
if ( !res.isValid() ) {
|
||||
mApp->getNotificationCenter()->addNotification( res.errorMsg );
|
||||
mContext->getNotificationCenter()->addNotification( res.errorMsg );
|
||||
updateBuildButton();
|
||||
if ( doneFn )
|
||||
doneFn( EXIT_FAILURE );
|
||||
@@ -426,7 +435,7 @@ void StatusBuildOutputController::createContainer() {
|
||||
mMainSplitter->getLastWidget()->setParent( mUISceneNode );
|
||||
}
|
||||
|
||||
mContainer = mApp->getUISceneNode()
|
||||
mContainer = mContext->getUISceneNode()
|
||||
->loadLayoutFromString( XML, mMainSplitter )
|
||||
->asType<UILinearLayout>();
|
||||
mRelLayCE = mContainer->find( "build_output_command_executer" )
|
||||
@@ -436,14 +445,15 @@ void StatusBuildOutputController::createContainer() {
|
||||
editor->setLineBreakingColumn( 0 );
|
||||
editor->setShowLineNumber( false );
|
||||
editor->getDocument().reset();
|
||||
editor->getDocument().textInput( mApp->i18n( "no_build_has_been_run", "No build has been run" ),
|
||||
false );
|
||||
editor->getDocument().textInput(
|
||||
mContext->i18n( "no_build_has_been_run", "No build has been run" ), false );
|
||||
editor->setScrollY( editor->getMaxScroll().y );
|
||||
mButOutput = mContainer->find<UISelectButton>( "but_build_output_output" );
|
||||
mButIssues = mContainer->find<UISelectButton>( "but_build_output_issues" );
|
||||
mTableIssues = mContainer->find<UITableView>( "build_output_issues" );
|
||||
mTableIssues->setHeadersVisible( true );
|
||||
mTableIssues->setModel( StatusMessageModel::create( mStatusResults, mApp->getUISceneNode() ) );
|
||||
mTableIssues->setModel(
|
||||
StatusMessageModel::create( mStatusResults, mContext->getUISceneNode() ) );
|
||||
setHeaderWidth();
|
||||
mTableIssues->on( Event::OnSizeChange, [this]( auto ) { setHeaderWidth(); } );
|
||||
mTableIssues->onModelEvent( [this]( const ModelEvent* modelEvent ) {
|
||||
@@ -461,7 +471,7 @@ void StatusBuildOutputController::createContainer() {
|
||||
if ( !tab ) {
|
||||
FileInfo fileInfo( path );
|
||||
if ( fileInfo.exists() && fileInfo.isRegularFile() ) {
|
||||
mApp->loadFileFromPath(
|
||||
mContext->loadFileFromPath(
|
||||
path, true, nullptr,
|
||||
[this, lineNum, colNum]( UICodeEditor*, const std::string& ) {
|
||||
onLoadDone( lineNum, colNum );
|
||||
@@ -469,7 +479,7 @@ void StatusBuildOutputController::createContainer() {
|
||||
} else {
|
||||
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ )
|
||||
removeRelativeSubPaths( path );
|
||||
mApp->getDirTree()->asyncMatchTree(
|
||||
mContext->getDirTree()->asyncMatchTree(
|
||||
ProjectDirectoryTree::MatchType::Fuzzy, path, 1,
|
||||
[this, colNum, lineNum]( std::shared_ptr<FileListModel> res ) {
|
||||
if ( res->rowCount( {} ) == 0 )
|
||||
@@ -481,7 +491,7 @@ void StatusBuildOutputController::createContainer() {
|
||||
mUISceneNode->runOnMainThread( [this, path, lineNum, colNum] {
|
||||
UITab* tab = mSplitter->isDocumentOpen( path );
|
||||
if ( !tab ) {
|
||||
mApp->loadFileFromPath(
|
||||
mContext->loadFileFromPath(
|
||||
path, true, nullptr,
|
||||
[this, lineNum, colNum]( auto, auto ) {
|
||||
onLoadDone( lineNum, colNum );
|
||||
@@ -501,26 +511,27 @@ void StatusBuildOutputController::createContainer() {
|
||||
}
|
||||
} else if ( modelEvent->getModelEventType() == ModelEventType::OpenMenu ) {
|
||||
UIPopUpMenu* menu = UIPopUpMenu::New();
|
||||
menu->add( mApp->i18n( "copy_error_message", "Copy Error Message" ),
|
||||
mApp->findIcon( "copy" ) )
|
||||
menu->add( mContext->i18n( "copy_error_message", "Copy Error Message" ),
|
||||
mContext->findIcon( "copy" ) )
|
||||
->setId( "copy-error-message" );
|
||||
menu->add( mApp->i18n( "copy_file_path", "Copy File Path" ), mApp->findIcon( "copy" ) )
|
||||
menu->add( mContext->i18n( "copy_file_path", "Copy File Path" ),
|
||||
mContext->findIcon( "copy" ) )
|
||||
->setId( "copy-file-path" );
|
||||
menu->on( Event::OnItemClicked, [this, model, idx]( const Event* event ) {
|
||||
UIMenuItem* item = event->getNode()->asType<UIMenuItem>();
|
||||
std::string id( item->getId() );
|
||||
if ( id == "copy-error-message" ) {
|
||||
Variant msg( model->data( model->index( idx.row(), 0 ), ModelRole::Display ) );
|
||||
mApp->getWindow()->getClipboard()->setText( msg.toString() );
|
||||
mContext->getWindow()->getClipboard()->setText( msg.toString() );
|
||||
} else if ( id == "copy-file-path" ) {
|
||||
Variant msg( model->data( idx, ModelRole::Custom ) );
|
||||
mApp->getWindow()->getClipboard()->setText( msg.toString() );
|
||||
mContext->getWindow()->getClipboard()->setText( msg.toString() );
|
||||
}
|
||||
} );
|
||||
UITableCell* cell = mTableIssues->getCellFromIndex( idx );
|
||||
if ( modelEvent->getTriggerEvent()->getType() == Event::MouseClick ||
|
||||
cell == nullptr ) {
|
||||
Vector2f pos( mApp->getWindow()->getInput()->getMousePos().asFloat() );
|
||||
Vector2f pos( mContext->getWindow()->getInput()->getMousePos().asFloat() );
|
||||
menu->nodeToWorldTranslation( pos );
|
||||
UIMenu::findBestMenuPos( pos, menu );
|
||||
menu->setPixelsPosition( pos );
|
||||
@@ -565,18 +576,18 @@ void StatusBuildOutputController::createContainer() {
|
||||
} );
|
||||
|
||||
mBuildButton->onClick( [this]( auto ) {
|
||||
auto pbm = mApp->getProjectBuildManager();
|
||||
auto pbm = mContext->getProjectBuildManager();
|
||||
if ( nullptr == pbm )
|
||||
return;
|
||||
if ( !pbm->hasBuildConfig() ) {
|
||||
UIMessageBox::New( UIMessageBox::OK,
|
||||
mApp->i18n( "must_configure_build_config",
|
||||
"You must first add a build configuration" ) )
|
||||
mContext->i18n( "must_configure_build_config",
|
||||
"You must first add a build configuration" ) )
|
||||
->setCloseShortcut( { KEY_ESCAPE } )
|
||||
->setTitle( mApp->getWindowTitle() )
|
||||
->setTitle( mContext->getWindowTitle() )
|
||||
->showWhenReady()
|
||||
->on( Event::OnConfirm, [this]( auto ) {
|
||||
auto pbm = mApp->getProjectBuildManager();
|
||||
auto pbm = mContext->getProjectBuildManager();
|
||||
if ( nullptr != pbm )
|
||||
pbm->selectTab();
|
||||
} );
|
||||
@@ -586,7 +597,7 @@ void StatusBuildOutputController::createContainer() {
|
||||
} );
|
||||
|
||||
mStopButton->onClick( [this]( auto ) {
|
||||
auto pbm = mApp->getProjectBuildManager();
|
||||
auto pbm = mContext->getProjectBuildManager();
|
||||
if ( nullptr == pbm )
|
||||
return;
|
||||
pbm->cancelBuild();
|
||||
@@ -603,7 +614,7 @@ void StatusBuildOutputController::createContainer() {
|
||||
} );
|
||||
|
||||
mConfigureButton->onClick( [this]( auto ) {
|
||||
auto pbm = mApp->getProjectBuildManager();
|
||||
auto pbm = mContext->getProjectBuildManager();
|
||||
if ( nullptr == pbm )
|
||||
return;
|
||||
pbm->editCurrentBuild();
|
||||
|
||||
Reference in New Issue
Block a user