vpemain.cpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 2,090 行 · 第 1/5 页

CPP
2,090
字号
                        _activeVComp->doAction( _activeVComp->target(), action );
                        done = TRUE;
                        break;
                    }
                }
            }
        }
        // search source level accelerators
        if( !done ) {
            m = _activeVComp->selectedItem();
            actlist.reset();
            if( m ) {
                m->addActions( actlist );
                icount = actlist.count();
                for( i=0; i<icount; i++ ) {
                    action = (MAction*)actlist[i];
                    if( action->menuAccel() == kc ) {
                        _activeVComp->doAction( _activeVComp->selectedItem(),
                                                action );
                        done = TRUE;
                        break;
                    }
                }
            }
        }
    }
    return( TRUE );
}

void VpeMain::mRemoveItem( WMenuItem* )
{
    kRemoveItem( WKeyNone );
}

bool VpeMain::kRemoveItem( WKeyCode )
{
    bool        ret;

    ret = FALSE;
    _refuseFileLists = TRUE;
    HelpStack.push( HLP_REMOVING_A_SOURCE_FILE );
    if( _activeVComp ) {
        _activeVComp->setFocus();
        if( _activeVComp->selectedItem() ) {
            _activeVComp->mRemoveItem();
            ret = TRUE;
        }
    }
    _refuseFileLists = FALSE;
    HelpStack.pop();
    return( ret );
}

void VpeMain::mRenameItem( WMenuItem* )
{
    HelpStack.push( HLP_RENAMING_A_SOURCE_FILE );
    _refuseFileLists = TRUE;
    _activeVComp->setFocus();
    _activeVComp->mRenameItem();
    _refuseFileLists = FALSE;
    HelpStack.pop();
}

void VpeMain::mSetupItem( WMenuItem* )
{
    _refuseFileLists = TRUE;
    _activeVComp->setFocus();
    _activeVComp->setupItem( _activeVComp->selectedItem() );
    _refuseFileLists = FALSE;
}

void VpeMain::mSetupItem2( WMenuItem* item )
{
    _activeVComp->setFocus();
    _activeVComp->setupItem( (MItem*)item->tagPtr() );
}

void VpeMain::showItemCommand( WMenuItem* )
{
    _activeVComp->setFocus();
    _activeVComp->showItemCommand();
}

void VpeMain::mTouchItem( WMenuItem* )
{
    _activeVComp->setFocus();
    _activeVComp->touchItem( _activeVComp->selectedItem() );
}

void VpeMain::mIncludedItems( WMenuItem* )
{
    _refuseFileLists = TRUE;
    _activeVComp->setFocus();
    _activeVComp->mIncludedItems();
    _refuseFileLists = FALSE;
}

void VpeMain::mActionItem( WMenuItem* item )
{
    _activeVComp->setFocus();
    _activeVComp->doAction( _activeVComp->selectedItem(), (MAction*)item->tagPtr() );
}

void VpeMain::mActionItemSetup( WMenuItem* item )
{
    _activeVComp->setFocus();
    _activeVComp->actionSetup( _activeVComp->selectedItem(), (MAction*)item->tagPtr() );
}

void VpeMain::mActionComponent( WMenuItem* item )
{
    _activeVComp->setFocus();
    _activeVComp->doAction( _activeVComp->target(), (MAction*)item->tagPtr() );
}

void VpeMain::mActionComponentSetup( WMenuItem* item )
{
    _activeVComp->setFocus();
    _activeVComp->actionSetup( _activeVComp->target(), (MAction*)item->tagPtr() );
}

void VpeMain::mRefresh( WMenuItem* )
{
    startWait();
    _project->refresh();
    stopWait();
}

void VpeMain::mAction( WMenuItem* item )
{
    doAction( (MAction*)item->tagPtr() );
}

void VpeMain::doAction( const WString& actionName )
{
    int icount = _config->actions().count();
    for( int i=0; i<icount; i++ ) {
        MAction* action = (MAction*)_config->actions()[i];
        if( action->name().match( actionName ) ) {
            doAction( action );
            break;
        }
    }
}

void VpeMain::doAction( MAction* action )
{
    WString cmd;
    WFileName target( "dummy" );
    SwMode mode = SWMODE_RELEASE;
    if( _activeVComp ) {
        _activeVComp->target()->absName( target );
        mode = _activeVComp->component()->mode();
    }
    int location = action->expand( cmd, &target, "*", NULL, mode );
    WString t;
    action->text( t );
    executeCommand( cmd, location, t );
}

void VpeMain::mHelpItem( WMenuItem *mi ) {
    doAction( (MAction*) mi->tagPtr() );
}

void VpeMain::helpContents( WMenuItem* )
{
    _help->sysHelpContent();
}

void VpeMain::helpSearch( WMenuItem* )
{
    _help->sysHelpSearch( "" );
}

void VpeMain::helpUsage( WMenuItem* )
{
    _help->sysHelpOnHelp();
}

void VpeMain::about( WMenuItem* )
{
    WAbout about( this, &_hotSpotList, 4, _viperTitle, _viperDesc );
    about.process();
}

void VpeMain::editLog( WMenuItem* m )
{
    _msgLog->editRequest( m );
}

void VpeMain::helpLog( WMenuItem* m )
{
    _msgLog->helpRequest( m );
}

void VpeMain::cancelLog( WMenuItem* m )
{
    _msgLog->stopRequest( m );
}

void VpeMain::saveLogAs( WMenuItem* )
{
    _msgLog->saveLogAs();
}

void WEXPORT VpeMain::updateView()
{
    WString title( _viperTitle );
    if( _project ) {
        title.concatf( " [%s]", (const char*)_pModel->filename() );
    }
    setText( title );
}

