ScpCommander.cpp 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "ScpCommander.h"
  5. #include <Common.h>
  6. #include <CoreMain.h>
  7. #include <Interface.h>
  8. #include <TextsCore.h>
  9. #include <TextsWin.h>
  10. #include <HelpWin.h>
  11. #include <VCLCommon.h>
  12. #include <GUITools.h>
  13. #include <DragDrop.hpp>
  14. #include "Glyphs.h"
  15. #include "NonVisual.h"
  16. #include "Tools.h"
  17. #include "WinConfiguration.h"
  18. #include "TerminalManager.h"
  19. //---------------------------------------------------------------------------
  20. #pragma package(smart_init)
  21. #pragma link "CustomDirView"
  22. #pragma link "CustomScpExplorer"
  23. #pragma link "CustomUnixDirView"
  24. #pragma link "IEListView"
  25. #pragma link "NortonLikeListView"
  26. #pragma link "UnixDirView"
  27. #pragma link "DirView"
  28. #pragma link "PathLabel"
  29. #pragma link "HistoryComboBox"
  30. #pragma link "CustomDriveView"
  31. #pragma link "DriveView"
  32. #pragma link "UnixDriveView"
  33. #pragma link "TB2Dock"
  34. #pragma link "TB2Item"
  35. #pragma link "TB2Toolbar"
  36. #pragma link "TBX"
  37. #pragma link "TB2ExtItems"
  38. #pragma link "TBXExtItems"
  39. #pragma link "TBXLists"
  40. #pragma link "TBXStatusBars"
  41. #pragma link "TBXToolPals"
  42. #ifndef NO_RESOURCES
  43. #pragma resource "*.dfm"
  44. #endif
  45. //---------------------------------------------------------------------------
  46. class TSynchronizedBrowsingGuard
  47. {
  48. public:
  49. TSynchronizedBrowsingGuard()
  50. {
  51. FWasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  52. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  53. }
  54. ~TSynchronizedBrowsingGuard()
  55. {
  56. NonVisualDataModule->SynchronizeBrowsingAction->Checked = FWasSynchronisingBrowsing;
  57. }
  58. private:
  59. bool FWasSynchronisingBrowsing;
  60. };
  61. //---------------------------------------------------------------------------
  62. __fastcall TScpCommanderForm::TScpCommanderForm(TComponent* Owner)
  63. : TCustomScpExplorerForm(Owner)
  64. {
  65. FConstructed = true;
  66. FCurrentSide = osLocal;
  67. FLastLeftPanelWidth = LeftPanelWidth;
  68. FNormalPanelsWidth = -1;
  69. FSynchronisingBrowse = false;
  70. FFirstTerminal = true;
  71. FInternalDDDownloadList = new TStringList();
  72. FLocalPathComboBoxPaths = new TStringList();
  73. RemotePathComboBox->Images = FSystemImageList;
  74. RemotePathComboBox->SubMenuImages = FSystemImageList;
  75. LocalPathComboBox->Images = FSystemImageList;
  76. LocalPathComboBox->SubMenuImages = FSystemImageList;
  77. LocalPathComboUpdateDrives();
  78. LocalBackButton->LinkSubitems = HistoryMenu(osLocal, true)->Items;
  79. LocalForwardButton->LinkSubitems = HistoryMenu(osLocal, false)->Items;
  80. RemoteBackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  81. RemoteForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  82. TopDock->PopupMenu = NonVisualDataModule->CommanderBarPopup;
  83. StatusBar->PopupMenu = TopDock->PopupMenu;
  84. QueueDock->PopupMenu = TopDock->PopupMenu;
  85. BottomDock->PopupMenu = TopDock->PopupMenu;
  86. LocalTopDock->PopupMenu = NonVisualDataModule->LocalPanelPopup;
  87. LocalPathLabel->PopupMenu = LocalTopDock->PopupMenu;
  88. LocalStatusBar->PopupMenu = LocalTopDock->PopupMenu;
  89. LocalDriveView->PopupMenu = LocalTopDock->PopupMenu;
  90. LocalBottomDock->PopupMenu = LocalTopDock->PopupMenu;
  91. RemoteTopDock->PopupMenu = NonVisualDataModule->RemotePanelPopup;
  92. RemotePathLabel->PopupMenu = RemoteTopDock->PopupMenu;
  93. RemoteStatusBar->PopupMenu = RemoteTopDock->PopupMenu;
  94. RemoteDriveView->PopupMenu = RemoteTopDock->PopupMenu;
  95. RemoteBottomDock->PopupMenu = RemoteTopDock->PopupMenu;
  96. // set common norton shorcuts to our actions
  97. NonVisualDataModule->CommanderShortcuts();
  98. Splitter->ShowHint = True;
  99. reinterpret_cast<TLabel*>(Splitter)->OnDblClick = SplitterDblClick;
  100. reinterpret_cast<TLabel*>(LocalPanelSplitter)->OnDblClick = PanelSplitterDblClick;
  101. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = PanelSplitterDblClick;
  102. CommandLineCombo->Text = L"";
  103. FCommandLineComboPopulated = false;
  104. for (int i = 0; i < ToolbarToolbar->Items->Count; i++)
  105. {
  106. TTBCustomItem * Item = ToolbarToolbar->Items->Items[i];
  107. Item->Caption =
  108. ShortCutToText(Item->ShortCut) + L" " +
  109. Trim(StringReplace(StripHotkey(Item->Caption),
  110. L"...", L"", TReplaceFlags() << rfReplaceAll << rfIgnoreCase));
  111. }
  112. if (IsWin7())
  113. {
  114. LocalPathLabel->IndentVertical = LocalPathLabel->IndentVertical + 3;
  115. LocalPathLabel->Height = LocalPathLabel->Height + (3 * 2);
  116. RemotePathLabel->IndentVertical = RemotePathLabel->IndentVertical + 3;
  117. RemotePathLabel->Height = RemotePathLabel->Height + (3 * 2);
  118. }
  119. LocalDirView->Font = Screen->IconFont;
  120. NonVisualDataModule->InitMenus(this);
  121. NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
  122. }
  123. //---------------------------------------------------------------------------
  124. __fastcall TScpCommanderForm::~TScpCommanderForm()
  125. {
  126. delete FInternalDDDownloadList;
  127. SAFE_DESTROY(FLocalPathComboBoxPaths);
  128. }
  129. //---------------------------------------------------------------------------
  130. void __fastcall TScpCommanderForm::RestoreFormParams()
  131. {
  132. assert(WinConfiguration);
  133. TCustomScpExplorerForm::RestoreFormParams();
  134. RestoreForm(WinConfiguration->ScpCommander.WindowParams, this);
  135. }
  136. //---------------------------------------------------------------------------
  137. void __fastcall TScpCommanderForm::RestoreParams()
  138. {
  139. assert(Configuration);
  140. // IDE often looses this link
  141. LocalDirView->HeaderImages = GlyphsModule->ArrowImages;
  142. TCustomScpExplorerForm::RestoreParams();
  143. LeftPanelWidth = WinConfiguration->ScpCommander.LocalPanelWidth;
  144. LoadToolbarsLayoutStr(WinConfiguration->ScpCommander.ToolbarsLayout);
  145. SessionsPageControl->Visible = WinConfiguration->ScpCommander.SessionsTabs;
  146. StatusBar->Visible = WinConfiguration->ScpCommander.StatusBar;
  147. #define RESTORE_PANEL_PARAMS(PANEL) \
  148. PANEL ## DirView->ColProperties->ParamsStr = WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams; \
  149. PANEL ## StatusBar->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar; \
  150. PANEL ## DriveView->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.DriveView; \
  151. if (PANEL ## DriveView->Align == alTop) \
  152. PANEL ## DriveView->Height = WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight; \
  153. else \
  154. PANEL ## DriveView->Width = WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth
  155. RESTORE_PANEL_PARAMS(Local);
  156. RESTORE_PANEL_PARAMS(Remote);
  157. #undef RESTORE_PANEL_PARAMS
  158. FPanelsRestored = true;
  159. // just to make sure
  160. LocalDirView->DirColProperties->ExtVisible = false;
  161. RemoteDirView->UnixColProperties->ExtVisible = false;
  162. }
  163. //---------------------------------------------------------------------------
  164. void __fastcall TScpCommanderForm::StoreParams()
  165. {
  166. assert(WinConfiguration);
  167. WinConfiguration->BeginUpdate();
  168. try
  169. {
  170. WinConfiguration->ScpCommander.ToolbarsLayout = GetToolbarsLayoutStr();
  171. WinConfiguration->ScpCommander.LocalPanelWidth = LeftPanelWidth;
  172. WinConfiguration->ScpCommander.SessionsTabs = SessionsPageControl->Visible;
  173. WinConfiguration->ScpCommander.StatusBar = StatusBar->Visible;
  174. SaveCommandLine();
  175. WinConfiguration->ScpCommander.CurrentPanel = FCurrentSide;
  176. #define STORE_PANEL_PARAMS(PANEL) \
  177. WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams = PANEL ## DirView->ColProperties->ParamsStr; \
  178. WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar = PANEL ## StatusBar->Visible; \
  179. WinConfiguration->ScpCommander.PANEL ## Panel.DriveView = PANEL ## DriveView->Visible; \
  180. if (PANEL ## DriveView->Align == alTop) \
  181. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight = PANEL ## DriveView->Height; \
  182. else \
  183. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth = PANEL ## DriveView->Width
  184. STORE_PANEL_PARAMS(Local);
  185. STORE_PANEL_PARAMS(Remote);
  186. #undef RESTORE_PANEL_PARAMS
  187. WinConfiguration->ScpCommander.WindowParams = StoreForm(this);
  188. TCustomScpExplorerForm::StoreParams();
  189. }
  190. __finally
  191. {
  192. WinConfiguration->EndUpdate();
  193. }
  194. }
  195. //---------------------------------------------------------------------------
  196. void __fastcall TScpCommanderForm::UpdateTerminal(TTerminal * Terminal)
  197. {
  198. TCustomScpExplorerForm::UpdateTerminal(Terminal);
  199. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  200. assert(ManagedTerminal != NULL);
  201. SAFE_DESTROY(ManagedTerminal->LocalExplorerState);
  202. if (WinConfiguration->PreservePanelState)
  203. {
  204. ManagedTerminal->LocalExplorerState = LocalDirView->SaveState();
  205. ManagedTerminal->SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  206. }
  207. assert(LocalDirView != NULL);
  208. ManagedTerminal->LocalDirectory = LocalDirView->PathName;
  209. }
  210. //---------------------------------------------------------------------------
  211. void __fastcall TScpCommanderForm::UpdateSessionData(TSessionData * Data)
  212. {
  213. TCustomScpExplorerForm::UpdateSessionData(Data);
  214. assert(LocalDirView);
  215. Data->LocalDirectory = LocalDirView->PathName;
  216. Data->SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  217. }
  218. //---------------------------------------------------------------------------
  219. bool __fastcall TScpCommanderForm::InternalDDDownload(UnicodeString & TargetDirectory)
  220. {
  221. assert(IsFileControl(FDDTargetControl, osLocal));
  222. bool Result = false;
  223. if (FDDTargetControl == LocalDirView)
  224. {
  225. if (LocalDirView->DropTarget)
  226. {
  227. // when drop target is not directory, it is probably file type, which have
  228. // associated drop handler (such as ZIP file in WinXP). in this case we
  229. // must leave drop handling to destination application.
  230. // ! this check is duplicated in LocalDirViewDDTargetHasDropHandler()
  231. // for shellex downloads
  232. if (LocalDirView->ItemIsDirectory(LocalDirView->DropTarget))
  233. {
  234. TargetDirectory = LocalDirView->ItemFullFileName(LocalDirView->DropTarget);
  235. Result = true;
  236. }
  237. }
  238. else
  239. {
  240. TargetDirectory = IncludeTrailingBackslash(LocalDirView->Path);
  241. Result = true;
  242. }
  243. }
  244. else if (FDDTargetControl == LocalDriveView)
  245. {
  246. assert(LocalDriveView->DropTarget != NULL);
  247. TargetDirectory = LocalDriveView->NodePathName(LocalDriveView->DropTarget);
  248. Result = true;
  249. }
  250. else
  251. {
  252. assert(false);
  253. Abort();
  254. }
  255. return Result;
  256. }
  257. //---------------------------------------------------------------------------
  258. bool __fastcall TScpCommanderForm::CopyParamDialog(TTransferDirection Direction,
  259. TTransferType Type, bool Temp, TStrings * FileList, UnicodeString & TargetDirectory,
  260. TGUICopyParamType & CopyParam, bool Confirm, bool DragDrop)
  261. {
  262. bool Result = false;
  263. // Temp means d&d here so far, may change in future!
  264. if (Temp && (Direction == tdToLocal) &&
  265. IsFileControl(FDDTargetControl, osLocal))
  266. {
  267. Result = InternalDDDownload(TargetDirectory);
  268. if (Result)
  269. {
  270. assert(FileList->Count > 0);
  271. FInternalDDDownloadList->Assign(FileList);
  272. }
  273. }
  274. else if (!Temp && TargetDirectory.IsEmpty())
  275. {
  276. if (Direction == tdToLocal)
  277. {
  278. TargetDirectory = IncludeTrailingBackslash(LocalDirView->Path);
  279. }
  280. else
  281. {
  282. TargetDirectory = UnixIncludeTrailingBackslash(RemoteDirView->Path);
  283. }
  284. }
  285. if (!Result)
  286. {
  287. Result = TCustomScpExplorerForm::CopyParamDialog(Direction, Type, Temp,
  288. FileList, TargetDirectory, CopyParam, Confirm, DragDrop);
  289. }
  290. return Result;
  291. }
  292. //---------------------------------------------------------------------------
  293. void __fastcall TScpCommanderForm::DoShow()
  294. {
  295. ActiveControl = (WinConfiguration->ScpCommander.CurrentPanel == osLocal ?
  296. (TCustomDirView *)LocalDirView : (TCustomDirView *)RemoteDirView);
  297. TCustomScpExplorerForm::DoShow();
  298. UpdateControls();
  299. }
  300. //---------------------------------------------------------------------------
  301. Boolean __fastcall TScpCommanderForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  302. {
  303. #define FLAG ((TActionFlag)(Action->Tag))
  304. return
  305. // always require Commander flag
  306. (FLAG & afCommander) &&
  307. // if action is execution or update, we don't require any other flag
  308. // if we check for shortcut, we require proper dirview to be selected
  309. ((Allowed != aaShortCut) ||
  310. ((FLAG & afLocal) && (FCurrentSide == osLocal)) ||
  311. ((FLAG & afRemote) && (FCurrentSide == osRemote))
  312. );
  313. #undef FLAG
  314. }
  315. //---------------------------------------------------------------------------
  316. TCustomDirView * __fastcall TScpCommanderForm::DirView(TOperationSide Side)
  317. {
  318. Side = GetSide(Side);
  319. if (Side == osLocal)
  320. {
  321. return LocalDirView;
  322. }
  323. else
  324. {
  325. return TCustomScpExplorerForm::DirView(Side);
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. bool __fastcall TScpCommanderForm::IsFileControl(TObject * Control,
  330. TOperationSide Side)
  331. {
  332. return
  333. ((Side == osLocal) &&
  334. ((Control == LocalDirView) || (Control == LocalDriveView))) ||
  335. TCustomScpExplorerForm::IsFileControl(Control, Side);
  336. }
  337. //---------------------------------------------------------------------------
  338. void __fastcall TScpCommanderForm::ReloadLocalDirectory(const UnicodeString Directory)
  339. {
  340. if (Directory.IsEmpty() || ComparePaths(Directory, LocalDirView->Path))
  341. {
  342. LocalDirView->ReloadDirectory();
  343. LocalDriveView->ValidateDirectory(LocalDriveView->Selected);
  344. }
  345. TCustomScpExplorerForm::ReloadLocalDirectory();
  346. }
  347. //---------------------------------------------------------------------------
  348. void __fastcall TScpCommanderForm::BatchStart(void *& Storage)
  349. {
  350. Storage = new bool;
  351. *static_cast<bool*>(Storage) = LocalDirView->WatchForChanges;
  352. LocalDirView->WatchForChanges = false;
  353. LocalDriveView->WatchDirectory = false;
  354. TCustomScpExplorerForm::BatchStart(Storage);
  355. }
  356. //---------------------------------------------------------------------------
  357. void __fastcall TScpCommanderForm::BatchEnd(void * Storage)
  358. {
  359. TCustomScpExplorerForm::BatchEnd(Storage);
  360. assert(Storage != NULL);
  361. LocalDirView->WatchForChanges = *static_cast<bool*>(Storage);
  362. LocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  363. delete Storage;
  364. }
  365. //---------------------------------------------------------------------------
  366. void __fastcall TScpCommanderForm::TerminalChanged()
  367. {
  368. if (Terminal)
  369. {
  370. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  371. TCustomScpExplorerForm::TerminalChanged();
  372. // we will load completelly different directory, so particularly
  373. // do not attempt to select previously selected directory
  374. LocalDirView->ContinueSession(false);
  375. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  376. assert(ManagedTerminal != NULL);
  377. // reset home directory
  378. LocalDirView->HomeDirectory = L"";
  379. if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  380. {
  381. UnicodeString LocalDirectory = ManagedTerminal->LocalDirectory;
  382. bool DocumentsDir = LocalDirectory.IsEmpty();
  383. if (!DocumentsDir)
  384. {
  385. try
  386. {
  387. LocalDirView->Path = LocalDirectory;
  388. }
  389. catch(Exception & E)
  390. {
  391. DocumentsDir = true;
  392. Terminal->ShowExtendedException(&E);
  393. }
  394. }
  395. if (DocumentsDir)
  396. {
  397. try
  398. {
  399. LocalDirView->HomeDirectory = L"";
  400. LocalDirView->ExecuteHomeDirectory();
  401. }
  402. catch(Exception & E)
  403. {
  404. Terminal->ShowExtendedException(&E);
  405. LocalDirView->Path = ExtractFilePath(Application->ExeName);
  406. }
  407. }
  408. }
  409. FFirstTerminal = false;
  410. if (WinConfiguration->DefaultDirIsHome &&
  411. !Terminal->SessionData->UpdateDirectories)
  412. {
  413. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  414. }
  415. if (WinConfiguration->PreservePanelState &&
  416. !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  417. {
  418. if (ManagedTerminal->LocalExplorerState != NULL)
  419. {
  420. LocalDirView->RestoreState(ManagedTerminal->LocalExplorerState);
  421. }
  422. else
  423. {
  424. LocalDirView->ClearState();
  425. }
  426. NonVisualDataModule->SynchronizeBrowsingAction->Checked = ManagedTerminal->SynchronizeBrowsing;
  427. }
  428. }
  429. else
  430. {
  431. TCustomScpExplorerForm::TerminalChanged();
  432. }
  433. }
  434. //---------------------------------------------------------------------------
  435. void __fastcall TScpCommanderForm::ConfigurationChanged()
  436. {
  437. TCustomScpExplorerForm::ConfigurationChanged();
  438. if (WinConfiguration->DefaultDirIsHome && Terminal &&
  439. !Terminal->SessionData->UpdateDirectories)
  440. {
  441. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  442. }
  443. else
  444. {
  445. LocalDirView->HomeDirectory = L"";
  446. }
  447. LocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  448. LocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  449. LocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  450. LocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  451. LocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  452. LocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  453. LocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  454. LocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  455. RemoteDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  456. if (LocalDirView->RowSelect != WinConfiguration->FullRowSelect)
  457. {
  458. LocalDirView->RowSelect = WinConfiguration->FullRowSelect;
  459. // selection is not redrawn automatically when RowSelect changes
  460. LocalDirView->Invalidate();
  461. }
  462. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler =
  463. !WinConfiguration->DDExtEnabled;
  464. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler =
  465. !WinConfiguration->DDExtEnabled;
  466. if ((LocalPanel->Left > RemotePanel->Left) != WinConfiguration->ScpCommander.SwappedPanels)
  467. {
  468. int AWidth = ClientWidth;
  469. Panel(false)->Align = alClient;
  470. Panel(true)->Align = alLeft;
  471. TControl * ControlsOrder[] =
  472. { Panel(true), Splitter, Panel(false) };
  473. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  474. Panel(true)->TabOrder = 0;
  475. Panel(false)->TabOrder = 1;
  476. ClientWidth = AWidth;
  477. LeftPanelWidth = FLastLeftPanelWidth;
  478. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  479. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  480. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  481. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  482. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  483. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction->ShortCut,
  484. NonVisualDataModule->RemoteChangePathAction->ShortCut);
  485. }
  486. if ((RemoteDriveView->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  487. {
  488. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  489. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  490. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  491. // save value only is it was set yet
  492. if (FPanelsRestored)
  493. {
  494. if (TreeOnLeft)
  495. {
  496. // want to be on left, so it is on top, saving height
  497. LocalPanel.DriveViewHeight = LocalDriveView->Height;
  498. RemotePanel.DriveViewHeight = RemoteDriveView->Height;
  499. }
  500. else
  501. {
  502. LocalPanel.DriveViewWidth = LocalDriveView->Width;
  503. RemotePanel.DriveViewWidth = RemoteDriveView->Width;
  504. }
  505. }
  506. TAlign NonClientAlign = (TreeOnLeft ? alLeft : alTop);
  507. LocalDriveView->Align = NonClientAlign;
  508. LocalPanelSplitter->Align = NonClientAlign;
  509. RemoteDriveView->Align = NonClientAlign;
  510. RemotePanelSplitter->Align = NonClientAlign;
  511. FixControlsPlacement();
  512. if (TreeOnLeft)
  513. {
  514. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  515. RemoteDriveView->Width = RemotePanel.DriveViewWidth;
  516. }
  517. else
  518. {
  519. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  520. RemoteDriveView->Height = RemotePanel.DriveViewHeight;
  521. }
  522. // in case it trigges config-changed event (does not),
  523. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  524. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  525. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  526. }
  527. }
  528. //---------------------------------------------------------------------------
  529. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  530. {
  531. return (WinConfiguration->ScpCommander.SwappedPanels == Left ?
  532. RemotePanel : LocalPanel);
  533. }
  534. //---------------------------------------------------------------------------
  535. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  536. {
  537. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  538. }
  539. //---------------------------------------------------------------------------
  540. void __fastcall TScpCommanderForm::SetLeftPanelWidth(double value)
  541. {
  542. double Total = LocalPanel->Width + RemotePanel->Width;
  543. FLeftPanelWidth = value;
  544. if (value * Total != Panel(true)->Width)
  545. {
  546. Panel(true)->Width = static_cast<int>(value * Total);
  547. UpdateControls();
  548. }
  549. }
  550. //---------------------------------------------------------------------------
  551. double __fastcall TScpCommanderForm::GetLeftPanelWidth()
  552. {
  553. return FLeftPanelWidth;
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  557. {
  558. double Left = Panel(true)->Width;
  559. double Total = LocalPanel->Width + RemotePanel->Width;
  560. FLeftPanelWidth = Left / Total;
  561. FLastLeftPanelWidth = LeftPanelWidth;
  562. UpdateControls();
  563. }
  564. //---------------------------------------------------------------------------
  565. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  566. int &NewSize, bool & /*Accept*/)
  567. {
  568. // When splitter is drag so far to right, that width contraint of remote panel would
  569. // be violated, it doesn't stop, but extend form width.
  570. // Following prevents this behaviour.
  571. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  572. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  576. {
  577. LeftPanelWidth = 0.5;
  578. }
  579. //---------------------------------------------------------------------------
  580. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  581. {
  582. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  583. assert(Splitter != NULL);
  584. TCustomDriveView * DriveView;
  585. TCustomDriveView * OtherDriveView;
  586. if (Splitter == LocalPanelSplitter)
  587. {
  588. DriveView = LocalDriveView;
  589. OtherDriveView = RemoteDriveView;
  590. }
  591. else
  592. {
  593. DriveView = RemoteDriveView;
  594. OtherDriveView = LocalDriveView;
  595. }
  596. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  597. assert(DriveView->Visible);
  598. if (OtherDriveView->Visible)
  599. {
  600. if (TreeOnLeft)
  601. {
  602. DriveView->Width = OtherDriveView->Width;
  603. }
  604. else
  605. {
  606. DriveView->Height = OtherDriveView->Height;
  607. }
  608. }
  609. else
  610. {
  611. if (TreeOnLeft)
  612. {
  613. OtherDriveView->Width = DriveView->Width;
  614. }
  615. else
  616. {
  617. OtherDriveView->Height = DriveView->Height;
  618. }
  619. OtherDriveView->Visible = true;
  620. }
  621. FixControlsPlacement();
  622. }
  623. //---------------------------------------------------------------------------
  624. void __fastcall TScpCommanderForm::UpdateControls()
  625. {
  626. TCustomScpExplorerForm::UpdateControls();
  627. UnicodeString SplitterLongHint = Splitter->Hint;
  628. SplitterLongHint.Delete(1, SplitterLongHint.Pos(L"|"));
  629. Splitter->Hint = FORMAT(L"%0.0f%%|%s", (LeftPanelWidth*100, SplitterLongHint));
  630. UnicodeString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  631. ((FCurrentSide == osRemote) ? L"$" : L">");
  632. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  633. {
  634. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  635. // command line combo width needs to be updated as caption width has probably changed
  636. ToolBarResize(CommandLineToolbar);
  637. }
  638. LocalDirView->Color = (SessionColor != 0 ? SessionColor : clWindow);
  639. LocalDriveView->Color = LocalDirView->Color;
  640. }
  641. //---------------------------------------------------------------------------
  642. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  643. {
  644. assert((Side == osLocal) || (Side == osRemote));
  645. TTBXComboBoxItem * PathComboBox;
  646. if (Side == osLocal)
  647. {
  648. PathComboBox = LocalPathComboBox;
  649. }
  650. else
  651. {
  652. PathComboBox = RemotePathComboBox;
  653. }
  654. ClickToolbarItem(PathComboBox, false);
  655. }
  656. //---------------------------------------------------------------------------
  657. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  658. {
  659. switch (Component) {
  660. case fcToolBar: return ToolbarToolbar;
  661. case fcStatusBar: return StatusBar;
  662. case fcLocalStatusBar: return LocalStatusBar;
  663. case fcRemoteStatusBar: return RemoteStatusBar;
  664. case fcCommandLinePanel: return CommandLineToolbar;
  665. case fcLocalTree: return LocalDriveView;
  666. case fcSessionToolbar: return SessionToolbar;
  667. case fcCustomCommandsBand: return CustomCommandsToolbar;
  668. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  669. case fcColorPalette: return reinterpret_cast<TControl*>(SessionColorPalette);
  670. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  671. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  672. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  673. case fcCommanderMenuBand: return MenuToolbar;
  674. case fcCommanderSessionBand: return SessionToolbar;
  675. case fcCommanderPreferencesBand: return PreferencesToolbar;
  676. case fcCommanderSelectionBand: return SelectionToolbar;
  677. case fcCommanderToolbarBand: return CommandToolbar;
  678. case fcCommanderSortBand: return SortToolbar;
  679. case fcCommanderCommandsBand: return CommandsToolbar;
  680. case fcCommanderUpdatesBand: return UpdatesToolbar;
  681. case fcCommanderTransferBand: return TransferToolbar;
  682. case fcCommanderUploadDownloadBand: return UploadDownloadToolbar;
  683. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  684. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  685. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  686. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  687. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  688. default: return TCustomScpExplorerForm::GetComponent(Component);
  689. }
  690. }
  691. //---------------------------------------------------------------------------
  692. void __fastcall TScpCommanderForm::FixControlsPlacement()
  693. {
  694. TCustomScpExplorerForm::FixControlsPlacement();
  695. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  696. TControl * ControlsOrder[] =
  697. { BottomDock, QueueSplitter, QueuePanel, StatusBar };
  698. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  699. TControl * LocalControlsOrder[] =
  700. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  701. LocalDirView, LocalBottomDock, LocalStatusBar };
  702. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  703. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  704. TControl * RemoteControlsOrder[] =
  705. { RemoteTopDock, RemotePathLabel, RemoteDriveView, RemotePanelSplitter,
  706. RemoteDirView, RemoteBottomDock, RemoteStatusBar };
  707. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  708. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  709. if (LocalDirView->ItemFocused != NULL)
  710. {
  711. LocalDirView->ItemFocused->MakeVisible(false);
  712. }
  713. }
  714. //---------------------------------------------------------------------------
  715. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  716. {
  717. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TScpCommanderForm::CompareDirectories()
  721. {
  722. LocalDirView->CompareFiles(RemoteDirView, false,
  723. WinConfiguration->ScpCommander.CompareCriterias());
  724. RemoteDirView->CompareFiles(LocalDirView, false,
  725. WinConfiguration->ScpCommander.CompareCriterias());
  726. if (LocalDirView->SelCount + RemoteDirView->SelCount == 0)
  727. {
  728. MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
  729. HELP_COMPARE_NO_DIFFERENCES);
  730. }
  731. }
  732. //---------------------------------------------------------------------------
  733. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  734. {
  735. UnicodeString LocalDirectory = LocalDirView->PathName;
  736. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  737. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, false);
  738. }
  739. //---------------------------------------------------------------------------
  740. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  741. {
  742. UnicodeString LocalDirectory = LocalDirView->PathName;
  743. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  744. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  745. TSynchronizeMode Mode =
  746. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  747. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  748. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode,
  749. SaveMode, false))
  750. {
  751. if (SaveMode)
  752. {
  753. GUIConfiguration->SynchronizeModeAuto = Mode;
  754. }
  755. }
  756. }
  757. //---------------------------------------------------------------------------
  758. void __fastcall TScpCommanderForm::ExploreLocalDirectory()
  759. {
  760. if ((int)ShellExecute(Application->Handle, L"explore",
  761. (wchar_t*)LocalDirView->Path.data(), NULL, NULL, SW_SHOWNORMAL) <= 32)
  762. {
  763. throw Exception(FORMAT(EXPLORE_LOCAL_DIR_ERROR, (LocalDirView->Path)));
  764. }
  765. }
  766. //---------------------------------------------------------------------------
  767. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  768. TListItem *Item, bool &AllowExec)
  769. {
  770. assert(Item);
  771. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  772. DirectoryExists(ResolveFileShortCut(LocalDirView->ItemFullFileName(Item), true)))
  773. {
  774. AllowExec = true;
  775. }
  776. else
  777. {
  778. DoDirViewExecFile(Sender, Item, AllowExec);
  779. }
  780. }
  781. //---------------------------------------------------------------------------
  782. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  783. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  784. bool &Accept)
  785. {
  786. // LocalDirViewDDDragEnter is duplication of
  787. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  788. // literal type of 'DataObj' parameter.Actual type is however same
  789. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  790. }
  791. //---------------------------------------------------------------------------
  792. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  793. bool DragDrop)
  794. {
  795. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  796. (DropSourceControl == LocalDirView);
  797. }
  798. //---------------------------------------------------------------------------
  799. void __fastcall TScpCommanderForm::FileOperationProgress(
  800. TFileOperationProgressType & ProgressData, TCancelStatus & Cancel)
  801. {
  802. // Heuristic: When operation finishes and DD targed is local dir view,
  803. // we suppose that drag&drop download finished, so local dir view should be
  804. // reloaded
  805. if (!ProgressData.InProgress && FProgressForm &&
  806. IsFileControl(FDDTargetControl, osLocal) &&
  807. ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
  808. {
  809. ReloadLocalDirectory();
  810. }
  811. TCustomScpExplorerForm::FileOperationProgress(ProgressData, Cancel);
  812. }
  813. //---------------------------------------------------------------------------
  814. UnicodeString __fastcall TScpCommanderForm::ChangeFilePath(UnicodeString Path, TOperationSide Side)
  815. {
  816. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  817. UnicodeString Result;
  818. while (!Path.IsEmpty())
  819. {
  820. int P = Path.Pos(Side == osLocal ? L'\\' : L'/');
  821. if (P > 0)
  822. {
  823. Result += CopyParams.ChangeFileName(Path.SubString(1, P - 1), Side, false) +
  824. (Side == osLocal ? L'/' : L'\\');
  825. Path.Delete(1, P);
  826. }
  827. else
  828. {
  829. Result += CopyParams.ChangeFileName(Path, osLocal, false);
  830. Path = L"";
  831. }
  832. }
  833. return Result;
  834. }
  835. //---------------------------------------------------------------------------
  836. void __fastcall TScpCommanderForm::SynchronizeBrowsingLocal(
  837. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  838. {
  839. Terminal->ExceptionOnFail = true;
  840. TStrings * Paths = new TStringList();
  841. try
  842. {
  843. Paths->Add(IncludeTrailingBackslash(PrevPath));
  844. Paths->Add(IncludeTrailingBackslash(LocalDirView->Path));
  845. UnicodeString CommonPath;
  846. if (ExtractCommonPath(Paths, CommonPath))
  847. {
  848. PrevPath = IncludeTrailingBackslash(PrevPath);
  849. CommonPath = IncludeTrailingBackslash(CommonPath);
  850. NewPath = RemoteDirView->Path;
  851. while (!ComparePaths(PrevPath, CommonPath))
  852. {
  853. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  854. {
  855. Abort();
  856. }
  857. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  858. PrevPath = ExtractFilePath(ExcludeTrailingBackslash(PrevPath));
  859. }
  860. NewPath = UnixIncludeTrailingBackslash(NewPath) +
  861. ToUnixPath(LocalDirView->Path.SubString(PrevPath.Length() + 1,
  862. LocalDirView->Path.Length() - PrevPath.Length()));
  863. }
  864. else
  865. {
  866. Abort();
  867. }
  868. if (Create)
  869. {
  870. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  871. RemoteDirView->CreateDirectoryEx(NewPath, &Properties);
  872. }
  873. RemoteDirView->Path = NewPath;
  874. }
  875. __finally
  876. {
  877. Terminal->ExceptionOnFail = false;
  878. delete Paths;
  879. }
  880. }
  881. //---------------------------------------------------------------------------
  882. void __fastcall TScpCommanderForm::SynchronizeBrowsingRemote(
  883. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  884. {
  885. TStrings * Paths = new TStringList();
  886. try
  887. {
  888. Paths->Add(UnixIncludeTrailingBackslash(PrevPath));
  889. Paths->Add(UnixIncludeTrailingBackslash(RemoteDirView->Path));
  890. UnicodeString CommonPath;
  891. if (UnixExtractCommonPath(Paths, CommonPath))
  892. {
  893. PrevPath = UnixIncludeTrailingBackslash(PrevPath);
  894. CommonPath = UnixIncludeTrailingBackslash(CommonPath);
  895. UnicodeString NewLocalPath;
  896. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  897. while (!UnixComparePaths(PrevPath, CommonPath))
  898. {
  899. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  900. if (NewLocalPath == NewPath)
  901. {
  902. Abort();
  903. }
  904. NewPath = NewLocalPath;
  905. PrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(PrevPath));
  906. }
  907. NewPath = IncludeTrailingBackslash(NewPath) +
  908. ChangeFilePath(
  909. RemoteDirView->Path.SubString(PrevPath.Length() + 1,
  910. RemoteDirView->Path.Length() - PrevPath.Length()),
  911. osRemote);
  912. }
  913. else
  914. {
  915. Abort();
  916. }
  917. }
  918. __finally
  919. {
  920. delete Paths;
  921. }
  922. if (Create)
  923. {
  924. LocalDirView->CreateDirectory(NewPath);
  925. }
  926. LocalDirView->Path = NewPath;
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  930. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  931. {
  932. if (ADirView == LocalDirView)
  933. {
  934. SynchronizeBrowsingLocal(PrevPath, NewPath, Create);
  935. }
  936. else
  937. {
  938. SynchronizeBrowsingRemote(PrevPath, NewPath, Create);
  939. }
  940. }
  941. //---------------------------------------------------------------------------
  942. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  943. {
  944. UnicodeString PrevPath;
  945. // cannot assign to UnicodeString before the class is constructed,
  946. // if we do, the value get lost when UnicodeString constructor gets finally called,
  947. // what results in memory leak in the best case
  948. if (FConstructed)
  949. {
  950. PrevPath = FPrevPath[ADirView == LocalDirView];
  951. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  952. }
  953. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  954. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  955. {
  956. bool PrevAllowTransferPresetAutoSelect = FAllowTransferPresetAutoSelect;
  957. FAllowTransferPresetAutoSelect = false;
  958. FSynchronisingBrowse = true;
  959. try
  960. {
  961. try
  962. {
  963. UnicodeString NewPath;
  964. try
  965. {
  966. SynchronizeBrowsing(ADirView, PrevPath, NewPath, false);
  967. }
  968. // EAbort means that we do not know how to synchronize browsing
  969. // there's no fallback scenario for that
  970. catch(EAbort &)
  971. {
  972. throw;
  973. }
  974. catch(Exception & E)
  975. {
  976. // what does this say?
  977. if (Application->Terminated)
  978. {
  979. throw;
  980. }
  981. else
  982. {
  983. TStrings * MoreMessages = ExceptionToMoreMessages(&E);
  984. try
  985. {
  986. if (MoreMessageDialog(FMTLOAD(SYNC_DIR_BROWSE_CREATE, (NewPath)),
  987. MoreMessages, qtConfirmation, qaYes | qaNo,
  988. HELP_SYNC_DIR_BROWSE_ERROR) == qaYes)
  989. {
  990. try
  991. {
  992. SynchronizeBrowsing(ADirView, PrevPath, NewPath, true);
  993. }
  994. catch(Exception & E)
  995. {
  996. if (!Application->Terminated)
  997. {
  998. Terminal->ShowExtendedException(&E);
  999. }
  1000. throw;
  1001. }
  1002. }
  1003. else
  1004. {
  1005. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1006. }
  1007. }
  1008. __finally
  1009. {
  1010. delete MoreMessages;
  1011. }
  1012. }
  1013. }
  1014. }
  1015. catch(Exception & E)
  1016. {
  1017. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1018. // what does this say?
  1019. if (Application->Terminated)
  1020. {
  1021. throw;
  1022. }
  1023. else
  1024. {
  1025. MessageDialog(LoadStr(SYNC_DIR_BROWSE_ERROR), qtInformation, qaOK,
  1026. HELP_SYNC_DIR_BROWSE_ERROR);
  1027. }
  1028. }
  1029. }
  1030. __finally
  1031. {
  1032. FSynchronisingBrowse = false;
  1033. FAllowTransferPresetAutoSelect = PrevAllowTransferPresetAutoSelect;
  1034. }
  1035. }
  1036. }
  1037. //---------------------------------------------------------------------------
  1038. void __fastcall TScpCommanderForm::DoDirViewLoaded(TCustomDirView * ADirView)
  1039. {
  1040. TCustomScpExplorerForm::DoDirViewLoaded(ADirView);
  1041. UpdateControls();
  1042. SynchronizeBrowsing(ADirView);
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. void __fastcall TScpCommanderForm::AddEditLink(bool Add)
  1046. {
  1047. if (FCurrentSide == osLocal)
  1048. {
  1049. bool Edit = false;
  1050. UnicodeString FileName;
  1051. UnicodeString PointTo;
  1052. bool SymbolicLink = true;
  1053. if (LocalDirView->ItemFocused)
  1054. {
  1055. assert(LocalDirView->ItemFocused->Data);
  1056. PFileRec FileRec = (PFileRec)LocalDirView->ItemFocused->Data;
  1057. Edit = !Add && (UpperCase(FileRec->FileExt) == L"LNK");
  1058. if (Edit)
  1059. {
  1060. UnicodeString FullName = LocalDirView->ItemFullFileName(LocalDirView->ItemFocused);
  1061. FileName = FullName;
  1062. PointTo = ResolveFileShortCut(FullName, false);
  1063. if (PointTo.IsEmpty())
  1064. {
  1065. throw Exception(FMTLOAD(RESOLVE_SHORTCUT_ERROR, (FullName)));
  1066. }
  1067. }
  1068. else
  1069. {
  1070. PointTo = FileRec->FileName;
  1071. }
  1072. }
  1073. if (DoSymlinkDialog(FileName, PointTo, osLocal, SymbolicLink, Edit, false))
  1074. {
  1075. assert(SymbolicLink);
  1076. assert(!FileName.IsEmpty());
  1077. assert(!PointTo.IsEmpty());
  1078. if (ExtractFileDrive(FileName) == L"" && FileName[1] != L'\\')
  1079. {
  1080. FileName = IncludeTrailingBackslash(LocalDirView->PathName) + FileName;
  1081. }
  1082. if (ExtractFileDrive(PointTo) == L"" && PointTo[1] != L'\\')
  1083. {
  1084. PointTo = IncludeTrailingBackslash(LocalDirView->PathName) + PointTo;
  1085. }
  1086. if (ExtractFileExt(FileName) == L"")
  1087. {
  1088. FileName = FileName + L".lnk";
  1089. }
  1090. if (Edit && !DeleteFile(FileName))
  1091. {
  1092. throw Exception(FMTLOAD(DELETE_LOCAL_FILE_ERROR, (FileName)));
  1093. }
  1094. if (!CreateFileShortCut(PointTo, FileName, L""))
  1095. {
  1096. throw Exception(CREATE_SHORTCUT_ERROR);
  1097. }
  1098. }
  1099. }
  1100. else
  1101. {
  1102. TCustomScpExplorerForm::AddEditLink(Add);
  1103. }
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void __fastcall TScpCommanderForm::DoOpenDirectoryDialog(TOpenDirectoryMode Mode,
  1107. TOperationSide Side)
  1108. {
  1109. bool UseLocationProfiles;
  1110. do
  1111. {
  1112. UseLocationProfiles = WinConfiguration->UseLocationProfiles;
  1113. if (UseLocationProfiles)
  1114. {
  1115. TStrings * LocalDirectories = NULL;
  1116. TStrings * RemoteDirectories = NULL;
  1117. try
  1118. {
  1119. LocalDirectories = CreateVisitedDirectories(osLocal);
  1120. RemoteDirectories = CreateVisitedDirectories(osRemote);
  1121. UnicodeString Local = LocalDirView->PathName;
  1122. UnicodeString Remote = RemoteDirView->PathName;
  1123. if (LocationProfilesDialog(Mode, Side, Local, Remote, LocalDirectories,
  1124. RemoteDirectories, Terminal))
  1125. {
  1126. DoOpenBookmark(Local, Remote);
  1127. }
  1128. }
  1129. __finally
  1130. {
  1131. delete LocalDirectories;
  1132. delete RemoteDirectories;
  1133. }
  1134. }
  1135. else
  1136. {
  1137. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1138. TCustomScpExplorerForm::DoOpenDirectoryDialog(Mode, Side);
  1139. }
  1140. // for second and further rounds, always do browse only
  1141. Mode = odBrowse;
  1142. }
  1143. while (UseLocationProfiles != WinConfiguration->UseLocationProfiles);
  1144. }
  1145. //---------------------------------------------------------------------------
  1146. void __fastcall TScpCommanderForm::DoOpenBookmark(UnicodeString Local, UnicodeString Remote)
  1147. {
  1148. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1149. // make sure that whatever path is valid it is opened first and only
  1150. // after that an eventual error is reported
  1151. try
  1152. {
  1153. if (!Local.IsEmpty())
  1154. {
  1155. LocalDirView->Path = Local;
  1156. }
  1157. }
  1158. __finally
  1159. {
  1160. if (!Remote.IsEmpty())
  1161. {
  1162. RemoteDirView->Path = Remote;
  1163. }
  1164. }
  1165. }
  1166. //---------------------------------------------------------------------------
  1167. bool __fastcall TScpCommanderForm::OpenBookmark(UnicodeString Local, UnicodeString Remote)
  1168. {
  1169. bool Result;
  1170. if (WinConfiguration->UseLocationProfiles)
  1171. {
  1172. DoOpenBookmark(Local, Remote);
  1173. Result = true;
  1174. }
  1175. else
  1176. {
  1177. Result = TCustomScpExplorerForm::OpenBookmark(Local, Remote);
  1178. }
  1179. return Result;
  1180. }
  1181. //---------------------------------------------------------------------------
  1182. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1183. TObject * /*Sender*/, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1184. {
  1185. // when drop target is not directory, it is probably file type, which have
  1186. // associated drop handler (such as ZIP file in WinXP). in this case we
  1187. // cannot allow downloading when using shellex.
  1188. // ! this check is duplicated in InternalDDDownload() for non-shellex downloads
  1189. if ((FDDExtMapFile != NULL) &&
  1190. !LocalDirView->ItemIsDirectory(Item))
  1191. {
  1192. DropHandler = false;
  1193. }
  1194. }
  1195. //---------------------------------------------------------------------------
  1196. void __fastcall TScpCommanderForm::LocalFileControlDDDragOver(TObject * /*Sender*/,
  1197. int grfKeyState, TPoint & /*Point*/, int & dwEffect)
  1198. {
  1199. if (IsFileControl(DropSourceControl, osRemote))
  1200. {
  1201. if (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == 0) ||
  1202. (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == MK_SHIFT) &&
  1203. !WinConfiguration->DDAllowMoveInit))
  1204. {
  1205. dwEffect = DROPEFFECT_Copy;
  1206. }
  1207. }
  1208. }
  1209. //---------------------------------------------------------------------------
  1210. bool __fastcall TScpCommanderForm::DDGetTarget(UnicodeString & Directory, bool & Internal)
  1211. {
  1212. bool Result;
  1213. if (!FDDExtTarget.IsEmpty())
  1214. {
  1215. Directory = FDDExtTarget;
  1216. FDDExtTarget = L"";
  1217. Result = true;
  1218. Internal = true;
  1219. }
  1220. else
  1221. {
  1222. Result = TCustomScpExplorerForm::DDGetTarget(Directory, Internal);
  1223. }
  1224. return Result;
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. void __fastcall TScpCommanderForm::DDExtInitDrag(TFileList * FileList,
  1228. bool & Created)
  1229. {
  1230. FDDExtTarget = L"";
  1231. TCustomScpExplorerForm::DDExtInitDrag(FileList, Created);
  1232. }
  1233. //---------------------------------------------------------------------------
  1234. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1235. TObject * /*Sender*/, int dwEffect, UnicodeString SourcePath,
  1236. UnicodeString TargetPath, bool & DoOperation)
  1237. {
  1238. if (IsFileControl(DropSourceControl, osRemote))
  1239. {
  1240. UnicodeString TargetDirectory;
  1241. if (InternalDDDownload(TargetDirectory))
  1242. {
  1243. if (FDDExtMapFile != NULL)
  1244. {
  1245. FDDExtTarget = TargetDirectory;
  1246. }
  1247. else
  1248. {
  1249. assert(FInternalDDDownloadList->Count > 0);
  1250. assert(dwEffect == DROPEFFECT_Copy || dwEffect == DROPEFFECT_Move);
  1251. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1252. TTransferType TransferType = dwEffect == DROPEFFECT_Copy ? ttCopy : ttMove;
  1253. if (FDDMoveSlipped)
  1254. {
  1255. TransferType = ttMove;
  1256. }
  1257. if (CopyParamDialog(tdToLocal, TransferType,
  1258. false, FInternalDDDownloadList, TargetDirectory, CopyParams,
  1259. WinConfiguration->DDTransferConfirmation, true))
  1260. {
  1261. int Params =
  1262. (TransferType == ttMove ? cpDelete : 0) |
  1263. (CopyParams.NewerOnly ? cpNewerOnly : 0);
  1264. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1265. &CopyParams, Params);
  1266. Configuration->Usage->Inc(L"DownloadsDragDropInternal");
  1267. FInternalDDDownloadList->Clear();
  1268. }
  1269. }
  1270. DoOperation = false;
  1271. }
  1272. }
  1273. }
  1274. //---------------------------------------------------------------------------
  1275. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1276. TObject * /*Sender*/, int dwEffect, UnicodeString /*SourcePath*/,
  1277. UnicodeString /*TargetPath*/)
  1278. {
  1279. if ((dwEffect == DROPEFFECT_Move) &&
  1280. IsFileControl(DropSourceControl, osLocal))
  1281. {
  1282. ReloadLocalDirectory();
  1283. }
  1284. }
  1285. //---------------------------------------------------------------------------
  1286. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1287. {
  1288. SideEnter(osLocal);
  1289. }
  1290. //---------------------------------------------------------------------------
  1291. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1292. {
  1293. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1294. SideEnter(osLocal);
  1295. }
  1296. //---------------------------------------------------------------------------
  1297. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1298. {
  1299. if (Visible && (FCurrentSide != Side))
  1300. {
  1301. // this may get called yet before controls are initialized
  1302. CommandLineCombo->Strings->Clear();
  1303. FCommandLineComboPopulated = false;
  1304. }
  1305. TCustomScpExplorerForm::SideEnter(Side);
  1306. if (Visible)
  1307. {
  1308. UpdateControls();
  1309. LocalPathLabel->UpdateStatus();
  1310. RemotePathLabel->UpdateStatus();
  1311. }
  1312. }
  1313. //---------------------------------------------------------------------------
  1314. void __fastcall TScpCommanderForm::OpenConsole(UnicodeString Command)
  1315. {
  1316. SaveCommandLine();
  1317. try
  1318. {
  1319. TCustomScpExplorerForm::OpenConsole(Command);
  1320. }
  1321. __finally
  1322. {
  1323. FCommandLineComboPopulated = false;
  1324. }
  1325. }
  1326. //---------------------------------------------------------------------------
  1327. void __fastcall TScpCommanderForm::SaveCommandLine()
  1328. {
  1329. if (FCommandLineComboPopulated)
  1330. {
  1331. CustomWinConfiguration->History[
  1332. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"] =
  1333. CommandLineCombo->Strings;
  1334. }
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. bool __fastcall TScpCommanderForm::ExecuteCommandLine()
  1338. {
  1339. UnicodeString Command = CommandLineCombo->Text;
  1340. bool Result =
  1341. !Command.IsEmpty() &&
  1342. ((FCurrentSide != osRemote) ||
  1343. (Terminal->AllowedAnyCommand(Command) &&
  1344. EnsureCommandSessionFallback(fcAnyCommand)));
  1345. if (Result)
  1346. {
  1347. CommandLinePopulate();
  1348. SaveToHistory(CommandLineCombo->Strings, Command);
  1349. CommandLineCombo->Text = L"";
  1350. if (FCurrentSide == osRemote)
  1351. {
  1352. OpenConsole(Command);
  1353. }
  1354. else
  1355. {
  1356. UnicodeString Program, Params, Dir;
  1357. SplitCommand(Command, Program, Params, Dir);
  1358. if (!ExecuteShell(Program, Params))
  1359. {
  1360. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
  1361. }
  1362. }
  1363. }
  1364. return Result;
  1365. }
  1366. //---------------------------------------------------------------------------
  1367. void __fastcall TScpCommanderForm::CommandLinePopulate()
  1368. {
  1369. if (!FCommandLineComboPopulated)
  1370. {
  1371. TStrings * CommandsHistory;
  1372. CommandsHistory = CustomWinConfiguration->History[
  1373. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"];
  1374. if ((CommandsHistory != NULL) && (CommandsHistory->Count > 0))
  1375. {
  1376. CommandLineCombo->Strings = CommandsHistory;
  1377. }
  1378. else
  1379. {
  1380. CommandLineCombo->Strings->Clear();
  1381. }
  1382. FCommandLineComboPopulated = true;
  1383. }
  1384. }
  1385. //---------------------------------------------------------------------------
  1386. void __fastcall TScpCommanderForm::GoToCommandLine()
  1387. {
  1388. ComponentVisible[fcCommandLinePanel] = true;
  1389. if (CommandLineCombo->Enabled)
  1390. {
  1391. ClickToolbarItem(CommandLineCombo, true);
  1392. }
  1393. }
  1394. //---------------------------------------------------------------------------
  1395. void __fastcall TScpCommanderForm::GoToTree()
  1396. {
  1397. if (FCurrentSide == osLocal)
  1398. {
  1399. ComponentVisible[fcLocalTree] = true;
  1400. LocalDriveView->SetFocus();
  1401. }
  1402. else
  1403. {
  1404. TCustomScpExplorerForm::GoToTree();
  1405. }
  1406. }
  1407. //---------------------------------------------------------------------------
  1408. void __fastcall TScpCommanderForm::PanelExportStore(TOperationSide Side,
  1409. TPanelExport Export, TPanelExportDestination Destination,
  1410. TStringList * ExportData)
  1411. {
  1412. if (Destination == pedCommandLine)
  1413. {
  1414. ComponentVisible[fcCommandLinePanel] = true;
  1415. UnicodeString Buf;
  1416. for (int Index = 0; Index < ExportData->Count; Index++)
  1417. {
  1418. Buf += ExportData->Strings[Index] + L" ";
  1419. }
  1420. CommandLineCombo->Text = CommandLineCombo->Text + Buf;
  1421. }
  1422. else
  1423. {
  1424. TCustomScpExplorerForm::PanelExportStore(Side, Export, Destination, ExportData);
  1425. }
  1426. }
  1427. //---------------------------------------------------------------------------
  1428. int __fastcall TScpCommanderForm::GetStaticComponentsHeight()
  1429. {
  1430. return TCustomScpExplorerForm::GetStaticComponentsHeight() +
  1431. (BottomDock->Visible ? BottomDock->Height : 0) +
  1432. (StatusBar->Visible ? StatusBar->Height : 0);
  1433. }
  1434. //---------------------------------------------------------------------------
  1435. void __fastcall TScpCommanderForm::SysResizing(unsigned int Cmd)
  1436. {
  1437. TCustomScpExplorerForm::SysResizing(Cmd);
  1438. if ((Cmd == SC_MAXIMIZE) ||
  1439. ((Cmd == SC_DEFAULT) && (WindowState != wsMaximized)))
  1440. {
  1441. FNormalPanelsWidth = LocalPanel->Width + RemotePanel->Width;
  1442. }
  1443. else if ((Cmd == SC_RESTORE) ||
  1444. ((Cmd == SC_DEFAULT) && (WindowState == wsMaximized)))
  1445. {
  1446. if (FNormalPanelsWidth >= 0)
  1447. {
  1448. Panel(true)->Width = static_cast<int>(FLeftPanelWidth * FNormalPanelsWidth);
  1449. FNormalPanelsWidth = -1;
  1450. }
  1451. }
  1452. }
  1453. //---------------------------------------------------------------------------
  1454. void __fastcall TScpCommanderForm::Resize()
  1455. {
  1456. TCustomScpExplorerForm::Resize();
  1457. LeftPanelWidth = FLastLeftPanelWidth;
  1458. UpdateControls();
  1459. }
  1460. //---------------------------------------------------------------------------
  1461. void __fastcall TScpCommanderForm::LocalFileControlDDMenuPopup(TObject * /*Sender*/,
  1462. HMENU AMenu, IDataObject * /*DataObj*/, int /*AMinCustCmd*/, int /*grfKeyState*/,
  1463. TPoint & /*pt*/)
  1464. {
  1465. if (IsFileControl(DropSourceControl, osRemote) &&
  1466. !WinConfiguration->DDAllowMoveInit)
  1467. {
  1468. // index of copy item
  1469. int Index = GetMenuDefaultItem(AMenu, TRUE, 0);
  1470. assert(Index >= 0);
  1471. UnicodeString Caption = Dragdrop_MIMoveStr;
  1472. MENUITEMINFO MI;
  1473. memset(&MI, 0, sizeof(MI));
  1474. MI.cbSize = sizeof(MI);
  1475. MI.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
  1476. MI.fType = MFT_STRING;
  1477. MI.wID = 1 /*DragDrop::CmdMove*/;
  1478. MI.dwTypeData = Caption.c_str();
  1479. MI.cch = Caption.Length();
  1480. MI.fState = MFS_ENABLED;
  1481. InsertMenuItem(AMenu, Index, TRUE, &MI);
  1482. if (FDDMoveSlipped)
  1483. {
  1484. SetMenuDefaultItem(AMenu, Index, TRUE);
  1485. }
  1486. FDDMoveSlipped = false;
  1487. }
  1488. }
  1489. //---------------------------------------------------------------------------
  1490. void __fastcall TScpCommanderForm::PathLabelDblClick(TObject * Sender)
  1491. {
  1492. OpenDirectory(Sender == LocalPathLabel ? osLocal : osRemote);
  1493. }
  1494. //---------------------------------------------------------------------------
  1495. void __fastcall TScpCommanderForm::LocalPathLabelGetStatus(
  1496. TCustomPathLabel * /*Sender*/, bool & Active)
  1497. {
  1498. // this strange form is here to make borland compiler work :-)
  1499. Active = Active || LocalDriveView->Focused();
  1500. }
  1501. //---------------------------------------------------------------------------
  1502. void __fastcall TScpCommanderForm::RemotePathLabelGetStatus(
  1503. TCustomPathLabel * /*Sender*/, bool & Active)
  1504. {
  1505. // this strange form is here to make borland compiler work :-)
  1506. Active = Active || RemoteDriveView->Focused();
  1507. }
  1508. //---------------------------------------------------------------------------
  1509. void __fastcall TScpCommanderForm::LocalPathLabelPathClick(
  1510. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1511. {
  1512. if (ComparePaths(Path, LocalDirView->Path))
  1513. {
  1514. OpenDirectory(osLocal);
  1515. }
  1516. else
  1517. {
  1518. LocalDirView->Path = Path;
  1519. }
  1520. }
  1521. //---------------------------------------------------------------------------
  1522. void __fastcall TScpCommanderForm::RemotePathLabelPathClick(
  1523. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1524. {
  1525. if (UnixComparePaths(Path, RemoteDirView->Path))
  1526. {
  1527. OpenDirectory(osRemote);
  1528. }
  1529. else
  1530. {
  1531. RemoteDirView->Path = Path;
  1532. }
  1533. }
  1534. //---------------------------------------------------------------------------
  1535. void __fastcall TScpCommanderForm::LocalDirViewFileIconForName(
  1536. TObject * /*Sender*/, TListItem * /*Item*/, UnicodeString & FileName)
  1537. {
  1538. UnicodeString PartialExt = Configuration->PartialExt;
  1539. if (AnsiSameText(ExtractFileExt(FileName), PartialExt))
  1540. {
  1541. FileName.SetLength(FileName.Length() - PartialExt.Length());
  1542. }
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. void __fastcall TScpCommanderForm::LocalDirViewUpdateStatusBar(
  1546. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1547. {
  1548. UpdateFileStatusBar(LocalStatusBar, FileInfo, 0);
  1549. }
  1550. //---------------------------------------------------------------------------
  1551. void __fastcall TScpCommanderForm::RemoteDirViewUpdateStatusBar(
  1552. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1553. {
  1554. UpdateFileStatusBar(RemoteStatusBar, FileInfo, 0);
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. void __fastcall TScpCommanderForm::LocalStatusBarClick(TObject * /*Sender*/)
  1558. {
  1559. LocalDirView->SetFocus();
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. UnicodeString __fastcall TScpCommanderForm::PathForCaption()
  1563. {
  1564. UnicodeString Result;
  1565. if (FCurrentSide == osLocal)
  1566. {
  1567. // for consistency do not show even local path when there is no terminal
  1568. if (Terminal != NULL)
  1569. {
  1570. switch (WinConfiguration->PathInCaption)
  1571. {
  1572. case picShort:
  1573. {
  1574. Result = ExtractFileName(LocalDirView->PathName);
  1575. if (Result.IsEmpty())
  1576. {
  1577. Result = LocalDirView->PathName;
  1578. }
  1579. }
  1580. break;
  1581. case picFull:
  1582. Result = LocalDirView->PathName;
  1583. break;
  1584. }
  1585. }
  1586. }
  1587. else
  1588. {
  1589. Result = TCustomScpExplorerForm::PathForCaption();
  1590. }
  1591. return Result;
  1592. }
  1593. //---------------------------------------------------------------------------
  1594. void __fastcall TScpCommanderForm::GetTransferPresetAutoSelectData(
  1595. TCopyParamRuleData & Data)
  1596. {
  1597. TCustomScpExplorerForm::GetTransferPresetAutoSelectData(Data);
  1598. Data.LocalDirectory = LocalDirView->PathName;
  1599. }
  1600. //---------------------------------------------------------------------------
  1601. void __fastcall TScpCommanderForm::BeforeAction()
  1602. {
  1603. TCustomScpExplorerForm::BeforeAction();
  1604. if (LocalDirView->ItemFocused != NULL)
  1605. {
  1606. LocalDirView->ItemFocused->CancelEdit();
  1607. }
  1608. }
  1609. //---------------------------------------------------------------------------
  1610. void __fastcall TScpCommanderForm::RemoteDirViewPathChange(TCustomDirView * /*Sender*/)
  1611. {
  1612. UpdateRemotePathComboBox(RemotePathComboBox, false);
  1613. }
  1614. //---------------------------------------------------------------------------
  1615. void __fastcall TScpCommanderForm::LocalPathComboUpdateDrives()
  1616. {
  1617. TStrings* Strings = LocalPathComboBox->Strings;
  1618. Strings->BeginUpdate();
  1619. try
  1620. {
  1621. Strings->Clear();
  1622. FLocalPathComboBoxPaths->Clear();
  1623. Strings->Add(LoadStr(SPECIAL_FOLDER_MY_DOCUMENTS));
  1624. FLocalPathComboBoxPaths->AddObject(DriveInfo->SpecialFolder[CSIDL_PERSONAL]->Location,
  1625. (TObject *)DriveInfo->SpecialFolder[CSIDL_PERSONAL]->ImageIndex);
  1626. Strings->Add(LoadStr(SPECIAL_FOLDER_DESKTOP));
  1627. FLocalPathComboBoxPaths->AddObject(DriveInfo->SpecialFolder[CSIDL_DESKTOP]->Location,
  1628. (TObject *)DriveInfo->SpecialFolder[CSIDL_DESKTOP]->ImageIndex);
  1629. for (TDrive Drive = FirstDrive; Drive <= LastDrive; Drive++)
  1630. {
  1631. if (DriveInfo->Data[Drive]->Valid)
  1632. {
  1633. Strings->Add(UnicodeString(L"&") + DriveInfo->GetPrettyName(Drive));
  1634. FLocalPathComboBoxPaths->AddObject(UnicodeString(Drive) + L":\\",
  1635. (TObject *)DriveInfo->GetImageIndex(Drive));
  1636. }
  1637. }
  1638. }
  1639. __finally
  1640. {
  1641. Strings->EndUpdate();
  1642. }
  1643. }
  1644. //---------------------------------------------------------------------------
  1645. void __fastcall TScpCommanderForm::LocalPathComboUpdate()
  1646. {
  1647. // this may get called even after destructor finishes
  1648. // (e.g. from SetDockAllowDrag invoked [indirectly] from StoreParams)
  1649. if (FLocalPathComboBoxPaths != NULL)
  1650. {
  1651. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1652. int Index = 0;
  1653. while ((Index < FLocalPathComboBoxPaths->Count) &&
  1654. !ComparePaths(FLocalPathComboBoxPaths->Strings[Index],
  1655. LocalDirView->Path.SubString(1, FLocalPathComboBoxPaths->Strings[Index].Length())))
  1656. {
  1657. Index++;
  1658. }
  1659. // what to do if not?
  1660. if (Index < FLocalPathComboBoxPaths->Count)
  1661. {
  1662. LocalPathComboBox->ItemIndex = Index;
  1663. }
  1664. }
  1665. }
  1666. //---------------------------------------------------------------------------
  1667. void __fastcall TScpCommanderForm::LocalDirViewPathChange(TCustomDirView * /*Sender*/)
  1668. {
  1669. LocalPathComboUpdate();
  1670. }
  1671. //---------------------------------------------------------------------------
  1672. void __fastcall TScpCommanderForm::LocalPathComboBoxCancel(TObject * /*Sender*/)
  1673. {
  1674. LocalPathComboUpdate();
  1675. }
  1676. //---------------------------------------------------------------------------
  1677. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  1678. TTBXComboBoxItem * /*Sender*/, const UnicodeString AText, int AIndex,
  1679. int & ImageIndex)
  1680. {
  1681. // this may get called even before constructor starts
  1682. // (e.g. from FixControlsPlacement)
  1683. if (FLocalPathComboBoxPaths != NULL)
  1684. {
  1685. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1686. assert(AIndex < FLocalPathComboBoxPaths->Count);
  1687. if (AIndex < 0)
  1688. {
  1689. AIndex = LocalPathComboBox->ItemIndex;
  1690. }
  1691. if (AIndex >= 0)
  1692. {
  1693. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  1694. }
  1695. }
  1696. }
  1697. //---------------------------------------------------------------------------
  1698. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject * /*Sender*/)
  1699. {
  1700. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1701. assert((LocalPathComboBox->ItemIndex >= 0) && (LocalPathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  1702. UnicodeString Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1703. if (Path.Length() == 3)
  1704. {
  1705. LocalDirView->ExecuteDrive(Path[1]);
  1706. }
  1707. else
  1708. {
  1709. LocalDirView->Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1710. }
  1711. }
  1712. //---------------------------------------------------------------------------
  1713. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  1714. {
  1715. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  1716. if ((Item == LocalPathComboBox) ||
  1717. (Item == RemotePathComboBox) ||
  1718. (Item == CommandLineCombo))
  1719. {
  1720. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  1721. }
  1722. }
  1723. //---------------------------------------------------------------------------
  1724. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  1725. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1726. {
  1727. CommandLinePopulate();
  1728. }
  1729. //---------------------------------------------------------------------------
  1730. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  1731. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  1732. {
  1733. InstallPathWordBreakProc(EditControl);
  1734. FCommandLineComboEdit = EditControl;
  1735. FToolbarEditOldWndProc = EditControl->WindowProc;
  1736. EditControl->WindowProc = CommandLineComboEditWndProc;
  1737. }
  1738. //---------------------------------------------------------------------------
  1739. void __fastcall TScpCommanderForm::ExitToolbar()
  1740. {
  1741. CurrentPanel()->SetFocus();
  1742. }
  1743. //---------------------------------------------------------------------------
  1744. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  1745. {
  1746. bool Handled = false;
  1747. if (Message.Msg == WM_CHAR)
  1748. {
  1749. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  1750. {
  1751. case VK_ESCAPE:
  1752. CommandLineCombo->Text = L"";
  1753. ExitToolbar();
  1754. Handled = true;
  1755. break;
  1756. case VK_TAB:
  1757. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1758. ExitToolbar();
  1759. Handled = true;
  1760. break;
  1761. case VK_RETURN:
  1762. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1763. ExitToolbar();
  1764. if (!ExecuteCommandLine())
  1765. {
  1766. // re-enter command line
  1767. // (most probably exited by now as message dialog was shown)
  1768. GoToCommandLine();
  1769. }
  1770. Handled = true;
  1771. break;
  1772. }
  1773. }
  1774. if (!Handled)
  1775. {
  1776. FToolbarEditOldWndProc(Message);
  1777. }
  1778. }
  1779. //---------------------------------------------------------------------------
  1780. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  1781. {
  1782. LocalPathComboUpdateDrives();
  1783. LocalPathComboUpdate();
  1784. }
  1785. //---------------------------------------------------------------------------
  1786. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  1787. {
  1788. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1789. TCustomScpExplorerForm::HomeDirectory(Side);
  1790. }
  1791. //---------------------------------------------------------------------------
  1792. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  1793. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1794. {
  1795. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  1796. }
  1797. //---------------------------------------------------------------------------
  1798. void __fastcall TScpCommanderForm::DoFocusRemotePath(UnicodeString Path)
  1799. {
  1800. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1801. TCustomScpExplorerForm::DoFocusRemotePath(Path);
  1802. }
  1803. //---------------------------------------------------------------------------
  1804. void __fastcall TScpCommanderForm::HistoryGo(TOperationSide Side, int Index)
  1805. {
  1806. TOperationSide OtherSide = ((Side == osLocal) ? osRemote : osLocal);
  1807. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  1808. ((Index < 0) ? (-Index < DirView(OtherSide)->BackCount) : (Index < DirView(OtherSide)->ForwardCount)))
  1809. {
  1810. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1811. TCustomScpExplorerForm::HistoryGo(Side, Index);
  1812. TCustomScpExplorerForm::HistoryGo(OtherSide, Index);
  1813. }
  1814. else
  1815. {
  1816. TCustomScpExplorerForm::HistoryGo(Side, Index);
  1817. }
  1818. }
  1819. //---------------------------------------------------------------------------
  1820. void __fastcall TScpCommanderForm::DirViewHistoryGo(
  1821. TCustomDirView * Sender, int Index, bool & Cancel)
  1822. {
  1823. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1824. HistoryGo(Side, Index);
  1825. Cancel = true;
  1826. }
  1827. //---------------------------------------------------------------------------