CustomScpExplorer.cpp 205 KB

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