CustomScpExplorer.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Clipbrd.hpp>
  5. #include "CustomScpExplorer.h"
  6. #include <Common.h>
  7. #include <Interface.h>
  8. #include <Net.h>
  9. #include <ScpMain.h>
  10. #include <FileSystems.h>
  11. #include <TextsWin.h>
  12. #include <DiscMon.hpp>
  13. #include <VCLCommon.h>
  14. #include <Log.h>
  15. #include <Progress.h>
  16. #include <SynchronizeProgress.h>
  17. #include <OperationStatus.h>
  18. #include <DragExt.h>
  19. #include "GUITools.h"
  20. #include "NonVisual.h"
  21. #include "Tools.h"
  22. #include "WinConfiguration.h"
  23. #include "TerminalManager.h"
  24. //---------------------------------------------------------------------------
  25. #pragma package(smart_init)
  26. #pragma link "CustomDirView"
  27. #pragma link "CustomUnixDirView"
  28. #pragma link "IEListView"
  29. #pragma link "NortonLikeListView"
  30. #pragma link "UnixDirView"
  31. #pragma link "AssociatedStatusBar"
  32. #pragma resource "*.dfm"
  33. //---------------------------------------------------------------------------
  34. #ifdef DEBUGMODE
  35. #define DEBUG(MSG) CurrentSSH->LogEvent(MSG)
  36. #else
  37. #define DEBUG(MSG)
  38. #endif
  39. //---------------------------------------------------------------------------
  40. #define SAVE_SELECTION(DIRVIEW) \
  41. AnsiString FocusFile = ""; \
  42. AnsiString LastFocusedFile = ""; \
  43. if (DIRVIEW->ItemFocused) LastFocusedFile = DIRVIEW->ItemFocused->Caption; \
  44. { TListItem * ClosestUnselected = DIRVIEW->ClosestUnselected(DIRVIEW->ItemFocused); \
  45. if (ClosestUnselected) FocusFile = ClosestUnselected->Caption; }
  46. #define RESTORE_SELECTION(DIRVIEW) \
  47. if (!LastFocusedFile.IsEmpty() && \
  48. (!DIRVIEW->ItemFocused || (DIRVIEW->ItemFocused->Caption != LastFocusedFile))) \
  49. { \
  50. TListItem *ItemToSelect = DIRVIEW->FindFileItem(FocusFile); \
  51. if (ItemToSelect) \
  52. { \
  53. DIRVIEW->ItemFocused = ItemToSelect; \
  54. DIRVIEW->ItemFocused->MakeVisible(False); \
  55. } \
  56. }
  57. //---------------------------------------------------------------------------
  58. class TMutexGuard
  59. {
  60. public:
  61. TMutexGuard(HANDLE AMutex, int Message = MUTEX_RELEASE_TIMEOUT,
  62. int Timeout = 5000)
  63. {
  64. FMutex = NULL;
  65. unsigned long WaitResult = WaitForSingleObject(AMutex, Timeout);
  66. if (WaitResult == WAIT_TIMEOUT)
  67. {
  68. throw Exception(LoadStr(MUTEX_RELEASE_TIMEOUT));
  69. }
  70. else
  71. {
  72. FMutex = AMutex;
  73. }
  74. }
  75. ~TMutexGuard()
  76. {
  77. if (FMutex != NULL)
  78. {
  79. ReleaseMutex(FMutex);
  80. }
  81. }
  82. private:
  83. HANDLE FMutex;
  84. };
  85. //---------------------------------------------------------------------------
  86. __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
  87. FLastDirView(NULL), FFormRestored(False), TForm(Owner)
  88. {
  89. RestoreParams();
  90. RemoteDirView->Invalidate();
  91. assert(NonVisualDataModule && !NonVisualDataModule->ScpExplorer);
  92. NonVisualDataModule->ScpExplorer = this;
  93. Application->OnHint = ApplicationHint;
  94. FAutoOperation = false;
  95. FForceExecution = false;
  96. FShowStatusBarHint = false;
  97. FIgnoreNextSysCommand = false;
  98. FErrorList = NULL;
  99. FSynchronizeProgressForm = NULL;
  100. FProgressForm = NULL;
  101. FDDExtDropEffect = DROPEFFECT_NONE;
  102. FDDExtMapFile = NULL;
  103. FDDExtMutex = CreateMutex(NULL, false, DRAG_EXT_MUTEX);
  104. assert(FDDExtMutex != NULL);
  105. UseSystemSettings(this);
  106. TComboBox * SessionCombo = dynamic_cast<TComboBox*>(GetComponent(fcSessionCombo));
  107. if (SessionCombo != NULL)
  108. {
  109. SessionCombo->OnDrawItem = SessionComboDrawItem;
  110. SessionCombo->OnDropDown = SessionComboDropDown;
  111. SessionCombo->OnChange = SessionComboChange;
  112. SessionCombo->Hint = NonVisualDataModule->OpenedSessionsAction->Hint;
  113. }
  114. TToolBar * MenuToolBar = dynamic_cast<TToolBar*>(GetComponent(fcMenuToolBar));
  115. assert(MenuToolBar);
  116. MenuToolBar->Font = Screen->MenuFont;
  117. assert(MenuToolBar->ControlCount);
  118. MenuToolBar->Height = MenuToolBar->Controls[0]->Height;
  119. RemoteDirView->Font = Screen->IconFont;
  120. RemoteDirView->DDAllowMove = true;
  121. }
  122. //---------------------------------------------------------------------------
  123. __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
  124. {
  125. CloseHandle(FDDExtMutex);
  126. FDDExtMutex = NULL;
  127. assert(!FErrorList);
  128. StoreParams();
  129. Terminal = NULL;
  130. assert(NonVisualDataModule && (NonVisualDataModule->ScpExplorer == this));
  131. NonVisualDataModule->ScpExplorer = NULL;
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TCustomScpExplorerForm::SetTerminal(TTerminal * value)
  135. {
  136. if (FTerminal != value)
  137. {
  138. if (FTerminal)
  139. {
  140. UpdateSessionData(Terminal->SessionData);
  141. }
  142. FTerminal = value;
  143. TerminalChanged();
  144. }
  145. }
  146. //---------------------------------------------------------------------------
  147. void __fastcall TCustomScpExplorerForm::TerminalChanged()
  148. {
  149. RemoteDirView->Terminal = Terminal;
  150. Caption = Application->Title;
  151. if (Terminal)
  152. {
  153. UpdateStatusBar();
  154. }
  155. TerminalListChanged(NULL);
  156. }
  157. //---------------------------------------------------------------------------
  158. void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
  159. {
  160. assert(Configuration && RemoteDirView);
  161. RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  162. RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  163. RemoteDirView->ShowInaccesibleDirectories = WinConfiguration->ShowInaccesibleDirectories;
  164. RemoteDirView->DDTemporaryDirectory = WinConfiguration->DDTemporaryDirectory;
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TCustomScpExplorerForm::RemoteDirViewGetCopyParam(
  168. TUnixDirView * /*Sender*/, TTransferDirection Direction,
  169. TTransferType Type, AnsiString &TargetDirectory, TStrings * FileList,
  170. TCopyParamType &CopyParam)
  171. {
  172. if (!CopyParamDialog(Direction, Type, true, FileList,
  173. TargetDirectory, CopyParam, WinConfiguration->DDTransferConfirmation))
  174. {
  175. Abort();
  176. }
  177. }
  178. //---------------------------------------------------------------------------
  179. bool __fastcall TCustomScpExplorerForm::CopyParamDialog(
  180. TTransferDirection Direction, TTransferType Type, bool DragDrop,
  181. TStrings * FileList, AnsiString & TargetDirectory, TCopyParamType & CopyParam,
  182. bool Confirm)
  183. {
  184. bool Result = true;
  185. assert(Terminal && Terminal->Active);
  186. if (DragDrop && (Direction == tdToLocal) && (Type == ttMove) &&
  187. !WinConfiguration->DDAllowMove)
  188. {
  189. int Answer = MessageDialog(LoadStr(DND_DOWNLOAD_MOVE_WARNING), qtWarning,
  190. qaOK | qaCancel, 0, mpNeverAskAgainCheck);
  191. if (Answer == qaNeverAskAgain)
  192. {
  193. WinConfiguration->DDAllowMove = true;
  194. }
  195. else if (Answer == qaCancel)
  196. {
  197. Result = false;
  198. }
  199. }
  200. if (Result && Confirm)
  201. {
  202. Result = DoCopyDialog(Direction == tdToRemote, Type == ttMove,
  203. DragDrop, FileList, Terminal->IsCapable[fcTextMode], TargetDirectory,
  204. &CopyParam, true);
  205. }
  206. return Result;
  207. }
  208. //---------------------------------------------------------------------------
  209. void __fastcall TCustomScpExplorerForm::RestoreFormParams()
  210. {
  211. }
  212. //---------------------------------------------------------------------------
  213. void __fastcall TCustomScpExplorerForm::RestoreParams()
  214. {
  215. // IDE often looses this link
  216. RemoteDirView->HeaderImages = NonVisualDataModule->ArrowImages;
  217. if (Position == poDesigned)
  218. {
  219. RestoreFormParams();
  220. }
  221. ConfigurationChanged();
  222. }
  223. //---------------------------------------------------------------------------
  224. void __fastcall TCustomScpExplorerForm::StoreParams()
  225. {
  226. }
  227. //---------------------------------------------------------------------------
  228. void __fastcall TCustomScpExplorerForm::CreateParams(TCreateParams & Params)
  229. {
  230. if (!FFormRestored)
  231. {
  232. FFormRestored = true;
  233. RestoreFormParams();
  234. }
  235. TForm::CreateParams(Params);
  236. }
  237. //---------------------------------------------------------------------------
  238. void __fastcall TCustomScpExplorerForm::FileOperationProgress(
  239. TFileOperationProgressType & ProgressData, TCancelStatus & /*Cancel*/)
  240. {
  241. // operation is being executed and we still didn't show up progress form
  242. if (ProgressData.InProgress && !FProgressForm)
  243. {
  244. //assert(Screen && Screen->ActiveCustomForm);
  245. FProgressForm = new TProgressForm(Application);
  246. FProgressForm->DeleteToRecycleBin = WinConfiguration->DeleteToRecycleBin;
  247. // When main window is hidden, we suppose "/upload" mode
  248. if (!Visible)
  249. {
  250. FProgressForm->DisconnectWhenComplete = true;
  251. }
  252. }
  253. // operation is finished (or terminated), so we hide progress form
  254. else if (!ProgressData.InProgress && FProgressForm)
  255. {
  256. SAFE_DESTROY(FProgressForm);
  257. }
  258. if (FProgressForm)
  259. {
  260. FProgressForm->SetProgressData(ProgressData);
  261. if (FProgressForm->Cancel > ProgressData.Cancel)
  262. {
  263. ProgressData.Cancel = FProgressForm->Cancel;
  264. }
  265. }
  266. }
  267. //---------------------------------------------------------------------------
  268. void __fastcall TCustomScpExplorerForm::OperationProgress(
  269. TFileOperationProgressType & ProgressData, TCancelStatus & Cancel)
  270. {
  271. FileOperationProgress(ProgressData, Cancel);
  272. }
  273. //---------------------------------------------------------------------------
  274. void __fastcall TCustomScpExplorerForm::DoOperationFinished(
  275. TFileOperation Operation, TOperationSide Side,
  276. bool DragDrop, const AnsiString FileName, bool Success,
  277. bool & DisconnectWhenComplete)
  278. {
  279. if (!FAutoOperation)
  280. {
  281. // no selection on "/upload", form servers only as event handler
  282. // (it is not displayed)
  283. if (!DragDrop && Visible && (Operation != foCalculateSize))
  284. {
  285. TListItem *Item = DirView(Side)->FindFileItem(FileName);
  286. assert(Item);
  287. if (Success) Item->Selected = false;
  288. Item->MakeVisible(false);
  289. }
  290. if (FProgressForm)
  291. {
  292. DisconnectWhenComplete = FProgressForm->DisconnectWhenComplete;
  293. }
  294. }
  295. }
  296. //---------------------------------------------------------------------------
  297. void __fastcall TCustomScpExplorerForm::OperationFinished(
  298. TFileOperation Operation, TOperationSide Side,
  299. bool DragDrop, const AnsiString FileName, Boolean Success,
  300. bool & DisconnectWhenComplete)
  301. {
  302. DoOperationFinished(Operation, Side, DragDrop, FileName, Success,
  303. DisconnectWhenComplete);
  304. }
  305. //---------------------------------------------------------------------------
  306. TCustomDirView * __fastcall TCustomScpExplorerForm::DirView(TOperationSide Side)
  307. {
  308. assert((Side == osRemote) || ((Side == osCurrent) && FLastDirView));
  309. return (Side == osCurrent) ? FLastDirView : RemoteDirView;
  310. }
  311. //---------------------------------------------------------------------------
  312. bool __fastcall TCustomScpExplorerForm::GetEnableFocusedOperation(TOperationSide Side)
  313. {
  314. return DirView(Side)->AnyFileSelected(true);
  315. }
  316. //---------------------------------------------------------------------------
  317. bool __fastcall TCustomScpExplorerForm::GetEnableSelectedOperation(TOperationSide Side)
  318. {
  319. return DirView(Side)->AnyFileSelected(false);
  320. }
  321. //---------------------------------------------------------------------------
  322. void __fastcall TCustomScpExplorerForm::RemoteDirViewContextPopup(
  323. TObject * /*Sender*/, const TPoint &MousePos, bool &Handled)
  324. {
  325. TListItem * Item = RemoteDirView->ItemFocused;
  326. if ((RemoteDirView->GetItemAt(MousePos.x, MousePos.y) == Item) &&
  327. RemoteDirView->AnyFileSelected(true))
  328. {
  329. TPoint ScreenPoint, ClientPoint;
  330. ClientPoint = ((MousePos.x < 0) && (MousePos.y < 0)) ?
  331. TPoint(0, 0) : MousePos;
  332. ScreenPoint = RemoteDirView->ClientToScreen(ClientPoint);
  333. NonVisualDataModule->CurrentOpenMenuItem->Default = !WinConfiguration->CopyOnDoubleClick;
  334. NonVisualDataModule->CurrentCopyMenuItem->Default = WinConfiguration->CopyOnDoubleClick;
  335. NonVisualDataModule->CurrentOpenMenuItem->Visible = WinConfiguration->ExpertMode;
  336. NonVisualDataModule->CurentEditMenuItem->Visible = WinConfiguration->ExpertMode;
  337. reinterpret_cast<TPopupMenu*>(GetComponent(fcRemotePopup))->Popup(
  338. ScreenPoint.x, ScreenPoint.y);
  339. }
  340. Handled = true;
  341. }
  342. //---------------------------------------------------------------------------
  343. void __fastcall TCustomScpExplorerForm::BatchStart(void *& Storage)
  344. {
  345. assert(FErrorList == NULL);
  346. Storage = new bool;
  347. if (HasDirView[osLocal])
  348. {
  349. *static_cast<bool*>(Storage) = DirView(osLocal)->WatchForChanges;
  350. DirView(osLocal)->WatchForChanges = false;
  351. }
  352. if (WinConfiguration->ContinueOnError)
  353. {
  354. FErrorList = new TStringList();
  355. }
  356. }
  357. //---------------------------------------------------------------------------
  358. void __fastcall TCustomScpExplorerForm::BatchEnd(void * Storage)
  359. {
  360. assert(Storage != NULL);
  361. if (FErrorList)
  362. {
  363. HandleErrorList(FErrorList);
  364. }
  365. if (HasDirView[osLocal])
  366. {
  367. DirView(osLocal)->WatchForChanges = *static_cast<bool*>(Storage);
  368. }
  369. delete Storage;
  370. }
  371. //---------------------------------------------------------------------------
  372. void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  373. TOperationSide Side, TStrings * FileList, bool NoConfirmation, void * Param)
  374. {
  375. void * BatchStorage;
  376. BatchStart(BatchStorage);
  377. try
  378. {
  379. if ((Operation == foCopy) || (Operation == foMove))
  380. {
  381. TTransferDirection Direction = (Side == osLocal ? tdToRemote : tdToLocal);
  382. TTransferType Type = (Operation == foCopy ? ttCopy : ttMove);
  383. AnsiString TargetDirectory;
  384. if (Param != NULL)
  385. {
  386. TargetDirectory = *static_cast<AnsiString*>(Param);
  387. }
  388. TCopyParamType CopyParam = Configuration->CopyParam;
  389. if (CopyParamDialog(Direction, Type, false, FileList, TargetDirectory,
  390. CopyParam, !NoConfirmation))
  391. {
  392. assert(Terminal);
  393. TCustomDirView * DView = DirView(Side);
  394. bool SelectionRestored = false;
  395. DView->SaveSelection();
  396. try
  397. {
  398. if (Side == osLocal)
  399. {
  400. int Params = 0;
  401. if (Operation == foMove) Params |= cpDelete;
  402. Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params);
  403. if (Operation == foMove)
  404. {
  405. DView->Reload(True);
  406. DView->RestoreSelection();
  407. SelectionRestored = true;
  408. }
  409. }
  410. else
  411. {
  412. try
  413. {
  414. Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam,
  415. (Operation == foMove ? cpDelete : 0));
  416. }
  417. __finally
  418. {
  419. if (Operation == foMove)
  420. {
  421. DView->RestoreSelection();
  422. SelectionRestored = true;
  423. }
  424. if (HasDirView[osLocal] &&
  425. (IncludeTrailingBackslash(TargetDirectory) ==
  426. IncludeTrailingBackslash(DirView(osLocal)->Path)))
  427. {
  428. DirView(osLocal)->ReloadDirectory();
  429. }
  430. }
  431. }
  432. }
  433. __finally
  434. {
  435. if (!SelectionRestored)
  436. {
  437. DView->DiscardSavedSelection();
  438. }
  439. }
  440. }
  441. }
  442. else if (Operation == foRename)
  443. {
  444. assert(DirView(Side)->ItemFocused);
  445. DirView(Side)->ItemFocused->EditCaption();
  446. }
  447. else if (Operation == foDelete)
  448. {
  449. assert(FileList->Count);
  450. bool Confirmed = !WinConfiguration->ConfirmDeleting;
  451. if (!Confirmed)
  452. {
  453. AnsiString Query;
  454. if (FileList->Count == 1)
  455. {
  456. if (Side == osLocal)
  457. {
  458. Query = ExtractFileName(FileList->Strings[0]);
  459. }
  460. else
  461. {
  462. Query = UnixExtractFileName(FileList->Strings[0]);
  463. }
  464. Query = FMTLOAD(CONFIRM_DELETE_FILE, (Query));
  465. }
  466. else
  467. {
  468. Query = FMTLOAD(CONFIRM_DELETE_FILES, (FileList->Count));
  469. }
  470. int Answer = MessageDialog(Query, qtConfirmation,
  471. qaOK | qaCancel, 0, mpNeverAskAgainCheck);
  472. if (Answer == qaNeverAskAgain)
  473. {
  474. Confirmed = true;
  475. WinConfiguration->ConfirmDeleting = false;
  476. }
  477. else
  478. {
  479. Confirmed = (Answer == qaOK);
  480. }
  481. }
  482. if (Confirmed) DeleteFiles(Side, FileList);
  483. }
  484. else if (Operation == foSetProperties)
  485. {
  486. SetProperties(Side, FileList);
  487. }
  488. else if (Operation == foCustomCommand)
  489. {
  490. assert(Param);
  491. assert(Side == osRemote);
  492. FCustomCommandName = *((AnsiString *)Param);
  493. try
  494. {
  495. AnsiString Command = TCustomFileSystem::CompleteCustomCommand(
  496. WinConfiguration->CustomCommands->Values[FCustomCommandName],
  497. "", CustomCommandGetParamValue);
  498. Terminal->CustomCommandOnFiles(Command,
  499. WinConfiguration->CustomCommands->Params[FCustomCommandName],
  500. FileList);
  501. }
  502. __finally
  503. {
  504. FCustomCommandName = "";
  505. }
  506. }
  507. else if (Operation == foRemoteMove)
  508. {
  509. assert(Side == osRemote);
  510. RemoteMoveFiles(FileList, NoConfirmation);
  511. }
  512. else
  513. {
  514. assert(false);
  515. }
  516. }
  517. __finally
  518. {
  519. BatchEnd(BatchStorage);
  520. }
  521. }
  522. //---------------------------------------------------------------------------
  523. TOperationSide __fastcall TCustomScpExplorerForm::GetSide(TOperationSide Side)
  524. {
  525. if (Side == osCurrent)
  526. {
  527. Side = osRemote;
  528. }
  529. return Side;
  530. }
  531. //---------------------------------------------------------------------------
  532. void __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Operation,
  533. TOperationSide Side, bool OnFocused, bool NoConfirmation, void * Param)
  534. {
  535. Side = GetSide(Side);
  536. TStrings * FileList = DirView(Side)->CreateFileList(OnFocused, (Side == osLocal), NULL);
  537. try
  538. {
  539. ExecuteFileOperation(Operation, Side, FileList, NoConfirmation, Param);
  540. }
  541. __finally
  542. {
  543. delete FileList;
  544. }
  545. }
  546. //---------------------------------------------------------------------------
  547. void __fastcall TCustomScpExplorerForm::CustomCommandGetParamValue(
  548. const AnsiString AName, AnsiString & Value)
  549. {
  550. assert(!FCustomCommandName.IsEmpty());
  551. AnsiString Name = AName;
  552. if (Name.IsEmpty())
  553. {
  554. Name = FMTLOAD(CUSTOM_COMMANDS_PARAM_PROMPT, (StripHotkey(FCustomCommandName)));
  555. }
  556. if (!InputDialog(FMTLOAD(CUSTOM_COMMANDS_PARAM_TITLE,
  557. (StripHotkey(FCustomCommandName))), Name, Value))
  558. {
  559. Abort();
  560. }
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TCustomScpExplorerForm::HandleErrorList(TStringList *& ErrorList)
  564. {
  565. try
  566. {
  567. if (ErrorList->Count)
  568. {
  569. if (MessageDialog(FMTLOAD(ERROR_LIST_COUNT, (ErrorList->Count)), qtError,
  570. qaOK | qaCancel, 0) == qaOK)
  571. {
  572. int Answer;
  573. int Index = 0;
  574. do
  575. {
  576. assert(Index >= 0 && Index < ErrorList->Count);
  577. Answer = MoreMessageDialog(
  578. FMTLOAD(ERROR_LIST_NUMBER, (Index+1, ErrorList->Count, ErrorList->Strings[Index])),
  579. dynamic_cast<TStrings *>(ErrorList->Objects[Index]), qtError,
  580. (Index ? qaPrev : 0) | (Index < ErrorList->Count - 1 ? qaNext : 0) |
  581. qaOK, 0);
  582. if (Answer == qaNext)
  583. {
  584. Index++;
  585. }
  586. if (Answer == qaPrev)
  587. {
  588. Index--;
  589. }
  590. }
  591. while (Answer != qaOK);
  592. }
  593. }
  594. }
  595. __finally
  596. {
  597. TStrings * List = ErrorList;
  598. ErrorList = NULL;
  599. for (int i = 0; i < List->Count; i++)
  600. {
  601. delete List->Objects[i];
  602. }
  603. delete List;
  604. }
  605. }
  606. //---------------------------------------------------------------------------
  607. void __fastcall TCustomScpExplorerForm::ExecuteFile(TOperationSide Side,
  608. TExecuteFileBy ExecuteFileBy)
  609. {
  610. assert(!WinConfiguration->DisableOpenEdit);
  611. if (Side == osCurrent)
  612. {
  613. Side = FLastDirView == RemoteDirView ? osRemote : osLocal;
  614. }
  615. bool Edit = (ExecuteFileBy == efEditor || ExecuteFileBy == efAlternativeEditor);
  616. TStrings * FileList = DirView(Side)->CreateFocusedFileList(Side == osLocal);
  617. try
  618. {
  619. assert(FileList->Count == 1);
  620. if (Side == osRemote)
  621. {
  622. TCopyParamType CopyParam = Configuration->CopyParam;
  623. if (Edit)
  624. {
  625. CopyParam.TransferMode = tmAscii;
  626. }
  627. CopyParam.FileNameCase = ncNoChange;
  628. CopyParam.PreserveReadOnly = false;
  629. CopyParam.ResumeSupport = rsOff;
  630. AnsiString TempDir = UniqTempDir(WinConfiguration->DDTemporaryDirectory);
  631. ForceDirectories(TempDir);
  632. FAutoOperation = true;
  633. Terminal->ExceptionOnFail = true;
  634. try
  635. {
  636. Terminal->CopyToLocal(FileList, TempDir, &CopyParam, cpTemporary);
  637. }
  638. __finally
  639. {
  640. FAutoOperation = false;
  641. Terminal->ExceptionOnFail = false;
  642. }
  643. FExecutedFile = TempDir + FileList->Strings[0];
  644. }
  645. else
  646. {
  647. FExecutedFile = FileList->Strings[0];
  648. }
  649. }
  650. __finally
  651. {
  652. delete FileList;
  653. }
  654. Terminal->BeginTransaction();
  655. try
  656. {
  657. try
  658. {
  659. FExecutedFileTimestamp = FileAge(FExecutedFile);
  660. FFileExecutedBy = ExecuteFileBy;
  661. if (Edit && ((WinConfiguration->Editor.Editor == edInternal) !=
  662. (ExecuteFileBy == efAlternativeEditor)))
  663. {
  664. TNotifyEvent OnFileChanged = NULL;
  665. AnsiString Caption = FExecutedFile;
  666. if (Side == osRemote)
  667. {
  668. OnFileChanged = ExecutedFileChanged;
  669. Caption = RemoteDirView->Path + ExtractFileName(FExecutedFile);
  670. }
  671. DoEditorForm(FExecutedFile, this, OnFileChanged, Caption);
  672. }
  673. else
  674. {
  675. TDiscMonitor * DiscMonitor = NULL;
  676. try
  677. {
  678. if (Side == osRemote)
  679. {
  680. DiscMonitor = new TDiscMonitor(this);
  681. DiscMonitor->SubTree = false;
  682. DiscMonitor->Filters = TMonitorFilters() << moLastWrite;
  683. DiscMonitor->Directory = ExtractFilePath(FExecutedFile);
  684. DiscMonitor->OnChange = ExecutedFileChanged;
  685. DiscMonitor->Active = true;
  686. }
  687. TOperationStatusForm * StatusForm = new TOperationStatusForm(Application);
  688. try
  689. {
  690. StatusForm->Status = LoadStr(DOCUMENT_WAIT);
  691. StatusForm->ShowAsModal();
  692. if (Edit)
  693. {
  694. AnsiString ExternalEditor, Program, Params, Dir;
  695. ExternalEditor = WinConfiguration->Editor.ExternalEditor;
  696. TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
  697. SplitCommand(ExternalEditor, Program, Params, Dir);
  698. assert(Params.Pos(ShellCommandFileNamePattern) > 0);
  699. Params = StringReplace(Params, ShellCommandFileNamePattern,
  700. AddPathQuotes(FExecutedFile), TReplaceFlags() << rfReplaceAll);
  701. if (ExecuteShellAndWait(Program, Params) < 0)
  702. {
  703. throw Exception(FMTLOAD(EDITOR_ERROR, (Program)));
  704. }
  705. }
  706. else
  707. {
  708. assert(Side == osRemote);
  709. if (ExecuteShellAndWait(FExecutedFile, "") < 0)
  710. {
  711. throw Exception(FMTLOAD(EXECUTE_FILE_ERROR, (FExecutedFile)));
  712. }
  713. }
  714. }
  715. __finally
  716. {
  717. delete StatusForm;
  718. }
  719. if (Side == osRemote)
  720. {
  721. if (DiscMonitor)
  722. {
  723. DiscMonitor->Active = false;
  724. }
  725. // upload file if it was saved while [editor] was closed
  726. ExecutedFileChanged(NULL);
  727. }
  728. }
  729. __finally
  730. {
  731. delete DiscMonitor;
  732. }
  733. }
  734. }
  735. __finally
  736. {
  737. AnsiString FileName = FExecutedFile;
  738. FExecutedFile = "";
  739. if (Side == osRemote)
  740. {
  741. bool Deleted;
  742. AnsiString DirName = ExtractFilePath(FileName);
  743. if (WinConfiguration->ForceDeleteTempFolder)
  744. {
  745. Deleted = RecursiveDeleteFile(ExcludeTrailingBackslash(DirName), false);
  746. }
  747. else
  748. {
  749. Deleted = DeleteFile(FileName) && RemoveDir(DirName);
  750. }
  751. if (!Deleted)
  752. {
  753. throw Exception(FMTLOAD(DELETE_TEMP_EXECUTE_FILE_ERROR, (DirName)));
  754. }
  755. }
  756. else
  757. {
  758. DirView(osLocal)->ReloadDirectory();
  759. }
  760. }
  761. }
  762. __finally
  763. {
  764. Terminal->EndTransaction();
  765. }
  766. }
  767. //---------------------------------------------------------------------------
  768. void __fastcall TCustomScpExplorerForm::ExecutedFileChanged(TObject * Sender)
  769. {
  770. static Uploading = 0;
  771. try
  772. {
  773. assert(!FExecutedFile.IsEmpty());
  774. if (Uploading == 1)
  775. {
  776. Uploading = 2;
  777. }
  778. else
  779. {
  780. Uploading = 1;
  781. try
  782. {
  783. int FileTimestamp = FileAge(FExecutedFile);
  784. if (FileTimestamp != FExecutedFileTimestamp)
  785. {
  786. FExecutedFileTimestamp = FileTimestamp;
  787. TStrings * FileList = new TStringList();
  788. try
  789. {
  790. FileList->Add(FExecutedFile);
  791. TCopyParamType CopyParam = Configuration->CopyParam;
  792. if (FFileExecutedBy == efEditor || FFileExecutedBy == efAlternativeEditor)
  793. {
  794. CopyParam.TransferMode = tmAscii;
  795. }
  796. CopyParam.TransferMode = tmAscii;
  797. CopyParam.FileNameCase = ncNoChange;
  798. CopyParam.PreserveRights = false;
  799. CopyParam.ResumeSupport = rsOff;
  800. FAutoOperation = true;
  801. Terminal->ExceptionOnFail = true;
  802. try
  803. {
  804. Terminal->CopyToRemote(FileList, RemoteDirView->PathName,
  805. &CopyParam, cpNoConfirmation);
  806. }
  807. __finally
  808. {
  809. FAutoOperation = false;
  810. Terminal->ExceptionOnFail = false;
  811. }
  812. }
  813. __finally
  814. {
  815. delete FileList;
  816. }
  817. }
  818. }
  819. __finally
  820. {
  821. if (Uploading == 2)
  822. {
  823. Uploading = 0;
  824. ExecutedFileChanged(this);
  825. }
  826. else
  827. {
  828. Uploading = 0;
  829. }
  830. }
  831. }
  832. }
  833. catch (Exception & E)
  834. {
  835. if (dynamic_cast<TDiscMonitor *> (Sender))
  836. {
  837. HandleExtendedException(&E);
  838. }
  839. else
  840. {
  841. throw;
  842. }
  843. }
  844. }
  845. //---------------------------------------------------------------------------
  846. void __fastcall TCustomScpExplorerForm::DirViewEnter(TObject *Sender)
  847. {
  848. DoDirViewEnter(dynamic_cast<TCustomDirView*>(Sender));
  849. }
  850. //---------------------------------------------------------------------------
  851. void __fastcall TCustomScpExplorerForm::DoDirViewEnter(TCustomDirView * DirView)
  852. {
  853. assert(DirView != NULL);
  854. FLastDirView = DirView;
  855. }
  856. //---------------------------------------------------------------------------
  857. void __fastcall TCustomScpExplorerForm::DeleteFiles(TOperationSide Side,
  858. TStrings * FileList)
  859. {
  860. assert(Terminal);
  861. TCustomDirView * DView = DirView(Side);
  862. DView->SaveSelection();
  863. try
  864. {
  865. if (Side == osRemote)
  866. {
  867. Terminal->DeleteFiles(FileList);
  868. }
  869. else
  870. {
  871. try
  872. {
  873. Terminal->DeleteLocalFiles(FileList);
  874. }
  875. __finally
  876. {
  877. DView->Reload(true);
  878. }
  879. }
  880. }
  881. catch(...)
  882. {
  883. DView->DiscardSavedSelection();
  884. throw;
  885. }
  886. DView->RestoreSelection();
  887. }
  888. //---------------------------------------------------------------------------
  889. bool __fastcall TCustomScpExplorerForm::RemoteMoveDialog(TStrings * FileList,
  890. AnsiString & Target, AnsiString & FileMask, bool NoConfirmation)
  891. {
  892. if (RemoteDirView->DropTarget != NULL)
  893. {
  894. assert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
  895. Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
  896. }
  897. else
  898. {
  899. Target = RemoteDirView->Path;
  900. }
  901. Target = UnixIncludeTrailingBackslash(Target);
  902. FileMask = "*.*";
  903. bool Result = true;
  904. if (!NoConfirmation)
  905. {
  906. Result = DoRemoteMoveDialog(FileList, Target, FileMask);
  907. }
  908. return Result;
  909. }
  910. //---------------------------------------------------------------------------
  911. void __fastcall TCustomScpExplorerForm::RemoteMoveFiles(
  912. TStrings * FileList, bool NoConfirmation)
  913. {
  914. AnsiString Target, FileMask;
  915. if (RemoteMoveDialog(FileList, Target, FileMask, NoConfirmation))
  916. {
  917. RemoteDirView->SaveSelection();
  918. try
  919. {
  920. Terminal->MoveFiles(FileList, Target, FileMask);
  921. }
  922. catch(...)
  923. {
  924. RemoteDirView->DiscardSavedSelection();
  925. throw;
  926. }
  927. RemoteDirView->RestoreSelection();
  928. }
  929. }
  930. //---------------------------------------------------------------------------
  931. void __fastcall TCustomScpExplorerForm::CreateDirectory(TOperationSide Side)
  932. {
  933. AnsiString Name = LoadStr(NEW_FOLDER);
  934. if (InputDialog(LoadStr(CREATE_FOLDER_CAPTION), LoadStr(CREATE_FOLDER_PROMPT), Name))
  935. {
  936. DirView(Side)->CreateDirectory(Name);
  937. }
  938. }
  939. //---------------------------------------------------------------------------
  940. void __fastcall TCustomScpExplorerForm::OpenDirectory(TOperationSide Side)
  941. {
  942. DoOpenDirectoryDialog(odBrowse, Side);
  943. }
  944. //---------------------------------------------------------------------------
  945. void __fastcall TCustomScpExplorerForm::RemoteDirViewGetSelectFilter(
  946. TCustomDirView *Sender, bool Select, TFileFilter &Filter)
  947. {
  948. assert(Sender);
  949. if (!DoSelectMaskDialog(Sender, Select, &Filter, Configuration)) Abort();
  950. }
  951. //---------------------------------------------------------------------------
  952. void __fastcall TCustomScpExplorerForm::SetProperties(TOperationSide Side, TStrings * FileList)
  953. {
  954. if (Side == osRemote)
  955. {
  956. TRemoteProperties CurrentProperties;
  957. CurrentProperties = TRemoteProperties::CommonProperties(FileList);
  958. int Flags = 0;
  959. if (Terminal->IsCapable[fcModeChanging]) Flags |= cpMode;
  960. if (Terminal->IsCapable[fcOwnerChanging]) Flags |= cpOwner;
  961. if (Terminal->IsCapable[fcGroupChanging]) Flags |= cpGroup;
  962. TRemoteProperties NewProperties = CurrentProperties;
  963. if (DoPropertiesDialog(FileList, RemoteDirView->PathName,
  964. Terminal->UserGroups, &NewProperties, Flags, Terminal))
  965. {
  966. NewProperties = TRemoteProperties::ChangedProperties(CurrentProperties, NewProperties);
  967. Terminal->ChangeFilesProperties(FileList, &NewProperties);
  968. }
  969. }
  970. else
  971. {
  972. DirView(Side)->DisplayPropertiesMenu();
  973. }
  974. }
  975. //---------------------------------------------------------------------------
  976. void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
  977. {
  978. if (!DirView(osCurrent)->IsEditing())
  979. {
  980. TShortCut KeyShortCut = ShortCut(Key, Shift);
  981. for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
  982. {
  983. TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
  984. if (((Action->ShortCut == KeyShortCut) ||
  985. (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
  986. AllowedAction(Action, aaShortCut))
  987. {
  988. Key = 0;
  989. Action->Execute();
  990. return;
  991. }
  992. }
  993. for (int i = 0; i < NonVisualDataModule->OpenedSessionsMenu->Count; i++)
  994. {
  995. TMenuItem * Item = NonVisualDataModule->OpenedSessionsMenu->Items[i];
  996. if (Item->ShortCut == KeyShortCut)
  997. {
  998. Key = 0;
  999. Item->Click();
  1000. FIgnoreNextSysCommand = true;
  1001. return;
  1002. }
  1003. }
  1004. if (Key == VK_TAB && Shift.Contains(ssCtrl))
  1005. {
  1006. TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
  1007. }
  1008. }
  1009. TForm::KeyDown(Key, Shift);
  1010. }
  1011. //---------------------------------------------------------------------------
  1012. void __fastcall TCustomScpExplorerForm::UpdateStatusBar()
  1013. {
  1014. TStatusBar * SessionStatusBar = (TStatusBar *)GetComponent(fcStatusBar);
  1015. assert(SessionStatusBar && (SessionStatusBar->Panels->Count >= 3));
  1016. if (FShowStatusBarHint)
  1017. {
  1018. SessionStatusBar->SimplePanel = true;
  1019. SessionStatusBar->SimpleText = FStatusBarHint;
  1020. }
  1021. else if (!Terminal || !Terminal->Active || Terminal->Status < sshReady)
  1022. {
  1023. // note: (Terminal->Status < sshReady) currently never happens here,
  1024. // so STATUS_CONNECTING is never used
  1025. SessionStatusBar->SimplePanel = true;
  1026. SessionStatusBar->SimpleText = LoadStr(
  1027. !Terminal || !Terminal->Active ? STATUS_DISCONNECTED : STATUS_CONNECTING);
  1028. }
  1029. else
  1030. {
  1031. assert(Terminal);
  1032. SessionStatusBar->SimplePanel = false;
  1033. int Index = SessionStatusBar->Tag;
  1034. SessionStatusBar->Panels->Items[Index]->Text = FormatBytes(Terminal->BytesReceived);
  1035. SessionStatusBar->Panels->Items[Index + 1]->Text = FormatBytes(Terminal->BytesSent);
  1036. SessionStatusBar->Panels->Items[Index + 5]->Text = Terminal->ProtocolName;
  1037. SessionStatusBar->Panels->Items[Index + 6]->Text =
  1038. FormatDateTime(Configuration->TimeFormat, Terminal->Duration);
  1039. }
  1040. SessionStatusBar->Invalidate();
  1041. }
  1042. //---------------------------------------------------------------------------
  1043. void __fastcall TCustomScpExplorerForm::SessionStatusBarDrawPanel(
  1044. TStatusBar *StatusBar, TStatusPanel *Panel, const TRect &Rect)
  1045. {
  1046. if (Terminal && Terminal->Active && Terminal->Status >= sshReady)
  1047. {
  1048. int ImageIndex;
  1049. AnsiString PanelText;
  1050. switch (Panel->Index - StatusBar->Tag) {
  1051. case 2: ImageIndex = Terminal->SshVersion - 1; break;
  1052. case 3: ImageIndex = 2 + (Terminal->CSCompression || Terminal->SCCompression); break;
  1053. case 4: ImageIndex = 4; PanelText = CipherNames[Terminal->CSCipher]; break;
  1054. default: assert(false); break;
  1055. }
  1056. TCanvas *SCanvas = StatusBar->Canvas;
  1057. if ((Panel->Alignment == taCenter) && PanelText.IsEmpty())
  1058. {
  1059. NonVisualDataModule->SessionImages->Draw(SCanvas,
  1060. Rect.Left + Rect.Width() / 2 - NonVisualDataModule->SessionImages->Width / 2,
  1061. Rect.Top, ImageIndex, true);
  1062. }
  1063. else
  1064. {
  1065. NonVisualDataModule->SessionImages->Draw(SCanvas,
  1066. Rect.Left + 1, Rect.Top, ImageIndex, true);
  1067. if (!PanelText.IsEmpty())
  1068. {
  1069. SCanvas->TextOut(Rect.left + 18, Rect.top + 1, PanelText);
  1070. }
  1071. }
  1072. }
  1073. }
  1074. //---------------------------------------------------------------------------
  1075. void __fastcall TCustomScpExplorerForm::SessionIdle()
  1076. {
  1077. // terminal may not be active here, when connection is closed by remote side
  1078. // and coresponding error message is being displayed
  1079. if (Terminal && Terminal->Active)
  1080. {
  1081. Terminal->Idle();
  1082. }
  1083. UpdateStatusBar();
  1084. FIgnoreNextSysCommand = false;
  1085. }
  1086. //---------------------------------------------------------------------------
  1087. void __fastcall TCustomScpExplorerForm::SessionStatusBarMouseMove(
  1088. TObject * Sender, TShiftState /*Shift*/, int X, int Y)
  1089. {
  1090. if (Terminal && Terminal->Active)
  1091. {
  1092. const int Hints[3] = { STATUS_RECEIVED_HINT, STATUS_SENT_HINT, STATUS_DURATION_HINT };
  1093. TStatusBar * StatusBar = ((TStatusBar *)Sender);
  1094. assert(StatusBar);
  1095. TPoint Local(X, Y)/* = StatusBar->ScreenToClient(Mouse->CursorPos)*/;
  1096. int IPanel = 0;
  1097. while ((Local.x > StatusBar->Panels->Items[IPanel]->Width) &&
  1098. (IPanel < StatusBar->Panels->Count - 1))
  1099. {
  1100. Local.x -= StatusBar->Panels->Items[IPanel]->Width;
  1101. IPanel ++;
  1102. }
  1103. AnsiString AHint;
  1104. if (StatusBar->Tag && (IPanel == 0))
  1105. {
  1106. AHint = LoadStr(STATUS_FILEINFO_HINT);
  1107. }
  1108. else
  1109. {
  1110. if (StatusBar->Tag) IPanel--;
  1111. switch (IPanel) {
  1112. case 0:
  1113. case 1: AHint = LoadStr(Hints[IPanel]); break;
  1114. case 6: AHint = LoadStr(Hints[2]); break;
  1115. case 2: AHint = FMTLOAD(STATUS_VERSION_HINT, (Terminal->SshVersion)); break;
  1116. case 3:
  1117. if (Terminal->CSCompression == Terminal->SCCompression)
  1118. {
  1119. AHint = FMTLOAD(STATUS_COMPRESSION_HINT, (BooleanToStr(Terminal->CSCompression)));
  1120. }
  1121. else
  1122. {
  1123. AHint = FMTLOAD(STATUS_COMPRESSION2_HINT,
  1124. (BooleanToStr(Terminal->CSCompression), BooleanToStr(Terminal->SCCompression)));
  1125. }
  1126. break;
  1127. case 4:
  1128. if (Terminal->CSCipher == Terminal->SCCipher)
  1129. {
  1130. AHint = FMTLOAD(STATUS_ENCRYPTION_HINT, (CipherNames[Terminal->CSCipher]));
  1131. }
  1132. else
  1133. {
  1134. AHint = FMTLOAD(STATUS_ENCRYPTION2_HINT,
  1135. (CipherNames[Terminal->CSCipher], CipherNames[Terminal->SCCipher]));
  1136. }
  1137. break;
  1138. case 5:
  1139. AHint = FMTLOAD(STATUS_FS_PROTOCOL, (Terminal->ProtocolName));
  1140. break;
  1141. default: AHint = ""; break;
  1142. }
  1143. }
  1144. if (AHint.IsEmpty())
  1145. {
  1146. StatusBar->Hint = AHint;
  1147. }
  1148. else
  1149. {
  1150. AHint = FORMAT("%s|X", (AHint));
  1151. if (AHint != StatusBar->Hint)
  1152. {
  1153. Application->CancelHint();
  1154. StatusBar->Hint = AHint;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. //---------------------------------------------------------------------------
  1160. void __fastcall TCustomScpExplorerForm::ApplicationHint(TObject * /*Sender*/)
  1161. {
  1162. assert(GetComponent(fcStatusBar) && Application);
  1163. AnsiString AHint = GetLongHint(Application->Hint);
  1164. FShowStatusBarHint = Active && !AHint.IsEmpty() && (AHint != "X");
  1165. if (FShowStatusBarHint)
  1166. {
  1167. FStatusBarHint = AHint != "E" ? AHint : AnsiString("");
  1168. }
  1169. else
  1170. {
  1171. FStatusBarHint = "";
  1172. }
  1173. UpdateStatusBar();
  1174. }
  1175. //---------------------------------------------------------------------------
  1176. void __fastcall TCustomScpExplorerForm::NewSession()
  1177. {
  1178. TSessionData * Data = new TSessionData("");
  1179. try
  1180. {
  1181. Data->Assign(StoredSessions->DefaultSettings);
  1182. if (DoLoginDialog(StoredSessions, Data, loAddSession))
  1183. {
  1184. assert(Data->CanLogin);
  1185. TTerminalManager * Manager = TTerminalManager::Instance();
  1186. TTerminal * Terminal = Manager->NewTerminal(Data);
  1187. Manager->ActiveTerminal = Terminal;
  1188. Manager->ConnectActiveTerminal();
  1189. }
  1190. }
  1191. __finally
  1192. {
  1193. delete Data;
  1194. }
  1195. }
  1196. //---------------------------------------------------------------------------
  1197. void __fastcall TCustomScpExplorerForm::CloseSession()
  1198. {
  1199. TTerminalManager::Instance()->FreeActiveTerminal();
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
  1203. {
  1204. TTerminalManager * Manager = TTerminalManager::Instance();
  1205. TTerminal * Terminal = Manager->NewTerminal(Data);
  1206. Manager->ActiveTerminal = Terminal;
  1207. Manager->ConnectActiveTerminal();
  1208. }
  1209. //---------------------------------------------------------------------------
  1210. void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
  1211. bool &CanClose)
  1212. {
  1213. if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
  1214. {
  1215. int Result;
  1216. if (TTerminalManager::Instance()->Count > 1)
  1217. {
  1218. Result = MessageDialog(LoadStr(CLOSE_SESSIONS), qtConfirmation,
  1219. qaOK | qaCancel, 0, mpNeverAskAgainCheck);
  1220. }
  1221. else
  1222. {
  1223. Result = MessageDialog(FMTLOAD(CLOSE_SESSION,
  1224. (Terminal->SessionData->SessionName)), qtConfirmation,
  1225. qaOK | qaCancel, 0, mpNeverAskAgainCheck);
  1226. }
  1227. if (Result == qaNeverAskAgain)
  1228. {
  1229. WinConfiguration->ConfirmClosingSession = false;
  1230. }
  1231. CanClose = (Result == qaOK || Result == qaNeverAskAgain);
  1232. }
  1233. }
  1234. //---------------------------------------------------------------------------
  1235. void __fastcall TCustomScpExplorerForm::DropDownButtonMenu(TObject *Sender)
  1236. {
  1237. ((TToolButton*)Sender)->CheckMenuDropdown();
  1238. }
  1239. //---------------------------------------------------------------------------
  1240. void __fastcall TCustomScpExplorerForm::RemoteDirViewDisplayProperties(
  1241. TObject *Sender)
  1242. {
  1243. TStrings *FileList = ((TUnixDirView*)Sender)->CreateFileList(True, False, NULL);
  1244. try
  1245. {
  1246. SetProperties(osRemote, FileList);
  1247. }
  1248. __finally
  1249. {
  1250. delete FileList;
  1251. }
  1252. }
  1253. //---------------------------------------------------------------------------
  1254. void __fastcall TCustomScpExplorerForm::SetComponentVisible(Word Component, Boolean value)
  1255. {
  1256. TControl * Control = GetComponent((Word)(Component & 0x00FF));
  1257. assert(Control);
  1258. if ((dynamic_cast<TCoolBar*>(Control) != NULL) && (Component & 0xFF00))
  1259. {
  1260. TCoolBand * Band = GetCoolBand(dynamic_cast<TCoolBar*>(Control),
  1261. (Component & 0xFF00) >> 8);
  1262. assert(Band);
  1263. Band->Visible = value;
  1264. }
  1265. else
  1266. {
  1267. Control->Visible = value;
  1268. }
  1269. if (RemoteDirView->ItemFocused != NULL)
  1270. {
  1271. RemoteDirView->ItemFocused->MakeVisible(false);
  1272. }
  1273. }
  1274. //---------------------------------------------------------------------------
  1275. bool __fastcall TCustomScpExplorerForm::GetComponentVisible(Word Component)
  1276. {
  1277. TControl * Control = GetComponent((Word)(Component & 0x00FF));
  1278. if (Control == NULL)
  1279. {
  1280. return false;
  1281. }
  1282. else if ((dynamic_cast<TCoolBar*>(Control) != NULL) && (Component & 0xFF00))
  1283. {
  1284. TCoolBand * Band = GetCoolBand(dynamic_cast<TCoolBar*>(Control),
  1285. (Component & 0xFF00) >> 8);
  1286. return Band != NULL ? Band->Visible : false;
  1287. }
  1288. else
  1289. {
  1290. return Control->Visible;
  1291. }
  1292. }
  1293. //---------------------------------------------------------------------------
  1294. TCoolBand * __fastcall TCustomScpExplorerForm::GetCoolBand(TCoolBar * Coolbar, int ID)
  1295. {
  1296. return dynamic_cast<TCoolBand *>(Coolbar->Bands->FindItemID(ID));
  1297. }
  1298. //---------------------------------------------------------------------------
  1299. TControl * __fastcall TCustomScpExplorerForm::GetComponent(Byte Component)
  1300. {
  1301. switch (Component) {
  1302. case fcStatusBar: return RemoteStatusBar;
  1303. case fcCoolBar: return TopCoolBar;
  1304. case fcRemotePopup: return reinterpret_cast<TControl *>(NonVisualDataModule->RemoteDirViewPopup);
  1305. default: return NULL;
  1306. }
  1307. }
  1308. //---------------------------------------------------------------------------
  1309. void __fastcall TCustomScpExplorerForm::DirViewColumnRightClick(
  1310. TObject *Sender, TListColumn *Column, TPoint &Point)
  1311. {
  1312. assert(NonVisualDataModule && Column && Sender);
  1313. NonVisualDataModule->ListColumn = Column;
  1314. TPoint ScreenPoint = ((TControl*)Sender)->ClientToScreen(Point);
  1315. TPopupMenu * DirViewColumnMenu;
  1316. if (Sender == RemoteDirView)
  1317. {
  1318. DirViewColumnMenu = NonVisualDataModule->RemoteDirViewColumnPopup;
  1319. }
  1320. else
  1321. {
  1322. DirViewColumnMenu = NonVisualDataModule->LocalDirViewColumnPopup;
  1323. }
  1324. DirViewColumnMenu->Popup(ScreenPoint.x, ScreenPoint.y);
  1325. }
  1326. //---------------------------------------------------------------------------
  1327. void __fastcall TCustomScpExplorerForm::DirViewExecFile(
  1328. TObject *Sender, TListItem *Item, bool &AllowExec)
  1329. {
  1330. DoDirViewExecFile(Sender, Item, AllowExec);
  1331. }
  1332. //---------------------------------------------------------------------------
  1333. void __fastcall TCustomScpExplorerForm::DoDirViewExecFile(TObject * Sender,
  1334. TListItem * Item, bool & AllowExec)
  1335. {
  1336. assert(Sender && Item && Configuration);
  1337. TCustomDirView * ADirView = (TCustomDirView *)Sender;
  1338. if (ADirView->ItemIsDirectory(Item))
  1339. {
  1340. AllowExec = true;
  1341. }
  1342. else if (WinConfiguration->CopyOnDoubleClick && !FForceExecution)
  1343. {
  1344. ExecuteFileOperation(foCopy,
  1345. (ADirView == DirView(osRemote) ? osRemote : osLocal),
  1346. true, !WinConfiguration->CopyOnDoubleClickConfirmation);
  1347. AllowExec = false;
  1348. }
  1349. else if (ADirView == DirView(osRemote) && !WinConfiguration->DisableOpenEdit)
  1350. {
  1351. ExecuteFile(osRemote, efDefault);
  1352. AllowExec = false;
  1353. }
  1354. else
  1355. {
  1356. AllowExec = true;
  1357. }
  1358. }
  1359. //---------------------------------------------------------------------------
  1360. bool __fastcall TCustomScpExplorerForm::GetHasDirView(TOperationSide Side)
  1361. {
  1362. return ((Side == osRemote) || (Side == osCurrent));
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. void __fastcall TCustomScpExplorerForm::CompareDirectories()
  1366. {
  1367. assert(false);
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. void __fastcall TCustomScpExplorerForm::SynchronizeDirectories()
  1371. {
  1372. assert(false);
  1373. }
  1374. //---------------------------------------------------------------------------
  1375. void __fastcall TCustomScpExplorerForm::FullSynchronizeDirectories()
  1376. {
  1377. assert(false);
  1378. }
  1379. //---------------------------------------------------------------------------
  1380. bool __fastcall TCustomScpExplorerForm::DoFullSynchronizeDirectories(
  1381. AnsiString & LocalDirectory, AnsiString & RemoteDirectory, TSynchronizeMode & Mode)
  1382. {
  1383. bool Result;
  1384. int Params = GUIConfiguration->SynchronizeParams;
  1385. bool SaveSettings;
  1386. Result = DoFullSynchronizeDialog(Mode, Params, LocalDirectory, RemoteDirectory,
  1387. SaveSettings);
  1388. if (Result)
  1389. {
  1390. if (SaveSettings)
  1391. {
  1392. GUIConfiguration->SynchronizeParams = Params;
  1393. }
  1394. assert(!FAutoOperation);
  1395. void * BatchStorage;
  1396. BatchStart(BatchStorage);
  1397. FAutoOperation = true;
  1398. try
  1399. {
  1400. FSynchronizeProgressForm = new TSynchronizeProgressForm(Application);
  1401. FSynchronizeProgressForm->Start();
  1402. Terminal->Synchronize(LocalDirectory, RemoteDirectory,
  1403. static_cast<TTerminal::TSynchronizeMode>(Mode),
  1404. Params, TerminalSynchronizeDirectory);
  1405. }
  1406. __finally
  1407. {
  1408. FAutoOperation = false;
  1409. SAFE_DESTROY(FSynchronizeProgressForm);
  1410. BatchEnd(BatchStorage);
  1411. if (HasDirView[osLocal])
  1412. {
  1413. DirView(osLocal)->Reload(true);
  1414. }
  1415. }
  1416. }
  1417. return Result;
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TCustomScpExplorerForm::TerminalSynchronizeDirectory(
  1421. const AnsiString LocalDirectory, const AnsiString RemoteDirectory, bool & Continue)
  1422. {
  1423. assert(FSynchronizeProgressForm != NULL);
  1424. FSynchronizeProgressForm->SetData(LocalDirectory, RemoteDirectory, Continue);
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TCustomScpExplorerForm::ExploreLocalDirectory()
  1428. {
  1429. assert(false);
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TCustomScpExplorerForm::SaveCurrentSession()
  1433. {
  1434. AnsiString SessionName;
  1435. SessionName = Terminal->SessionData->SessionName;
  1436. SessionName = DoSaveSessionDialog(StoredSessions, SessionName);
  1437. if (!SessionName.IsEmpty())
  1438. {
  1439. TSessionData * SessionData = new TSessionData("");
  1440. try
  1441. {
  1442. SessionData->Assign(Terminal->SessionData);
  1443. UpdateSessionData(SessionData);
  1444. StoredSessions->NewSession(SessionName, SessionData);
  1445. StoredSessions->Save();
  1446. }
  1447. __finally
  1448. {
  1449. delete SessionData;
  1450. }
  1451. }
  1452. }
  1453. //---------------------------------------------------------------------------
  1454. void __fastcall TCustomScpExplorerForm::UpdateSessionData(TSessionData * Data)
  1455. {
  1456. assert(Terminal && Terminal->SessionData);
  1457. if (!Data)
  1458. {
  1459. Data = Terminal->SessionData;
  1460. }
  1461. // cannot use RemoteDirView->Path, because it is empty if connection
  1462. // was already closed
  1463. Data->RemoteDirectory = Terminal->CurrentDirectory;
  1464. }
  1465. //---------------------------------------------------------------------------
  1466. void __fastcall TCustomScpExplorerForm::ToolBarResize(TObject *Sender)
  1467. {
  1468. TToolBar * ToolBar = (TToolBar*)Sender;
  1469. TControl * Child = (TControl *)ToolBar->Controls[0];
  1470. Child->Width = ToolBar->Width;
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TCustomScpExplorerForm::RemoteDirViewWarnLackOfTempSpace(
  1474. TUnixDirView * /*Sender*/, const AnsiString Path, __int64 RequiredSpace,
  1475. bool &Continue)
  1476. {
  1477. if (WinConfiguration->DDWarnLackOfTempSpace)
  1478. {
  1479. AnsiString ADrive = ExtractFileDrive(ExpandFileName(Path));
  1480. if (!ADrive.IsEmpty())
  1481. {
  1482. __int64 FreeSpace = DiskFree((Byte)(ADrive[1]-'A'+1));
  1483. Integer MessageRes = 0;
  1484. if (RequiredSpace >= 0)
  1485. {
  1486. __int64 RequiredWithReserve;
  1487. RequiredWithReserve = (__int64)(RequiredSpace * WinConfiguration->DDWarnLackOfTempSpaceRatio);
  1488. if (FreeSpace < RequiredWithReserve) MessageRes = DD_WARN_LACK_OF_TEMP_SPACE;
  1489. }
  1490. else
  1491. {
  1492. MessageRes = DD_WARN_UNKNOWN_TEMP_SPACE;
  1493. }
  1494. if (MessageRes)
  1495. {
  1496. int Result;
  1497. Result = MessageDialog(FMTLOAD(MessageRes, (Path,
  1498. FormatBytes(FreeSpace), FormatBytes(RequiredSpace))),
  1499. qtWarning, qaYes | qaNo, 0, mpNeverAskAgainCheck);
  1500. if (Result == qaNeverAskAgain)
  1501. {
  1502. WinConfiguration->DDWarnLackOfTempSpace = false;
  1503. }
  1504. Continue = (Result == qaYes || Result == qaNeverAskAgain);
  1505. }
  1506. }
  1507. }
  1508. }
  1509. //---------------------------------------------------------------------------
  1510. void __fastcall TCustomScpExplorerForm::AddBookmark(TOperationSide Side)
  1511. {
  1512. DoOpenDirectoryDialog(odAddBookmark, Side);
  1513. }
  1514. //---------------------------------------------------------------------------
  1515. TStrings * __fastcall TCustomScpExplorerForm::CreateVisitedDirectories(TOperationSide Side)
  1516. {
  1517. TStringList * VisitedDirectories = new TStringList();
  1518. try
  1519. {
  1520. TCustomDirView * DView = DirView(Side);
  1521. VisitedDirectories->Duplicates = dupIgnore;
  1522. // we should better use TCustomDirView::FCaseSensitive, but it is private
  1523. VisitedDirectories->CaseSensitive = (Side == osRemote);
  1524. VisitedDirectories->Sorted = true;
  1525. for (int Index = -DView->BackCount; Index <= DView->ForwardCount; Index++)
  1526. {
  1527. VisitedDirectories->Add(DView->HistoryPath[Index]);
  1528. }
  1529. }
  1530. catch (...)
  1531. {
  1532. delete VisitedDirectories;
  1533. throw;
  1534. }
  1535. return VisitedDirectories;
  1536. }
  1537. //---------------------------------------------------------------------------
  1538. void __fastcall TCustomScpExplorerForm::DoOpenDirectoryDialog(
  1539. TOpenDirectoryMode Mode, TOperationSide Side)
  1540. {
  1541. if (Mode != odAddBookmark ||
  1542. (MessageDialog(FMTLOAD(ADD_BOOKMARK_CONFIRM, (DirView(Side)->PathName)),
  1543. qtConfirmation, qaYes | qaNo, 0) == qaYes))
  1544. {
  1545. TStrings * VisitedDirectories = CreateVisitedDirectories(Side);
  1546. try
  1547. {
  1548. AnsiString Name = DirView(Side)->PathName;
  1549. if (::DoOpenDirectoryDialog(Mode, Side, Name, VisitedDirectories, Terminal))
  1550. {
  1551. DirView(Side)->Path = Name;
  1552. }
  1553. }
  1554. __finally
  1555. {
  1556. delete VisitedDirectories;
  1557. }
  1558. }
  1559. }
  1560. //---------------------------------------------------------------------------
  1561. void __fastcall TCustomScpExplorerForm::OpenInPutty()
  1562. {
  1563. OpenSessionInPutty(Terminal->SessionData);
  1564. }
  1565. //---------------------------------------------------------------------------
  1566. void __fastcall TCustomScpExplorerForm::OpenConsole(AnsiString Command)
  1567. {
  1568. DoConsoleDialog(Terminal, Command);
  1569. }
  1570. //---------------------------------------------------------------------------
  1571. void __fastcall TCustomScpExplorerForm::DirViewDDDragEnter(
  1572. TObject *Sender, _di_IDataObject /*DataObj*/, int /*grfKeyState*/,
  1573. const TPoint & /*Point*/, int & /*dwEffect*/, bool & Accept)
  1574. {
  1575. if ((DropSourceControl == RemoteDirView) &&
  1576. (FDDExtMapFile != NULL))
  1577. {
  1578. Accept = true;
  1579. }
  1580. FDDTargetDirView = (TCustomDirView*)Sender;
  1581. }
  1582. //---------------------------------------------------------------------------
  1583. void __fastcall TCustomScpExplorerForm::DirViewDDDragLeave(
  1584. TObject *Sender)
  1585. {
  1586. USEDPARAM(Sender);
  1587. assert(FDDTargetDirView == Sender);
  1588. FDDTargetDirView = NULL;
  1589. }
  1590. //---------------------------------------------------------------------------
  1591. void __fastcall TCustomScpExplorerForm::AddEditLink()
  1592. {
  1593. assert(FLastDirView == RemoteDirView);
  1594. bool Edit = false;
  1595. TRemoteFile * File = NULL;
  1596. AnsiString FileName;
  1597. AnsiString PointTo;
  1598. bool SymbolicLink = true;
  1599. if (RemoteDirView->ItemFocused)
  1600. {
  1601. assert(RemoteDirView->ItemFocused->Data);
  1602. File = (TRemoteFile *)RemoteDirView->ItemFocused->Data;
  1603. Edit = File->IsSymLink && Terminal->SessionData->ResolveSymlinks;
  1604. if (Edit)
  1605. {
  1606. FileName = File->FileName;
  1607. PointTo = File->LinkTo;
  1608. }
  1609. else
  1610. {
  1611. PointTo = File->FileName;
  1612. }
  1613. }
  1614. if (DoSymlinkDialog(FileName, PointTo, osRemote, SymbolicLink, Edit,
  1615. Terminal->IsCapable[fcHardLink]))
  1616. {
  1617. if (Edit)
  1618. {
  1619. assert(File->FileName == FileName);
  1620. bool Recursive = false;
  1621. Terminal->ExceptionOnFail = true;
  1622. try
  1623. {
  1624. Terminal->DeleteFile("", File, &Recursive);
  1625. }
  1626. __finally
  1627. {
  1628. Terminal->ExceptionOnFail = false;
  1629. }
  1630. }
  1631. Terminal->CreateLink(FileName, PointTo, SymbolicLink);
  1632. }
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. void __fastcall TCustomScpExplorerForm::ExecuteCurrentFile()
  1636. {
  1637. assert(!WinConfiguration->DisableOpenEdit);
  1638. FForceExecution = true;
  1639. try
  1640. {
  1641. DirView(osCurrent)->ExecuteCurrentFile();
  1642. }
  1643. __finally
  1644. {
  1645. FForceExecution = false;
  1646. }
  1647. }
  1648. //---------------------------------------------------------------------------
  1649. void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
  1650. {
  1651. try
  1652. {
  1653. NewSession();
  1654. }
  1655. __finally
  1656. {
  1657. if (!Terminal || !Terminal->Active)
  1658. {
  1659. Application->Terminate();
  1660. }
  1661. }
  1662. }
  1663. //---------------------------------------------------------------------------
  1664. void __fastcall TCustomScpExplorerForm::TerminalListChanged(TObject * /*Sender*/)
  1665. {
  1666. TCustomCombo * SessionCombo = dynamic_cast<TCustomCombo *>(GetComponent(fcSessionCombo));
  1667. if (SessionCombo != NULL)
  1668. {
  1669. SessionCombo->Items = TTerminalManager::Instance()->TerminalList;
  1670. SessionCombo->ItemIndex = TTerminalManager::Instance()->ActiveTerminalIndex;
  1671. }
  1672. NonVisualDataModule->CreateOpenedSessionListMenu();
  1673. }
  1674. //---------------------------------------------------------------------------
  1675. void __fastcall TCustomScpExplorerForm::SessionComboDropDown(TObject * Sender)
  1676. {
  1677. TCustomComboBox * SessionCombo = dynamic_cast<TCustomComboBox *>(Sender);
  1678. assert(SessionCombo);
  1679. TCanvas * Canvas = SessionCombo->Canvas;
  1680. int MaxWidth = 0, Width;
  1681. for (int i = 0; i < SessionCombo->Items->Count; i++)
  1682. {
  1683. Width = Canvas->TextExtent(SessionCombo->Items->Strings[i]).cx;
  1684. TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(i);
  1685. if (ShortCut != scNone)
  1686. {
  1687. Width += Canvas->TextExtent(ShortCutToText(ShortCut)).cx;
  1688. }
  1689. if (Width > MaxWidth)
  1690. {
  1691. MaxWidth = Width;
  1692. }
  1693. }
  1694. MaxWidth += 8;
  1695. if (SessionCombo->Items->Count > ((TComboBox *)SessionCombo)->DropDownCount)
  1696. {
  1697. MaxWidth += GetSystemMetrics(SM_CXVSCROLL);
  1698. }
  1699. SessionCombo->Perform(CB_SETDROPPEDWIDTH, MaxWidth + 8 + 1, 0);
  1700. }
  1701. //---------------------------------------------------------------------------
  1702. void __fastcall TCustomScpExplorerForm::SessionComboDrawItem(
  1703. TWinControl * Control, int Index, const TRect & Rect, TOwnerDrawState /*State*/)
  1704. {
  1705. TCustomComboBox * SessionCombo = dynamic_cast<TCustomComboBox *>(Control);
  1706. assert(SessionCombo);
  1707. TCanvas * Canvas = SessionCombo->Canvas;
  1708. Canvas->FillRect(Rect);
  1709. if (Index >= 0)
  1710. {
  1711. int ShortCutWidth = 0;
  1712. AnsiString ShortCutStr;
  1713. if (Rect.Top != 3)
  1714. {
  1715. TShortCut ShortCut = NonVisualDataModule->OpenSessionShortCut(Index);
  1716. if (ShortCut != scNone)
  1717. {
  1718. ShortCutStr = ShortCutToText(ShortCut);
  1719. ShortCutWidth = Canvas->TextExtent(ShortCutStr).cx;
  1720. }
  1721. }
  1722. TRect R = Rect;
  1723. R.Right -= ShortCutWidth + 2;
  1724. Canvas->TextRect(R, R.Left + 2, R.Top, SessionCombo->Items->Strings[Index]);
  1725. R = Rect;
  1726. R.Left = R.Right - ShortCutWidth - 2;
  1727. Canvas->TextRect(R, R.Left, R.Top, ShortCutStr);
  1728. }
  1729. }
  1730. //---------------------------------------------------------------------------
  1731. void __fastcall TCustomScpExplorerForm::SessionComboChange(TObject * Sender)
  1732. {
  1733. TCustomComboBox * SessionCombo = dynamic_cast<TCustomComboBox *>(Sender);
  1734. assert(SessionCombo);
  1735. TTerminal * Terminal;
  1736. Terminal = dynamic_cast<TTerminal *>(SessionCombo->Items->Objects[SessionCombo->ItemIndex]);
  1737. assert(Terminal);
  1738. TTerminalManager::Instance()->ActiveTerminal = Terminal;
  1739. }
  1740. //---------------------------------------------------------------------------
  1741. void __fastcall TCustomScpExplorerForm::CMAppSysCommand(TMessage & Message)
  1742. {
  1743. TWMSysCommand * SysCommand = (TWMSysCommand *)Message.LParam;
  1744. if (SysCommand->CmdType != SC_KEYMENU || !FIgnoreNextSysCommand)
  1745. {
  1746. FIgnoreNextSysCommand = false;
  1747. TForm::Dispatch(&Message);
  1748. }
  1749. else
  1750. {
  1751. Message.Result = 1;
  1752. }
  1753. }
  1754. //---------------------------------------------------------------------------
  1755. void __fastcall TCustomScpExplorerForm::DoShow()
  1756. {
  1757. TToolBar * MenuToolBar = dynamic_cast<TToolBar*>(GetComponent(fcMenuToolBar));
  1758. MenuToolBar->Height = MenuToolBar->Controls[0]->Height;
  1759. TForm::DoShow();
  1760. }
  1761. //---------------------------------------------------------------------------
  1762. int __fastcall TCustomScpExplorerForm::MoreMessageDialog(const AnsiString Message,
  1763. TStrings * MoreMessages, TQueryType Type, int Answers,
  1764. int HelpCtx, int Params)
  1765. {
  1766. if (WinConfiguration->ContinueOnError && (Params & mpAllowContinueOnError) &&
  1767. FErrorList)
  1768. {
  1769. TStringList * MoreMessagesCopy = NULL;
  1770. if (MoreMessages)
  1771. {
  1772. MoreMessagesCopy = new TStringList();
  1773. MoreMessagesCopy->Assign(MoreMessages);
  1774. }
  1775. FErrorList->AddObject(Message, MoreMessagesCopy);
  1776. if (Answers & qaSkip) return qaSkip;
  1777. else
  1778. if (Answers & qaIgnore) return qaIgnore;
  1779. else
  1780. if (Answers & qaOK) return qaOK;
  1781. else
  1782. if (Answers & qaYes) return qaYes;
  1783. else
  1784. if (Answers & qaRetry) return qaRetry;
  1785. else
  1786. {
  1787. assert(false);
  1788. return qaYes;
  1789. }
  1790. }
  1791. else
  1792. {
  1793. return ::MoreMessageDialog(Message, MoreMessages, Type, Answers, HelpCtx, Params);
  1794. }
  1795. }
  1796. //---------------------------------------------------------------------------
  1797. void __fastcall TCustomScpExplorerForm::RemoteDirViewDDCreateDragFileList(
  1798. TObject * /*Sender*/, TFileList * FileList, bool & Created)
  1799. {
  1800. if (FDDExtMapFile != NULL)
  1801. {
  1802. CloseHandle(FDDExtMapFile);
  1803. FDDExtMapFile = NULL;
  1804. }
  1805. if (WinConfiguration->DDExtEnabled)
  1806. {
  1807. DDExtInitDrag(FileList, Created);
  1808. }
  1809. }
  1810. //---------------------------------------------------------------------------
  1811. void __fastcall TCustomScpExplorerForm::DDExtInitDrag(TFileList * FileList,
  1812. bool & Created)
  1813. {
  1814. FDragExtFakeDirectory =
  1815. ExcludeTrailingBackslash(UniqTempDir(WinConfiguration->DDTemporaryDirectory));
  1816. ForceDirectories(FDragExtFakeDirectory);
  1817. FileList->AddItem(NULL, FDragExtFakeDirectory);
  1818. Created = true;
  1819. FDDExtMapFile = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE,
  1820. 0, sizeof(TDragExtCommStruct), DRAG_EXT_MAPPING);
  1821. {
  1822. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  1823. TDragExtCommStruct* CommStruct;
  1824. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  1825. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  1826. assert(CommStruct != NULL);
  1827. CommStruct->Version = TDragExtCommStruct::CurrentVersion;
  1828. CommStruct->Dragging = true;
  1829. strncpy(CommStruct->DropDest, FDragExtFakeDirectory.c_str(),
  1830. sizeof(CommStruct->DropDest));
  1831. CommStruct->DropDest[sizeof(CommStruct->DropDest) - 1] = '\0';
  1832. UnmapViewOfFile(CommStruct);
  1833. }
  1834. FDDExtDropEffect = DROPEFFECT_NONE;
  1835. }
  1836. //---------------------------------------------------------------------------
  1837. void __fastcall TCustomScpExplorerForm::RemoteDirViewDDEnd(TObject * /*Sender*/)
  1838. {
  1839. if (FDDExtMapFile != NULL)
  1840. {
  1841. try
  1842. {
  1843. if (FDDExtDropEffect != DROPEFFECT_NONE)
  1844. {
  1845. AnsiString TargetDirectory;
  1846. DDGetTarget(TargetDirectory);
  1847. ExecuteFileOperation(
  1848. FDDExtDropEffect == DROPEFFECT_MOVE ? foMove : foCopy, osRemote, true,
  1849. !WinConfiguration->DDTransferConfirmation, &TargetDirectory);
  1850. }
  1851. }
  1852. __finally
  1853. {
  1854. CloseHandle(FDDExtMapFile);
  1855. FDDExtMapFile = NULL;
  1856. RemoveDir(FDragExtFakeDirectory);
  1857. FDragExtFakeDirectory = "";
  1858. }
  1859. }
  1860. }
  1861. //---------------------------------------------------------------------------
  1862. void __fastcall TCustomScpExplorerForm::DDGetTarget(AnsiString & Directory)
  1863. {
  1864. bool Result = false;
  1865. Enabled = false;
  1866. try
  1867. {
  1868. int Timer = 0;
  1869. while (!Result && (Timer < WinConfiguration->DDExtTimeout))
  1870. {
  1871. {
  1872. TMutexGuard Guard(FDDExtMutex, DRAGEXT_MUTEX_RELEASE_TIMEOUT);
  1873. TDragExtCommStruct* CommStruct;
  1874. CommStruct = static_cast<TDragExtCommStruct*>(MapViewOfFile(FDDExtMapFile,
  1875. FILE_MAP_ALL_ACCESS, 0, 0, 0));
  1876. assert(CommStruct != NULL);
  1877. Result = !CommStruct->Dragging;
  1878. if (Result)
  1879. {
  1880. Directory = ExtractFilePath(CommStruct->DropDest);
  1881. }
  1882. UnmapViewOfFile(CommStruct);
  1883. }
  1884. Sleep(50);
  1885. Timer += 50;
  1886. Application->ProcessMessages();
  1887. }
  1888. }
  1889. __finally
  1890. {
  1891. Enabled = true;
  1892. }
  1893. if (!Result)
  1894. {
  1895. throw Exception(LoadStr(DRAGEXT_TARGET_UNKNOWN));
  1896. }
  1897. }
  1898. //---------------------------------------------------------------------------
  1899. void __fastcall TCustomScpExplorerForm::RemoteDirViewDDTargetDrop(
  1900. TUnixDirView * /*Sender*/, int DropEffect, bool & Continue)
  1901. {
  1902. if ((DropEffect == DROPEFFECT_MOVE) &&
  1903. (FDDTargetDirView == RemoteDirView))
  1904. {
  1905. ExecuteFileOperation(foRemoteMove, osRemote, true,
  1906. !WinConfiguration->DDTransferConfirmation);
  1907. // abort drag&drop
  1908. Abort();
  1909. }
  1910. else if (FDDExtMapFile != NULL)
  1911. {
  1912. Continue = false;
  1913. FDDExtDropEffect = DropEffect;
  1914. }
  1915. }
  1916. //---------------------------------------------------------------------------
  1917. class TFakeDataObjectFilesEx : public TDataObjectFilesEx
  1918. {
  1919. public:
  1920. __fastcall TFakeDataObjectFilesEx(TFileList * AFileList, bool RenderPIDL,
  1921. bool RenderFilename) : TDataObjectFilesEx(AFileList, RenderPIDL, RenderFilename)
  1922. {
  1923. }
  1924. virtual bool __fastcall AllowData(const tagFORMATETC & FormatEtc)
  1925. {
  1926. return (FormatEtc.cfFormat == CF_HDROP) ? false :
  1927. TDataObjectFilesEx::AllowData(FormatEtc);
  1928. }
  1929. };
  1930. //---------------------------------------------------------------------------
  1931. void __fastcall TCustomScpExplorerForm::RemoteDirViewDDCreateDataObject(
  1932. TObject * /*Sender*/, TDataObject *& DataObject)
  1933. {
  1934. if (FDDExtMapFile != NULL)
  1935. {
  1936. TFileList * FileList = RemoteDirView->DragDropFilesEx->FileList;
  1937. if (!FileList->RenderPIDLs() || !FileList->RenderNames())
  1938. {
  1939. Abort();
  1940. }
  1941. if (FileList->Count > 0)
  1942. {
  1943. TDataObjectFilesEx * FilesObject = new TFakeDataObjectFilesEx(FileList, true, true);
  1944. if (!FilesObject->IsValid(true, true))
  1945. {
  1946. FilesObject->_Release();
  1947. }
  1948. else
  1949. {
  1950. DataObject = FilesObject;
  1951. }
  1952. }
  1953. }
  1954. }
  1955. //---------------------------------------------------------------------------
  1956. void __fastcall TCustomScpExplorerForm::GoToCommandLine()
  1957. {
  1958. assert(false);
  1959. }
  1960. //---------------------------------------------------------------------------
  1961. void __fastcall TCustomScpExplorerForm::PanelExport(TOperationSide Side,
  1962. TPanelExport Export, TPanelExportDestination Destination, bool OnFocused)
  1963. {
  1964. Side = GetSide(Side);
  1965. TCustomDirView * DirView = this->DirView(Side);
  1966. TStringList * ExportData = new TStringList();
  1967. try
  1968. {
  1969. if (Export == pePath)
  1970. {
  1971. ExportData->Add(DirView->PathName);
  1972. }
  1973. else
  1974. {
  1975. bool FullPath = (Export == peFullFileList);
  1976. DirView->CreateFileList(OnFocused, FullPath, ExportData);
  1977. AnsiString FileName;
  1978. for (int Index = 0; Index < ExportData->Count; Index++)
  1979. {
  1980. if (ExportData->Strings[Index].Pos(" ") > 0)
  1981. {
  1982. ExportData->Strings[Index] = FORMAT("\"%s\"", (ExportData->Strings[Index]));
  1983. }
  1984. }
  1985. }
  1986. PanelExportStore(Side, Export, Destination, ExportData);
  1987. }
  1988. __finally
  1989. {
  1990. delete ExportData;
  1991. }
  1992. }
  1993. //---------------------------------------------------------------------------
  1994. void __fastcall TCustomScpExplorerForm::PanelExportStore(TOperationSide /*Side*/,
  1995. TPanelExport /*Export*/, TPanelExportDestination Destination,
  1996. TStringList * ExportData)
  1997. {
  1998. if (Destination == pedClipboard)
  1999. {
  2000. Clipboard()->AsText = ExportData->Text;
  2001. }
  2002. else
  2003. {
  2004. assert(false);
  2005. }
  2006. }