CustomScpExplorer.cpp 181 KB

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