CustomScpExplorer.cpp 205 KB

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