vpemain.cpp

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

CPP
2,090
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  Viper (Open Watcom IDE) mainline.
*
****************************************************************************/


#include <io.h>
#include <stdlib.h>

extern "C" {
    #include "rcdefs.h"
    #include "banner.h"
};

#include "vpemain.hpp"
#include "vmsglog.hpp"

#include "wwinmain.hpp"
#include "wmenu.hpp"
#include "wfiledlg.hpp"
#include "wmsgdlg.hpp"
#include "winpdlg.hpp"
#include "wpickdlg.hpp"
#include "wautodlg.hpp"
#include "weditdlg.hpp"
#include "wfilenam.hpp"
#include "wobjfile.hpp"
#include "wstrlist.hpp"
#include "wserver.hpp"
#include "wclient.hpp"
#include "wprocess.hpp"
#include "mconfig.hpp"

#include "vcompon.hpp"
#include "mcompon.hpp"
#include "maction.hpp"
#include "mtarget.hpp"
#include "mtoolitm.hpp"
#include "vcompdlg.hpp"

#include "wabout.hpp"
#include "mcommand.hpp"
#include "wmetrics.hpp"
#include "wsystem.hpp"

#include "wstatwin.hpp"
#include "wflashp.hpp"
#include "vhelpstk.hpp"
#include "veditdlg.hpp"
#include "ide.h"
#include "autoenv.h"

#define OLDEST_SUPPORTED_VERSION 23
#define LATEST_SUPPORTED_VERSION 40
/*
 * 39 and 40 are written the same, but read in differently
 * 39 messed up .BEFORE / .AFTER containing CR/LF's
 * since this is the same as the separator char.
 */

static char _projectIdent[] = { "projectIdent" };

MAINOBJECT( VpeMain, COORD_USER, 10240, 10240 )

#define _pModel ((MProject*)model())

Define( VpeMain )
static char pFilter[] = { "Project Files(*.wpj)\0*.wpj\0All files(*.*)\0*.*\0\0" };

static WHotSpots _hotSpotList( 4 );

struct mPop {
    char*       name;
    cbp         onpop;
    MenuData*   menu;
    int         count;
};

struct mData {
    char*       name;
    cbm         callback;
    char*       hint;
    int         toolId;
    MenuPop*    pop;
};

char _viperTitle[] = { "Open Watcom IDE" };
char _viperError[] = { "IDE Error" };
char _viperRequest[] = { "IDE Request" };
char _viperInfo[] = { "IDE Information" };

#pragma warning 438 9
const char* _viperDesc[] = {
    banner1w( "Integrated Development Environment", _VIPER_VERSION_ ),
    banner2( "1993" ),
    banner3,
    banner3a,
    NULL
};

void VpeMain::loadNewEditor( WFileName &fn ) {
    WString errmsg;

    _editorDll.LoadDll( fn.gets(), &errmsg );
    if( !_editorDll.isInitialized() ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, errmsg.gets() );
    }
}

WEXPORT VpeMain::VpeMain()
    : WMdiWindow( _viperTitle )
    , _project( NULL )
    , _neverSaved( FALSE )
    , _activeVComp( NULL )
    , _msgLog( NULL )
    , _batchOk( TRUE )
    , _quitAnyways( FALSE )
    , _targetPopup( NULL )
    , _itemsPopup( NULL )
    , _logPopup( NULL )
    , _toolBarActive( FALSE )
    , _statusBar( NULL )
    , _myHandle( "V1234" )
    , _help( NULL )
    , _otherhelp( NULL )
    , _rcsClient( this )
    , _refuseFileLists( FALSE )
    , _autoRefresh( TRUE )
{
    /* check and fix env vars if needed; this should perhaps be done in
     * the GUI library and not here.
     */
    watcom_setup_env();
    if( getenv( "WATCOM" ) == NULL ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
        "WATCOM environment variable not set.\n"
        "IDE will not function correctly" );
    }

    hookF1Key( TRUE );
#if defined( __OS2__ )
    HelpStack.push( HLP_INDEX_OF_TOPICS );
