vcompon.cpp

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

CPP
895
字号
            _component->removeItem( m );
        }
    }
}

void VComponent::mRenameItem( WMenuItem* )
{
    MItem* m = selectedItem();
    if( m ) {
        WInputDialog inp( this, "Rename file" );
        inp.setBrowse( _config->fileFilters(), FALSE );
        WFileName fn( *m );
        bool done = FALSE;
        for( ; !done ; ) {
            if( !inp.getInput( fn, "Enter new filename" ) ) break;
//            fn.toLower();
            fn.removeQuotes();
            MRule* rule = _config->findMatchingRule( fn, target()->rule(),
                              _component->mask() );
            if( rule ) {
                MItem* item = new MItem( fn, _component, rule );
                if( okToInclude( item, TRUE, m ) ) {
                    _component->renameItem( m, fn, rule );
                    done = TRUE;
                }
                delete item;
            }
        }
    }
}

void VComponent::dblClicked( WWindow* )
{
    if( selectedItem() ) {
        doAction( selectedItem(), NULL );
    }
}

void VComponent::expandItem( WWindow* )
{
    MItem* item = selectedItem();
    if( item != NULL && !item->parent() ) {
        item->setExpanded( !item->expanded() );
        _component->updateItemList();
    }
}

void VComponent::actionSetup( MItem* item, MAction* action )
{
    WString a;
    action->text( a );
    WString text;
    text.printf( "Switches for '%s' action on '%s'",
        (const char*)a, (const char*)*item );
    WVList& states = item->getActionStates( action );
    VSetup setup( this, action->tool(), _component->mask(),
        &states, text, mode() );
    if( setup.process() ) {
        _component->setDirty();
    }
}

void VComponent::setupItem( MItem* m )
{
    MRule* r = m->rule();
    if( r != _config->nilRule() ) {
        WString text;
        text.printf( "Switches for making '%s' in target '%s'",
            (const char*)*m, (const char*)*target() );
        VSetup setup( this, r->tool(), _component->mask(),
            &m->states(), text, mode() );
        if( setup.process() ) {
            touchItem( m );
            _component->items().updateAllViews();
            _component->setDirty();
        }
    }
}

void VComponent::showItemCommand()
{
    MItem* m = selectedItem();
    if( m ) {
        WString n;
        _component->getItemCommand( m, n );
        WMessageDialog::messagef( this, MsgInfo, MsgOk,
            "Source Command", "%s", (const char*)n );
    }
}

void VComponent::touchItem( MItem* m )
{
    if( m ) {
        if( m->isMask() ) {
            MsgRetType ret = WMessageDialog::messagef(
                this, MsgQuestion, MsgYesNo, _viperRequest,
                "Mark all %s files in '%s' for remake?",
                m->ext(), (const char*)*target() );
            if( ret == MsgRetYes ) {
                _component->touchItem( m );
            }
        } else {
            _component->touchItem( m );
        }
    }
}

typedef struct capData {
    WPickList*  incList;
    MComponent* comp;
} CapData;

static rtn_status captureName( time_t, char* name, void* data )
{
    MComponent* comp = ((CapData*)data)->comp;
    WPickList* incList = ((CapData*)data)->incList;
    WFileName fn( name ); //fn.toLower();
    MRule* rule = _config->findMatchingRule(
        fn, comp->target()->rule(), comp->mask() );
    if( rule ) {
        incList->add( new MItem( fn, comp, rule ) );
    }
    return ADR_CONTINUE;
}

void VComponent::mIncludedItems( WMenuItem* )
{
    MItem* m = selectedItem();
    if( m ) {
        WFileName resf;
        m->absResult( resf );
        WPickList incList;
        CapData data;
        data.incList = &incList;
        data.comp = _component;
        startWait();
        _parent->setStatus( "Scanning result file..." );
        walk_status stat = WalkOBJAutoDep( (char*)(const char*)resf,
            captureName, &data );
#ifndef __OS2__
        if( stat == ADW_NOT_AN_OBJ ) {
            stat = WalkRESAutoDep( (char*)(const char*)resf,
                captureName, &data );
        }
#endif
        _parent->setStatus( NULL );
        stopWait();
        if( stat == ADW_NOT_AN_OBJ ) {
            WMessageDialog::info( this, "Unable to scan '%s' result file", (const char*)*m );
        }
        if( stat != ADW_OK ) {
            WMessageDialog::info( this, "File '%s' not yet compiled", (const char*)*m );
        } else if( stat == ADW_NO_DEPS || incList.count() == 0 ) {
            WMessageDialog::info( this, "No files included from '%s'", (const char*)*m );
        } else if( incList.count() > 0 ) {
            WString title;
            title.printf( "Edit files included by" );
            WPickDialog dlg( incList, (cbs)&MItem::name, this, title );
            int index = dlg.pickOne( (const char *)*m );
            if( index >= 0 ) {
                MItem* mi = (MItem*)incList[ index ];
                doAction( mi, NULL );
            }
        }
        incList.deleteContents();
    }
}

