optmgr.cpp

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

CPP
797
字号
/****************************************************************************
*
*                            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:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <string.h>
#include <mbctype.h>

#include <wfiledlg.hpp>
#include <wfilenam.hpp>
#include <wmsgdlg.hpp>

#include "assure.h"
#include "browse.h"
#include "busyntc.h"
#include "chbffile.h"
#include "death.h"
#include "eddlldg.h"
#include "fileinfo.h"
#include "gtcllopt.h"
#include "gtinhopt.h"
#include "death.h"
#include "enumstl.h"
#include "memfilt.h"
#include "menuids.h"
#include "querycfg.h"
#include "rxcfg.h"
#include "viewmgr.h"
#include "wbrwin.h"

#define SIG     "WATCOM Source Browser Option File\032\015\023"
#define SIGLEN  (sizeof(SIG))
#define VER     "VER 1.1"
#define VERLEN  (sizeof(VER))

static char * OBRFilter = "Option File (*.obr)\0" "*.obr\0"
                          "All Files(*.*)\0" "*.*\0\0";
static char * DefaultOBRFile = "setup.obr";

const MemberFilter DefaultMemFilt = {
    MemberFilter::ILNoInherited,// don't show any inherited members
    MemberFilter::AccAll,       // show members with any access (public,etc)
    MemberFilter::MemAll        // show all members (static, virt, variables, functions)
};
const RXOptions      DefaultRXOpt = {
    TRUE,                       // RX anchored
    "",                         // all RX characters
};

static const char * DefaultEditorParms = "%f";
#if defined( __OS2__ )
    static bool DefaultEditorIsDLL = TRUE;
    static const char * DefaultEditor = "epmlink";
#else
#pragma initialize before program
    static bool DefaultEditorIsDLL = !__IsDBCS;
    static const char * DefaultEditor =
        ( __IsDBCS ? "notepad.exe" : "weditviw.dll" );
#endif

OptionManager::OptionSet::OptionSet()
        : _memberFilter( DefaultMemFilt )
        , _enumStyle( EV_HexLowerCase )     // enum-view style is 0xa5
        , _treeAutoArrange( FALSE )
        , _treeDirection( TreeVertical )
        , _edgeType( EdgesStraight )
        , _ignoreCase( TRUE )
        , _wholeWord( FALSE )
        , _useRX( FALSE )
        , _rxOptions( DefaultRXOpt )
        , _classOpts( GTClassOpts() )
        , _functionOpts( GTFunctionOpts() )
        , _autoSave( FALSE )
//----------------------------------------------------------------------
{
}

static OptionManager::OptionSet OptionManager::_default;

OptionManager::OptionManager()
        : _menuManager( NULL )
        , _modified( FALSE )
        , _fileName( NULL )
        , _queryConfig( NULL )
        , _editorName( DefaultEditor )
        , _editorIsDLL( DefaultEditorIsDLL )
        , _editorParms( DefaultEditorParms )
//------------------------------------------
{
}

OptionManager::~OptionManager()
//-----------------------------
{
    delete _fileName;
    delete _queryConfig;
    delete _inheritOption;
    delete _callOption;
}

static MIMenuID OptManagerMenus[] = {
    MIMenuID( MMFile,           FMLoad ),
    MIMenuID( MMFile,           FMSave ),
    MIMenuID( MMFile,           FMSaveAs ),
    MIMenuID( MMOptions,        OMRegExp ),
    MIMenuID( MMOptions,        OMMemberFilters ),
    MIMenuID( MMOptions,        OMQuery ),
    MIMenuID( MMOptions,        OMEnumStyles ),
    MIMenuID( MMOptions,        OMTreeAutoArrange ),
    MIMenuID( MMOptions,        OMTreeSquareLines ),
    MIMenuID( MMOptions,        OMTreeHorizontal ),
    MIMenuID( MMOptions,        OMInheritTreeLegend ),
    MIMenuID( MMOptions,        OMCallTreeLegend ),
    MIMenuID( MMOptions,        OMEditorDLL ),
    MIMenuID( MMOptions,        OMAutoSave ),
};

#define NumOptMgrMenus ( sizeof( OptManagerMenus ) / sizeof( MIMenuID ) )

void OptionManager::setMenus( MenuManager * mgr )
//-----------------------------------------------
{
    int i;

    _menuManager = mgr;
    for( i = 0; i < NumOptMgrMenus; i += 1 ) {
        _menuManager->registerForMenu( this, OptManagerMenus[ i ] );
    }
}

void OptionManager::unSetMenus( MenuManager * )
//---------------------------------------------
{
    int i;

    for( i = 0; i < NumOptMgrMenus; i += 1 ) {
        _menuManager->unRegister( OptManagerMenus[ i ] );
    }

    _menuManager = NULL;
}

void OptionManager::menuSelected( const MIMenuID & id )
//-----------------------------------------------------
{
    switch( id.mainID() ) {
    case MMFile:
        switch( id.subID() ) {
        case FMLoad:
            load();
            break;
        case FMSave:
            if( hasFile() ) {
                saveTo( _fileName->gets() );
            } else {
                saveTo( DefaultOBRFile );
            }
            break;
        case FMSaveAs:
            save();
            break;
        default:
            NODEFAULT;
        }
        break;
    case MMOptions:
        switch( id.subID() ) {
        case OMRegExp:
            editRegExp();
            break;
        case OMMemberFilters:
            editMemberFilters();
            break;
        case OMQuery:
            editQuery();
            break;
        case OMEnumStyles:
            editEnumStyle();
            break;
        case OMTreeAutoArrange:
            toggleTreeAutoArrange();
            break;
        case OMTreeSquareLines:
            toggleEdgeType();
            break;
        case OMTreeHorizontal:
            toggleTreeDirection();
            break;
        case OMInheritTreeLegend:
            editInheritLegend();
            break;
        case OMCallTreeLegend:
            editCallLegend();
            break;
        case OMEditorDLL:
            editEditorDLL();
            break;
        case OMAutoSave:
            toggleAutoSave();
            break;
        default:
            NODEFAULT;
        }
        break;
    default:
        NODEFAULT;
    }
}

bool OptionManager::exit()
//------------------------
{
    MsgRetType ret;

    if( _current._autoSave && hasFile() ) {
        saveTo( _fileName->gets() );
        return TRUE;    // ok to terminate
    }

    if( _modified || _current._autoSave ) {
        if( hasFile() ) {
            ret = WMessageDialog::messagef( topWindow, MsgQuestion,
                                        MsgYesNoCancel, "Source Browser",
                                        "Save Option changes to %s?",
                                        _fileName->gets() );
        } else {
            ret = WMessageDialog::message( topWindow, MsgQuestion,
                                        MsgYesNoCancel,
                                        "Save Option changes?",
                                        "Source Browser" );
        }
        switch( ret ) {
        case MsgRetYes:
            if( hasFile() ) {
                saveTo( _fileName->gets() );
                return TRUE;
            } else {
                return save();      // terminate only if save works
            }
        case MsgRetNo:
            return TRUE;            // terminate
        default:
            return FALSE;           // don't terminate
        }
    }
    return TRUE;
}

bool OptionManager::isModified() const
//------------------------------------
{
    return _modified;
}

void OptionManager::editMemberFilters()
//-------------------------------------
{
    MemberFilterDlg dlg( topWindow, _default._memberFilter,
                         _current._memberFilter );

    if( dlg.process() ) {
        modified();
    }
}

void OptionManager::editEnumStyle()
//---------------------------------
{
    EnumStyleEdit dlg( topWindow, _default._enumStyle,
                        _current._enumStyle );

    if( dlg.process() ) {
        modified();
    }
}

void OptionManager::toggleTreeAutoArrange()
//-----------------------------------------
{
    _current._treeAutoArrange = !_current._treeAutoArrange;
    modified();
}

void OptionManager::toggleEdgeType()
//----------------------------------
{
    _current._edgeType = (_current._edgeType == EdgesSquare) ?
                         EdgesStraight : EdgesSquare;
    modified();
}

void OptionManager::toggleTreeDirection()
//---------------------------------------
{
    _current._treeDirection = (_current._treeDirection == TreeVertical) ?
                         TreeHorizontal : TreeVertical;
    modified();
}

void OptionManager::editInheritLegend()
//-------------------------------------
{
    if( !_inheritOption ) {
        _inheritOption = new GTInheritOption( _current._classOpts );
    }
    _inheritOption->process( topWindow );
}

void OptionManager::editCallLegend()
//----------------------------------
{
    if( !_callOption ) {
        _callOption = new GTCallOption( _current._functionOpts );
    }
    _callOption->process( topWindow );
}

void OptionManager::editRegExp()
//------------------------------
{
    RegExpCfg rxcfg( topWindow, _default._rxOptions, _current._rxOptions );

    if( rxcfg.process() ) {
        modified();
    }
}

void OptionManager::editQuery()
//-----------------------------
{
    if( !_queryConfig ) {
        _queryConfig = new QueryConfig( &_queryKey, NULL, "Query" );
    }

    if( _queryConfig->process( topWindow ) ) {
        modified();
        WBRWinBase::viewManager()->eventOccured( VEQueryFiltChange, NULL );
    }
}

void OptionManager::editEditorDLL()
//---------------------------------
{
    NewEditDLL  edit( browseTop, _editorName, _editorIsDLL, _editorParms,
                      DefaultEditor, DefaultEditorIsDLL, DefaultEditorParms );

    if( edit.process() ) {
        setEditor( edit.getEditor(), edit.isEditorDLL(), edit.getEditorParms());
    }
}

void OptionManager::toggleAutoSave()
//----------------------------------
{
    _current._autoSave = !_current._autoSave;
    modified();
}

void OptionManager::checkMenus()
//------------------------------
{
    _menuManager->checkMenu( MIMenuID( MMOptions, OMAutoSave ),
                             _current._autoSave );
    _menuManager->checkMenu( MIMenuID( MMOptions, OMTreeAutoArrange ),
                             _current._treeAutoArrange );
    _menuManager->checkMenu( MIMenuID( MMOptions, OMTreeSquareLines ),
                             _current._edgeType == EdgesSquare );
    _menuManager->checkMenu( MIMenuID( MMOptions, OMTreeHorizontal ),
                             _current._treeDirection == TreeHorizontal );
}

const char * OptionManager::fileName() const

⌨️ 快捷键说明

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