ScpCommander.cpp 70 KB

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