vpemain.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 2,090 行 · 第 1/5 页
CPP
2,090 行
}
bool VpeMain::saveProjectAs( const WFileName& def )
{
if( checkProject() ) {
WFileDialog fd( this, pFilter );
WFileName fn( fd.getSaveFileName( def, "Save Project as", WFSaveDefault ) );
if( fn.legal() && okToReplace( fn ) ) {
// fn.toLower();
_project->setFilename( fn );
addOldProject( fn );
return( unloadProject( fn ) );
}
}
return( FALSE );
}
void VpeMain::setBefore( WMenuItem* )
{
HelpStack.push( HLP_EXECUTING_SPECIAL_COMMANDS );
WEditDialog ed( this, ".Before text" );
MCommand txt( _project->before() );
if( ed.edit( txt ) ) {
_project->setBefore( txt );
}
HelpStack.pop();
}
void VpeMain::setAfter( WMenuItem* )
{
HelpStack.push( HLP_EXECUTING_SPECIAL_COMMANDS );
WEditDialog ed( this, ".After text" );
MCommand txt( _project->after() );
if( ed.edit( txt ) ) {
_project->setAfter( txt );
}
HelpStack.pop();
}
void VpeMain::setCompBefore( WMenuItem* )
{
HelpStack.push( HLP_EXECUTING_SPECIAL_COMMANDS );
_activeVComp->setFocus();
_activeVComp->setCompBefore();
HelpStack.pop();
}
void VpeMain::setCompAfter( WMenuItem* )
{
HelpStack.push( HLP_EXECUTING_SPECIAL_COMMANDS );
_activeVComp->setFocus();
_activeVComp->setCompAfter();
HelpStack.pop();
}
bool VpeMain::optionToSave()
{
MsgRetType ret = WMessageDialog::messagef( this, MsgQuestion, MsgYesNoCancel, _viperRequest,
"The project %s is being closed. Do you want to save the changes that were made in this session?", (const char*)_project->filename() );
if( ret == MsgRetCancel ) {
return( FALSE );
}
if( ret == MsgRetYes ) {
return( saveProject() );
}
return( TRUE );
}
bool VpeMain::okToQuit()
{
if( running() ) {
MsgRetType ret = WMessageDialog::messagef( this, MsgInfo, MsgOkCancel, NULL,
"Batch execution is busy. Quit anyways?" );
if( ret == MsgRetOk ) {
_quitAnyways = TRUE;
_msgLog->killBatcher();
}
return( FALSE );
} else if( _project && _project->isDirty() ) {
return( optionToSave() );
}
return( TRUE );
}
bool VpeMain::okToClear()
{
if( running() ) {
WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Can't close project while batch execution is active" );
return( FALSE );
} else if( _project && _project->isDirty() ) {
return( optionToSave() );
}
return( TRUE );
}
void VpeMain::clearProject()
{
setUpdates( FALSE );
setStatus( "Clearing project..." );
delete _project;
_project = NULL;
_neverSaved = FALSE;
_activeVComp = NULL;
_compViews.deleteContents();
deleteMsglog();
setUpdates();
setStatus( NULL );
}
void VpeMain::deleteMsglog()
{
delete _msgLog;
_msgLog = NULL;
}
void VpeMain::toolBar( WMenuItem* )
{
if( _toolBarActive ) {
delete clearToolBar();
_toolBarActive = FALSE;
} else {
buildMenuBar();
}
}
void VpeMain::createStatusBar()
{
if( !_statusBar ) {
int h = getTextExtentY( "X" ) * 3/2;
_statusBar = new WStatWindow( this, WRect( 0,-h,-1,h), "Ready" );
_statusBar->show();
}
}
void VpeMain::deleteStatusBar()
{
delete _statusBar;
_statusBar = NULL;
}
void VpeMain::setEditor( WMenuItem* ) {
VEditDlg dlg( this, _editor, _editorParms, _editorIsDll );
WFileName fn( _editor );
WString parms( _editorParms );
bool isdll;
isdll = _editorIsDll;
if( dlg.process( fn, parms, isdll ) ) {
if( isdll != _editorIsDll ||
!( fn == _editor ) || !( parms == _editorParms ) ) {
_editorIsDll = isdll;
_editor = fn;
_editorParms = parms;
_editorDll.UnloadDll();
if( _editorIsDll ) {
loadNewEditor( _editor );
}
}
}
}
void VpeMain::statusBar( WMenuItem* )
{
if( _statusBar ) {
deleteStatusBar();
} else {
createStatusBar();
}
}
bool VpeMain::createDirectory( const WFileName& f )
{
WFileName d( f );
d.absoluteTo( _project->filename() );
if( !d.dirExists() ) {
if( !confirm( "Do you want to create directory for '%s'?", f ) ) {
return( FALSE );
}
if( !d.makeDir() ) {
WMessageDialog::messagef( this, MsgError, MsgOk, _viperError,
"Unable to create directory for '%s'", (const char *)f );
return( FALSE );
}
}
return( TRUE );
}
#if 0
char* VpeMain::getFilters()
{
WStringList filtList;
int maxLen = 0;
WPickList& rules = _config->rules();
int icount = rules.count();
for( int i=0; i<icount; i++ ) {
MRule* r = (MRule*)rules[i];
if( r->ismakeable() ) {
WString* name = new WString();
r->name( *name );
name->concatf( "(%s)", (char*)r->mask() );
filtList.add( name );
maxLen += name->size() + 1;
filtList.add( new WString( r->mask() ) );
maxLen += r->mask().size() + 1;
}
}
filtList.add( new WString( "All Files(*.*)" ) );
maxLen += 14 + 1;
filtList.add( new WString( "*.*" ) );
maxLen += 3 + 1;
char* filts = new char[ maxLen + 1 ];
int off = 0;
icount = filtList.count();
for( i=0; i<icount; i++ ) {
char* p = filtList.cStringAt( i );
strcpy( &filts[off], p );
off += strlen( p ) + 1;
}
filts[off] = '\0';
return( filts );
}
#endif
WStyle VpeMain::vCompStyle()
{
if( _activeVComp ) {
if( !_activeVComp->isMaximized() ) {
return( WStyleDefault );
}
}
return( WStyleDefault | WStyleMaximize );
}
bool VpeMain::addComponent( WMenuItem* )
{
static char cFilter[] = { "Target Files(*.tgt)\0*.tgt\0Executables(*.exe)\0*.exe\0Static Libraries(*.lib)\0*.lib\0Dynamic Libraries(*.dll)\0*.dll\0All files(*.*)\0*.*\0\0" };
bool ok = FALSE;
HelpStack.push( HLP_ADDING_A_TARGET );
VCompDialog dlg( this, "New Target", _project, cFilter );
WFileName fn( _project->filename().fName() );
MRule* rule;
WString mask;
if( dlg.process( fn, &rule, mask, NULL ) ) {
setStatus( "Adding.." );
startWait();
if( strieq( fn.ext(), ".tgt" ) ) {
ok = attachTgtFile( fn );
} else {
if( createDirectory( fn ) ) {
MComponent* mcomp = new MComponent( _project, rule, mask, fn );
_project->addComponent( mcomp );
VComponent* vcomp = new VComponent( this, mcomp, vCompStyle() );
_compViews.add( vcomp );
mcomp->updateItemList();
ok = TRUE;
}
}
stopWait();
setStatus( NULL );
}
HelpStack.pop();
return( ok );
}
void VpeMain::vAddComponent( WMenuItem* )
{
addComponent();
}
bool VpeMain::attachTgtFile( WFileName& fn )
{
bool ok = FALSE;
MComponent* mcomp = _project->attachComponent( fn );
if( !mcomp ) {
WMessageDialog::messagef( this, MsgError, MsgOk, _viperError, "Unable to read file '%s'", (const char*)fn );
} else {
VComponent* vcomp = new VComponent( this, mcomp, vCompStyle() );
_compViews.add( vcomp );
ok = TRUE;
}
return( ok );
}
void VpeMain::removeComponent( WMenuItem* )
{
_activeVComp->setFocus();
MComponent* comp = (MComponent*)_activeVComp->model();
WFileName target( *comp->target() );
target.setExt( ".tgt" );
if( confirm( "Are you sure you wish to remove '%s'?", target ) ) {
delete _compViews.removeSame( _activeVComp );
delete _project->removeComponent( comp );
}
}
void VpeMain::renameComponent( WMenuItem* )
{
HelpStack.push( HLP_RENAMING_A_TARGET );
_activeVComp->setFocus();
VComponent* vcomp = _activeVComp;
//static char cFilter[] = { "Executables(*.exe)\0*.exe\0Static Libraries(*.lib)\0*.lib\0Dynamic Libraries(*.dll)\0*.dll\0All files(*.*)\0*.*\0\0" };
static char cFilter[] = { "Target Files(*.tgt)\0*.tgt\0Executables(*.exe)\0*.exe\0Static Libraries(*.lib)\0*.lib\0Dynamic Libraries(*.dll)\0*.dll\0All files(*.*)\0*.*\0\0" };
VCompDialog dlg( this, "Rename Target", _project, cFilter );
MComponent* comp = vcomp->component();
WFileName fn( comp->relFilename() );
fn.setExt( vcomp->target()->ext() );
MRule* rule;
WString mask;
if( dlg.process( fn, &rule, mask, comp ) ) {
if( strieq( fn.ext(), ".tgt" ) ) {
WRect rr; vcomp->getRectangle( rr );
if( attachTgtFile( fn ) ) {
VComponent* newvc = _activeVComp;
delete _compViews.removeSame( vcomp );
delete _project->removeComponent( comp );
_activeVComp = newvc;
_activeVComp->move( rr );
_activeVComp->setFocus();
}
} else {
vcomp->renameComponent( fn, rule, mask );
}
}
HelpStack.pop();
}
void VpeMain::setupComponent( WMenuItem* )
{
_activeVComp->setFocus();
_activeVComp->setupComponent();
}
void VpeMain::showCompCommand( WMenuItem* )
{
_activeVComp->setFocus();
_activeVComp->showCompCommand();
}
void VpeMain::touchComponent( WMenuItem* )
{
_activeVComp->setFocus();
_activeVComp->touchComponent();
}
void VpeMain::mAutodepend( WMenuItem* )
{
_activeVComp->setFocus();
_activeVComp->mAutodepend();
}
void VpeMain::mAutotrack( WMenuItem* )
{
_activeVComp->setFocus();
_activeVComp->mAutotrack();
}
void VpeMain::mDebugMode( WMenuItem* )
{
_activeVComp->setFocus();
_activeVComp->mDebugMode();
}
void VpeMain::mHint( WMenuItem*, const char* hint )
{
setStatus( hint );
}
void VpeMain::mAddItem( WMenuItem* )
{
kAddItem( WKeyNone );
}
bool VpeMain::kAddItem( WKeyCode )
{
bool ret;
ret = FALSE;
if( _activeVComp ) {
HelpStack.push( HLP_ADDING_SOURCE_FILES );
_activeVComp->setFocus();
_activeVComp->mAddItem();
ret = TRUE;
HelpStack.pop();
}
return( ret );
}
bool VpeMain::kDynAccel( WKeyCode kc ) {
bool done;
MAction *action;
int i;
done = FALSE;
// search project level accelerators
int icount = _config->actions().count();
for( i=0; i<icount; i++ ) {
action = (MAction*)_config->actions()[i];
if( action->menuAccel() == kc ) {
doAction( action );
done = TRUE;
break;
}
}
if( _activeVComp ) {
MItem *m;
WVList actlist;
// search target level accelerators
if( !done ) {
m = _activeVComp->target();
if( m ) {
m->addActions( actlist );
icount = actlist.count();
for( i=0; i<icount; i++ ) {
action = (MAction*)actlist[i];
if( action->menuAccel() == kc ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?