bool WEXPORT VComponent::gettingFocus( WWindow* )
{
    _parent->setActive( this );
#if 0   //this code won't work because of a bug in GUI
    if( _vItems ) {
        _vItems->setFocus();
        return TRUE;
    }
#endif
    return FALSE;
}

bool WEXPORT VComponent::losingFocus( WWindow* )
{
    return FALSE;
}

void WEXPORT VComponent::updateView()
{
    WFileName fn( _component->relFilename() );
    fn.setExt( target()->ext() );
    WString text( fn );
    if( _config->debug() ) {
        text.concat( " '" );
        text.concat( target()->rule()->tag() );
        text.concat( "'" );
    }
    setText( text );

    WString n;
    if( debugMode() ) {
        n.concatf( "(D) " );
    } else {
        n.concatf( "(R) " );
    }
    _component->typeDesc( n );
    _tBox->setText( n );
}

void WEXPORT VComponent::modelGone()
{
}

void WEXPORT VComponent::mAutodepend()
{
    _component->setAutodepend( !_component->autodepend() );
}

void WEXPORT VComponent::mAutotrack()
{
    _component->setAutotrack( !_component->autotrack() );
}

void WEXPORT VComponent::mDebugMode()
{
    MsgRetType ret = WMessageDialog::messagef( this, MsgQuestion, MsgYesNoCancel, _viperRequest,
            "Mark '%s' and all it's component files for remake?", (const char*)*target() );
    if( ret != MsgRetCancel ) {
        bool all = (ret == MsgRetYes);
        _component->setMode( debugMode() ? SWMODE_RELEASE : SWMODE_DEBUG );
        _component->touchTarget( all );
        updateView();
    }
}

#if 1
void WEXPORT VComponent::renameComponent( WFileName& fn, MRule* rule, WString& mask )
{
    if( _parent->createDirectory( fn ) ) {
        MsgRetType ret = WMessageDialog::messagef( this, MsgQuestion,
                MsgYesNoCancel, _viperRequest,
                "Also mark all source files of '%s' for remake?",
                (const char*)*target() );
        if( ret != MsgRetCancel ) {
            if( !_component->renameComponent( fn, rule, mask ) ) {
                WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
                                          "Unable to rename file" );
            } else {
                _component->touchTarget( ret == MsgRetYes );
                createControls();
                updateView();
            }
        }
    }
}
#else
void WEXPORT VComponent::renameComponent()
{
static char cFilter[] = { "Executables(*.exe)\0*.exe\0Static Libraries(*.lib)\0*.lib\0Dynamic Libraries(*.dll)\0*.dll\0All files(*.*)\0*.*\0\0" };
    VCompDialog dlg( this, "Rename Target", _parent->project(), cFilter );
    WFileName fn( _component->relFilename() );
    fn.setExt( target()->ext() );
    MRule* rule;
    WString mask;
    if( dlg.process( fn, &rule, mask, _component ) ) {
        if( strieq( fn.ext(), ".tgt" ) ) {
            if( !_parent->attachTgtFile( fn ) ) {
                //WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Cannot rename file to .tgt extension" );
            }
        } else {
            if( _parent->createDirectory( fn ) ) {
                if( !_component->renameComponent( fn, rule, mask ) ) {
                    WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Unable to rename file" );
                } else {
                    touchComponent();
                    createControls();
                    updateView();
                }
            }
        }
    }
}
#endif

