CustomScpExplorer.cpp 181 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "CustomScpExplorer.h"
  6. #include <Interface.h>
  7. #include <Exceptions.h>
  8. #include <CoreMain.h>
  9. #include <FileSystems.h>
  10. #include <TextsCore.h>
  11. #include <TextsWin.h>
  12. #include <HelpWin.h>
  13. #include <VCLCommon.h>
  14. #include <Log.h>
  15. #include <Progress.h>
  16. #include <SynchronizeProgress.h>
  17. #include <OperationStatus.h>
  18. #include <DragExt.h>
  19. #include "GUITools.h"
  20. #include "NonVisual.h"
  21. #include "Glyphs.h"
  22. #include "Tools.h"
  23. #include "WinConfiguration.h"
  24. #include "TerminalManager.h"
  25. #include "EditorManager.h"
  26. #include "Setup.h"
  27. #include <Consts.hpp>
  28. //---------------------------------------------------------------------------
  29. #pragma package(smart_init)
  30. #pragma link "CustomDirView"
  31. #pragma link "CustomUnixDirView"
  32. #pragma link "IEListView"
  33. #pragma link "NortonLikeListView"
  34. #pragma link "UnixDirView"
  35. #pragma link "CustomDriveView"
  36. #pragma link "UnixDriveView"
  37. #pragma link "CustomDriveView"
  38. #pragma link "TB2Dock"
  39. #pragma link "TBXStatusBars"
  40. #pragma link "TB2Item"
  41. #pragma link "TB2Toolbar"
  42. #pragma resource "*.dfm"
  43. //---------------------------------------------------------------------------
  44. #define SAVE_SELECTION(DIRVIEW) \
  45. AnsiString FocusFile = ""; \
  46. AnsiString LastFocusedFile = ""; \
  47. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  48. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  49. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  50. #define RESTORE_SELECTION(DIRVIEW) \
  51. if (!LastFocusedFile.IsEmpty() && \
  52. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  53. { \
  54. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  55. if (ItemToSelect) \
  56. { \
  57. DIRVIEW->ItemFocused = ItemToSelect; \
  58. DIRVIEW->ItemFocused->MakeVisible(False); \
  59. } \
  60. }
  61. //---------------------------------------------------------------------------
  62. #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
  63. //---------------------------------------------------------------------------
  64. class TMutexGuard
  65. {
  66. public:
  67. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  68. int Timeout = 5000)
  69. {
  70. FMutex = NULL;
  71. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  72. if (WaitResult == WAIT_TIMEOUT)
  73. {
  74. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  75. }
  76. else
  77. {
  78. FMutex = AMutex;
  79. }
  80. }
  81. ~TMutexGuard()
  82. {
  83. if (FMutex != NULL)
  84. {
  85. ReleaseMutex(FMutex);
  86. }
  87. }
  88. private:
  89. HANDLE FMutex;
  90. };
  91. //---------------------------------------------------------------------------
  92. struct TTransferOperationParam
  93. {
  94. TTransferOperationParam();
  95. AnsiString TargetDirectory;
  96. bool Temp;
  97. bool DragDrop;
  98. };
  99. //---------------------------------------------------------------------------
  100. TTransferOperationParam::TTransferOperationParam()
  101. {
  102. Temp = false;
  103. DragDrop = false;
  104. }
  105. //---------------------------------------------------------------------------
  106. TCustomCommandParam::TCustomCommandParam()
  107. {
  108. Params = 0;
  109. }
  110. //---------------------------------------------------------------------------
  111. class TTransferPresetNoteData : public TObject
  112. {
  113. public:
  114. AnsiString Message;
  115. TStrings * More;
  116. virtual __fastcall ~TTransferPresetNoteData()
  117. {
  118. delete More;
  119. }
  120. };
  121. //---------------------------------------------------------------------------
  122. static const int OutPos = -32000;
  123. //---------------------------------------------------------------------------
  124. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  125. FFormRestored(False), TForm(Owner)
  126. {
  127. FCurrentSide = osRemote;
  128. FDocks = new TList();
  129. RestoreParams();
  130. ConfigurationChanged();
  131. RemoteDirView->Invalidate();
  132. assert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  133. NonVisualDataModule->ScpExplorer = this;
  134. Application->OnHint = ApplicationHint;
  135. Application->OnMinimize = ApplicationMinimize;
  136. Application->OnRestore = ApplicationRestore;
  137. FAutoOperation = false;
  138. FForceExecution = false;
  139. FShowStatusBarHint = false;
  140. FIgnoreNextSysCommand = false;
  141. FErrorList = NULL;
  142. FSynchronizeProgressForm = NULL;
  143. FProgressForm = NULL;
  144. FRefreshLocalDirectory = false;
  145. FRefreshRemoteDirectory = false;
  146. FDDMoveSlipped = false;
  147. FDDExtMapFile = NULL;
  148. FDDExtMutex = CreateMutex(NULL, false, DRAG_EXT_MUTEX);
  149. assert(FDDExtMutex != NULL);
  150. FDDTargetControl = NULL;
  151. FDelayedDeletionTimer = NULL;
  152. FDelayedDeletionList = new TStringList();
  153. FDDFileList = NULL;
  154. FPendingTempSpaceWarn = false;
  155. FCapturedLog = NULL;
  156. FDragDropOperation = false;
  157. memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
  158. FNoTransferPresetAutoSelect = false;
  159. FCopyParamDefault = "";
  160. FSynchronizeController = NULL;
  161. FPendingQueueActionItem = NULL;
  162. FLockLevel = 0;
  163. FTrayIcon = new TTrayIcon(0);
  164. FTrayIcon->OnClick = TrayIconClick;
  165. FEditorManager = new TEditorManager();
  166. FEditorManager->OnFileChange = ExecutedFileChanged;
  167. FEditorManager->OnFileReload = ExecutedFileReload;
  168. FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
  169. FQueueStatus = NULL;
  170. FQueueStatusSection = new TCriticalSection();
  171. FQueueStatusInvalidated = false;
  172. FQueueItemInvalidated = false;
  173. FQueueActedItem = NULL;
  174. FQueueController = new TQueueController(QueueView);
  175. FUserActionTimer = new TTimer(this);
  176. FUserActionTimer->Enabled = false;
  177. FUserActionTimer->Interval = 10;
  178. FUserActionTimer->OnTimer = UserActionTimer;
  179. FNotes = new TStringList();
  180. FNoteTimer = new TTimer(this);
  181. FNoteTimer->Enabled = false;
  182. FNoteTimer->OnTimer = NoteTimer;
  183. FOnNoteClick = NULL;
  184. FOle32Library = LoadLibrary("Ole32.dll");
  185. FDragMoveCursor = FOle32Library != NULL ?
  186. LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
  187. UseSystemSettings(this);
  188. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem*>(
  189. static_cast<TObject*>(GetComponent(fcSessionCombo)));
  190. if (SessionCombo != NULL)
  191. {
  192. SessionCombo->OnDrawItem = SessionComboDrawItem;
  193. SessionCombo->OnPopup = SessionComboPopup;
  194. SessionCombo->OnChange = SessionComboChange;
  195. SessionCombo->Hint = NonVisualDataModule->OpenedSessionsAction->Hint;
  196. }
  197. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  198. static_cast<TObject*>(GetComponent(fcTransferList)));
  199. assert(TransferList != NULL);
  200. FTransferListHoverIndex = -1;
  201. TransferList->OnChange = TransferListChange;
  202. TransferList->OnDrawItem = TransferListDrawItem;
  203. class TTBXPublicItem : public TTBXCustomItem
  204. {
  205. public:
  206. __property ItemStyle;
  207. };
  208. TTBXPublicItem * ColorMenu = reinterpret_cast<TTBXPublicItem *>(GetComponent(fcColorMenu));
  209. ColorMenu->ItemStyle = ColorMenu->ItemStyle << tbisSubmenu;
  210. RemoteDirView->Font = Screen->IconFont;
  211. reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
  212. StartUpdates();
  213. }
  214. //---------------------------------------------------------------------------
  215. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  216. {
  217. Application->UnhookMainWindow(MainWindowHook);
  218. Application->OnHint = NULL;
  219. Application->OnMinimize = NULL;
  220. Application->OnRestore = NULL;
  221. delete FTrayIcon;
  222. FTrayIcon = NULL;
  223. FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
  224. delete FEditorManager;
  225. if (FDelayedDeletionTimer)
  226. {
  227. DoDelayedDeletion(NULL);
  228. SAFE_DESTROY(FDelayedDeletionTimer);
  229. }
  230. SAFE_DESTROY(FDelayedDeletionList);
  231. assert(FSynchronizeController == NULL);
  232. CloseHandle(FDDExtMutex);
  233. FDDExtMutex = NULL;
  234. FreeLibrary(FOle32Library);
  235. FOle32Library = NULL;
  236. FDragMoveCursor = NULL;
  237. assert(!FErrorList);
  238. StoreParams();
  239. Terminal = NULL;
  240. Queue = NULL;
  241. assert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  242. NonVisualDataModule->ScpExplorer = NULL;
  243. delete FQueueController;
  244. FQueueController = NULL;
  245. delete FQueueStatusSection;
  246. FQueueStatusSection = NULL;
  247. delete FQueueStatus;
  248. FQueueStatus = NULL;
  249. delete FUserActionTimer;
  250. FUserActionTimer = NULL;
  251. delete FNoteTimer;
  252. delete FNotes;
  253. delete FNoteData;
  254. SAFE_DESTROY(FDocks);
  255. SAFE_DESTROY(FHistoryMenu[0][0]);
  256. SAFE_DESTROY(FHistoryMenu[0][1]);
  257. SAFE_DESTROY(FHistoryMenu[1][0]);
  258. SAFE_DESTROY(FHistoryMenu[1][1]);
  259. StopUpdateThread();
  260. }
  261. //---------------------------------------------------------------------------
  262. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  263. {
  264. if (FTerminal != value)
  265. {
  266. TerminalChanging();
  267. FTerminal = value;
  268. bool PrevNoTransferPresetAutoSelect = FNoTransferPresetAutoSelect;
  269. FNoTransferPresetAutoSelect = true;
  270. try
  271. {
  272. TerminalChanged();
  273. }
  274. __finally
  275. {
  276. FNoTransferPresetAutoSelect = PrevNoTransferPresetAutoSelect;
  277. }
  278. if (Terminal != NULL)
  279. {
  280. TransferPresetAutoSelect();
  281. }
  282. }
  283. }
  284. //---------------------------------------------------------------------------
  285. void __fastcall TCustomScpExplorerForm::TerminalChanging()
  286. {
  287. if (FTerminal != NULL)
  288. {
  289. UpdateTerminal(Terminal);
  290. }
  291. }
  292. //---------------------------------------------------------------------------
  293. void __fastcall TCustomScpExplorerForm::TerminalChanged()
  294. {
  295. RemoteDirView->Terminal = Terminal;
  296. Caption = Application->Title;
  297. NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked = false;
  298. if (Terminal)
  299. {
  300. if (Terminal->Active)
  301. {
  302. Terminal->RefreshDirectory();
  303. }
  304. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  305. assert(ManagedTerminal != NULL);
  306. if (WinConfiguration->PreservePanelState &&
  307. (ManagedTerminal->RemoteExplorerState != NULL))
  308. {
  309. RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
  310. }
  311. SessionColor = ManagedTerminal->Color;
  312. InitStatusBar();
  313. }
  314. TerminalListChanged(NULL);
  315. UpdateTransferList();
  316. }
  317. //---------------------------------------------------------------------------
  318. void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
  319. {
  320. if (Queue != value)
  321. {
  322. if (FQueue != NULL)
  323. {
  324. FQueue->OnListUpdate = NULL;
  325. FQueue->OnQueueItemUpdate = NULL;
  326. }
  327. FQueue = value;
  328. if (FQueue != NULL)
  329. {
  330. assert(FQueue->OnListUpdate == NULL);
  331. FQueue->OnListUpdate = QueueListUpdate;
  332. assert(FQueue->OnQueueItemUpdate == NULL);
  333. FQueue->OnQueueItemUpdate = QueueItemUpdate;
  334. }
  335. QueueChanged();
  336. }
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TCustomScpExplorerForm::QueueViewDeletion(TObject * /*Sender*/,
  340. TListItem * Item)
  341. {
  342. if (FQueueActedItem == Item)
  343. {
  344. FQueueActedItem = NULL;
  345. if ((QueueView->PopupMenu != NULL) &&
  346. (QueueView->PopupMenu->PopupComponent == QueueView))
  347. {
  348. // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
  349. ReleaseCapture();
  350. }
  351. }
  352. if (Item->Data == FPendingQueueActionItem)
  353. {
  354. FPendingQueueActionItem = NULL;
  355. }
  356. }
  357. //---------------------------------------------------------------------------
  358. void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool AppIdle)
  359. {
  360. {
  361. TGuard Guard(FQueueStatusSection);
  362. FQueueStatusInvalidated = false;
  363. if (FQueue != NULL)
  364. {
  365. FQueueStatus = FQueue->CreateStatus(FQueueStatus);
  366. }
  367. }
  368. FQueueController->UpdateQueueStatus(FQueueStatus);
  369. UpdateQueueView();
  370. bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
  371. if (NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked &&
  372. IsEmpty && (Terminal != NULL))
  373. {
  374. NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked = false;
  375. if (AppIdle)
  376. {
  377. Terminal->CloseOnCompletion(LoadStr(CLOSED_ON_QUEUE_EMPTY));
  378. }
  379. }
  380. }
  381. //---------------------------------------------------------------------------
  382. void __fastcall TCustomScpExplorerForm::UpdateQueueView()
  383. {
  384. ComponentVisible[fcQueueView] =
  385. (WinConfiguration->QueueView.Show == qvShow) ||
  386. ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
  387. (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
  388. }
  389. //---------------------------------------------------------------------------
  390. void __fastcall TCustomScpExplorerForm::QueueChanged()
  391. {
  392. if (FQueueStatus != NULL)
  393. {
  394. delete FQueueStatus;
  395. FQueueStatus = NULL;
  396. }
  397. UpdateQueueStatus(false);
  398. }
  399. //---------------------------------------------------------------------------
  400. void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
  401. {
  402. if (FQueue == Queue)
  403. {
  404. FQueueStatusInvalidated = true;
  405. }
  406. }
  407. //---------------------------------------------------------------------------
  408. void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
  409. TQueueItem * Item)
  410. {
  411. if (FQueue == Queue)
  412. {
  413. TGuard Guard(FQueueStatusSection);
  414. assert(FQueueStatus != NULL);
  415. TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
  416. if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
  417. {
  418. FRefreshLocalDirectory = (QueueItem == NULL) ||
  419. (!QueueItem->Info->ModifiedLocal.IsEmpty());
  420. FRefreshRemoteDirectory = (QueueItem == NULL) ||
  421. (!QueueItem->Info->ModifiedRemote.IsEmpty());
  422. }
  423. if (QueueItem != NULL)
  424. {
  425. QueueItem->UserData = (void*)true;
  426. FQueueItemInvalidated = true;
  427. }
  428. }
  429. }
  430. //---------------------------------------------------------------------------
  431. void __fastcall TCustomScpExplorerForm::RefreshQueueItems(bool AppIdle)
  432. {
  433. if (FQueueStatus != NULL)
  434. {
  435. bool QueueAutoPopup = GUIConfiguration->QueueAutoPopup;
  436. bool Refresh = FQueueItemInvalidated;
  437. FQueueItemInvalidated = false;
  438. int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->ActiveCount;
  439. bool Updated = false;
  440. bool Update;
  441. TQueueItemProxy * QueueItem;
  442. bool WasUserAction;
  443. for (int Index = 0; Index < Limit; Index++)
  444. {
  445. Update = false;
  446. QueueItem = FQueueStatus->Items[Index];
  447. WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
  448. if (AppIdle && QueueAutoPopup && WasUserAction &&
  449. (FPendingQueueActionItem == NULL))
  450. {
  451. FPendingQueueActionItem = QueueItem;
  452. FUserActionTimer->Enabled = true;
  453. }
  454. if ((bool)QueueItem->UserData)
  455. {
  456. QueueItem->UserData = (void*)false;
  457. QueueItem->Update();
  458. Updated = true;
  459. Update = true;
  460. }
  461. else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem))
  462. {
  463. Update = true;
  464. }
  465. if (Update)
  466. {
  467. FQueueController->RefreshQueueItem(QueueItem);
  468. }
  469. }
  470. if (Updated)
  471. {
  472. NonVisualDataModule->UpdateNonVisibleActions();
  473. }
  474. }
  475. }
  476. //---------------------------------------------------------------------------
  477. void __fastcall TCustomScpExplorerForm::UpdateTransferList()
  478. {
  479. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  480. static_cast<TComponent*>(GetComponent(fcTransferList)));
  481. TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
  482. static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
  483. TransferList->Strings->BeginUpdate();
  484. try
  485. {
  486. TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
  487. TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
  488. TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
  489. if (FTransferDropDownHint.IsEmpty())
  490. {
  491. FTransferDropDownHint = TransferDropDown->Hint;
  492. }
  493. // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
  494. AnsiString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
  495. TransferDropDown->Text = Name;
  496. TransferDropDown->Hint = FORMAT("%s\n \n%s:\n%s|%s",
  497. (FTransferDropDownHint, Name,
  498. GUIConfiguration->CurrentCopyParam.GetInfoStr("; ",
  499. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General)),
  500. FTransferDropDownHint));
  501. // update the label, otherwise when it is updated only on the first draw
  502. // of the list, it is drawn "bold" for some reason
  503. FTransferListHoverIndex = TransferList->ItemIndex;
  504. UpdateTransferLabel();
  505. }
  506. __finally
  507. {
  508. TransferList->Strings->EndUpdate();
  509. }
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
  513. {
  514. TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
  515. assert(Toolbar != NULL);
  516. NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TCustomScpExplorerForm::UpdateActions()
  520. {
  521. TForm::UpdateActions();
  522. if (ComponentVisible[fcCustomCommandsBand])
  523. {
  524. UpdateCustomCommandsToolbar();
  525. }
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  529. {
  530. assert(Configuration && RemoteDirView);
  531. RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  532. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  533. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  534. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  535. RemoteDriveView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
  536. RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  537. RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  538. RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  539. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  540. UpdateTransferList();
  541. if (Terminal != NULL)
  542. {
  543. TransferPresetAutoSelect();
  544. }
  545. UpdateQueueView();
  546. UpdateControls();
  547. // this can be called even before constuctor finishes.
  548. // can we be sure that the FEditorManager is NULL then?
  549. if (FEditorManager != NULL)
  550. {
  551. FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
  552. }
  553. if (ComponentVisible[fcCustomCommandsBand])
  554. {
  555. UpdateCustomCommandsToolbar();
  556. }
  557. }
  558. //---------------------------------------------------------------------------
  559. void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
  560. const AnsiString FileName, TEditedFileData & /*Data*/, TObject * Token,
  561. void * /*Arg*/)
  562. {
  563. if (Token != NULL)
  564. {
  565. TForm * Editor = dynamic_cast<TForm*>(Token);
  566. assert(Editor != NULL);
  567. ReconfigureEditorForm(Editor);
  568. }
  569. }
  570. //---------------------------------------------------------------------------
  571. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  572. TTransferDirection Direction, TTransferType Type, bool Temp,
  573. TStrings * FileList, AnsiString & TargetDirectory, TGUICopyParamType & CopyParam,
  574. bool Confirm, bool DragDrop)
  575. {
  576. bool Result = true;
  577. assert(Terminal && Terminal->Active);
  578. // Temp means d&d here so far, may change in future!
  579. if (Temp && (Direction == tdToLocal) && (Type == ttMove) &&
  580. !WinConfiguration->DDAllowMove)
  581. {
  582. TMessageParams Params(mpNeverAskAgainCheck);
  583. int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
  584. qaOK | qaCancel, HELP_DND_DOWNLOAD_MOVE_WARNING, &Params);
  585. if (Answer == qaNeverAskAgain)
  586. {
  587. WinConfiguration->DDAllowMove = true;
  588. }
  589. else if (Answer == qaCancel)
  590. {
  591. Result = false;
  592. }
  593. }
  594. // these parameters are known in advance
  595. int Params =
  596. FLAGMASK(Type == ttMove, cpDelete);
  597. bool ToTemp = (Temp && (Direction == tdToLocal));
  598. if (Result && Confirm)
  599. {
  600. bool DisableNewerOnly =
  601. (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
  602. ToTemp;
  603. int Options =
  604. FLAGMASK(DisableNewerOnly, coDisableNewerOnly) |
  605. FLAGMASK(ToTemp, coTemp) |
  606. FLAGMASK(DragDrop, coDoNotShowAgain);
  607. TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
  608. int CopyParamAttrs = (Direction == tdToRemote ?
  609. UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download);
  610. int OutputOptions = 0;
  611. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  612. FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, &OutputOptions);
  613. if (Result && DragDrop && FLAGSET(OutputOptions, cooDoNotShowAgain))
  614. {
  615. WinConfiguration->DDTransferConfirmation = false;
  616. }
  617. }
  618. if (Result && CopyParam.Queue && !ToTemp)
  619. {
  620. assert(Queue != NULL);
  621. // these parameter are known only after transfer dialog
  622. Params |=
  623. (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0) |
  624. (CopyParam.NewerOnly ? cpNewerOnly : 0);
  625. TQueueItem * QueueItem;
  626. if (Direction == tdToRemote)
  627. {
  628. QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
  629. &CopyParam, Params);
  630. }
  631. else
  632. {
  633. QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
  634. &CopyParam, Params);
  635. }
  636. Queue->AddItem(QueueItem);
  637. Result = false;
  638. TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
  639. if (HasDirView[Side])
  640. {
  641. DirView(Side)->SelectAll(smNone);
  642. }
  643. }
  644. return Result;
  645. }
  646. //---------------------------------------------------------------------------
  647. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  648. {
  649. }
  650. //---------------------------------------------------------------------------
  651. void __fastcall TCustomScpExplorerForm::RestoreParams()
  652. {
  653. assert(FDocks != NULL);
  654. for (int Index = 0; Index < ComponentCount; Index++)
  655. {
  656. TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
  657. if ((Dock != NULL) && (Dock->Tag == 0))
  658. {
  659. FDocks->Add(Dock);
  660. }
  661. }
  662. // IDE often looses this link
  663. RemoteDirView->HeaderImages = GlyphsModule->ArrowImages;
  664. ConfigurationChanged();
  665. QueuePanel->Height = WinConfiguration->QueueView.Height;
  666. LoadListViewStr(QueueView, WinConfiguration->QueueView.Layout);
  667. QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TCustomScpExplorerForm::StoreParams()
  671. {
  672. WinConfiguration->QueueView.Height = QueuePanel->Height;
  673. WinConfiguration->QueueView.Layout = GetListViewStr(QueueView);
  674. WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
  675. }
  676. //---------------------------------------------------------------------------
  677. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  678. {
  679. if (!FFormRestored)
  680. {
  681. FFormRestored = true;
  682. RestoreFormParams();
  683. }
  684. TForm::CreateParams(Params);
  685. }
  686. //---------------------------------------------------------------------------
  687. void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
  688. {
  689. assert(FDocks != NULL);
  690. for (int Index = 0; Index < FDocks->Count; Index++)
  691. {
  692. static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
  693. }
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(AnsiString LayoutStr)
  697. {
  698. SetDockAllowDrag(true);
  699. ::LoadToolbarsLayoutStr(this, LayoutStr);
  700. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  701. }
  702. //---------------------------------------------------------------------------
  703. AnsiString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
  704. {
  705. AnsiString Result;
  706. SetDockAllowDrag(true);
  707. Result = ::GetToolbarsLayoutStr(this);
  708. SetDockAllowDrag(!WinConfiguration->LockToolbars);
  709. return Result;
  710. }
  711. //---------------------------------------------------------------------------
  712. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  713. TFileOperationProgressType & ProgressData, TCancelStatus & /*Cancel*/)
  714. {
  715. // Download to temporary local directory
  716. if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
  717. {
  718. bool Continue = true;
  719. FPendingTempSpaceWarn = false;
  720. DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
  721. if (!Continue)
  722. {
  723. Abort();
  724. }
  725. }
  726. // operation is being executed and we still didn't show up progress form
  727. if (ProgressData.InProgress && !FProgressForm)
  728. {
  729. FProgressForm = new TProgressForm(Application);
  730. FProgressForm->DeleteToRecycleBin = (ProgressData.Side == osLocal ?
  731. WinConfiguration->DeleteToRecycleBin :
  732. Terminal->SessionData->DeleteToRecycleBin);
  733. // When main window is hidden, synchronisation form does not exist,
  734. // we suppose "/upload" or URL download mode
  735. if (!Visible && (ProgressData.Operation != foCalculateSize) &&
  736. (ProgressData.Operation != foCalculateChecksum) &&
  737. (FSynchronizeProgressForm == NULL))
  738. {
  739. FProgressForm->DisconnectWhenComplete = true;
  740. }
  741. }
  742. // operation is finished (or terminated), so we hide progress form
  743. else if (!ProgressData.InProgress && FProgressForm)
  744. {
  745. SAFE_DESTROY(FProgressForm);
  746. if ((ProgressData.Operation != foCalculateSize) &&
  747. (ProgressData.Cancel == csContinue) &&
  748. !FAutoOperation)
  749. {
  750. OperationComplete(ProgressData.StartTime);
  751. }
  752. }
  753. if (FProgressForm)
  754. {
  755. FProgressForm->SetProgressData(ProgressData);
  756. if (FProgressForm->Cancel > ProgressData.Cancel)
  757. {
  758. ProgressData.Cancel = FProgressForm->Cancel;
  759. }
  760. }
  761. }
  762. //---------------------------------------------------------------------------
  763. void __fastcall TCustomScpExplorerForm::OperationComplete(
  764. const TDateTime & StartTime)
  765. {
  766. if (GUIConfiguration->BeepOnFinish &&
  767. (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
  768. {
  769. MessageBeep(MB_OK);
  770. }
  771. }
  772. //---------------------------------------------------------------------------
  773. void __fastcall TCustomScpExplorerForm::OperationProgress(
  774. TFileOperationProgressType & ProgressData, TCancelStatus & Cancel)
  775. {
  776. FileOperationProgress(ProgressData, Cancel);
  777. }
  778. //---------------------------------------------------------------------------
  779. bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
  780. bool DragDrop)
  781. {
  782. return (!DragDrop && (DropSourceControl == NULL)) ||
  783. (DropSourceControl == RemoteDirView);
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  787. TFileOperation Operation, TOperationSide Side,
  788. bool /*Temp*/, const AnsiString FileName, bool Success,
  789. bool & DisconnectWhenComplete)
  790. {
  791. if (!FAutoOperation)
  792. {
  793. // no selection on "/upload", form servers only as event handler
  794. // (it is not displayed)
  795. if (PanelOperation(Side, FDragDropOperation) &&
  796. Visible && (Operation != foCalculateSize) &&
  797. (Operation != foGetProperties) && (Operation != foCalculateChecksum))
  798. {
  799. TCustomDirView * DView = DirView(Side);
  800. AnsiString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
  801. TListItem *Item = DView->FindFileItem(FileNameOnly);
  802. // this can happen when local drive is unplugged in the middle of the operation
  803. if (Item != NULL)
  804. {
  805. if (Success) Item->Selected = false;
  806. if (DView->ViewStyle == vsReport)
  807. {
  808. TRect DisplayRect = Item->DisplayRect(drBounds);
  809. if (DisplayRect.Bottom > DView->ClientHeight)
  810. {
  811. DView->Scroll(0, Item->Top - DView->TopItem->Top);
  812. }
  813. }
  814. Item->MakeVisible(false);
  815. }
  816. }
  817. }
  818. if (Success && (FSynchronizeController != NULL))
  819. {
  820. if (Operation == foCopy)
  821. {
  822. assert(Side == osLocal);
  823. FSynchronizeController->LogOperation(soUpload, FileName);
  824. }
  825. else if (Operation == foDelete)
  826. {
  827. assert(Side == osRemote);
  828. FSynchronizeController->LogOperation(soDelete, FileName);
  829. }
  830. }
  831. if (FProgressForm)
  832. {
  833. DisconnectWhenComplete = FProgressForm->DisconnectWhenComplete;
  834. }
  835. }
  836. //---------------------------------------------------------------------------
  837. void __fastcall TCustomScpExplorerForm::OperationFinished(
  838. TFileOperation Operation, TOperationSide Side,
  839. bool Temp, const AnsiString FileName, Boolean Success,
  840. bool & DisconnectWhenComplete)
  841. {
  842. DoOperationFinished(Operation, Side, Temp, FileName, Success,
  843. DisconnectWhenComplete);
  844. }
  845. //---------------------------------------------------------------------------
  846. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  847. {
  848. assert(GetSide(Side) == osRemote);
  849. USEDPARAM(Side);
  850. return RemoteDirView;
  851. }
  852. //---------------------------------------------------------------------------
  853. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
  854. TOperationSide Side, int FilesOnly)
  855. {
  856. return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0));
  857. }
  858. //---------------------------------------------------------------------------
  859. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
  860. TOperationSide Side, int FilesOnly)
  861. {
  862. return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0));
  863. }
  864. //---------------------------------------------------------------------------
  865. struct THistoryItemData
  866. {
  867. // TOperationSide has 1 byte, but whole structure seems padded to 4 bytes,
  868. // just like "int"
  869. TOperationSide Side;
  870. short int Index;
  871. };
  872. //---------------------------------------------------------------------------
  873. void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
  874. {
  875. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  876. THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
  877. DirView(Data.Side)->HistoryGo(Data.Index);
  878. }
  879. //---------------------------------------------------------------------------
  880. void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
  881. bool Back)
  882. {
  883. if (FHistoryMenu[Side == osLocal][Back] != NULL)
  884. {
  885. TCustomDirView * DView = DirView(Side);
  886. TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
  887. int ICount = Back ? DView->BackCount : DView->ForwardCount;
  888. if (ICount > 10)
  889. {
  890. ICount = 10;
  891. }
  892. Menu->Items->Clear();
  893. THistoryItemData Data;
  894. Data.Side = Side;
  895. for (short int i = 1; i <= ICount; i++)
  896. {
  897. TTBCustomItem * Item = new TTBXItem(Menu);
  898. Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
  899. Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
  900. Item->Hint = DView->HistoryPath[Data.Index];
  901. assert(sizeof(int) == sizeof(THistoryItemData));
  902. Item->Tag = *reinterpret_cast<int*>(&Data);
  903. Item->OnClick = HistoryItemClick;
  904. Menu->Items->Add(Item);
  905. }
  906. }
  907. }
  908. //---------------------------------------------------------------------------
  909. TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
  910. TOperationSide Side, bool Back)
  911. {
  912. if (FHistoryMenu[Side == osLocal][Back] == NULL)
  913. {
  914. // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
  915. // operator new allocates memory in Pascal code, but calls inline
  916. // contructor in C++, leading in problems, the funtion does
  917. // both in Pascal code
  918. FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
  919. UpdateHistoryMenu(Side, Back);
  920. }
  921. return FHistoryMenu[Side == osLocal][Back];
  922. }
  923. //---------------------------------------------------------------------------
  924. void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
  925. TCustomDirView *Sender)
  926. {
  927. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  928. UpdateHistoryMenu(Side, true);
  929. UpdateHistoryMenu(Side, false);
  930. }
  931. //---------------------------------------------------------------------------
  932. bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
  933. {
  934. // remote custom commands can be executed only if the server supports shell commands
  935. // or have secondary shell
  936. return (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
  937. }
  938. //---------------------------------------------------------------------------
  939. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  940. const AnsiString & Command, int Params, bool OnFocused)
  941. {
  942. int Result;
  943. TFileCustomCommand RemoteCustomCommand;
  944. TLocalCustomCommand LocalCustomCommand;
  945. TFileCustomCommand * NonInteractiveCustomCommand =
  946. FLAGCLEAR(Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
  947. TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
  948. AnsiString Cmd = InteractiveCustomCommand.Complete(Command, false);
  949. if (FLAGCLEAR(Params, ccLocal))
  950. {
  951. Result = CustomCommandRemoteAllowed();
  952. if (Result)
  953. {
  954. // custom command that does not operate with files can be executed anytime ...
  955. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  956. {
  957. // ... but do not show such command in remote file menu
  958. // (TODO, currently custom commands are in file menu only, so we cannot hide
  959. // such command, because it won't be accessible from elsewhere)
  960. Result = OnFocused ? /*-1*/ true : true;
  961. }
  962. else
  963. {
  964. Result = (FCurrentSide == osRemote) && EnableSelectedOperation[osRemote];
  965. }
  966. }
  967. }
  968. else
  969. {
  970. // custom command that does not operate with files can be executed anytime
  971. if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
  972. {
  973. Result = true;
  974. }
  975. else if (LocalCustomCommand.HasLocalFileName(Cmd))
  976. {
  977. // special case is "diff"-style command that can be executed over any side,
  978. // if we have both sides
  979. Result = (HasDirView[osLocal] && EnableSelectedOperation[osLocal]) &&
  980. EnableSelectedOperation[osRemote];
  981. }
  982. else
  983. {
  984. // other local custom commands can be executed only on remote side
  985. Result = (FCurrentSide == osRemote) && EnableSelectedOperation[osRemote];
  986. }
  987. }
  988. return Result;
  989. }
  990. //---------------------------------------------------------------------------
  991. int __fastcall TCustomScpExplorerForm::CustomCommandState(
  992. const AnsiString & Description, bool OnFocused)
  993. {
  994. AnsiString Command = WinConfiguration->CustomCommands->Values[Description];
  995. int Params = WinConfiguration->CustomCommands->Params[Description];
  996. return CustomCommandState(Command, Params, OnFocused);
  997. }
  998. //---------------------------------------------------------------------------
  999. void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
  1000. AnsiString Name, AnsiString Command, int Params)
  1001. {
  1002. if (FLAGCLEAR(Params, ccLocal))
  1003. {
  1004. if (EnsureCommandSessionFallback(fcShellAnyCommand))
  1005. {
  1006. TRemoteCustomCommand RemoteCustomCommand;
  1007. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1008. &RemoteCustomCommand, Name);
  1009. Command = InteractiveCustomCommand.Complete(Command, false);
  1010. bool Capture = FLAGSET(Params, ccShowResults) || FLAGSET(Params, ccCopyResults);
  1011. TCaptureOutputEvent OutputEvent = NULL;
  1012. assert(FCapturedLog == NULL);
  1013. if (Capture)
  1014. {
  1015. FCapturedLog = new TStringList();
  1016. OutputEvent = TerminalCaptureLog;
  1017. }
  1018. try
  1019. {
  1020. if (!RemoteCustomCommand.IsFileCommand(Command))
  1021. {
  1022. // Complete just replaces !! with !
  1023. Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
  1024. OutputEvent);
  1025. }
  1026. else
  1027. {
  1028. Terminal->CustomCommandOnFiles(Command, Params, FileList, OutputEvent);
  1029. }
  1030. if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
  1031. {
  1032. if (FLAGSET(Params, ccCopyResults))
  1033. {
  1034. CopyToClipboard(FCapturedLog);
  1035. }
  1036. if (FLAGSET(Params, ccShowResults))
  1037. {
  1038. DoConsoleDialog(Terminal, "", FCapturedLog);
  1039. }
  1040. }
  1041. }
  1042. __finally
  1043. {
  1044. SAFE_DESTROY(FCapturedLog);
  1045. }
  1046. }
  1047. }
  1048. else
  1049. {
  1050. TLocalCustomCommand LocalCustomCommand;
  1051. TWinInteractiveCustomCommand InteractiveCustomCommand(
  1052. &LocalCustomCommand, Name);
  1053. Command = InteractiveCustomCommand.Complete(Command, false);
  1054. if (!LocalCustomCommand.IsFileCommand(Command))
  1055. {
  1056. // Complete just replaces !! with !
  1057. ExecuteShellAndWait(LocalCustomCommand.Complete(Command, true));
  1058. }
  1059. else
  1060. {
  1061. TStrings * LocalFileList = NULL;
  1062. TStrings * RemoteFileList = NULL;
  1063. try
  1064. {
  1065. bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
  1066. bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
  1067. if (LocalFileCommand)
  1068. {
  1069. assert(HasDirView[osLocal]);
  1070. assert(EnableSelectedOperation[osLocal]);
  1071. LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
  1072. if (FileListCommand)
  1073. {
  1074. if (LocalFileList->Count != 1)
  1075. {
  1076. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
  1077. }
  1078. }
  1079. else
  1080. {
  1081. if ((LocalFileList->Count != 1) &&
  1082. (FileList->Count != 1) &&
  1083. (LocalFileList->Count != FileList->Count))
  1084. {
  1085. throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
  1086. }
  1087. }
  1088. }
  1089. AnsiString TempDir;
  1090. TemporarilyDownloadFiles(FileList, false, TempDir, false, false);
  1091. try
  1092. {
  1093. RemoteFileList = new TStringList();
  1094. TMakeLocalFileListParams MakeFileListParam;
  1095. MakeFileListParam.FileList = RemoteFileList;
  1096. MakeFileListParam.IncludeDirs = FLAGSET(Params, ccApplyToDirectories);
  1097. MakeFileListParam.Recursive =
  1098. FLAGSET(Params, ccRecursive) && !FileListCommand;
  1099. ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
  1100. TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
  1101. Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
  1102. assert(FProgressForm != NULL);
  1103. FProgressForm->ReadOnly = true;
  1104. try
  1105. {
  1106. if (FileListCommand)
  1107. {
  1108. AnsiString LocalFile;
  1109. // MakeFileList does not delimit filenames
  1110. AnsiString FileList = MakeFileList(RemoteFileList);
  1111. if (LocalFileCommand)
  1112. {
  1113. assert(LocalFileList->Count == 1);
  1114. LocalFile = LocalFileList->Strings[0];
  1115. }
  1116. TLocalCustomCommand CustomCommand("", LocalFile, FileList);
  1117. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1118. }
  1119. else if (LocalFileCommand)
  1120. {
  1121. if (LocalFileList->Count == 1)
  1122. {
  1123. AnsiString LocalFile = LocalFileList->Strings[0];
  1124. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1125. {
  1126. AnsiString FileName = RemoteFileList->Strings[Index];
  1127. TLocalCustomCommand CustomCommand
  1128. (FileName, LocalFile, "");
  1129. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1130. }
  1131. }
  1132. else if (RemoteFileList->Count == 1)
  1133. {
  1134. AnsiString FileName = RemoteFileList->Strings[0];
  1135. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1136. {
  1137. TLocalCustomCommand CustomCommand
  1138. (FileName, LocalFileList->Strings[Index], "");
  1139. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1140. }
  1141. }
  1142. else
  1143. {
  1144. if (LocalFileList->Count != RemoteFileList->Count)
  1145. {
  1146. throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
  1147. }
  1148. for (int Index = 0; Index < LocalFileList->Count; Index++)
  1149. {
  1150. AnsiString FileName = RemoteFileList->Strings[Index];
  1151. TLocalCustomCommand CustomCommand
  1152. (FileName, LocalFileList->Strings[Index], "");
  1153. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1154. }
  1155. }
  1156. }
  1157. else
  1158. {
  1159. for (int Index = 0; Index < RemoteFileList->Count; Index++)
  1160. {
  1161. TLocalCustomCommand CustomCommand
  1162. (RemoteFileList->Strings[Index], "", "");
  1163. ExecuteShellAndWait(CustomCommand.Complete(Command, true));
  1164. }
  1165. }
  1166. }
  1167. __finally
  1168. {
  1169. Progress.Stop();
  1170. }
  1171. }
  1172. __finally
  1173. {
  1174. RecursiveDeleteFile(ExcludeTrailingBackslash(TempDir), false);
  1175. }
  1176. }
  1177. __finally
  1178. {
  1179. delete RemoteFileList;
  1180. delete LocalFileList;
  1181. }
  1182. }
  1183. }
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
  1187. const AnsiString & AddedLine, bool /*StdError*/)
  1188. {
  1189. assert(FCapturedLog != NULL);
  1190. FCapturedLog->Add(AddedLine);
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
  1194. TOperationSide Side)
  1195. {
  1196. return (Side == osRemote) &&
  1197. ((Control == RemoteDirView) || (Control == RemoteDriveView));
  1198. }
  1199. //---------------------------------------------------------------------------
  1200. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  1201. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  1202. {
  1203. TListItem * Item = RemoteDirView->ItemFocused;
  1204. if ((RemoteDirView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  1205. RemoteDirView->AnyFileSelected(true, false))
  1206. {
  1207. TPoint ScreenPoint, ClientPoint;
  1208. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  1209. TPoint(0, 0) : MousePos;
  1210. ScreenPoint = RemoteDirView->ClientToScreen(ClientPoint);
  1211. #define DEFAULTITEM(ITEM, DEFAULT) \
  1212. { \
  1213. TTBItemOptions O; \
  1214. O = NonVisualDataModule->ITEM->Options; \
  1215. if ((DEFAULT) && Terminal->ResolvingSymlinks && \
  1216. !RemoteDirView->ItemIsDirectory(Item)) \
  1217. NonVisualDataModule->ITEM->Options = O << tboDefault; \
  1218. else \
  1219. NonVisualDataModule->ITEM->Options = O >> tboDefault; \
  1220. }
  1221. DEFAULTITEM(CurrentOpenMenuItem, WinConfiguration->DoubleClickAction == dcaOpen);
  1222. DEFAULTITEM(CurrentEditMenuItem, WinConfiguration->DoubleClickAction == dcaEdit);
  1223. DEFAULTITEM(CurrentCopyMenuItem, WinConfiguration->DoubleClickAction == dcaCopy);
  1224. #undef DEFAULTITEM
  1225. NonVisualDataModule->CurrentOpenMenuItem->Visible = WinConfiguration->ExpertMode;
  1226. NonVisualDataModule->CurrentEditMenuItem->Visible = WinConfiguration->ExpertMode;
  1227. reinterpret_cast<TPopupMenu*>(GetComponent(fcRemotePopup))->Popup(
  1228. ScreenPoint.x, ScreenPoint.y);
  1229. }
  1230. Handled = true;
  1231. }
  1232. //---------------------------------------------------------------------------
  1233. void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const AnsiString Directory)
  1234. {
  1235. }
  1236. //---------------------------------------------------------------------------
  1237. void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
  1238. {
  1239. assert(FErrorList == NULL);
  1240. if (WinConfiguration->ContinueOnError)
  1241. {
  1242. FErrorList = new TStringList();
  1243. }
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
  1247. {
  1248. if (FErrorList)
  1249. {
  1250. HandleErrorList(FErrorList);
  1251. }
  1252. }
  1253. //---------------------------------------------------------------------------
  1254. void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  1255. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  1256. {
  1257. void * BatchStorage;
  1258. BatchStart(BatchStorage);
  1259. try
  1260. {
  1261. if ((Operation == foCopy) || (Operation == foMove))
  1262. {
  1263. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  1264. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  1265. AnsiString TargetDirectory;
  1266. bool Temp = false;
  1267. bool DragDrop = false;
  1268. if (Param != NULL)
  1269. {
  1270. TTransferOperationParam& TParam =
  1271. *static_cast<TTransferOperationParam*>(Param);
  1272. TargetDirectory = TParam.TargetDirectory;
  1273. Temp = TParam.Temp;
  1274. DragDrop = TParam.DragDrop;
  1275. }
  1276. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1277. if (CopyParamDialog(Direction, Type, Temp, FileList, TargetDirectory,
  1278. CopyParam, !NoConfirmation, DragDrop))
  1279. {
  1280. assert(Terminal);
  1281. bool SelectionRestored = false;
  1282. TCustomDirView * DView = NULL;
  1283. if (HasDirView[Side])
  1284. {
  1285. DView = DirView(Side);
  1286. DView->SaveSelection();
  1287. DView->SaveSelectedNames();
  1288. }
  1289. try
  1290. {
  1291. if (Side == osLocal)
  1292. {
  1293. int Params =
  1294. FLAGMASK(Operation == foMove, cpDelete) |
  1295. FLAGMASK(CopyParam.NewerOnly, cpNewerOnly) |
  1296. FLAGMASK(Temp, cpTemporary);
  1297. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params);
  1298. if (Operation == foMove)
  1299. {
  1300. ReloadLocalDirectory();
  1301. if (DView != NULL)
  1302. {
  1303. DView->RestoreSelection();
  1304. }
  1305. SelectionRestored = true;
  1306. }
  1307. }
  1308. else
  1309. {
  1310. try
  1311. {
  1312. int Params =
  1313. (Operation == foMove ? cpDelete : 0) |
  1314. (CopyParam.NewerOnly ? cpNewerOnly : 0);
  1315. Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam,
  1316. Params);
  1317. }
  1318. __finally
  1319. {
  1320. if (Operation == foMove)
  1321. {
  1322. if (DView != NULL)
  1323. {
  1324. DView->RestoreSelection();
  1325. }
  1326. SelectionRestored = true;
  1327. }
  1328. ReloadLocalDirectory(TargetDirectory);
  1329. }
  1330. }
  1331. }
  1332. __finally
  1333. {
  1334. if (!SelectionRestored && (DView != NULL))
  1335. {
  1336. DView->DiscardSavedSelection();
  1337. }
  1338. }
  1339. }
  1340. }
  1341. else if (Operation == foRename)
  1342. {
  1343. assert(DirView(Side)->ItemFocused);
  1344. DirView(Side)->ItemFocused->EditCaption();
  1345. }
  1346. else if (Operation == foDelete)
  1347. {
  1348. assert(FileList->Count);
  1349. bool Recycle;
  1350. if (Side == osLocal)
  1351. {
  1352. Recycle = WinConfiguration->DeleteToRecycleBin;
  1353. }
  1354. else
  1355. {
  1356. Recycle = Terminal->SessionData->DeleteToRecycleBin &&
  1357. !Terminal->IsRecycledFile(FileList->Strings[0]);
  1358. }
  1359. bool Confirmed =
  1360. !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
  1361. if (!Confirmed)
  1362. {
  1363. AnsiString Query;
  1364. if (FileList->Count == 1)
  1365. {
  1366. if (Side == osLocal)
  1367. {
  1368. Query = ExtractFileName(FileList->Strings[0]);
  1369. }
  1370. else
  1371. {
  1372. Query = UnixExtractFileName(FileList->Strings[0]);
  1373. }
  1374. Query = FMTLOAD(
  1375. (Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
  1376. }
  1377. else
  1378. {
  1379. Query = FMTLOAD(
  1380. (Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
  1381. }
  1382. TMessageParams Params(mpNeverAskAgainCheck);
  1383. int Answer = MessageDialog(Query, qtConfirmation,
  1384. qaOK | qaCancel, HELP_NONE, &Params);
  1385. if (Answer == qaNeverAskAgain)
  1386. {
  1387. Confirmed = true;
  1388. if (Recycle)
  1389. {
  1390. WinConfiguration->ConfirmRecycling = false;
  1391. }
  1392. else
  1393. {
  1394. WinConfiguration->ConfirmDeleting = false;
  1395. }
  1396. }
  1397. else
  1398. {
  1399. Confirmed = (Answer == qaOK);
  1400. }
  1401. }
  1402. if (Confirmed) DeleteFiles(Side, FileList);
  1403. }
  1404. else if (Operation == foSetProperties)
  1405. {
  1406. RemoteDirView->SaveSelectedNames();
  1407. SetProperties(Side, FileList);
  1408. }
  1409. else if (Operation == foCustomCommand)
  1410. {
  1411. assert(Param);
  1412. assert(Side == osRemote);
  1413. RemoteDirView->SaveSelectedNames();
  1414. TCustomCommandParam * AParam = static_cast<TCustomCommandParam*>(Param);
  1415. CustomCommand(FileList, AParam->Name, AParam->Command, AParam->Params);
  1416. }
  1417. else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
  1418. {
  1419. assert(Side == osRemote);
  1420. RemoteTransferFiles(FileList, NoConfirmation, (Operation == foRemoteMove));
  1421. }
  1422. else
  1423. {
  1424. assert(false);
  1425. }
  1426. }
  1427. __finally
  1428. {
  1429. BatchEnd(BatchStorage);
  1430. }
  1431. }
  1432. //---------------------------------------------------------------------------
  1433. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  1434. {
  1435. if (Side == osCurrent)
  1436. {
  1437. Side = FCurrentSide;
  1438. }
  1439. return Side;
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  1443. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  1444. {
  1445. Side = GetSide(Side);
  1446. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  1447. try
  1448. {
  1449. ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  1450. }
  1451. __finally
  1452. {
  1453. delete FileList;
  1454. }
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  1458. {
  1459. try
  1460. {
  1461. if (ErrorList->Count)
  1462. {
  1463. if (MessageDialog(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)), qtError,
  1464. qaOK | qaCancel, HELP_NONE) == qaOK)
  1465. {
  1466. int Answer;
  1467. int Index = 0;
  1468. do
  1469. {
  1470. assert(Index >= 0 && Index < ErrorList->Count);
  1471. TQueryButtonAlias Aliases[2];
  1472. Aliases[0].Button = qaYes;
  1473. Aliases[0].Alias = LoadStr(PREV_BUTTON);
  1474. Aliases[1].Button = qaNo;
  1475. Aliases[1].Alias = LoadStr(NEXT_BUTTON);
  1476. TMessageParams Params;
  1477. Params.Aliases = Aliases;
  1478. Params.AliasesCount = LENOF(Aliases);
  1479. Answer = MoreMessageDialog(
  1480. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  1481. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  1482. (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
  1483. qaOK, HELP_NONE, &Params);
  1484. if (Answer == qaNo)
  1485. {
  1486. Index++;
  1487. }
  1488. if (Answer == qaYes)
  1489. {
  1490. Index--;
  1491. }
  1492. }
  1493. while (Answer != qaOK);
  1494. }
  1495. }
  1496. }
  1497. __finally
  1498. {
  1499. TStrings * List = ErrorList;
  1500. ErrorList = NULL;
  1501. for (int i = 0; i < List->Count; i++)
  1502. {
  1503. delete List->Objects[i];
  1504. }
  1505. delete List;
  1506. }
  1507. }
  1508. //---------------------------------------------------------------------------
  1509. void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
  1510. {
  1511. assert(!WinConfiguration->DisableOpenEdit);
  1512. Side = GetSide(Side);
  1513. AnsiString Name = LoadStr(NEW_FILE);
  1514. if (InputDialog(LoadStr(NEW_FILE_CAPTION), LoadStr(NEW_FILE_PROMPT), Name,
  1515. HELP_EDIT_NEW))
  1516. {
  1517. AnsiString TargetFileName;
  1518. AnsiString LocalFileName;
  1519. AnsiString TempDir;
  1520. if (Side == osRemote)
  1521. {
  1522. TempDir = WinConfiguration->TemporaryDir();
  1523. if (!ForceDirectories(TempDir))
  1524. {
  1525. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TempDir)));
  1526. }
  1527. TargetFileName = UnixExtractFileName(Name);
  1528. LocalFileName = TempDir +
  1529. GUIConfiguration->CurrentCopyParam.ChangeFileName(TargetFileName, osRemote, false);
  1530. }
  1531. else
  1532. {
  1533. if (ExtractFilePath(Name).IsEmpty())
  1534. {
  1535. LocalFileName = IncludeTrailingBackslash(DirView(Side)->PathName) + Name;
  1536. }
  1537. else
  1538. {
  1539. LocalFileName = ExpandFileName(Name);
  1540. }
  1541. TargetFileName = ExtractFileName(Name);
  1542. }
  1543. if (!FileExists(LocalFileName))
  1544. {
  1545. int File = FileCreate(LocalFileName);
  1546. if (File < 0)
  1547. {
  1548. if (!TempDir.IsEmpty())
  1549. {
  1550. RemoveDir(TempDir);
  1551. }
  1552. throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
  1553. }
  1554. else
  1555. {
  1556. FileClose(File);
  1557. }
  1558. }
  1559. TExecuteFileBy ExecuteFileBy = efDefaultEditor;
  1560. const TEditorPreferences * ExternalEditor = NULL;
  1561. TFileMasks::TParams MaskParams; // size not known
  1562. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
  1563. false, MaskParams);
  1564. CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
  1565. ExternalEditor);
  1566. }
  1567. }
  1568. //---------------------------------------------------------------------------
  1569. bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
  1570. TExecuteFileBy ExecuteFileBy, const TEditorPreferences * ExternalEditor)
  1571. {
  1572. assert((ExecuteFileBy == efExternalEditor) ==
  1573. ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
  1574. assert(ExecuteFileBy != efDefaultEditor);
  1575. return
  1576. ((ExecuteFileBy == efInternalEditor)) ||
  1577. ((ExecuteFileBy == efExternalEditor) && ExternalEditor->Data.ExternalEditorText);
  1578. }
  1579. //---------------------------------------------------------------------------
  1580. void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
  1581. TExecuteFileBy ExecuteFileBy, AnsiString FileName, AnsiString OriginalFileName,
  1582. const TEditorPreferences * ExternalEditor)
  1583. {
  1584. assert(!WinConfiguration->DisableOpenEdit);
  1585. assert((ExecuteFileBy == efExternalEditor) ==
  1586. ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
  1587. assert(ExecuteFileBy != efDefaultEditor);
  1588. Side = GetSide(Side);
  1589. TEditedFileData Data;
  1590. if (Side == osRemote)
  1591. {
  1592. Data.Terminal = Terminal;
  1593. Data.Queue = Queue;
  1594. Data.ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
  1595. Data.RemoteDirectory = RemoteDirView->PathName;
  1596. Data.SessionName = Terminal->SessionData->SessionName;
  1597. Data.OriginalFileName = OriginalFileName;
  1598. Data.Command = ""; // will be changed later for external editor
  1599. }
  1600. bool SingleEditor = WinConfiguration->Editor.SingleEditor;
  1601. TOperationStatusForm * StatusForm = NULL;
  1602. try
  1603. {
  1604. bool CloseFlag = false;
  1605. bool * PCloseFlag = NULL;
  1606. if ((Side == osRemote) && SingleEditor)
  1607. {
  1608. StatusForm = new TOperationStatusForm(Application);
  1609. StatusForm->Status = LoadStr(DOCUMENT_WAIT);
  1610. StatusForm->ShowAsModal();
  1611. PCloseFlag = &CloseFlag;
  1612. }
  1613. if (ExecuteFileBy == efInternalEditor)
  1614. {
  1615. if (Side == osRemote)
  1616. {
  1617. AnsiString Caption = RemoteDirView->Path + OriginalFileName +
  1618. " - " + Terminal->SessionData->SessionName;
  1619. TForm * Editor = ShowEditorForm(FileName, this, FEditorManager->FileChanged,
  1620. FEditorManager->FileReload, FEditorManager->FileClosed, Caption, !SingleEditor);
  1621. FEditorManager->AddFileInternal(FileName, Data, PCloseFlag, Editor);
  1622. }
  1623. else
  1624. {
  1625. ShowEditorForm(FileName, this, NULL, NULL, NULL, "", true);
  1626. }
  1627. }
  1628. else
  1629. {
  1630. HANDLE Process;
  1631. if (ExecuteFileBy == efExternalEditor)
  1632. {
  1633. AnsiString Program, Params, Dir;
  1634. Data.Command = ExternalEditor->Data.ExternalEditor;
  1635. ReformatFileNameCommand(Data.Command);
  1636. SplitCommand(Data.Command, Program, Params, Dir);
  1637. Params = ExpandFileNameCommand(Params, FileName);
  1638. if (!ExecuteShell(Program, Params, Process))
  1639. {
  1640. throw Exception(FMTLOAD(EDITOR_ERROR, (Program)));
  1641. }
  1642. }
  1643. else
  1644. {
  1645. assert(Side == osRemote);
  1646. if (!ExecuteShell(FileName, "", Process))
  1647. {
  1648. throw Exception(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
  1649. }
  1650. }
  1651. if ((Side == osLocal) ||
  1652. ((ExecuteFileBy == efExternalEditor) && !SingleEditor &&
  1653. ExternalEditor->Data.MDIExternalEditor))
  1654. {
  1655. // no need for handle
  1656. if (Process != NULL)
  1657. {
  1658. CHECK(CloseHandle(Process));
  1659. }
  1660. Process = INVALID_HANDLE_VALUE;
  1661. }
  1662. else
  1663. {
  1664. if (Process == NULL)
  1665. {
  1666. throw Exception(LoadStr(OPEN_FILE_NO_PROCESS2));
  1667. }
  1668. }
  1669. if (Side == osRemote)
  1670. {
  1671. FEditorManager->AddFileExternal(FileName, Data, PCloseFlag, Process);
  1672. }
  1673. }
  1674. if (StatusForm != NULL)
  1675. {
  1676. do
  1677. {
  1678. Application->HandleMessage();
  1679. }
  1680. while (!Application->Terminated && !CloseFlag);
  1681. }
  1682. }
  1683. __finally
  1684. {
  1685. if (StatusForm != NULL)
  1686. {
  1687. delete StatusForm;
  1688. }
  1689. }
  1690. }
  1691. //---------------------------------------------------------------------------
  1692. void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
  1693. TStrings * FileList, bool ForceText, AnsiString & TempDir, bool AllFiles,
  1694. bool GetTargetNames)
  1695. {
  1696. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1697. if (ForceText)
  1698. {
  1699. CopyParam.TransferMode = tmAscii;
  1700. }
  1701. // do not forget to add additional options to ExecutedFileChanged, FAR and SS
  1702. CopyParam.FileNameCase = ncNoChange;
  1703. CopyParam.PreserveReadOnly = false;
  1704. CopyParam.ResumeSupport = rsOff;
  1705. CopyParam.ReplaceInvalidChars = true;
  1706. CopyParam.FileMask = "";
  1707. if (AllFiles)
  1708. {
  1709. CopyParam.ExcludeFileMask = TFileMasks();
  1710. }
  1711. if (TempDir.IsEmpty())
  1712. {
  1713. TempDir = WinConfiguration->TemporaryDir();
  1714. if (!ForceDirectories(TempDir))
  1715. {
  1716. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TempDir)));
  1717. }
  1718. }
  1719. FAutoOperation = true;
  1720. Terminal->ExceptionOnFail = true;
  1721. try
  1722. {
  1723. try
  1724. {
  1725. // turn off confirmations, as for MDI editors we may possibly download
  1726. // the same file over
  1727. Terminal->CopyToLocal(FileList, TempDir, &CopyParam,
  1728. cpNoConfirmation | cpTemporary);
  1729. if (GetTargetNames)
  1730. {
  1731. for (int i = 0; i < FileList->Count; i++)
  1732. {
  1733. FileList->Strings[i] =
  1734. CopyParam.ChangeFileName(UnixExtractFileName(FileList->Strings[i]), osRemote, false);
  1735. }
  1736. }
  1737. }
  1738. catch(...)
  1739. {
  1740. try
  1741. {
  1742. RecursiveDeleteFile(ExcludeTrailingBackslash(TempDir), false);
  1743. }
  1744. catch(...)
  1745. {
  1746. }
  1747. throw;
  1748. }
  1749. }
  1750. __finally
  1751. {
  1752. FAutoOperation = false;
  1753. Terminal->ExceptionOnFail = false;
  1754. }
  1755. }
  1756. //---------------------------------------------------------------------------
  1757. void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
  1758. TExecuteFileBy & ExecuteFileBy, const TEditorPreferences *& ExternalEditor,
  1759. const AnsiString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
  1760. {
  1761. if (ExecuteFileBy == efDefaultEditor)
  1762. {
  1763. ExternalEditor = WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
  1764. if ((ExternalEditor == NULL) || (ExternalEditor->Data.Editor == edInternal))
  1765. {
  1766. ExecuteFileBy = efInternalEditor;
  1767. ExternalEditor = NULL;
  1768. }
  1769. else
  1770. {
  1771. ExecuteFileBy = efExternalEditor;
  1772. }
  1773. }
  1774. }
  1775. //---------------------------------------------------------------------------
  1776. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  1777. TExecuteFileBy ExecuteFileBy, const TEditorPreferences * ExternalEditor,
  1778. bool AllSelected, bool OnFocused)
  1779. {
  1780. assert(!WinConfiguration->DisableOpenEdit);
  1781. assert((ExecuteFileBy == efExternalEditor) ==
  1782. ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
  1783. Side = GetSide(Side);
  1784. TCustomDirView * DView = DirView(Side);
  1785. if (WinConfiguration->Editor.SingleEditor)
  1786. {
  1787. AllSelected = false;
  1788. }
  1789. TStrings * FileList = AllSelected ?
  1790. DView->CreateFileList(OnFocused, Side == osLocal) :
  1791. DView->CreateFocusedFileList(Side == osLocal);
  1792. try
  1793. {
  1794. assert(AllSelected || (FileList->Count == 1));
  1795. for (int i = 0; i < FileList->Count; i++)
  1796. {
  1797. AnsiString ListFileName = FileList->Strings[i];
  1798. AnsiString FileNameOnly = (Side == osRemote) ?
  1799. UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
  1800. TListItem * Item = DView->FindFileItem(FileNameOnly);
  1801. if (!DView->ItemIsDirectory(Item))
  1802. {
  1803. AnsiString OriginalFileName;
  1804. AnsiString FullFileName;
  1805. AnsiString FileName;
  1806. if (Side == osRemote)
  1807. {
  1808. OriginalFileName = ListFileName;
  1809. FullFileName = RemoteDirView->Path + ListFileName;
  1810. }
  1811. else
  1812. {
  1813. OriginalFileName = ExtractFileName(ListFileName);
  1814. FullFileName = ListFileName;
  1815. }
  1816. TFileMasks::TParams MaskParams;
  1817. MaskParams.Size = DView->ItemFileSize(Item);
  1818. ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
  1819. (Side == osLocal), MaskParams);
  1820. if (Side == osRemote)
  1821. {
  1822. TObject * Token = NULL;
  1823. AnsiString TempDir; // path to already edited file in MDI editor
  1824. if (!FEditorManager->CanAddFile(RemoteDirView->PathName, OriginalFileName,
  1825. Terminal->SessionData->SessionName, Token, TempDir))
  1826. {
  1827. if (Token != NULL)
  1828. {
  1829. TForm * Form = dynamic_cast<TForm *>(Token);
  1830. Form->SetFocus();
  1831. Abort();
  1832. }
  1833. else
  1834. {
  1835. throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY, (OriginalFileName)));
  1836. }
  1837. }
  1838. TStringList * FileList1 = new TStringList();
  1839. try
  1840. {
  1841. FileList1->AddObject(ListFileName, FileList->Objects[i]);
  1842. TemporarilyDownloadFiles(FileList1,
  1843. RemoteExecuteForceText(ExecuteFileBy, ExternalEditor), TempDir, true, true);
  1844. FileName = TempDir + FileList1->Strings[0];
  1845. }
  1846. __finally
  1847. {
  1848. delete FileList1;
  1849. }
  1850. }
  1851. else
  1852. {
  1853. FileName = FileList->Strings[i];
  1854. }
  1855. CustomExecuteFile(Side, ExecuteFileBy, FileName, OriginalFileName, ExternalEditor);
  1856. }
  1857. }
  1858. }
  1859. __finally
  1860. {
  1861. delete FileList;
  1862. }
  1863. }
  1864. //---------------------------------------------------------------------------
  1865. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const AnsiString FileName,
  1866. const TEditedFileData & Data, HANDLE UploadCompleteEvent)
  1867. {
  1868. if ((Data.Terminal == NULL) || !Data.Terminal->Active)
  1869. {
  1870. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED,
  1871. (ExtractFileName(FileName), Data.SessionName)));
  1872. }
  1873. TStrings * FileList = new TStringList();
  1874. try
  1875. {
  1876. FileList->Add(FileName);
  1877. // consider using the same settings (preset) as when the file was downloaded
  1878. TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  1879. if (Data.ForceText)
  1880. {
  1881. CopyParam.TransferMode = tmAscii;
  1882. }
  1883. // do not forget to add additional options to TemporarilyDownloadFiles, FAR and SS
  1884. CopyParam.FileNameCase = ncNoChange;
  1885. CopyParam.PreserveRights = false;
  1886. CopyParam.ResumeSupport = rsOff;
  1887. // so i do not need to worry if masking algorithm works in all cases
  1888. // ("" means "copy file name", no masking is actually done)
  1889. if (ExtractFileName(FileName) == Data.OriginalFileName)
  1890. {
  1891. CopyParam.FileMask = "";
  1892. }
  1893. else
  1894. {
  1895. CopyParam.FileMask = DelimitFileNameMask(Data.OriginalFileName);
  1896. }
  1897. CopyParam.ReplaceInvalidChars = true; // not used for uploads anyway
  1898. CopyParam.ExcludeFileMask = TFileMasks();
  1899. if (WinConfiguration->Editor.SingleEditor)
  1900. {
  1901. FAutoOperation = true;
  1902. Data.Terminal->ExceptionOnFail = true;
  1903. try
  1904. {
  1905. Data.Terminal->CopyToRemote(FileList, RemoteDirView->PathName,
  1906. &CopyParam, cpNoConfirmation | cpTemporary);
  1907. }
  1908. __finally
  1909. {
  1910. FAutoOperation = false;
  1911. Data.Terminal->ExceptionOnFail = false;
  1912. if (UploadCompleteEvent != INVALID_HANDLE_VALUE)
  1913. {
  1914. SetEvent(UploadCompleteEvent);
  1915. }
  1916. }
  1917. }
  1918. else
  1919. {
  1920. assert(Queue != NULL);
  1921. int Params = cpNoConfirmation | cpTemporary;
  1922. TQueueItem * QueueItem = new TUploadQueueItem(Data.Terminal, FileList,
  1923. Data.RemoteDirectory, &CopyParam, Params);
  1924. QueueItem->CompleteEvent = UploadCompleteEvent;
  1925. Data.Queue->AddItem(QueueItem);
  1926. }
  1927. }
  1928. __finally
  1929. {
  1930. delete FileList;
  1931. }
  1932. }
  1933. //---------------------------------------------------------------------------
  1934. void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
  1935. const AnsiString FileName, const TEditedFileData & Data)
  1936. {
  1937. if ((Data.Terminal == NULL) || !Data.Terminal->Active)
  1938. {
  1939. throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
  1940. (ExtractFileName(FileName), Data.SessionName)));
  1941. }
  1942. TStrings * FileList = new TStringList();
  1943. try
  1944. {
  1945. AnsiString RemoteFileName =
  1946. UnixIncludeTrailingBackslash(Data.RemoteDirectory) + Data.OriginalFileName;
  1947. TRemoteFile * File = NULL;
  1948. FTerminal->ExceptionOnFail = true;
  1949. try
  1950. {
  1951. FTerminal->ReadFile(RemoteFileName, File);
  1952. if (!File->HaveFullFileName)
  1953. {
  1954. File->FullFileName = RemoteFileName;
  1955. }
  1956. }
  1957. __finally
  1958. {
  1959. FTerminal->ExceptionOnFail = false;
  1960. }
  1961. FileList->AddObject(RemoteFileName, File);
  1962. AnsiString TempDir = ExtractFilePath(FileName);
  1963. TemporarilyDownloadFiles(FileList, Data.ForceText, TempDir, true, true);
  1964. // sanity check, the target file name should be still the same
  1965. assert(ExtractFileName(FileName) == FileList->Strings[0]);
  1966. }
  1967. __finally
  1968. {
  1969. delete FileList;
  1970. }
  1971. }
  1972. //---------------------------------------------------------------------------
  1973. void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
  1974. const TEditedFileData & Data, bool * CloseFlag, bool & KeepOpen)
  1975. {
  1976. // CloseFlag is set for single editors only.
  1977. if (CloseFlag == NULL)
  1978. {
  1979. // Command is set for external editors only (not for "shell" open).
  1980. if (!Data.Command.IsEmpty())
  1981. {
  1982. bool AnyFound = false;
  1983. bool AnyMDI = false;
  1984. bool AnyNonMDI = false;
  1985. bool AnyDetect = false;
  1986. TEditorList * EditorList = new TEditorList();
  1987. try
  1988. {
  1989. *EditorList = *WinConfiguration->EditorList;
  1990. for (int i = 0; i < EditorList->Count; i++)
  1991. {
  1992. const TEditorPreferences * Editor = EditorList->Editors[i];
  1993. if ((Editor->Data.Editor == edExternal) &&
  1994. (Editor->Data.ExternalEditor == Data.Command))
  1995. {
  1996. AnyFound = true;
  1997. if (!Editor->Data.MDIExternalEditor)
  1998. {
  1999. AnyNonMDI = true;
  2000. if (Editor->Data.DetectMDIExternalEditor)
  2001. {
  2002. AnyDetect = true;
  2003. }
  2004. }
  2005. else
  2006. {
  2007. AnyMDI = true;
  2008. }
  2009. }
  2010. }
  2011. bool EnableMDI = false;
  2012. bool DisableDetect = false;
  2013. if (AnyMDI)
  2014. {
  2015. KeepOpen = true;
  2016. if (AnyNonMDI)
  2017. {
  2018. // there is at least one instance of the editor with MDI support enabled,
  2019. // and one with disabled, enable it for all instances
  2020. EnableMDI = true;
  2021. }
  2022. }
  2023. else if (AnyFound && !AnyDetect)
  2024. {
  2025. // at least once instance found but all have MDI autodetection disabled
  2026. // => close the file (default action)
  2027. }
  2028. else
  2029. {
  2030. // no instance of the editor has MDI support enabled
  2031. TMessageParams Params;
  2032. if (AnyFound)
  2033. {
  2034. // there is at least one instance of the editor with enabled
  2035. // MDI autodetection
  2036. Params.Params |= mpNeverAskAgainCheck;
  2037. }
  2038. int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED, (Data.OriginalFileName)), qtWarning,
  2039. qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
  2040. switch (Answer)
  2041. {
  2042. case qaNeverAskAgain:
  2043. DisableDetect = true;
  2044. break;
  2045. case qaNo:
  2046. EnableMDI = true;
  2047. KeepOpen = true;
  2048. break;
  2049. }
  2050. }
  2051. if (AnyFound && (EnableMDI || DisableDetect))
  2052. {
  2053. bool Changed = false;
  2054. for (int i = 0; i < EditorList->Count; i++)
  2055. {
  2056. const TEditorPreferences * Editor = EditorList->Editors[i];
  2057. if ((Editor->Data.Editor == edExternal) &&
  2058. (Editor->Data.ExternalEditor == Data.Command) &&
  2059. ((EnableMDI && !Editor->Data.MDIExternalEditor) ||
  2060. (DisableDetect && Editor->Data.DetectMDIExternalEditor)))
  2061. {
  2062. Changed = true;
  2063. TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
  2064. if (EnableMDI)
  2065. {
  2066. UpdatedEditor->Data.MDIExternalEditor = true;
  2067. }
  2068. if (DisableDetect)
  2069. {
  2070. UpdatedEditor->Data.DetectMDIExternalEditor = false;
  2071. }
  2072. EditorList->Change(i, UpdatedEditor);
  2073. }
  2074. }
  2075. if (Changed)
  2076. {
  2077. WinConfiguration->EditorList = EditorList;
  2078. }
  2079. }
  2080. }
  2081. __finally
  2082. {
  2083. delete EditorList;
  2084. }
  2085. }
  2086. else
  2087. {
  2088. // "open" case
  2089. MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data.OriginalFileName)), qtWarning,
  2090. qaOK, HELP_APP_EARLY_CLOSED);
  2091. }
  2092. }
  2093. }
  2094. //---------------------------------------------------------------------------
  2095. void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
  2096. {
  2097. SideEnter(osRemote);
  2098. }
  2099. //---------------------------------------------------------------------------
  2100. void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
  2101. {
  2102. MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
  2103. SideEnter(osRemote);
  2104. }
  2105. //---------------------------------------------------------------------------
  2106. void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
  2107. {
  2108. FCurrentSide = Side;
  2109. UpdateControls();
  2110. }
  2111. //---------------------------------------------------------------------------
  2112. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  2113. TStrings * FileList)
  2114. {
  2115. assert(Terminal);
  2116. TCustomDirView * DView = DirView(Side);
  2117. DView->SaveSelection();
  2118. DView->SaveSelectedNames();
  2119. try
  2120. {
  2121. if (Side == osRemote)
  2122. {
  2123. Terminal->DeleteFiles(FileList);
  2124. }
  2125. else
  2126. {
  2127. try
  2128. {
  2129. Terminal->DeleteLocalFiles(FileList);
  2130. }
  2131. __finally
  2132. {
  2133. ReloadLocalDirectory();
  2134. }
  2135. }
  2136. }
  2137. catch(...)
  2138. {
  2139. DView->DiscardSavedSelection();
  2140. throw;
  2141. }
  2142. DView->RestoreSelection();
  2143. }
  2144. //---------------------------------------------------------------------------
  2145. bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TStrings * FileList,
  2146. AnsiString & Target, AnsiString & FileMask, bool NoConfirmation, bool Move)
  2147. {
  2148. if (RemoteDriveView->DropTarget != NULL)
  2149. {
  2150. Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
  2151. }
  2152. else if (RemoteDirView->DropTarget != NULL)
  2153. {
  2154. assert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  2155. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  2156. }
  2157. else
  2158. {
  2159. Target = RemoteDirView->Path;
  2160. }
  2161. Target = UnixIncludeTrailingBackslash(Target);
  2162. FileMask = "*.*";
  2163. bool Result = true;
  2164. if (!NoConfirmation)
  2165. {
  2166. Result = DoRemoteTransferDialog(FileList, Target, FileMask, Move);
  2167. }
  2168. return Result;
  2169. }
  2170. //---------------------------------------------------------------------------
  2171. void __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
  2172. TStrings * FileList, bool NoConfirmation, bool Move)
  2173. {
  2174. AnsiString Target, FileMask;
  2175. if ((Move || EnsureCommandSessionFallback(fcRemoteCopy)) &&
  2176. RemoteTransferDialog(FileList, Target, FileMask, NoConfirmation, Move))
  2177. {
  2178. RemoteDirView->SaveSelection();
  2179. RemoteDirView->SaveSelectedNames();
  2180. try
  2181. {
  2182. if (Move)
  2183. {
  2184. Terminal->MoveFiles(FileList, Target, FileMask);
  2185. }
  2186. else
  2187. {
  2188. Terminal->CopyFiles(FileList, Target, FileMask);
  2189. }
  2190. }
  2191. catch(...)
  2192. {
  2193. RemoteDirView->DiscardSavedSelection();
  2194. throw;
  2195. }
  2196. RemoteDirView->RestoreSelection();
  2197. }
  2198. }
  2199. //---------------------------------------------------------------------------
  2200. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  2201. {
  2202. Side = GetSide(Side);
  2203. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  2204. TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
  2205. AnsiString Name = LoadStr(NEW_FOLDER);
  2206. bool SaveSettings = false;
  2207. if (DoCreateDirectoryDialog(Name, AProperties, SaveSettings))
  2208. {
  2209. if (Side == osRemote)
  2210. {
  2211. if (SaveSettings)
  2212. {
  2213. GUIConfiguration->NewDirectoryProperties = Properties;
  2214. }
  2215. RemoteDirView->CreateDirectoryEx(Name, &Properties);
  2216. }
  2217. else
  2218. {
  2219. DirView(Side)->CreateDirectory(Name);
  2220. }
  2221. }
  2222. }
  2223. //---------------------------------------------------------------------------
  2224. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  2225. {
  2226. DoOpenDirectoryDialog(odBrowse, Side);
  2227. }
  2228. //---------------------------------------------------------------------------
  2229. void __fastcall TCustomScpExplorerForm::RemoteDirViewGetSelectFilter(
  2230. TCustomDirView *Sender, bool Select, TFileFilter &Filter)
  2231. {
  2232. assert(Sender);
  2233. if (!DoSelectMaskDialog(Sender, Select, &Filter, Configuration)) Abort();
  2234. }
  2235. //---------------------------------------------------------------------------
  2236. void __fastcall TCustomScpExplorerForm::CalculateSizeEvent(
  2237. TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
  2238. bool & Close)
  2239. {
  2240. // terminal can be already closed (e.g. dropped connection)
  2241. if (Terminal != NULL)
  2242. {
  2243. try
  2244. {
  2245. Terminal->CalculateFilesSize(FileList, Size, 0, NULL, &Stats);
  2246. }
  2247. catch(...)
  2248. {
  2249. if (!Terminal->Active)
  2250. {
  2251. Close = true;
  2252. }
  2253. throw;
  2254. }
  2255. }
  2256. }
  2257. //---------------------------------------------------------------------------
  2258. void __fastcall TCustomScpExplorerForm::CalculateChecksum(const AnsiString & Alg,
  2259. TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
  2260. bool & Close)
  2261. {
  2262. // terminal can be already closed (e.g. dropped connection)
  2263. if (Terminal != NULL)
  2264. {
  2265. try
  2266. {
  2267. Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
  2268. }
  2269. catch(...)
  2270. {
  2271. if (!Terminal->Active)
  2272. {
  2273. Close = true;
  2274. }
  2275. throw;
  2276. }
  2277. }
  2278. }
  2279. //---------------------------------------------------------------------------
  2280. void __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  2281. {
  2282. if (Side == osRemote)
  2283. {
  2284. TRemoteProperties CurrentProperties;
  2285. if (Terminal->LoadFilesProperties(FileList))
  2286. {
  2287. RemoteDirView->Invalidate();
  2288. }
  2289. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  2290. int Flags = 0;
  2291. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  2292. if (Terminal->IsCapable[fcOwnerChanging]) Flags |= cpOwner;
  2293. if (Terminal->IsCapable[fcGroupChanging]) Flags |= cpGroup;
  2294. TCalculateChecksumEvent CalculateChecksumEvent = NULL;
  2295. if (Terminal->IsCapable[fcCalculatingChecksum])
  2296. {
  2297. CalculateChecksumEvent = CalculateChecksum;
  2298. }
  2299. TRemoteProperties NewProperties = CurrentProperties;
  2300. if (DoPropertiesDialog(FileList, RemoteDirView->PathName,
  2301. Terminal->Groups, Terminal->Users, &NewProperties, Flags,
  2302. CalculateSizeEvent, CalculateChecksumEvent))
  2303. {
  2304. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  2305. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  2306. }
  2307. }
  2308. else
  2309. {
  2310. DirView(Side)->DisplayPropertiesMenu();
  2311. }
  2312. }
  2313. //---------------------------------------------------------------------------
  2314. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  2315. {
  2316. if (QueueView->Focused() && (QueueView->OnKeyDown != NULL))
  2317. {
  2318. QueueView->OnKeyDown(QueueView, Key, Shift);
  2319. }
  2320. if (!DirView(osCurrent)->IsEditing())
  2321. {
  2322. TShortCut KeyShortCut = ShortCut(Key, Shift);
  2323. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  2324. {
  2325. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  2326. if (((Action->ShortCut == KeyShortCut) ||
  2327. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  2328. AllowedAction(Action, aaShortCut))
  2329. {
  2330. Key = 0;
  2331. Action->Execute();
  2332. return;
  2333. }
  2334. }
  2335. for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
  2336. {
  2337. if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
  2338. {
  2339. FIgnoreNextSysCommand = true;
  2340. TTerminalManager::Instance()->ActiveTerminalIndex = i;
  2341. return;
  2342. }
  2343. }
  2344. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  2345. {
  2346. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  2347. Key = 0;
  2348. }
  2349. }
  2350. TForm::KeyDown(Key, Shift);
  2351. }
  2352. //---------------------------------------------------------------------------
  2353. void __fastcall TCustomScpExplorerForm::InitStatusBar()
  2354. {
  2355. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  2356. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  2357. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  2358. assert(Terminal);
  2359. bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
  2360. SessionStatusBar->Panels->Items[1]->Enabled = SecurityEnabled;
  2361. // expanded from ?: to avoid memory leaks
  2362. if (SecurityEnabled)
  2363. {
  2364. SessionStatusBar->Panels->Items[1]->Hint =
  2365. FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
  2366. }
  2367. else
  2368. {
  2369. SessionStatusBar->Panels->Items[1]->Hint = LoadStr(STATUS_INSECURE);
  2370. }
  2371. if (FileSystemInfo.ProtocolName.IsEmpty())
  2372. {
  2373. SessionStatusBar->Panels->Items[2]->Caption = SessionInfo.ProtocolName;
  2374. }
  2375. else
  2376. {
  2377. SessionStatusBar->Panels->Items[2]->Caption = FileSystemInfo.ProtocolName;
  2378. }
  2379. SessionStatusBar->Panels->Items[2]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
  2380. SessionStatusBar->Panels->Items[3]->Enabled =
  2381. (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
  2382. if (SessionInfo.CSCompression == SessionInfo.SCCompression)
  2383. {
  2384. SessionStatusBar->Panels->Items[3]->Hint =
  2385. FMTLOAD(STATUS_COMPRESSION_HINT, (DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR))));
  2386. }
  2387. else
  2388. {
  2389. SessionStatusBar->Panels->Items[3]->Hint = FMTLOAD(STATUS_COMPRESSION2_HINT,
  2390. (DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR)),
  2391. DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR))));
  2392. }
  2393. SessionStatusBar->Panels->Items[4]->Hint = LoadStr(STATUS_DURATION_HINT);
  2394. UpdateStatusBar();
  2395. }
  2396. //---------------------------------------------------------------------------
  2397. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  2398. {
  2399. TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
  2400. assert(SessionStatusBar != NULL);
  2401. if (FShowStatusBarHint)
  2402. {
  2403. SessionStatusBar->SimplePanel = true;
  2404. SessionStatusBar->SimpleText = FStatusBarHint;
  2405. }
  2406. else if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
  2407. {
  2408. // note: (Terminal->Status < sshReady) currently never happens here,
  2409. // so STATUS_CONNECTING is never used
  2410. SessionStatusBar->SimplePanel = true;
  2411. SessionStatusBar->SimpleText = LoadStr(
  2412. !Terminal || !Terminal->Active ? STATUS_DISCONNECTED : STATUS_CONNECTING);
  2413. }
  2414. else
  2415. {
  2416. assert(Terminal);
  2417. SessionStatusBar->SimplePanel = false;
  2418. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  2419. if (FNote.IsEmpty())
  2420. {
  2421. UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
  2422. }
  2423. else
  2424. {
  2425. SessionStatusBar->Panels->Items[0]->Caption = FNote;
  2426. }
  2427. SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
  2428. SessionStatusBar->Panels->Items[4]->Caption =
  2429. FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
  2430. }
  2431. }
  2432. //---------------------------------------------------------------------------
  2433. void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
  2434. {
  2435. Panel->Caption = "";
  2436. }
  2437. //---------------------------------------------------------------------------
  2438. void __fastcall TCustomScpExplorerForm::Idle(bool AppIdle)
  2439. {
  2440. FEditorManager->Check();
  2441. // make sure that Idle is called before update queue, as it may invoke QueueEvent
  2442. // that needs to know is queue view is visible (and it may be closed after queue update)
  2443. TTerminalManager::Instance()->Idle();
  2444. if (AppIdle)
  2445. {
  2446. if (FRefreshRemoteDirectory)
  2447. {
  2448. if ((Terminal != NULL) && Terminal->Active)
  2449. {
  2450. Terminal->RefreshDirectory();
  2451. }
  2452. FRefreshRemoteDirectory = false;
  2453. }
  2454. if (FRefreshLocalDirectory)
  2455. {
  2456. ReloadLocalDirectory();
  2457. FRefreshLocalDirectory = false;
  2458. }
  2459. }
  2460. if (FQueueStatusInvalidated)
  2461. {
  2462. UpdateQueueStatus(AppIdle);
  2463. }
  2464. RefreshQueueItems(AppIdle);
  2465. UpdateStatusBar();
  2466. FIgnoreNextSysCommand = false;
  2467. }
  2468. //---------------------------------------------------------------------------
  2469. void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
  2470. {
  2471. try
  2472. {
  2473. FUserActionTimer->Enabled = false;
  2474. if (GUIConfiguration->QueueAutoPopup && (FPendingQueueActionItem != NULL))
  2475. {
  2476. if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
  2477. {
  2478. FPendingQueueActionItem->ProcessUserAction();
  2479. }
  2480. }
  2481. }
  2482. __finally
  2483. {
  2484. FPendingQueueActionItem = NULL;
  2485. }
  2486. }
  2487. //---------------------------------------------------------------------------
  2488. void __fastcall TCustomScpExplorerForm::ApplicationHint(TObject * /*Sender*/)
  2489. {
  2490. assert(Application);
  2491. AnsiString AHint = GetLongHint(Application->Hint);
  2492. FShowStatusBarHint = Active && !AHint.IsEmpty() && (AHint != "X");
  2493. if (FShowStatusBarHint)
  2494. {
  2495. FStatusBarHint = AHint != "E" ? AHint : AnsiString("");
  2496. }
  2497. else
  2498. {
  2499. FStatusBarHint = "";
  2500. }
  2501. UpdateStatusBar();
  2502. }
  2503. //---------------------------------------------------------------------------
  2504. void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
  2505. {
  2506. if (WinConfiguration->MinimizeToTray)
  2507. {
  2508. UpdateTrayIcon();
  2509. FTrayIcon->Visible = true;
  2510. ShowWindow(Application->Handle, SW_HIDE);
  2511. }
  2512. }
  2513. //---------------------------------------------------------------------------
  2514. void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
  2515. {
  2516. if (FTrayIcon->Visible)
  2517. {
  2518. FTrayIcon->Visible = false;
  2519. ShowWindow(Application->Handle, SW_SHOW);
  2520. }
  2521. }
  2522. //---------------------------------------------------------------------------
  2523. void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
  2524. {
  2525. FTrayIcon->Hint = Application->Title;
  2526. }
  2527. //---------------------------------------------------------------------------
  2528. void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
  2529. {
  2530. UpdateTrayIcon();
  2531. }
  2532. //---------------------------------------------------------------------------
  2533. void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
  2534. {
  2535. Application->Restore();
  2536. Application->BringToFront();
  2537. }
  2538. //---------------------------------------------------------------------------
  2539. bool __fastcall TCustomScpExplorerForm::OpenInNewWindow()
  2540. {
  2541. return FLAGSET(GetAsyncKeyState(VK_SHIFT), 0x8000);
  2542. }
  2543. //---------------------------------------------------------------------------
  2544. void __fastcall TCustomScpExplorerForm::NewSession()
  2545. {
  2546. if (OpenInNewWindow())
  2547. {
  2548. if (!ExecuteShell(Application->ExeName, ""))
  2549. {
  2550. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Application->ExeName)));
  2551. }
  2552. }
  2553. else
  2554. {
  2555. TTerminalManager::Instance()->NewSession();
  2556. }
  2557. }
  2558. //---------------------------------------------------------------------------
  2559. void __fastcall TCustomScpExplorerForm::DuplicateSession()
  2560. {
  2561. TSessionData * SessionData = new TSessionData("");
  2562. try
  2563. {
  2564. SessionData->Assign(Terminal->SessionData);
  2565. // current working directories become defaults here, what is not right
  2566. UpdateSessionData(SessionData);
  2567. if (OpenInNewWindow())
  2568. {
  2569. AnsiString SessionName = StoredSessions->HiddenPrefix + "duplicate";
  2570. StoredSessions->NewSession(SessionName, SessionData);
  2571. // modified only, explicit
  2572. StoredSessions->Save(false, true);
  2573. if (!ExecuteShell(Application->ExeName, FORMAT("\"%s\"", (SessionName))))
  2574. {
  2575. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Application->ExeName)));
  2576. }
  2577. }
  2578. else
  2579. {
  2580. TTerminalManager * Manager = TTerminalManager::Instance();
  2581. TTerminal * Terminal = Manager->NewTerminal(SessionData);
  2582. Manager->ActiveTerminal = Terminal;
  2583. Manager->ConnectActiveTerminal();
  2584. }
  2585. }
  2586. __finally
  2587. {
  2588. delete SessionData;
  2589. }
  2590. }
  2591. //---------------------------------------------------------------------------
  2592. bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
  2593. {
  2594. assert(FQueue != NULL);
  2595. return (FQueue->IsEmpty ||
  2596. (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK));
  2597. }
  2598. //---------------------------------------------------------------------------
  2599. void __fastcall TCustomScpExplorerForm::CloseSession()
  2600. {
  2601. if (CanCloseQueue())
  2602. {
  2603. TTerminalManager::Instance()->FreeActiveTerminal();
  2604. }
  2605. }
  2606. //---------------------------------------------------------------------------
  2607. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  2608. {
  2609. if (OpenInNewWindow())
  2610. {
  2611. if (!ExecuteShell(Application->ExeName, FORMAT("\"%s\"", (Data->Name))))
  2612. {
  2613. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Application->ExeName)));
  2614. }
  2615. }
  2616. else
  2617. {
  2618. TTerminalManager * Manager = TTerminalManager::Instance();
  2619. TTerminal * Terminal = Manager->NewTerminal(Data);
  2620. Manager->ActiveTerminal = Terminal;
  2621. Manager->ConnectActiveTerminal();
  2622. }
  2623. }
  2624. //---------------------------------------------------------------------------
  2625. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  2626. bool &CanClose)
  2627. {
  2628. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  2629. {
  2630. int Result;
  2631. TMessageParams Params(mpNeverAskAgainCheck);
  2632. AnsiString Message;
  2633. if (TTerminalManager::Instance()->Count > 1)
  2634. {
  2635. Message = LoadStr(CLOSE_SESSIONS);
  2636. }
  2637. else
  2638. {
  2639. Message = FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName));
  2640. }
  2641. Result = MessageDialog(Message, qtConfirmation,
  2642. qaOK | qaCancel, HELP_NONE, &Params);
  2643. if (Result == qaNeverAskAgain)
  2644. {
  2645. WinConfiguration->ConfirmClosingSession = false;
  2646. }
  2647. CanClose = (Result == qaOK || Result == qaNeverAskAgain);
  2648. }
  2649. if (CanClose)
  2650. {
  2651. CanClose = CanCloseQueue();
  2652. }
  2653. if (CanClose)
  2654. {
  2655. CanClose = FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
  2656. FEditorManager->CloseExternalFilesWithoutProcess() &&
  2657. (FEditorManager->Empty(true) ||
  2658. (MessageDialog(LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel,
  2659. HELP_NONE) == qaIgnore));
  2660. }
  2661. }
  2662. //---------------------------------------------------------------------------
  2663. void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
  2664. {
  2665. TForm * Form = dynamic_cast<TForm *>(Sender);
  2666. assert(Form != NULL);
  2667. Form->Close();
  2668. }
  2669. //---------------------------------------------------------------------------
  2670. void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
  2671. {
  2672. TForm * Form = dynamic_cast<TForm *>(Sender);
  2673. delete Form;
  2674. }
  2675. //---------------------------------------------------------------------------
  2676. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  2677. TObject *Sender)
  2678. {
  2679. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  2680. try
  2681. {
  2682. SetProperties(osRemote, FileList);
  2683. }
  2684. __finally
  2685. {
  2686. delete FileList;
  2687. }
  2688. }
  2689. //---------------------------------------------------------------------------
  2690. void __fastcall TCustomScpExplorerForm::ComponentShowing(Word Component, bool value)
  2691. {
  2692. if (value)
  2693. {
  2694. if (Component == fcCustomCommandsBand)
  2695. {
  2696. UpdateCustomCommandsToolbar();
  2697. }
  2698. }
  2699. }
  2700. //---------------------------------------------------------------------------
  2701. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Word Component, Boolean value)
  2702. {
  2703. TControl * Control = GetComponent(Component);
  2704. assert(Control);
  2705. bool Changed = (Control->Visible != value);
  2706. if (Changed)
  2707. {
  2708. ComponentShowing(Component, value);
  2709. TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
  2710. bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
  2711. ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
  2712. if (value)
  2713. {
  2714. int RemainingHeight = Control->Parent->ClientHeight;
  2715. int RemainingWidth = Control->Parent->ClientWidth;
  2716. for (int i = 0; i < Control->Parent->ControlCount; i++)
  2717. {
  2718. TControl * ChildControl = Control->Parent->Controls[i];
  2719. if (ChildControl->Visible)
  2720. {
  2721. switch (ChildControl->Align)
  2722. {
  2723. case alTop:
  2724. case alBottom:
  2725. RemainingHeight -= ChildControl->Height;
  2726. break;
  2727. case alLeft:
  2728. case alRight:
  2729. RemainingWidth -= ChildControl->Width;
  2730. break;
  2731. }
  2732. }
  2733. }
  2734. static int Reserve = 32;
  2735. // queue in explorer, trees in commander
  2736. if (Control->Height > RemainingHeight - Reserve)
  2737. {
  2738. Control->Height = RemainingHeight / 2;
  2739. }
  2740. if (Control->Width > RemainingWidth - Reserve)
  2741. {
  2742. Control->Width = RemainingWidth / 2;
  2743. }
  2744. }
  2745. Control->Visible = value;
  2746. if (WasFocused && Visible)
  2747. {
  2748. DirView(osCurrent)->SetFocus();
  2749. }
  2750. FixControlsPlacement();
  2751. }
  2752. }
  2753. //---------------------------------------------------------------------------
  2754. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Word Component)
  2755. {
  2756. TControl * Control = GetComponent(Component);
  2757. if (Control == NULL)
  2758. {
  2759. return false;
  2760. }
  2761. else
  2762. {
  2763. return Control->Visible;
  2764. }
  2765. }
  2766. //---------------------------------------------------------------------------
  2767. void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
  2768. {
  2769. if (RemoteDirView->ItemFocused != NULL)
  2770. {
  2771. RemoteDirView->ItemFocused->MakeVisible(false);
  2772. }
  2773. QueueSplitter->Visible = QueuePanel->Visible;
  2774. RemotePanelSplitter->Visible = RemoteDriveView->Visible;
  2775. }
  2776. //---------------------------------------------------------------------------
  2777. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  2778. {
  2779. switch (Component) {
  2780. case fcStatusBar: return RemoteStatusBar;
  2781. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
  2782. case fcQueueView: return QueuePanel;
  2783. case fcQueueToolbar: return QueueDock;
  2784. case fcRemoteTree: return RemoteDriveView;
  2785. default: return NULL;
  2786. }
  2787. }
  2788. //---------------------------------------------------------------------------
  2789. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  2790. TObject *Sender, TListColumn *Column, TPoint &Point)
  2791. {
  2792. assert(NonVisualDataModule && Column && Sender);
  2793. NonVisualDataModule->ListColumn = Column;
  2794. TPoint ScreenPoint = ((TControl*)Sender)->ClientToScreen(Point);
  2795. TPopupMenu * DirViewColumnMenu;
  2796. if (Sender == RemoteDirView)
  2797. {
  2798. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  2799. NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
  2800. (Column->Index == uvName);
  2801. }
  2802. else
  2803. {
  2804. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  2805. NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
  2806. (Column->Index == dvName);
  2807. }
  2808. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  2809. }
  2810. //---------------------------------------------------------------------------
  2811. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  2812. TObject *Sender, TListItem *Item, bool &AllowExec)
  2813. {
  2814. DoDirViewExecFile(Sender, Item, AllowExec);
  2815. }
  2816. //---------------------------------------------------------------------------
  2817. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  2818. TListItem * Item, bool & AllowExec)
  2819. {
  2820. assert(Sender && Item && Configuration);
  2821. assert(AllowExec);
  2822. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  2823. bool Remote = (ADirView == DirView(osRemote));
  2824. bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
  2825. // Anything special is done on double click only (not on "open" indicated by FForceExecution),
  2826. // on files only (not directories)
  2827. // and only when symlinks are resolved (apply to remote panel only)
  2828. if (!ADirView->ItemIsDirectory(Item) &&
  2829. (ResolvedSymlinks || FForceExecution))
  2830. {
  2831. if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
  2832. !FForceExecution &&
  2833. ResolvedSymlinks)
  2834. {
  2835. if (WinConfiguration->DoubleClickAction == dcaCopy)
  2836. {
  2837. ExecuteFileOperation(foCopy,
  2838. (ADirView == DirView(osRemote) ? osRemote : osLocal),
  2839. true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  2840. AllowExec = false;
  2841. }
  2842. else if (WinConfiguration->DoubleClickAction == dcaEdit)
  2843. {
  2844. if (!Remote || !WinConfiguration->DisableOpenEdit)
  2845. {
  2846. ExecuteFile(osCurrent, efDefaultEditor);
  2847. AllowExec = false;
  2848. }
  2849. }
  2850. else
  2851. {
  2852. assert(false);
  2853. }
  2854. }
  2855. // if we have not done anything special, fall back to default behaviour
  2856. if (AllowExec)
  2857. {
  2858. if (Remote && !WinConfiguration->DisableOpenEdit)
  2859. {
  2860. ExecuteFile(osRemote, efShell);
  2861. AllowExec = false;
  2862. }
  2863. }
  2864. }
  2865. }
  2866. //---------------------------------------------------------------------------
  2867. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  2868. {
  2869. return ((Side == osRemote) || (Side == osCurrent));
  2870. }
  2871. //---------------------------------------------------------------------------
  2872. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  2873. {
  2874. assert(false);
  2875. }
  2876. //---------------------------------------------------------------------------
  2877. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  2878. {
  2879. assert(false);
  2880. }
  2881. //---------------------------------------------------------------------------
  2882. bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
  2883. AnsiString & LocalDirectory, AnsiString & RemoteDirectory, bool UseDefaults)
  2884. {
  2885. TSynchronizeParamType Params;
  2886. Params.LocalDirectory = LocalDirectory;
  2887. Params.RemoteDirectory = RemoteDirectory;
  2888. int UnusedParams =
  2889. (GUIConfiguration->SynchronizeParams &
  2890. (spPreviewChanges | spTimestamp | spNotByTime | spBySize));
  2891. Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
  2892. Params.Options = GUIConfiguration->SynchronizeOptions;
  2893. bool SaveSettings = false;
  2894. TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
  2895. &DoSynchronizeTooManyDirectories);
  2896. assert(FSynchronizeController == NULL);
  2897. FSynchronizeController = &Controller;
  2898. bool Result;
  2899. try
  2900. {
  2901. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  2902. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
  2903. int Options =
  2904. FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
  2905. Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
  2906. SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, UseDefaults);
  2907. if (Result)
  2908. {
  2909. if (SaveSettings)
  2910. {
  2911. GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
  2912. GUIConfiguration->SynchronizeOptions = Params.Options;
  2913. }
  2914. LocalDirectory = Params.LocalDirectory;
  2915. RemoteDirectory = Params.RemoteDirectory;
  2916. }
  2917. }
  2918. __finally
  2919. {
  2920. FSynchronizeController = NULL;
  2921. }
  2922. return Result;
  2923. }
  2924. //---------------------------------------------------------------------------
  2925. void __fastcall TCustomScpExplorerForm::DoSynchronize(
  2926. TSynchronizeController * /*Sender*/, const AnsiString LocalDirectory,
  2927. const AnsiString RemoteDirectory, const TCopyParamType & CopyParam,
  2928. const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
  2929. TSynchronizeOptions * Options, bool Full)
  2930. {
  2931. try
  2932. {
  2933. int PParams = Params.Params;
  2934. if (!Full)
  2935. {
  2936. PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache |
  2937. TTerminal::spDelayProgress | TTerminal::spSubDirs;
  2938. }
  2939. Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
  2940. PParams, Checklist, Options);
  2941. }
  2942. catch(Exception & E)
  2943. {
  2944. ShowExtendedExceptionEx(Terminal, &E);
  2945. throw;
  2946. }
  2947. }
  2948. //---------------------------------------------------------------------------
  2949. void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
  2950. TSynchronizeController * /*Sender*/, const AnsiString Directory,
  2951. const AnsiString ErrorStr)
  2952. {
  2953. if (!Directory.IsEmpty())
  2954. {
  2955. SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
  2956. }
  2957. else
  2958. {
  2959. SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
  2960. }
  2961. }
  2962. //---------------------------------------------------------------------------
  2963. void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
  2964. TSynchronizeController * /*Sender*/, int & MaxDirectories)
  2965. {
  2966. if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
  2967. {
  2968. MaxDirectories = GUIConfiguration->MaxWatchDirectories;
  2969. }
  2970. else
  2971. {
  2972. TMessageParams Params(mpNeverAskAgainCheck);
  2973. int Result = MessageDialog(
  2974. FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
  2975. qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
  2976. if ((Result == qaYes) || (Result == qaNeverAskAgain))
  2977. {
  2978. MaxDirectories *= 2;
  2979. if (Result == qaNeverAskAgain)
  2980. {
  2981. GUIConfiguration->MaxWatchDirectories = MaxDirectories;
  2982. }
  2983. }
  2984. else
  2985. {
  2986. Abort();
  2987. }
  2988. }
  2989. }
  2990. //---------------------------------------------------------------------------
  2991. void __fastcall TCustomScpExplorerForm::Synchronize(const AnsiString LocalDirectory,
  2992. const AnsiString RemoteDirectory, TSynchronizeMode Mode,
  2993. const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
  2994. TSynchronizeOptions * Options)
  2995. {
  2996. assert(!FAutoOperation);
  2997. void * BatchStorage;
  2998. BatchStart(BatchStorage);
  2999. FAutoOperation = true;
  3000. TSynchronizeChecklist * AChecklist = NULL;
  3001. try
  3002. {
  3003. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  3004. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  3005. {
  3006. FSynchronizeProgressForm->Start();
  3007. }
  3008. AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  3009. static_cast<TTerminal::TSynchronizeMode>(Mode),
  3010. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
  3011. Options);
  3012. SAFE_DESTROY(FSynchronizeProgressForm);
  3013. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  3014. if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
  3015. {
  3016. FSynchronizeProgressForm->Start();
  3017. }
  3018. Terminal->SynchronizeApply(AChecklist, LocalDirectory, RemoteDirectory,
  3019. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
  3020. }
  3021. __finally
  3022. {
  3023. if (Checklist == NULL)
  3024. {
  3025. delete AChecklist;
  3026. }
  3027. else
  3028. {
  3029. *Checklist = AChecklist;
  3030. }
  3031. FAutoOperation = false;
  3032. SAFE_DESTROY(FSynchronizeProgressForm);
  3033. BatchEnd(BatchStorage);
  3034. ReloadLocalDirectory();
  3035. }
  3036. }
  3037. //---------------------------------------------------------------------------
  3038. bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
  3039. {
  3040. // can be called from command line
  3041. return Visible &&
  3042. ((DirView(osRemote)->SelCount > 0) ||
  3043. (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
  3044. }
  3045. //---------------------------------------------------------------------------
  3046. void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
  3047. int Params, TSynchronizeOptions & Options)
  3048. {
  3049. if (FLAGSET(Params, spSelectedOnly) && SynchronizeAllowSelectedOnly())
  3050. {
  3051. Options.Filter = new TStringList();
  3052. Options.Filter->CaseSensitive = false;
  3053. Options.Filter->Duplicates = dupAccept;
  3054. if (DirView(osRemote)->SelCount > 0)
  3055. {
  3056. DirView(osRemote)->CreateFileList(false, false, Options.Filter);
  3057. }
  3058. if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
  3059. {
  3060. DirView(osLocal)->CreateFileList(false, false, Options.Filter);
  3061. }
  3062. Options.Filter->Sort();
  3063. }
  3064. }
  3065. //---------------------------------------------------------------------------
  3066. bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  3067. AnsiString & LocalDirectory, AnsiString & RemoteDirectory,
  3068. TSynchronizeMode & Mode, bool & SaveMode, bool UseDefaults)
  3069. {
  3070. bool Result;
  3071. int Params = GUIConfiguration->SynchronizeParams;
  3072. bool SaveSettings = false;
  3073. int Options =
  3074. FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
  3075. FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
  3076. TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
  3077. TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
  3078. Result = UseDefaults ||
  3079. DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  3080. &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
  3081. if (Result)
  3082. {
  3083. TSynchronizeOptions SynchronizeOptions;
  3084. GetSynchronizeOptions(Params, SynchronizeOptions);
  3085. if (SaveSettings)
  3086. {
  3087. GUIConfiguration->SynchronizeParams = Params;
  3088. }
  3089. else
  3090. {
  3091. SaveMode = false;
  3092. }
  3093. TDateTime StartTime = Now();
  3094. TSynchronizeChecklist * Checklist = NULL;
  3095. try
  3096. {
  3097. assert(!FAutoOperation);
  3098. FAutoOperation = true;
  3099. try
  3100. {
  3101. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
  3102. FSynchronizeProgressForm->Start();
  3103. Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
  3104. static_cast<TTerminal::TSynchronizeMode>(Mode),
  3105. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
  3106. &SynchronizeOptions);
  3107. }
  3108. __finally
  3109. {
  3110. FAutoOperation = false;
  3111. SAFE_DESTROY(FSynchronizeProgressForm);
  3112. }
  3113. if (Checklist->Count == 0)
  3114. {
  3115. MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
  3116. HELP_SYNCHRONIZE_NO_DIFFERENCES);
  3117. }
  3118. else if (FLAGCLEAR(Params, spPreviewChanges) ||
  3119. DoSynchronizeChecklistDialog(Checklist, Mode, Params,
  3120. LocalDirectory, RemoteDirectory))
  3121. {
  3122. assert(!FAutoOperation);
  3123. void * BatchStorage;
  3124. BatchStart(BatchStorage);
  3125. FAutoOperation = true;
  3126. if (FLAGSET(Params, spPreviewChanges))
  3127. {
  3128. StartTime = Now();
  3129. }
  3130. try
  3131. {
  3132. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
  3133. FSynchronizeProgressForm->Start();
  3134. Terminal->SynchronizeApply(Checklist, LocalDirectory, RemoteDirectory,
  3135. &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
  3136. }
  3137. __finally
  3138. {
  3139. FAutoOperation = false;
  3140. SAFE_DESTROY(FSynchronizeProgressForm);
  3141. BatchEnd(BatchStorage);
  3142. ReloadLocalDirectory();
  3143. }
  3144. }
  3145. }
  3146. __finally
  3147. {
  3148. delete Checklist;
  3149. }
  3150. OperationComplete(StartTime);
  3151. }
  3152. return Result;
  3153. }
  3154. //---------------------------------------------------------------------------
  3155. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  3156. const AnsiString LocalDirectory, const AnsiString RemoteDirectory,
  3157. bool & Continue, bool /*Collect*/)
  3158. {
  3159. assert(FSynchronizeProgressForm != NULL);
  3160. if (!FSynchronizeProgressForm->Started)
  3161. {
  3162. FSynchronizeProgressForm->Start();
  3163. }
  3164. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  3165. }
  3166. //---------------------------------------------------------------------------
  3167. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  3168. {
  3169. assert(false);
  3170. }
  3171. //---------------------------------------------------------------------------
  3172. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  3173. {
  3174. AnsiString SessionName;
  3175. SessionName = Terminal->SessionData->SessionName;
  3176. SessionName = DoSaveSessionDialog(SessionName, NULL);
  3177. if (!SessionName.IsEmpty())
  3178. {
  3179. TSessionData * SessionData = new TSessionData("");
  3180. try
  3181. {
  3182. SessionData->Assign(Terminal->SessionData);
  3183. UpdateSessionData(SessionData);
  3184. StoredSessions->NewSession(SessionName, SessionData);
  3185. // modified only, explicit
  3186. StoredSessions->Save(false, true);
  3187. }
  3188. __finally
  3189. {
  3190. delete SessionData;
  3191. }
  3192. }
  3193. }
  3194. //---------------------------------------------------------------------------
  3195. void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
  3196. {
  3197. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(FTerminal);
  3198. assert(ManagedTerminal != NULL);
  3199. SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
  3200. if (WinConfiguration->PreservePanelState)
  3201. {
  3202. ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
  3203. }
  3204. // cannot use RemoteDirView->Path, because it is empty if connection
  3205. // was already closed
  3206. ManagedTerminal->RemoteDirectory = Terminal->CurrentDirectory;
  3207. ManagedTerminal->Color = SessionColor;
  3208. }
  3209. //---------------------------------------------------------------------------
  3210. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  3211. {
  3212. assert(Data != NULL);
  3213. // cannot use RemoteDirView->Path, because it is empty if connection
  3214. // was already closed
  3215. Data->RemoteDirectory = Terminal->CurrentDirectory;
  3216. Data->Color = SessionColor;
  3217. }
  3218. //---------------------------------------------------------------------------
  3219. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  3220. {
  3221. TTBXToolbar * ToolBar = dynamic_cast<TTBXToolbar*>(Sender);
  3222. assert(ToolBar != NULL);
  3223. if (ToolBar->Items->Count == 1)
  3224. {
  3225. TTBControlItem * Item = dynamic_cast<TTBControlItem *>(ToolBar->Items->Items[0]);
  3226. assert(Item != NULL);
  3227. // seems that Item->Control can be NULL when closing window
  3228. if (Item->Control != NULL)
  3229. {
  3230. Item->Control->Width = ToolBar->Width - ToolBar->NonClientWidth;
  3231. }
  3232. }
  3233. else
  3234. {
  3235. int ControlWidth;
  3236. TControl * ResizeControl = NULL;
  3237. TTBXComboBoxItem * ResizeComboBox = NULL;
  3238. for (int i = 0; i < ToolBar->Items->Count; i++)
  3239. {
  3240. TTBControlItem * ControlItem;
  3241. ControlItem = dynamic_cast<TTBControlItem *>(ToolBar->Items->Items[i]);
  3242. // seems that Item->Control can be NULL when closing window
  3243. if ((ControlItem != NULL) && (ControlItem->Control != NULL) &&
  3244. (ControlItem->Control->Tag != 0))
  3245. {
  3246. ResizeControl = ControlItem->Control;
  3247. ControlWidth = ResizeControl->Width;
  3248. break;
  3249. }
  3250. // currently never used
  3251. TTBXComboBoxItem * ComboBoxItem;
  3252. ComboBoxItem = dynamic_cast<TTBXComboBoxItem *>(ToolBar->Items->Items[i]);
  3253. if (ComboBoxItem != NULL)
  3254. {
  3255. ResizeComboBox = ComboBoxItem;
  3256. ControlWidth = ResizeComboBox->EditWidth;
  3257. break;
  3258. }
  3259. }
  3260. ControlWidth = ToolBar->Width - (ToolBar->View->BaseSize.x -
  3261. ControlWidth) - ToolBar->NonClientWidth;
  3262. if (ResizeControl != NULL)
  3263. {
  3264. ResizeControl->Width = ControlWidth;
  3265. }
  3266. // currently never used
  3267. if (ResizeComboBox != NULL)
  3268. {
  3269. ResizeComboBox->EditWidth = ControlWidth;
  3270. }
  3271. }
  3272. }
  3273. //---------------------------------------------------------------------------
  3274. void __fastcall TCustomScpExplorerForm::AddressToolbarGetBaseSize(
  3275. TTBCustomToolbar * Toolbar, TPoint & ASize)
  3276. {
  3277. for (int i = 0; i < Toolbar->Items->Count; i++)
  3278. {
  3279. TTBControlItem * ControlItem;
  3280. ControlItem = dynamic_cast<TTBControlItem *>(Toolbar->Items->Items[i]);
  3281. if (ControlItem != NULL)
  3282. {
  3283. ASize.x = ASize.x - ControlItem->Control->Width +
  3284. ControlItem->Control->Constraints->MinWidth;
  3285. }
  3286. // currently never used
  3287. TTBXComboBoxItem * ComboBoxItem;
  3288. ComboBoxItem = dynamic_cast<TTBXComboBoxItem *>(Toolbar->Items->Items[i]);
  3289. if (ComboBoxItem != NULL)
  3290. {
  3291. ASize.x = ASize.x - ComboBoxItem->EditWidth + ComboBoxItem->Tag;
  3292. }
  3293. }
  3294. }
  3295. //---------------------------------------------------------------------------
  3296. void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
  3297. const AnsiString Path, __int64 RequiredSpace, bool & Continue)
  3298. {
  3299. if (WinConfiguration->DDWarnLackOfTempSpace)
  3300. {
  3301. AnsiString ADrive = ExtractFileDrive(ExpandFileName(Path));
  3302. if (!ADrive.IsEmpty())
  3303. {
  3304. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  3305. assert(RequiredSpace >= 0);
  3306. __int64 RequiredWithReserve;
  3307. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  3308. if (FreeSpace < RequiredWithReserve)
  3309. {
  3310. int Result;
  3311. TMessageParams Params(mpNeverAskAgainCheck);
  3312. Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
  3313. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  3314. qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
  3315. if (Result == qaNeverAskAgain)
  3316. {
  3317. WinConfiguration->DDWarnLackOfTempSpace = false;
  3318. }
  3319. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  3320. }
  3321. }
  3322. }
  3323. }
  3324. //---------------------------------------------------------------------------
  3325. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  3326. {
  3327. DoOpenDirectoryDialog(odAddBookmark, Side);
  3328. }
  3329. //---------------------------------------------------------------------------
  3330. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  3331. {
  3332. TStringList * VisitedDirectories = new TStringList();
  3333. try
  3334. {
  3335. TCustomDirView * DView = DirView(Side);
  3336. VisitedDirectories->Duplicates = dupIgnore;
  3337. // we should better use TCustomDirView::FCaseSensitive, but it is private
  3338. VisitedDirectories->CaseSensitive = (Side == osRemote);
  3339. VisitedDirectories->Sorted = true;
  3340. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  3341. {
  3342. VisitedDirectories->Add(DView->HistoryPath[Index]);
  3343. }
  3344. }
  3345. catch (...)
  3346. {
  3347. delete VisitedDirectories;
  3348. throw;
  3349. }
  3350. return VisitedDirectories;
  3351. }
  3352. //---------------------------------------------------------------------------
  3353. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  3354. TOpenDirectoryMode Mode, TOperationSide Side)
  3355. {
  3356. if (Mode != odAddBookmark ||
  3357. (MessageDialog(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)),
  3358. qtConfirmation, qaYes | qaNo, HELP_ADD_BOOKMARK_CONFIRM) == qaYes))
  3359. {
  3360. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  3361. try
  3362. {
  3363. AnsiString Name = DirView(Side)->PathName;
  3364. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
  3365. HasDirView[osLocal]))
  3366. {
  3367. DirView(Side)->Path = Name;
  3368. }
  3369. }
  3370. __finally
  3371. {
  3372. delete VisitedDirectories;
  3373. }
  3374. }
  3375. }
  3376. //---------------------------------------------------------------------------
  3377. bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
  3378. {
  3379. bool Result = FTerminal->IsCapable[Capability] ||
  3380. FTerminal->CommandSessionOpened;
  3381. if (!Result)
  3382. {
  3383. assert(FTerminal->IsCapable[fcSecondaryShell]);
  3384. if (!GUIConfiguration->ConfirmCommandSession)
  3385. {
  3386. Result = true;
  3387. }
  3388. else
  3389. {
  3390. TMessageParams Params(mpNeverAskAgainCheck);
  3391. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
  3392. int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION,
  3393. (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
  3394. qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
  3395. if (Answer == qaNeverAskAgain)
  3396. {
  3397. GUIConfiguration->ConfirmCommandSession = false;
  3398. Result = true;
  3399. }
  3400. else if (Answer == qaOK)
  3401. {
  3402. Result = true;
  3403. }
  3404. }
  3405. if (Result)
  3406. {
  3407. try
  3408. {
  3409. TTerminalManager::ConnectTerminal(FTerminal->CommandSession, false);
  3410. }
  3411. catch(Exception & E)
  3412. {
  3413. ShowExtendedExceptionEx(FTerminal->CommandSession, &E);
  3414. Result = false;
  3415. }
  3416. }
  3417. }
  3418. return Result;
  3419. }
  3420. //---------------------------------------------------------------------------
  3421. void __fastcall TCustomScpExplorerForm::OpenConsole(AnsiString Command)
  3422. {
  3423. if (EnsureCommandSessionFallback(fcAnyCommand))
  3424. {
  3425. DoConsoleDialog(Terminal, Command);
  3426. }
  3427. }
  3428. //---------------------------------------------------------------------------
  3429. void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
  3430. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  3431. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  3432. {
  3433. if (IsFileControl(DropSourceControl, osRemote) &&
  3434. (FDDExtMapFile != NULL))
  3435. {
  3436. Accept = true;
  3437. }
  3438. FDDTargetControl = dynamic_cast<TControl*>(Sender);
  3439. assert(FDDTargetControl != NULL);
  3440. }
  3441. //---------------------------------------------------------------------------
  3442. void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
  3443. TObject *Sender)
  3444. {
  3445. USEDPARAM(Sender);
  3446. assert(FDDTargetControl == Sender);
  3447. FDDTargetControl = NULL;
  3448. }
  3449. //---------------------------------------------------------------------------
  3450. void __fastcall TCustomScpExplorerForm::AddEditLink(bool Add)
  3451. {
  3452. assert(FCurrentSide == osRemote);
  3453. bool Edit = false;
  3454. TRemoteFile * File = NULL;
  3455. AnsiString FileName;
  3456. AnsiString PointTo;
  3457. bool SymbolicLink = true;
  3458. if (RemoteDirView->ItemFocused)
  3459. {
  3460. assert(RemoteDirView->ItemFocused->Data);
  3461. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  3462. Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  3463. if (Edit)
  3464. {
  3465. FileName = File->FileName;
  3466. PointTo = File->LinkTo;
  3467. }
  3468. else
  3469. {
  3470. PointTo = File->FileName;
  3471. }
  3472. }
  3473. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  3474. Terminal->IsCapable[fcHardLink]))
  3475. {
  3476. if (Edit)
  3477. {
  3478. assert(File->FileName == FileName);
  3479. bool Recursive = false;
  3480. Terminal->ExceptionOnFail = true;
  3481. try
  3482. {
  3483. Terminal->DeleteFile("", File, &Recursive);
  3484. }
  3485. __finally
  3486. {
  3487. Terminal->ExceptionOnFail = false;
  3488. }
  3489. }
  3490. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  3491. }
  3492. }
  3493. //---------------------------------------------------------------------------
  3494. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  3495. {
  3496. assert(!WinConfiguration->DisableOpenEdit);
  3497. FForceExecution = true;
  3498. try
  3499. {
  3500. DirView(osCurrent)->ExecuteCurrentFile();
  3501. }
  3502. __finally
  3503. {
  3504. FForceExecution = false;
  3505. }
  3506. }
  3507. //---------------------------------------------------------------------------
  3508. void __fastcall TCustomScpExplorerForm::TerminalClosed(TObject * Sender)
  3509. {
  3510. FEditorManager->ProcessFiles(FileTerminalClosed, Sender);
  3511. }
  3512. //---------------------------------------------------------------------------
  3513. void __fastcall TCustomScpExplorerForm::FileTerminalClosed(const AnsiString FileName,
  3514. TEditedFileData & Data, TObject * /*Token*/, void * Arg)
  3515. {
  3516. TTerminal * Terminal = static_cast<TTerminal *>(Arg);
  3517. assert(Terminal != NULL);
  3518. if (Data.Terminal == Terminal)
  3519. {
  3520. Data.Terminal = NULL;
  3521. }
  3522. }
  3523. //---------------------------------------------------------------------------
  3524. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  3525. {
  3526. try
  3527. {
  3528. TTerminalManager::Instance()->NewSession();
  3529. }
  3530. __finally
  3531. {
  3532. if (!Terminal || !Terminal->Active)
  3533. {
  3534. Application->Terminate();
  3535. }
  3536. }
  3537. }
  3538. //---------------------------------------------------------------------------
  3539. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  3540. {
  3541. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem*>(
  3542. static_cast<TComponent*>(GetComponent(fcSessionCombo)));
  3543. if (SessionCombo != NULL)
  3544. {
  3545. SessionCombo->Strings = TTerminalManager::Instance()->TerminalList;
  3546. SessionCombo->ItemIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  3547. }
  3548. if ((TTerminalManager::Instance()->ActiveCount >= 2) &&
  3549. !WinConfiguration->SessionToolbarAutoShown &&
  3550. !ComponentVisible[fcSessionToolbar])
  3551. {
  3552. ComponentVisible[fcSessionToolbar] = true;
  3553. WinConfiguration->SessionToolbarAutoShown = true;
  3554. }
  3555. }
  3556. //---------------------------------------------------------------------------
  3557. void __fastcall TCustomScpExplorerForm::SessionComboPopup(TTBCustomItem * Sender,
  3558. bool /*FromLink*/)
  3559. {
  3560. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem *>(Sender);
  3561. assert(SessionCombo);
  3562. HDC DC = GetDC(0);
  3563. TCanvas * Canvas = new TCanvas();
  3564. try
  3565. {
  3566. Canvas->Handle = DC;
  3567. Canvas->Font = ToolbarFont;
  3568. int MaxWidth = 0, Width;
  3569. for (int i = 0; i < SessionCombo->Strings->Count; i++)
  3570. {
  3571. Width = Canvas->TextExtent(SessionCombo->Strings->Strings[i]).cx;
  3572. TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(i);
  3573. if (ShortCut != scNone)
  3574. {
  3575. Width += Canvas->TextExtent(ShortCutToText(ShortCut) + " ").cx;
  3576. }
  3577. if (Width > MaxWidth)
  3578. {
  3579. MaxWidth = Width;
  3580. }
  3581. }
  3582. if (SessionCombo->Strings->Count > SessionCombo->MaxVisibleItems)
  3583. {
  3584. MaxWidth += GetSystemMetrics(SM_CXVSCROLL);
  3585. }
  3586. SessionCombo->MinListWidth = MaxWidth + 8 + 8 + 1;
  3587. }
  3588. __finally
  3589. {
  3590. Canvas->Handle = NULL;
  3591. ReleaseDC(0, DC);
  3592. delete Canvas;
  3593. }
  3594. }
  3595. //---------------------------------------------------------------------------
  3596. void __fastcall TCustomScpExplorerForm::SessionComboDrawItem(
  3597. TTBXCustomList * Sender, TCanvas * Canvas, const TRect & ARect, int Index,
  3598. int AHoverIndex, bool & DrawDefault)
  3599. {
  3600. TTBXStringList * SessionCombo = dynamic_cast<TTBXStringList *>(Sender);
  3601. assert(SessionCombo);
  3602. if (Index >= 0)
  3603. {
  3604. int ShortCutWidth = 0;
  3605. AnsiString ShortCutStr;
  3606. TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(Index);
  3607. if (ShortCut != scNone)
  3608. {
  3609. ShortCutStr = " " + ShortCutToText(ShortCut);
  3610. ShortCutWidth = Canvas->TextExtent(ShortCutStr).cx;
  3611. }
  3612. if (Index != AHoverIndex)
  3613. {
  3614. TManagedTerminal * Terminal =
  3615. dynamic_cast<TManagedTerminal *>(SessionCombo->Strings->Objects[Index]);
  3616. assert(Terminal != NULL);
  3617. TColor Color =
  3618. (Terminal == this->Terminal ? SessionColor : Terminal->Color);
  3619. if (Color != 0)
  3620. {
  3621. Canvas->Brush->Color = Color;
  3622. Canvas->Brush->Style = bsSolid;
  3623. Canvas->FillRect(ARect);
  3624. }
  3625. }
  3626. TRect R = ARect;
  3627. InflateRect(&R, -4, 1);
  3628. R.Right -= ShortCutWidth + 2;
  3629. AnsiString S = SessionCombo->Strings->Strings[Index];
  3630. DrawText(Canvas->Handle, S.c_str(), S.Length(), &R,
  3631. DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
  3632. R = ARect;
  3633. InflateRect(&R, -4, 1);
  3634. R.Left = R.Right - ShortCutWidth;
  3635. DrawText(Canvas->Handle, ShortCutStr.c_str(), ShortCutStr.Length(), &R,
  3636. DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
  3637. }
  3638. DrawDefault = false;
  3639. }
  3640. //---------------------------------------------------------------------------
  3641. void __fastcall TCustomScpExplorerForm::SessionComboChange(TObject * Sender,
  3642. const AnsiString Text)
  3643. {
  3644. TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem *>(Sender);
  3645. assert(SessionCombo);
  3646. TTerminal * Terminal;
  3647. Terminal = dynamic_cast<TTerminal *>(SessionCombo->Strings->Objects[SessionCombo->ItemIndex]);
  3648. assert(Terminal);
  3649. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  3650. }
  3651. //---------------------------------------------------------------------------
  3652. void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
  3653. {
  3654. TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
  3655. assert(TransferList != NULL);
  3656. AnsiString Name;
  3657. if (TransferList->ItemIndex <= 0)
  3658. {
  3659. Name = "";
  3660. }
  3661. else
  3662. {
  3663. Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
  3664. }
  3665. if (FCopyParamAutoSelected.IsEmpty())
  3666. {
  3667. // if previous preset was not autoselected, make new preset the "default"
  3668. FCopyParamDefault = Name;
  3669. }
  3670. GUIConfiguration->CopyParamCurrent = Name;
  3671. }
  3672. //---------------------------------------------------------------------------
  3673. void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
  3674. {
  3675. // sanity check
  3676. bool ExistingPreset =
  3677. (FTransferListHoverIndex >= 0) &&
  3678. (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
  3679. assert(ExistingPreset);
  3680. if (ExistingPreset)
  3681. {
  3682. HDC DC = GetDC(0);
  3683. TCanvas * Canvas = new TCanvas();
  3684. try
  3685. {
  3686. Canvas->Handle = DC;
  3687. Canvas->Font = ToolbarFont;
  3688. AnsiString Name;
  3689. if (FTransferListHoverIndex == 0)
  3690. {
  3691. Name = "";
  3692. }
  3693. else
  3694. {
  3695. Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
  3696. }
  3697. TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
  3698. static_cast<TComponent*>(GetComponent(fcTransferLabel)));
  3699. TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
  3700. static_cast<TObject*>(GetComponent(fcTransferList)));
  3701. AnsiString InfoStr =
  3702. GUIConfiguration->CopyParamPreset[Name].
  3703. GetInfoStr("; ",
  3704. FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General));
  3705. int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - 10;
  3706. if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
  3707. {
  3708. AnsiString Ellipsis = "...";
  3709. while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
  3710. {
  3711. InfoStr.SetLength(InfoStr.Length() - 1);
  3712. }
  3713. InfoStr += Ellipsis;
  3714. }
  3715. // UpdateCaption does not cause invalidation of whole submenu, while
  3716. // setting Caption property does.
  3717. // also it probably does not resize the label, even if necessary
  3718. // (we do not want that anyway)
  3719. TransferLabel->UpdateCaption(InfoStr);
  3720. }
  3721. __finally
  3722. {
  3723. Canvas->Handle = NULL;
  3724. ReleaseDC(0, DC);
  3725. delete Canvas;
  3726. }
  3727. }
  3728. }
  3729. //---------------------------------------------------------------------------
  3730. void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
  3731. TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
  3732. int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
  3733. {
  3734. if (FTransferListHoverIndex != AHoverIndex)
  3735. {
  3736. FTransferListHoverIndex = AHoverIndex;
  3737. UpdateTransferLabel();
  3738. }
  3739. }
  3740. //---------------------------------------------------------------------------
  3741. void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
  3742. {
  3743. int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
  3744. TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
  3745. if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
  3746. {
  3747. if (Command == _APPCOMMAND_BROWSER_FAVORITES)
  3748. {
  3749. OpenDirectory(GetSide(osCurrent));
  3750. Message.Result = 1;
  3751. }
  3752. else
  3753. {
  3754. TForm::Dispatch(&Message);
  3755. }
  3756. }
  3757. else
  3758. {
  3759. TForm::Dispatch(&Message);
  3760. }
  3761. }
  3762. //---------------------------------------------------------------------------
  3763. void __fastcall TCustomScpExplorerForm::CMAppSysCommand(TMessage & Message)
  3764. {
  3765. TWMSysCommand * SysCommand = (TWMSysCommand *)Message.LParam;
  3766. if (SysCommand->CmdType != SC_KEYMENU || !FIgnoreNextSysCommand)
  3767. {
  3768. FIgnoreNextSysCommand = false;
  3769. TForm::Dispatch(&Message);
  3770. }
  3771. else
  3772. {
  3773. Message.Result = 1;
  3774. }
  3775. }
  3776. //---------------------------------------------------------------------------
  3777. void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
  3778. {
  3779. // The four low-order bits are used internally by Windows
  3780. unsigned int Cmd = (Message.WParam & 0xFFF0);
  3781. // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
  3782. // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
  3783. // 61730 - restore thru double click - undocumented
  3784. // 61490 - maximize thru double click - undocumented
  3785. if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
  3786. (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
  3787. {
  3788. SysResizing(Cmd);
  3789. }
  3790. TForm::Dispatch(&Message);
  3791. }
  3792. //---------------------------------------------------------------------------
  3793. void __fastcall TCustomScpExplorerForm::WMWindowPosChanging(TWMWindowPosMsg & Message)
  3794. {
  3795. // MSVDM (not sure is it is generic feature) sets size of all windows
  3796. // to iconic and moves top-level windows (with destop as parent) out
  3797. // of the screen (-32000:-32000). However other windows (such as
  3798. // VCL main window with hidden parent) are moved just above
  3799. // the task bar. Override this.
  3800. if (FLAGCLEAR(Message.WindowPos->flags, SWP_NOMOVE) &&
  3801. (Message.WindowPos->cx == GetSystemMetrics(SM_CXMINIMIZED)) &&
  3802. (Message.WindowPos->cy == GetSystemMetrics(SM_CYMINIMIZED)))
  3803. {
  3804. Message.WindowPos->x = OutPos;
  3805. Message.WindowPos->y = OutPos;
  3806. }
  3807. TForm::Dispatch(&Message);
  3808. }
  3809. //---------------------------------------------------------------------------
  3810. void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
  3811. {
  3812. }
  3813. //---------------------------------------------------------------------------
  3814. void __fastcall TCustomScpExplorerForm::DoShow()
  3815. {
  3816. // only now are the controls resized finally, so the size constraints
  3817. // will not conflict with possibly very small window size
  3818. RestoreFormParams();
  3819. FixControlsPlacement();
  3820. if (Position == poDefaultPosOnly)
  3821. {
  3822. CutFormToDesktop(this);
  3823. }
  3824. TForm::DoShow();
  3825. }
  3826. //---------------------------------------------------------------------------
  3827. void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
  3828. const AnsiString & Str, TQueryType Type, Exception * E, unsigned int Seconds)
  3829. {
  3830. if (WinConfiguration->BalloonNotifications &&
  3831. (dynamic_cast<EAbort*>(E) == NULL))
  3832. {
  3833. AnsiString Message;
  3834. if (E == NULL)
  3835. {
  3836. Message = Str;
  3837. }
  3838. else
  3839. {
  3840. assert(Str.IsEmpty());
  3841. Message = E->Message;
  3842. }
  3843. if (!Message.IsEmpty())
  3844. {
  3845. const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
  3846. &_SMsgDlgError, &_SMsgDlgInformation, NULL };
  3847. AnsiString Title = LoadResourceString(Captions[Type]);
  3848. if (Terminal != NULL)
  3849. {
  3850. Title = FORMAT("%s - %s",
  3851. (TTerminalManager::Instance()->TerminalTitle(Terminal), Title));
  3852. }
  3853. if (Seconds == 0)
  3854. {
  3855. Seconds = WinConfiguration->NotificationsTimeout;
  3856. }
  3857. FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * 1000);
  3858. }
  3859. }
  3860. }
  3861. //---------------------------------------------------------------------------
  3862. int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const AnsiString Message,
  3863. TStrings * MoreMessages, TQueryType Type, int Answers,
  3864. AnsiString HelpKeyword, const TMessageParams * Params,
  3865. TTerminal * Terminal)
  3866. {
  3867. if (WinConfiguration->ContinueOnError &&
  3868. (Params != NULL) && (Params->Params & mpAllowContinueOnError) &&
  3869. FErrorList)
  3870. {
  3871. TStringList * MoreMessagesCopy = NULL;
  3872. if (MoreMessages)
  3873. {
  3874. MoreMessagesCopy = new TStringList();
  3875. MoreMessagesCopy->Assign(MoreMessages);
  3876. }
  3877. FErrorList->AddObject(Message, MoreMessagesCopy);
  3878. if (Answers & qaSkip) return qaSkip;
  3879. else
  3880. if (Answers & qaIgnore) return qaIgnore;
  3881. else
  3882. if (Answers & qaOK) return qaOK;
  3883. else
  3884. if (Answers & qaYes) return qaYes;
  3885. else
  3886. if (Answers & qaRetry) return qaRetry;
  3887. else
  3888. {
  3889. assert(false);
  3890. return qaYes;
  3891. }
  3892. }
  3893. else
  3894. {
  3895. if (FTrayIcon->Visible)
  3896. {
  3897. PopupTrayBalloon(Terminal, Message, Type);
  3898. }
  3899. int Result;
  3900. try
  3901. {
  3902. Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
  3903. }
  3904. __finally
  3905. {
  3906. FTrayIcon->CancelBalloon();
  3907. }
  3908. return Result;
  3909. }
  3910. }
  3911. //---------------------------------------------------------------------------
  3912. void __fastcall TCustomScpExplorerForm::ShowExtendedException(
  3913. TTerminal * Terminal, Exception * E)
  3914. {
  3915. if (FTrayIcon->Visible)
  3916. {
  3917. PopupTrayBalloon(Terminal, "", qtError, E);
  3918. }
  3919. try
  3920. {
  3921. ShowExtendedExceptionEx(Terminal, E);
  3922. }
  3923. __finally
  3924. {
  3925. FTrayIcon->CancelBalloon();
  3926. }
  3927. }
  3928. //---------------------------------------------------------------------------
  3929. void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
  3930. TTerminal * Terminal, Exception * E)
  3931. {
  3932. Notify(Terminal, "", qtError, false, NULL, E);
  3933. }
  3934. //---------------------------------------------------------------------------
  3935. void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
  3936. AnsiString Message, TQueryType Type,
  3937. bool Important, TNotifyEvent OnClick, Exception * E)
  3938. {
  3939. if (dynamic_cast<EAbort*>(E) == NULL)
  3940. {
  3941. unsigned int Seconds = WinConfiguration->NotificationsTimeout;
  3942. if (Important)
  3943. {
  3944. Seconds *= 5;
  3945. }
  3946. if (E != NULL)
  3947. {
  3948. assert(Message.IsEmpty());
  3949. Message = E->Message;
  3950. }
  3951. AnsiString NoteMessage(Message);
  3952. if (Terminal != NULL)
  3953. {
  3954. NoteMessage = FORMAT("%s: %s",
  3955. (TTerminalManager::Instance()->TerminalTitle(Terminal), NoteMessage));
  3956. }
  3957. if (WinConfiguration->BalloonNotifications &&
  3958. TTrayIcon::SupportsBalloons())
  3959. {
  3960. AddNote(NoteMessage);
  3961. PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds);
  3962. }
  3963. else
  3964. {
  3965. FlashOnBackground();
  3966. PostNote(NoteMessage, Seconds, OnClick, NULL);
  3967. }
  3968. }
  3969. }
  3970. //---------------------------------------------------------------------------
  3971. void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
  3972. TTerminalQueue * /*Queue*/, TQueueEvent Event)
  3973. {
  3974. AnsiString Message;
  3975. switch (Event)
  3976. {
  3977. case qeEmpty:
  3978. if ((ATerminal != Terminal) || !ComponentVisible[fcQueueView])
  3979. {
  3980. Message = LoadStr(BALLOON_QUEUE_EMPTY);
  3981. }
  3982. break;
  3983. case qePendingUserAction:
  3984. if ((ATerminal != Terminal) ||
  3985. (!ComponentVisible[fcQueueView] && !GUIConfiguration->QueueAutoPopup))
  3986. {
  3987. Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
  3988. }
  3989. break;
  3990. default:
  3991. assert(false);
  3992. }
  3993. if (!Message.IsEmpty())
  3994. {
  3995. Notify(ATerminal, Message, qtInformation);
  3996. }
  3997. }
  3998. //---------------------------------------------------------------------------
  3999. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
  4000. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  4001. {
  4002. if (FDDExtMapFile != NULL)
  4003. {
  4004. CloseHandle(FDDExtMapFile);
  4005. FDDExtMapFile = NULL;
  4006. }
  4007. if (WinConfiguration->DDExtEnabled)
  4008. {
  4009. if (!WinConfiguration->DDExtInstalled)
  4010. {
  4011. throw Exception(LoadStr(DRAGEXT_TARGET_NOT_INSTALLED));
  4012. }
  4013. DDExtInitDrag(FileList, Created);
  4014. }
  4015. }
  4016. //---------------------------------------------------------------------------
  4017. void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
  4018. bool & Created)
  4019. {
  4020. FDragExtFakeDirectory =
  4021. ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
  4022. if (!ForceDirectories(FDragExtFakeDirectory))
  4023. {
  4024. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragExtFakeDirectory)));
  4025. }
  4026. FileList->AddItem(NULL, FDragExtFakeDirectory);
  4027. Created = true;
  4028. FDDExtMapFile = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  4029. 0, sizeof(TDragExtCommStruct), DRAG_EXT_MAPPING);
  4030. {
  4031. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  4032. TDragExtCommStruct* CommStruct;
  4033. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  4034. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  4035. assert(CommStruct != NULL);
  4036. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  4037. CommStruct->Dragging = true;
  4038. strncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
  4039. sizeof(CommStruct->DropDest));
  4040. CommStruct->DropDest[sizeof(CommStruct->DropDest) - 1] = '\0';
  4041. UnmapViewOfFile(CommStruct);
  4042. }
  4043. FDDMoveSlipped = false;
  4044. }
  4045. //---------------------------------------------------------------------------
  4046. void __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
  4047. TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
  4048. {
  4049. if (Sender == RemoteDirView)
  4050. {
  4051. ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
  4052. }
  4053. else
  4054. {
  4055. assert(Sender == RemoteDriveView);
  4056. TStrings * FileList = RemoteDriveView->DragFileList();
  4057. try
  4058. {
  4059. ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
  4060. }
  4061. __finally
  4062. {
  4063. delete FileList;
  4064. }
  4065. }
  4066. if (FDDTargetControl == RemoteDriveView)
  4067. {
  4068. RemoteDriveView->UpdateDropTarget();
  4069. }
  4070. // foRemoteMove happens when file/dir is dragged within the remote tree view
  4071. // or from tree view to dir view.
  4072. // foMove happens when file/dir is dragged from remote tree view outside of
  4073. // application via dragex
  4074. if (((Operation == foRemoteMove) || (Operation == foMove)) &&
  4075. (DropSourceControl == RemoteDriveView))
  4076. {
  4077. RemoteDriveView->UpdateDropSource();
  4078. }
  4079. }
  4080. //---------------------------------------------------------------------------
  4081. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
  4082. {
  4083. SAFE_DESTROY(FDDFileList);
  4084. if (FDDExtMapFile != NULL)
  4085. {
  4086. try
  4087. {
  4088. TDragResult DDResult = (Sender == RemoteDirView) ?
  4089. RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
  4090. if ((DDResult == drCopy) || (DDResult == drMove))
  4091. {
  4092. AnsiString TargetDirectory;
  4093. TFileOperation Operation;
  4094. Operation = (DDResult == drMove) ? foMove : foCopy;
  4095. if (FDDMoveSlipped)
  4096. {
  4097. Operation = foMove;
  4098. }
  4099. TTransferOperationParam Param;
  4100. DDGetTarget(Param.TargetDirectory);
  4101. // download using ddext
  4102. Param.Temp = false;
  4103. Param.DragDrop = true;
  4104. RemoteFileControlFileOperation(Sender, Operation,
  4105. !WinConfiguration->DDTransferConfirmation, &Param);
  4106. }
  4107. }
  4108. __finally
  4109. {
  4110. CloseHandle(FDDExtMapFile);
  4111. FDDExtMapFile = NULL;
  4112. RemoveDir(FDragExtFakeDirectory);
  4113. FDragExtFakeDirectory = "";
  4114. }
  4115. }
  4116. if (!FDragDropSshTerminate.IsEmpty())
  4117. {
  4118. throw ESshTerminate(NULL, FDragDropSshTerminate);
  4119. }
  4120. }
  4121. //---------------------------------------------------------------------------
  4122. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
  4123. TObject * Sender, int dwEffect, HRESULT & /*Result*/)
  4124. {
  4125. HCURSOR SlippedCopyCursor;
  4126. FDDMoveSlipped =
  4127. (FDragMoveCursor != NULL) &&
  4128. (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
  4129. ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0) &&
  4130. FTerminal->IsCapable[fcRemoteMove]) ||
  4131. (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
  4132. SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
  4133. DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
  4134. DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
  4135. // Remember drop effect so we know (when user dropes files), if we copy or move
  4136. FLastDropEffect = dwEffect;
  4137. }
  4138. //---------------------------------------------------------------------------
  4139. void __fastcall TCustomScpExplorerForm::DDGetTarget(AnsiString & Directory)
  4140. {
  4141. bool Result = false;
  4142. Enabled = false;
  4143. try
  4144. {
  4145. int Timer = 0;
  4146. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  4147. {
  4148. {
  4149. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  4150. TDragExtCommStruct* CommStruct;
  4151. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  4152. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  4153. assert(CommStruct != NULL);
  4154. Result = !CommStruct->Dragging;
  4155. if (Result)
  4156. {
  4157. Directory = ExtractFilePath(CommStruct->DropDest);
  4158. }
  4159. UnmapViewOfFile(CommStruct);
  4160. }
  4161. if (!Result)
  4162. {
  4163. Sleep(50);
  4164. Timer += 50;
  4165. Application->ProcessMessages();
  4166. }
  4167. }
  4168. }
  4169. __finally
  4170. {
  4171. Enabled = true;
  4172. }
  4173. if (!Result)
  4174. {
  4175. throw Exception(LoadStr(DRAGEXT_TARGET_UNKNOWN));
  4176. }
  4177. }
  4178. //---------------------------------------------------------------------------
  4179. void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
  4180. const AnsiString TempDir, int SecDelay)
  4181. {
  4182. TDateTime Alarm = Now() + (double)SecDelay*(double(1)/24/60/60);
  4183. FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
  4184. if (FDelayedDeletionTimer == NULL)
  4185. {
  4186. assert(HandleAllocated());
  4187. FDelayedDeletionTimer = new TTimer(this);
  4188. FDelayedDeletionTimer->Interval = 10000;
  4189. FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
  4190. }
  4191. else
  4192. {
  4193. FDelayedDeletionTimer->Enabled = true;
  4194. }
  4195. }
  4196. //---------------------------------------------------------------------------
  4197. void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
  4198. {
  4199. assert(FDelayedDeletionList != NULL);
  4200. TDateTime N = Now();
  4201. TDateTime Alert;
  4202. AnsiString Directory;
  4203. for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
  4204. {
  4205. Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
  4206. if ((N >= Alert) || (Sender == NULL))
  4207. {
  4208. Directory = FDelayedDeletionList->Strings[Index];
  4209. if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
  4210. {
  4211. FDelayedDeletionList->Delete(Index);
  4212. }
  4213. }
  4214. }
  4215. if (FDelayedDeletionList->Count == 0)
  4216. {
  4217. FDelayedDeletionTimer->Enabled = false;
  4218. }
  4219. }
  4220. //---------------------------------------------------------------------------
  4221. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
  4222. {
  4223. if (IsFileControl(FDDTargetControl, osRemote))
  4224. {
  4225. TTransferOperationParam Param;
  4226. Param.DragDrop = true;
  4227. // when move from remote side is disabled, we allow coying inside the remote
  4228. // panel, but we interpret is as moving (we also slip in the move cursor)
  4229. if ((FLastDropEffect == DROPEFFECT_MOVE) ||
  4230. (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
  4231. FDDMoveSlipped))
  4232. {
  4233. RemoteFileControlFileOperation(DropSourceControl,
  4234. foRemoteMove, !WinConfiguration->DDTransferConfirmation, &Param);
  4235. }
  4236. else if (FLastDropEffect == DROPEFFECT_COPY)
  4237. {
  4238. RemoteFileControlFileOperation(DropSourceControl,
  4239. foRemoteCopy, !WinConfiguration->DDTransferConfirmation, &Param);
  4240. }
  4241. // abort drag&drop
  4242. Abort();
  4243. }
  4244. else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE))
  4245. {
  4246. assert(!FDragTempDir.IsEmpty());
  4247. TTransferType Type;
  4248. AnsiString TempDir = FDragTempDir;
  4249. // We clear FDragTempDir before calling
  4250. // just in case it fail (raises exception)
  4251. FDragTempDir = "";
  4252. Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
  4253. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  4254. // empty directory parameter means temp directory -> don't display it!
  4255. AnsiString TargetDir = "";
  4256. if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
  4257. TargetDir, CopyParams, WinConfiguration->DDTransferConfirmation, true))
  4258. {
  4259. Abort();
  4260. }
  4261. // TargetDir is set when dropped on local file control
  4262. // (this was workaround for legacy dirview event handling, now it should be
  4263. // made prettier)
  4264. if (TargetDir.IsEmpty())
  4265. {
  4266. TargetDir = TempDir;
  4267. if (ForceDirectories(TargetDir))
  4268. {
  4269. assert(Terminal && !TargetDir.IsEmpty());
  4270. // do not attempt to warn unless we know total transfer size
  4271. FPendingTempSpaceWarn = CopyParams.CalculateSize;
  4272. try
  4273. {
  4274. FDragDropOperation = true;
  4275. // cpNewerOnly has no efect here,
  4276. // as we download to empty temp directory
  4277. int Params = cpTemporary |
  4278. (Type == ttMove ? cpDelete : 0);
  4279. DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
  4280. }
  4281. __finally
  4282. {
  4283. FDragDropOperation = false;
  4284. FPendingTempSpaceWarn = false;
  4285. AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
  4286. }
  4287. }
  4288. else
  4289. {
  4290. throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
  4291. }
  4292. }
  4293. }
  4294. }
  4295. //---------------------------------------------------------------------------
  4296. void __fastcall TCustomScpExplorerForm::DDDownload(TStrings * FilesToCopy,
  4297. const AnsiString TargetDir, const TCopyParamType * CopyParam, int Params)
  4298. {
  4299. Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params);
  4300. if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
  4301. {
  4302. RemoteDriveView->UpdateDropSource();
  4303. }
  4304. }
  4305. //---------------------------------------------------------------------------
  4306. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  4307. {
  4308. public:
  4309. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  4310. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  4311. {
  4312. }
  4313. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  4314. {
  4315. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  4316. TDataObjectFilesEx::AllowData(FormatEtc);
  4317. }
  4318. };
  4319. //---------------------------------------------------------------------------
  4320. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
  4321. TObject * Sender, TDataObject *& DataObject)
  4322. {
  4323. if (FDDExtMapFile != NULL)
  4324. {
  4325. TFileList * FileList = DragDropFiles(Sender)->FileList;
  4326. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  4327. {
  4328. Abort();
  4329. }
  4330. if (FileList->Count > 0)
  4331. {
  4332. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  4333. if (!FilesObject->IsValid(true, true))
  4334. {
  4335. FilesObject->_Release();
  4336. }
  4337. else
  4338. {
  4339. DataObject = FilesObject;
  4340. }
  4341. }
  4342. }
  4343. }
  4344. //---------------------------------------------------------------------------
  4345. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  4346. {
  4347. assert(false);
  4348. }
  4349. //---------------------------------------------------------------------------
  4350. void __fastcall TCustomScpExplorerForm::GoToTree()
  4351. {
  4352. ComponentVisible[fcRemoteTree] = true;
  4353. RemoteDriveView->SetFocus();
  4354. }
  4355. //---------------------------------------------------------------------------
  4356. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  4357. TPanelExport Export, TPanelExportDestination Destination, bool OnFocused)
  4358. {
  4359. Side = GetSide(Side);
  4360. TCustomDirView * DirView = this->DirView(Side);
  4361. TStringList * ExportData = new TStringList();
  4362. try
  4363. {
  4364. switch (Export)
  4365. {
  4366. case pePath:
  4367. ExportData->Add(DirView->PathName);
  4368. break;
  4369. case peFileList:
  4370. case peFullFileList:
  4371. {
  4372. bool FullPath = (Export == peFullFileList);
  4373. DirView->CreateFileList(OnFocused, FullPath, ExportData);
  4374. AnsiString FileName;
  4375. for (int Index = 0; Index < ExportData->Count; Index++)
  4376. {
  4377. if (ExportData->Strings[Index].Pos(" ") > 0)
  4378. {
  4379. ExportData->Strings[Index] = FORMAT("\"%s\"", (ExportData->Strings[Index]));
  4380. }
  4381. }
  4382. }
  4383. break;
  4384. case peUrl:
  4385. {
  4386. assert(DirView == RemoteDirView);
  4387. DirView->CreateFileList(OnFocused, true, ExportData);
  4388. for (int Index = 0; Index < ExportData->Count; Index++)
  4389. {
  4390. ExportData->Strings[Index] =
  4391. FTerminal->FileUrl(ExportData->Strings[Index]);
  4392. }
  4393. }
  4394. break;
  4395. default:
  4396. assert(false);
  4397. }
  4398. PanelExportStore(Side, Export, Destination, ExportData);
  4399. }
  4400. __finally
  4401. {
  4402. delete ExportData;
  4403. }
  4404. }
  4405. //---------------------------------------------------------------------------
  4406. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  4407. TPanelExport /*Export*/, TPanelExportDestination Destination,
  4408. TStringList * ExportData)
  4409. {
  4410. if (Destination == pedClipboard)
  4411. {
  4412. CopyToClipboard(ExportData);
  4413. }
  4414. else
  4415. {
  4416. assert(false);
  4417. }
  4418. }
  4419. //---------------------------------------------------------------------------
  4420. TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
  4421. {
  4422. return FQueueController->DefaultOperation();
  4423. }
  4424. //---------------------------------------------------------------------------
  4425. bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
  4426. TQueueOperation Operation)
  4427. {
  4428. switch (Operation)
  4429. {
  4430. case qoPreferences:
  4431. return true;
  4432. case qoGoTo:
  4433. return ComponentVisible[fcQueueView];
  4434. case qoDisconnectOnceEmpty:
  4435. return !FQueueController->Empty;
  4436. default:
  4437. return FQueueController->AllowOperation(Operation);
  4438. }
  4439. }
  4440. //---------------------------------------------------------------------------
  4441. void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
  4442. TQueueOperation Operation)
  4443. {
  4444. if (Operation == qoGoTo)
  4445. {
  4446. assert(QueueView->Visible);
  4447. QueueView->SetFocus();
  4448. }
  4449. else if (Operation == qoPreferences)
  4450. {
  4451. PreferencesDialog(pmQueue);
  4452. }
  4453. else
  4454. {
  4455. FQueueController->ExecuteOperation(Operation);
  4456. }
  4457. }
  4458. //---------------------------------------------------------------------------
  4459. void __fastcall TCustomScpExplorerForm::QueueViewContextPopup(
  4460. TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
  4461. {
  4462. FQueueActedItem = QueueView->ItemFocused;
  4463. }
  4464. //---------------------------------------------------------------------------
  4465. /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
  4466. {
  4467. return TopDock->Height + QueueSplitter->Height;
  4468. }
  4469. //---------------------------------------------------------------------------
  4470. void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
  4471. TObject * /*Sender*/, int & NewSize, bool & Accept)
  4472. {
  4473. // when queue is hidden by double-clicking splitter, stray attempt to
  4474. // resize the panel with strange value arrives, make sure it is ignored
  4475. if (ComponentVisible[fcQueueView])
  4476. {
  4477. int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
  4478. RemotePanel->Constraints->MinHeight;
  4479. if (NewSize > HeightLimit)
  4480. {
  4481. NewSize = HeightLimit;
  4482. }
  4483. }
  4484. else
  4485. {
  4486. Accept = false;
  4487. }
  4488. }
  4489. //---------------------------------------------------------------------------
  4490. void __fastcall TCustomScpExplorerForm::QueueViewStartDrag(TObject * /*Sender*/,
  4491. TDragObject *& /*DragObject*/)
  4492. {
  4493. FQueueActedItem = QueueView->ItemFocused;
  4494. }
  4495. //---------------------------------------------------------------------------
  4496. void __fastcall TCustomScpExplorerForm::QueueViewDragOver(TObject * /*Sender*/,
  4497. TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
  4498. {
  4499. Accept = true;
  4500. if (Source == QueueView)
  4501. {
  4502. TListItem * DropTarget = QueueView->GetItemAt(X, Y);
  4503. Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
  4504. if (Accept)
  4505. {
  4506. TQueueItemProxy * QueueItem;
  4507. TQueueItemProxy * DestQueueItem;
  4508. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  4509. DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
  4510. Accept = (QueueItem != DestQueueItem) &&
  4511. (QueueItem->Status == TQueueItem::qsPending) &&
  4512. (DestQueueItem->Status == TQueueItem::qsPending);
  4513. }
  4514. }
  4515. }
  4516. //---------------------------------------------------------------------------
  4517. void __fastcall TCustomScpExplorerForm::QueueViewDragDrop(TObject * /*Sender*/,
  4518. TObject * /*Source*/, int /*X*/, int /*Y*/)
  4519. {
  4520. if ((FQueueActedItem != NULL) && (QueueView->DropTarget != NULL))
  4521. {
  4522. TQueueItemProxy * QueueItem;
  4523. TQueueItemProxy * DestQueueItem;
  4524. QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
  4525. DestQueueItem = static_cast<TQueueItemProxy *>(QueueView->DropTarget->Data);
  4526. QueueItem->Move(DestQueueItem);
  4527. }
  4528. }
  4529. //---------------------------------------------------------------------------
  4530. void __fastcall TCustomScpExplorerForm::QueueViewEnter(TObject * /*Sender*/)
  4531. {
  4532. if ((QueueView->ItemFocused == NULL) &&
  4533. (QueueView->Items->Count > 0))
  4534. {
  4535. QueueView->ItemFocused = QueueView->Items->Item[0];
  4536. }
  4537. }
  4538. //---------------------------------------------------------------------------
  4539. void __fastcall TCustomScpExplorerForm::QueueViewSelectItem(
  4540. TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
  4541. {
  4542. if (Selected)
  4543. {
  4544. NonVisualDataModule->UpdateNonVisibleActions();
  4545. }
  4546. }
  4547. //---------------------------------------------------------------------------
  4548. TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
  4549. {
  4550. TDragDropFilesEx * Result = NULL;
  4551. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  4552. if (DirView != NULL)
  4553. {
  4554. Result = DirView->DragDropFilesEx;
  4555. }
  4556. else
  4557. {
  4558. TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
  4559. if (DriveView != NULL)
  4560. {
  4561. Result = DriveView->DragDropFilesEx;
  4562. }
  4563. }
  4564. assert(Result != NULL);
  4565. return Result;
  4566. }
  4567. //---------------------------------------------------------------------------
  4568. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
  4569. TObject * Sender, int Effect, AnsiString /*SourcePath*/,
  4570. AnsiString TargetPath, bool & /*DoOperation*/)
  4571. {
  4572. TFileOperation Operation;
  4573. switch (Effect)
  4574. {
  4575. case DROPEFFECT_MOVE:
  4576. Operation = foMove;
  4577. break;
  4578. case DROPEFFECT_COPY:
  4579. // occures on WinXP (reported by user)
  4580. default:
  4581. Operation = foCopy;
  4582. break;
  4583. };
  4584. TStrings * FileList = new TStringList();
  4585. try
  4586. {
  4587. TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
  4588. for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
  4589. {
  4590. FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
  4591. }
  4592. FDragDropOperation = true;
  4593. TTransferOperationParam Param;
  4594. Param.TargetDirectory = TargetPath;
  4595. // upload, no temp dirs
  4596. Param.Temp = false;
  4597. Param.DragDrop = true;
  4598. ExecuteFileOperation(Operation, osLocal, FileList,
  4599. !WinConfiguration->DDTransferConfirmation, &Param);
  4600. }
  4601. __finally
  4602. {
  4603. FDragDropOperation = false;
  4604. delete FileList;
  4605. }
  4606. }
  4607. //---------------------------------------------------------------------------
  4608. void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
  4609. TObject * Sender, int grfKeyState, int & dwEffect)
  4610. {
  4611. // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
  4612. if ((dwEffect != DROPEFFECT_None) &&
  4613. IsFileControl(DropSourceControl, osRemote))
  4614. {
  4615. // do not allow drop on remote panel (on free space, still allow drop on directories)
  4616. if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
  4617. (RemoteDirView->DropTarget == NULL))
  4618. {
  4619. dwEffect = DROPEFFECT_None;
  4620. }
  4621. else
  4622. {
  4623. if (dwEffect == DROPEFFECT_Copy)
  4624. {
  4625. bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
  4626. bool CopyCapable = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
  4627. // if we do not support neither of operations, there's no discussion
  4628. if (!MoveCapable && !CopyCapable)
  4629. {
  4630. dwEffect = DROPEFFECT_None;
  4631. }
  4632. // when moving is disabled, we need to keep effect to "copy",
  4633. // which will be later interpretted as move (with slipped-in cursor)
  4634. else if (!WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL))
  4635. {
  4636. // no-op, keep copy
  4637. }
  4638. else
  4639. {
  4640. // The default effect inside remote panel is move,
  4641. // unless we do not support it, but support copy
  4642. if (FLAGCLEAR(grfKeyState, MK_CONTROL))
  4643. {
  4644. dwEffect = MoveCapable ? DROPEFFECT_Move : DROPEFFECT_Copy;
  4645. }
  4646. else
  4647. {
  4648. // with ctrl-down, we want copy unless it is not supported
  4649. dwEffect = CopyCapable ? DROPEFFECT_Copy : DROPEFFECT_None;
  4650. }
  4651. }
  4652. }
  4653. }
  4654. }
  4655. }
  4656. //---------------------------------------------------------------------------
  4657. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
  4658. TObject * Sender, TRemoteFile * File, AnsiString & FileName)
  4659. {
  4660. if (FDDTotalSize >= 0)
  4661. {
  4662. if (File->IsDirectory)
  4663. {
  4664. FDDTotalSize = -1;
  4665. }
  4666. else
  4667. {
  4668. FDDTotalSize += File->Size;
  4669. }
  4670. }
  4671. assert(!FDragTempDir.IsEmpty());
  4672. // TODO: this is quite ineffective
  4673. // TODO: what if invalid character replacement is disabled?
  4674. FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
  4675. AnsiString TransferFileName;
  4676. if (Sender == RemoteDriveView)
  4677. {
  4678. TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
  4679. }
  4680. else
  4681. {
  4682. TransferFileName = File->FileName;
  4683. }
  4684. FDDFileList->AddObject(TransferFileName, File);
  4685. }
  4686. //---------------------------------------------------------------------------
  4687. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
  4688. TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
  4689. const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
  4690. {
  4691. FDDFileList = new TStringList();
  4692. FDragTempDir = WinConfiguration->TemporaryDir();
  4693. FDDTotalSize = 0;
  4694. FDragDropSshTerminate = "";
  4695. }
  4696. //---------------------------------------------------------------------------
  4697. void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
  4698. TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
  4699. HRESULT & Result)
  4700. {
  4701. if (Result == DRAGDROP_S_DROP)
  4702. {
  4703. try
  4704. {
  4705. GlobalDragImageList->HideDragImage();
  4706. try
  4707. {
  4708. RemoteFileControlDDTargetDrop();
  4709. }
  4710. catch(ESshTerminate & E)
  4711. {
  4712. assert(E.MoreMessages == NULL); // not supported
  4713. assert(!E.Message.IsEmpty());
  4714. FDragDropSshTerminate = E.Message;
  4715. }
  4716. }
  4717. catch (Exception &E)
  4718. {
  4719. // If downloading fails we need to cancel drag&drop, othwerwise
  4720. // Explorer shows error
  4721. // But by the way exception probably never reach this point as
  4722. // it's catched on way
  4723. Result = DRAGDROP_S_CANCEL;
  4724. assert(Terminal != NULL);
  4725. Terminal->ShowExtendedException(&E);
  4726. }
  4727. }
  4728. }
  4729. //---------------------------------------------------------------------------
  4730. void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
  4731. TObject * /*Sender*/, AnsiString FileName, bool Directory, __int64 Size,
  4732. AnsiString Masks,bool & Matches)
  4733. {
  4734. TFileMasks::TParams MaskParams;
  4735. MaskParams.Size = Size;
  4736. TFileMasks M(Masks);
  4737. Matches = M.Matches(FileName, Directory, AnsiString(""), &MaskParams);
  4738. }
  4739. //---------------------------------------------------------------------------
  4740. void __fastcall TCustomScpExplorerForm::RemoteDirViewGetOverlay(
  4741. TObject * Sender, TListItem * Item, WORD & Indexes)
  4742. {
  4743. TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
  4744. AnsiString Ext;
  4745. if (DirView == RemoteDirView)
  4746. {
  4747. Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
  4748. }
  4749. else
  4750. {
  4751. Ext = ExtractFileExt(DirView->ItemFileName(Item));
  4752. }
  4753. if (SameText(Ext, Configuration->PartialExt))
  4754. {
  4755. Indexes |= oiPartial;
  4756. }
  4757. }
  4758. //---------------------------------------------------------------------------
  4759. bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
  4760. {
  4761. return
  4762. IsFormatInClipboard(CF_TEXT) ||
  4763. DirView(osCurrent)->CanPasteFromClipBoard();
  4764. }
  4765. //---------------------------------------------------------------------------
  4766. void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
  4767. {
  4768. if (DirView(osCurrent)->CanPasteFromClipBoard())
  4769. {
  4770. DirView(osCurrent)->PasteFromClipBoard();
  4771. }
  4772. else
  4773. {
  4774. AnsiString Path;
  4775. if (TextFromClipboard(Path) && !Path.IsEmpty())
  4776. {
  4777. DirView(osCurrent)->Path = Path;
  4778. }
  4779. }
  4780. }
  4781. //---------------------------------------------------------------------------
  4782. void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
  4783. {
  4784. // TBD
  4785. }
  4786. //---------------------------------------------------------------------------
  4787. AnsiString __fastcall TCustomScpExplorerForm::FileStatusBarText(
  4788. const TStatusFileInfo & FileInfo)
  4789. {
  4790. return
  4791. FMTLOAD(FILE_INFO_FORMAT,
  4792. (FormatBytes(FileInfo.SelectedSize),
  4793. FormatBytes(FileInfo.FilesSize),
  4794. FormatFloat("#,##0", FileInfo.SelectedCount),
  4795. FormatFloat("#,##0", FileInfo.FilesCount)));
  4796. }
  4797. //---------------------------------------------------------------------------
  4798. void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
  4799. TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, int Panel)
  4800. {
  4801. AnsiString Text = FileStatusBarText(FileInfo);
  4802. if (StatusBar->SimplePanel)
  4803. {
  4804. assert(Panel == 0);
  4805. StatusBar->SimpleText = Text;
  4806. }
  4807. else
  4808. {
  4809. StatusBar->Panels->Items[Panel]->Caption = Text;
  4810. }
  4811. }
  4812. //---------------------------------------------------------------------------
  4813. void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
  4814. TObject * /*Sender*/)
  4815. {
  4816. RemoteDirView->SetFocus();
  4817. }
  4818. //---------------------------------------------------------------------------
  4819. void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
  4820. {
  4821. TQueueViewConfiguration Config = WinConfiguration->QueueView;
  4822. switch (Config.Show)
  4823. {
  4824. case qvShow:
  4825. if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
  4826. {
  4827. Config.Show = qvHide;
  4828. }
  4829. else
  4830. {
  4831. Config.Show = Config.LastHideShow;
  4832. }
  4833. break;
  4834. case qvHideWhenEmpty:
  4835. if (ComponentVisible[fcQueueView])
  4836. {
  4837. Config.Show = qvHide;
  4838. }
  4839. else
  4840. {
  4841. Config.LastHideShow = Config.Show;
  4842. Config.Show = qvShow;
  4843. }
  4844. break;
  4845. case qvHide:
  4846. Config.LastHideShow = Config.Show;
  4847. Config.Show = qvShow;
  4848. break;
  4849. }
  4850. WinConfiguration->QueueView = Config;
  4851. }
  4852. //---------------------------------------------------------------------------
  4853. AnsiString __fastcall TCustomScpExplorerForm::PathForCaption()
  4854. {
  4855. AnsiString Result;
  4856. if (FTerminal != NULL)
  4857. {
  4858. switch (WinConfiguration->PathInCaption)
  4859. {
  4860. case picShort:
  4861. {
  4862. Result = UnixExtractFileName(FTerminal->CurrentDirectory);
  4863. if (Result.IsEmpty())
  4864. {
  4865. Result = FTerminal->CurrentDirectory;
  4866. }
  4867. }
  4868. break;
  4869. case picFull:
  4870. Result = FTerminal->CurrentDirectory;
  4871. break;
  4872. }
  4873. }
  4874. return Result;
  4875. }
  4876. //---------------------------------------------------------------------------
  4877. void __fastcall TCustomScpExplorerForm::UpdateControls()
  4878. {
  4879. // beware that app title can contain progress indicator that we do not want to
  4880. // see in window title. we rely here on fact that this should be never called
  4881. // during operation
  4882. Caption = TTerminalManager::Instance()->UpdateAppTitle();
  4883. RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
  4884. RemoteDriveView->Color = RemoteDirView->Color;
  4885. }
  4886. //---------------------------------------------------------------------------
  4887. void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
  4888. {
  4889. UpdateControls();
  4890. }
  4891. //---------------------------------------------------------------------------
  4892. void __fastcall TCustomScpExplorerForm::DirViewLoaded(
  4893. TObject * Sender)
  4894. {
  4895. TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
  4896. assert(DirView != NULL);
  4897. DoDirViewLoaded(DirView);
  4898. TransferPresetAutoSelect();
  4899. }
  4900. //---------------------------------------------------------------------------
  4901. void __fastcall TCustomScpExplorerForm::StartUpdates()
  4902. {
  4903. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  4904. // first run after installation
  4905. if (double(Updates.LastCheck) == 0)
  4906. {
  4907. // make sure next time there will be an update (if enabled)
  4908. Updates.LastCheck = TDateTime(1);
  4909. WinConfiguration->Updates = Updates;
  4910. }
  4911. else if ((double(Updates.Period) > 0) &&
  4912. (Now() - Updates.LastCheck >= Updates.Period))
  4913. {
  4914. StartUpdateThread(UpdatesChecked);
  4915. }
  4916. }
  4917. //---------------------------------------------------------------------------
  4918. void __fastcall TCustomScpExplorerForm::UpdatesChecked()
  4919. {
  4920. AnsiString Message;
  4921. bool New;
  4922. TQueryType Type;
  4923. GetUpdatesMessage(Message, New, Type, false);
  4924. if (!Message.IsEmpty())
  4925. {
  4926. if (!New && (Type != qtWarning))
  4927. {
  4928. PostNote(Message, 0, UpdatesNoteClicked, NULL);
  4929. }
  4930. else
  4931. {
  4932. Notify(NULL, Message, Type, true, UpdatesNoteClicked);
  4933. }
  4934. }
  4935. }
  4936. //---------------------------------------------------------------------------
  4937. void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
  4938. {
  4939. CheckForUpdates(true);
  4940. }
  4941. //---------------------------------------------------------------------------
  4942. void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
  4943. TCopyParamRuleData & Data)
  4944. {
  4945. assert(Terminal != NULL);
  4946. Data.HostName = Terminal->SessionData->HostName;
  4947. Data.UserName = Terminal->SessionData->UserName;
  4948. Data.RemoteDirectory = RemoteDirView->PathName;
  4949. }
  4950. //---------------------------------------------------------------------------
  4951. void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
  4952. {
  4953. if (!FNoTransferPresetAutoSelect)
  4954. {
  4955. assert(Terminal != NULL);
  4956. TCopyParamRuleData Data;
  4957. GetTransferPresetAutoSelectData(Data);
  4958. int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
  4959. AnsiString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
  4960. if (CopyParamIndex < 0)
  4961. {
  4962. // there is no preset that matches autoselection
  4963. // set preset that we consider "default"
  4964. FCopyParamAutoSelected = ""; // forget last autoselected preset
  4965. GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
  4966. }
  4967. else
  4968. {
  4969. // there is preset matching autoselection
  4970. AnsiString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
  4971. if (CopyParamName == FCopyParamAutoSelected)
  4972. {
  4973. // autoselected the same preset as the last time
  4974. // make no change (i.e. preserve custom user preset, if any)
  4975. }
  4976. else
  4977. {
  4978. // autoselected the different preset then the last time (or there
  4979. // was default preset set)
  4980. FCopyParamAutoSelected = CopyParamName; // remember autoselection
  4981. GUIConfiguration->CopyParamCurrent = CopyParamName;
  4982. }
  4983. }
  4984. if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
  4985. {
  4986. TTransferPresetNoteData * Data = new TTransferPresetNoteData;
  4987. try
  4988. {
  4989. int Fmt =
  4990. (CopyParamIndex < 0) ?
  4991. (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
  4992. COPY_PARAM_AUTOSELECTED;
  4993. Data->Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
  4994. Data->More = new TStringList();
  4995. int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
  4996. AnsiString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr("\n",
  4997. CopyParamAttrs);
  4998. if (CopyParamIndex >= 0)
  4999. {
  5000. assert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
  5001. Info = FORMAT("%s\n \n%s", (Info,
  5002. FMTLOAD(COPY_PARAM_RULE,
  5003. (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr("\n")))));
  5004. }
  5005. Data->More->Text = Info;
  5006. if (WinConfiguration->CopyParamAutoSelectNotice)
  5007. {
  5008. TransferPresetNoteMessage(Data, true);
  5009. }
  5010. else
  5011. {
  5012. PostNote(Data->Message, 0, TransferPresetNoteClicked, Data);
  5013. Data = NULL; // ownership passed
  5014. }
  5015. }
  5016. __finally
  5017. {
  5018. delete Data;
  5019. }
  5020. }
  5021. }
  5022. }
  5023. //---------------------------------------------------------------------------
  5024. void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
  5025. TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
  5026. {
  5027. assert(NoteData != NULL);
  5028. TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
  5029. TQueryButtonAlias Aliases[1];
  5030. Aliases[0].Button = qaIgnore; // ignore" is after "ok"
  5031. Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
  5032. Params.Aliases = Aliases;
  5033. Params.AliasesCount = LENOF(Aliases);
  5034. int Result =
  5035. MoreMessageDialog(NoteData->Message, NoteData->More, qtInformation,
  5036. qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
  5037. switch (Result)
  5038. {
  5039. case qaNeverAskAgain:
  5040. assert(AllowNeverAskAgain);
  5041. WinConfiguration->CopyParamAutoSelectNotice = false;
  5042. break;
  5043. case qaIgnore:
  5044. PreferencesDialog(pmPresets);
  5045. break;
  5046. }
  5047. }
  5048. //---------------------------------------------------------------------------
  5049. void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * /*Sender*/)
  5050. {
  5051. TransferPresetNoteMessage(dynamic_cast<TTransferPresetNoteData *>(FNoteData), false);
  5052. }
  5053. //---------------------------------------------------------------------------
  5054. void __fastcall TCustomScpExplorerForm::PreferencesDialog(
  5055. TPreferencesMode APreferencesMode)
  5056. {
  5057. TCopyParamRuleData Data;
  5058. GetTransferPresetAutoSelectData(Data);
  5059. TPreferencesDialogData PreferencesData;
  5060. PreferencesData.CopyParamRuleData = &Data;
  5061. DoPreferencesDialog(APreferencesMode, &PreferencesData);
  5062. }
  5063. //---------------------------------------------------------------------------
  5064. void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
  5065. const AnsiString & Command, int Params)
  5066. {
  5067. if (CustomCommandState(Command, Params, FEditingFocusedAdHocCommand) <= 0)
  5068. {
  5069. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command)));
  5070. }
  5071. }
  5072. //---------------------------------------------------------------------------
  5073. void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
  5074. {
  5075. bool RemoteAllowed = CustomCommandRemoteAllowed();
  5076. TCustomCommandParam Param;
  5077. // make sure we use local custom command when remote are not supported
  5078. if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
  5079. {
  5080. Param = FLastCustomCommand;
  5081. }
  5082. else
  5083. {
  5084. Param.Params |= ccLocal;
  5085. }
  5086. Param.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
  5087. FEditingFocusedAdHocCommand = OnFocused;
  5088. int Options = FLAGMASK(!RemoteAllowed, ccoDisableRemote);
  5089. if (DoCustomCommandDialog(Param.Name, Param.Command, Param.Params,
  5090. WinConfiguration->CustomCommands, ccmAdHoc, Options,
  5091. AdHocCustomCommandValidate))
  5092. {
  5093. FLastCustomCommand = Param;
  5094. UpdateCustomCommandsToolbar();
  5095. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Param);
  5096. }
  5097. }
  5098. //---------------------------------------------------------------------------
  5099. void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
  5100. {
  5101. assert(!FLastCustomCommand.Command.IsEmpty());
  5102. int State = CustomCommandState(FLastCustomCommand.Command,
  5103. FLastCustomCommand.Params, OnFocused);
  5104. assert(State > 0);
  5105. if (State <= 0)
  5106. {
  5107. throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
  5108. }
  5109. ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
  5110. }
  5111. //---------------------------------------------------------------------------
  5112. bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
  5113. TCustomCommandParam & CustomCommand, int & State)
  5114. {
  5115. bool Result = !FLastCustomCommand.Command.IsEmpty();
  5116. if (Result)
  5117. {
  5118. CustomCommand = FLastCustomCommand;
  5119. State = CustomCommandState(FLastCustomCommand.Command,
  5120. FLastCustomCommand.Params, OnFocused);
  5121. }
  5122. return Result;
  5123. }
  5124. //---------------------------------------------------------------------------
  5125. void __fastcall TCustomScpExplorerForm::WhatsThis()
  5126. {
  5127. SendMessage(Handle, WM_SYSCOMMAND, SC_CONTEXTHELP, 0);
  5128. }
  5129. //---------------------------------------------------------------------------
  5130. void __fastcall TCustomScpExplorerForm::BeforeAction()
  5131. {
  5132. if (RemoteDirView->ItemFocused != NULL)
  5133. {
  5134. RemoteDirView->ItemFocused->CancelEdit();
  5135. }
  5136. }
  5137. //---------------------------------------------------------------------------
  5138. void __fastcall TCustomScpExplorerForm::PostComponentHide(unsigned short Component)
  5139. {
  5140. assert(ComponentVisible[Component]);
  5141. PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
  5142. }
  5143. //---------------------------------------------------------------------------
  5144. void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
  5145. {
  5146. // when queue panel is resized here directly, the status bar is stretched
  5147. // over whole space the panel occupied
  5148. PostComponentHide(fcQueueView);
  5149. }
  5150. //---------------------------------------------------------------------------
  5151. void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
  5152. {
  5153. TMessage * M = static_cast<TMessage*>(Message);
  5154. switch (M->Msg)
  5155. {
  5156. case CM_APPSYSCOMMAND:
  5157. CMAppSysCommand(*M);
  5158. break;
  5159. case _WM_APPCOMMAND:
  5160. WMAppCommand(*M);
  5161. break;
  5162. case WM_SYSCOMMAND:
  5163. WMSysCommand(*M);
  5164. break;
  5165. case WM_WINDOWPOSCHANGING:
  5166. WMWindowPosChanging(*reinterpret_cast<TWMWindowPosMsg *>(M));
  5167. break;
  5168. case WM_COMPONENT_HIDE:
  5169. {
  5170. unsigned short Component = static_cast<unsigned short>(M->WParam);
  5171. // sanity check
  5172. if (ComponentVisible[Component])
  5173. {
  5174. // special treatment
  5175. if (Component == fcQueueView)
  5176. {
  5177. ToggleQueueVisibility();
  5178. assert(!ComponentVisible[fcQueueView]);
  5179. }
  5180. else
  5181. {
  5182. ComponentVisible[Component] = false;
  5183. }
  5184. }
  5185. }
  5186. break;
  5187. default:
  5188. TForm::Dispatch(Message);
  5189. break;
  5190. }
  5191. }
  5192. //---------------------------------------------------------------------------
  5193. void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
  5194. TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
  5195. int & MaxHeight)
  5196. {
  5197. // workaround for bug in TWinControl.CalcConstraints
  5198. // Check for empty rect (restore from iconinc state) is done there only after
  5199. // call to AdjustClientRect, which enlarges the rect (for forms).
  5200. TRect R = GetClientRect();
  5201. // when restoring from iconic state, place no restrictions
  5202. if (IsRectEmpty(R))
  5203. {
  5204. MinWidth = 0;
  5205. MinHeight = 0;
  5206. MaxWidth = 0;
  5207. MaxHeight = 0;
  5208. }
  5209. }
  5210. //---------------------------------------------------------------------------
  5211. void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const AnsiString Path,
  5212. TSpaceAvailable & ASpaceAvailable, bool & Close)
  5213. {
  5214. // terminal can be already closed (e.g. dropped connection)
  5215. if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
  5216. {
  5217. try
  5218. {
  5219. Terminal->SpaceAvailable(Path, ASpaceAvailable);
  5220. }
  5221. catch(...)
  5222. {
  5223. if (!Terminal->Active)
  5224. {
  5225. Close = true;
  5226. }
  5227. throw;
  5228. }
  5229. }
  5230. }
  5231. //---------------------------------------------------------------------------
  5232. void __fastcall TCustomScpExplorerForm::FileSystemInfo()
  5233. {
  5234. const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
  5235. const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
  5236. TGetSpaceAvailable OnGetSpaceAvailable = NULL;
  5237. if (Terminal->IsCapable[fcCheckingSpaceAvailable])
  5238. {
  5239. OnGetSpaceAvailable = GetSpaceAvailable;
  5240. }
  5241. DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
  5242. OnGetSpaceAvailable);
  5243. }
  5244. //---------------------------------------------------------------------------
  5245. void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
  5246. {
  5247. if (value != FSessionColor)
  5248. {
  5249. FSessionColor = value;
  5250. TColor C = (value != 0 ? value : clNone);
  5251. TTBXColorPalette * ColorPalette = dynamic_cast<TTBXColorPalette *>(
  5252. static_cast<TObject *>(GetComponent(fcColorPalette)));
  5253. assert(ColorPalette != NULL);
  5254. ColorPalette->Color = C;
  5255. TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
  5256. static_cast<TObject *>(GetComponent(fcColorMenu)));
  5257. assert(ColorItem != NULL);
  5258. ColorItem->Color = C;
  5259. UpdateControls();
  5260. }
  5261. }
  5262. //---------------------------------------------------------------------------
  5263. void __fastcall TCustomScpExplorerForm::SessionColorPick()
  5264. {
  5265. TColorDialog * Dialog = new TColorDialog(this);
  5266. try
  5267. {
  5268. Dialog->Options = Dialog->Options << cdFullOpen;
  5269. Dialog->Color = (FSessionColor != 0 ? FSessionColor : clSkyBlue);
  5270. if (Dialog->Execute())
  5271. {
  5272. SessionColor = Dialog->Color;
  5273. }
  5274. }
  5275. __finally
  5276. {
  5277. delete Dialog;
  5278. }
  5279. }
  5280. //---------------------------------------------------------------------------
  5281. void __fastcall TCustomScpExplorerForm::SessionColorPaletteChange(
  5282. TObject * Sender)
  5283. {
  5284. TTBXColorPalette * ColorPalette = dynamic_cast<TTBXColorPalette *>(Sender);
  5285. assert(ColorPalette != NULL);
  5286. SessionColor = (ColorPalette->Color != clNone ? ColorPalette->Color : (TColor)0);
  5287. }
  5288. //---------------------------------------------------------------------------
  5289. bool __fastcall TCustomScpExplorerForm::CancelNote()
  5290. {
  5291. bool Result = FNoteTimer->Enabled;
  5292. if (Result)
  5293. {
  5294. // cannot cancel note too early
  5295. if (Now() - FNoteShown >
  5296. EncodeTime(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0))
  5297. {
  5298. FNoteTimer->Enabled = false;
  5299. FNote = "";
  5300. // beware that OnNoteClick may being executed
  5301. SAFE_DESTROY(FNoteData);
  5302. FOnNoteClick = NULL;
  5303. FNoteHints = FNotes->Text;
  5304. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  5305. UpdateStatusBar();
  5306. }
  5307. }
  5308. return Result;
  5309. }
  5310. //---------------------------------------------------------------------------
  5311. void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
  5312. {
  5313. assert(FNoteTimer->Enabled);
  5314. CancelNote();
  5315. }
  5316. //---------------------------------------------------------------------------
  5317. void __fastcall TCustomScpExplorerForm::AddNote(AnsiString Note, bool UpdateNow)
  5318. {
  5319. int P = Note.Pos("\n");
  5320. if (P > 0)
  5321. {
  5322. Note.SetLength(P - 1);
  5323. }
  5324. FNotes->Add(FORMAT("[%s] %s",
  5325. (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
  5326. while (FNotes->Count > 10)
  5327. {
  5328. FNotes->Delete(0);
  5329. }
  5330. if (UpdateNow)
  5331. {
  5332. FNoteHints = FNotes->Text;
  5333. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  5334. UpdateStatusBar();
  5335. }
  5336. }
  5337. //---------------------------------------------------------------------------
  5338. void __fastcall TCustomScpExplorerForm::PostNote(AnsiString Note,
  5339. unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
  5340. {
  5341. int P = Note.Pos("\n");
  5342. if (P > 0)
  5343. {
  5344. Note.SetLength(P - 1);
  5345. }
  5346. FNoteHints = FNotes->Text;
  5347. FNoteHints.Delete(FNoteHints.Length() - 1, 2);
  5348. FNote = Note;
  5349. // beware that OnNoteClick may being executed
  5350. SAFE_DESTROY(FNoteData);
  5351. FNoteData = NoteData;
  5352. FOnNoteClick = OnNoteClick;
  5353. AddNote(Note, false);
  5354. UpdateStatusBar();
  5355. FNoteShown = Now();
  5356. FNoteTimer->Enabled = false;
  5357. if (Seconds == 0)
  5358. {
  5359. Seconds = WinConfiguration->NotificationsTimeout;
  5360. }
  5361. FNoteTimer->Interval = Seconds * 1000;
  5362. FNoteTimer->Enabled = true;
  5363. }
  5364. //---------------------------------------------------------------------------
  5365. void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
  5366. {
  5367. PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
  5368. }
  5369. //---------------------------------------------------------------------------
  5370. void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
  5371. {
  5372. PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
  5373. (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
  5374. (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
  5375. 0, NULL, NULL);
  5376. }
  5377. //---------------------------------------------------------------------------
  5378. void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
  5379. {
  5380. WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
  5381. PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
  5382. (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
  5383. (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
  5384. }
  5385. //---------------------------------------------------------------------------
  5386. void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
  5387. {
  5388. Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
  5389. PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
  5390. (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
  5391. (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
  5392. }
  5393. //---------------------------------------------------------------------------
  5394. void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
  5395. TTBXCustomStatusBar * /*Sender*/, TTBXStatusPanel * Panel)
  5396. {
  5397. if (Panel->Index == 0)
  5398. {
  5399. if (FOnNoteClick != NULL)
  5400. {
  5401. FOnNoteClick(NULL);
  5402. }
  5403. }
  5404. else
  5405. {
  5406. FileSystemInfo();
  5407. }
  5408. }
  5409. //---------------------------------------------------------------------------
  5410. void __fastcall TCustomScpExplorerForm::LockWindow()
  5411. {
  5412. // workaround:
  5413. // 1) for unknown reason, disabling window, while minimized,
  5414. // prevents it from restoring, even if it was enabled again meanwhile
  5415. // 2) when disabling the main window, while another has focus
  5416. // minimize is no longer possible ("keep up to date" dialog)
  5417. if (!IsIconic(Application->Handle) && (Screen->ActiveForm == this))
  5418. {
  5419. Enabled = false;
  5420. }
  5421. FLockLevel++;
  5422. }
  5423. //---------------------------------------------------------------------------
  5424. void __fastcall TCustomScpExplorerForm::UnlockWindow()
  5425. {
  5426. assert(FLockLevel > 0);
  5427. FLockLevel--;
  5428. if (FLockLevel == 0)
  5429. {
  5430. Enabled = true;
  5431. }
  5432. }
  5433. //---------------------------------------------------------------------------
  5434. bool __fastcall TCustomScpExplorerForm::MainWindowHook(TMessage & AMessage)
  5435. {
  5436. // workaround for problem with hidden application window.
  5437. // "groupped" window arrangement commands send WM_WINDOWPOSCHANGING to
  5438. // windows associated with taskbar buttons (i.e. the hidden one for VCL).
  5439. // we forward here the message to the main window.
  5440. // this does not solve "all windows" arrangement commands,
  5441. // which calculates size according to number of all visible windows.
  5442. // hence they count VCL application twice.
  5443. // code is said to be from Issue 4/95 of The Delphi Magazine
  5444. if (AMessage.Msg == WM_WINDOWPOSCHANGING)
  5445. {
  5446. TWMWindowPosMsg & Message = reinterpret_cast<TWMWindowPosMsg &>(AMessage);
  5447. assert(Message.WindowPos->hwnd == Application->Handle);
  5448. if ((Message.WindowPos->hwnd == Application->Handle) &&
  5449. !IsIconic(Message.WindowPos->hwnd) &&
  5450. (Message.WindowPos->cx > 0) &&
  5451. (Message.WindowPos->cy > 0))
  5452. {
  5453. unsigned int LocalFlags = Message.WindowPos->flags | SWP_NOZORDER;
  5454. if (BorderStyle == bsSizeable)
  5455. {
  5456. LocalFlags = LocalFlags & ~SWP_NOSIZE;
  5457. }
  5458. else
  5459. {
  5460. LocalFlags = LocalFlags | SWP_NOSIZE;
  5461. }
  5462. SetWindowPos(Handle, 0, Message.WindowPos->x, Message.WindowPos->y,
  5463. Message.WindowPos->cx, Message.WindowPos->cy, LocalFlags);
  5464. }
  5465. }
  5466. return false;
  5467. }
  5468. //---------------------------------------------------------------------------