// // Copyright 2007 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // // p4wEditLocalPane: // Edit the file text of the client file on local workspace #include <p4wp4.h> #include "p4wStrBuf.h" #include "p4wHtml.h" #include "p4wPane.h" #include "p4wEditLocalPane.h" p4wEditLocalPane::p4wEditLocalPane( p4wView & ParentView, p4wRequest & Request ) : p4wPane( ParentView, Request ), fSeenData(0), fMsg(NULL) { } p4wEditLocalPane::~p4wEditLocalPane() { } // ------------------------------------- // Render functions. // void p4wEditLocalPane::Begin() { // // Begin the pane. p4wHtml htm; htm.comment( "BEGIN EDIT LOCAL PANE" ); fRequest << htm; } void p4wEditLocalPane::Render( StrDict * varList ) { Error e; StrBuf buf; StrBuf md5; CharSetCvt *cvt = NULL; CharSetCvt::CharSet cs; if( varList->GetVar( "clientFile" ) == NULL ) return; StrPtr *headType = varList->GetVar( "headType" ); FileSys *f; // // If this is a utf16 filetype, we need to use // the correct type to translate it to utf8 if (headType && !strcmp(headType->Text(), "utf16")) { f = FileSys::Create( FST_UTF16 ); // // If we are in unicode mode, we need to translate // file to UTF-8 so that it is displayed correctly } else if( Unicode() ) { f = FileSys::Create( FST_UNICODE ); cs = CharSetCvt::Lookup( fRequest.GetClientApi().GetCharset().Text() ); cvt = CharSetCvt::FindCvt( cs, CharSetCvt::UTF_8 ); f->Translator( cvt ); } else { f = FileSys::Create( FST_TEXT ); } f->Set( *varList->GetVar( "clientFile" ) ); if (!fRequest.isLocalRequest() && (f->Stat() & FSF_SYMLINK) && !SEC_ALLOW_CR8CHG_SYMLINKS) { delete f; if(cvt) delete cvt; fRequest << "A Symlink may not be edited by a remote browser."; return; } f->Digest(&md5, &e); if(!e.Test()) f->Open( FOM_READ, &e ); if(!e.Test()) f->ReadWhole( &buf, &e ); if(!e.Test()) f->Close( &e ); delete f; if(cvt) delete cvt; if( e.Test() ) return; if( !fSeenData ) { fSeenData = 1; p4wHtml htm; StrBuf clearIcon; htm.beginTable( "0", "100%", "0", "0", "#FFFFFF" ); htm.beginTRow(); htm.beginCol(); htm.icon( clearIcon.Text(), "15", "0", "", 1 ); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol(0, 0, 0, 0, 0, "10"); htm.icon( clearIcon.Text(), "1", "11", "", 1 ); htm.endCol(); htm.beginCol(0, 0, 0, 0, 0, "100%"); // htm.beginTable( "0", "100%", "8", "1", "#7F7F7F" ); // htm.beginTRow( NULL, NULL, "#FFFFFF" ); // htm.beginCol(); // htm << "<center>"; htm.beginTable( "0", NULL, "2", "0", "#FFFFFF" ); htm.beginTRow(); htm.beginCol(); // htm << "<center>"; if (fMsg) htm << fMsg; if (fRequest.GetCmd() == AC_EDITTEXTLOCALPROCESSOR) { char time_buffer[255 + 1]; time_buffer[0] = '\0'; time_t iTime = time( NULL ); StrBuf time_format; time_format.Append( "%a, %d %b %Y %H:%M:%S %Z" ); strftime( time_buffer, sizeof( time_buffer ), time_format.Text(), localtime( &iTime ) ); htm << "File saved at " << time_buffer; StrPtr *change = varList->GetVar( "change" ); fRequest << htm; htm.Clear(); if (change) { p4wHtml htm(1); htm << " - Click to submit changelist "; StrBuf newBase; fRequest.UseNewBase( newBase, NULL, "path", NULL ); p4wURL urlMaker; StrBuf changeURL; StrBufDict cmdArgs; cmdArgs.SetVar( "arg", change ); urlMaker.ConstructURL( changeURL, newBase.Text(), AC_CHANGEPENDINGEDIT, strcmp(change->Text(), "default") ? &cmdArgs : NULL, fRequest.GetUnicode() ); htm.beginLink( changeURL.Text() ); if (strcmp(change->Text(), "default")) htm << p4wStrBuf().EscapeHTML( *change, Unicode() ).Text(); else htm << "Default"; htm.endLink(); fRequest << htm; } htm << crlf; } fRequest << htm; } if( PageLimitExceeded() ) return; p4wHtml htm; StrBuf newBase; StrBuf actionURL; StrBuf clientFile; clientFile << varList->GetVar( "clientFile" ); if (fRequest.GetViewMode() == VM_WORKSPACE) fRequest.UseNewBase( newBase, NULL, "path", clientFile.Text() ); else fRequest.UseNewBase( newBase, NULL, "path", varList->GetVar( "depotFile" )->Text() ); fRequest.ConstructSafeURL( actionURL, newBase.Text(), AC_EDITTEXTLOCALPROCESSOR, NULL ); htm.beginForm( actionURL.Text() ); htm.hiddenField( "Key", md5.Text() ); htm.beginTextbox( "Edit", 25, 90 ); fRequest << htm; p4wHtml htmnocrlf(1); htmnocrlf.text( p4wStrBuf().EscapeHTML( buf, Unicode() ).Text() ); fRequest << htmnocrlf; htm.Clear(); htm.endTextbox(); htm << "<p>" << crlf; htm.button( "savefile", "Save" ); htm << "</center>"; htm.endForm(); fRequest << htm; } void p4wEditLocalPane::End() { // // End the pane. p4wHtml htm; if( fSeenData ) { StrBuf clearIcon; // htm << "</center>"; htm.endCol(); htm.endTRow(); htm.endTable(); // htm << "</center>"; // htm.endCol(); // htm.endTRow(); // htm.endTable(); htm << "</center>"; htm.endCol(); htm.beginCol(); htm.icon( clearIcon.Text(), "1", "11", "", 1 ); htm.endCol(); htm.endTRow(); htm.endTable(); } else { htm.beginTRow(); htm.beginCol(); htm.text( "File not found, or file is empty." ); htm.endCol(); htm.endTRow(); } htm.comment( "END EDIT LOCAL PANE" ); fRequest << htm; }
# | 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/p4wEditLocalPane.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |