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