// // Copyright 2003 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // // p4wPreviewPane: // Generates a result pane containing the result of a preview command // with a form and a button to perform the previewed action #include <p4wp4.h> #include "p4wStrBuf.h" #include "p4wHtml.h" #include "p4wPane.h" #include "p4wPreviewPane.h" #include "p4wMenuPane.h" p4wPreviewPane::p4wPreviewPane( p4wView & ParentView, p4wRequest & Request, const char *title ) : p4wRunPane( ParentView, Request ), fSeenBegin(0) { fTitle.Set( title ); fFirstErrorOnly = 0; } p4wPreviewPane::~p4wPreviewPane() { } void p4wPreviewPane::Begin() { p4wHtml htm; p4wURL urlMaker; StrBuf title; // // Only process ::Begin() at the beginning of the function list. if( fSeenBegin ) return; // // Construct the title doTitle( title ); // // Begin the pane. fSeenBegin = 1; // // Draw the contents header htm.comment( "BEGIN PREVIEW PANE" ); if (fRequest.fSave4Later) { StrBuf clearIcon; urlMaker.ConstructURL( clearIcon, "/clearpixelIcon", AC_ICON, NULL ); htm.beginTRow(); htm.beginCol(); htm.icon( clearIcon.Text(), "10", "1", "", 1 ); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol(); htm.beginTable(); htm.beginCol(); htm.icon( clearIcon.Text(), "1", "10", "", 1 ); htm.endCol(); } else { // // Used to generate a line underneath the title StrBuf grayIcon; urlMaker.ConstructURL( grayIcon, "/grayPixelIcon", AC_ICON, NULL ); htm.beginTRow(); htm.beginCol(); htm.beginSpan( "title" ); htm << title; htm.endSpan(); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol( "top" ); htm.icon( grayIcon.Text(), "1", "100%", "", 1, "0", "0" ); htm.endCol(); htm.endTRow(); fRequest << htm; htm.Clear(); // // Generate a linkified path for some commands doDirHeader(); htm.beginTRow(); } htm.beginCol(); const StrPtr *mu = fRequest.GetDynArg("mu"); if (mu || fRequest.GetLastReturnType() == AC_BROWSEFILE) { int show = mu ? atoi(mu->Text()) : -1; htm.SetRequest(&fRequest); htm.RenderFileMenu(show ? show : -1); htm << "<script language=javascript>" << crlf; htm << "setmushow("; htm << show; htm << ");" << crlf; htm << "</script>" << crlf; } else { const StrPtr *lac = fRequest.GetDynArg( "lac" ); if (lac && lac->Atoi() == AC_SYNCCHANGE) { fRequest << htm; htm.Clear(); p4wMenuPane::renderSubChgMenu( &fRequest, NULL ); } } htm.beginDList(); htm.dListTag(); htm.text( "Command:", "b" ); htm.dListVal(); htm.text( p4wStrBuf().EscapeHTML( fTitle, Unicode() ).Text() ); htm.dListTag(); htm.text( "Result:", "b" ); fRequest << htm; } void p4wPreviewPane::RenderInfo( char *data, char level ) { p4wHtml htm; htm.dListVal(); htm.text( p4wStrBuf().EscapeHTML( StrRef(data), Unicode() ).Text() ); fRequest << htm; } void p4wPreviewPane::RenderError( char *data, int escapeHTML ) { RenderErrorList( data, escapeHTML ); } void p4wPreviewPane::End() { // // End the page p4wHtml htm; doForm(); htm.endDList(); htm.endCol(); htm.endTRow(); htm.comment( "END PREVIEW PANE" ); fRequest << htm; } // // HandleError() - Override default error handler so that we can replace // specific p4 error messages with more friendly errors. void p4wPreviewPane::HandleError( Error *e ) { // // Replace labelsync's "empty string" error with a more // specific error message. static char *const lSyncErr = "You did not specify which files to labelsync.<BR>Please go back to the form and correct your entries under the 'Files' heading."; if( fRequest.GetCmd() == AC_LABSYNCPROCESSOR && e->GetSeverity() == E_FAILED && e->GetGeneric() == EV_USAGE ) { StrBuf errMsg; e->Fmt( &errMsg ); if( strstr( errMsg.Text(), "empty string is not allowed" ) ) { if( !fSeenBegin ) Begin(); RenderError( lSyncErr, 0 ); return; } } // // Handle all other errors using the default p4 error messages DoHandleError( e, 0 ); } void p4wPreviewPane::doDirHeader() { // // Generate a linkified path for status pages underneath // the Files tab AllCommands lac = fRequest.GetLastReturnType(); StrBuf path; path.Set( fRequest.GetReturnURL( lac ).Text() ); int isFileBrowser = lac != AC_PATHBROWSER; int isDepot = fRequest.GetViewMode() != VM_WORKSPACE; p4wHtml htm; StrBuf clearIcon; p4wURL urlMaker; urlMaker.ConstructURL( clearIcon, "/clearpixelIcon", AC_ICON, NULL ); // // Integrate using branch, sync to changelist and sync to label // do not display the path. Jump through some hoops to see // if this is one of the commands to exclude. AllCommands ac = fRequest.GetCmd(); const StrPtr *lc = fRequest.GetDynArg( "lac" ); const StrPtr *bv = fRequest.GetDynArg( "bv" ); if( lc ) ac = (AllCommands) lc->Atoi(); if( bv ) ac = AC_INTEGRATEBRANCH; switch( ac ) { case AC_SYNCCMD: case AC_SYNCREV: case AC_SYNCFILE: case AC_SYNCPROCESSOR: case AC_REMOVEFRM: case AC_REMOVEFILEFRM: case AC_REVERTPROCESSOR: case AC_REVERTCMD: case AC_REVERTUNCHANGEDFILEFRM: case AC_REVERTFILE: case AC_INTEGPROCESSOR: case AC_RESOLVEPROCESSOR: case AC_RESOLVECMD: htm.beginTRow(); htm.beginCol(); htm.beginSpan( "path" ); htm << " "; fRequest << htm; htm.Clear(); (void)OutputDirectoryHeader( path.Text(), isFileBrowser, 1, isDepot ); htm.endSpan(); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol(); htm.icon( clearIcon.Text(), "10", "0", "", 1 ); htm.endCol(); htm.endTRow(); fRequest << htm; break; default: break; } } void p4wPreviewPane::doTitle( StrBuf &title ) { // // Generate a title for the page. Usually this involves // prepending "Preview", taking the first argument of the // passed in title and capitalizing it. There are some // exceptions based on command, hence this method. StrBuf cmd; const StrPtr *lac = fRequest.GetDynArg( "lac" ); const StrPtr *bv = fRequest.GetDynArg( "bv" ); int ac = 0; if( lac ) ac = (AllCommands) lac->Atoi(); // // Get the first word of the passed in title and capitalize it cmd.Set( fTitle.Text(), 1 ); StrOps::Caps( cmd ); cmd << &fTitle.Text()[1]; char *e = strchr( cmd.Text(), ' ' ); if( e ) cmd.SetEnd( e ); // // Preview commands are labeled "Preview <Operation>:. title << "Preview "; if( fRequest.GetCmd() == AC_SYNCPROCESSOR && lac ) { if( ac == AC_SYNCCHANGE ) title << "Sync to Changelist"; else if( ac == AC_SYNCLABEL ) title << "Sync Workspace to Label"; else if( ac == AC_REMOVEFRM || ac == AC_REMOVEFILEFRM ) title << "Remove from Workspace"; else title << "Sync"; } else if( fRequest.GetCmd() == AC_LABSYNCPROCESSOR ) { title << "Add/Replace"; } else if( fRequest.GetCmd() == AC_INTEGPROCESSOR && bv ) { title << "Integrate Using Branch"; } else { title << cmd; } title << ":"; } void p4wPreviewPane::doForm() { // // Generate a form with the action button and hidden // fields based on the user's previous form selections Spec spec; StrBufDict specTable; StrBuf actionURL; const StrPtr *lac = fRequest.GetDynArg( "lac" ); p4wHtml htm; // // Begin the form GetAction( actionURL ); htm.dListTag(); htm.dListVal(); htm.beginForm( actionURL.Text() ); // // Parse the form for the interesting variables // and set hidden fields using those set values. // Generate the button too. spec.Add( "Option" ); spec.Add( "Force" ); spec.Add( "Path" ); spec.Add( "Files" ); spec.Add( "dirVal" ); spec.Add( "File" )->type = SDT_LLIST; spec.Add( "fl" )->type = SDT_LLIST; spec.Add( "atVal" ); int i; StrRef fileVar( "File" ); StrRef flVar( "fl" ); StrPtr *file; StrPtr *flag; switch( fRequest.GetCmd() ) { case AC_SYNCPROCESSOR: { // // Sync options spec.Add( "isRemove" ); spec.Add( "revVal" ); spec.Add( "atChangeVal" ); spec.Add( "OptionSync" ); fRequest.ProcessForm( spec, &specTable ); if( specTable.GetVar( "Option" ) ) htm.hiddenField( "Option", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Option" ), Unicode() ).Text() ); if( specTable.GetVar( "Force" ) ) htm.hiddenField( "Force", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Force" ), Unicode() ).Text() ); if( specTable.GetVar( "Path" ) ) htm.hiddenField( "Path", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Path" ), Unicode() ).Text() ); if( specTable.GetVar( "Files" ) ) htm.hiddenField( "Files", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Files" ), Unicode() ).Text() ); if( specTable.GetVar( "dirVal" ) ) htm.hiddenField( "dirVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "dirVal" ), Unicode() ).Text() ); if( specTable.GetVar( "atVal" ) ) htm.hiddenField( "atVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "atVal" ), Unicode() ).Text() ); if( specTable.GetVar( "isRemove" ) ) htm.hiddenField( "isRemove", p4wStrBuf().EscapeHTML( *specTable.GetVar( "isRemove" ), Unicode() ).Text() ); if( specTable.GetVar( "revVal" ) ) htm.hiddenField( "revVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "revVal" ), Unicode() ).Text() ); if( specTable.GetVar( "atChangeVal" ) ) htm.hiddenField( "atChangeVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "atChangeVal" ), Unicode() ).Text() ); if( specTable.GetVar( "OptionSync" ) ) htm.hiddenField( "OptionSync", p4wStrBuf().EscapeHTML( *specTable.GetVar( "OptionSync" ), Unicode() ).Text() ); for( i = 0; file = specTable.GetVar( fileVar, i ); i++ ) htm.hiddenField( "File", p4wStrBuf().EscapeHTML( *file, Unicode() ).Text() ); htm.hiddenField( "formActions", "sync" ); if( specTable.GetVar( "isRemove" ) ) htm.button( "sync", "Remove" ); else htm.button( "sync", "Sync" ); } break; case AC_REVERTPROCESSOR: { // // Revert options spec.Add( "OptionUnch" ); spec.Add( "OptionChg" ); spec.Add( "changelistVal" ); fRequest.ProcessForm( spec, &specTable ); if( specTable.GetVar( "Option" ) ) htm.hiddenField( "Option", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Option" ), Unicode() ).Text() ); if( specTable.GetVar( "Path" ) ) htm.hiddenField( "Path", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Path" ), Unicode() ).Text() ); if( specTable.GetVar( "Files" ) ) htm.hiddenField( "Files", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Files" ), Unicode() ).Text() ); if( specTable.GetVar( "dirVal" ) ) htm.hiddenField( "dirVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "dirVal" ), Unicode() ).Text() ); if( specTable.GetVar( "OptionUnch" ) ) htm.hiddenField( "OptionUnch", p4wStrBuf().EscapeHTML( *specTable.GetVar( "OptionUnch" ), Unicode() ).Text() ); if( specTable.GetVar( "OptionChg" ) ) htm.hiddenField( "OptionChg", p4wStrBuf().EscapeHTML( *specTable.GetVar( "OptionChg" ), Unicode() ).Text() ); if( specTable.GetVar( "changelistVal" ) ) htm.hiddenField( "changelistVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "changelistVal" ), Unicode() ).Text() ); for( i = 0; file = specTable.GetVar( fileVar, i ); i++ ) htm.hiddenField( "File", p4wStrBuf().EscapeHTML( *file, Unicode() ).Text() ); htm.hiddenField( "formActions", "revert" ); htm.button( "revert", "Revert" ); } break; case AC_INTEGPROCESSOR: { // // Integrate options spec.Add( "Path1" ); spec.Add( "Path2" ); spec.Add( "Branch" ); spec.Add( "DestDir" ); spec.Add( "Use" ); spec.Add( "Dir" ); spec.Add( "In" ); spec.Add( "Rev1" ); spec.Add( "Rev2" ); spec.Add( "Pattern" ); spec.Add( "Changelist" ); spec.Add( "integType" ); fRequest.ProcessForm( spec, &specTable ); if( specTable.GetVar( "Path1" ) ) htm.hiddenField( "Path1", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Path1" ), Unicode() ).Text() ); if( specTable.GetVar( "Path2" ) ) htm.hiddenField( "Path2", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Path2" ), Unicode() ).Text() ); if( specTable.GetVar( "Branch" ) ) htm.hiddenField( "Branch", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Branch" ), Unicode() ).Text() ); if( specTable.GetVar( "DestDir" ) ) htm.hiddenField( "DestDir", p4wStrBuf().EscapeHTML( *specTable.GetVar( "DestDir" ), Unicode() ).Text() ); if( specTable.GetVar( "Use" ) ) htm.hiddenField( "Use", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Use" ), Unicode() ).Text() ); if( specTable.GetVar( "Dir" ) ) htm.hiddenField( "Dir", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Dir" ), Unicode() ).Text() ); if( specTable.GetVar( "In" ) ) htm.hiddenField( "In", p4wStrBuf().EscapeHTML( *specTable.GetVar( "In" ), Unicode() ).Text() ); if( specTable.GetVar( "Rev1" ) ) htm.hiddenField( "Rev1", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Rev1" ), Unicode() ).Text() ); if( specTable.GetVar( "Rev2" ) ) htm.hiddenField( "Rev2", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Rev2" ), Unicode() ).Text() ); if( specTable.GetVar( "Pattern" ) ) htm.hiddenField( "Pattern", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Pattern" ), Unicode() ).Text() ); if( specTable.GetVar( "Changelist" ) ) htm.hiddenField( "Changelist", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Changelist" ), Unicode() ).Text() ); if( specTable.GetVar( "integType" ) ) htm.hiddenField( "integType", p4wStrBuf().EscapeHTML( *specTable.GetVar( "integType" ), Unicode() ).Text() ); for( i = 0; flag = specTable.GetVar( flVar, i ); i++ ) htm.hiddenField( "fl", p4wStrBuf().EscapeHTML( *flag, Unicode() ).Text() ); htm.hiddenField( "formActions", "integrate" ); htm.button( "integrate", "Integrate" ); } break; case AC_RESOLVEPROCESSOR: { // // Resolve options spec.Add( "OptionRes" ); spec.Add( "OptionFrc" ); spec.Add( "OptionMark" ); fRequest.ProcessForm( spec, &specTable ); if( specTable.GetVar( "Option" ) ) htm.hiddenField( "Option", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Option" ), Unicode() ).Text() ); if( specTable.GetVar( "Path" ) ) htm.hiddenField( "Path", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Path" ), Unicode() ).Text() ); if( specTable.GetVar( "Files" ) ) htm.hiddenField( "Files", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Files" ), Unicode() ).Text() ); if( specTable.GetVar( "dirVal" ) ) htm.hiddenField( "dirVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "dirVal" ), Unicode() ).Text() ); if( specTable.GetVar( "OptionRes" ) ) htm.hiddenField( "OptionRes", p4wStrBuf().EscapeHTML( *specTable.GetVar( "OptionRes" ), Unicode() ).Text() );; if( specTable.GetVar( "OptionFrc" ) ) htm.hiddenField( "OptionFrc", p4wStrBuf().EscapeHTML( *specTable.GetVar( "OptionFrc" ), Unicode() ).Text() ); if( specTable.GetVar( "OptionMark" ) ) htm.hiddenField( "OptionMark", p4wStrBuf().EscapeHTML( *specTable.GetVar( "OptionMark" ), Unicode() ).Text() ); char *p = 0; for( i = 0; file = specTable.GetVar( fileVar, i ); i++ ) htm.hiddenField( "File", p = p4wStrBuf().EscapeHTML( *file, Unicode() ).Text() ); if ( i == 1 && p && specTable.GetVar( "headType" ) ) { htm.hiddenField( "headType", specTable.GetVar( "headType" )->Text() ); htm.hiddenField( "actionFile", p ); } htm.hiddenField( "formActions", "resolve" ); htm.button( "resolve", "Resolve" ); } break; case AC_LABSYNCPROCESSOR: { spec.Add( "OptionLS" ); fRequest.ProcessForm( spec, &specTable ); if( specTable.GetVar( "Option" ) ) htm.hiddenField( "Option", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Option" ), Unicode() ).Text() ); if( specTable.GetVar( "Path" ) ) htm.hiddenField( "Path", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Path" ), Unicode() ).Text() ); if( specTable.GetVar( "Files" ) ) htm.hiddenField( "Files", p4wStrBuf().EscapeHTML( *specTable.GetVar( "Files" ), Unicode() ).Text() ); if( specTable.GetVar( "dirVal" ) ) htm.hiddenField( "dirVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "dirVal" ), Unicode() ).Text() ); if( specTable.GetVar( "atVal" ) ) htm.hiddenField( "atVal", p4wStrBuf().EscapeHTML( *specTable.GetVar( "atVal" ), Unicode() ).Text() ); if( specTable.GetVar( "OptionLS" ) ) htm.hiddenField( "OptionLS", p4wStrBuf().EscapeHTML( *specTable.GetVar( "OptionLS" ), Unicode() ).Text() ); for( i = 0; file = specTable.GetVar( fileVar, i ); i++ ) htm.hiddenField( "File", p4wStrBuf().EscapeHTML( *file, Unicode() ).Text() ); htm.hiddenField( "formActions", "labelsync" ); htm.button( "labelsync", "Add/Replace" ); } break; default: break; } // // End the form htm.endForm(); fRequest << htm; } void p4wPreviewPane::GetAction( StrBuf & actionURL ) { const StrPtr *sr = fRequest.GetDynArg( "sr" ); const StrPtr *lac = fRequest.GetDynArg( "lac" ); const StrPtr *bv = fRequest.GetDynArg( "bv" ); StrBufDict args; if( fRequest.GetCmd() == AC_SYNCPROCESSOR ) { if( sr ) args.SetVar( "sr", sr->Text() ); if( lac ) args.SetVar( "lac", lac->Text() ); ConstructAction( AC_SYNCPROCESSOR, &args, 1, actionURL ); } else if( fRequest.GetCmd() == AC_REVERTPROCESSOR ) { ConstructAction( AC_REVERTPROCESSOR, NULL, 1, actionURL ); } else if( fRequest.GetCmd() == AC_INTEGPROCESSOR ) { if( bv ) args.SetVar( "bv", bv->Text() ); ConstructAction( AC_INTEGPROCESSOR, &args, 1, actionURL ); } else if( fRequest.GetCmd() == AC_RESOLVEPROCESSOR ) { ConstructAction( AC_RESOLVEPROCESSOR, NULL, 1, actionURL ); } else if( fRequest.GetCmd() == AC_LABSYNCPROCESSOR ) { ConstructAction( AC_LABSYNCPROCESSOR, NULL, 1, actionURL ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/Panes/p4wPreviewPane.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |