| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <Common.h>
- #include "CustomScpExplorer.h"
- #include <Interface.h>
- #include <Exceptions.h>
- #include <CoreMain.h>
- #include <FileSystems.h>
- #include <TextsCore.h>
- #include <TextsWin.h>
- #include <HelpWin.h>
- #include <VCLCommon.h>
- #include <Log.h>
- #include <Progress.h>
- #include <SynchronizeProgress.h>
- #include <OperationStatus.h>
- #include <DragExt.h>
- #include "GUITools.h"
- #include "NonVisual.h"
- #include "Glyphs.h"
- #include "Tools.h"
- #include "WinConfiguration.h"
- #include "TerminalManager.h"
- #include "EditorManager.h"
- #include "Setup.h"
- #include <Consts.hpp>
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "CustomDirView"
- #pragma link "CustomUnixDirView"
- #pragma link "IEListView"
- #pragma link "NortonLikeListView"
- #pragma link "UnixDirView"
- #pragma link "CustomDriveView"
- #pragma link "UnixDriveView"
- #pragma link "CustomDriveView"
- #pragma link "TB2Dock"
- #pragma link "TBXStatusBars"
- #pragma link "TB2Item"
- #pragma link "TB2Toolbar"
- #pragma resource "*.dfm"
- //---------------------------------------------------------------------------
- #define SAVE_SELECTION(DIRVIEW) \
- AnsiString FocusFile = ""; \
- AnsiString LastFocusedFile = ""; \
- if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
- { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
- if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
- #define RESTORE_SELECTION(DIRVIEW) \
- if (!LastFocusedFile.IsEmpty() && \
- (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
- { \
- TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
- if (ItemToSelect) \
- { \
- DIRVIEW->ItemFocused = ItemToSelect; \
- DIRVIEW->ItemFocused->MakeVisible(False); \
- } \
- }
- //---------------------------------------------------------------------------
- #define WM_COMPONENT_HIDE (WM_WINSCP_USER + 4)
- //---------------------------------------------------------------------------
- class TMutexGuard
- {
- public:
- TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
- int Timeout = 5000)
- {
- FMutex = NULL;
- unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
- if (WaitResult == WAIT_TIMEOUT)
- {
- throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
- }
- else
- {
- FMutex = AMutex;
- }
- }
- ~TMutexGuard()
- {
- if (FMutex != NULL)
- {
- ReleaseMutex(FMutex);
- }
- }
- private:
- HANDLE FMutex;
- };
- //---------------------------------------------------------------------------
- struct TTransferOperationParam
- {
- TTransferOperationParam();
- AnsiString TargetDirectory;
- bool Temp;
- bool DragDrop;
- };
- //---------------------------------------------------------------------------
- TTransferOperationParam::TTransferOperationParam()
- {
- Temp = false;
- DragDrop = false;
- }
- //---------------------------------------------------------------------------
- TCustomCommandParam::TCustomCommandParam()
- {
- Params = 0;
- }
- //---------------------------------------------------------------------------
- class TTransferPresetNoteData : public TObject
- {
- public:
- AnsiString Message;
- TStrings * More;
- virtual __fastcall ~TTransferPresetNoteData()
- {
- delete More;
- }
- };
- //---------------------------------------------------------------------------
- static const int OutPos = -32000;
- //---------------------------------------------------------------------------
- __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
- FFormRestored(False), TForm(Owner)
- {
- FCurrentSide = osRemote;
- FDocks = new TList();
- RestoreParams();
- ConfigurationChanged();
- RemoteDirView->Invalidate();
- assert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
- NonVisualDataModule->ScpExplorer = this;
- Application->OnHint = ApplicationHint;
- Application->OnMinimize = ApplicationMinimize;
- Application->OnRestore = ApplicationRestore;
- FAutoOperation = false;
- FForceExecution = false;
- FShowStatusBarHint = false;
- FIgnoreNextSysCommand = false;
- FErrorList = NULL;
- FSynchronizeProgressForm = NULL;
- FProgressForm = NULL;
- FRefreshLocalDirectory = false;
- FRefreshRemoteDirectory = false;
- FDDMoveSlipped = false;
- FDDExtMapFile = NULL;
- FDDExtMutex = CreateMutex(NULL, false, DRAG_EXT_MUTEX);
- assert(FDDExtMutex != NULL);
- FDDTargetControl = NULL;
- FDelayedDeletionTimer = NULL;
- FDelayedDeletionList = new TStringList();
- FDDFileList = NULL;
- FPendingTempSpaceWarn = false;
- FCapturedLog = NULL;
- FDragDropOperation = false;
- memset(&FHistoryMenu, 0, sizeof(FHistoryMenu));
- FNoTransferPresetAutoSelect = false;
- FCopyParamDefault = "";
- FSynchronizeController = NULL;
- FPendingQueueActionItem = NULL;
- FLockLevel = 0;
- FTrayIcon = new TTrayIcon(0);
- FTrayIcon->OnClick = TrayIconClick;
- FEditorManager = new TEditorManager();
- FEditorManager->OnFileChange = ExecutedFileChanged;
- FEditorManager->OnFileReload = ExecutedFileReload;
- FEditorManager->OnFileEarlyClosed = ExecutedFileEarlyClosed;
- FQueueStatus = NULL;
- FQueueStatusSection = new TCriticalSection();
- FQueueStatusInvalidated = false;
- FQueueItemInvalidated = false;
- FQueueActedItem = NULL;
- FQueueController = new TQueueController(QueueView);
- FUserActionTimer = new TTimer(this);
- FUserActionTimer->Enabled = false;
- FUserActionTimer->Interval = 10;
- FUserActionTimer->OnTimer = UserActionTimer;
- FNotes = new TStringList();
- FNoteTimer = new TTimer(this);
- FNoteTimer->Enabled = false;
- FNoteTimer->OnTimer = NoteTimer;
- FOnNoteClick = NULL;
- FOle32Library = LoadLibrary("Ole32.dll");
- FDragMoveCursor = FOle32Library != NULL ?
- LoadCursor(FOle32Library, MAKEINTRESOURCE(2)) : NULL;
- UseSystemSettings(this);
- TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem*>(
- static_cast<TObject*>(GetComponent(fcSessionCombo)));
- if (SessionCombo != NULL)
- {
- SessionCombo->OnDrawItem = SessionComboDrawItem;
- SessionCombo->OnPopup = SessionComboPopup;
- SessionCombo->OnChange = SessionComboChange;
- SessionCombo->Hint = NonVisualDataModule->OpenedSessionsAction->Hint;
- }
- TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
- static_cast<TObject*>(GetComponent(fcTransferList)));
- assert(TransferList != NULL);
- FTransferListHoverIndex = -1;
- TransferList->OnChange = TransferListChange;
- TransferList->OnDrawItem = TransferListDrawItem;
- class TTBXPublicItem : public TTBXCustomItem
- {
- public:
- __property ItemStyle;
- };
- TTBXPublicItem * ColorMenu = reinterpret_cast<TTBXPublicItem *>(GetComponent(fcColorMenu));
- ColorMenu->ItemStyle = ColorMenu->ItemStyle << tbisSubmenu;
- RemoteDirView->Font = Screen->IconFont;
- reinterpret_cast<TLabel*>(QueueSplitter)->OnDblClick = QueueSplitterDblClick;
- StartUpdates();
- }
- //---------------------------------------------------------------------------
- __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
- {
- Application->UnhookMainWindow(MainWindowHook);
- Application->OnHint = NULL;
- Application->OnMinimize = NULL;
- Application->OnRestore = NULL;
- delete FTrayIcon;
- FTrayIcon = NULL;
- FEditorManager->CloseInternalEditors(ForceCloseInternalEditor);
- delete FEditorManager;
- if (FDelayedDeletionTimer)
- {
- DoDelayedDeletion(NULL);
- SAFE_DESTROY(FDelayedDeletionTimer);
- }
- SAFE_DESTROY(FDelayedDeletionList);
- assert(FSynchronizeController == NULL);
- CloseHandle(FDDExtMutex);
- FDDExtMutex = NULL;
- FreeLibrary(FOle32Library);
- FOle32Library = NULL;
- FDragMoveCursor = NULL;
- assert(!FErrorList);
- StoreParams();
- Terminal = NULL;
- Queue = NULL;
- assert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
- NonVisualDataModule->ScpExplorer = NULL;
- delete FQueueController;
- FQueueController = NULL;
- delete FQueueStatusSection;
- FQueueStatusSection = NULL;
- delete FQueueStatus;
- FQueueStatus = NULL;
- delete FUserActionTimer;
- FUserActionTimer = NULL;
- delete FNoteTimer;
- delete FNotes;
- delete FNoteData;
- SAFE_DESTROY(FDocks);
- SAFE_DESTROY(FHistoryMenu[0][0]);
- SAFE_DESTROY(FHistoryMenu[0][1]);
- SAFE_DESTROY(FHistoryMenu[1][0]);
- SAFE_DESTROY(FHistoryMenu[1][1]);
- StopUpdateThread();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
- {
- if (FTerminal != value)
- {
- TerminalChanging();
- FTerminal = value;
- bool PrevNoTransferPresetAutoSelect = FNoTransferPresetAutoSelect;
- FNoTransferPresetAutoSelect = true;
- try
- {
- TerminalChanged();
- }
- __finally
- {
- FNoTransferPresetAutoSelect = PrevNoTransferPresetAutoSelect;
- }
- if (Terminal != NULL)
- {
- TransferPresetAutoSelect();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalChanging()
- {
- if (FTerminal != NULL)
- {
- UpdateTerminal(Terminal);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalChanged()
- {
- RemoteDirView->Terminal = Terminal;
- Caption = Application->Title;
- NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked = false;
- if (Terminal)
- {
- if (Terminal->Active)
- {
- Terminal->RefreshDirectory();
- }
- TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
- assert(ManagedTerminal != NULL);
- if (WinConfiguration->PreservePanelState &&
- (ManagedTerminal->RemoteExplorerState != NULL))
- {
- RemoteDirView->RestoreState(ManagedTerminal->RemoteExplorerState);
- }
- SessionColor = ManagedTerminal->Color;
- InitStatusBar();
- }
- TerminalListChanged(NULL);
- UpdateTransferList();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetQueue(TTerminalQueue * value)
- {
- if (Queue != value)
- {
- if (FQueue != NULL)
- {
- FQueue->OnListUpdate = NULL;
- FQueue->OnQueueItemUpdate = NULL;
- }
- FQueue = value;
- if (FQueue != NULL)
- {
- assert(FQueue->OnListUpdate == NULL);
- FQueue->OnListUpdate = QueueListUpdate;
- assert(FQueue->OnQueueItemUpdate == NULL);
- FQueue->OnQueueItemUpdate = QueueItemUpdate;
- }
- QueueChanged();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewDeletion(TObject * /*Sender*/,
- TListItem * Item)
- {
- if (FQueueActedItem == Item)
- {
- FQueueActedItem = NULL;
- if ((QueueView->PopupMenu != NULL) &&
- (QueueView->PopupMenu->PopupComponent == QueueView))
- {
- // rather "trick", suggested by Jordan on jrsoftware.toolbar2000
- ReleaseCapture();
- }
- }
- if (Item->Data == FPendingQueueActionItem)
- {
- FPendingQueueActionItem = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateQueueStatus(bool AppIdle)
- {
- {
- TGuard Guard(FQueueStatusSection);
- FQueueStatusInvalidated = false;
- if (FQueue != NULL)
- {
- FQueueStatus = FQueue->CreateStatus(FQueueStatus);
- }
- }
- FQueueController->UpdateQueueStatus(FQueueStatus);
- UpdateQueueView();
- bool IsEmpty = (FQueueStatus == NULL) || (FQueueStatus->Count == 0);
- if (NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked &&
- IsEmpty && (Terminal != NULL))
- {
- NonVisualDataModule->QueueDisconnectOnceEmptyAction->Checked = false;
- if (AppIdle)
- {
- Terminal->CloseOnCompletion(LoadStr(CLOSED_ON_QUEUE_EMPTY));
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateQueueView()
- {
- ComponentVisible[fcQueueView] =
- (WinConfiguration->QueueView.Show == qvShow) ||
- ((WinConfiguration->QueueView.Show == qvHideWhenEmpty) &&
- (FQueueStatus != NULL) && (FQueueStatus->Count > 0));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueChanged()
- {
- if (FQueueStatus != NULL)
- {
- delete FQueueStatus;
- FQueueStatus = NULL;
- }
- UpdateQueueStatus(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueListUpdate(TTerminalQueue * Queue)
- {
- if (FQueue == Queue)
- {
- FQueueStatusInvalidated = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueItemUpdate(TTerminalQueue * Queue,
- TQueueItem * Item)
- {
- if (FQueue == Queue)
- {
- TGuard Guard(FQueueStatusSection);
- assert(FQueueStatus != NULL);
- TQueueItemProxy * QueueItem = FQueueStatus->FindByQueueItem(Item);
- if ((Item->Status == TQueueItem::qsDone) && (Terminal != NULL))
- {
- FRefreshLocalDirectory = (QueueItem == NULL) ||
- (!QueueItem->Info->ModifiedLocal.IsEmpty());
- FRefreshRemoteDirectory = (QueueItem == NULL) ||
- (!QueueItem->Info->ModifiedRemote.IsEmpty());
- }
- if (QueueItem != NULL)
- {
- QueueItem->UserData = (void*)true;
- FQueueItemInvalidated = true;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RefreshQueueItems(bool AppIdle)
- {
- if (FQueueStatus != NULL)
- {
- bool QueueAutoPopup = GUIConfiguration->QueueAutoPopup;
- bool Refresh = FQueueItemInvalidated;
- FQueueItemInvalidated = false;
- int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->ActiveCount;
- bool Updated = false;
- bool Update;
- TQueueItemProxy * QueueItem;
- bool WasUserAction;
- for (int Index = 0; Index < Limit; Index++)
- {
- Update = false;
- QueueItem = FQueueStatus->Items[Index];
- WasUserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
- if (AppIdle && QueueAutoPopup && WasUserAction &&
- (FPendingQueueActionItem == NULL))
- {
- FPendingQueueActionItem = QueueItem;
- FUserActionTimer->Enabled = true;
- }
- if ((bool)QueueItem->UserData)
- {
- QueueItem->UserData = (void*)false;
- QueueItem->Update();
- Updated = true;
- Update = true;
- }
- else if (FQueueController->QueueItemNeedsFrequentRefresh(QueueItem))
- {
- Update = true;
- }
- if (Update)
- {
- FQueueController->RefreshQueueItem(QueueItem);
- }
- }
- if (Updated)
- {
- NonVisualDataModule->UpdateNonVisibleActions();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateTransferList()
- {
- TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
- static_cast<TComponent*>(GetComponent(fcTransferList)));
- TTBXDropDownItem * TransferDropDown = dynamic_cast<TTBXDropDownItem*>(
- static_cast<TComponent*>(GetComponent(fcTransferDropDown)));
- TransferList->Strings->BeginUpdate();
- try
- {
- TransferList->Strings->Assign(GUIConfiguration->CopyParamList->NameList);
- TransferList->Strings->Insert(0, StripHotkey(LoadStr(COPY_PARAM_DEFAULT)));
- TransferList->ItemIndex = GUIConfiguration->CopyParamIndex + 1;
- if (FTransferDropDownHint.IsEmpty())
- {
- FTransferDropDownHint = TransferDropDown->Hint;
- }
- // this way we get name for "default" settings (COPY_PARAM_DEFAULT)
- AnsiString Name = TransferList->Strings->Strings[TransferList->ItemIndex];
- TransferDropDown->Text = Name;
- TransferDropDown->Hint = FORMAT("%s\n \n%s:\n%s|%s",
- (FTransferDropDownHint, Name,
- GUIConfiguration->CurrentCopyParam.GetInfoStr("; ",
- FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General)),
- FTransferDropDownHint));
- // update the label, otherwise when it is updated only on the first draw
- // of the list, it is drawn "bold" for some reason
- FTransferListHoverIndex = TransferList->ItemIndex;
- UpdateTransferLabel();
- }
- __finally
- {
- TransferList->Strings->EndUpdate();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateCustomCommandsToolbar()
- {
- TTBXToolbar * Toolbar = dynamic_cast<TTBXToolbar *>(GetComponent(fcCustomCommandsBand));
- assert(Toolbar != NULL);
- NonVisualDataModule->UpdateCustomCommandsToolbar(Toolbar);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateActions()
- {
- TForm::UpdateActions();
- if (ComponentVisible[fcCustomCommandsBand])
- {
- UpdateCustomCommandsToolbar();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
- {
- assert(Configuration && RemoteDirView);
- RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
- RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
- RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
- RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
- RemoteDriveView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
- RemoteDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
- RemoteDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
- RemoteDriveView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
- SetDockAllowDrag(!WinConfiguration->LockToolbars);
- UpdateTransferList();
- if (Terminal != NULL)
- {
- TransferPresetAutoSelect();
- }
- UpdateQueueView();
- UpdateControls();
- // this can be called even before constuctor finishes.
- // can we be sure that the FEditorManager is NULL then?
- if (FEditorManager != NULL)
- {
- FEditorManager->ProcessFiles(FileConfigurationChanged, NULL);
- }
- if (ComponentVisible[fcCustomCommandsBand])
- {
- UpdateCustomCommandsToolbar();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileConfigurationChanged(
- const AnsiString FileName, TEditedFileData & /*Data*/, TObject * Token,
- void * /*Arg*/)
- {
- if (Token != NULL)
- {
- TForm * Editor = dynamic_cast<TForm*>(Token);
- assert(Editor != NULL);
- ReconfigureEditorForm(Editor);
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
- TTransferDirection Direction, TTransferType Type, bool Temp,
- TStrings * FileList, AnsiString & TargetDirectory, TGUICopyParamType & CopyParam,
- bool Confirm, bool DragDrop)
- {
- bool Result = true;
- assert(Terminal && Terminal->Active);
- // Temp means d&d here so far, may change in future!
- if (Temp && (Direction == tdToLocal) && (Type == ttMove) &&
- !WinConfiguration->DDAllowMove)
- {
- TMessageParams Params(mpNeverAskAgainCheck);
- int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
- qaOK | qaCancel, HELP_DND_DOWNLOAD_MOVE_WARNING, &Params);
- if (Answer == qaNeverAskAgain)
- {
- WinConfiguration->DDAllowMove = true;
- }
- else if (Answer == qaCancel)
- {
- Result = false;
- }
- }
- // these parameters are known in advance
- int Params =
- FLAGMASK(Type == ttMove, cpDelete);
- bool ToTemp = (Temp && (Direction == tdToLocal));
- if (Result && Confirm)
- {
- bool DisableNewerOnly =
- (!Terminal->IsCapable[fcNewerOnlyUpload] && (Direction == tdToRemote)) ||
- ToTemp;
- int Options =
- FLAGMASK(DisableNewerOnly, coDisableNewerOnly) |
- FLAGMASK(ToTemp, coTemp) |
- FLAGMASK(DragDrop, coDoNotShowAgain);
- TUsableCopyParamAttrs UsableCopyParamAttrs = Terminal->UsableCopyParamAttrs(Params);
- int CopyParamAttrs = (Direction == tdToRemote ?
- UsableCopyParamAttrs.Upload : UsableCopyParamAttrs.Download);
- int OutputOptions = 0;
- Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
- FileList, TargetDirectory, &CopyParam, Options, CopyParamAttrs, &OutputOptions);
- if (Result && DragDrop && FLAGSET(OutputOptions, cooDoNotShowAgain))
- {
- WinConfiguration->DDTransferConfirmation = false;
- }
- }
- if (Result && CopyParam.Queue && !ToTemp)
- {
- assert(Queue != NULL);
- // these parameter are known only after transfer dialog
- Params |=
- (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 0) |
- (CopyParam.NewerOnly ? cpNewerOnly : 0);
- TQueueItem * QueueItem;
- if (Direction == tdToRemote)
- {
- QueueItem = new TUploadQueueItem(Terminal, FileList, TargetDirectory,
- &CopyParam, Params);
- }
- else
- {
- QueueItem = new TDownloadQueueItem(Terminal, FileList, TargetDirectory,
- &CopyParam, Params);
- }
- Queue->AddItem(QueueItem);
- Result = false;
- TOperationSide Side = ((Direction == tdToRemote) ? osLocal : osRemote);
- if (HasDirView[Side])
- {
- DirView(Side)->SelectAll(smNone);
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RestoreFormParams()
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RestoreParams()
- {
- assert(FDocks != NULL);
- for (int Index = 0; Index < ComponentCount; Index++)
- {
- TTBDock * Dock = dynamic_cast<TTBDock *>(Components[Index]);
- if ((Dock != NULL) && (Dock->Tag == 0))
- {
- FDocks->Add(Dock);
- }
- }
- // IDE often looses this link
- RemoteDirView->HeaderImages = GlyphsModule->ArrowImages;
- ConfigurationChanged();
- QueuePanel->Height = WinConfiguration->QueueView.Height;
- LoadListViewStr(QueueView, WinConfiguration->QueueView.Layout);
- QueueDock->Visible = WinConfiguration->QueueView.ToolBar;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::StoreParams()
- {
- WinConfiguration->QueueView.Height = QueuePanel->Height;
- WinConfiguration->QueueView.Layout = GetListViewStr(QueueView);
- WinConfiguration->QueueView.ToolBar = QueueDock->Visible;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
- {
- if (!FFormRestored)
- {
- FFormRestored = true;
- RestoreFormParams();
- }
- TForm::CreateParams(Params);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetDockAllowDrag(bool value)
- {
- assert(FDocks != NULL);
- for (int Index = 0; Index < FDocks->Count; Index++)
- {
- static_cast<TTBDock*>(FDocks->Items[Index])->AllowDrag = value;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::LoadToolbarsLayoutStr(AnsiString LayoutStr)
- {
- SetDockAllowDrag(true);
- ::LoadToolbarsLayoutStr(this, LayoutStr);
- SetDockAllowDrag(!WinConfiguration->LockToolbars);
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TCustomScpExplorerForm::GetToolbarsLayoutStr()
- {
- AnsiString Result;
- SetDockAllowDrag(true);
- Result = ::GetToolbarsLayoutStr(this);
- SetDockAllowDrag(!WinConfiguration->LockToolbars);
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileOperationProgress(
- TFileOperationProgressType & ProgressData, TCancelStatus & /*Cancel*/)
- {
- // Download to temporary local directory
- if (FPendingTempSpaceWarn && ProgressData.InProgress && ProgressData.TotalSizeSet)
- {
- bool Continue = true;
- FPendingTempSpaceWarn = false;
- DoWarnLackOfTempSpace(ProgressData.Directory, ProgressData.TotalSize, Continue);
- if (!Continue)
- {
- Abort();
- }
- }
- // operation is being executed and we still didn't show up progress form
- if (ProgressData.InProgress && !FProgressForm)
- {
- FProgressForm = new TProgressForm(Application);
- FProgressForm->DeleteToRecycleBin = (ProgressData.Side == osLocal ?
- WinConfiguration->DeleteToRecycleBin :
- Terminal->SessionData->DeleteToRecycleBin);
- // When main window is hidden, synchronisation form does not exist,
- // we suppose "/upload" or URL download mode
- if (!Visible && (ProgressData.Operation != foCalculateSize) &&
- (ProgressData.Operation != foCalculateChecksum) &&
- (FSynchronizeProgressForm == NULL))
- {
- FProgressForm->DisconnectWhenComplete = true;
- }
- }
- // operation is finished (or terminated), so we hide progress form
- else if (!ProgressData.InProgress && FProgressForm)
- {
- SAFE_DESTROY(FProgressForm);
- if ((ProgressData.Operation != foCalculateSize) &&
- (ProgressData.Cancel == csContinue) &&
- !FAutoOperation)
- {
- OperationComplete(ProgressData.StartTime);
- }
- }
- if (FProgressForm)
- {
- FProgressForm->SetProgressData(ProgressData);
- if (FProgressForm->Cancel > ProgressData.Cancel)
- {
- ProgressData.Cancel = FProgressForm->Cancel;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OperationComplete(
- const TDateTime & StartTime)
- {
- if (GUIConfiguration->BeepOnFinish &&
- (Now() - StartTime > GUIConfiguration->BeepOnFinishAfter))
- {
- MessageBeep(MB_OK);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OperationProgress(
- TFileOperationProgressType & ProgressData, TCancelStatus & Cancel)
- {
- FileOperationProgress(ProgressData, Cancel);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::PanelOperation(TOperationSide /*Side*/,
- bool DragDrop)
- {
- return (!DragDrop && (DropSourceControl == NULL)) ||
- (DropSourceControl == RemoteDirView);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoOperationFinished(
- TFileOperation Operation, TOperationSide Side,
- bool /*Temp*/, const AnsiString FileName, bool Success,
- bool & DisconnectWhenComplete)
- {
- if (!FAutoOperation)
- {
- // no selection on "/upload", form servers only as event handler
- // (it is not displayed)
- if (PanelOperation(Side, FDragDropOperation) &&
- Visible && (Operation != foCalculateSize) &&
- (Operation != foGetProperties) && (Operation != foCalculateChecksum))
- {
- TCustomDirView * DView = DirView(Side);
- AnsiString FileNameOnly = ExtractFileName(FileName, (Side == osRemote));
- TListItem *Item = DView->FindFileItem(FileNameOnly);
- // this can happen when local drive is unplugged in the middle of the operation
- if (Item != NULL)
- {
- if (Success) Item->Selected = false;
- if (DView->ViewStyle == vsReport)
- {
- TRect DisplayRect = Item->DisplayRect(drBounds);
- if (DisplayRect.Bottom > DView->ClientHeight)
- {
- DView->Scroll(0, Item->Top - DView->TopItem->Top);
- }
- }
- Item->MakeVisible(false);
- }
- }
- }
- if (Success && (FSynchronizeController != NULL))
- {
- if (Operation == foCopy)
- {
- assert(Side == osLocal);
- FSynchronizeController->LogOperation(soUpload, FileName);
- }
- else if (Operation == foDelete)
- {
- assert(Side == osRemote);
- FSynchronizeController->LogOperation(soDelete, FileName);
- }
- }
- if (FProgressForm)
- {
- DisconnectWhenComplete = FProgressForm->DisconnectWhenComplete;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OperationFinished(
- TFileOperation Operation, TOperationSide Side,
- bool Temp, const AnsiString FileName, Boolean Success,
- bool & DisconnectWhenComplete)
- {
- DoOperationFinished(Operation, Side, Temp, FileName, Success,
- DisconnectWhenComplete);
- }
- //---------------------------------------------------------------------------
- TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
- {
- assert(GetSide(Side) == osRemote);
- USEDPARAM(Side);
- return RemoteDirView;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(
- TOperationSide Side, int FilesOnly)
- {
- return DirView(Side)->AnyFileSelected(true, (FilesOnly != 0));
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(
- TOperationSide Side, int FilesOnly)
- {
- return DirView(Side)->AnyFileSelected(false, (FilesOnly != 0));
- }
- //---------------------------------------------------------------------------
- struct THistoryItemData
- {
- // TOperationSide has 1 byte, but whole structure seems padded to 4 bytes,
- // just like "int"
- TOperationSide Side;
- short int Index;
- };
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::HistoryItemClick(System::TObject* Sender)
- {
- TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
- THistoryItemData Data = *reinterpret_cast<THistoryItemData*>(&(Item->Tag));
- DirView(Data.Side)->HistoryGo(Data.Index);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateHistoryMenu(TOperationSide Side,
- bool Back)
- {
- if (FHistoryMenu[Side == osLocal][Back] != NULL)
- {
- TCustomDirView * DView = DirView(Side);
- TTBXPopupMenu * Menu = FHistoryMenu[Side == osLocal][Back];
- int ICount = Back ? DView->BackCount : DView->ForwardCount;
- if (ICount > 10)
- {
- ICount = 10;
- }
- Menu->Items->Clear();
- THistoryItemData Data;
- Data.Side = Side;
- for (short int i = 1; i <= ICount; i++)
- {
- TTBCustomItem * Item = new TTBXItem(Menu);
- Data.Index = static_cast<short int>(i * (Back ? -1 : 1));
- Item->Caption = MinimizeName(DView->HistoryPath[Data.Index], 50, (Side == osRemote));
- Item->Hint = DView->HistoryPath[Data.Index];
- assert(sizeof(int) == sizeof(THistoryItemData));
- Item->Tag = *reinterpret_cast<int*>(&Data);
- Item->OnClick = HistoryItemClick;
- Menu->Items->Add(Item);
- }
- }
- }
- //---------------------------------------------------------------------------
- TTBXPopupMenu * __fastcall TCustomScpExplorerForm::HistoryMenu(
- TOperationSide Side, bool Back)
- {
- if (FHistoryMenu[Side == osLocal][Back] == NULL)
- {
- // In Pascal the size of TTBXPopupMenu is 132, in C++ 136,
- // operator new allocates memory in Pascal code, but calls inline
- // contructor in C++, leading in problems, the funtion does
- // both in Pascal code
- FHistoryMenu[Side == osLocal][Back] = CreateTBXPopupMenu(this);
- UpdateHistoryMenu(Side, Back);
- }
- return FHistoryMenu[Side == osLocal][Back];
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewHistoryChange(
- TCustomDirView *Sender)
- {
- TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
- UpdateHistoryMenu(Side, true);
- UpdateHistoryMenu(Side, false);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
- {
- // remote custom commands can be executed only if the server supports shell commands
- // or have secondary shell
- return (FTerminal->IsCapable[fcSecondaryShell] || FTerminal->IsCapable[fcShellAnyCommand]);
- }
- //---------------------------------------------------------------------------
- int __fastcall TCustomScpExplorerForm::CustomCommandState(
- const AnsiString & Command, int Params, bool OnFocused)
- {
- int Result;
- TFileCustomCommand RemoteCustomCommand;
- TLocalCustomCommand LocalCustomCommand;
- TFileCustomCommand * NonInteractiveCustomCommand =
- FLAGCLEAR(Params, ccLocal) ? &RemoteCustomCommand : &LocalCustomCommand;
- TInteractiveCustomCommand InteractiveCustomCommand(NonInteractiveCustomCommand);
- AnsiString Cmd = InteractiveCustomCommand.Complete(Command, false);
- if (FLAGCLEAR(Params, ccLocal))
- {
- Result = CustomCommandRemoteAllowed();
- if (Result)
- {
- // custom command that does not operate with files can be executed anytime ...
- if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
- {
- // ... but do not show such command in remote file menu
- // (TODO, currently custom commands are in file menu only, so we cannot hide
- // such command, because it won't be accessible from elsewhere)
- Result = OnFocused ? /*-1*/ true : true;
- }
- else
- {
- Result = (FCurrentSide == osRemote) && EnableSelectedOperation[osRemote];
- }
- }
- }
- else
- {
- // custom command that does not operate with files can be executed anytime
- if (!NonInteractiveCustomCommand->IsFileCommand(Cmd))
- {
- Result = true;
- }
- else if (LocalCustomCommand.HasLocalFileName(Cmd))
- {
- // special case is "diff"-style command that can be executed over any side,
- // if we have both sides
- Result = (HasDirView[osLocal] && EnableSelectedOperation[osLocal]) &&
- EnableSelectedOperation[osRemote];
- }
- else
- {
- // other local custom commands can be executed only on remote side
- Result = (FCurrentSide == osRemote) && EnableSelectedOperation[osRemote];
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TCustomScpExplorerForm::CustomCommandState(
- const AnsiString & Description, bool OnFocused)
- {
- AnsiString Command = WinConfiguration->CustomCommands->Values[Description];
- int Params = WinConfiguration->CustomCommands->Params[Description];
- return CustomCommandState(Command, Params, OnFocused);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
- AnsiString Name, AnsiString Command, int Params)
- {
- if (FLAGCLEAR(Params, ccLocal))
- {
- if (EnsureCommandSessionFallback(fcShellAnyCommand))
- {
- TRemoteCustomCommand RemoteCustomCommand;
- TWinInteractiveCustomCommand InteractiveCustomCommand(
- &RemoteCustomCommand, Name);
- Command = InteractiveCustomCommand.Complete(Command, false);
- bool Capture = FLAGSET(Params, ccShowResults) || FLAGSET(Params, ccCopyResults);
- TCaptureOutputEvent OutputEvent = NULL;
- assert(FCapturedLog == NULL);
- if (Capture)
- {
- FCapturedLog = new TStringList();
- OutputEvent = TerminalCaptureLog;
- }
- try
- {
- if (!RemoteCustomCommand.IsFileCommand(Command))
- {
- // Complete just replaces !! with !
- Terminal->AnyCommand(RemoteCustomCommand.Complete(Command, true),
- OutputEvent);
- }
- else
- {
- Terminal->CustomCommandOnFiles(Command, Params, FileList, OutputEvent);
- }
- if ((FCapturedLog != NULL) && (FCapturedLog->Count > 0))
- {
- if (FLAGSET(Params, ccCopyResults))
- {
- CopyToClipboard(FCapturedLog);
- }
- if (FLAGSET(Params, ccShowResults))
- {
- DoConsoleDialog(Terminal, "", FCapturedLog);
- }
- }
- }
- __finally
- {
- SAFE_DESTROY(FCapturedLog);
- }
- }
- }
- else
- {
- TLocalCustomCommand LocalCustomCommand;
- TWinInteractiveCustomCommand InteractiveCustomCommand(
- &LocalCustomCommand, Name);
- Command = InteractiveCustomCommand.Complete(Command, false);
- if (!LocalCustomCommand.IsFileCommand(Command))
- {
- // Complete just replaces !! with !
- ExecuteShellAndWait(LocalCustomCommand.Complete(Command, true));
- }
- else
- {
- TStrings * LocalFileList = NULL;
- TStrings * RemoteFileList = NULL;
- try
- {
- bool FileListCommand = LocalCustomCommand.IsFileListCommand(Command);
- bool LocalFileCommand = LocalCustomCommand.HasLocalFileName(Command);
- if (LocalFileCommand)
- {
- assert(HasDirView[osLocal]);
- assert(EnableSelectedOperation[osLocal]);
- LocalFileList = DirView(osLocal)->CreateFileList(false, true, NULL);
- if (FileListCommand)
- {
- if (LocalFileList->Count != 1)
- {
- throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH1));
- }
- }
- else
- {
- if ((LocalFileList->Count != 1) &&
- (FileList->Count != 1) &&
- (LocalFileList->Count != FileList->Count))
- {
- throw Exception(LoadStr(CUSTOM_COMMAND_SELECTED_UNMATCH));
- }
- }
- }
- AnsiString TempDir;
- TemporarilyDownloadFiles(FileList, false, TempDir, false, false);
- try
- {
- RemoteFileList = new TStringList();
- TMakeLocalFileListParams MakeFileListParam;
- MakeFileListParam.FileList = RemoteFileList;
- MakeFileListParam.IncludeDirs = FLAGSET(Params, ccApplyToDirectories);
- MakeFileListParam.Recursive =
- FLAGSET(Params, ccRecursive) && !FileListCommand;
- ProcessLocalDirectory(TempDir, Terminal->MakeLocalFileList, &MakeFileListParam);
- TFileOperationProgressType Progress(&OperationProgress, &OperationFinished);
- Progress.Start(foCustomCommand, osRemote, FileListCommand ? 1 : FileList->Count);
- assert(FProgressForm != NULL);
- FProgressForm->ReadOnly = true;
- try
- {
- if (FileListCommand)
- {
- AnsiString LocalFile;
- // MakeFileList does not delimit filenames
- AnsiString FileList = MakeFileList(RemoteFileList);
- if (LocalFileCommand)
- {
- assert(LocalFileList->Count == 1);
- LocalFile = LocalFileList->Strings[0];
- }
- TLocalCustomCommand CustomCommand("", LocalFile, FileList);
- ExecuteShellAndWait(CustomCommand.Complete(Command, true));
- }
- else if (LocalFileCommand)
- {
- if (LocalFileList->Count == 1)
- {
- AnsiString LocalFile = LocalFileList->Strings[0];
- for (int Index = 0; Index < RemoteFileList->Count; Index++)
- {
- AnsiString FileName = RemoteFileList->Strings[Index];
- TLocalCustomCommand CustomCommand
- (FileName, LocalFile, "");
- ExecuteShellAndWait(CustomCommand.Complete(Command, true));
- }
- }
- else if (RemoteFileList->Count == 1)
- {
- AnsiString FileName = RemoteFileList->Strings[0];
- for (int Index = 0; Index < LocalFileList->Count; Index++)
- {
- TLocalCustomCommand CustomCommand
- (FileName, LocalFileList->Strings[Index], "");
- ExecuteShellAndWait(CustomCommand.Complete(Command, true));
- }
- }
- else
- {
- if (LocalFileList->Count != RemoteFileList->Count)
- {
- throw Exception(LoadStr(CUSTOM_COMMAND_PAIRS_DOWNLOAD_FAILED));
- }
- for (int Index = 0; Index < LocalFileList->Count; Index++)
- {
- AnsiString FileName = RemoteFileList->Strings[Index];
- TLocalCustomCommand CustomCommand
- (FileName, LocalFileList->Strings[Index], "");
- ExecuteShellAndWait(CustomCommand.Complete(Command, true));
- }
- }
- }
- else
- {
- for (int Index = 0; Index < RemoteFileList->Count; Index++)
- {
- TLocalCustomCommand CustomCommand
- (RemoteFileList->Strings[Index], "", "");
- ExecuteShellAndWait(CustomCommand.Complete(Command, true));
- }
- }
- }
- __finally
- {
- Progress.Stop();
- }
- }
- __finally
- {
- RecursiveDeleteFile(ExcludeTrailingBackslash(TempDir), false);
- }
- }
- __finally
- {
- delete RemoteFileList;
- delete LocalFileList;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalCaptureLog(
- const AnsiString & AddedLine, bool /*StdError*/)
- {
- assert(FCapturedLog != NULL);
- FCapturedLog->Add(AddedLine);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::IsFileControl(TObject * Control,
- TOperationSide Side)
- {
- return (Side == osRemote) &&
- ((Control == RemoteDirView) || (Control == RemoteDriveView));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
- TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
- {
- TListItem * Item = RemoteDirView->ItemFocused;
- if ((RemoteDirView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
- RemoteDirView->AnyFileSelected(true, false))
- {
- TPoint ScreenPoint, ClientPoint;
- ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
- TPoint(0, 0) : MousePos;
- ScreenPoint = RemoteDirView->ClientToScreen(ClientPoint);
- #define DEFAULTITEM(ITEM, DEFAULT) \
- { \
- TTBItemOptions O; \
- O = NonVisualDataModule->ITEM->Options; \
- if ((DEFAULT) && Terminal->ResolvingSymlinks && \
- !RemoteDirView->ItemIsDirectory(Item)) \
- NonVisualDataModule->ITEM->Options = O << tboDefault; \
- else \
- NonVisualDataModule->ITEM->Options = O >> tboDefault; \
- }
- DEFAULTITEM(CurrentOpenMenuItem, WinConfiguration->DoubleClickAction == dcaOpen);
- DEFAULTITEM(CurrentEditMenuItem, WinConfiguration->DoubleClickAction == dcaEdit);
- DEFAULTITEM(CurrentCopyMenuItem, WinConfiguration->DoubleClickAction == dcaCopy);
- #undef DEFAULTITEM
- NonVisualDataModule->CurrentOpenMenuItem->Visible = WinConfiguration->ExpertMode;
- NonVisualDataModule->CurrentEditMenuItem->Visible = WinConfiguration->ExpertMode;
- reinterpret_cast<TPopupMenu*>(GetComponent(fcRemotePopup))->Popup(
- ScreenPoint.x, ScreenPoint.y);
- }
- Handled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ReloadLocalDirectory(const AnsiString Directory)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::BatchStart(void *& /*Storage*/)
- {
- assert(FErrorList == NULL);
- if (WinConfiguration->ContinueOnError)
- {
- FErrorList = new TStringList();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::BatchEnd(void * /*Storage*/)
- {
- if (FErrorList)
- {
- HandleErrorList(FErrorList);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
- TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
- {
- void * BatchStorage;
- BatchStart(BatchStorage);
- try
- {
- if ((Operation == foCopy) || (Operation == foMove))
- {
- TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
- TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
- AnsiString TargetDirectory;
- bool Temp = false;
- bool DragDrop = false;
- if (Param != NULL)
- {
- TTransferOperationParam& TParam =
- *static_cast<TTransferOperationParam*>(Param);
- TargetDirectory = TParam.TargetDirectory;
- Temp = TParam.Temp;
- DragDrop = TParam.DragDrop;
- }
- TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
- if (CopyParamDialog(Direction, Type, Temp, FileList, TargetDirectory,
- CopyParam, !NoConfirmation, DragDrop))
- {
- assert(Terminal);
- bool SelectionRestored = false;
- TCustomDirView * DView = NULL;
- if (HasDirView[Side])
- {
- DView = DirView(Side);
- DView->SaveSelection();
- DView->SaveSelectedNames();
- }
- try
- {
- if (Side == osLocal)
- {
- int Params =
- FLAGMASK(Operation == foMove, cpDelete) |
- FLAGMASK(CopyParam.NewerOnly, cpNewerOnly) |
- FLAGMASK(Temp, cpTemporary);
- Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params);
- if (Operation == foMove)
- {
- ReloadLocalDirectory();
- if (DView != NULL)
- {
- DView->RestoreSelection();
- }
- SelectionRestored = true;
- }
- }
- else
- {
- try
- {
- int Params =
- (Operation == foMove ? cpDelete : 0) |
- (CopyParam.NewerOnly ? cpNewerOnly : 0);
- Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam,
- Params);
- }
- __finally
- {
- if (Operation == foMove)
- {
- if (DView != NULL)
- {
- DView->RestoreSelection();
- }
- SelectionRestored = true;
- }
- ReloadLocalDirectory(TargetDirectory);
- }
- }
- }
- __finally
- {
- if (!SelectionRestored && (DView != NULL))
- {
- DView->DiscardSavedSelection();
- }
- }
- }
- }
- else if (Operation == foRename)
- {
- assert(DirView(Side)->ItemFocused);
- DirView(Side)->ItemFocused->EditCaption();
- }
- else if (Operation == foDelete)
- {
- assert(FileList->Count);
- bool Recycle;
- if (Side == osLocal)
- {
- Recycle = WinConfiguration->DeleteToRecycleBin;
- }
- else
- {
- Recycle = Terminal->SessionData->DeleteToRecycleBin &&
- !Terminal->IsRecycledFile(FileList->Strings[0]);
- }
- bool Confirmed =
- !(Recycle ? WinConfiguration->ConfirmRecycling : WinConfiguration->ConfirmDeleting);
- if (!Confirmed)
- {
- AnsiString Query;
- if (FileList->Count == 1)
- {
- if (Side == osLocal)
- {
- Query = ExtractFileName(FileList->Strings[0]);
- }
- else
- {
- Query = UnixExtractFileName(FileList->Strings[0]);
- }
- Query = FMTLOAD(
- (Recycle ? CONFIRM_RECYCLE_FILE : CONFIRM_DELETE_FILE), (Query));
- }
- else
- {
- Query = FMTLOAD(
- (Recycle ? CONFIRM_RECYCLE_FILES : CONFIRM_DELETE_FILES), (FileList->Count));
- }
- TMessageParams Params(mpNeverAskAgainCheck);
- int Answer = MessageDialog(Query, qtConfirmation,
- qaOK | qaCancel, HELP_NONE, &Params);
- if (Answer == qaNeverAskAgain)
- {
- Confirmed = true;
- if (Recycle)
- {
- WinConfiguration->ConfirmRecycling = false;
- }
- else
- {
- WinConfiguration->ConfirmDeleting = false;
- }
- }
- else
- {
- Confirmed = (Answer == qaOK);
- }
- }
- if (Confirmed) DeleteFiles(Side, FileList);
- }
- else if (Operation == foSetProperties)
- {
- RemoteDirView->SaveSelectedNames();
- SetProperties(Side, FileList);
- }
- else if (Operation == foCustomCommand)
- {
- assert(Param);
- assert(Side == osRemote);
- RemoteDirView->SaveSelectedNames();
- TCustomCommandParam * AParam = static_cast<TCustomCommandParam*>(Param);
- CustomCommand(FileList, AParam->Name, AParam->Command, AParam->Params);
- }
- else if ((Operation == foRemoteMove) || (Operation == foRemoteCopy))
- {
- assert(Side == osRemote);
- RemoteTransferFiles(FileList, NoConfirmation, (Operation == foRemoteMove));
- }
- else
- {
- assert(false);
- }
- }
- __finally
- {
- BatchEnd(BatchStorage);
- }
- }
- //---------------------------------------------------------------------------
- TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
- {
- if (Side == osCurrent)
- {
- Side = FCurrentSide;
- }
- return Side;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
- TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
- {
- Side = GetSide(Side);
- TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
- try
- {
- ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
- }
- __finally
- {
- delete FileList;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
- {
- try
- {
- if (ErrorList->Count)
- {
- if (MessageDialog(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)), qtError,
- qaOK | qaCancel, HELP_NONE) == qaOK)
- {
- int Answer;
- int Index = 0;
- do
- {
- assert(Index >= 0 && Index < ErrorList->Count);
- TQueryButtonAlias Aliases[2];
- Aliases[0].Button = qaYes;
- Aliases[0].Alias = LoadStr(PREV_BUTTON);
- Aliases[1].Button = qaNo;
- Aliases[1].Alias = LoadStr(NEXT_BUTTON);
- TMessageParams Params;
- Params.Aliases = Aliases;
- Params.AliasesCount = LENOF(Aliases);
- Answer = MoreMessageDialog(
- FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
- dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
- (Index ? qaYes : 0) | (Index < ErrorList->Count - 1 ? qaNo : 0) |
- qaOK, HELP_NONE, &Params);
- if (Answer == qaNo)
- {
- Index++;
- }
- if (Answer == qaYes)
- {
- Index--;
- }
- }
- while (Answer != qaOK);
- }
- }
- }
- __finally
- {
- TStrings * List = ErrorList;
- ErrorList = NULL;
- for (int i = 0; i < List->Count; i++)
- {
- delete List->Objects[i];
- }
- delete List;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::EditNew(TOperationSide Side)
- {
- assert(!WinConfiguration->DisableOpenEdit);
- Side = GetSide(Side);
- AnsiString Name = LoadStr(NEW_FILE);
- if (InputDialog(LoadStr(NEW_FILE_CAPTION), LoadStr(NEW_FILE_PROMPT), Name,
- HELP_EDIT_NEW))
- {
- AnsiString TargetFileName;
- AnsiString LocalFileName;
- AnsiString TempDir;
- if (Side == osRemote)
- {
- TempDir = WinConfiguration->TemporaryDir();
- if (!ForceDirectories(TempDir))
- {
- throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TempDir)));
- }
- TargetFileName = UnixExtractFileName(Name);
- LocalFileName = TempDir +
- GUIConfiguration->CurrentCopyParam.ChangeFileName(TargetFileName, osRemote, false);
- }
- else
- {
- if (ExtractFilePath(Name).IsEmpty())
- {
- LocalFileName = IncludeTrailingBackslash(DirView(Side)->PathName) + Name;
- }
- else
- {
- LocalFileName = ExpandFileName(Name);
- }
- TargetFileName = ExtractFileName(Name);
- }
- if (!FileExists(LocalFileName))
- {
- int File = FileCreate(LocalFileName);
- if (File < 0)
- {
- if (!TempDir.IsEmpty())
- {
- RemoveDir(TempDir);
- }
- throw Exception(FMTLOAD(CREATE_FILE_ERROR, (LocalFileName)));
- }
- else
- {
- FileClose(File);
- }
- }
- TExecuteFileBy ExecuteFileBy = efDefaultEditor;
- const TEditorPreferences * ExternalEditor = NULL;
- TFileMasks::TParams MaskParams; // size not known
- ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, TargetFileName,
- false, MaskParams);
- CustomExecuteFile(Side, ExecuteFileBy, LocalFileName, TargetFileName,
- ExternalEditor);
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::RemoteExecuteForceText(
- TExecuteFileBy ExecuteFileBy, const TEditorPreferences * ExternalEditor)
- {
- assert((ExecuteFileBy == efExternalEditor) ==
- ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
- assert(ExecuteFileBy != efDefaultEditor);
- return
- ((ExecuteFileBy == efInternalEditor)) ||
- ((ExecuteFileBy == efExternalEditor) && ExternalEditor->Data.ExternalEditorText);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
- TExecuteFileBy ExecuteFileBy, AnsiString FileName, AnsiString OriginalFileName,
- const TEditorPreferences * ExternalEditor)
- {
- assert(!WinConfiguration->DisableOpenEdit);
- assert((ExecuteFileBy == efExternalEditor) ==
- ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
- assert(ExecuteFileBy != efDefaultEditor);
- Side = GetSide(Side);
- TEditedFileData Data;
- if (Side == osRemote)
- {
- Data.Terminal = Terminal;
- Data.Queue = Queue;
- Data.ForceText = RemoteExecuteForceText(ExecuteFileBy, ExternalEditor);
- Data.RemoteDirectory = RemoteDirView->PathName;
- Data.SessionName = Terminal->SessionData->SessionName;
- Data.OriginalFileName = OriginalFileName;
- Data.Command = ""; // will be changed later for external editor
- }
- bool SingleEditor = WinConfiguration->Editor.SingleEditor;
- TOperationStatusForm * StatusForm = NULL;
- try
- {
- bool CloseFlag = false;
- bool * PCloseFlag = NULL;
- if ((Side == osRemote) && SingleEditor)
- {
- StatusForm = new TOperationStatusForm(Application);
- StatusForm->Status = LoadStr(DOCUMENT_WAIT);
- StatusForm->ShowAsModal();
- PCloseFlag = &CloseFlag;
- }
- if (ExecuteFileBy == efInternalEditor)
- {
- if (Side == osRemote)
- {
- AnsiString Caption = RemoteDirView->Path + OriginalFileName +
- " - " + Terminal->SessionData->SessionName;
- TForm * Editor = ShowEditorForm(FileName, this, FEditorManager->FileChanged,
- FEditorManager->FileReload, FEditorManager->FileClosed, Caption, !SingleEditor);
- FEditorManager->AddFileInternal(FileName, Data, PCloseFlag, Editor);
- }
- else
- {
- ShowEditorForm(FileName, this, NULL, NULL, NULL, "", true);
- }
- }
- else
- {
- HANDLE Process;
- if (ExecuteFileBy == efExternalEditor)
- {
- AnsiString Program, Params, Dir;
- Data.Command = ExternalEditor->Data.ExternalEditor;
- ReformatFileNameCommand(Data.Command);
- SplitCommand(Data.Command, Program, Params, Dir);
- Params = ExpandFileNameCommand(Params, FileName);
- if (!ExecuteShell(Program, Params, Process))
- {
- throw Exception(FMTLOAD(EDITOR_ERROR, (Program)));
- }
- }
- else
- {
- assert(Side == osRemote);
- if (!ExecuteShell(FileName, "", Process))
- {
- throw Exception(FMTLOAD(EXECUTE_FILE_ERROR, (FileName)));
- }
- }
- if ((Side == osLocal) ||
- ((ExecuteFileBy == efExternalEditor) && !SingleEditor &&
- ExternalEditor->Data.MDIExternalEditor))
- {
- // no need for handle
- if (Process != NULL)
- {
- CHECK(CloseHandle(Process));
- }
- Process = INVALID_HANDLE_VALUE;
- }
- else
- {
- if (Process == NULL)
- {
- throw Exception(LoadStr(OPEN_FILE_NO_PROCESS2));
- }
- }
- if (Side == osRemote)
- {
- FEditorManager->AddFileExternal(FileName, Data, PCloseFlag, Process);
- }
- }
- if (StatusForm != NULL)
- {
- do
- {
- Application->HandleMessage();
- }
- while (!Application->Terminated && !CloseFlag);
- }
- }
- __finally
- {
- if (StatusForm != NULL)
- {
- delete StatusForm;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TemporarilyDownloadFiles(
- TStrings * FileList, bool ForceText, AnsiString & TempDir, bool AllFiles,
- bool GetTargetNames)
- {
- TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
- if (ForceText)
- {
- CopyParam.TransferMode = tmAscii;
- }
- // do not forget to add additional options to ExecutedFileChanged, FAR and SS
- CopyParam.FileNameCase = ncNoChange;
- CopyParam.PreserveReadOnly = false;
- CopyParam.ResumeSupport = rsOff;
- CopyParam.ReplaceInvalidChars = true;
- CopyParam.FileMask = "";
- if (AllFiles)
- {
- CopyParam.ExcludeFileMask = TFileMasks();
- }
- if (TempDir.IsEmpty())
- {
- TempDir = WinConfiguration->TemporaryDir();
- if (!ForceDirectories(TempDir))
- {
- throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TempDir)));
- }
- }
- FAutoOperation = true;
- Terminal->ExceptionOnFail = true;
- try
- {
- try
- {
- // turn off confirmations, as for MDI editors we may possibly download
- // the same file over
- Terminal->CopyToLocal(FileList, TempDir, &CopyParam,
- cpNoConfirmation | cpTemporary);
- if (GetTargetNames)
- {
- for (int i = 0; i < FileList->Count; i++)
- {
- FileList->Strings[i] =
- CopyParam.ChangeFileName(UnixExtractFileName(FileList->Strings[i]), osRemote, false);
- }
- }
- }
- catch(...)
- {
- try
- {
- RecursiveDeleteFile(ExcludeTrailingBackslash(TempDir), false);
- }
- catch(...)
- {
- }
- throw;
- }
- }
- __finally
- {
- FAutoOperation = false;
- Terminal->ExceptionOnFail = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecuteFileNormalize(
- TExecuteFileBy & ExecuteFileBy, const TEditorPreferences *& ExternalEditor,
- const AnsiString & FileName, bool Local, const TFileMasks::TParams & MaskParams)
- {
- if (ExecuteFileBy == efDefaultEditor)
- {
- ExternalEditor = WinConfiguration->DefaultEditorForFile(FileName, Local, MaskParams);
- if ((ExternalEditor == NULL) || (ExternalEditor->Data.Editor == edInternal))
- {
- ExecuteFileBy = efInternalEditor;
- ExternalEditor = NULL;
- }
- else
- {
- ExecuteFileBy = efExternalEditor;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
- TExecuteFileBy ExecuteFileBy, const TEditorPreferences * ExternalEditor,
- bool AllSelected, bool OnFocused)
- {
- assert(!WinConfiguration->DisableOpenEdit);
- assert((ExecuteFileBy == efExternalEditor) ==
- ((ExternalEditor != NULL) && (ExternalEditor->Data.Editor == edExternal)));
- Side = GetSide(Side);
- TCustomDirView * DView = DirView(Side);
- if (WinConfiguration->Editor.SingleEditor)
- {
- AllSelected = false;
- }
- TStrings * FileList = AllSelected ?
- DView->CreateFileList(OnFocused, Side == osLocal) :
- DView->CreateFocusedFileList(Side == osLocal);
- try
- {
- assert(AllSelected || (FileList->Count == 1));
- for (int i = 0; i < FileList->Count; i++)
- {
- AnsiString ListFileName = FileList->Strings[i];
- AnsiString FileNameOnly = (Side == osRemote) ?
- UnixExtractFileName(ListFileName) : ExtractFileName(ListFileName);
- TListItem * Item = DView->FindFileItem(FileNameOnly);
- if (!DView->ItemIsDirectory(Item))
- {
- AnsiString OriginalFileName;
- AnsiString FullFileName;
- AnsiString FileName;
- if (Side == osRemote)
- {
- OriginalFileName = ListFileName;
- FullFileName = RemoteDirView->Path + ListFileName;
- }
- else
- {
- OriginalFileName = ExtractFileName(ListFileName);
- FullFileName = ListFileName;
- }
- TFileMasks::TParams MaskParams;
- MaskParams.Size = DView->ItemFileSize(Item);
- ExecuteFileNormalize(ExecuteFileBy, ExternalEditor, FullFileName,
- (Side == osLocal), MaskParams);
- if (Side == osRemote)
- {
- TObject * Token = NULL;
- AnsiString TempDir; // path to already edited file in MDI editor
- if (!FEditorManager->CanAddFile(RemoteDirView->PathName, OriginalFileName,
- Terminal->SessionData->SessionName, Token, TempDir))
- {
- if (Token != NULL)
- {
- TForm * Form = dynamic_cast<TForm *>(Token);
- Form->SetFocus();
- Abort();
- }
- else
- {
- throw Exception(FMTLOAD(ALREADY_EDITED_EXTERNALLY, (OriginalFileName)));
- }
- }
- TStringList * FileList1 = new TStringList();
- try
- {
- FileList1->AddObject(ListFileName, FileList->Objects[i]);
- TemporarilyDownloadFiles(FileList1,
- RemoteExecuteForceText(ExecuteFileBy, ExternalEditor), TempDir, true, true);
- FileName = TempDir + FileList1->Strings[0];
- }
- __finally
- {
- delete FileList1;
- }
- }
- else
- {
- FileName = FileList->Strings[i];
- }
- CustomExecuteFile(Side, ExecuteFileBy, FileName, OriginalFileName, ExternalEditor);
- }
- }
- }
- __finally
- {
- delete FileList;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(const AnsiString FileName,
- const TEditedFileData & Data, HANDLE UploadCompleteEvent)
- {
- if ((Data.Terminal == NULL) || !Data.Terminal->Active)
- {
- throw Exception(FMTLOAD(EDIT_SESSION_CLOSED,
- (ExtractFileName(FileName), Data.SessionName)));
- }
- TStrings * FileList = new TStringList();
- try
- {
- FileList->Add(FileName);
- // consider using the same settings (preset) as when the file was downloaded
- TGUICopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
- if (Data.ForceText)
- {
- CopyParam.TransferMode = tmAscii;
- }
- // do not forget to add additional options to TemporarilyDownloadFiles, FAR and SS
- CopyParam.FileNameCase = ncNoChange;
- CopyParam.PreserveRights = false;
- CopyParam.ResumeSupport = rsOff;
- // so i do not need to worry if masking algorithm works in all cases
- // ("" means "copy file name", no masking is actually done)
- if (ExtractFileName(FileName) == Data.OriginalFileName)
- {
- CopyParam.FileMask = "";
- }
- else
- {
- CopyParam.FileMask = DelimitFileNameMask(Data.OriginalFileName);
- }
- CopyParam.ReplaceInvalidChars = true; // not used for uploads anyway
- CopyParam.ExcludeFileMask = TFileMasks();
- if (WinConfiguration->Editor.SingleEditor)
- {
- FAutoOperation = true;
- Data.Terminal->ExceptionOnFail = true;
- try
- {
- Data.Terminal->CopyToRemote(FileList, RemoteDirView->PathName,
- &CopyParam, cpNoConfirmation | cpTemporary);
- }
- __finally
- {
- FAutoOperation = false;
- Data.Terminal->ExceptionOnFail = false;
- if (UploadCompleteEvent != INVALID_HANDLE_VALUE)
- {
- SetEvent(UploadCompleteEvent);
- }
- }
- }
- else
- {
- assert(Queue != NULL);
- int Params = cpNoConfirmation | cpTemporary;
- TQueueItem * QueueItem = new TUploadQueueItem(Data.Terminal, FileList,
- Data.RemoteDirectory, &CopyParam, Params);
- QueueItem->CompleteEvent = UploadCompleteEvent;
- Data.Queue->AddItem(QueueItem);
- }
- }
- __finally
- {
- delete FileList;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecutedFileReload(
- const AnsiString FileName, const TEditedFileData & Data)
- {
- if ((Data.Terminal == NULL) || !Data.Terminal->Active)
- {
- throw Exception(FMTLOAD(EDIT_SESSION_CLOSED_RELOAD,
- (ExtractFileName(FileName), Data.SessionName)));
- }
- TStrings * FileList = new TStringList();
- try
- {
- AnsiString RemoteFileName =
- UnixIncludeTrailingBackslash(Data.RemoteDirectory) + Data.OriginalFileName;
- TRemoteFile * File = NULL;
- FTerminal->ExceptionOnFail = true;
- try
- {
- FTerminal->ReadFile(RemoteFileName, File);
- if (!File->HaveFullFileName)
- {
- File->FullFileName = RemoteFileName;
- }
- }
- __finally
- {
- FTerminal->ExceptionOnFail = false;
- }
- FileList->AddObject(RemoteFileName, File);
- AnsiString TempDir = ExtractFilePath(FileName);
- TemporarilyDownloadFiles(FileList, Data.ForceText, TempDir, true, true);
- // sanity check, the target file name should be still the same
- assert(ExtractFileName(FileName) == FileList->Strings[0]);
- }
- __finally
- {
- delete FileList;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecutedFileEarlyClosed(
- const TEditedFileData & Data, bool * CloseFlag, bool & KeepOpen)
- {
- // CloseFlag is set for single editors only.
- if (CloseFlag == NULL)
- {
- // Command is set for external editors only (not for "shell" open).
- if (!Data.Command.IsEmpty())
- {
- bool AnyFound = false;
- bool AnyMDI = false;
- bool AnyNonMDI = false;
- bool AnyDetect = false;
- TEditorList * EditorList = new TEditorList();
- try
- {
- *EditorList = *WinConfiguration->EditorList;
- for (int i = 0; i < EditorList->Count; i++)
- {
- const TEditorPreferences * Editor = EditorList->Editors[i];
- if ((Editor->Data.Editor == edExternal) &&
- (Editor->Data.ExternalEditor == Data.Command))
- {
- AnyFound = true;
- if (!Editor->Data.MDIExternalEditor)
- {
- AnyNonMDI = true;
- if (Editor->Data.DetectMDIExternalEditor)
- {
- AnyDetect = true;
- }
- }
- else
- {
- AnyMDI = true;
- }
- }
- }
- bool EnableMDI = false;
- bool DisableDetect = false;
- if (AnyMDI)
- {
- KeepOpen = true;
- if (AnyNonMDI)
- {
- // there is at least one instance of the editor with MDI support enabled,
- // and one with disabled, enable it for all instances
- EnableMDI = true;
- }
- }
- else if (AnyFound && !AnyDetect)
- {
- // at least once instance found but all have MDI autodetection disabled
- // => close the file (default action)
- }
- else
- {
- // no instance of the editor has MDI support enabled
- TMessageParams Params;
- if (AnyFound)
- {
- // there is at least one instance of the editor with enabled
- // MDI autodetection
- Params.Params |= mpNeverAskAgainCheck;
- }
- int Answer = MessageDialog(FMTLOAD(EDITOR_EARLY_CLOSED, (Data.OriginalFileName)), qtWarning,
- qaYes | qaNo, HELP_EDITOR_EARLY_CLOSED, &Params);
- switch (Answer)
- {
- case qaNeverAskAgain:
- DisableDetect = true;
- break;
- case qaNo:
- EnableMDI = true;
- KeepOpen = true;
- break;
- }
- }
- if (AnyFound && (EnableMDI || DisableDetect))
- {
- bool Changed = false;
- for (int i = 0; i < EditorList->Count; i++)
- {
- const TEditorPreferences * Editor = EditorList->Editors[i];
- if ((Editor->Data.Editor == edExternal) &&
- (Editor->Data.ExternalEditor == Data.Command) &&
- ((EnableMDI && !Editor->Data.MDIExternalEditor) ||
- (DisableDetect && Editor->Data.DetectMDIExternalEditor)))
- {
- Changed = true;
- TEditorPreferences * UpdatedEditor = new TEditorPreferences(*Editor);
- if (EnableMDI)
- {
- UpdatedEditor->Data.MDIExternalEditor = true;
- }
- if (DisableDetect)
- {
- UpdatedEditor->Data.DetectMDIExternalEditor = false;
- }
- EditorList->Change(i, UpdatedEditor);
- }
- }
- if (Changed)
- {
- WinConfiguration->EditorList = EditorList;
- }
- }
- }
- __finally
- {
- delete EditorList;
- }
- }
- else
- {
- // "open" case
- MessageDialog(FMTLOAD(APP_EARLY_CLOSED, (Data.OriginalFileName)), qtWarning,
- qaOK, HELP_APP_EARLY_CLOSED);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewEnter(TObject * /*Sender*/)
- {
- SideEnter(osRemote);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDriveViewEnter(TObject * /*Sender*/)
- {
- MakeNextInTabOrder(RemoteDirView, RemoteDriveView);
- SideEnter(osRemote);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SideEnter(TOperationSide Side)
- {
- FCurrentSide = Side;
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
- TStrings * FileList)
- {
- assert(Terminal);
- TCustomDirView * DView = DirView(Side);
- DView->SaveSelection();
- DView->SaveSelectedNames();
- try
- {
- if (Side == osRemote)
- {
- Terminal->DeleteFiles(FileList);
- }
- else
- {
- try
- {
- Terminal->DeleteLocalFiles(FileList);
- }
- __finally
- {
- ReloadLocalDirectory();
- }
- }
- }
- catch(...)
- {
- DView->DiscardSavedSelection();
- throw;
- }
- DView->RestoreSelection();
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TStrings * FileList,
- AnsiString & Target, AnsiString & FileMask, bool NoConfirmation, bool Move)
- {
- if (RemoteDriveView->DropTarget != NULL)
- {
- Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
- }
- else if (RemoteDirView->DropTarget != NULL)
- {
- assert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
- Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
- }
- else
- {
- Target = RemoteDirView->Path;
- }
- Target = UnixIncludeTrailingBackslash(Target);
- FileMask = "*.*";
- bool Result = true;
- if (!NoConfirmation)
- {
- Result = DoRemoteTransferDialog(FileList, Target, FileMask, Move);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteTransferFiles(
- TStrings * FileList, bool NoConfirmation, bool Move)
- {
- AnsiString Target, FileMask;
- if ((Move || EnsureCommandSessionFallback(fcRemoteCopy)) &&
- RemoteTransferDialog(FileList, Target, FileMask, NoConfirmation, Move))
- {
- RemoteDirView->SaveSelection();
- RemoteDirView->SaveSelectedNames();
- try
- {
- if (Move)
- {
- Terminal->MoveFiles(FileList, Target, FileMask);
- }
- else
- {
- Terminal->CopyFiles(FileList, Target, FileMask);
- }
- }
- catch(...)
- {
- RemoteDirView->DiscardSavedSelection();
- throw;
- }
- RemoteDirView->RestoreSelection();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
- {
- Side = GetSide(Side);
- TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
- TRemoteProperties * AProperties = (Side == osRemote ? &Properties : NULL);
- AnsiString Name = LoadStr(NEW_FOLDER);
- bool SaveSettings = false;
- if (DoCreateDirectoryDialog(Name, AProperties, SaveSettings))
- {
- if (Side == osRemote)
- {
- if (SaveSettings)
- {
- GUIConfiguration->NewDirectoryProperties = Properties;
- }
- RemoteDirView->CreateDirectoryEx(Name, &Properties);
- }
- else
- {
- DirView(Side)->CreateDirectory(Name);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
- {
- DoOpenDirectoryDialog(odBrowse, Side);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewGetSelectFilter(
- TCustomDirView *Sender, bool Select, TFileFilter &Filter)
- {
- assert(Sender);
- if (!DoSelectMaskDialog(Sender, Select, &Filter, Configuration)) Abort();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CalculateSizeEvent(
- TStrings * FileList, __int64 & Size, TCalculateSizeStats & Stats,
- bool & Close)
- {
- // terminal can be already closed (e.g. dropped connection)
- if (Terminal != NULL)
- {
- try
- {
- Terminal->CalculateFilesSize(FileList, Size, 0, NULL, &Stats);
- }
- catch(...)
- {
- if (!Terminal->Active)
- {
- Close = true;
- }
- throw;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CalculateChecksum(const AnsiString & Alg,
- TStrings * FileList, TCalculatedChecksumEvent OnCalculatedChecksum,
- bool & Close)
- {
- // terminal can be already closed (e.g. dropped connection)
- if (Terminal != NULL)
- {
- try
- {
- Terminal->CalculateFilesChecksum(Alg, FileList, NULL, OnCalculatedChecksum);
- }
- catch(...)
- {
- if (!Terminal->Active)
- {
- Close = true;
- }
- throw;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
- {
- if (Side == osRemote)
- {
- TRemoteProperties CurrentProperties;
- if (Terminal->LoadFilesProperties(FileList))
- {
- RemoteDirView->Invalidate();
- }
- CurrentProperties = TRemoteProperties::CommonProperties(FileList);
- int Flags = 0;
- if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
- if (Terminal->IsCapable[fcOwnerChanging]) Flags |= cpOwner;
- if (Terminal->IsCapable[fcGroupChanging]) Flags |= cpGroup;
- TCalculateChecksumEvent CalculateChecksumEvent = NULL;
- if (Terminal->IsCapable[fcCalculatingChecksum])
- {
- CalculateChecksumEvent = CalculateChecksum;
- }
- TRemoteProperties NewProperties = CurrentProperties;
- if (DoPropertiesDialog(FileList, RemoteDirView->PathName,
- Terminal->Groups, Terminal->Users, &NewProperties, Flags,
- CalculateSizeEvent, CalculateChecksumEvent))
- {
- NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
- Terminal->ChangeFilesProperties(FileList, &NewProperties);
- }
- }
- else
- {
- DirView(Side)->DisplayPropertiesMenu();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
- {
- if (QueueView->Focused() && (QueueView->OnKeyDown != NULL))
- {
- QueueView->OnKeyDown(QueueView, Key, Shift);
- }
- if (!DirView(osCurrent)->IsEditing())
- {
- TShortCut KeyShortCut = ShortCut(Key, Shift);
- for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
- {
- TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
- if (((Action->ShortCut == KeyShortCut) ||
- (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
- AllowedAction(Action, aaShortCut))
- {
- Key = 0;
- Action->Execute();
- return;
- }
- }
- for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
- {
- if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
- {
- FIgnoreNextSysCommand = true;
- TTerminalManager::Instance()->ActiveTerminalIndex = i;
- return;
- }
- }
- if (Key == VK_TAB && Shift.Contains(ssCtrl))
- {
- TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
- Key = 0;
- }
- }
- TForm::KeyDown(Key, Shift);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::InitStatusBar()
- {
- const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
- const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
- TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
- assert(Terminal);
- bool SecurityEnabled = !SessionInfo.SecurityProtocolName.IsEmpty();
- SessionStatusBar->Panels->Items[1]->Enabled = SecurityEnabled;
- // expanded from ?: to avoid memory leaks
- if (SecurityEnabled)
- {
- SessionStatusBar->Panels->Items[1]->Hint =
- FMTLOAD(STATUS_SECURE, (SessionInfo.SecurityProtocolName));
- }
- else
- {
- SessionStatusBar->Panels->Items[1]->Hint = LoadStr(STATUS_INSECURE);
- }
- if (FileSystemInfo.ProtocolName.IsEmpty())
- {
- SessionStatusBar->Panels->Items[2]->Caption = SessionInfo.ProtocolName;
- }
- else
- {
- SessionStatusBar->Panels->Items[2]->Caption = FileSystemInfo.ProtocolName;
- }
- SessionStatusBar->Panels->Items[2]->Hint = LoadStr(STATUS_PROTOCOL_HINT);
- SessionStatusBar->Panels->Items[3]->Enabled =
- (!SessionInfo.CSCompression.IsEmpty() || !SessionInfo.SCCompression.IsEmpty());
- if (SessionInfo.CSCompression == SessionInfo.SCCompression)
- {
- SessionStatusBar->Panels->Items[3]->Hint =
- FMTLOAD(STATUS_COMPRESSION_HINT, (DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR))));
- }
- else
- {
- SessionStatusBar->Panels->Items[3]->Hint = FMTLOAD(STATUS_COMPRESSION2_HINT,
- (DefaultStr(SessionInfo.CSCompression, LoadStr(NO_STR)),
- DefaultStr(SessionInfo.SCCompression, LoadStr(NO_STR))));
- }
- SessionStatusBar->Panels->Items[4]->Hint = LoadStr(STATUS_DURATION_HINT);
- UpdateStatusBar();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
- {
- TTBXStatusBar * SessionStatusBar = (TTBXStatusBar *)GetComponent(fcStatusBar);
- assert(SessionStatusBar != NULL);
- if (FShowStatusBarHint)
- {
- SessionStatusBar->SimplePanel = true;
- SessionStatusBar->SimpleText = FStatusBarHint;
- }
- else if (!Terminal || !Terminal->Active || Terminal->Status < ssOpened)
- {
- // note: (Terminal->Status < sshReady) currently never happens here,
- // so STATUS_CONNECTING is never used
- SessionStatusBar->SimplePanel = true;
- SessionStatusBar->SimpleText = LoadStr(
- !Terminal || !Terminal->Active ? STATUS_DISCONNECTED : STATUS_CONNECTING);
- }
- else
- {
- assert(Terminal);
- SessionStatusBar->SimplePanel = false;
- const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
- if (FNote.IsEmpty())
- {
- UpdateStatusPanelText(SessionStatusBar->Panels->Items[0]);
- }
- else
- {
- SessionStatusBar->Panels->Items[0]->Caption = FNote;
- }
- SessionStatusBar->Panels->Items[0]->Hint = FNoteHints;
- SessionStatusBar->Panels->Items[4]->Caption =
- FormatDateTimeSpan(Configuration->TimeFormat, Now() - SessionInfo.LoginTime);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateStatusPanelText(TTBXStatusPanel * Panel)
- {
- Panel->Caption = "";
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::Idle(bool AppIdle)
- {
- FEditorManager->Check();
- // make sure that Idle is called before update queue, as it may invoke QueueEvent
- // that needs to know is queue view is visible (and it may be closed after queue update)
- TTerminalManager::Instance()->Idle();
- if (AppIdle)
- {
- if (FRefreshRemoteDirectory)
- {
- if ((Terminal != NULL) && Terminal->Active)
- {
- Terminal->RefreshDirectory();
- }
- FRefreshRemoteDirectory = false;
- }
- if (FRefreshLocalDirectory)
- {
- ReloadLocalDirectory();
- FRefreshLocalDirectory = false;
- }
- }
- if (FQueueStatusInvalidated)
- {
- UpdateQueueStatus(AppIdle);
- }
- RefreshQueueItems(AppIdle);
- UpdateStatusBar();
- FIgnoreNextSysCommand = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UserActionTimer(TObject * /*Sender*/)
- {
- try
- {
- FUserActionTimer->Enabled = false;
- if (GUIConfiguration->QueueAutoPopup && (FPendingQueueActionItem != NULL))
- {
- if (TQueueItem::IsUserActionStatus(FPendingQueueActionItem->Status))
- {
- FPendingQueueActionItem->ProcessUserAction();
- }
- }
- }
- __finally
- {
- FPendingQueueActionItem = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ApplicationHint(TObject * /*Sender*/)
- {
- assert(Application);
- AnsiString AHint = GetLongHint(Application->Hint);
- FShowStatusBarHint = Active && !AHint.IsEmpty() && (AHint != "X");
- if (FShowStatusBarHint)
- {
- FStatusBarHint = AHint != "E" ? AHint : AnsiString("");
- }
- else
- {
- FStatusBarHint = "";
- }
- UpdateStatusBar();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ApplicationMinimize(TObject * /*Sender*/)
- {
- if (WinConfiguration->MinimizeToTray)
- {
- UpdateTrayIcon();
- FTrayIcon->Visible = true;
- ShowWindow(Application->Handle, SW_HIDE);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
- {
- if (FTrayIcon->Visible)
- {
- FTrayIcon->Visible = false;
- ShowWindow(Application->Handle, SW_SHOW);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateTrayIcon()
- {
- FTrayIcon->Hint = Application->Title;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ApplicationTitleChanged()
- {
- UpdateTrayIcon();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TrayIconClick(TObject * /*Sender*/)
- {
- Application->Restore();
- Application->BringToFront();
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::OpenInNewWindow()
- {
- // VK_SHIFT seems to indicate shift down even when it is not
- return (GetAsyncKeyState(VK_LSHIFT) != 0) || (GetAsyncKeyState(VK_RSHIFT) != 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::NewSession()
- {
- if (OpenInNewWindow())
- {
- if (!ExecuteShell(Application->ExeName, ""))
- {
- throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Application->ExeName)));
- }
- }
- else
- {
- TTerminalManager::Instance()->NewSession();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DuplicateSession()
- {
- TSessionData * SessionData = new TSessionData("");
- try
- {
- SessionData->Assign(Terminal->SessionData);
- // current working directories become defaults here, what is not right
- UpdateSessionData(SessionData);
- if (OpenInNewWindow())
- {
- AnsiString SessionName = StoredSessions->HiddenPrefix + "duplicate";
- StoredSessions->NewSession(SessionName, SessionData);
- // modified only, explicit
- StoredSessions->Save(false, true);
- if (!ExecuteShell(Application->ExeName, FORMAT("\"%s\"", (SessionName))))
- {
- throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Application->ExeName)));
- }
- }
- else
- {
- TTerminalManager * Manager = TTerminalManager::Instance();
- TTerminal * Terminal = Manager->NewTerminal(SessionData);
- Manager->ActiveTerminal = Terminal;
- Manager->ConnectActiveTerminal();
- }
- }
- __finally
- {
- delete SessionData;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
- {
- assert(FQueue != NULL);
- return (FQueue->IsEmpty ||
- (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS), qtWarning, qaOK | qaCancel, HELP_NONE) == qaOK));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CloseSession()
- {
- if (CanCloseQueue())
- {
- TTerminalManager::Instance()->FreeActiveTerminal();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
- {
- if (OpenInNewWindow())
- {
- if (!ExecuteShell(Application->ExeName, FORMAT("\"%s\"", (Data->Name))))
- {
- throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Application->ExeName)));
- }
- }
- else
- {
- TTerminalManager * Manager = TTerminalManager::Instance();
- TTerminal * Terminal = Manager->NewTerminal(Data);
- Manager->ActiveTerminal = Terminal;
- Manager->ConnectActiveTerminal();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
- bool &CanClose)
- {
- if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
- {
- int Result;
- TMessageParams Params(mpNeverAskAgainCheck);
- AnsiString Message;
- if (TTerminalManager::Instance()->Count > 1)
- {
- Message = LoadStr(CLOSE_SESSIONS);
- }
- else
- {
- Message = FMTLOAD(CLOSE_SESSION, (Terminal->SessionData->SessionName));
- }
- Result = MessageDialog(Message, qtConfirmation,
- qaOK | qaCancel, HELP_NONE, &Params);
- if (Result == qaNeverAskAgain)
- {
- WinConfiguration->ConfirmClosingSession = false;
- }
- CanClose = (Result == qaOK || Result == qaNeverAskAgain);
- }
- if (CanClose)
- {
- CanClose = CanCloseQueue();
- }
- if (CanClose)
- {
- CanClose = FEditorManager->CloseInternalEditors(CloseInternalEditor) &&
- FEditorManager->CloseExternalFilesWithoutProcess() &&
- (FEditorManager->Empty(true) ||
- (MessageDialog(LoadStr(PENDING_EDITORS), qtWarning, qaIgnore | qaCancel,
- HELP_NONE) == qaIgnore));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CloseInternalEditor(TObject * Sender)
- {
- TForm * Form = dynamic_cast<TForm *>(Sender);
- assert(Form != NULL);
- Form->Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ForceCloseInternalEditor(TObject * Sender)
- {
- TForm * Form = dynamic_cast<TForm *>(Sender);
- delete Form;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
- TObject *Sender)
- {
- TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
- try
- {
- SetProperties(osRemote, FileList);
- }
- __finally
- {
- delete FileList;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ComponentShowing(Word Component, bool value)
- {
- if (value)
- {
- if (Component == fcCustomCommandsBand)
- {
- UpdateCustomCommandsToolbar();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetComponentVisible(Word Component, Boolean value)
- {
- TControl * Control = GetComponent(Component);
- assert(Control);
- bool Changed = (Control->Visible != value);
- if (Changed)
- {
- ComponentShowing(Component, value);
- TWinControl * WinControl = dynamic_cast<TWinControl*>(Control);
- bool WasFocused = (WinControl != NULL) && (ActiveControl != NULL) &&
- ((ActiveControl == WinControl) || (ActiveControl->Parent == WinControl));
- if (value)
- {
- int RemainingHeight = Control->Parent->ClientHeight;
- int RemainingWidth = Control->Parent->ClientWidth;
- for (int i = 0; i < Control->Parent->ControlCount; i++)
- {
- TControl * ChildControl = Control->Parent->Controls[i];
- if (ChildControl->Visible)
- {
- switch (ChildControl->Align)
- {
- case alTop:
- case alBottom:
- RemainingHeight -= ChildControl->Height;
- break;
- case alLeft:
- case alRight:
- RemainingWidth -= ChildControl->Width;
- break;
- }
- }
- }
- static int Reserve = 32;
- // queue in explorer, trees in commander
- if (Control->Height > RemainingHeight - Reserve)
- {
- Control->Height = RemainingHeight / 2;
- }
- if (Control->Width > RemainingWidth - Reserve)
- {
- Control->Width = RemainingWidth / 2;
- }
- }
- Control->Visible = value;
- if (WasFocused && Visible)
- {
- DirView(osCurrent)->SetFocus();
- }
- FixControlsPlacement();
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Word Component)
- {
- TControl * Control = GetComponent(Component);
- if (Control == NULL)
- {
- return false;
- }
- else
- {
- return Control->Visible;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
- {
- if (RemoteDirView->ItemFocused != NULL)
- {
- RemoteDirView->ItemFocused->MakeVisible(false);
- }
- QueueSplitter->Visible = QueuePanel->Visible;
- RemotePanelSplitter->Visible = RemoteDriveView->Visible;
- }
- //---------------------------------------------------------------------------
- TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
- {
- switch (Component) {
- case fcStatusBar: return RemoteStatusBar;
- case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteFilePopup);
- case fcQueueView: return QueuePanel;
- case fcQueueToolbar: return QueueDock;
- case fcRemoteTree: return RemoteDriveView;
- default: return NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
- TObject *Sender, TListColumn *Column, TPoint &Point)
- {
- assert(NonVisualDataModule && Column && Sender);
- NonVisualDataModule->ListColumn = Column;
- TPoint ScreenPoint = ((TControl*)Sender)->ClientToScreen(Point);
- TPopupMenu * DirViewColumnMenu;
- if (Sender == RemoteDirView)
- {
- DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
- NonVisualDataModule->RemoteSortByExtColumnPopupItem->Visible =
- (Column->Index == uvName);
- }
- else
- {
- DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
- NonVisualDataModule->LocalSortByExtColumnPopupItem->Visible =
- (Column->Index == dvName);
- }
- DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewExecFile(
- TObject *Sender, TListItem *Item, bool &AllowExec)
- {
- DoDirViewExecFile(Sender, Item, AllowExec);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
- TListItem * Item, bool & AllowExec)
- {
- assert(Sender && Item && Configuration);
- assert(AllowExec);
- TCustomDirView * ADirView = (TCustomDirView *)Sender;
- bool Remote = (ADirView == DirView(osRemote));
- bool ResolvedSymlinks = !Remote || Terminal->ResolvingSymlinks;
- // Anything special is done on double click only (not on "open" indicated by FForceExecution),
- // on files only (not directories)
- // and only when symlinks are resolved (apply to remote panel only)
- if (!ADirView->ItemIsDirectory(Item) &&
- (ResolvedSymlinks || FForceExecution))
- {
- if ((WinConfiguration->DoubleClickAction != dcaOpen) &&
- !FForceExecution &&
- ResolvedSymlinks)
- {
- if (WinConfiguration->DoubleClickAction == dcaCopy)
- {
- ExecuteFileOperation(foCopy,
- (ADirView == DirView(osRemote) ? osRemote : osLocal),
- true, !WinConfiguration->CopyOnDoubleClickConfirmation);
- AllowExec = false;
- }
- else if (WinConfiguration->DoubleClickAction == dcaEdit)
- {
- if (!Remote || !WinConfiguration->DisableOpenEdit)
- {
- ExecuteFile(osCurrent, efDefaultEditor);
- AllowExec = false;
- }
- }
- else
- {
- assert(false);
- }
- }
- // if we have not done anything special, fall back to default behaviour
- if (AllowExec)
- {
- if (Remote && !WinConfiguration->DisableOpenEdit)
- {
- ExecuteFile(osRemote, efShell);
- AllowExec = false;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
- {
- return ((Side == osRemote) || (Side == osCurrent));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CompareDirectories()
- {
- assert(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
- {
- assert(false);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::DoSynchronizeDirectories(
- AnsiString & LocalDirectory, AnsiString & RemoteDirectory, bool UseDefaults)
- {
- TSynchronizeParamType Params;
- Params.LocalDirectory = LocalDirectory;
- Params.RemoteDirectory = RemoteDirectory;
- int UnusedParams =
- (GUIConfiguration->SynchronizeParams &
- (spPreviewChanges | spTimestamp | spNotByTime | spBySize));
- Params.Params = GUIConfiguration->SynchronizeParams & ~UnusedParams;
- Params.Options = GUIConfiguration->SynchronizeOptions;
- bool SaveSettings = false;
- TSynchronizeController Controller(&DoSynchronize, &DoSynchronizeInvalid,
- &DoSynchronizeTooManyDirectories);
- assert(FSynchronizeController == NULL);
- FSynchronizeController = &Controller;
- bool Result;
- try
- {
- TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
- int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).Upload;
- int Options =
- FLAGMASK(SynchronizeAllowSelectedOnly(), soAllowSelectedOnly);
- Result = DoSynchronizeDialog(Params, &CopyParam, Controller.StartStop,
- SaveSettings, Options, CopyParamAttrs, GetSynchronizeOptions, UseDefaults);
- if (Result)
- {
- if (SaveSettings)
- {
- GUIConfiguration->SynchronizeParams = Params.Params | UnusedParams;
- GUIConfiguration->SynchronizeOptions = Params.Options;
- }
- LocalDirectory = Params.LocalDirectory;
- RemoteDirectory = Params.RemoteDirectory;
- }
- }
- __finally
- {
- FSynchronizeController = NULL;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoSynchronize(
- TSynchronizeController * /*Sender*/, const AnsiString LocalDirectory,
- const AnsiString RemoteDirectory, const TCopyParamType & CopyParam,
- const TSynchronizeParamType & Params, TSynchronizeChecklist ** Checklist,
- TSynchronizeOptions * Options, bool Full)
- {
- try
- {
- int PParams = Params.Params;
- if (!Full)
- {
- PParams |= TTerminal::spNoRecurse | TTerminal::spUseCache |
- TTerminal::spDelayProgress | TTerminal::spSubDirs;
- }
- Synchronize(LocalDirectory, RemoteDirectory, smRemote, CopyParam,
- PParams, Checklist, Options);
- }
- catch(Exception & E)
- {
- ShowExtendedExceptionEx(Terminal, &E);
- throw;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoSynchronizeInvalid(
- TSynchronizeController * /*Sender*/, const AnsiString Directory,
- const AnsiString ErrorStr)
- {
- if (!Directory.IsEmpty())
- {
- SimpleErrorDialog(FMTLOAD(WATCH_ERROR_DIRECTORY, (Directory)), ErrorStr);
- }
- else
- {
- SimpleErrorDialog(LoadStr(WATCH_ERROR_GENERAL), ErrorStr);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoSynchronizeTooManyDirectories(
- TSynchronizeController * /*Sender*/, int & MaxDirectories)
- {
- if (MaxDirectories < GUIConfiguration->MaxWatchDirectories)
- {
- MaxDirectories = GUIConfiguration->MaxWatchDirectories;
- }
- else
- {
- TMessageParams Params(mpNeverAskAgainCheck);
- int Result = MessageDialog(
- FMTLOAD(TOO_MANY_WATCH_DIRECTORIES, (MaxDirectories, MaxDirectories)),
- qtConfirmation, qaYes | qaNo, HELP_TOO_MANY_WATCH_DIRECTORIES, &Params);
- if ((Result == qaYes) || (Result == qaNeverAskAgain))
- {
- MaxDirectories *= 2;
- if (Result == qaNeverAskAgain)
- {
- GUIConfiguration->MaxWatchDirectories = MaxDirectories;
- }
- }
- else
- {
- Abort();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::Synchronize(const AnsiString LocalDirectory,
- const AnsiString RemoteDirectory, TSynchronizeMode Mode,
- const TCopyParamType & CopyParam, int Params, TSynchronizeChecklist ** Checklist,
- TSynchronizeOptions * Options)
- {
- assert(!FAutoOperation);
- void * BatchStorage;
- BatchStart(BatchStorage);
- FAutoOperation = true;
- TSynchronizeChecklist * AChecklist = NULL;
- try
- {
- FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
- if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
- {
- FSynchronizeProgressForm->Start();
- }
- AChecklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
- static_cast<TTerminal::TSynchronizeMode>(Mode),
- &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
- Options);
- SAFE_DESTROY(FSynchronizeProgressForm);
- FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
- if (FLAGCLEAR(Params, TTerminal::spDelayProgress))
- {
- FSynchronizeProgressForm->Start();
- }
- Terminal->SynchronizeApply(AChecklist, LocalDirectory, RemoteDirectory,
- &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
- }
- __finally
- {
- if (Checklist == NULL)
- {
- delete AChecklist;
- }
- else
- {
- *Checklist = AChecklist;
- }
- FAutoOperation = false;
- SAFE_DESTROY(FSynchronizeProgressForm);
- BatchEnd(BatchStorage);
- ReloadLocalDirectory();
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::SynchronizeAllowSelectedOnly()
- {
- // can be called from command line
- return Visible &&
- ((DirView(osRemote)->SelCount > 0) ||
- (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0)));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::GetSynchronizeOptions(
- int Params, TSynchronizeOptions & Options)
- {
- if (FLAGSET(Params, spSelectedOnly) && SynchronizeAllowSelectedOnly())
- {
- Options.Filter = new TStringList();
- Options.Filter->CaseSensitive = false;
- Options.Filter->Duplicates = dupAccept;
- if (DirView(osRemote)->SelCount > 0)
- {
- DirView(osRemote)->CreateFileList(false, false, Options.Filter);
- }
- if (HasDirView[osLocal] && (DirView(osLocal)->SelCount > 0))
- {
- DirView(osLocal)->CreateFileList(false, false, Options.Filter);
- }
- Options.Filter->Sort();
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
- AnsiString & LocalDirectory, AnsiString & RemoteDirectory,
- TSynchronizeMode & Mode, bool & SaveMode, bool UseDefaults)
- {
- bool Result;
- int Params = GUIConfiguration->SynchronizeParams;
- bool SaveSettings = false;
- int Options =
- FLAGMASK(!Terminal->IsCapable[fcTimestampChanging], fsoDisableTimestamp) |
- FLAGMASK(SynchronizeAllowSelectedOnly(), fsoAllowSelectedOnly);
- TCopyParamType CopyParam = GUIConfiguration->CurrentCopyParam;
- TUsableCopyParamAttrs CopyParamAttrs = Terminal->UsableCopyParamAttrs(0);
- Result = UseDefaults ||
- DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
- &CopyParam, SaveSettings, SaveMode, Options, CopyParamAttrs);
- if (Result)
- {
- TSynchronizeOptions SynchronizeOptions;
- GetSynchronizeOptions(Params, SynchronizeOptions);
- if (SaveSettings)
- {
- GUIConfiguration->SynchronizeParams = Params;
- }
- else
- {
- SaveMode = false;
- }
- TDateTime StartTime = Now();
- TSynchronizeChecklist * Checklist = NULL;
- try
- {
- assert(!FAutoOperation);
- FAutoOperation = true;
- try
- {
- FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, true);
- FSynchronizeProgressForm->Start();
- Checklist = Terminal->SynchronizeCollect(LocalDirectory, RemoteDirectory,
- static_cast<TTerminal::TSynchronizeMode>(Mode),
- &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory,
- &SynchronizeOptions);
- }
- __finally
- {
- FAutoOperation = false;
- SAFE_DESTROY(FSynchronizeProgressForm);
- }
- if (Checklist->Count == 0)
- {
- MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
- HELP_SYNCHRONIZE_NO_DIFFERENCES);
- }
- else if (FLAGCLEAR(Params, spPreviewChanges) ||
- DoSynchronizeChecklistDialog(Checklist, Mode, Params,
- LocalDirectory, RemoteDirectory))
- {
- assert(!FAutoOperation);
- void * BatchStorage;
- BatchStart(BatchStorage);
- FAutoOperation = true;
- if (FLAGSET(Params, spPreviewChanges))
- {
- StartTime = Now();
- }
- try
- {
- FSynchronizeProgressForm = new TSynchronizeProgressForm(Application, true, false);
- FSynchronizeProgressForm->Start();
- Terminal->SynchronizeApply(Checklist, LocalDirectory, RemoteDirectory,
- &CopyParam, Params | spNoConfirmation, TerminalSynchronizeDirectory);
- }
- __finally
- {
- FAutoOperation = false;
- SAFE_DESTROY(FSynchronizeProgressForm);
- BatchEnd(BatchStorage);
- ReloadLocalDirectory();
- }
- }
- }
- __finally
- {
- delete Checklist;
- }
- OperationComplete(StartTime);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
- const AnsiString LocalDirectory, const AnsiString RemoteDirectory,
- bool & Continue, bool /*Collect*/)
- {
- assert(FSynchronizeProgressForm != NULL);
- if (!FSynchronizeProgressForm->Started)
- {
- FSynchronizeProgressForm->Start();
- }
- FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
- {
- assert(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
- {
- AnsiString SessionName;
- SessionName = Terminal->SessionData->SessionName;
- SessionName = DoSaveSessionDialog(SessionName, NULL);
- if (!SessionName.IsEmpty())
- {
- TSessionData * SessionData = new TSessionData("");
- try
- {
- SessionData->Assign(Terminal->SessionData);
- UpdateSessionData(SessionData);
- StoredSessions->NewSession(SessionName, SessionData);
- // modified only, explicit
- StoredSessions->Save(false, true);
- }
- __finally
- {
- delete SessionData;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateTerminal(TTerminal * Terminal)
- {
- TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(FTerminal);
- assert(ManagedTerminal != NULL);
- SAFE_DESTROY(ManagedTerminal->RemoteExplorerState);
- if (WinConfiguration->PreservePanelState)
- {
- ManagedTerminal->RemoteExplorerState = RemoteDirView->SaveState();
- }
- // cannot use RemoteDirView->Path, because it is empty if connection
- // was already closed
- ManagedTerminal->RemoteDirectory = Terminal->CurrentDirectory;
- ManagedTerminal->Color = SessionColor;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
- {
- assert(Data != NULL);
- // cannot use RemoteDirView->Path, because it is empty if connection
- // was already closed
- Data->RemoteDirectory = Terminal->CurrentDirectory;
- Data->Color = SessionColor;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
- {
- TTBXToolbar * ToolBar = dynamic_cast<TTBXToolbar*>(Sender);
- assert(ToolBar != NULL);
- if (ToolBar->Items->Count == 1)
- {
- TTBControlItem * Item = dynamic_cast<TTBControlItem *>(ToolBar->Items->Items[0]);
- assert(Item != NULL);
- // seems that Item->Control can be NULL when closing window
- if (Item->Control != NULL)
- {
- Item->Control->Width = ToolBar->Width - ToolBar->NonClientWidth;
- }
- }
- else
- {
- int ControlWidth;
- TControl * ResizeControl = NULL;
- TTBXComboBoxItem * ResizeComboBox = NULL;
- for (int i = 0; i < ToolBar->Items->Count; i++)
- {
- TTBControlItem * ControlItem;
- ControlItem = dynamic_cast<TTBControlItem *>(ToolBar->Items->Items[i]);
- // seems that Item->Control can be NULL when closing window
- if ((ControlItem != NULL) && (ControlItem->Control != NULL) &&
- (ControlItem->Control->Tag != 0))
- {
- ResizeControl = ControlItem->Control;
- ControlWidth = ResizeControl->Width;
- break;
- }
- // currently never used
- TTBXComboBoxItem * ComboBoxItem;
- ComboBoxItem = dynamic_cast<TTBXComboBoxItem *>(ToolBar->Items->Items[i]);
- if (ComboBoxItem != NULL)
- {
- ResizeComboBox = ComboBoxItem;
- ControlWidth = ResizeComboBox->EditWidth;
- break;
- }
- }
- ControlWidth = ToolBar->Width - (ToolBar->View->BaseSize.x -
- ControlWidth) - ToolBar->NonClientWidth;
- if (ResizeControl != NULL)
- {
- ResizeControl->Width = ControlWidth;
- }
- // currently never used
- if (ResizeComboBox != NULL)
- {
- ResizeComboBox->EditWidth = ControlWidth;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AddressToolbarGetBaseSize(
- TTBCustomToolbar * Toolbar, TPoint & ASize)
- {
- for (int i = 0; i < Toolbar->Items->Count; i++)
- {
- TTBControlItem * ControlItem;
- ControlItem = dynamic_cast<TTBControlItem *>(Toolbar->Items->Items[i]);
- if (ControlItem != NULL)
- {
- ASize.x = ASize.x - ControlItem->Control->Width +
- ControlItem->Control->Constraints->MinWidth;
- }
- // currently never used
- TTBXComboBoxItem * ComboBoxItem;
- ComboBoxItem = dynamic_cast<TTBXComboBoxItem *>(Toolbar->Items->Items[i]);
- if (ComboBoxItem != NULL)
- {
- ASize.x = ASize.x - ComboBoxItem->EditWidth + ComboBoxItem->Tag;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoWarnLackOfTempSpace(
- const AnsiString Path, __int64 RequiredSpace, bool & Continue)
- {
- if (WinConfiguration->DDWarnLackOfTempSpace)
- {
- AnsiString ADrive = ExtractFileDrive(ExpandFileName(Path));
- if (!ADrive.IsEmpty())
- {
- __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
- assert(RequiredSpace >= 0);
- __int64 RequiredWithReserve;
- RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
- if (FreeSpace < RequiredWithReserve)
- {
- int Result;
- TMessageParams Params(mpNeverAskAgainCheck);
- Result = MessageDialog(FMTLOAD(DD_WARN_LACK_OF_TEMP_SPACE, (Path,
- FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
- qtWarning, qaYes | qaNo, HELP_DD_WARN_LACK_OF_TEMP_SPACE, &Params);
- if (Result == qaNeverAskAgain)
- {
- WinConfiguration->DDWarnLackOfTempSpace = false;
- }
- Continue = (Result == qaYes || Result == qaNeverAskAgain);
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
- {
- DoOpenDirectoryDialog(odAddBookmark, Side);
- }
- //---------------------------------------------------------------------------
- TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
- {
- TStringList * VisitedDirectories = new TStringList();
- try
- {
- TCustomDirView * DView = DirView(Side);
- VisitedDirectories->Duplicates = dupIgnore;
- // we should better use TCustomDirView::FCaseSensitive, but it is private
- VisitedDirectories->CaseSensitive = (Side == osRemote);
- VisitedDirectories->Sorted = true;
- for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
- {
- VisitedDirectories->Add(DView->HistoryPath[Index]);
- }
- }
- catch (...)
- {
- delete VisitedDirectories;
- throw;
- }
- return VisitedDirectories;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
- TOpenDirectoryMode Mode, TOperationSide Side)
- {
- if (Mode != odAddBookmark ||
- (MessageDialog(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)),
- qtConfirmation, qaYes | qaNo, HELP_ADD_BOOKMARK_CONFIRM) == qaYes))
- {
- TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
- try
- {
- AnsiString Name = DirView(Side)->PathName;
- if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal,
- HasDirView[osLocal]))
- {
- DirView(Side)->Path = Name;
- }
- }
- __finally
- {
- delete VisitedDirectories;
- }
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::EnsureCommandSessionFallback(TFSCapability Capability)
- {
- bool Result = FTerminal->IsCapable[Capability] ||
- FTerminal->CommandSessionOpened;
- if (!Result)
- {
- assert(FTerminal->IsCapable[fcSecondaryShell]);
- if (!GUIConfiguration->ConfirmCommandSession)
- {
- Result = true;
- }
- else
- {
- TMessageParams Params(mpNeverAskAgainCheck);
- const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo();
- int Answer = MessageDialog(FMTLOAD(PERFORM_ON_COMMAND_SESSION,
- (FileSystemInfo.ProtocolName, FileSystemInfo.ProtocolName)), qtConfirmation,
- qaOK | qaCancel, HELP_PERFORM_ON_COMMAND_SESSION, &Params);
- if (Answer == qaNeverAskAgain)
- {
- GUIConfiguration->ConfirmCommandSession = false;
- Result = true;
- }
- else if (Answer == qaOK)
- {
- Result = true;
- }
- }
- if (Result)
- {
- try
- {
- TTerminalManager::ConnectTerminal(FTerminal->CommandSession, false);
- }
- catch(Exception & E)
- {
- ShowExtendedExceptionEx(FTerminal->CommandSession, &E);
- Result = false;
- }
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OpenConsole(AnsiString Command)
- {
- if (EnsureCommandSessionFallback(fcAnyCommand))
- {
- DoConsoleDialog(Terminal, Command);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileControlDDDragEnter(
- TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
- const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
- {
- if (IsFileControl(DropSourceControl, osRemote) &&
- (FDDExtMapFile != NULL))
- {
- Accept = true;
- }
- FDDTargetControl = dynamic_cast<TControl*>(Sender);
- assert(FDDTargetControl != NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileControlDDDragLeave(
- TObject *Sender)
- {
- USEDPARAM(Sender);
- assert(FDDTargetControl == Sender);
- FDDTargetControl = NULL;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AddEditLink(bool Add)
- {
- assert(FCurrentSide == osRemote);
- bool Edit = false;
- TRemoteFile * File = NULL;
- AnsiString FileName;
- AnsiString PointTo;
- bool SymbolicLink = true;
- if (RemoteDirView->ItemFocused)
- {
- assert(RemoteDirView->ItemFocused->Data);
- File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
- Edit = !Add && File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
- if (Edit)
- {
- FileName = File->FileName;
- PointTo = File->LinkTo;
- }
- else
- {
- PointTo = File->FileName;
- }
- }
- if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
- Terminal->IsCapable[fcHardLink]))
- {
- if (Edit)
- {
- assert(File->FileName == FileName);
- bool Recursive = false;
- Terminal->ExceptionOnFail = true;
- try
- {
- Terminal->DeleteFile("", File, &Recursive);
- }
- __finally
- {
- Terminal->ExceptionOnFail = false;
- }
- }
- Terminal->CreateLink(FileName, PointTo, SymbolicLink);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
- {
- assert(!WinConfiguration->DisableOpenEdit);
- FForceExecution = true;
- try
- {
- DirView(osCurrent)->ExecuteCurrentFile();
- }
- __finally
- {
- FForceExecution = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalClosed(TObject * Sender)
- {
- FEditorManager->ProcessFiles(FileTerminalClosed, Sender);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileTerminalClosed(const AnsiString FileName,
- TEditedFileData & Data, TObject * /*Token*/, void * Arg)
- {
- TTerminal * Terminal = static_cast<TTerminal *>(Arg);
- assert(Terminal != NULL);
- if (Data.Terminal == Terminal)
- {
- Data.Terminal = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
- {
- try
- {
- TTerminalManager::Instance()->NewSession();
- }
- __finally
- {
- if (!Terminal || !Terminal->Active)
- {
- Application->Terminate();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
- {
- TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem*>(
- static_cast<TComponent*>(GetComponent(fcSessionCombo)));
- if (SessionCombo != NULL)
- {
- SessionCombo->Strings = TTerminalManager::Instance()->TerminalList;
- SessionCombo->ItemIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
- }
- if ((TTerminalManager::Instance()->ActiveCount >= 2) &&
- !WinConfiguration->SessionToolbarAutoShown &&
- !ComponentVisible[fcSessionToolbar])
- {
- ComponentVisible[fcSessionToolbar] = true;
- WinConfiguration->SessionToolbarAutoShown = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionComboPopup(TTBCustomItem * Sender,
- bool /*FromLink*/)
- {
- TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem *>(Sender);
- assert(SessionCombo);
- HDC DC = GetDC(0);
- TCanvas * Canvas = new TCanvas();
- try
- {
- Canvas->Handle = DC;
- Canvas->Font = ToolbarFont;
- int MaxWidth = 0, Width;
- for (int i = 0; i < SessionCombo->Strings->Count; i++)
- {
- Width = Canvas->TextExtent(SessionCombo->Strings->Strings[i]).cx;
- TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(i);
- if (ShortCut != scNone)
- {
- Width += Canvas->TextExtent(ShortCutToText(ShortCut) + " ").cx;
- }
- if (Width > MaxWidth)
- {
- MaxWidth = Width;
- }
- }
- if (SessionCombo->Strings->Count > SessionCombo->MaxVisibleItems)
- {
- MaxWidth += GetSystemMetrics(SM_CXVSCROLL);
- }
- SessionCombo->MinListWidth = MaxWidth + 8 + 8 + 1;
- }
- __finally
- {
- Canvas->Handle = NULL;
- ReleaseDC(0, DC);
- delete Canvas;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionComboDrawItem(
- TTBXCustomList * Sender, TCanvas * Canvas, const TRect & ARect, int Index,
- int AHoverIndex, bool & DrawDefault)
- {
- TTBXStringList * SessionCombo = dynamic_cast<TTBXStringList *>(Sender);
- assert(SessionCombo);
- if (Index >= 0)
- {
- int ShortCutWidth = 0;
- AnsiString ShortCutStr;
- TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(Index);
- if (ShortCut != scNone)
- {
- ShortCutStr = " " + ShortCutToText(ShortCut);
- ShortCutWidth = Canvas->TextExtent(ShortCutStr).cx;
- }
- if (Index != AHoverIndex)
- {
- TManagedTerminal * Terminal =
- dynamic_cast<TManagedTerminal *>(SessionCombo->Strings->Objects[Index]);
- assert(Terminal != NULL);
- TColor Color =
- (Terminal == this->Terminal ? SessionColor : Terminal->Color);
- if (Color != 0)
- {
- Canvas->Brush->Color = Color;
- Canvas->Brush->Style = bsSolid;
- Canvas->FillRect(ARect);
- }
- }
- TRect R = ARect;
- InflateRect(&R, -4, 1);
- R.Right -= ShortCutWidth + 2;
- AnsiString S = SessionCombo->Strings->Strings[Index];
- DrawText(Canvas->Handle, S.c_str(), S.Length(), &R,
- DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
- R = ARect;
- InflateRect(&R, -4, 1);
- R.Left = R.Right - ShortCutWidth;
- DrawText(Canvas->Handle, ShortCutStr.c_str(), ShortCutStr.Length(), &R,
- DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
- }
- DrawDefault = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionComboChange(TObject * Sender,
- const AnsiString Text)
- {
- TTBXComboBoxItem * SessionCombo = dynamic_cast<TTBXComboBoxItem *>(Sender);
- assert(SessionCombo);
- TTerminal * Terminal;
- Terminal = dynamic_cast<TTerminal *>(SessionCombo->Strings->Objects[SessionCombo->ItemIndex]);
- assert(Terminal);
- TTerminalManager::Instance()->ActiveTerminal = Terminal;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TransferListChange(TObject * Sender)
- {
- TTBXStringList * TransferList = dynamic_cast<TTBXStringList *>(Sender);
- assert(TransferList != NULL);
- AnsiString Name;
- if (TransferList->ItemIndex <= 0)
- {
- Name = "";
- }
- else
- {
- Name = GUIConfiguration->CopyParamList->Names[TransferList->ItemIndex - 1];
- }
- if (FCopyParamAutoSelected.IsEmpty())
- {
- // if previous preset was not autoselected, make new preset the "default"
- FCopyParamDefault = Name;
- }
- GUIConfiguration->CopyParamCurrent = Name;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateTransferLabel()
- {
- // sanity check
- bool ExistingPreset =
- (FTransferListHoverIndex >= 0) &&
- (FTransferListHoverIndex < 1 + GUIConfiguration->CopyParamList->Count);
- assert(ExistingPreset);
- if (ExistingPreset)
- {
- HDC DC = GetDC(0);
- TCanvas * Canvas = new TCanvas();
- try
- {
- Canvas->Handle = DC;
- Canvas->Font = ToolbarFont;
- AnsiString Name;
- if (FTransferListHoverIndex == 0)
- {
- Name = "";
- }
- else
- {
- Name = GUIConfiguration->CopyParamList->Names[FTransferListHoverIndex - 1];
- }
- TTBXLabelItem * TransferLabel = dynamic_cast<TTBXLabelItem*>(
- static_cast<TComponent*>(GetComponent(fcTransferLabel)));
- TTBXStringList * TransferList = dynamic_cast<TTBXStringList*>(
- static_cast<TObject*>(GetComponent(fcTransferList)));
- AnsiString InfoStr =
- GUIConfiguration->CopyParamPreset[Name].
- GetInfoStr("; ",
- FLAGMASK(Terminal != NULL, Terminal->UsableCopyParamAttrs(0).General));
- int MaxWidth = TransferList->MinWidth - (2 * TransferLabel->Margin) - 10;
- if (Canvas->TextExtent(InfoStr).cx > MaxWidth)
- {
- AnsiString Ellipsis = "...";
- while (Canvas->TextExtent(InfoStr + Ellipsis).cx > MaxWidth)
- {
- InfoStr.SetLength(InfoStr.Length() - 1);
- }
- InfoStr += Ellipsis;
- }
- // UpdateCaption does not cause invalidation of whole submenu, while
- // setting Caption property does.
- // also it probably does not resize the label, even if necessary
- // (we do not want that anyway)
- TransferLabel->UpdateCaption(InfoStr);
- }
- __finally
- {
- Canvas->Handle = NULL;
- ReleaseDC(0, DC);
- delete Canvas;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TransferListDrawItem(
- TTBXCustomList * /*Sender*/, TCanvas * /*ACanvas*/, const TRect & /*ARect*/,
- int /*AIndex*/, int AHoverIndex, bool & /*DrawDefault*/)
- {
- if (FTransferListHoverIndex != AHoverIndex)
- {
- FTransferListHoverIndex = AHoverIndex;
- UpdateTransferLabel();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::WMAppCommand(TMessage & Message)
- {
- int Command = GET_APPCOMMAND_LPARAM(Message.LParam);
- TShiftState Shift = KeyDataToShiftState(GET_KEYSTATE_LPARAM(Message.LParam));
- if ((Shift * (TShiftState() << ssShift << ssAlt << ssCtrl)).Empty())
- {
- if (Command == _APPCOMMAND_BROWSER_FAVORITES)
- {
- OpenDirectory(GetSide(osCurrent));
- Message.Result = 1;
- }
- else
- {
- TForm::Dispatch(&Message);
- }
- }
- else
- {
- TForm::Dispatch(&Message);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CMAppSysCommand(TMessage & Message)
- {
- TWMSysCommand * SysCommand = (TWMSysCommand *)Message.LParam;
- if (SysCommand->CmdType != SC_KEYMENU || !FIgnoreNextSysCommand)
- {
- FIgnoreNextSysCommand = false;
- TForm::Dispatch(&Message);
- }
- else
- {
- Message.Result = 1;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::WMSysCommand(TMessage & Message)
- {
- // The four low-order bits are used internally by Windows
- unsigned int Cmd = (Message.WParam & 0xFFF0);
- // SC_RESTORE, SC_MAXIMIZE, SC_MINIMIZE - buttons on windows title
- // SC_DEFAULT - double click on windows title (does not work, at least on WinXP)
- // 61730 - restore thru double click - undocumented
- // 61490 - maximize thru double click - undocumented
- if ((Cmd == SC_RESTORE) || (Cmd == SC_MAXIMIZE) ||
- (Cmd == SC_MINIMIZE) || (Cmd == SC_DEFAULT))
- {
- SysResizing(Cmd);
- }
- TForm::Dispatch(&Message);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::WMWindowPosChanging(TWMWindowPosMsg & Message)
- {
- // MSVDM (not sure is it is generic feature) sets size of all windows
- // to iconic and moves top-level windows (with destop as parent) out
- // of the screen (-32000:-32000). However other windows (such as
- // VCL main window with hidden parent) are moved just above
- // the task bar. Override this.
- if (FLAGCLEAR(Message.WindowPos->flags, SWP_NOMOVE) &&
- (Message.WindowPos->cx == GetSystemMetrics(SM_CXMINIMIZED)) &&
- (Message.WindowPos->cy == GetSystemMetrics(SM_CYMINIMIZED)))
- {
- Message.WindowPos->x = OutPos;
- Message.WindowPos->y = OutPos;
- }
- TForm::Dispatch(&Message);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SysResizing(unsigned int /*Cmd*/)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoShow()
- {
- // only now are the controls resized finally, so the size constraints
- // will not conflict with possibly very small window size
- RestoreFormParams();
- FixControlsPlacement();
- if (Position == poDefaultPosOnly)
- {
- CutFormToDesktop(this);
- }
- TForm::DoShow();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PopupTrayBalloon(TTerminal * Terminal,
- const AnsiString & Str, TQueryType Type, Exception * E, unsigned int Seconds)
- {
- if (WinConfiguration->BalloonNotifications &&
- (dynamic_cast<EAbort*>(E) == NULL))
- {
- AnsiString Message;
- if (E == NULL)
- {
- Message = Str;
- }
- else
- {
- assert(Str.IsEmpty());
- Message = E->Message;
- }
- if (!Message.IsEmpty())
- {
- const ResourceString * Captions[] = { &_SMsgDlgConfirm, &_SMsgDlgWarning,
- &_SMsgDlgError, &_SMsgDlgInformation, NULL };
- AnsiString Title = LoadResourceString(Captions[Type]);
- if (Terminal != NULL)
- {
- Title = FORMAT("%s - %s",
- (TTerminalManager::Instance()->TerminalTitle(Terminal), Title));
- }
- if (Seconds == 0)
- {
- Seconds = WinConfiguration->NotificationsTimeout;
- }
- FTrayIcon->PopupBalloon(Title, Message, Type, Seconds * 1000);
- }
- }
- }
- //---------------------------------------------------------------------------
- int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const AnsiString Message,
- TStrings * MoreMessages, TQueryType Type, int Answers,
- AnsiString HelpKeyword, const TMessageParams * Params,
- TTerminal * Terminal)
- {
- if (WinConfiguration->ContinueOnError &&
- (Params != NULL) && (Params->Params & mpAllowContinueOnError) &&
- FErrorList)
- {
- TStringList * MoreMessagesCopy = NULL;
- if (MoreMessages)
- {
- MoreMessagesCopy = new TStringList();
- MoreMessagesCopy->Assign(MoreMessages);
- }
- FErrorList->AddObject(Message, MoreMessagesCopy);
- if (Answers & qaSkip) return qaSkip;
- else
- if (Answers & qaIgnore) return qaIgnore;
- else
- if (Answers & qaOK) return qaOK;
- else
- if (Answers & qaYes) return qaYes;
- else
- if (Answers & qaRetry) return qaRetry;
- else
- {
- assert(false);
- return qaYes;
- }
- }
- else
- {
- if (FTrayIcon->Visible)
- {
- PopupTrayBalloon(Terminal, Message, Type);
- }
- int Result;
- try
- {
- Result = ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpKeyword, Params);
- }
- __finally
- {
- FTrayIcon->CancelBalloon();
- }
- return Result;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ShowExtendedException(
- TTerminal * Terminal, Exception * E)
- {
- if (FTrayIcon->Visible)
- {
- PopupTrayBalloon(Terminal, "", qtError, E);
- }
- try
- {
- ShowExtendedExceptionEx(Terminal, E);
- }
- __finally
- {
- FTrayIcon->CancelBalloon();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::InactiveTerminalException(
- TTerminal * Terminal, Exception * E)
- {
- Notify(Terminal, "", qtError, false, NULL, E);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::Notify(TTerminal * Terminal,
- AnsiString Message, TQueryType Type,
- bool Important, TNotifyEvent OnClick, Exception * E)
- {
- if (dynamic_cast<EAbort*>(E) == NULL)
- {
- unsigned int Seconds = WinConfiguration->NotificationsTimeout;
- if (Important)
- {
- Seconds *= 5;
- }
- if (E != NULL)
- {
- assert(Message.IsEmpty());
- Message = E->Message;
- }
- AnsiString NoteMessage(Message);
- if (Terminal != NULL)
- {
- NoteMessage = FORMAT("%s: %s",
- (TTerminalManager::Instance()->TerminalTitle(Terminal), NoteMessage));
- }
- if (WinConfiguration->BalloonNotifications &&
- TTrayIcon::SupportsBalloons())
- {
- AddNote(NoteMessage);
- PopupTrayBalloon(Terminal, Message, Type, NULL, Seconds);
- }
- else
- {
- FlashOnBackground();
- PostNote(NoteMessage, Seconds, OnClick, NULL);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueEvent(TTerminal * ATerminal,
- TTerminalQueue * /*Queue*/, TQueueEvent Event)
- {
- AnsiString Message;
- switch (Event)
- {
- case qeEmpty:
- if ((ATerminal != Terminal) || !ComponentVisible[fcQueueView])
- {
- Message = LoadStr(BALLOON_QUEUE_EMPTY);
- }
- break;
- case qePendingUserAction:
- if ((ATerminal != Terminal) ||
- (!ComponentVisible[fcQueueView] && !GUIConfiguration->QueueAutoPopup))
- {
- Message = LoadStr(BALLOON_QUEUE_USER_ACTION);
- }
- break;
- default:
- assert(false);
- }
- if (!Message.IsEmpty())
- {
- Notify(ATerminal, Message, qtInformation);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDragFileList(
- TObject * /*Sender*/, TFileList * FileList, bool & Created)
- {
- if (FDDExtMapFile != NULL)
- {
- CloseHandle(FDDExtMapFile);
- FDDExtMapFile = NULL;
- }
- if (WinConfiguration->DDExtEnabled)
- {
- if (!WinConfiguration->DDExtInstalled)
- {
- throw Exception(LoadStr(DRAGEXT_TARGET_NOT_INSTALLED));
- }
- DDExtInitDrag(FileList, Created);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
- bool & Created)
- {
- FDragExtFakeDirectory =
- ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
- if (!ForceDirectories(FDragExtFakeDirectory))
- {
- throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (FDragExtFakeDirectory)));
- }
- FileList->AddItem(NULL, FDragExtFakeDirectory);
- Created = true;
- FDDExtMapFile = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
- 0, sizeof(TDragExtCommStruct), DRAG_EXT_MAPPING);
- {
- TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
- TDragExtCommStruct* CommStruct;
- CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
- FILE_MAP_ALL_ACCESS, 0, 0, 0));
- assert(CommStruct != NULL);
- CommStruct->Version = TDragExtCommStruct::CurrentVersion;
- CommStruct->Dragging = true;
- strncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
- sizeof(CommStruct->DropDest));
- CommStruct->DropDest[sizeof(CommStruct->DropDest) - 1] = '\0';
- UnmapViewOfFile(CommStruct);
- }
- FDDMoveSlipped = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlFileOperation(
- TObject * Sender, TFileOperation Operation, bool NoConfirmation, void * Param)
- {
- if (Sender == RemoteDirView)
- {
- ExecuteFileOperation(Operation, osRemote, true, NoConfirmation, Param);
- }
- else
- {
- assert(Sender == RemoteDriveView);
- TStrings * FileList = RemoteDriveView->DragFileList();
- try
- {
- ExecuteFileOperation(Operation, osRemote, FileList, NoConfirmation, Param);
- }
- __finally
- {
- delete FileList;
- }
- }
- if (FDDTargetControl == RemoteDriveView)
- {
- RemoteDriveView->UpdateDropTarget();
- }
- // foRemoteMove happens when file/dir is dragged within the remote tree view
- // or from tree view to dir view.
- // foMove happens when file/dir is dragged from remote tree view outside of
- // application via dragex
- if (((Operation == foRemoteMove) || (Operation == foMove)) &&
- (DropSourceControl == RemoteDriveView))
- {
- RemoteDriveView->UpdateDropSource();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDEnd(TObject * Sender)
- {
- SAFE_DESTROY(FDDFileList);
- if (FDDExtMapFile != NULL)
- {
- try
- {
- TDragResult DDResult = (Sender == RemoteDirView) ?
- RemoteDirView->LastDDResult : RemoteDriveView->LastDDResult;
- if ((DDResult == drCopy) || (DDResult == drMove))
- {
- AnsiString TargetDirectory;
- TFileOperation Operation;
- Operation = (DDResult == drMove) ? foMove : foCopy;
- if (FDDMoveSlipped)
- {
- Operation = foMove;
- }
- TTransferOperationParam Param;
- DDGetTarget(Param.TargetDirectory);
- // download using ddext
- Param.Temp = false;
- Param.DragDrop = true;
- RemoteFileControlFileOperation(Sender, Operation,
- !WinConfiguration->DDTransferConfirmation, &Param);
- }
- }
- __finally
- {
- CloseHandle(FDDExtMapFile);
- FDDExtMapFile = NULL;
- RemoveDir(FDragExtFakeDirectory);
- FDragExtFakeDirectory = "";
- }
- }
- if (!FDragDropSshTerminate.IsEmpty())
- {
- throw ESshTerminate(NULL, FDragDropSshTerminate);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDGiveFeedback(
- TObject * Sender, int dwEffect, HRESULT & /*Result*/)
- {
- HCURSOR SlippedCopyCursor;
- FDDMoveSlipped =
- (FDragMoveCursor != NULL) &&
- (!WinConfiguration->DDAllowMoveInit) && (dwEffect == DROPEFFECT_Copy) &&
- ((IsFileControl(FDDTargetControl, osRemote) && (GetKeyState(VK_CONTROL) >= 0) &&
- FTerminal->IsCapable[fcRemoteMove]) ||
- (IsFileControl(FDDTargetControl, osLocal) && (GetKeyState(VK_SHIFT) < 0)));
- SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
- DragDropFiles(Sender)->CHCopy = SlippedCopyCursor;
- DragDropFiles(Sender)->CHScrollCopy = SlippedCopyCursor;
- // Remember drop effect so we know (when user dropes files), if we copy or move
- FLastDropEffect = dwEffect;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DDGetTarget(AnsiString & Directory)
- {
- bool Result = false;
- Enabled = false;
- try
- {
- int Timer = 0;
- while (!Result && (Timer < WinConfiguration->DDExtTimeout))
- {
- {
- TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
- TDragExtCommStruct* CommStruct;
- CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
- FILE_MAP_ALL_ACCESS, 0, 0, 0));
- assert(CommStruct != NULL);
- Result = !CommStruct->Dragging;
- if (Result)
- {
- Directory = ExtractFilePath(CommStruct->DropDest);
- }
- UnmapViewOfFile(CommStruct);
- }
- if (!Result)
- {
- Sleep(50);
- Timer += 50;
- Application->ProcessMessages();
- }
- }
- }
- __finally
- {
- Enabled = true;
- }
- if (!Result)
- {
- throw Exception(LoadStr(DRAGEXT_TARGET_UNKNOWN));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AddDelayedDirectoryDeletion(
- const AnsiString TempDir, int SecDelay)
- {
- TDateTime Alarm = Now() + (double)SecDelay*(double(1)/24/60/60);
- FDelayedDeletionList->AddObject(TempDir, reinterpret_cast<TObject*>(Alarm.FileDate()));
- if (FDelayedDeletionTimer == NULL)
- {
- assert(HandleAllocated());
- FDelayedDeletionTimer = new TTimer(this);
- FDelayedDeletionTimer->Interval = 10000;
- FDelayedDeletionTimer->OnTimer = DoDelayedDeletion;
- }
- else
- {
- FDelayedDeletionTimer->Enabled = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoDelayedDeletion(TObject * Sender)
- {
- assert(FDelayedDeletionList != NULL);
- TDateTime N = Now();
- TDateTime Alert;
- AnsiString Directory;
- for (int Index = FDelayedDeletionList->Count-1; Index >= 0; Index--)
- {
- Alert = FileDateToDateTime(reinterpret_cast<int>(FDelayedDeletionList->Objects[Index]));
- if ((N >= Alert) || (Sender == NULL))
- {
- Directory = FDelayedDeletionList->Strings[Index];
- if (DeleteDirectory(ExcludeTrailingBackslash(Directory)))
- {
- FDelayedDeletionList->Delete(Index);
- }
- }
- }
- if (FDelayedDeletionList->Count == 0)
- {
- FDelayedDeletionTimer->Enabled = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDTargetDrop()
- {
- if (IsFileControl(FDDTargetControl, osRemote))
- {
- TTransferOperationParam Param;
- Param.DragDrop = true;
- // when move from remote side is disabled, we allow coying inside the remote
- // panel, but we interpret is as moving (we also slip in the move cursor)
- if ((FLastDropEffect == DROPEFFECT_MOVE) ||
- (!WinConfiguration->DDAllowMoveInit && (FLastDropEffect == DROPEFFECT_COPY) &&
- FDDMoveSlipped))
- {
- RemoteFileControlFileOperation(DropSourceControl,
- foRemoteMove, !WinConfiguration->DDTransferConfirmation, &Param);
- }
- else if (FLastDropEffect == DROPEFFECT_COPY)
- {
- RemoteFileControlFileOperation(DropSourceControl,
- foRemoteCopy, !WinConfiguration->DDTransferConfirmation, &Param);
- }
- // abort drag&drop
- Abort();
- }
- else if ((FDDExtMapFile == NULL) && (FLastDropEffect != DROPEFFECT_NONE))
- {
- assert(!FDragTempDir.IsEmpty());
- TTransferType Type;
- AnsiString TempDir = FDragTempDir;
- // We clear FDragTempDir before calling
- // just in case it fail (raises exception)
- FDragTempDir = "";
- Type = (FLastDropEffect & DROPEFFECT_MOVE ? ttMove : Type = ttCopy);
- TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
- // empty directory parameter means temp directory -> don't display it!
- AnsiString TargetDir = "";
- if (!CopyParamDialog(tdToLocal, Type, true, FDDFileList,
- TargetDir, CopyParams, WinConfiguration->DDTransferConfirmation, true))
- {
- Abort();
- }
- // TargetDir is set when dropped on local file control
- // (this was workaround for legacy dirview event handling, now it should be
- // made prettier)
- if (TargetDir.IsEmpty())
- {
- TargetDir = TempDir;
- if (ForceDirectories(TargetDir))
- {
- assert(Terminal && !TargetDir.IsEmpty());
- // do not attempt to warn unless we know total transfer size
- FPendingTempSpaceWarn = CopyParams.CalculateSize;
- try
- {
- FDragDropOperation = true;
- // cpNewerOnly has no efect here,
- // as we download to empty temp directory
- int Params = cpTemporary |
- (Type == ttMove ? cpDelete : 0);
- DDDownload(FDDFileList, TargetDir, &CopyParams, Params);
- }
- __finally
- {
- FDragDropOperation = false;
- FPendingTempSpaceWarn = false;
- AddDelayedDirectoryDeletion(TargetDir, WinConfiguration->DDDeleteDelay);
- }
- }
- else
- {
- throw Exception(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TargetDir)));
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DDDownload(TStrings * FilesToCopy,
- const AnsiString TargetDir, const TCopyParamType * CopyParam, int Params)
- {
- Terminal->CopyToLocal(FilesToCopy, TargetDir, CopyParam, Params);
- if (FLAGSET(Params, cpDelete) && (DropSourceControl == RemoteDriveView))
- {
- RemoteDriveView->UpdateDropSource();
- }
- }
- //---------------------------------------------------------------------------
- class TFakeDataObjectFilesEx : public TDataObjectFilesEx
- {
- public:
- __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
- bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
- {
- }
- virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
- {
- return (FormatEtc.cfFormat == CF_HDROP) ? false :
- TDataObjectFilesEx::AllowData(FormatEtc);
- }
- };
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDCreateDataObject(
- TObject * Sender, TDataObject *& DataObject)
- {
- if (FDDExtMapFile != NULL)
- {
- TFileList * FileList = DragDropFiles(Sender)->FileList;
- if (!FileList->RenderPIDLs() || !FileList->RenderNames())
- {
- Abort();
- }
- if (FileList->Count > 0)
- {
- TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
- if (!FilesObject->IsValid(true, true))
- {
- FilesObject->_Release();
- }
- else
- {
- DataObject = FilesObject;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::GoToCommandLine()
- {
- assert(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::GoToTree()
- {
- ComponentVisible[fcRemoteTree] = true;
- RemoteDriveView->SetFocus();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
- TPanelExport Export, TPanelExportDestination Destination, bool OnFocused)
- {
- Side = GetSide(Side);
- TCustomDirView * DirView = this->DirView(Side);
- TStringList * ExportData = new TStringList();
- try
- {
- switch (Export)
- {
- case pePath:
- ExportData->Add(DirView->PathName);
- break;
- case peFileList:
- case peFullFileList:
- {
- bool FullPath = (Export == peFullFileList);
- DirView->CreateFileList(OnFocused, FullPath, ExportData);
- AnsiString FileName;
- for (int Index = 0; Index < ExportData->Count; Index++)
- {
- if (ExportData->Strings[Index].Pos(" ") > 0)
- {
- ExportData->Strings[Index] = FORMAT("\"%s\"", (ExportData->Strings[Index]));
- }
- }
- }
- break;
- case peUrl:
- {
- assert(DirView == RemoteDirView);
- DirView->CreateFileList(OnFocused, true, ExportData);
- for (int Index = 0; Index < ExportData->Count; Index++)
- {
- ExportData->Strings[Index] =
- FTerminal->FileUrl(ExportData->Strings[Index]);
- }
- }
- break;
- default:
- assert(false);
- }
- PanelExportStore(Side, Export, Destination, ExportData);
- }
- __finally
- {
- delete ExportData;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
- TPanelExport /*Export*/, TPanelExportDestination Destination,
- TStringList * ExportData)
- {
- if (Destination == pedClipboard)
- {
- CopyToClipboard(ExportData);
- }
- else
- {
- assert(false);
- }
- }
- //---------------------------------------------------------------------------
- TQueueOperation __fastcall TCustomScpExplorerForm::DefaultQueueOperation()
- {
- return FQueueController->DefaultOperation();
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::AllowQueueOperation(
- TQueueOperation Operation)
- {
- switch (Operation)
- {
- case qoPreferences:
- return true;
- case qoGoTo:
- return ComponentVisible[fcQueueView];
- case qoDisconnectOnceEmpty:
- return !FQueueController->Empty;
- default:
- return FQueueController->AllowOperation(Operation);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
- TQueueOperation Operation)
- {
- if (Operation == qoGoTo)
- {
- assert(QueueView->Visible);
- QueueView->SetFocus();
- }
- else if (Operation == qoPreferences)
- {
- PreferencesDialog(pmQueue);
- }
- else
- {
- FQueueController->ExecuteOperation(Operation);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewContextPopup(
- TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
- {
- FQueueActedItem = QueueView->ItemFocused;
- }
- //---------------------------------------------------------------------------
- /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
- {
- return TopDock->Height + QueueSplitter->Height;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
- TObject * /*Sender*/, int & NewSize, bool & Accept)
- {
- // when queue is hidden by double-clicking splitter, stray attempt to
- // resize the panel with strange value arrives, make sure it is ignored
- if (ComponentVisible[fcQueueView])
- {
- int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
- RemotePanel->Constraints->MinHeight;
- if (NewSize > HeightLimit)
- {
- NewSize = HeightLimit;
- }
- }
- else
- {
- Accept = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewStartDrag(TObject * /*Sender*/,
- TDragObject *& /*DragObject*/)
- {
- FQueueActedItem = QueueView->ItemFocused;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewDragOver(TObject * /*Sender*/,
- TObject * Source, int X, int Y, TDragState /*State*/, bool & Accept)
- {
- Accept = true;
- if (Source == QueueView)
- {
- TListItem * DropTarget = QueueView->GetItemAt(X, Y);
- Accept = (DropTarget != NULL) && (FQueueActedItem != NULL);
- if (Accept)
- {
- TQueueItemProxy * QueueItem;
- TQueueItemProxy * DestQueueItem;
- QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
- DestQueueItem = static_cast<TQueueItemProxy *>(DropTarget->Data);
- Accept = (QueueItem != DestQueueItem) &&
- (QueueItem->Status == TQueueItem::qsPending) &&
- (DestQueueItem->Status == TQueueItem::qsPending);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewDragDrop(TObject * /*Sender*/,
- TObject * /*Source*/, int /*X*/, int /*Y*/)
- {
- if ((FQueueActedItem != NULL) && (QueueView->DropTarget != NULL))
- {
- TQueueItemProxy * QueueItem;
- TQueueItemProxy * DestQueueItem;
- QueueItem = static_cast<TQueueItemProxy *>(FQueueActedItem->Data);
- DestQueueItem = static_cast<TQueueItemProxy *>(QueueView->DropTarget->Data);
- QueueItem->Move(DestQueueItem);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewEnter(TObject * /*Sender*/)
- {
- if ((QueueView->ItemFocused == NULL) &&
- (QueueView->Items->Count > 0))
- {
- QueueView->ItemFocused = QueueView->Items->Item[0];
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewSelectItem(
- TObject * /*Sender*/, TListItem * /*Item*/, bool Selected)
- {
- if (Selected)
- {
- NonVisualDataModule->UpdateNonVisibleActions();
- }
- }
- //---------------------------------------------------------------------------
- TDragDropFilesEx * __fastcall TCustomScpExplorerForm::DragDropFiles(TObject * Sender)
- {
- TDragDropFilesEx * Result = NULL;
- TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
- if (DirView != NULL)
- {
- Result = DirView->DragDropFilesEx;
- }
- else
- {
- TCustomDriveView * DriveView = dynamic_cast<TCustomDriveView *>(Sender);
- if (DriveView != NULL)
- {
- Result = DriveView->DragDropFilesEx;
- }
- }
- assert(Result != NULL);
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDFileOperation(
- TObject * Sender, int Effect, AnsiString /*SourcePath*/,
- AnsiString TargetPath, bool & /*DoOperation*/)
- {
- TFileOperation Operation;
- switch (Effect)
- {
- case DROPEFFECT_MOVE:
- Operation = foMove;
- break;
- case DROPEFFECT_COPY:
- // occures on WinXP (reported by user)
- default:
- Operation = foCopy;
- break;
- };
- TStrings * FileList = new TStringList();
- try
- {
- TDragDropFilesEx * DragDropFilesEx = DragDropFiles(Sender);
- for (int Index = 0; Index < DragDropFilesEx->FileList->Count; Index++)
- {
- FileList->Add(DragDropFilesEx->FileList->Items[Index]->Name);
- }
- FDragDropOperation = true;
- TTransferOperationParam Param;
- Param.TargetDirectory = TargetPath;
- // upload, no temp dirs
- Param.Temp = false;
- Param.DragDrop = true;
- ExecuteFileOperation(Operation, osLocal, FileList,
- !WinConfiguration->DDTransferConfirmation, &Param);
- }
- __finally
- {
- FDragDropOperation = false;
- delete FileList;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileContolDDChooseEffect(
- TObject * Sender, int grfKeyState, int & dwEffect)
- {
- // if any drop effect is allowed at all (e.g. no drop to self and drop to parent)
- if ((dwEffect != DROPEFFECT_None) &&
- IsFileControl(DropSourceControl, osRemote))
- {
- // do not allow drop on remote panel (on free space, still allow drop on directories)
- if ((Sender == RemoteDirView) && (DropSourceControl == RemoteDirView) &&
- (RemoteDirView->DropTarget == NULL))
- {
- dwEffect = DROPEFFECT_None;
- }
- else
- {
- if (dwEffect == DROPEFFECT_Copy)
- {
- bool MoveCapable = FTerminal->IsCapable[fcRemoteMove];
- bool CopyCapable = FTerminal->IsCapable[fcRemoteCopy] || FTerminal->IsCapable[fcSecondaryShell];
- // if we do not support neither of operations, there's no discussion
- if (!MoveCapable && !CopyCapable)
- {
- dwEffect = DROPEFFECT_None;
- }
- // when moving is disabled, we need to keep effect to "copy",
- // which will be later interpretted as move (with slipped-in cursor)
- else if (!WinConfiguration->DDAllowMoveInit && FLAGCLEAR(grfKeyState, MK_CONTROL))
- {
- // no-op, keep copy
- }
- else
- {
- // The default effect inside remote panel is move,
- // unless we do not support it, but support copy
- if (FLAGCLEAR(grfKeyState, MK_CONTROL))
- {
- dwEffect = MoveCapable ? DROPEFFECT_Move : DROPEFFECT_Copy;
- }
- else
- {
- // with ctrl-down, we want copy unless it is not supported
- dwEffect = CopyCapable ? DROPEFFECT_Copy : DROPEFFECT_None;
- }
- }
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragFileName(
- TObject * Sender, TRemoteFile * File, AnsiString & FileName)
- {
- if (FDDTotalSize >= 0)
- {
- if (File->IsDirectory)
- {
- FDDTotalSize = -1;
- }
- else
- {
- FDDTotalSize += File->Size;
- }
- }
- assert(!FDragTempDir.IsEmpty());
- // TODO: this is quite ineffective
- // TODO: what if invalid character replacement is disabled?
- FileName = FDragTempDir + GUIConfiguration->CurrentCopyParam.ValidLocalFileName(File->FileName);
- AnsiString TransferFileName;
- if (Sender == RemoteDriveView)
- {
- TransferFileName = UnixExcludeTrailingBackslash(File->FullFileName);
- }
- else
- {
- TransferFileName = File->FileName;
- }
- FDDFileList->AddObject(TransferFileName, File);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDDragDetect(
- TObject * /*Sender*/, int /*grfKeyState*/, const TPoint & /*DetectStart*/,
- const TPoint & /*Point*/, TDragDetectStatus /*DragStatus*/)
- {
- FDDFileList = new TStringList();
- FDragTempDir = WinConfiguration->TemporaryDir();
- FDDTotalSize = 0;
- FDragDropSshTerminate = "";
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteFileControlDDQueryContinueDrag(
- TObject * /*Sender*/, BOOL /*FEscapePressed*/, int /*grfKeyState*/,
- HRESULT & Result)
- {
- if (Result == DRAGDROP_S_DROP)
- {
- try
- {
- GlobalDragImageList->HideDragImage();
- try
- {
- RemoteFileControlDDTargetDrop();
- }
- catch(ESshTerminate & E)
- {
- assert(E.MoreMessages == NULL); // not supported
- assert(!E.Message.IsEmpty());
- FDragDropSshTerminate = E.Message;
- }
- }
- catch (Exception &E)
- {
- // If downloading fails we need to cancel drag&drop, othwerwise
- // Explorer shows error
- // But by the way exception probably never reach this point as
- // it's catched on way
- Result = DRAGDROP_S_CANCEL;
- assert(Terminal != NULL);
- Terminal->ShowExtendedException(&E);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewMatchMask(
- TObject * /*Sender*/, AnsiString FileName, bool Directory, __int64 Size,
- AnsiString Masks,bool & Matches)
- {
- TFileMasks::TParams MaskParams;
- MaskParams.Size = Size;
- TFileMasks M(Masks);
- Matches = M.Matches(FileName, Directory, AnsiString(""), &MaskParams);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewGetOverlay(
- TObject * Sender, TListItem * Item, WORD & Indexes)
- {
- TCustomDirView * DirView = reinterpret_cast<TCustomDirView *>(Sender);
- AnsiString Ext;
- if (DirView == RemoteDirView)
- {
- Ext = UnixExtractFileExt(DirView->ItemFileName(Item));
- }
- else
- {
- Ext = ExtractFileExt(DirView->ItemFileName(Item));
- }
- if (SameText(Ext, Configuration->PartialExt))
- {
- Indexes |= oiPartial;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::CanPasteFromClipBoard()
- {
- return
- IsFormatInClipboard(CF_TEXT) ||
- DirView(osCurrent)->CanPasteFromClipBoard();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PasteFromClipBoard()
- {
- if (DirView(osCurrent)->CanPasteFromClipBoard())
- {
- DirView(osCurrent)->PasteFromClipBoard();
- }
- else
- {
- AnsiString Path;
- if (TextFromClipboard(Path) && !Path.IsEmpty())
- {
- DirView(osCurrent)->Path = Path;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileListFromClipboard()
- {
- // TBD
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TCustomScpExplorerForm::FileStatusBarText(
- const TStatusFileInfo & FileInfo)
- {
- return
- FMTLOAD(FILE_INFO_FORMAT,
- (FormatBytes(FileInfo.SelectedSize),
- FormatBytes(FileInfo.FilesSize),
- FormatFloat("#,##0", FileInfo.SelectedCount),
- FormatFloat("#,##0", FileInfo.FilesCount)));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateFileStatusBar(
- TTBXStatusBar * StatusBar, const TStatusFileInfo & FileInfo, int Panel)
- {
- AnsiString Text = FileStatusBarText(FileInfo);
- if (StatusBar->SimplePanel)
- {
- assert(Panel == 0);
- StatusBar->SimpleText = Text;
- }
- else
- {
- StatusBar->Panels->Items[Panel]->Caption = Text;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteStatusBarClick(
- TObject * /*Sender*/)
- {
- RemoteDirView->SetFocus();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ToggleQueueVisibility()
- {
- TQueueViewConfiguration Config = WinConfiguration->QueueView;
- switch (Config.Show)
- {
- case qvShow:
- if ((FQueueStatus != NULL) && (FQueueStatus->Count > 0))
- {
- Config.Show = qvHide;
- }
- else
- {
- Config.Show = Config.LastHideShow;
- }
- break;
- case qvHideWhenEmpty:
- if (ComponentVisible[fcQueueView])
- {
- Config.Show = qvHide;
- }
- else
- {
- Config.LastHideShow = Config.Show;
- Config.Show = qvShow;
- }
- break;
- case qvHide:
- Config.LastHideShow = Config.Show;
- Config.Show = qvShow;
- break;
- }
- WinConfiguration->QueueView = Config;
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TCustomScpExplorerForm::PathForCaption()
- {
- AnsiString Result;
- if (FTerminal != NULL)
- {
- switch (WinConfiguration->PathInCaption)
- {
- case picShort:
- {
- Result = UnixExtractFileName(FTerminal->CurrentDirectory);
- if (Result.IsEmpty())
- {
- Result = FTerminal->CurrentDirectory;
- }
- }
- break;
- case picFull:
- Result = FTerminal->CurrentDirectory;
- break;
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateControls()
- {
- // beware that app title can contain progress indicator that we do not want to
- // see in window title. we rely here on fact that this should be never called
- // during operation
- Caption = TTerminalManager::Instance()->UpdateAppTitle();
- RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
- RemoteDriveView->Color = RemoteDirView->Color;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoDirViewLoaded(TCustomDirView * /*Sender*/)
- {
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewLoaded(
- TObject * Sender)
- {
- TCustomDirView * DirView = dynamic_cast<TCustomDirView *>(Sender);
- assert(DirView != NULL);
- DoDirViewLoaded(DirView);
- TransferPresetAutoSelect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::StartUpdates()
- {
- TUpdatesConfiguration Updates = WinConfiguration->Updates;
- // first run after installation
- if (double(Updates.LastCheck) == 0)
- {
- // make sure next time there will be an update (if enabled)
- Updates.LastCheck = TDateTime(1);
- WinConfiguration->Updates = Updates;
- }
- else if ((double(Updates.Period) > 0) &&
- (Now() - Updates.LastCheck >= Updates.Period))
- {
- StartUpdateThread(UpdatesChecked);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdatesChecked()
- {
- AnsiString Message;
- bool New;
- TQueryType Type;
- GetUpdatesMessage(Message, New, Type, false);
- if (!Message.IsEmpty())
- {
- if (!New && (Type != qtWarning))
- {
- PostNote(Message, 0, UpdatesNoteClicked, NULL);
- }
- else
- {
- Notify(NULL, Message, Type, true, UpdatesNoteClicked);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdatesNoteClicked(TObject * /*Sender*/)
- {
- CheckForUpdates(true);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::GetTransferPresetAutoSelectData(
- TCopyParamRuleData & Data)
- {
- assert(Terminal != NULL);
- Data.HostName = Terminal->SessionData->HostName;
- Data.UserName = Terminal->SessionData->UserName;
- Data.RemoteDirectory = RemoteDirView->PathName;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TransferPresetAutoSelect()
- {
- if (!FNoTransferPresetAutoSelect)
- {
- assert(Terminal != NULL);
- TCopyParamRuleData Data;
- GetTransferPresetAutoSelectData(Data);
- int CopyParamIndex = GUIConfiguration->CopyParamList->Find(Data);
- AnsiString CopyParamCurrent = GUIConfiguration->CopyParamCurrent;
- if (CopyParamIndex < 0)
- {
- // there is no preset that matches autoselection
- // set preset that we consider "default"
- FCopyParamAutoSelected = ""; // forget last autoselected preset
- GUIConfiguration->CopyParamCurrent = FCopyParamDefault;
- }
- else
- {
- // there is preset matching autoselection
- AnsiString CopyParamName = GUIConfiguration->CopyParamList->Names[CopyParamIndex];
- if (CopyParamName == FCopyParamAutoSelected)
- {
- // autoselected the same preset as the last time
- // make no change (i.e. preserve custom user preset, if any)
- }
- else
- {
- // autoselected the different preset then the last time (or there
- // was default preset set)
- FCopyParamAutoSelected = CopyParamName; // remember autoselection
- GUIConfiguration->CopyParamCurrent = CopyParamName;
- }
- }
- if (GUIConfiguration->CopyParamCurrent != CopyParamCurrent)
- {
- TTransferPresetNoteData * Data = new TTransferPresetNoteData;
- try
- {
- int Fmt =
- (CopyParamIndex < 0) ?
- (GUIConfiguration->CopyParamIndex < 0 ? COPY_PARAM_DEFAULT_NORM : COPY_PARAM_DEFAULT_CUSTOM) :
- COPY_PARAM_AUTOSELECTED;
- Data->Message = FMTLOAD(Fmt, (StripHotkey(GUIConfiguration->CopyParamCurrent)));
- Data->More = new TStringList();
- int CopyParamAttrs = Terminal->UsableCopyParamAttrs(0).General;
- AnsiString Info = GUIConfiguration->CurrentCopyParam.GetInfoStr("\n",
- CopyParamAttrs);
- if (CopyParamIndex >= 0)
- {
- assert(GUIConfiguration->CopyParamList->Rules[CopyParamIndex] != NULL);
- Info = FORMAT("%s\n \n%s", (Info,
- FMTLOAD(COPY_PARAM_RULE,
- (GUIConfiguration->CopyParamList->Rules[CopyParamIndex]->GetInfoStr("\n")))));
- }
- Data->More->Text = Info;
- if (WinConfiguration->CopyParamAutoSelectNotice)
- {
- TransferPresetNoteMessage(Data, true);
- }
- else
- {
- PostNote(Data->Message, 0, TransferPresetNoteClicked, Data);
- Data = NULL; // ownership passed
- }
- }
- __finally
- {
- delete Data;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TransferPresetNoteMessage(
- TTransferPresetNoteData * NoteData, bool AllowNeverAskAgain)
- {
- assert(NoteData != NULL);
- TMessageParams Params(AllowNeverAskAgain ? mpNeverAskAgainCheck : 0);
- TQueryButtonAlias Aliases[1];
- Aliases[0].Button = qaIgnore; // ignore" is after "ok"
- Aliases[0].Alias = LoadStr(CONFIGURE_BUTTON);
- Params.Aliases = Aliases;
- Params.AliasesCount = LENOF(Aliases);
- int Result =
- MoreMessageDialog(NoteData->Message, NoteData->More, qtInformation,
- qaOK | qaIgnore, HELP_COPY_PARAM_AUTOSELECTED, &Params);
- switch (Result)
- {
- case qaNeverAskAgain:
- assert(AllowNeverAskAgain);
- WinConfiguration->CopyParamAutoSelectNotice = false;
- break;
- case qaIgnore:
- PreferencesDialog(pmPresets);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TransferPresetNoteClicked(TObject * /*Sender*/)
- {
- TransferPresetNoteMessage(dynamic_cast<TTransferPresetNoteData *>(FNoteData), false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PreferencesDialog(
- TPreferencesMode APreferencesMode)
- {
- TCopyParamRuleData Data;
- GetTransferPresetAutoSelectData(Data);
- TPreferencesDialogData PreferencesData;
- PreferencesData.CopyParamRuleData = &Data;
- DoPreferencesDialog(APreferencesMode, &PreferencesData);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
- const AnsiString & Command, int Params)
- {
- if (CustomCommandState(Command, Params, FEditingFocusedAdHocCommand) <= 0)
- {
- throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command)));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AdHocCustomCommand(bool OnFocused)
- {
- bool RemoteAllowed = CustomCommandRemoteAllowed();
- TCustomCommandParam Param;
- // make sure we use local custom command when remote are not supported
- if (RemoteAllowed || FLAGSET(FLastCustomCommand.Params, ccLocal))
- {
- Param = FLastCustomCommand;
- }
- else
- {
- Param.Params |= ccLocal;
- }
- Param.Name = LoadStr(CUSTOM_COMMAND_AD_HOC_NAME);
- FEditingFocusedAdHocCommand = OnFocused;
- int Options = FLAGMASK(!RemoteAllowed, ccoDisableRemote);
- if (DoCustomCommandDialog(Param.Name, Param.Command, Param.Params,
- WinConfiguration->CustomCommands, ccmAdHoc, Options,
- AdHocCustomCommandValidate))
- {
- FLastCustomCommand = Param;
- UpdateCustomCommandsToolbar();
- ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &Param);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
- {
- assert(!FLastCustomCommand.Command.IsEmpty());
- int State = CustomCommandState(FLastCustomCommand.Command,
- FLastCustomCommand.Params, OnFocused);
- assert(State > 0);
- if (State <= 0)
- {
- throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
- }
- ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetLastCustomCommand(bool OnFocused,
- TCustomCommandParam & CustomCommand, int & State)
- {
- bool Result = !FLastCustomCommand.Command.IsEmpty();
- if (Result)
- {
- CustomCommand = FLastCustomCommand;
- State = CustomCommandState(FLastCustomCommand.Command,
- FLastCustomCommand.Params, OnFocused);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::WhatsThis()
- {
- SendMessage(Handle, WM_SYSCOMMAND, SC_CONTEXTHELP, 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::BeforeAction()
- {
- if (RemoteDirView->ItemFocused != NULL)
- {
- RemoteDirView->ItemFocused->CancelEdit();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PostComponentHide(unsigned short Component)
- {
- assert(ComponentVisible[Component]);
- PostMessage(Handle, WM_COMPONENT_HIDE, Component, 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender*/)
- {
- // when queue panel is resized here directly, the status bar is stretched
- // over whole space the panel occupied
- PostComponentHide(fcQueueView);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
- {
- TMessage * M = static_cast<TMessage*>(Message);
- switch (M->Msg)
- {
- case CM_APPSYSCOMMAND:
- CMAppSysCommand(*M);
- break;
- case _WM_APPCOMMAND:
- WMAppCommand(*M);
- break;
- case WM_SYSCOMMAND:
- WMSysCommand(*M);
- break;
- case WM_WINDOWPOSCHANGING:
- WMWindowPosChanging(*reinterpret_cast<TWMWindowPosMsg *>(M));
- break;
- case WM_COMPONENT_HIDE:
- {
- unsigned short Component = static_cast<unsigned short>(M->WParam);
- // sanity check
- if (ComponentVisible[Component])
- {
- // special treatment
- if (Component == fcQueueView)
- {
- ToggleQueueVisibility();
- assert(!ComponentVisible[fcQueueView]);
- }
- else
- {
- ComponentVisible[Component] = false;
- }
- }
- }
- break;
- default:
- TForm::Dispatch(Message);
- break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FormConstrainedResize(
- TObject * /*Sender*/, int & MinWidth, int & MinHeight, int & MaxWidth,
- int & MaxHeight)
- {
- // workaround for bug in TWinControl.CalcConstraints
- // Check for empty rect (restore from iconinc state) is done there only after
- // call to AdjustClientRect, which enlarges the rect (for forms).
- TRect R = GetClientRect();
- // when restoring from iconic state, place no restrictions
- if (IsRectEmpty(R))
- {
- MinWidth = 0;
- MinHeight = 0;
- MaxWidth = 0;
- MaxHeight = 0;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::GetSpaceAvailable(const AnsiString Path,
- TSpaceAvailable & ASpaceAvailable, bool & Close)
- {
- // terminal can be already closed (e.g. dropped connection)
- if ((Terminal != NULL) && Terminal->IsCapable[fcCheckingSpaceAvailable])
- {
- try
- {
- Terminal->SpaceAvailable(Path, ASpaceAvailable);
- }
- catch(...)
- {
- if (!Terminal->Active)
- {
- Close = true;
- }
- throw;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileSystemInfo()
- {
- const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
- const TFileSystemInfo & FileSystemInfo = Terminal->GetFileSystemInfo(true);
- TGetSpaceAvailable OnGetSpaceAvailable = NULL;
- if (Terminal->IsCapable[fcCheckingSpaceAvailable])
- {
- OnGetSpaceAvailable = GetSpaceAvailable;
- }
- DoFileSystemInfoDialog(SessionInfo, FileSystemInfo, Terminal->CurrentDirectory,
- OnGetSpaceAvailable);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetSessionColor(TColor value)
- {
- if (value != FSessionColor)
- {
- FSessionColor = value;
- TColor C = (value != 0 ? value : clNone);
- TTBXColorPalette * ColorPalette = dynamic_cast<TTBXColorPalette *>(
- static_cast<TObject *>(GetComponent(fcColorPalette)));
- assert(ColorPalette != NULL);
- ColorPalette->Color = C;
- TTBXColorItem * ColorItem = dynamic_cast<TTBXColorItem *>(
- static_cast<TObject *>(GetComponent(fcColorMenu)));
- assert(ColorItem != NULL);
- ColorItem->Color = C;
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionColorPick()
- {
- TColorDialog * Dialog = new TColorDialog(this);
- try
- {
- Dialog->Options = Dialog->Options << cdFullOpen;
- Dialog->Color = (FSessionColor != 0 ? FSessionColor : clSkyBlue);
- if (Dialog->Execute())
- {
- SessionColor = Dialog->Color;
- }
- }
- __finally
- {
- delete Dialog;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionColorPaletteChange(
- TObject * Sender)
- {
- TTBXColorPalette * ColorPalette = dynamic_cast<TTBXColorPalette *>(Sender);
- assert(ColorPalette != NULL);
- SessionColor = (ColorPalette->Color != clNone ? ColorPalette->Color : (TColor)0);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::CancelNote()
- {
- bool Result = FNoteTimer->Enabled;
- if (Result)
- {
- // cannot cancel note too early
- if (Now() - FNoteShown >
- EncodeTime(0, 0, (unsigned short)(WinConfiguration->NotificationsStickTime), 0))
- {
- FNoteTimer->Enabled = false;
- FNote = "";
- // beware that OnNoteClick may being executed
- SAFE_DESTROY(FNoteData);
- FOnNoteClick = NULL;
- FNoteHints = FNotes->Text;
- FNoteHints.Delete(FNoteHints.Length() - 1, 2);
- UpdateStatusBar();
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::NoteTimer(TObject * /*Sender*/)
- {
- assert(FNoteTimer->Enabled);
- CancelNote();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AddNote(AnsiString Note, bool UpdateNow)
- {
- int P = Note.Pos("\n");
- if (P > 0)
- {
- Note.SetLength(P - 1);
- }
- FNotes->Add(FORMAT("[%s] %s",
- (FormatDateTime(Configuration->TimeFormat, Now()), Note)));
- while (FNotes->Count > 10)
- {
- FNotes->Delete(0);
- }
- if (UpdateNow)
- {
- FNoteHints = FNotes->Text;
- FNoteHints.Delete(FNoteHints.Length() - 1, 2);
- UpdateStatusBar();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PostNote(AnsiString Note,
- unsigned int Seconds, TNotifyEvent OnNoteClick, TObject * NoteData)
- {
- int P = Note.Pos("\n");
- if (P > 0)
- {
- Note.SetLength(P - 1);
- }
- FNoteHints = FNotes->Text;
- FNoteHints.Delete(FNoteHints.Length() - 1, 2);
- FNote = Note;
- // beware that OnNoteClick may being executed
- SAFE_DESTROY(FNoteData);
- FNoteData = NoteData;
- FOnNoteClick = OnNoteClick;
- AddNote(Note, false);
- UpdateStatusBar();
- FNoteShown = Now();
- FNoteTimer->Enabled = false;
- if (Seconds == 0)
- {
- Seconds = WinConfiguration->NotificationsTimeout;
- }
- FNoteTimer->Interval = Seconds * 1000;
- FNoteTimer->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ReadDirectoryCancelled()
- {
- PostNote(LoadStr(DIRECTORY_READING_CANCELLED), 0, NULL, NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SynchronizeBrowsingChanged()
- {
- PostNote(FORMAT(LoadStrPart(SYNC_DIR_BROWSE_TOGGLE, 1),
- (LoadStrPart(SYNC_DIR_BROWSE_TOGGLE,
- (NonVisualDataModule->SynchronizeBrowsingAction->Checked ? 2 : 3)))),
- 0, NULL, NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ToggleShowHiddenFiles()
- {
- WinConfiguration->ShowHiddenFiles = !WinConfiguration->ShowHiddenFiles;
- PostNote(FORMAT(LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE, 1),
- (LoadStrPart(SHOW_HIDDEN_FILES_TOGGLE,
- (WinConfiguration->ShowHiddenFiles ? 2 : 3)))), 0, NULL, NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ToggleAutoReadDirectoryAfterOp()
- {
- Configuration->AutoReadDirectoryAfterOp = !Configuration->AutoReadDirectoryAfterOp;
- PostNote(FORMAT(LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE, 1),
- (LoadStrPart(AUTO_READ_DIRECTORY_TOGGLE,
- (Configuration->AutoReadDirectoryAfterOp ? 2 : 3)))), 0, NULL, NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::StatusBarPanelDblClick(
- TTBXCustomStatusBar * /*Sender*/, TTBXStatusPanel * Panel)
- {
- if (Panel->Index == 0)
- {
- if (FOnNoteClick != NULL)
- {
- FOnNoteClick(NULL);
- }
- }
- else
- {
- FileSystemInfo();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::LockWindow()
- {
- // workaround:
- // 1) for unknown reason, disabling window, while minimized,
- // prevents it from restoring, even if it was enabled again meanwhile
- // 2) when disabling the main window, while another has focus
- // minimize is no longer possible ("keep up to date" dialog)
- if (!IsIconic(Application->Handle) && (Screen->ActiveForm == this))
- {
- Enabled = false;
- }
- FLockLevel++;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UnlockWindow()
- {
- assert(FLockLevel > 0);
- FLockLevel--;
- if (FLockLevel == 0)
- {
- Enabled = true;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::MainWindowHook(TMessage & AMessage)
- {
- // workaround for problem with hidden application window.
- // "groupped" window arrangement commands send WM_WINDOWPOSCHANGING to
- // windows associated with taskbar buttons (i.e. the hidden one for VCL).
- // we forward here the message to the main window.
- // this does not solve "all windows" arrangement commands,
- // which calculates size according to number of all visible windows.
- // hence they count VCL application twice.
- // code is said to be from Issue 4/95 of The Delphi Magazine
- if (AMessage.Msg == WM_WINDOWPOSCHANGING)
- {
- TWMWindowPosMsg & Message = reinterpret_cast<TWMWindowPosMsg &>(AMessage);
- assert(Message.WindowPos->hwnd == Application->Handle);
- if ((Message.WindowPos->hwnd == Application->Handle) &&
- !IsIconic(Message.WindowPos->hwnd) &&
- (Message.WindowPos->cx > 0) &&
- (Message.WindowPos->cy > 0))
- {
- unsigned int LocalFlags = Message.WindowPos->flags | SWP_NOZORDER;
- if (BorderStyle == bsSizeable)
- {
- LocalFlags = LocalFlags & ~SWP_NOSIZE;
- }
- else
- {
- LocalFlags = LocalFlags | SWP_NOSIZE;
- }
- SetWindowPos(Handle, 0, Message.WindowPos->x, Message.WindowPos->y,
- Message.WindowPos->cx, Message.WindowPos->cy, LocalFlags);
- }
- }
- return false;
- }
- //---------------------------------------------------------------------------
|