CustomScpExplorer.cpp 201 KB

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