ScpCommander.cpp 65 KB

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