CustomScpExplorer.cpp 189 KB

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