#else
    HelpStack.push( HLP_TABLE_OF_CONTENTS );
#endif
    _hotSpotList.addHotSpot( B_sourceOpen, "" );        //the order must not change
    _hotSpotList.addHotSpot( B_sourceClosed, "" );
    _hotSpotList.addHotSpot( B_sourceItem, "" );
    _hotSpotList.addHotSpot( B_flashPage, "" );
    _hotSpotList.attach();

    WRect sc;
    WSystemMetrics::screenCoordinates( sc );
    sc.w( sc.w()*3/4 );
    sc.h( sc.h()*19/20 );
    move( sc );

    WProcessInfo proc;
    WString cmd;
    proc.getCommandArgs( cmd );

    bool debug = FALSE;
    bool c_for_pb = FALSE;
    bool c_for_pbnt = FALSE;
    WFileName pj;
    WFileName cfg;
    WStringList parms( cmd );
    int jcount = parms.count();
    for( int j=0; j<jcount; j++ ) {
        if( parms.stringAt( j ) == "-c" ) {
            if( j+1 < parms.count() ) {
                j++;
                cfg = parms.cStringAt( j );
            }
        } else if( parms.stringAt( j ) == "-b" ) {
            _batchOk = FALSE;
        } else if( parms.stringAt( j ) == "-d" ) {
            debug = TRUE;
        } else if( parms.stringAt( j ) == "-pb" ) {
            c_for_pb = TRUE;
        } else if( parms.stringAt( j ) == "-pbnt" ) {
            c_for_pbnt = TRUE;
        } else {
            pj = parms.cStringAt( j );
        }
    }

    setIcon( I_Viper );

    WFlashPage* flash = new WFlashPage( NULL, &_hotSpotList, 4, _viperTitle, _viperDesc );

    new MConfig( cfg, debug );
    if( !_config->ok() ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, (const char*)_config->errMsg() );
    }
    _config->enumAccel( this, (bcbk)&VpeMain::registerAccel );

    _editor = _config->editor();
    _editorIsDll = _config->editorIsDLL();

    buildMenuBar();

    createStatusBar();

    _help = new WSystemHelp( this, _viperTitle, _config->helpFile() );

    if( !_config->debug() ) {
        _myHandle.printf( "V%04x", proc.processId() );
    }

//    _server = new WServer( _myHandle, _myHandle, this, (sbc)&VpeMain::serverNotify );
//    _editorClient = new WClient( this, (cbc)&VpeMain::editorNotify );
//    _browseClient = new WClient( this, (cbc)&VpeMain::browseNotify );

    if( pj.size() > 0 ) {
        if( c_for_pb ) {
            cForPBProject( pj, FALSE );
        } else if( c_for_pbnt ) {
            cForPBProject( pj, TRUE );
        } else {
            validateProjectName( pj );
            loadProject( pj );
        }
    }
    readIdeInit();
    if( _editorIsDll ) {
        loadNewEditor( _editor );
    }
    if( !_rcsClient.Init() ) {
        WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
        "Unable to load the source control DLL.\n"
        "Source control functions will not be available" );
    }
    updateView();

    delete flash;
    show( WWinStateShowNormal );
}

WEXPORT VpeMain::~VpeMain()
{
    hookF1Key( FALSE );
//    delete _server;
//    _editorClient->disconnect();
//    delete _editorClient;
//    _browseClient->disconnect();
//    delete _browseClient;

    delete _project;
    delete _config;
    _compViews.deleteContents();
    _oldProjects.deleteContents();
    delete _msgLog;
    if( _editorDll.isInitialized() ) {
        _editorDll.EDITDisconnect();
    }
}

#ifndef NOPERSIST
VpeMain* WEXPORT VpeMain::createSelf( WObjectFile& )
{
    return( NULL );
}

void WEXPORT VpeMain::readSelf( WObjectFile& p )
{
    WRect r; p.readObject( &r );
    if( p.version() < 36 ) {
        r.w( (WOrdinal)((long)r.w()*10240/640) );
        r.h( (WOrdinal)((long)r.h()*10240/480) );
    }
//    move( r );
    if( isMaximized() ) {
        GUIMaximizeWindow( handle() );
    } else {
        size( r.w(), r.h() );
    }
    update();
    show();     //in case this is the first time
    setUpdates( FALSE );
    _project = (MProject*)p.readObject();
    attachModel( _project );
    p.readObject( &_compViews );
    _activeVComp = (VComponent*)p.readObject();
    if( !_activeVComp && _compViews.count() > 0 ) {
        _activeVComp = (VComponent*)_compViews[0];
    }
    if( _activeVComp ) {
        _activeVComp->setFocus();
    }
    setUpdates();
}

typedef int (WObject::*cofn)( WFileName *, WString &, WString & );
void WEXPORT VpeMain::writeSelf( WObjectFile& p )
{
    WRect r; getRectangle( r );
    p.writeObject( &r, FORCE );
    _project->setRCS( &_rcsClient, (cofn)&VRcsClient::Checkout );
    p.writeObject( _project );
    p.writeObject( &_compViews );
    p.writeObject( _activeVComp );
}
#endif

bool VpeMain::registerAccel( WKeyCode kc )
{
    removeAccelKey( kc );
    addAccelKey( kc, this, (bcbk)&VpeMain::kDynAccel );
    return( FALSE );
}


void VpeMain::setStatus( const char* msg )
{
    if( _statusBar ) {
        _statusBar->setStatus( msg );
    }
}

void VpeMain::toolPicked( WToolBarItem* tool )
{
    ToolType typ = ((VToolItem*)tool)->toolType();
    if( typ == TOOL_MENU ) {
        WMenuItem* mitem = (WMenuItem*)tool->tagPtr();
        mitem->picked();
    } else {
        MToolItem* mt = (MToolItem*)tool->tagPtr();
        if( typ == TOOL_PROJECT_ACTION ) {
            doAction( mt->actionName() );
        } else if( _activeVComp ) {
            _activeVComp->setFocus();
            if( typ == TOOL_ITEM_ACTION ) {
                MItem* m = _activeVComp->selectedItem();
                if( m ) {
                    _activeVComp->doAction( m, mt->actionName() );
                }
            } else if( typ == TOOL_TARGET_ACTION ) {
                _activeVComp->doAction( _activeVComp->target(), mt->actionName() );
            }
        }
    }
}

bool VpeMain::toolChanged( WToolBar* /*tool*/, WToolBarState state )
{
    switch( state ) {
        case WToolBarClosed: {
            _toolBarActive = FALSE;
            break;
        }
    }
    return( TRUE );
}

void VpeMain::buildMenuBar()
{
    setUpdates( FALSE );
    delete clearToolBar();
    delete clearMenu();

    removeAccelKey( WKeyInsert );
    removeAccelKey( WKeyDelete );
    removeAccelKey( WKeyCtrlN );
    removeAccelKey( WKeyCtrlO );
    removeAccelKey( WKeyCtrlS );
    removeAccelKey( WKeyDelete );

    WMenu* menuBar = new WMenu();
    VToolBar* toolBar = new VToolBar();
    toolBar->onChanged( this, (cbtb)&VpeMain::toolChanged );

    WPopupMenu* pop0 = makeMenu( &popup0, toolBar );
    menuBar->insertPopup( pop0, 0 );

    WPopupMenu* pop1 = makeMenu( &popup1, toolBar );
    menuBar->insertPopup( pop1, 1 );

    WPopupMenu* pop2 = makeMenu( &popup2, toolBar );
    menuBar->insertPopup( pop2, 2 );
    _targetPopup = pop2;

    WPopupMenu* pop3 = makeMenu( &popup3, toolBar );
    menuBar->insertPopup( pop3, 3 );
    _itemsPopup = pop3;

    WPopupMenu* pop4 = makeMenu( &popup4, toolBar );
    menuBar->insertPopup( pop4, 4 );

    WPopupMenu* pop5 = makeMenu( &popup5, toolBar );
    menuBar->insertPopup( pop5, 5 );
    _logPopup = pop5;

⌨️ 快捷键说明

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