void WEXPORT VpeMain::modelGone()
{
    _project = NULL;
    updateView();
}

void VpeMain::quickRefresh()
{
    if( _activeVComp ) {
        _activeVComp->component()->refresh();
    }
}

//static char okAnswer[] = "ok";
//static char noAnswer[] = "no";

void VpeMain::editorNotify( const char* msg )
{
    if( strieq( msg, "disconnect" ) ) {
        quickRefresh();
    }
}

void VpeMain::browseNotify( const char* msg )
{
    if( strieq( msg, "disconnect" ) ) {
        quickRefresh();
    }
}

#if(0)
WString* VpeMain::serverNotify( const char* msg )
{
    bool ok = TRUE;
    WStringList toks( msg );
    if( toks.stringAt(0) == "Editor" ) {
        executeCommand( toks.cString( 1 ), EXECUTE_EDITOR, "AutoEdit" );
    } else if( toks.stringAt(0) == "Browse" ) {
        executeCommand( toks.cString( 1 ), EXECUTE_BROWSE, "AutoBrowse" );
    } else if( toks.stringAt(0) == "TakeFocus" ) {
        setFocus();
        this->setFocus();
    } else {
        return( NULL );
    }
    return( ok ? new WString( okAnswer ) : new WString( noAnswer ) );
}
#endif

const char* VpeMain::toolName( char tag )
{
    static WString tagstr;
    tagstr = "";
    tagstr.concat( tag );
    tagstr.concat( _myHandle );
    return( tagstr );
}

bool VpeMain::running()
{
    return( _msgLog && _msgLog->running() );
}

void VpeMain::runBatch( const WString& cmd )
{
    if( running() ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Batch execution is busy" );
    } else if( _batchOk ) {
        setStatus( "Executing Log..." );
        if( !_msgLog ) {
            _msgLog = new VMsgLog( this );
            _msgLog->startConnect();
            if( _activeVComp ) {
                _activeVComp->setFocus();
            }
        }
        if( !_msgLog ) return;
        WFileName dir; dir.getCWD( FALSE );
        _msgLog->setDirectory( dir );
        _msgLog->runCommand( cmd );
    }
}

void VpeMain::executeBrowse( const WString& cmd )
{
    if( _config->debug() && !confirm( "executeBrowse: '%s'", cmd ) ) {
        return;
    }
    setStatus( "Executing source browser..." );
    WString bat;
    WStringList x( cmd );
    bat.concat( _config->browse() );
    if( x.stringAt(0) == "Open" ) {
        bat.concat( " " );
        bat.concat( x.cString( 1 ) );
    }

    const char *fn = x.cString(1);

    // don't allow browsing if no browseable files
    bool browseable = FALSE;
    bool exists = FALSE;
    if( _activeVComp ) {
        MComponent* comp = _activeVComp->component();
        WVList itemlist;
        comp->getMaskItems( itemlist );
        int icount = itemlist.count();
        for( int i=0; i<icount; i++ ) {
            MItem* m = (MItem*)itemlist[i];
            if( m->rule()->browseSwitch().size() != 0 ) {
                browseable = TRUE;
            }
        }
        exists = comp->tryBrowse();
        if( exists ) comp->makeMakeFile();
    }

    if( !browseable ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperInfo,
                "Browsing is not supported for any files in the current Target." );
        return;
    }
    if( !exists ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperInfo,
            "No Browser files found.\n Please add the -db Compiler Option and Make again.", fn+1 );
    } else {
        execute( bat );
    }
}

bool VpeMain::confirm( const char* prompt, const char* msg )
{
    MsgRetType ret = WMessageDialog::messagef( this, MsgQuestion, MsgYesNo, _viperRequest, prompt, msg );
    return( ret == MsgRetYes );
}

WHotSpots& VpeMain::hotSpotList()
{
    return( _hotSpotList );
}

SayReturn VpeMain::say( SayStyle style, SayCode code, const char* text )
{
    static MsgLevel styles[] = { MsgInfo, MsgWarning, MsgError };
    static MsgButtons codes[] = { MsgOk, MsgOkCancel, MsgYesNoCancel };
    switch( WMessageDialog::message( this, styles[ style ], codes[ code ], text ) ) {
        case MsgRetNo:
            return( RetNo );
        case MsgRetOk:
            return( RetOk );
        case MsgRetYes:
            return( RetYes );
        default:
            return( RetCancel );
    }
}

bool VpeMain::checkProject()
{
    if( !_project ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "No active project" );
        return( FALSE );
    }
    return( TRUE );
}

bool VpeMain::contextHelp( bool is_act_wnd ) {
    if( !is_act_wnd && !HelpStack.isempty() ) {
        _help->sysHelpId( (int)HelpStack.getTop() );
    }
    return( TRUE );
}

void VpeMain::mCheckin( WMenuItem *) {
    WFileName           fn;

    if( _activeVComp ) {
        if( _activeVComp->selectedItem() ) {
            _activeVComp->selectedItem()->absName( fn );
            WFileName proj = _project->filename();
            WFileName targ = _activeVComp->component()->filename();
            _editorDll.EDITSaveThis( &fn );
            if( !_rcsClient.Checkin( &fn, proj, targ ) ) {
                WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
                                "Checkin was not completed" );
            } else if( _autoRefresh && _project != NULL ) {
                _project->refresh( FALSE );
            }
        }
    }
}

void VpeMain::mCheckout( WMenuItem *) {

    WFileName           fn;

    if( _activeVComp ) {
        if( _activeVComp->selectedItem() ) {
            _activeVComp->selectedItem()->absName( fn );
            if( _editorDll.EDITIsFileInBuf( &fn ) ) {
                WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
                                "Checkout was not completed.  "
                                "'%s' is currently opened in the editor.  "
                    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?