CustomScpExplorer.cpp 191 KB

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