vpemain.cpp

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

CPP
2,090
字号
                action->text( h );
                h.concat( "' action on selected source file" );
                WMenuItem* mi = new WMenuItem( n, this, (cbm)&VpeMain::mActionItemSetup, (cbh)&VpeMain::mHint, h );
                mi->setTagPtr( action );
                pop->insertItem( mi, ii+base );
                ii++;
            }
        }
    }

    WString ss;
    if( m ) {
        MTool* tool = m->rule()->tool();
        if( tool != _config->nilTool() ) {
            tool->name( ss );
            ss.concat( ' ' );
        }
    }
    ss.concat( menu3a[0].name );
    pop->setItemText( ss, 0 );                //set item switch text

    bool isp = (m != NULL);
    pop->enableItem( isp && m->ismakeable(), 0 );     //setup item
    pop->enableItem( isp && m->ismakeable(), 1 );     //show command
}

MenuPop VpeMain::popup4 = { "&Options", (cbp)&VpeMain::onPopup4, menu4, 1 };
MenuData VpeMain::menu4[] = {
    "&Switches...", (cbm)&VpeMain::setupComponent, "Set switch values for making current target", 0, NULL,
};

void VpeMain::onPopup4( WPopupMenu* pop )
{
    int base = popup4.count;
    int jcount = pop->childCount();
    for( int j=jcount; j>base; ) {
        j--;
        delete pop->removeItemAt( j );
    }

    //add switch setting for current target
    WString ss;
    if( _activeVComp ) {
        MTool* tool = _activeVComp->target()->rule()->tool();
        if( tool != _config->nilTool() ) {
            tool->name( ss );
            ss.concat( ' ' );
        }
    }
    ss.concat( menu4[0].name );
    pop->setItemText( ss, 0 );                //set target switch text

    int ccount = base;
    //add switch setting for all make-actions of current item
    ccount += addComponentActionSetups( pop, ccount );

    //for each 'mask' in current target, add switch setting for that item
    ccount += addComponentMaskSetups( pop, ccount );

    bool isv = (_activeVComp != NULL);
    pop->enableItem( isv, 0 );                //setup target
}

MenuPop VpeMain::popup5 = { "&Log", (cbp)&VpeMain::onPopup5, menu5, 5 };
MenuData VpeMain::menu5[] = {
    "&Edit File", (cbm)&VpeMain::editLog, "Edit file whose name is in the message", 0, NULL,
    "&Help on Message", (cbm)&VpeMain::helpLog, "Help on the message", 0, NULL,
    "&Stop", (cbm)&VpeMain::cancelLog, "Stop the executing operation", 0, NULL,
    NULL, NULL, NULL, 0, NULL,
    "Save Log &As...", (cbm)&VpeMain::saveLogAs, "Save contents of the IDE log window to a disk file", 0, NULL,
};

void VpeMain::onPopup5( WPopupMenu* pop )
{
    bool editOk = FALSE;
    bool helpOk = FALSE;
    if( _msgLog ) {
        _msgLog->getState( editOk, helpOk );
    }
    pop->enableItem( editOk, 0 );      //edit
    pop->enableItem( helpOk, 1 );      //help
    pop->enableItem( running(), 2 );   //stop
    bool islog = _msgLog && _msgLog->logExists();
    pop->enableItem( islog && !running(), 4 );  //save
}

void VpeMain::onPopup6( WPopupMenu* pop )
{
    bool isp = (_project!=NULL);
    pop->enableItem( isp, 0 ); //refresh
}

MenuPop VpeMain::popup7 = { "&Help", (cbp)&VpeMain::onPopup7, menu7, 3 };
MenuData VpeMain::menu7[] = {
    "&Contents", (cbm)&VpeMain::helpContents, "Help table of contents", 0, NULL,
    "&Search for Help On...", (cbm)&VpeMain::helpSearch, "Search for help on a particular topic", 0, NULL,
    "&How to Use Help", (cbm)&VpeMain::helpUsage, "Explanation on how to use the help facility", 0, NULL,
};

void VpeMain::onPopup7( WPopupMenu* pop )
{
    bool hp = ( _config->helpFile().size() > 0 );
    pop->enableItem( hp, 0 );                  //contents
    pop->enableItem( hp , 1 );                 //search for help
    pop->enableItem( hp , 2 );                 //help on help
    pop->enableItem( TRUE, 4 );                //about
}

int VpeMain::addComponentActionSetups( WPopupMenu* pop, int base )
{
    int ii = 0;
    if( _activeVComp ) {
        MItem* m = _activeVComp->target();
        WVList actlist;
        if( m ) {
            m->addActions( actlist );
            int icount = actlist.count();
            for( int i=0; i<icount; i++ ) {
                MAction* action = (MAction*)actlist[i];
                if( action->hasSwitches( TRUE ) ) {
                    if( ii == 0 ) {
                        pop->insertSeparator( base );
                        ii++;
                    }
                    WString n( action->name() ); n.concat( " switches..." );
                    WString h( "Setup switches for '" );
                    action->text( h );
                    h.concat( "' action on selected target" );
                    WMenuItem* mi = new WMenuItem( n, this, (cbm)&VpeMain::mActionComponentSetup, (cbh)&VpeMain::mHint, h );
                    mi->setTagPtr( action );
                    pop->insertItem( mi, ii+base );
                    ii++;
                }
            }
        }
    }
    return( ii );
}

int VpeMain::addComponentMaskSetups( WPopupMenu* pop, int base )
{
    int ii = 0;
    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];
            MTool* tool = m->rule()->tool();
            if( tool != _config->nilTool() ) {
                if( ii == 0 ) {
                    pop->insertSeparator( base );
                    ii++;
                }
                WString n;
                tool->name( n );
                n.concat( " switches..." );
                WString h( "Setup switches for '" );
                tool->name( h );
                h.concat( "' in selected target" );
                WMenuItem* mi = new WMenuItem( n, this, (cbm)&VpeMain::mSetupItem2, (cbh)&VpeMain::mHint, h );
                mi->setTagPtr( m );
                pop->insertItem( mi, ii+base );
                ii++;
            }
        }
    }
    return( ii );
}

bool VpeMain::keyDown( WORD key )
{
    if( key == GUI_KEY_F6 ) {
        if( _editorClient->connected() ) {
            _editorClient->sendMsg( "TakeFocus" );
        }
        return( TRUE );
    }
    return( FALSE );
}

bool VpeMain::gettingFocus( WWindow* )
{
    if( _activeVComp ) {
        _activeVComp->setFocus();
        return( TRUE );
    }
    return( FALSE );
}

bool VpeMain::appActivate( bool activated ) {
    if( activated && _project != NULL ) {
        if( _autoRefresh ) {
            _project->refresh( FALSE );
        } else {
            _project->refresh( TRUE );
        }
    }
    return( FALSE );
}

bool VpeMain::validateProjectName( WFileName& fn )
{
    if( fn.size() > 0 ) {
//        fn.toLower();
        if( fn.legal() ) {
            if( strlen( fn.ext() ) == 0 ) {
                fn.setExt( ".wpj" );
            }
            return( TRUE );
        }
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Project name '%s' is invalid", (const char*)fn );
    }
    return( FALSE );
}

bool VpeMain::kNewProject( WKeyCode )
{
    newProject( NULL );
    return( FALSE );
}

void VpeMain::newProject( WMenuItem* )
{
    if( okToClear() ) {
        HelpStack.push( HLP_OPENING_A_PROJECT );
        WFileDialog dlg( this, pFilter );
        WFileName fn( dlg.getOpenFileName( "noname.wpj", "Enter project filename", WFOpenNewAll ) );
        if( validateProjectName( fn ) ) {
            if( !fn.dirExists() ) {
                if( !confirm( "Do you want to create directory for '%s'?", fn ) ) {
                    HelpStack.pop();
                    return;
                }
                if( !fn.makeDir() ) {
                    WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
                                "Unable to create directory for '%s'",
                                (const char *)fn );
                    HelpStack.pop();
                    return;
                }
            }
            clearProject();
            _project = new MProject( fn );
            attachModel( _project );
            if( addComponent( NULL ) ) {
                _neverSaved = TRUE;
            }
        }
    }
    HelpStack.pop();
}

