/* * FileExitOptionSaveChanges - exit file, giving option to save if modified */ bool FileExitOptionSaveChanges( file *f ) { bool aborted = FALSE; char buffer[MAX_STR]; #ifdef __WIN__ int resp; vi_rc rc; MySprintf( buffer, "\"%s\" has been modified - save changes?", f->name ); resp = MessageBox( Root, buffer, EditorName, MB_YESNOCANCEL | MB_TASKMODAL ); if( resp == IDYES ) { rc = SaveFile( NULL, -1, -1, FALSE ); if( rc != ERR_NO_ERR ) { MySprintf( buffer, "Error saving \"%s\"", f->name ); MessageBox( Root, buffer, EditorName, MB_OK | MB_TASKMODAL ); aborted = TRUE; } else { NextFileDammit(); } } else if( resp == IDCANCEL ) { aborted = TRUE; } else { NextFileDammit(); } #else char response[MAX_SRC_LINE]; MySprintf( buffer, "\"%s\" has been modified - save changes (yes|no|cancel)?", f->name ); if( GetResponse( buffer, response ) == GOT_RESPONSE ) { switch( response[0] ) { case 0: // if the user hit ENTER then the buffer will be // a string of 0 chars so act as if y had been hit case 'y': case 'Y': SaveAndExit( NULL ); break; case 'n': case 'N': NextFileDammit(); break; case 'c': case 'C': default: aborted = TRUE; // return( FALSE ); } } else { aborted = TRUE; } #endif return aborted; } /* FileOptionExitSaveChanges */
bool EditRomInfoDialog::Create() { if (!LoadWindowFromXML("game-ui.xml", "edit_metadata", this)) return false; bool err = false; UIUtilE::Assign(this, m_gamenameEdit, "title_edit", &err); UIUtilE::Assign(this, m_genreEdit, "genre_edit", &err); UIUtilE::Assign(this, m_yearEdit, "year_edit", &err); UIUtilE::Assign(this, m_countryEdit, "country_edit", &err); UIUtilE::Assign(this, m_plotEdit, "description_edit", &err); UIUtilE::Assign(this, m_publisherEdit, "publisher_edit", &err); UIUtilE::Assign(this, m_favoriteCheck, "favorite_check", &err); UIUtilE::Assign(this, m_screenshotButton, "screenshot_button", &err); UIUtilE::Assign(this, m_screenshotText, "screenshot_text", &err); UIUtilE::Assign(this, m_fanartButton, "fanart_button", &err); UIUtilE::Assign(this, m_fanartText, "fanart_text", &err); UIUtilE::Assign(this, m_boxartButton, "coverart_button", &err); UIUtilE::Assign(this, m_boxartText, "coverart_text", &err); UIUtilE::Assign(this, m_doneButton, "done_button", &err); if (err) { VERBOSE(VB_IMPORTANT, "Cannot load screen 'edit_metadata'"); return false; } fillWidgets(); BuildFocusList(); connect(m_gamenameEdit, SIGNAL(valueChanged()), SLOT(SetGamename())); connect(m_genreEdit, SIGNAL(valueChanged()), SLOT(SetGenre())); connect(m_yearEdit, SIGNAL(valueChanged()), SLOT(SetYear())); connect(m_countryEdit, SIGNAL(valueChanged()), SLOT(SetCountry())); connect(m_plotEdit, SIGNAL(valueChanged()), SLOT(SetPlot())); connect(m_publisherEdit, SIGNAL(valueChanged()), SLOT(SetPublisher())); connect(m_favoriteCheck, SIGNAL(valueChanged()), SLOT(ToggleFavorite())); connect(m_screenshotButton, SIGNAL(Clicked()), SLOT(FindScreenshot())); connect(m_fanartButton, SIGNAL(Clicked()), SLOT(FindFanart())); connect(m_boxartButton, SIGNAL(Clicked()), SLOT(FindBoxart())); connect(m_doneButton, SIGNAL(Clicked()), SLOT(SaveAndExit())); return true; }
/* * StartSaveExit - prepare to do save & exit of file */ vi_rc StartSaveExit( void ) { vi_key key; vi_key levent; /* * get the next key */ levent = LastEvent; key = GetNextEvent( FALSE ); if( key != levent ) { if( key == VI_KEY( ESC ) ) { return( ERR_NO_ERR ); } return( InvalidKey() ); } return( SaveAndExit( NULL ) ); } /* StartSaveExit */
/* * EditFileFromList - edit from file in current active list */ vi_rc EditFileFromList( void ) { int i, tmp, j, n = 0, fcnt; window_id optwin; bool repeat = true; info *cinfo; char **list, modchar; vi_key evlist[4] = { VI_KEY( F1 ), VI_KEY( F2 ), VI_KEY( F3 ), VI_KEY( DUMMY ) }; bool show_lineno; window_info wi; selectitem si; vi_rc rc; /* * set up options for file list */ memcpy( &wi, &extraw_info, sizeof( window_info ) ); wi.x1 = 2; wi.x2 = 19; rc = DisplayExtraInfo( &wi, &optwin, fileOpts, NUM_OPTS ); if( rc != ERR_NO_ERR ) { return( rc ); } while( repeat ) { /* * set up for this pass */ repeat = false; MoveWindowToFrontDammit( optwin, false ); SaveCurrentInfo(); /* * allocate a buffer for strings, add strings */ list = (char **) MemAlloc( GimmeFileCount() * sizeof( char * ) ); for( j = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next, ++j ) { list[j] = MemAlloc( strlen( cinfo->CurrentFile->name ) + 3 ); if( cinfo->CurrentFile->modified ) { modchar = '*'; } else { modchar = ' '; } MySprintf( list[j], "%c %s", modchar, cinfo->CurrentFile->name ); } fcnt = j; tmp = filelistw_info.y2; i = filelistw_info.y2 - filelistw_info.y1 + 1; if( filelistw_info.has_border ) { i -= 2; } if( j < i ) { filelistw_info.y2 -= ( i - j ); } show_lineno = true; /* * get file */ if( n + 1 > j ) { n = j - 1; } memset( &si, 0, sizeof( si ) ); si.wi = &filelistw_info; si.title = "Current Files"; si.list = list; si.maxlist = j; si.num = n; si.retevents = evlist; si.event = VI_KEY( DUMMY ); si.show_lineno = show_lineno; si.cln = n + 1; si.eiw = optwin; rc = SelectItem( &si ); n = si.num; if( rc == ERR_NO_ERR ) { if( n >= 0 ) { cinfo = InfoHead; for( j = 0; j < n; ++j ) { cinfo = cinfo->next; } BringUpFile( cinfo, true ); switch( si.event ) { case VI_KEY( DUMMY ): case VI_KEY( F1 ): break; case VI_KEY( F2 ): rc = NextFile(); if( rc <= ERR_NO_ERR ) { repeat = true; } break; case VI_KEY( F3 ): rc = SaveAndExit( NULL ); if( rc <= ERR_NO_ERR ) { repeat = true; } break; } } } filelistw_info.y2 = tmp; MemFreeList( fcnt, list ); } /* * get rid of option stuff */ CloseAWindow( optwin ); return( rc ); } /* EditFileFromList */
//----------------------------------------------------------------------------- // Purpose: // Input : wParam - // lParam - // Output : LRESULT //----------------------------------------------------------------------------- LRESULT CTextureBrowser::OnTextureWindowDblClk(WPARAM wParam, LPARAM lParam) { WriteSettings(); SaveAndExit(); return(0); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTextureBrowser::OnCancel() { WriteSettings(); SaveAndExit(); CDialog::OnCancel(); }
bool EditMetadataDialog::Create() { if (!LoadWindowFromXML("video-ui.xml", "edit_metadata", this)) return false; bool err = false; UIUtilE::Assign(this, m_titleEdit, "title_edit", &err); UIUtilE::Assign(this, m_subtitleEdit, "subtitle_edit", &err); UIUtilE::Assign(this, m_playerEdit, "player_edit", &err); UIUtilE::Assign(this, m_seasonSpin, "season", &err); UIUtilE::Assign(this, m_episodeSpin, "episode", &err); UIUtilE::Assign(this, m_categoryList, "category_select", &err); UIUtilE::Assign(this, m_levelList, "level_select", &err); UIUtilE::Assign(this, m_childList, "child_select", &err); UIUtilE::Assign(this, m_browseCheck, "browse_check", &err); UIUtilE::Assign(this, m_watchedCheck, "watched_check", &err); UIUtilE::Assign(this, m_doneButton, "done_button", &err); if (err) { LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'edit_metadata'"); return false; } UIUtilW::Assign(this, m_coverartText, "coverart_text"); UIUtilW::Assign(this, m_screenshotText, "screenshot_text"); UIUtilW::Assign(this, m_bannerText, "banner_text"); UIUtilW::Assign(this, m_fanartText, "fanart_text"); UIUtilW::Assign(this, m_trailerText, "trailer_text"); UIUtilW::Assign(this, m_coverartButton, "coverart_button"); UIUtilW::Assign(this, m_bannerButton, "banner_button"); UIUtilW::Assign(this, m_fanartButton, "fanart_button"); UIUtilW::Assign(this, m_screenshotButton, "screenshot_button"); UIUtilW::Assign(this, m_trailerButton, "trailer_button"); UIUtilW::Assign(this, m_netBannerButton, "net_banner_button"); UIUtilW::Assign(this, m_netFanartButton, "net_fanart_button"); UIUtilW::Assign(this, m_netScreenshotButton, "net_screenshot_button"); UIUtilW::Assign(this, m_netCoverartButton, "net_coverart_button"); UIUtilW::Assign(this, m_taglineEdit, "tagline_edit"); UIUtilW::Assign(this, m_ratingEdit, "rating_edit"); UIUtilW::Assign(this, m_directorEdit, "director_edit"); UIUtilW::Assign(this, m_inetrefEdit, "inetref_edit"); UIUtilW::Assign(this, m_homepageEdit, "homepage_edit"); UIUtilW::Assign(this, m_plotEdit, "description_edit"); UIUtilW::Assign(this, m_yearSpin, "year_spin"); UIUtilW::Assign(this, m_userRatingSpin, "userrating_spin"); UIUtilW::Assign(this, m_lengthSpin, "length_spin"); UIUtilW::Assign(this, m_coverart, "coverart"); UIUtilW::Assign(this, m_screenshot, "screenshot"); UIUtilW::Assign(this, m_banner, "banner"); UIUtilW::Assign(this, m_fanart, "fanart"); fillWidgets(); BuildFocusList(); connect(m_titleEdit, SIGNAL(valueChanged()), SLOT(SetTitle())); m_titleEdit->SetMaxLength(128); connect(m_subtitleEdit, SIGNAL(valueChanged()), SLOT(SetSubtitle())); m_subtitleEdit->SetMaxLength(0); connect(m_playerEdit, SIGNAL(valueChanged()), SLOT(SetPlayer())); if (m_taglineEdit) { connect(m_taglineEdit, SIGNAL(valueChanged()), SLOT(SetTagline())); m_taglineEdit->SetMaxLength(255); } if (m_ratingEdit) { connect(m_ratingEdit, SIGNAL(valueChanged()), SLOT(SetRating())); m_ratingEdit->SetMaxLength(128); } if (m_directorEdit) { connect(m_directorEdit, SIGNAL(valueChanged()), SLOT(SetDirector())); m_directorEdit->SetMaxLength(128); } if (m_inetrefEdit) connect(m_inetrefEdit, SIGNAL(valueChanged()), SLOT(SetInetRef())); if (m_homepageEdit) { connect(m_homepageEdit, SIGNAL(valueChanged()), SLOT(SetHomepage())); m_homepageEdit->SetMaxLength(0); } if (m_plotEdit) { connect(m_plotEdit, SIGNAL(valueChanged()), SLOT(SetPlot())); m_plotEdit->SetMaxLength(0); } connect(m_seasonSpin, SIGNAL(LosingFocus()), SLOT(SetSeason())); connect(m_episodeSpin, SIGNAL(LosingFocus()), SLOT(SetEpisode())); if (m_yearSpin) connect(m_yearSpin, SIGNAL(LosingFocus()), SLOT(SetYear())); if (m_userRatingSpin) connect(m_userRatingSpin, SIGNAL(LosingFocus()), SLOT(SetUserRating())); if (m_lengthSpin) connect(m_lengthSpin, SIGNAL(LosingFocus()), SLOT(SetLength())); connect(m_doneButton, SIGNAL(Clicked()), SLOT(SaveAndExit())); // Find Artwork locally if (m_coverartButton) connect(m_coverartButton, SIGNAL(Clicked()), SLOT(FindCoverArt())); if (m_bannerButton) connect(m_bannerButton, SIGNAL(Clicked()), SLOT(FindBanner())); if (m_fanartButton) connect(m_fanartButton, SIGNAL(Clicked()), SLOT(FindFanart())); if (m_screenshotButton) connect(m_screenshotButton, SIGNAL(Clicked()), SLOT(FindScreenshot())); // Find Artwork on the Internet if (m_netCoverartButton) connect(m_netCoverartButton, SIGNAL(Clicked()), SLOT(FindNetCoverArt())); if (m_netBannerButton) connect(m_netBannerButton, SIGNAL(Clicked()), SLOT(FindNetBanner())); if (m_netFanartButton) connect(m_netFanartButton, SIGNAL(Clicked()), SLOT(FindNetFanart())); if (m_netScreenshotButton) connect(m_netScreenshotButton, SIGNAL(Clicked()), SLOT(FindNetScreenshot())); if (m_trailerButton) connect(m_trailerButton, SIGNAL(Clicked()), SLOT(FindTrailer())); connect(m_browseCheck, SIGNAL(valueChanged()), SLOT(ToggleBrowse())); connect(m_watchedCheck, SIGNAL(valueChanged()), SLOT(ToggleWatched())); connect(m_childList, SIGNAL(itemSelected(MythUIButtonListItem*)), SLOT(SetChild(MythUIButtonListItem*))); connect(m_levelList, SIGNAL(itemSelected(MythUIButtonListItem*)), SLOT(SetLevel(MythUIButtonListItem*))); connect(m_categoryList, SIGNAL(itemSelected(MythUIButtonListItem*)), SLOT(SetCategory(MythUIButtonListItem*))); connect(m_categoryList, SIGNAL(itemClicked(MythUIButtonListItem*)), SLOT(NewCategoryPopup())); return true; }
/* * RunCommandLine - run a command line command */ vi_rc RunCommandLine( const char *cmdl ) { int i, x, y, x2, y2; bool n1f, n2f; int tkn, flag; bool test1; linenum n1, n2; char st[FILENAME_MAX]; info *cinfo; long val; jmp_buf jmpaddr; vi_rc rc; const char *data; /* * parse command string */ tkn = TOK_INVALID; rc = ParseCommandLine( cmdl, &n1, &n1f, &n2, &n2f, &tkn, &data ); if( rc != ERR_NO_ERR ) { return( rc ); } if( !n2f ) { if( !n1f ) { n1 = n2 = CurrentPos.line; } else { n2 = n1; } } /* * process tokens */ rc = ERR_INVALID_COMMAND; test1 = n1f || n2f; switch( tkn ) { case PCL_T_ABOUT: rc = DoAboutBox(); break; case PCL_T_PUSH: rc = PushFileStackAndMsg(); break; case PCL_T_POP: rc = PopFileStack(); break; case PCL_T_EXECUTE: data = SkipLeadingSpaces( data ); if( *data != '\0' ) { key_map scr; rc = AddKeyMap( &scr, data ); if( rc != ERR_NO_ERR ) { break; } rc = RunKeyMap( &scr, 1L ); MemFree( scr.data ); } break; case PCL_T_DELETEMENU: rc = DoMenuDelete( data ); break; case PCL_T_DELETEMENUITEM: rc = DoItemDelete( data ); break; case PCL_T_ADDMENUITEM: rc = AddMenuItem( data ); break; case PCL_T_MAXIMIZE: rc = MaximizeCurrentWindow(); break; case PCL_T_MINIMIZE: rc = MinimizeCurrentWindow(); break; case PCL_T_EXITFILESONLY: if( !ExitWithPrompt( false, false ) ) { rc = ERR_EXIT_ABORTED; } else { rc = ERR_NO_ERR; } break; case PCL_T_EXITALL: if( !ExitWithPrompt( true, false ) ) { rc = ERR_EXIT_ABORTED; } else { rc = ERR_NO_ERR; } break; case PCL_T_QUITALL: ExitWithVerify(); rc = ERR_NO_ERR; break; case PCL_T_KEYADD: data = SkipLeadingSpaces( data ); KeyAddString( data ); rc = ERR_NO_ERR; break; case PCL_T_UNALIAS: rc = UnAlias( data ); break; case PCL_T_UNABBREV: rc = UnAbbrev( data ); break; case PCL_T_UNMAP: case PCL_T_UNMAP_DMT: flag = MAPFLAG_MESSAGE + MAPFLAG_UNMAP; if( tkn == PCL_T_UNMAP_DMT ) { flag |= MAPFLAG_DAMMIT; } rc = MapKey( flag, data ); break; case PCL_T_EVAL: data = Expand( dataBuff, data, NULL ); i = setjmp( jmpaddr ); if( i != 0 ) { rc = (vi_rc)i; } else { StartExprParse( data, jmpaddr ); val = GetConstExpr(); ltoa( val, st, EditVars.Radix ); Message1( "%s", st ); rc = ERR_NO_ERR; } break; case PCL_T_COMPILE: case PCL_T_SOURCE: case PCL_T_LOAD: { char *tstr; srcline sline; data = GetNextWord1( data, st ); if( *st == '\0' ) { rc = ERR_NO_FILE_SPECIFIED; break; } if( tkn == PCL_T_COMPILE ) { EditFlags.CompileScript = true; if( st[0] == '-' ) { if( st[1] == 'a' || st[1] == 'A' ) { EditFlags.CompileAssignments = true; if( st[1] == 'A' ) { EditFlags.CompileAssignmentsDammit = true; } data = GetNextWord1( data, st); if( *st == '\0' ) { rc = ERR_NO_FILE_SPECIFIED; break; } } } } if( tkn == PCL_T_LOAD ) { EditFlags.LoadResidentScript = true; } sline = 0; rc = Source( st, data, &sline ); EditFlags.LoadResidentScript = false; EditFlags.CompileScript = false; EditFlags.CompileAssignments = false; EditFlags.CompileAssignmentsDammit = false; if( EditFlags.SourceScriptActive ) { LastError = rc; } if( rc > ERR_NO_ERR ) { Error( "%s on line %u of \"%s\"", GetErrorMsg( rc ), sline, st ); } else { if( rc != DO_NOT_CLEAR_MESSAGE_WINDOW ) { if( tkn != PCL_T_SOURCE ) { if( tkn == PCL_T_LOAD ) { tstr = strLoad; } else { tstr = strCompile; } Message1( "Script \"%s\" %s, %u lines generated, %d errors", st, tstr, sline, SourceErrCount ); rc = DO_NOT_CLEAR_MESSAGE_WINDOW; } } } break; } case PCL_T_GENCONFIG: #ifndef __WIN__ data = GetNextWord1( data,st ); if( *st != '\0' ) { rc = GenerateConfiguration( st, true ); } else { rc = GenerateConfiguration( NULL, true ); } #else { bool temp = EditFlags.SaveConfig; EditFlags.SaveConfig = true; WriteProfile(); EditFlags.SaveConfig = temp; rc = ERR_NO_ERR; } #endif break; case PCL_T_COMPRESS: rc = CompressWhiteSpace(); break; case PCL_T_EXPAND: rc = ExpandWhiteSpace(); break; case PCL_T_SHOVE: rc = Shift( n1, n2, '>', true ); break; case PCL_T_SUCK: rc = Shift( n1, n2, '<', true ); break; case PCL_T_FILES: if( EditFlags.LineDisplay ) { rc = DisplayFileStatus(); } else { rc = EditFileFromList(); } break; case PCL_T_NEXT: rc = RotateFileForward(); break; case PCL_T_PREV: rc = RotateFileBackwards(); break; case PCL_T_HELP: rc = DoHelp( data ); break; case PCL_T_VIEW: case PCL_T_VIEW_DMT: EditFlags.ViewOnly = true; case PCL_T_EDIT: case PCL_T_EDIT_DMT: rc = EditFile( data, ( tkn == PCL_T_VIEW_DMT || tkn == PCL_T_EDIT_DMT ) ); EditFlags.ViewOnly = false; break; case PCL_T_OPEN: rc = OpenWindowOnFile( data ); break; case PCL_T_HIDE: case PCL_T_HIDE_DMT: rc = HideLineRange( n1, n2, ( tkn == PCL_T_HIDE_DMT ) ); break; case PCL_T_DELETE: rc = SetSavebufNumber( data ); if( rc != ERR_NO_ERR ) { break; } if( SelRgn.selected && !EditFlags.LineBased ) { AddSelRgnToSavebufAndDelete(); rc = ERR_NO_ERR; // @ may have turned this on - it is now definitely off SelRgn.selected = false; } else { rc = DeleteLineRange( n1, n2, SAVEBUF_FLAG ); } if( rc == ERR_NO_ERR ) { DCDisplayAllLines(); LineDeleteMessage( n1, n2 ); } break; case PCL_T_SAVEANDEXIT: data = GetNextWord1( data, st ); if( *st == '\0' ) { rc = SaveAndExit( st ); } else { rc = SaveAndExit( NULL ); } break; case PCL_T_PUT: case PCL_T_PUT_DMT: rc = SetSavebufNumber( data ); if( rc != ERR_NO_ERR ) { break; } rc = SaveAndResetFilePos( n1 ); if( rc == ERR_NO_ERR ) { if( tkn == PCL_T_PUT ) { rc = InsertSavebufAfter(); } else { rc = InsertSavebufBefore(); } RestoreCurrentFilePos(); } break; case PCL_T_YANK: rc = SetSavebufNumber( data ); if( rc != ERR_NO_ERR ) { break; } if( SelRgn.selected && !EditFlags.LineBased ) { rc = YankSelectedRegion(); // @ may have turned this on - it is now definitely off SelRgn.selected = false; } else { rc = YankLineRange( n1, n2 ); } break; case PCL_T_SUBSTITUTE: rc = Substitute( n1, n2, data ); break; case PCL_T_GLOBAL: case PCL_T_GLOBAL_DMT: if( !test1 ) { n1 = 1; rc = CFindLastLine( &n2 ); if( rc != ERR_NO_ERR ) { break; } } rc = Global( n1,n2, data, ( tkn == PCL_T_GLOBAL_DMT ) ); break; case PCL_T_WRITEQUIT: if( CurrentFile == NULL ) { rc = NextFile(); } else { CurrentFile->modified = true; data = GetNextWord1( data, st ); if( *st != '\0' ) { rc = SaveAndExit( st ); } else { rc = SaveAndExit( NULL ); } } break; case PCL_T_WRITE: case PCL_T_WRITE_DMT: data = GetNextWord1( data, st ); if( test1 ) { if( *st == '\0' ) { rc = ERR_NO_FILE_SPECIFIED; } else { rc = SaveFile( st, n1, n2, ( tkn == PCL_T_WRITE_DMT ) ); } } else { if( st[0] != '\0' ) { #ifdef __WIN__ if( st[0] == '?' && st[1] == '\0' ) { rc = SaveFileAs(); break; } else { rc = SaveFile( st, -1, -1, ( tkn == PCL_T_WRITE_DMT ) ); } #else rc = SaveFile( st, -1, -1, ( tkn == PCL_T_WRITE_DMT ) ); #endif } else { rc = SaveFile( NULL, -1, -1, ( tkn == PCL_T_WRITE_DMT ) ); if( rc == ERR_NO_ERR ) { Modified( false ); } } } break; case PCL_T_READ: rc = ReadAFile( n1, data ); break; case PCL_T_QUIT: #ifdef __WIN__ rc = CurFileExitOptionSaveChanges(); #else rc = NextFile(); #endif break; case PCL_T_QUIT_DMT: rc = NextFileDammit(); break; case PCL_T_DATE: GetDateTimeString( st ); Message1( st ); rc = DO_NOT_CLEAR_MESSAGE_WINDOW; break; case PCL_T_CD: data = GetNextWord1( data, st ); if( *st != '\0' ) { rc = SetCWD( st ); } else { rc = ERR_NO_ERR; } if( rc == ERR_NO_ERR ) { Message1( "Current directory is %s",CurrentDirectory ); } break; case PCL_T_SHELL: EVIL_SHELL: { #if defined( __NT__ ) && !defined( __WIN__ ) ExecCmd( NULL, NULL, NULL ); #else char foo[FILENAME_MAX]; strcpy( foo, Comspec ); ExecCmd( NULL, NULL, foo ); #endif DoVersion(); rc = ERR_NO_ERR; } break; case PCL_T_SYSTEM: if( n1f && n2f ) { rc = DoGenericFilter( n1, n2, data ); } else { data = SkipLeadingSpaces( data ); if( *data == '\0' ) { goto EVIL_SHELL; } ExecCmd( NULL, NULL, data ); rc = ERR_NO_ERR; } break; case PCL_T_RESIZE: rc = ResizeCurrentWindowWithKeys(); break; case PCL_T_TILE: data = GetNextWord1( data, st ); if( st[0] != '\0' ) { if( st[0] == 'v' ) { y = 1; for( x = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) { x++; } } else if( st[0] == 'h' ) { x = 1; for( y = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) { y++; } } else { x = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } else { y = atoi( st ); } } } else { x = EditVars.MaxWindowTileX; y = EditVars.MaxWindowTileY; } if( x > 0 && y > 0) { rc = WindowTile( x, y ); } break; case PCL_T_CASCADE: rc = WindowCascade(); break; case PCL_T_MOVEWIN: rc = MoveCurrentWindowWithKeys(); break; case PCL_T_TAG: data = GetNextWord1( data, st ); if( *st != '\0' ) { rc = TagHunt( st ); } break; case PCL_T_FGREP: { bool ci; data = SkipLeadingSpaces( data ); ci = EditFlags.CaseIgnore; if( data[0] == '-' ) { if( data[1] == 'c' ) { ci = false; data += 2; data = SkipLeadingSpaces( data ); rc = GetStringWithPossibleQuote( &data, st ); } else if( data[1] == 'i' ) { ci = true; data += 2; data = SkipLeadingSpaces( data ); rc = GetStringWithPossibleQuote( &data, st ); } else if( data[1] == 'f' ) { data += 2; data = SkipLeadingSpaces( data ); #ifdef __WIN__ // call fancy grep window { fancy_find *ff; /* ff will be set to point at a static fancy find struct * in the snoop module */ char snoopbuf[FILENAME_MAX]; if( !GetSnoopStringDialog( &ff ) ) { return( ERR_NO_ERR ); } strcpy( snoopbuf, ff->path ); /* assume no string means current directory */ if( strlen( snoopbuf ) && snoopbuf[strlen( snoopbuf ) - 1] != '\\' ){ strcat( snoopbuf, "\\" ); } MySprintf( st, "%s", ff->find ); strcat( snoopbuf, ff->ext ); ci = ff->case_ignore; if( !ff->use_regexp ) { //MakeExpressionNonRegular( st ); rc = DoFGREP( snoopbuf, st, ci ); } else { rc = DoEGREP( snoopbuf, st ); } break; } #endif } } else { rc = GetStringWithPossibleQuote( &data, st ); } if( rc != ERR_NO_STRING ) { rc = DoFGREP( data, st, ci ); } } break; case PCL_T_EGREP: rc = GetStringWithPossibleQuote( &data, st ); if( rc != ERR_NO_STRING ) { rc = DoEGREP( data, st ); } break; case PCL_T_SIZE: data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } x = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } y = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } x2 = atoi( st ); data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } y2 = atoi( st ); rc = CurrentWindowResize( x, y, x2, y2 ); break; case PCL_T_ECHO: data = GetNextWord1( data, st ); if( *st == '\0' ) { break; } rc = ERR_NO_ERR; if( !stricmp( st, "on" ) ) { EditFlags.EchoOn = true; break; } else if( !stricmp( st, "off" ) ) { EditFlags.EchoOn = false; break; } x = atoi( st ); data = SkipLeadingSpaces( data ); /* * FIXME: This is not good - I will definately have to * fix this code up. But right now I have to get the * editor ready for tomorrow. Brad. */ if( data[0] == '"' || data[0] == '/' ) { GetStringWithPossibleQuote( &data, st ); if( x > 2 ) { /* this is obviously a sick individual */ Error( "Invalid Echo" ); } else if( x == 1 ) { Message1( st ); } else if( x == 2 ) { Message2( st ); } // DisplayLineInWindow( MessageWindow, x, st ); } else { if( x > 2 ) { /* this is obviously a sick individual */ Error( "Invalid Echo" ); } else if( x == 1 ) { Message1( data ); } else if( x == 2 ) { Message2( data ); } // DisplayLineInWindow( MessageWindow, x, data ); } break; #ifdef VI_RCS case PCL_T_CHECKOUT: rc = ERR_NO_ERR; #ifdef __WINDOWS__ if( isOS2() ) break; // OS/2 shell returns before checkout finishes #endif if( CurrentFile != NULL ) { rc = ViRCSCheckout( rc ); } break; case PCL_T_CHECKIN: if( CurrentFile != NULL ) { rc = ViRCSCheckin( rc ); } break; #endif default: if( tkn >= 1000 ) { rc = ProcessEx( n1, n2, n2f, tkn - 1000, data ); break; } rc = TryCompileableToken( tkn, data, true ); if( rc != NOT_COMPILEABLE_TOKEN ) { break; } rc = ProcessWindow( tkn, data ); if( rc >= ERR_NO_ERR ) { break; } case TOK_INVALID: if( n1f && !n2f ) { if( !n1 ) { n1 = 1; } MemorizeCurrentContext(); rc = GoToLineNoRelCurs( n1 ); if( rc == ERR_NO_ERR ) { GoToColumnOnCurrentLine( 1 ); if( EditFlags.LineDisplay ) { MyPrintf( "%s\n", CurrentLine->data ); } } return( rc ); } rc = ERR_INVALID_COMMAND; break; } if( rc == ERR_NO_ERR ) { rc = DO_NOT_CLEAR_MESSAGE_WINDOW; } return( rc ); } /* RunCommandLine */
/* * EditFile - read a file into text */ vi_rc EditFile( const char *name, bool dammit ) { char *fn, **list, *currfn; int i, cnt, ocnt; int j, len; window_id wid = NO_WINDOW; char cdir[FILENAME_MAX]; info *ci, *il; bool usedir = false; char mask[FILENAME_MAX]; bool reset_dir; int index; #ifdef __WIN__ char *altname = NULL; #endif vi_rc rc; fn = MemAlloc( FILENAME_MAX ); /* * get file name */ strcpy( cdir, CurrentDirectory ); reset_dir = false; name = SkipLeadingSpaces( name ); if( name[0] == '$' ) { ++name; usedir = true; } fn[0] = '\0'; // if( NextWord1FN( name, fn ) <= 0 ) if( GetStringWithPossibleQuote2( &name, fn, false ) != ERR_NO_ERR ) { usedir = true; mask[0] = '*'; mask[1] = '\0'; } if( usedir ) { if( EditFlags.ExMode ) { MemFree( fn ); return( ERR_INVALID_IN_EX_MODE ); } len = strlen( fn ); if( len > 0 ) { strcpy( mask, fn ); cnt = 0; for( i = len; i-- > 0; ) { if( fn[i] == FILE_SEP ) { for( j = i + 1; j <= len; j++ ) { mask[j - (i + 1)] = fn[j]; } cnt = i; break; } } fn[cnt] = '\0'; } if( fn[0] != '\0' ) { rc = SelectFileOpen( fn, &fn, mask, true ); } else { #ifdef __WIN__ if( name[0] == '\0' ) { altname = MemAlloc( 1000 ); rc = SelectFileOpen( CurrentDirectory, &altname, mask, true ); name = GetNextFileName( altname, fn ); // if multiple, kill path if( isMultipleFiles( name ) ) { name = GetNextFileName( name, fn ); // get 1st name } } else { rc = SelectFileOpen( CurrentDirectory, &fn, mask, true ); } #else rc = SelectFileOpen( CurrentDirectory, &fn, mask, true ); #endif } if( rc != ERR_NO_ERR || fn[0] == '\0' ) { MemFree( fn ); SetCWD( cdir ); return( rc ); } } /* * loop through all files */ rc = ERR_NO_ERR; EditFlags.WatchForBreak = true; #ifdef __WIN__ ToggleHourglass( true ); #endif do { if( IsDirectory( fn ) ) { if( EditFlags.ExMode ) { rc = ERR_INVALID_IN_EX_MODE; reset_dir = true; break; } rc = SelectFileOpen( fn, &fn, "*", false ); if( rc != ERR_NO_ERR ) { reset_dir = true; break; } if( fn[0] == '\0' ) { reset_dir = true; rc = ERR_NO_ERR; break; } } currfn = fn; ocnt = cnt = ExpandFileNames( currfn, &list ); if( !cnt ) { cnt = 1; } else { currfn = list[0]; } /* * loop through all expanded files */ index = 1; while( cnt > 0 ) { cnt--; /* * quit current file if ! specified, else just save current state */ if( dammit ) { ci = InfoHead; if( CurrentInfo == ci ) { ci = ci->next; } RemoveFromAutoSaveList(); #ifdef __WIN__ CloseAChildWindow( current_window_id ); #else CloseAWindow( current_window_id ); #endif FreeUndoStacks(); FreeMarkList(); FreeEntireFile( CurrentFile ); MemFree( DeleteLLItem( (ss **)&InfoHead, (ss **)&InfoTail, (ss *)CurrentInfo ) ); CurrentInfo = NULL; current_window_id = NO_WINDOW; } else { ci = CurrentInfo; SaveCurrentInfo(); wid = current_window_id; } /* * see if new file is already being edited */ SaveCurrentInfo(); for( il = InfoHead; il != NULL; il = il->next ) { if( SameFile( il->CurrentFile->name, currfn ) ) { break; } if( strcmp( CurrentDirectory, il->CurrentFile->home ) ) { /* directory has changed -- check with full path * note that this will fail if an absolute path * was specified thus we do the regular check first */ char path[FILENAME_MAX]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; size_t path_len; _splitpath( il->CurrentFile->name, drive, dir, fname, ext ); if( drive[0] == '\0' ) { _splitpath( il->CurrentFile->home, drive, NULL, NULL, NULL ); } strcpy( path, il->CurrentFile->home ); path_len = strlen( path ); if( path_len-- > 0 ) { #ifdef __UNIX__ if( path[path_len] != FILE_SEP ) { #else if( path[path_len] != DRV_SEP && path[path_len] != FILE_SEP ) { #endif strcat( path, FILE_SEP_STR ); } } if( dir[0] == '\0' ) { _splitpath( path, NULL, dir, NULL, NULL ); } else if( dir[0] != FILE_SEP ) { char dir2[_MAX_DIR]; _splitpath( path, NULL, dir2, NULL, NULL ); strcat( dir2, dir ); strcpy( dir, dir2 ); } _makepath( path, drive, dir, fname, ext ); if( SameFile( path, currfn ) ) { break; } } } if( il != NULL ) { BringUpFile( il, true ); } else { /* * file not edited, go get it */ rc = NewFile( currfn, false ); if( rc != ERR_NO_ERR && rc != NEW_FILE ) { RestoreInfo( ci ); DCDisplayAllLines(); break; } if( !dammit ) { InactiveWindow( wid ); } if( EditFlags.BreakPressed ) { break; } } if( cnt > 0 ) { currfn = list[index]; index++; } } if( ocnt > 0 ) { MemFreeList( ocnt, list ); } if( EditFlags.BreakPressed ) { ClearBreak(); break; } name = GetNextFileName( name, fn ); } while( *fn != '\0' ); #ifdef __WIN__ if( altname != NULL ) { MemFree( altname ); } #endif MemFree( fn ); #ifdef __WIN__ ToggleHourglass( false ); #endif EditFlags.WatchForBreak = false; if( reset_dir ) { SetCWD( cdir ); } return( rc ); } /* EditFile */ #ifndef __WIN__ static const char *fileOpts[] = { (const char *)"<F1> Go To", (const char *)"<F2> Quit", (const char *)"<F3> Save & Quit" }; static const vi_key fileopts_evlist[] = { VI_KEY( F1 ), VI_KEY( F2 ), VI_KEY( F3 ), VI_KEY( DUMMY ) }; /* * EditFileFromList - edit from file in current active list */ vi_rc EditFileFromList( void ) { int i, tmp, j, n = 0, fcnt; window_id wid; bool repeat = true; info *cinfo; char **list, modchar; bool show_lineno; window_info wi; selectitem si; vi_rc rc; /* * set up options for file list */ memcpy( &wi, &extraw_info, sizeof( window_info ) ); wi.area.x1 = 2; wi.area.x2 = 19; rc = DisplayExtraInfo( &wi, &wid, fileOpts, sizeof( fileOpts ) / sizeof( fileOpts[0] ) ); if( rc != ERR_NO_ERR ) { return( rc ); } while( repeat > 0 ) { /* * set up for this pass */ repeat = false; MoveWindowToFrontDammit( wid, false ); SaveCurrentInfo(); /* * allocate a buffer for strings, add strings */ list = (char **) MemAlloc( GimmeFileCount() * sizeof( char * ) ); for( j = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next, ++j ) { list[j] = MemAlloc( strlen( cinfo->CurrentFile->name ) + 3 ); if( cinfo->CurrentFile->modified ) { modchar = '*'; } else { modchar = ' '; } MySprintf( list[j], "%c %s", modchar, cinfo->CurrentFile->name ); } fcnt = j; tmp = filelistw_info.area.y2; i = filelistw_info.area.y2 - filelistw_info.area.y1 + 1; if( filelistw_info.has_border ) { i -= 2; } if( j < i ) { filelistw_info.area.y2 -= ( i - j ); } show_lineno = true; /* * get file */ if( n + 1 > j ) { n = j - 1; } memset( &si, 0, sizeof( si ) ); si.wi = &filelistw_info; si.title = "Current Files"; si.list = list; si.maxlist = j; si.num = n; si.retevents = fileopts_evlist; si.event = VI_KEY( DUMMY ); si.show_lineno = show_lineno; si.cln = n + 1; si.eiw = wid; rc = SelectItem( &si ); n = si.num; if( rc == ERR_NO_ERR ) { if( n >= 0 ) { cinfo = InfoHead; for( j = 0; j < n; ++j ) { cinfo = cinfo->next; } BringUpFile( cinfo, true ); switch( si.event ) { case VI_KEY( DUMMY ): case VI_KEY( F1 ): break; case VI_KEY( F2 ): rc = NextFile(); if( rc <= ERR_NO_ERR ) { repeat = true; } break; case VI_KEY( F3 ): rc = SaveAndExit( NULL ); if( rc <= ERR_NO_ERR ) { repeat = true; } break; } } } filelistw_info.area.y2 = tmp; MemFreeList( fcnt, list ); } /* * get rid of option stuff */ CloseAWindow( wid ); return( rc ); } /* EditFileFromList */