| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <Clipbrd.hpp>
- #include <Common.h>
- #include "CustomScpExplorer.h"
- #include <Interface.h>
- #include <Net.h>
- #include <ScpMain.h>
- #include <FileSystems.h>
- #include <TextsWin.h>
- #include <DiscMon.hpp>
- #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 "Tools.h"
- #include "WinConfiguration.h"
- #include "TerminalManager.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "CustomDirView"
- #pragma link "CustomUnixDirView"
- #pragma link "IEListView"
- #pragma link "NortonLikeListView"
- #pragma link "UnixDirView"
- #pragma link "AssociatedStatusBar"
- #pragma resource "*.dfm"
- //---------------------------------------------------------------------------
- #ifdef DEBUGMODE
- #define DEBUG(MSG) CurrentSSH->LogEvent(MSG)
- #else
- #define DEBUG(MSG)
- #endif
- //---------------------------------------------------------------------------
- #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); \
- } \
- }
- //---------------------------------------------------------------------------
- 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;
- };
- //---------------------------------------------------------------------------
- __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
- FLastDirView(NULL), FFormRestored(False), TForm(Owner)
- {
- RestoreParams();
- 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);
- 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);
- TComboBox * SessionCombo = dynamic_cast<TComboBox*>(GetComponent(fcSessionCombo));
- if (SessionCombo != NULL)
- {
- SessionCombo->OnDrawItem = SessionComboDrawItem;
- SessionCombo->OnDropDown = SessionComboDropDown;
- SessionCombo->OnChange = SessionComboChange;
- SessionCombo->Hint = NonVisualDataModule->OpenedSessionsAction->Hint;
- }
- TToolBar * MenuToolBar = dynamic_cast<TToolBar*>(GetComponent(fcMenuToolBar));
- assert(MenuToolBar);
- MenuToolBar->Font = Screen->MenuFont;
- assert(MenuToolBar->ControlCount);
- MenuToolBar->Height = MenuToolBar->Controls[0]->Height;
- RemoteDirView->Font = Screen->IconFont;
- }
- //---------------------------------------------------------------------------
- __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
- {
- 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;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
- {
- if (FTerminal != value)
- {
- if (FTerminal)
- {
- UpdateSessionData(Terminal->SessionData);
- }
- FTerminal = value;
- TerminalChanged();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalChanged()
- {
- RemoteDirView->Terminal = Terminal;
- Caption = Application->Title;
- if (Terminal)
- {
- if (Terminal->Active)
- {
- Terminal->RefreshDirectory();
- }
- UpdateStatusBar();
- }
- TerminalListChanged(NULL);
- }
- //---------------------------------------------------------------------------
- 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))
- {
- SendMessage(PopupList->Window, WM_CANCELMODE, 0, 0);
- }
- }
- if (Item->Data == FPendingQueueActionItem)
- {
- FPendingQueueActionItem = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateQueueStatus()
- {
- {
- TGuard Guard(FQueueStatusSection);
- FQueueStatusInvalidated = false;
- if (FQueue != NULL)
- {
- FQueueStatus = FQueue->CreateStatus(FQueueStatus);
- }
- }
- FQueueController->UpdateQueueStatus(FQueueStatus);
-
- UpdateQueueView();
- }
- //---------------------------------------------------------------------------
- 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();
- }
- //---------------------------------------------------------------------------
- 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->ModifiesLocal);
- FRefreshRemoteDirectory = (QueueItem == NULL) || (QueueItem->Info->ModifiesRemote);
- }
- if (QueueItem != NULL)
- {
- QueueItem->Flag = true;
- FQueueItemInvalidated = true;
- }
- }
- }
- //---------------------------------------------------------------------------
- TQueueItemProxy * __fastcall TCustomScpExplorerForm::RefreshQueueItems()
- {
- TQueueItemProxy * Result = NULL;
- if (FQueueStatus != NULL)
- {
- bool Refresh = FQueueItemInvalidated;
- FQueueItemInvalidated = false;
- int Limit = Refresh ? FQueueStatus->Count : FQueueStatus->ActiveCount;
- bool Updated = false;
- bool Update;
- TQueueItemProxy * QueueItem;
- bool UserAction;
- for (int Index = 0; Index < Limit; Index++)
- {
- Update = false;
- QueueItem = FQueueStatus->Items[Index];
- UserAction = TQueueItem::IsUserActionStatus(QueueItem->Status);
- if (UserAction && (Result == NULL))
- {
- Result = QueueItem;
- }
- if (QueueItem->Flag)
- {
- QueueItem->Flag = false;
- QueueItem->Update();
- Updated = true;
- Update = true;
- }
- else if (UserAction)
- {
- Update = true;
- }
- if (Update)
- {
- FQueueController->RefreshQueueItem(QueueItem);
- }
- }
- if (Updated)
- {
- NonVisualDataModule->UpdateNonVisibleActions();
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
- {
- assert(Configuration && RemoteDirView);
- RemoteDirView->DDAllowMove = WinConfiguration->DDAllowMoveInit;
- RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
- RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
- RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
- RemoteDirView->DDTemporaryDirectory = WinConfiguration->DDTemporaryDirectory;
- UpdateQueueView();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewGetCopyParam(
- TUnixDirView * /*Sender*/, TTransferDirection Direction,
- TTransferType Type, AnsiString &TargetDirectory, TStrings * FileList,
- TCopyParamType &CopyParam)
- {
- TGUICopyParamType GUICopyParam = GUIConfiguration->CopyParam;
- // overwrites TCopyParamType fields only
- GUICopyParam = CopyParam;
- if (!CopyParamDialog(Direction, Type, true, FileList,
- TargetDirectory, GUICopyParam, WinConfiguration->DDTransferConfirmation))
- {
- Abort();
- }
- else
- {
- CopyParam = GUICopyParam;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
- TTransferDirection Direction, TTransferType Type, bool DragDrop,
- TStrings * FileList, AnsiString & TargetDirectory, TGUICopyParamType & CopyParam,
- bool Confirm)
- {
- bool Result = true;
- assert(Terminal && Terminal->Active);
- if (DragDrop && (Direction == tdToLocal) && (Type == ttMove) &&
- !WinConfiguration->DDAllowMove)
- {
- int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
- qaOK | qaCancel, 0, mpNeverAskAgainCheck);
- if (Answer == qaNeverAskAgain)
- {
- WinConfiguration->DDAllowMove = true;
- }
- else if (Answer == qaCancel)
- {
- Result = false;
- }
- }
- bool DragDropTemp = (DragDrop && (Direction == tdToLocal));
- if (Result && Confirm)
- {
- int Options =
- (!Terminal->IsCapable[fcTextMode] ? coDisableTransferMode : 0) |
- (DragDropTemp ? coDragDropTemp : 0);
- Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
- FileList, TargetDirectory, &CopyParam, Options);
- }
- if (Result && CopyParam.Queue && !DragDropTemp)
- {
- assert(Queue != NULL);
- int Params =
- ((Type == ttMove) ? cpDelete : 0) |
- (CopyParam.QueueNoConfirmation ? cpNoConfirmation : 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()
- {
- // IDE often looses this link
- RemoteDirView->HeaderImages = NonVisualDataModule->ArrowImages;
- if (Position == poDesigned)
- {
- RestoreFormParams();
- }
- ConfigurationChanged();
- QueuePanel->Height = WinConfiguration->QueueView.Height;
- LoadListViewStr(QueueView, WinConfiguration->QueueView.Layout);
- QueueCoolBar->Visible = WinConfiguration->QueueView.ToolBar;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::StoreParams()
- {
- WinConfiguration->QueueView.Height = QueuePanel->Height;
- WinConfiguration->QueueView.Layout = GetListViewStr(QueueView);
- WinConfiguration->QueueView.ToolBar = QueueCoolBar->Visible;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
- {
- if (!FFormRestored)
- {
- FFormRestored = true;
- RestoreFormParams();
- }
- TForm::CreateParams(Params);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FileOperationProgress(
- TFileOperationProgressType & ProgressData, TCancelStatus & /*Cancel*/)
- {
- // 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 = WinConfiguration->DeleteToRecycleBin;
- // When main window is hidden, we suppose "/upload" mode
- if (!Visible)
- {
- FProgressForm->DisconnectWhenComplete = true;
- }
- }
- // operation is finished (or terminated), so we hide progress form
- else if (!ProgressData.InProgress && FProgressForm)
- {
- SAFE_DESTROY(FProgressForm);
- }
- if (FProgressForm)
- {
- FProgressForm->SetProgressData(ProgressData);
- if (FProgressForm->Cancel > ProgressData.Cancel)
- {
- ProgressData.Cancel = FProgressForm->Cancel;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OperationProgress(
- TFileOperationProgressType & ProgressData, TCancelStatus & Cancel)
- {
- FileOperationProgress(ProgressData, Cancel);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoOperationFinished(
- TFileOperation Operation, TOperationSide Side,
- bool DragDrop, const AnsiString FileName, bool Success,
- bool & DisconnectWhenComplete)
- {
- if (!FAutoOperation)
- {
- // no selection on "/upload", form servers only as event handler
- // (it is not displayed)
- if (!DragDrop && Visible && (Operation != foCalculateSize))
- {
- AnsiString FileNameOnly = (Side == osRemote) ?
- UnixExtractFileName(FileName) : ExtractFileName(FileName);
- TListItem *Item = DirView(Side)->FindFileItem(FileNameOnly);
- assert(Item);
- if (Success) Item->Selected = false;
- Item->MakeVisible(false);
- }
- }
- if (FProgressForm)
- {
- DisconnectWhenComplete = FProgressForm->DisconnectWhenComplete;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OperationFinished(
- TFileOperation Operation, TOperationSide Side,
- bool DragDrop, const AnsiString FileName, Boolean Success,
- bool & DisconnectWhenComplete)
- {
- DoOperationFinished(Operation, Side, DragDrop, FileName, Success,
- DisconnectWhenComplete);
- }
- //---------------------------------------------------------------------------
- TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
- {
- assert((Side == osRemote) || ((Side == osCurrent) && FLastDirView));
- return (Side == osCurrent) ? FLastDirView : RemoteDirView;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(TOperationSide Side)
- {
- return DirView(Side)->AnyFileSelected(true);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(TOperationSide Side)
- {
- return DirView(Side)->AnyFileSelected(false);
- }
- //---------------------------------------------------------------------------
- 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))
- {
- TPoint ScreenPoint, ClientPoint;
- ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
- TPoint(0, 0) : MousePos;
- ScreenPoint = RemoteDirView->ClientToScreen(ClientPoint);
- NonVisualDataModule->CurrentOpenMenuItem->Default = !WinConfiguration->CopyOnDoubleClick;
- NonVisualDataModule->CurrentCopyMenuItem->Default = WinConfiguration->CopyOnDoubleClick;
- NonVisualDataModule->CurrentOpenMenuItem->Visible = WinConfiguration->ExpertMode;
- NonVisualDataModule->CurentEditMenuItem->Visible = WinConfiguration->ExpertMode;
- reinterpret_cast<TPopupMenu*>(GetComponent(fcRemotePopup))->Popup(
- ScreenPoint.x, ScreenPoint.y);
- }
- Handled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::BatchStart(void *& Storage)
- {
- assert(FErrorList == NULL);
- Storage = new bool;
- if (HasDirView[osLocal])
- {
- *static_cast<bool*>(Storage) = DirView(osLocal)->WatchForChanges;
- DirView(osLocal)->WatchForChanges = false;
- }
- if (WinConfiguration->ContinueOnError)
- {
- FErrorList = new TStringList();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::BatchEnd(void * Storage)
- {
- assert(Storage != NULL);
- if (FErrorList)
- {
- HandleErrorList(FErrorList);
- }
- if (HasDirView[osLocal])
- {
- DirView(osLocal)->WatchForChanges = *static_cast<bool*>(Storage);
- }
- delete Storage;
- }
- //---------------------------------------------------------------------------
- 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;
- if (Param != NULL)
- {
- TargetDirectory = *static_cast<AnsiString*>(Param);
- }
- TGUICopyParamType CopyParam = GUIConfiguration->CopyParam;
- if (CopyParamDialog(Direction, Type, false, FileList, TargetDirectory,
- CopyParam, !NoConfirmation))
- {
- assert(Terminal);
- TCustomDirView * DView = DirView(Side);
- bool SelectionRestored = false;
- DView->SaveSelection();
- try
- {
- if (Side == osLocal)
- {
- int Params = 0;
- if (Operation == foMove) Params |= cpDelete;
- Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params);
- if (Operation == foMove)
- {
- DView->Reload(True);
- DView->RestoreSelection();
- SelectionRestored = true;
- }
- }
- else
- {
- try
- {
- Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam,
- (Operation == foMove ? cpDelete : 0));
- }
- __finally
- {
- if (Operation == foMove)
- {
- DView->RestoreSelection();
- SelectionRestored = true;
- }
- if (HasDirView[osLocal] &&
- (IncludeTrailingBackslash(TargetDirectory) ==
- IncludeTrailingBackslash(DirView(osLocal)->Path)))
- {
- DirView(osLocal)->ReloadDirectory();
- }
- }
- }
- }
- __finally
- {
- if (!SelectionRestored)
- {
- 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));
- }
- int Answer = MessageDialog(Query, qtConfirmation,
- qaOK | qaCancel, 0, mpNeverAskAgainCheck);
- if (Answer == qaNeverAskAgain)
- {
- Confirmed = true;
- WinConfiguration->ConfirmDeleting = false;
- }
- else
- {
- Confirmed = (Answer == qaOK);
- }
- }
- if (Confirmed) DeleteFiles(Side, FileList);
- }
- else if (Operation == foSetProperties)
- {
- SetProperties(Side, FileList);
- }
- else if (Operation == foCustomCommand)
- {
- assert(Param);
- assert(Side == osRemote);
- FCustomCommandName = *((AnsiString *)Param);
- try
- {
- AnsiString Command = TCustomFileSystem::CompleteCustomCommand(
- WinConfiguration->CustomCommands->Values[FCustomCommandName],
- "", CustomCommandGetParamValue);
- Terminal->CustomCommandOnFiles(Command,
- WinConfiguration->CustomCommands->Params[FCustomCommandName],
- FileList);
- }
- __finally
- {
- FCustomCommandName = "";
- }
- }
- else if (Operation == foRemoteMove)
- {
- assert(Side == osRemote);
- RemoteMoveFiles(FileList, NoConfirmation);
- }
- else
- {
- assert(false);
- }
- }
- __finally
- {
- BatchEnd(BatchStorage);
- }
- }
- //---------------------------------------------------------------------------
- TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
- {
- if (Side == osCurrent)
- {
- Side = osRemote;
- }
- 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::CustomCommandGetParamValue(
- const AnsiString AName, AnsiString & Value)
- {
- assert(!FCustomCommandName.IsEmpty());
- AnsiString Name = AName;
- if (Name.IsEmpty())
- {
- Name = FMTLOAD(CUSTOM_COMMANDS_PARAM_PROMPT, (StripHotkey(FCustomCommandName)));
- }
- if (!InputDialog(FMTLOAD(CUSTOM_COMMANDS_PARAM_TITLE,
- (StripHotkey(FCustomCommandName))), Name, Value))
- {
- Abort();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
- {
- try
- {
- if (ErrorList->Count)
- {
- if (MessageDialog(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)), qtError,
- qaOK | qaCancel, 0) == qaOK)
- {
- int Answer;
- int Index = 0;
- do
- {
- assert(Index >= 0 && Index < ErrorList->Count);
- Answer = MoreMessageDialog(
- FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
- dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
- (Index ? qaPrev : 0) | (Index < ErrorList->Count - 1 ? qaNext : 0) |
- qaOK, 0);
- if (Answer == qaNext)
- {
- Index++;
- }
- if (Answer == qaPrev)
- {
- 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::ExecuteFile(TOperationSide Side,
- TExecuteFileBy ExecuteFileBy)
- {
- assert(!WinConfiguration->DisableOpenEdit);
- if (Side == osCurrent)
- {
- Side = FLastDirView == RemoteDirView ? osRemote : osLocal;
- }
- bool Edit = (ExecuteFileBy == efEditor || ExecuteFileBy == efAlternativeEditor);
- bool InternalEdit = Edit &&
- ((WinConfiguration->Editor.Editor == edInternal) !=
- (ExecuteFileBy == efAlternativeEditor));
- FExecutedFileForceText =
- (InternalEdit || (Edit && WinConfiguration->Editor.ExternalEditorText));
- TStrings * FileList = DirView(Side)->CreateFocusedFileList(Side == osLocal);
- try
- {
- assert(FileList->Count == 1);
- if (Side == osRemote)
- {
- TCopyParamType CopyParam = GUIConfiguration->CopyParam;
- if (FExecutedFileForceText)
- {
- CopyParam.TransferMode = tmAscii;
- }
- CopyParam.FileNameCase = ncNoChange;
- CopyParam.PreserveReadOnly = false;
- CopyParam.ResumeSupport = rsOff;
- AnsiString TempDir = UniqTempDir(WinConfiguration->DDTemporaryDirectory);
- ForceDirectories(TempDir);
- FAutoOperation = true;
- Terminal->ExceptionOnFail = true;
- try
- {
- Terminal->CopyToLocal(FileList, TempDir, &CopyParam, cpTemporary);
- }
- __finally
- {
- FAutoOperation = false;
- Terminal->ExceptionOnFail = false;
- }
- FExecutedFile = TempDir + FileList->Strings[0];
- }
- else
- {
- FExecutedFile = FileList->Strings[0];
- }
- }
- __finally
- {
- delete FileList;
- }
- Terminal->BeginTransaction();
- try
- {
- try
- {
- FExecutedFileTimestamp = FileAge(FExecutedFile);
- FFileExecutedBy = ExecuteFileBy;
- if (InternalEdit)
- {
- TNotifyEvent OnFileChanged = NULL;
- AnsiString Caption = FExecutedFile;
- if (Side == osRemote)
- {
- OnFileChanged = ExecutedFileChanged;
- Caption = RemoteDirView->Path + ExtractFileName(FExecutedFile);
- }
- DoEditorForm(FExecutedFile, this, OnFileChanged, Caption);
- }
- else
- {
- TDiscMonitor * DiscMonitor = NULL;
- try
- {
- if (Side == osRemote)
- {
- DiscMonitor = new TDiscMonitor(this);
- DiscMonitor->SubTree = false;
- DiscMonitor->Filters = TMonitorFilters() << moLastWrite;
- DiscMonitor->Directory = ExtractFilePath(FExecutedFile);
- DiscMonitor->OnChange = ExecutedFileChanged;
- DiscMonitor->Active = true;
- }
- TOperationStatusForm * StatusForm = new TOperationStatusForm(Application);
- try
- {
- StatusForm->Status = LoadStr(DOCUMENT_WAIT);
- StatusForm->ShowAsModal();
- if (Edit)
- {
- AnsiString ExternalEditor, Program, Params, Dir;
- ExternalEditor = WinConfiguration->Editor.ExternalEditor;
- TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
- SplitCommand(ExternalEditor, Program, Params, Dir);
- assert(Params.Pos(ShellCommandFileNamePattern) > 0);
- Params = StringReplace(Params, ShellCommandFileNamePattern,
- AddPathQuotes(FExecutedFile), TReplaceFlags() << rfReplaceAll);
- if (ExecuteShellAndWait(Program, Params) < 0)
- {
- throw Exception(FMTLOAD(EDITOR_ERROR, (Program)));
- }
- }
- else
- {
- assert(Side == osRemote);
- if (ExecuteShellAndWait(FExecutedFile, "") < 0)
- {
- throw Exception(FMTLOAD(EXECUTE_FILE_ERROR, (FExecutedFile)));
- }
- }
- }
- __finally
- {
- delete StatusForm;
- }
- if (Side == osRemote)
- {
- if (DiscMonitor)
- {
- DiscMonitor->Active = false;
- }
- // upload file if it was saved while [editor] was closed
- ExecutedFileChanged(NULL);
- }
- }
- __finally
- {
- delete DiscMonitor;
- }
- }
- }
- __finally
- {
- AnsiString FileName = FExecutedFile;
- FExecutedFile = "";
- if (Side == osRemote)
- {
- bool Deleted;
- AnsiString DirName = ExtractFilePath(FileName);
- if (WinConfiguration->ForceDeleteTempFolder)
- {
- Deleted = RecursiveDeleteFile(ExcludeTrailingBackslash(DirName), false);
- }
- else
- {
- Deleted = DeleteFile(FileName) && RemoveDir(DirName);
- }
- if (!Deleted)
- {
- throw Exception(FMTLOAD(DELETE_TEMP_EXECUTE_FILE_ERROR, (DirName)));
- }
- }
- else
- {
- DirView(osLocal)->ReloadDirectory();
- }
- }
- }
- __finally
- {
- Terminal->EndTransaction();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(TObject * Sender)
- {
- static Uploading = 0;
- try
- {
- assert(!FExecutedFile.IsEmpty());
- if (Uploading == 1)
- {
- Uploading = 2;
- }
- else
- {
- Uploading = 1;
- try
- {
- int FileTimestamp = FileAge(FExecutedFile);
- if (FileTimestamp != FExecutedFileTimestamp)
- {
- FExecutedFileTimestamp = FileTimestamp;
- TStrings * FileList = new TStringList();
- try
- {
- FileList->Add(FExecutedFile);
- TCopyParamType CopyParam = GUIConfiguration->CopyParam;
- if (FExecutedFileForceText)
- {
- CopyParam.TransferMode = tmAscii;
- }
- CopyParam.FileNameCase = ncNoChange;
- CopyParam.PreserveRights = false;
- CopyParam.ResumeSupport = rsOff;
- FAutoOperation = true;
- Terminal->ExceptionOnFail = true;
- try
- {
- Terminal->CopyToRemote(FileList, RemoteDirView->PathName,
- &CopyParam, cpNoConfirmation);
- }
- __finally
- {
- FAutoOperation = false;
- Terminal->ExceptionOnFail = false;
- }
- }
- __finally
- {
- delete FileList;
- }
- }
- }
- __finally
- {
- if (Uploading == 2)
- {
- Uploading = 0;
- ExecutedFileChanged(this);
- }
- else
- {
- Uploading = 0;
- }
- }
- }
- }
- catch (Exception & E)
- {
- if (dynamic_cast<TDiscMonitor *> (Sender))
- {
- Terminal->DoHandleExtendedException(&E);
- }
- else
- {
- throw;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewEnter(TObject *Sender)
- {
- DoDirViewEnter(dynamic_cast<TCustomDirView*>(Sender));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DoDirViewEnter(TCustomDirView * DirView)
- {
- assert(DirView != NULL);
- FLastDirView = DirView;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
- TStrings * FileList)
- {
- assert(Terminal);
- TCustomDirView * DView = DirView(Side);
- DView->SaveSelection();
- try
- {
- if (Side == osRemote)
- {
- Terminal->DeleteFiles(FileList);
- }
- else
- {
- try
- {
- Terminal->DeleteLocalFiles(FileList);
- }
- __finally
- {
- DView->Reload(true);
- }
- }
- }
- catch(...)
- {
- DView->DiscardSavedSelection();
- throw;
- }
- DView->RestoreSelection();
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::RemoteMoveDialog(TStrings * FileList,
- AnsiString & Target, AnsiString & FileMask, bool NoConfirmation)
- {
- 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 = DoRemoteMoveDialog(FileList, Target, FileMask);
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteMoveFiles(
- TStrings * FileList, bool NoConfirmation)
- {
- AnsiString Target, FileMask;
- if (RemoteMoveDialog(FileList, Target, FileMask, NoConfirmation))
- {
- RemoteDirView->SaveSelection();
- try
- {
- Terminal->MoveFiles(FileList, Target, FileMask);
- }
- catch(...)
- {
- RemoteDirView->DiscardSavedSelection();
- throw;
- }
- RemoteDirView->RestoreSelection();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
- {
- AnsiString Name = LoadStr(NEW_FOLDER);
- if (InputDialog(LoadStr(CREATE_FOLDER_CAPTION), LoadStr(CREATE_FOLDER_PROMPT), Name))
- {
- 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;
- 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 < NonVisualDataModule->OpenedSessionsMenu->Count; i++)
- {
- TMenuItem * Item = NonVisualDataModule->OpenedSessionsMenu->Items[i];
- if (Item->ShortCut == KeyShortCut)
- {
- Key = 0;
- Item->Click();
- FIgnoreNextSysCommand = true;
- return;
- }
- }
- if (Key == VK_TAB && Shift.Contains(ssCtrl))
- {
- TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
- }
- }
- TForm::KeyDown(Key, Shift);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
- {
- TStatusBar * SessionStatusBar = (TStatusBar *)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]->Text = FormatBytes(Terminal->BytesReceived);
- SessionStatusBar->Panels->Items[Index + 1]->Text = FormatBytes(Terminal->BytesSent);
- SessionStatusBar->Panels->Items[Index + 5]->Text = Terminal->ProtocolName;
- SessionStatusBar->Panels->Items[Index + 6]->Text =
- FormatDateTime(Configuration->TimeFormat, Terminal->Duration);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionStatusBarDrawPanel(
- TStatusBar *StatusBar, TStatusPanel *Panel, const TRect &Rect)
- {
- if (Terminal && Terminal->Active && Terminal->Status >= sshReady)
- {
- TFontStyles Style;
- StatusBar->Font->Style = Style;
- int ImageIndex;
- AnsiString PanelText;
- switch (Panel->Index - StatusBar->Tag) {
- case 2: ImageIndex = Terminal->SshVersion - 1; break;
- case 3: ImageIndex = 2 + (Terminal->CSCompression || Terminal->SCCompression); break;
- case 4: ImageIndex = 4; PanelText = CipherNames[Terminal->CSCipher]; break;
- default: assert(false); break;
- }
- TCanvas *SCanvas = StatusBar->Canvas;
- if ((Panel->Alignment == taCenter) && PanelText.IsEmpty())
- {
- NonVisualDataModule->SessionImages->Draw(SCanvas,
- Rect.Left + Rect.Width() / 2 - NonVisualDataModule->SessionImages->Width / 2,
- Rect.Top, ImageIndex, true);
- }
- else
- {
- NonVisualDataModule->SessionImages->Draw(SCanvas,
- Rect.Left + 1, Rect.Top, ImageIndex, true);
- if (!PanelText.IsEmpty())
- {
- SCanvas->TextOut(Rect.left + 18, Rect.top + 1, PanelText);
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::Idle(bool AppIdle)
- {
- // 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();
- }
- if (AppIdle)
- {
- if (FRefreshRemoteDirectory)
- {
- if ((Terminal != NULL) && Terminal->Active)
- {
- Terminal->RefreshDirectory();
- }
- FRefreshRemoteDirectory = false;
- }
- if (FRefreshLocalDirectory)
- {
- if (HasDirView[osLocal])
- {
- DirView(osLocal)->ReloadDirectory();
- }
- FRefreshLocalDirectory = false;
- }
- }
- if (FQueueStatusInvalidated)
- {
- UpdateQueueStatus();
- }
- TQueueItemProxy * PendingQueueActionItem = RefreshQueueItems();
- if (AppIdle &&
- GUIConfiguration->QueueAutoPopup &&
- (PendingQueueActionItem != NULL) &&
- (FPendingQueueActionItem == NULL))
- {
- FPendingQueueActionItem = PendingQueueActionItem;
- FUserActionTimer->Enabled = true;
- }
- 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::SessionStatusBarMouseMove(
- TObject * Sender, TShiftState /*Shift*/, int X, int Y)
- {
- if (Terminal && Terminal->Active)
- {
- const int Hints[3] = { STATUS_RECEIVED_HINT, STATUS_SENT_HINT, STATUS_DURATION_HINT };
- TStatusBar * StatusBar = ((TStatusBar *)Sender);
- assert(StatusBar);
- TPoint Local(X, Y)/* = StatusBar->ScreenToClient(Mouse->CursorPos)*/;
- int IPanel = 0;
- while ((Local.x > StatusBar->Panels->Items[IPanel]->Width) &&
- (IPanel < StatusBar->Panels->Count - 1))
- {
- Local.x -= StatusBar->Panels->Items[IPanel]->Width;
- IPanel ++;
- }
- AnsiString AHint;
- if (StatusBar->Tag && (IPanel == 0))
- {
- AHint = LoadStr(STATUS_FILEINFO_HINT);
- }
- else
- {
- if (StatusBar->Tag) IPanel--;
- switch (IPanel) {
- case 0:
- case 1: AHint = LoadStr(Hints[IPanel]); break;
- case 6: AHint = LoadStr(Hints[2]); break;
- case 2: AHint = FMTLOAD(STATUS_VERSION_HINT, (Terminal->SshVersion)); break;
- case 3:
- if (Terminal->CSCompression == Terminal->SCCompression)
- {
- AHint = FMTLOAD(STATUS_COMPRESSION_HINT, (BooleanToStr(Terminal->CSCompression)));
- }
- else
- {
- AHint = FMTLOAD(STATUS_COMPRESSION2_HINT,
- (BooleanToStr(Terminal->CSCompression), BooleanToStr(Terminal->SCCompression)));
- }
- break;
- case 4:
- if (Terminal->CSCipher == Terminal->SCCipher)
- {
- AHint = FMTLOAD(STATUS_ENCRYPTION_HINT, (CipherNames[Terminal->CSCipher]));
- }
- else
- {
- AHint = FMTLOAD(STATUS_ENCRYPTION2_HINT,
- (CipherNames[Terminal->CSCipher], CipherNames[Terminal->SCCipher]));
- }
- break;
- case 5:
- AHint = FMTLOAD(STATUS_FS_PROTOCOL, (Terminal->ProtocolName));
- break;
- default: AHint = ""; break;
- }
- }
- if (AHint.IsEmpty())
- {
- StatusBar->Hint = AHint;
- }
- else
- {
- AHint = FORMAT("%s|X", (AHint));
- if (AHint != StatusBar->Hint)
- {
- Application->CancelHint();
- StatusBar->Hint = AHint;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- 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()
- {
- TSessionData * Data = new TSessionData("");
- try
- {
- Data->Assign(StoredSessions->DefaultSettings);
- if (DoLoginDialog(StoredSessions, Data, loAddSession))
- {
- assert(Data->CanLogin);
- TTerminalManager * Manager = TTerminalManager::Instance();
- TTerminal * Terminal = Manager->NewTerminal(Data);
- Manager->ActiveTerminal = Terminal;
- Manager->ConnectActiveTerminal();
- }
- }
- __finally
- {
- delete Data;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::CanCloseQueue()
- {
- assert(FQueue != NULL);
- return (FQueue->IsEmpty ||
- (MessageDialog(LoadStr(PENDING_QUEUE_ITEMS), qtWarning, qaOK | qaCancel) == 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;
- if (TTerminalManager::Instance()->Count > 1)
- {
- Result = MessageDialog(LoadStr(CLOSE_SESSIONS), qtConfirmation,
- qaOK | qaCancel, 0, mpNeverAskAgainCheck);
- }
- else
- {
- Result = MessageDialog(FMTLOAD(CLOSE_SESSION,
- (Terminal->SessionData->SessionName)), qtConfirmation,
- qaOK | qaCancel, 0, mpNeverAskAgainCheck);
- }
- if (Result == qaNeverAskAgain)
- {
- WinConfiguration->ConfirmClosingSession = false;
- }
- CanClose = (Result == qaOK || Result == qaNeverAskAgain);
- }
- if (CanClose)
- {
- CanClose = CanCloseQueue();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DropDownButtonMenu(TObject *Sender)
- {
- ((TToolButton*)Sender)->CheckMenuDropdown();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
- TObject *Sender)
- {
- TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
- try
- {
- SetProperties(osRemote, FileList);
- }
- __finally
- {
- delete FileList;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SetComponentVisible(Word Component, Boolean value)
- {
- TControl * Control = GetComponent((Word)(Component & 0x00FF));
- assert(Control);
- bool Changed;
- if ((dynamic_cast<TCoolBar*>(Control) != NULL) && (Component & 0xFF00))
- {
- TCoolBand * Band = GetCoolBand(dynamic_cast<TCoolBar*>(Control),
- (Component & 0xFF00) >> 8);
- assert(Band);
- Changed = (Band->Visible != value);
- if (Changed)
- {
- Band->Visible = value;
- }
- }
- else
- {
- Changed = (Control->Visible != value);
- if (Changed)
- {
- Control->Visible = value;
- }
- }
- if (Changed)
- {
- FixControlsPlacement();
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Word Component)
- {
- TControl * Control = GetComponent((Word)(Component & 0x00FF));
- if (Control == NULL)
- {
- return false;
- }
- else if ((dynamic_cast<TCoolBar*>(Control) != NULL) && (Component & 0xFF00))
- {
- TCoolBand * Band = GetCoolBand(dynamic_cast<TCoolBar*>(Control),
- (Component & 0xFF00) >> 8);
- return Band != NULL ? Band->Visible : false;
- }
- else
- {
- return Control->Visible;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FixControlsPlacement()
- {
- TToolBar * MenuToolBar = dynamic_cast<TToolBar*>(GetComponent(fcMenuToolBar));
- MenuToolBar->Height = MenuToolBar->Controls[0]->Height;
- if (RemoteDirView->ItemFocused != NULL)
- {
- RemoteDirView->ItemFocused->MakeVisible(false);
- }
- QueueSplitter->Visible = QueuePanel->Visible;
- }
- //---------------------------------------------------------------------------
- TCoolBand * __fastcall TCustomScpExplorerForm::GetCoolBand(TCoolBar * Coolbar, int ID)
- {
- return dynamic_cast<TCoolBand *>(Coolbar->Bands->FindItemID(ID));
- }
- //---------------------------------------------------------------------------
- TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
- {
- switch (Component) {
- case fcStatusBar: return RemoteStatusBar;
- case fcCoolBar: return TopCoolBar;
- case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteDirViewPopup);
- case fcQueueView: return QueuePanel;
- case fcQueueToolbar: return QueueCoolBar;
- 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;
- }
- else
- {
- DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
- }
- 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);
- TCustomDirView * ADirView = (TCustomDirView *)Sender;
- if (ADirView->ItemIsDirectory(Item))
- {
- AllowExec = true;
- }
- else if (WinConfiguration->CopyOnDoubleClick && !FForceExecution)
- {
- ExecuteFileOperation(foCopy,
- (ADirView == DirView(osRemote) ? osRemote : osLocal),
- true, !WinConfiguration->CopyOnDoubleClickConfirmation);
- AllowExec = false;
- }
- else if (ADirView == DirView(osRemote) && !WinConfiguration->DisableOpenEdit)
- {
- ExecuteFile(osRemote, efDefault);
- AllowExec = false;
- }
- else
- {
- AllowExec = true;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
- {
- return ((Side == osRemote) || (Side == osCurrent));
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::CompareDirectories()
- {
- assert(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
- {
- assert(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::FullSynchronizeDirectories()
- {
- assert(false);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
- AnsiString & LocalDirectory, AnsiString & RemoteDirectory, TSynchronizeMode & Mode)
- {
- bool Result;
- int Params = GUIConfiguration->SynchronizeParams;
- bool SaveSettings;
- Result = DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
- SaveSettings);
- if (Result)
- {
- if (SaveSettings)
- {
- GUIConfiguration->SynchronizeParams = Params;
- }
- assert(!FAutoOperation);
- void * BatchStorage;
- BatchStart(BatchStorage);
- FAutoOperation = true;
- try
- {
- TCopyParamType CopyParam = GUIConfiguration->CopyParam;
- FSynchronizeProgressForm = new TSynchronizeProgressForm(Application);
- FSynchronizeProgressForm->Start();
- Terminal->Synchronize(LocalDirectory, RemoteDirectory,
- static_cast<TTerminal::TSynchronizeMode>(Mode),
- &CopyParam, Params, TerminalSynchronizeDirectory);
- }
- __finally
- {
- FAutoOperation = false;
- SAFE_DESTROY(FSynchronizeProgressForm);
- BatchEnd(BatchStorage);
- if (HasDirView[osLocal])
- {
- DirView(osLocal)->Reload(true);
- }
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
- const AnsiString LocalDirectory, const AnsiString RemoteDirectory, bool & Continue)
- {
- assert(FSynchronizeProgressForm != NULL);
- 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;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
- {
- TToolBar * ToolBar = (TToolBar*)Sender;
- TControl * Child = (TControl *)ToolBar->Controls[0];
- Child->Width = ToolBar->Width;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewWarnLackOfTempSpace(
- TUnixDirView * /*Sender*/, 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));
- Integer MessageRes = 0;
- if (RequiredSpace >= 0)
- {
- __int64 RequiredWithReserve;
- RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
- if (FreeSpace < RequiredWithReserve) MessageRes = DD_WARN_LACK_OF_TEMP_SPACE;
- }
- else
- {
- MessageRes = DD_WARN_UNKNOWN_TEMP_SPACE;
- }
- if (MessageRes)
- {
- int Result;
- Result = MessageDialog(FMTLOAD(MessageRes, (Path,
- FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
- qtWarning, qaYes | qaNo, 0, mpNeverAskAgainCheck);
- 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, 0) == qaYes))
- {
- TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
- try
- {
- AnsiString Name = DirView(Side)->PathName;
- if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal))
- {
- DirView(Side)->Path = Name;
- }
- }
- __finally
- {
- delete VisitedDirectories;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OpenInPutty()
- {
- OpenSessionInPutty(Terminal->SessionData);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::OpenConsole(AnsiString Command)
- {
- DoConsoleDialog(Terminal, Command);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewDDDragEnter(
- TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
- const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
- {
- if ((DropSourceControl == RemoteDirView) &&
- (FDDExtMapFile != NULL))
- {
- Accept = true;
- }
- FDDTargetDirView = (TCustomDirView*)Sender;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::DirViewDDDragLeave(
- TObject *Sender)
- {
- USEDPARAM(Sender);
- assert(FDDTargetDirView == Sender);
- FDDTargetDirView = NULL;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::AddEditLink()
- {
- assert(FLastDirView == RemoteDirView);
- 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 = 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::LastTerminalClosed(TObject * /*Sender*/)
- {
- try
- {
- NewSession();
- }
- __finally
- {
- if (!Terminal || !Terminal->Active)
- {
- Application->Terminate();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
- {
- TCustomCombo * SessionCombo = dynamic_cast<TCustomCombo *>(GetComponent(fcSessionCombo));
- if (SessionCombo != NULL)
- {
- SessionCombo->Items = TTerminalManager::Instance()->TerminalList;
- SessionCombo->ItemIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
- }
- NonVisualDataModule->CreateOpenedSessionListMenu();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionComboDropDown(TObject * Sender)
- {
- TCustomComboBox * SessionCombo = dynamic_cast<TCustomComboBox *>(Sender);
- assert(SessionCombo);
- TCanvas * Canvas = SessionCombo->Canvas;
- int MaxWidth = 0, Width;
- for (int i = 0; i < SessionCombo->Items->Count; i++)
- {
- Width = Canvas->TextExtent(SessionCombo->Items->Strings[i]).cx;
- TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(i);
- if (ShortCut != scNone)
- {
- Width += Canvas->TextExtent(ShortCutToText(ShortCut)).cx;
- }
- if (Width > MaxWidth)
- {
- MaxWidth = Width;
- }
- }
- MaxWidth += 8;
- if (SessionCombo->Items->Count > ((TComboBox *)SessionCombo)->DropDownCount)
- {
- MaxWidth += GetSystemMetrics(SM_CXVSCROLL);
- }
- SessionCombo->Perform(CB_SETDROPPEDWIDTH, MaxWidth + 8 + 1, 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionComboDrawItem(
- TWinControl * Control, int Index, const TRect & Rect, TOwnerDrawState /*State*/)
- {
- TCustomComboBox * SessionCombo = dynamic_cast<TCustomComboBox *>(Control);
- assert(SessionCombo);
- TCanvas * Canvas = SessionCombo->Canvas;
- Canvas->FillRect(Rect);
- if (Index >= 0)
- {
- int ShortCutWidth = 0;
- AnsiString ShortCutStr;
- if (Rect.Top != 3)
- {
- TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(Index);
- if (ShortCut != scNone)
- {
- ShortCutStr = ShortCutToText(ShortCut);
- ShortCutWidth = Canvas->TextExtent(ShortCutStr).cx;
- }
- }
- TRect R = Rect;
- R.Right -= ShortCutWidth + 2;
- Canvas->TextRect(R, R.Left + 2, R.Top, SessionCombo->Items->Strings[Index]);
- R = Rect;
- R.Left = R.Right - ShortCutWidth - 2;
- Canvas->TextRect(R, R.Left, R.Top, ShortCutStr);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::SessionComboChange(TObject * Sender)
- {
- TCustomComboBox * SessionCombo = dynamic_cast<TCustomComboBox *>(Sender);
- assert(SessionCombo);
- TTerminal * Terminal;
- Terminal = dynamic_cast<TTerminal *>(SessionCombo->Items->Objects[SessionCombo->ItemIndex]);
- assert(Terminal);
- TTerminalManager::Instance()->ActiveTerminal = Terminal;
- }
- //---------------------------------------------------------------------------
- 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::DoShow()
- {
- FixControlsPlacement();
- TForm::DoShow();
- }
- //---------------------------------------------------------------------------
- int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const AnsiString Message,
- TStrings * MoreMessages, TQueryType Type, int Answers,
- int HelpCtx, int Params)
- {
- if (WinConfiguration->ContinueOnError && (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, HelpCtx, Params);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewDDCreateDragFileList(
- 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(UniqTempDir(WinConfiguration->DDTemporaryDirectory));
- ForceDirectories(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::RemoteDirViewDDEnd(TObject * /*Sender*/)
- {
- if (FDDExtMapFile != NULL)
- {
- try
- {
- if ((RemoteDirView->LastDDResult == drCopy) ||
- (RemoteDirView->LastDDResult == drMove))
- {
- AnsiString TargetDirectory;
- TFileOperation Operation;
- Operation = (RemoteDirView->LastDDResult == drMove) ? foMove : foCopy;
- if (FDDMoveSlipped)
- {
- Operation = foMove;
- }
- DDGetTarget(TargetDirectory);
- ExecuteFileOperation(Operation, osRemote, true,
- !WinConfiguration->DDTransferConfirmation, &TargetDirectory);
- }
- }
- __finally
- {
- CloseHandle(FDDExtMapFile);
- FDDExtMapFile = NULL;
- RemoveDir(FDragExtFakeDirectory);
- FDragExtFakeDirectory = "";
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::RemoteDirViewDDGiveFeedback(
- TObject * /*Sender*/, int dwEffect, HRESULT & /*Result*/)
- {
- HCURSOR SlippedCopyCursor;
- FDDMoveSlipped =
- (FDragMoveCursor != NULL) &&
- (!RemoteDirView->DDAllowMove) && (dwEffect == DROPEFFECT_Copy) &&
- ((FDDTargetDirView == RemoteDirView) ||
- ((FDDTargetDirView != NULL) && (GetKeyState(VK_SHIFT) < 0)));
- SlippedCopyCursor = FDDMoveSlipped ? FDragMoveCursor : Dragdrop::DefaultCursor;
- RemoteDirView->DragDropFilesEx->CHCopy = SlippedCopyCursor;
- RemoteDirView->DragDropFilesEx->CHScrollCopy = SlippedCopyCursor;
- }
- //---------------------------------------------------------------------------
- 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::RemoteDirViewDDTargetDrop(
- TUnixDirView * /*Sender*/, int DropEffect, bool & Continue)
- {
- if (FDDTargetDirView == RemoteDirView)
- {
- // 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 ((DropEffect == DROPEFFECT_MOVE) ||
- ((!RemoteDirView->DDAllowMove) && (DropEffect == DROPEFFECT_COPY)))
- {
- ExecuteFileOperation(foRemoteMove, osRemote, true,
- !WinConfiguration->DDTransferConfirmation);
- }
- // abort drag&drop
- Abort();
- }
- else if (FDDExtMapFile != NULL)
- {
- Continue = false;
- FDDDropTime = Now();
- }
- }
- //---------------------------------------------------------------------------
- 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::RemoteDirViewDDCreateDataObject(
- TObject * /*Sender*/, TDataObject *& DataObject)
- {
- if (FDDExtMapFile != NULL)
- {
- TFileList * FileList = RemoteDirView->DragDropFilesEx->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::PanelExport(TOperationSide Side,
- TPanelExport Export, TPanelExportDestination Destination, bool OnFocused)
- {
- Side = GetSide(Side);
- TCustomDirView * DirView = this->DirView(Side);
- TStringList * ExportData = new TStringList();
- try
- {
- if (Export == pePath)
- {
- ExportData->Add(DirView->PathName);
- }
- else
- {
- 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]));
- }
- }
- }
- PanelExportStore(Side, Export, Destination, ExportData);
- }
- __finally
- {
- delete ExportData;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
- TPanelExport /*Export*/, TPanelExportDestination Destination,
- TStringList * ExportData)
- {
- if (Destination == pedClipboard)
- {
- TClipboard * AClipboard = Clipboard();
- if (ExportData->Count == 1)
- {
- AClipboard->AsText = ExportData->Strings[0];
- }
- else
- {
- AClipboard->AsText = ExportData->Text;
- }
- }
- 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];
- default:
- return FQueueController->AllowOperation(Operation);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::ExecuteQueueOperation(
- TQueueOperation Operation)
- {
- if (Operation == qoGoTo)
- {
- assert(QueueView->Visible);
- QueueView->SetFocus();
- }
- else if (Operation == qoPreferences)
- {
- DoPreferencesDialog(pmQueue);
- }
- else
- {
- FQueueController->ExecuteOperation(Operation);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueViewContextPopup(
- TObject * /*Sender*/, TPoint & /*MousePos*/, bool & /*Handled*/)
- {
- FQueueActedItem = QueueView->ItemFocused;
- }
- //---------------------------------------------------------------------------
- /*virtual*/ int __fastcall TCustomScpExplorerForm::GetStaticComponentsHeight()
- {
- return TopCoolBar->Height + QueueSplitter->Height;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::QueueSplitterCanResize(
- TObject * /*Sender*/, int & NewSize, bool & /*Accept*/)
- {
- int HeightLimit = ClientHeight - GetStaticComponentsHeight() -
- RemotePanel->Constraints->MinHeight;
- if (NewSize > HeightLimit)
- {
- NewSize = HeightLimit;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomScpExplorerForm::StatusBarResize(
- TObject * Sender)
- {
- RepaintStatusBar(dynamic_cast<TCustomStatusBar *>(Sender));
- }
- //---------------------------------------------------------------------------
- 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();
- }
- }
- //---------------------------------------------------------------------------
|