void WEXPORT VComponent::setupComponent()
{
    MRule* r = target()->rule();
    if( r != _config->nilRule() ) {
        WString text;
        text.printf( "Switches for making target '%s'", (const char*)*target() );
        VSetup setup( this, r->tool(), _component->mask(), &target()->states(), text, mode() );
        if( setup.process() ) {
            target()->touchResult();
            _component->setDirty();
        }
    }
}

void WEXPORT VComponent::setCompBefore()
{
    WEditDialog ed( this, "Target 'Before' text" );
    MCommand txt( _component->before() );
    if( ed.edit( txt ) ) {
        _component->setBefore( txt );
    }
}

void WEXPORT VComponent::setCompAfter()
{
    WEditDialog ed( this, "Target 'After' text" );
    MCommand txt( _component->after() );
    if( ed.edit( txt ) ) {
        _component->setAfter( txt );
    }
}

void VComponent::showCompCommand()
{
    WString n;
    _component->getTargetCommand( n );
    WMessageDialog::messagef( this, MsgInfo, MsgOk, "Target Command", "%s", (const char*)n );
}

void WEXPORT VComponent::touchComponent( bool quiet )
{
    MsgRetType          ret;

    if( quiet ) {
        ret = MsgRetYes;
    } else {
        ret = WMessageDialog::messagef( this, MsgQuestion,
                            MsgYesNoCancel, _viperRequest,
                            "Also mark all source files of '%s' for remake?",
                            (const char*)*target() );
    }
    if( ret != MsgRetCancel ) {
        bool all = (ret == MsgRetYes);
        _component->touchTarget( all );
    }
}

void WEXPORT VComponent::bActionComponent( WWindow* b )
{
    doAction( target(), (MAction*)((WButton*)b)->tagPtr() );
}

void VComponent::actionError( MItem* item, const WString& actionName )
{
    WString t;
    for( int i=0; i<actionName.size(); i++ ) {
        if( actionName[i] != '&' ) t.concat( (char)tolower(actionName[i]) );
    }
    WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "You cannot %s '%s'", (const char*)t, (const char*)*item );
}

void WEXPORT VComponent::doAction( MItem* item, const WString& actionName )
{
    WString cmd;
    int location = item->expandAction( actionName, cmd );
    if( location < 0 ) {
        actionError( item, actionName );
    } else {
        _parent->executeCommand( cmd, location );
    }
}

void WEXPORT VComponent::doAction( MItem* item, MAction* action )
{
    WString cmd;
    int location = item->expandAction( action, cmd );
    if( location < 0 ) {
        if( action != NULL ) {
            actionError( item, action->name() );
        }
    } else {
        _parent->executeCommand( cmd, location );
    }
}

MItem* WEXPORT VComponent::selectedItem()
{
    return (MItem*)_vItems->selectedTagPtr();
}

void WEXPORT VComponent::removeItem( WFileName &fn )
{
    _component->removeItem( fn );
}

void VComponent::beginFileList( unsigned owner ) {
    int         cnt;
    unsigned    i;
    MItem       *cur;

    WPickList &items = _component->items();
    cnt = items.count();
    for( i=0; i < cnt; i++ ) {
        cur = (MItem *)items[i];
        if( cur->owner() == owner ) cur->setVisited( FALSE );
    }
}

void VComponent::markFile( WFileName &file, unsigned owner ) {
    int         cnt;
    unsigned    i;
    MItem       *cur;
    WFileName   fn;

//    file.toLower(); // since comparison below is actually case sensitive
    WPickList &items = _component->items();
    cnt = items.count();
    for( i=0; ; i++ ) {
        if( i >= cnt ) {
            cur = NULL;
            break;
        }
        cur = (MItem *)items[i];
        cur->absName( fn );
        if( file == fn ) break;
    }
    if( cur != NULL ) {
        cur->setVisited( TRUE );
        cur->setOwner( owner );
    } else{
        fn = file;
        newItem( file, TRUE, TRUE, owner );
    }
}

void VComponent::endFileList( unsigned owner ) {
    int         cnt;
    unsigned    i;
    MItem       *cur;

    WPickList &items = _component->items();
    cnt = items.count();
    i=0;
    while( i < cnt ) {
        for( i=0; i < cnt ; i++ ) {
            cur = (MItem *)items[i];
            if( cur->owner() == owner && !cur->wasVisited() ) {
                _component->removeItem( cur );
                cnt = items.count();
                break;
            }
        }
    }
}

⌨️ 快捷键说明

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