bool VpeMain::loadProject( const WFileName& fn )
{
    WObjectFile of;
    if( of.open( fn, OStyleReadB ) ) {
        fn.setCWD();    //so the load will work for relative filenames
        if( of.version() < OLDEST_SUPPORTED_VERSION ) {
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Project '%s' format is obsolete; you must create the project again or use an older version of the IDE.", (const char*)fn );
        } else if( of.version() > LATEST_SUPPORTED_VERSION ) {
            WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Project '%s' format is too new; you must use a newer version of the IDE.", (const char*)fn );
        } else {
            if( of.version() >= 34 ) {
                char ident[ sizeof( _projectIdent ) + 1 ];
                of.readObject( ident, sizeof( ident ) - 1 );
                if( !streq( ident, _projectIdent ) ) {
                    WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Project '%s' format is bad.", (const char*)fn );
                    of.close();
                    return( FALSE );
                }
            }
            setStatus( "Loading..." );
            startWait();
            of.readObject( this );
            of.close();
            stopWait();
            setStatus( NULL );
            return( TRUE );
        }
        of.close();
        return( FALSE );
    }
    WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Unable to open project '%s'", (const char*)fn );
    return( FALSE );
}

bool VpeMain::unloadProject( const WFileName& fn, bool checkout )
{
    bool ok = TRUE;
    setStatus( "Saving..." );
    startWait();
    WObjectFile of( LATEST_SUPPORTED_VERSION );
    if( !of.open( fn, OStyleWriteB ) ) {
        WFileName proj = _project->filename();
        WFileName targ = ""; // no target
        if( checkout && _rcsClient.QuerySystem() != NO_RCS ) {
            if( WMessageDialog::messagef( this, MsgQuestion, MsgOkCancel,
                _viperRequest, "Project file '%s' is read-only. checkout? ",
                (const char*)fn ) == MsgRetOk ) {
                _rcsClient.Checkout( (WFileName*)&fn, proj, targ );
                unloadProject( fn, FALSE );
            } else {
                WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Unable to write project file '%s'", (const char*)fn );
                ok = FALSE;
            }
        } else {
                WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Unable to write project file '%s'", (const char*)fn );
                ok = FALSE;
        }
    } else {
        of.writeObject( _projectIdent );
        of.writeObject( this );
        of.close();
        ok = of.objOk();
        if( ok ) {
            _neverSaved = FALSE;
        }
    }
    stopWait();
    setStatus( NULL );
    return( ok );
}

bool VpeMain::kOpenProject( WKeyCode ) {
    openProject( NULL );
    return FALSE;
}

void VpeMain::openProject( WMenuItem* )
{
    if( okToClear() ) {
        HelpStack.push( HLP_OPENING_A_PROJECT );
        WFileDialog* fd = new WFileDialog( this, pFilter );
//      WFileName fn( fd->getOpenFileName( NULL, "Open", WFOpenExisting ) );
        WFileName fn( fd->getOpenFileName( NULL, "Open", WFOpenNew ) );
        if( validateProjectName( fn ) ) {
            clearProject();
            if( loadProject( fn ) ) {
                addOldProject( fn );
            }
        }
        delete fd;
        HelpStack.pop();
    }
}

void VpeMain::addOldProject( const WFileName& filename )
{
    int i;

    for( i=0; i<_oldProjects.count(); i++ ) {
        WFileName* fn = (WFileName*)_oldProjects[ i ];
        if( *fn == filename ) {
            delete _oldProjects.removeAt( i );
            break;
        }
    }
    _oldProjects.insertAt( 0, new WFileName( filename ) );
    for( i=_oldProjects.count(); i > MAXOLDPROJECTS; ) {
        i--;
        delete _oldProjects.removeAt( i );
    }
}

void VpeMain::openOldProject( WMenuItem* m )
{
    if( okToClear() ) {
        WFileName* fn = (WFileName*)m->tagPtr();
        if( fn->size() > 0 ) {
            clearProject();
            if( loadProject( *fn ) ) {
                _oldProjects.removeSame( fn );  //move to the front
                _oldProjects.insertAt( 0, fn );
            }
        }
    }
}

void VpeMain::closeProject( WMenuItem* )
{
    if( okToClear() ) {
        clearProject();
    }
}


bool VpeMain::okToReplace( WFileName& fn )
{
    if( fn.attribs() ) {
        if( !confirm( "File '%s' exists! Ok to replace?", fn ) ) {
            return( FALSE );
        }
    }
    return( TRUE );
}

bool VpeMain::kSaveProject( WKeyCode )
{
    saveProject();
    return( TRUE );
}

bool VpeMain::saveProject()
{
    if( checkProject() ) {
        WFileName& fn = _project->filename();
        if( !fn.legal() ) {
            WFileName def;
            _project->filename().noPath( def );
            return( saveProjectAs( def ) );
        } else if( !_neverSaved || okToReplace( fn ) ) {
            addOldProject( fn );
            return( unloadProject( fn ) );
        }
    }
    return( FALSE );

⌨️ 快捷键说明

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