ScpCommander.cpp 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056
  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. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler =
  470. !WinConfiguration->DDExtEnabled;
  471. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler =
  472. !WinConfiguration->DDExtEnabled;
  473. if ((LocalPanel->Left > RemotePanel->Left) != WinConfiguration->ScpCommander.SwappedPanels)
  474. {
  475. int AWidth = ClientWidth;
  476. Panel(false)->Align = alClient;
  477. Panel(true)->Align = alLeft;
  478. TControl * ControlsOrder[] =
  479. { Panel(true), Splitter, Panel(false) };
  480. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  481. Panel(true)->TabOrder = 0;
  482. Panel(false)->TabOrder = 1;
  483. ClientWidth = AWidth;
  484. LeftPanelWidth = FLastLeftPanelWidth;
  485. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  486. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  487. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  488. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  489. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  490. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction->ShortCut,
  491. NonVisualDataModule->RemoteChangePathAction->ShortCut);
  492. }
  493. if ((RemoteDriveView->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  494. {
  495. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  496. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  497. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  498. // save value only is it was set yet
  499. if (FPanelsRestored)
  500. {
  501. if (TreeOnLeft)
  502. {
  503. // want to be on left, so it is on top, saving height
  504. LocalPanel.DriveViewHeight = LocalDriveView->Height;
  505. RemotePanel.DriveViewHeight = RemoteDriveView->Height;
  506. }
  507. else
  508. {
  509. LocalPanel.DriveViewWidth = LocalDriveView->Width;
  510. RemotePanel.DriveViewWidth = RemoteDriveView->Width;
  511. }
  512. }
  513. TAlign NonClientAlign = (TreeOnLeft ? alLeft : alTop);
  514. // VCL adjusts cursors only between crVSplit and crHSplit,
  515. // See TSplitter.RequestAlign
  516. TCursor SplitterCursor = (TreeOnLeft ? crSizeWE : crSizeNS);
  517. LocalDriveView->Align = NonClientAlign;
  518. LocalPanelSplitter->Align = NonClientAlign;
  519. LocalPanelSplitter->Cursor = SplitterCursor;
  520. RemoteDriveView->Align = NonClientAlign;
  521. RemotePanelSplitter->Align = NonClientAlign;
  522. RemotePanelSplitter->Cursor = SplitterCursor;
  523. FixControlsPlacement();
  524. if (TreeOnLeft)
  525. {
  526. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  527. RemoteDriveView->Width = RemotePanel.DriveViewWidth;
  528. }
  529. else
  530. {
  531. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  532. RemoteDriveView->Height = RemotePanel.DriveViewHeight;
  533. }
  534. // in case it trigges config-changed event (does not),
  535. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  536. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  537. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  538. }
  539. if (FExplorerKeyboardShortcuts != WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  540. {
  541. SetShortcuts();
  542. }
  543. }
  544. //---------------------------------------------------------------------------
  545. void __fastcall TScpCommanderForm::SetShortcuts()
  546. {
  547. // set common norton shorcuts to our actions
  548. NonVisualDataModule->CommanderShortcuts();
  549. FExplorerKeyboardShortcuts = WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts;
  550. }
  551. //---------------------------------------------------------------------------
  552. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  553. {
  554. return (WinConfiguration->ScpCommander.SwappedPanels == Left ?
  555. RemotePanel : LocalPanel);
  556. }
  557. //---------------------------------------------------------------------------
  558. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  559. {
  560. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TScpCommanderForm::SetLeftPanelWidth(double value)
  564. {
  565. double Total = LocalPanel->Width + RemotePanel->Width;
  566. FLeftPanelWidth = value;
  567. if (value * Total != Panel(true)->Width)
  568. {
  569. Panel(true)->Width = static_cast<int>(value * Total);
  570. UpdateControls();
  571. }
  572. }
  573. //---------------------------------------------------------------------------
  574. double __fastcall TScpCommanderForm::GetLeftPanelWidth()
  575. {
  576. return FLeftPanelWidth;
  577. }
  578. //---------------------------------------------------------------------------
  579. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  580. {
  581. double Left = Panel(true)->Width;
  582. double Total = LocalPanel->Width + RemotePanel->Width;
  583. FLeftPanelWidth = Left / Total;
  584. FLastLeftPanelWidth = LeftPanelWidth;
  585. UpdateControls();
  586. }
  587. //---------------------------------------------------------------------------
  588. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  589. int &NewSize, bool & /*Accept*/)
  590. {
  591. // When splitter is drag so far to right, that width contraint of remote panel would
  592. // be violated, it doesn't stop, but extend form width.
  593. // Following prevents this behavior.
  594. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  595. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  596. }
  597. //---------------------------------------------------------------------------
  598. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  599. {
  600. LeftPanelWidth = 0.5;
  601. }
  602. //---------------------------------------------------------------------------
  603. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  604. {
  605. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  606. assert(Splitter != NULL);
  607. TCustomDriveView * DriveView;
  608. TCustomDriveView * OtherDriveView;
  609. if (Splitter == LocalPanelSplitter)
  610. {
  611. DriveView = LocalDriveView;
  612. OtherDriveView = RemoteDriveView;
  613. }
  614. else
  615. {
  616. DriveView = RemoteDriveView;
  617. OtherDriveView = LocalDriveView;
  618. }
  619. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  620. assert(DriveView->Visible);
  621. if (OtherDriveView->Visible)
  622. {
  623. if (TreeOnLeft)
  624. {
  625. DriveView->Width = OtherDriveView->Width;
  626. }
  627. else
  628. {
  629. DriveView->Height = OtherDriveView->Height;
  630. }
  631. }
  632. else
  633. {
  634. if (TreeOnLeft)
  635. {
  636. OtherDriveView->Width = DriveView->Width;
  637. }
  638. else
  639. {
  640. OtherDriveView->Height = DriveView->Height;
  641. }
  642. OtherDriveView->Visible = true;
  643. }
  644. FixControlsPlacement();
  645. }
  646. //---------------------------------------------------------------------------
  647. void __fastcall TScpCommanderForm::UpdateControls()
  648. {
  649. TCustomScpExplorerForm::UpdateControls();
  650. UnicodeString SplitterLongHint = Splitter->Hint;
  651. SplitterLongHint.Delete(1, SplitterLongHint.Pos(L"|"));
  652. Splitter->Hint = FORMAT(L"%0.0f%%|%s", (LeftPanelWidth*100, SplitterLongHint));
  653. UnicodeString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  654. ((FCurrentSide == osRemote) ? L"$" : L">");
  655. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  656. {
  657. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  658. // command line combo width needs to be updated as caption width has probably changed
  659. ToolBarResize(CommandLineToolbar);
  660. }
  661. LocalDirView->Color = (SessionColor != 0 ? SessionColor : clWindow);
  662. LocalDriveView->Color = LocalDirView->Color;
  663. TAction * CurrentCopyAction = (FCurrentSide == osLocal) ? NonVisualDataModule->LocalCopyAction : NonVisualDataModule->RemoteCopyAction;
  664. if (CurrentCopyItem->Action != CurrentCopyAction)
  665. {
  666. CurrentCopyItem->Action = CurrentCopyAction;
  667. CurrentCopyToolbar2Item->Action = CurrentCopyAction;
  668. UpdateToolbar2ItemCaption(CurrentCopyToolbar2Item);
  669. }
  670. TAction * CurrentMoveAction = (FCurrentSide == osLocal) ? NonVisualDataModule->LocalMoveAction : NonVisualDataModule->RemoteMoveAction;
  671. if (CurrentMoveItem->Action != CurrentMoveAction)
  672. {
  673. CurrentMoveItem->Action = CurrentMoveAction;
  674. CurrentMoveToolbar2Item->Action = CurrentMoveAction;
  675. UpdateToolbar2ItemCaption(CurrentMoveToolbar2Item);
  676. }
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  680. {
  681. assert((Side == osLocal) || (Side == osRemote));
  682. TTBXComboBoxItem * PathComboBox;
  683. if (Side == osLocal)
  684. {
  685. PathComboBox = LocalPathComboBox;
  686. }
  687. else
  688. {
  689. PathComboBox = RemotePathComboBox;
  690. }
  691. ClickToolbarItem(PathComboBox, false);
  692. }
  693. //---------------------------------------------------------------------------
  694. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  695. {
  696. switch (Component) {
  697. case fcToolBar2: return Toolbar2Toolbar; // name changed to enforce change of default visibility
  698. case fcStatusBar: return StatusBar;
  699. case fcLocalStatusBar: return LocalStatusBar;
  700. case fcRemoteStatusBar: return RemoteStatusBar;
  701. case fcCommandLinePanel: return CommandLineToolbar;
  702. case fcLocalTree: return LocalDriveView;
  703. case fcSessionToolbar: return SessionToolbar;
  704. case fcCustomCommandsBand: return CustomCommandsToolbar;
  705. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  706. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  707. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  708. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  709. case fcLocalPopup: return reinterpret_cast<TControl *>(NonVisualDataModule->LocalFilePopup);
  710. case fcCommanderMenuBand: return MenuToolbar;
  711. case fcCommanderSessionBand: return SessionToolbar;
  712. case fcCommanderPreferencesBand: return PreferencesToolbar;
  713. case fcCommanderSortBand: return SortToolbar;
  714. case fcCommanderCommandsBand: return CommandsToolbar;
  715. case fcCommanderUpdatesBand: return UpdatesToolbar;
  716. case fcCommanderTransferBand: return TransferToolbar;
  717. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  718. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  719. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  720. case fcCommanderLocalFileBand: return LocalFileToolbar;
  721. case fcCommanderLocalSelectionBand: return LocalSelectionToolbar;
  722. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  723. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  724. case fcCommanderRemoteFileBand: return RemoteFileToolbar;
  725. case fcCommanderRemoteSelectionBand: return RemoteSelectionToolbar;
  726. default: return TCustomScpExplorerForm::GetComponent(Component);
  727. }
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TScpCommanderForm::FixControlsPlacement()
  731. {
  732. TCustomScpExplorerForm::FixControlsPlacement();
  733. QueueSeparatorPanel->Visible = QueuePanel->Visible;
  734. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  735. TControl * ControlsOrder[] =
  736. { BottomDock, QueueSeparatorPanel, QueueSplitter, QueuePanel, StatusBar };
  737. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  738. TControl * LocalControlsOrder[] =
  739. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  740. LocalDirView, LocalBottomDock, LocalStatusBar };
  741. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  742. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  743. TControl * RemoteControlsOrder[] =
  744. { RemoteTopDock, RemotePathLabel, RemoteDriveView, RemotePanelSplitter,
  745. RemoteDirView, RemoteBottomDock, RemoteStatusBar };
  746. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  747. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  748. if (LocalDirView->ItemFocused != NULL)
  749. {
  750. LocalDirView->ItemFocused->MakeVisible(false);
  751. }
  752. }
  753. //---------------------------------------------------------------------------
  754. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  755. {
  756. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  757. }
  758. //---------------------------------------------------------------------------
  759. void __fastcall TScpCommanderForm::CompareDirectories()
  760. {
  761. LocalDirView->CompareFiles(RemoteDirView, false,
  762. WinConfiguration->ScpCommander.CompareCriterias());
  763. RemoteDirView->CompareFiles(LocalDirView, false,
  764. WinConfiguration->ScpCommander.CompareCriterias());
  765. if (LocalDirView->SelCount + RemoteDirView->SelCount == 0)
  766. {
  767. MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
  768. HELP_COMPARE_NO_DIFFERENCES);
  769. }
  770. }
  771. //---------------------------------------------------------------------------
  772. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  773. {
  774. UnicodeString LocalDirectory = LocalDirView->PathName;
  775. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  776. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, false);
  777. }
  778. //---------------------------------------------------------------------------
  779. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  780. {
  781. UnicodeString LocalDirectory = LocalDirView->PathName;
  782. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  783. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  784. TSynchronizeMode Mode =
  785. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  786. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  787. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode,
  788. SaveMode, false))
  789. {
  790. if (SaveMode)
  791. {
  792. GUIConfiguration->SynchronizeModeAuto = Mode;
  793. }
  794. }
  795. }
  796. //---------------------------------------------------------------------------
  797. void __fastcall TScpCommanderForm::ExploreLocalDirectory()
  798. {
  799. if ((int)ShellExecute(Application->Handle, L"explore",
  800. (wchar_t*)LocalDirView->Path.data(), NULL, NULL, SW_SHOWNORMAL) <= 32)
  801. {
  802. throw Exception(FORMAT(EXPLORE_LOCAL_DIR_ERROR, (LocalDirView->Path)));
  803. }
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  807. TListItem *Item, bool &AllowExec)
  808. {
  809. assert(Item);
  810. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  811. DirectoryExists(::ApiPath(ResolveFileShortCut(LocalDirView->ItemFullFileName(Item), true))))
  812. {
  813. AllowExec = true;
  814. }
  815. else
  816. {
  817. DoDirViewExecFile(Sender, Item, AllowExec);
  818. }
  819. }
  820. //---------------------------------------------------------------------------
  821. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  822. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  823. bool &Accept)
  824. {
  825. // LocalDirViewDDDragEnter is duplication of
  826. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  827. // literal type of 'DataObj' parameter.Actual type is however same
  828. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  829. }
  830. //---------------------------------------------------------------------------
  831. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  832. bool DragDrop)
  833. {
  834. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  835. (DropSourceControl == LocalDirView);
  836. }
  837. //---------------------------------------------------------------------------
  838. void __fastcall TScpCommanderForm::FileOperationProgress(
  839. TFileOperationProgressType & ProgressData)
  840. {
  841. // Heuristic: When operation finishes and DD targed is local dir view,
  842. // we suppose that drag&drop download finished, so local dir view should be
  843. // reloaded
  844. if (!ProgressData.InProgress && FProgressForm &&
  845. IsFileControl(FDDTargetControl, osLocal) &&
  846. ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
  847. {
  848. ReloadLocalDirectory();
  849. }
  850. TCustomScpExplorerForm::FileOperationProgress(ProgressData);
  851. }
  852. //---------------------------------------------------------------------------
  853. UnicodeString __fastcall TScpCommanderForm::ChangeFilePath(UnicodeString Path, TOperationSide Side)
  854. {
  855. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  856. UnicodeString Result;
  857. while (!Path.IsEmpty())
  858. {
  859. int P = Path.Pos(Side == osLocal ? L'\\' : L'/');
  860. if (P > 0)
  861. {
  862. Result += CopyParams.ChangeFileName(Path.SubString(1, P - 1), Side, false) +
  863. (Side == osLocal ? L'/' : L'\\');
  864. Path.Delete(1, P);
  865. }
  866. else
  867. {
  868. Result += CopyParams.ChangeFileName(Path, osLocal, false);
  869. Path = L"";
  870. }
  871. }
  872. return Result;
  873. }
  874. //---------------------------------------------------------------------------
  875. void __fastcall TScpCommanderForm::SynchronizeBrowsingLocal(
  876. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  877. {
  878. Terminal->ExceptionOnFail = true;
  879. TStrings * Paths = new TStringList();
  880. try
  881. {
  882. Paths->Add(IncludeTrailingBackslash(PrevPath));
  883. Paths->Add(IncludeTrailingBackslash(LocalDirView->Path));
  884. UnicodeString CommonPath;
  885. if (ExtractCommonPath(Paths, CommonPath))
  886. {
  887. PrevPath = IncludeTrailingBackslash(PrevPath);
  888. CommonPath = IncludeTrailingBackslash(CommonPath);
  889. NewPath = RemoteDirView->Path;
  890. while (!ComparePaths(PrevPath, CommonPath))
  891. {
  892. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  893. {
  894. Abort();
  895. }
  896. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  897. PrevPath = ExtractFilePath(ExcludeTrailingBackslash(PrevPath));
  898. }
  899. NewPath = UnixIncludeTrailingBackslash(NewPath) +
  900. ToUnixPath(LocalDirView->Path.SubString(PrevPath.Length() + 1,
  901. LocalDirView->Path.Length() - PrevPath.Length()));
  902. }
  903. else
  904. {
  905. Abort();
  906. }
  907. if (Create)
  908. {
  909. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  910. RemoteDirView->CreateDirectoryEx(NewPath, &Properties);
  911. }
  912. RemoteDirView->Path = NewPath;
  913. }
  914. __finally
  915. {
  916. Terminal->ExceptionOnFail = false;
  917. delete Paths;
  918. }
  919. }
  920. //---------------------------------------------------------------------------
  921. void __fastcall TScpCommanderForm::SynchronizeBrowsingRemote(
  922. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  923. {
  924. TStrings * Paths = new TStringList();
  925. try
  926. {
  927. Paths->Add(UnixIncludeTrailingBackslash(PrevPath));
  928. Paths->Add(UnixIncludeTrailingBackslash(RemoteDirView->Path));
  929. UnicodeString CommonPath;
  930. if (UnixExtractCommonPath(Paths, CommonPath))
  931. {
  932. PrevPath = UnixIncludeTrailingBackslash(PrevPath);
  933. CommonPath = UnixIncludeTrailingBackslash(CommonPath);
  934. UnicodeString NewLocalPath;
  935. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  936. while (!UnixSamePath(PrevPath, CommonPath))
  937. {
  938. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  939. if (NewLocalPath == NewPath)
  940. {
  941. Abort();
  942. }
  943. NewPath = NewLocalPath;
  944. PrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(PrevPath));
  945. }
  946. NewPath = IncludeTrailingBackslash(NewPath) +
  947. ChangeFilePath(
  948. RemoteDirView->Path.SubString(PrevPath.Length() + 1,
  949. RemoteDirView->Path.Length() - PrevPath.Length()),
  950. osRemote);
  951. }
  952. else
  953. {
  954. Abort();
  955. }
  956. }
  957. __finally
  958. {
  959. delete Paths;
  960. }
  961. if (Create)
  962. {
  963. LocalDirView->CreateDirectory(NewPath);
  964. }
  965. LocalDirView->Path = NewPath;
  966. }
  967. //---------------------------------------------------------------------------
  968. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  969. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  970. {
  971. if (ADirView == LocalDirView)
  972. {
  973. SynchronizeBrowsingLocal(PrevPath, NewPath, Create);
  974. }
  975. else
  976. {
  977. SynchronizeBrowsingRemote(PrevPath, NewPath, Create);
  978. }
  979. }
  980. //---------------------------------------------------------------------------
  981. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  982. {
  983. UnicodeString PrevPath;
  984. // cannot assign to UnicodeString before the class is constructed,
  985. // if we do, the value get lost when UnicodeString constructor gets finally called,
  986. // what results in memory leak in the best case
  987. if (FConstructed)
  988. {
  989. PrevPath = FPrevPath[ADirView == LocalDirView];
  990. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  991. }
  992. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  993. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  994. {
  995. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  996. FAllowTransferPresetAutoSelect = false;
  997. TValueRestorer<bool> SynchronisingBrowseRestorer(FSynchronisingBrowse);
  998. FSynchronisingBrowse = true;
  999. try
  1000. {
  1001. UnicodeString NewPath;
  1002. bool Error = false;
  1003. std::unique_ptr<TStrings> ErrorMoreMessages;
  1004. UnicodeString ErrorHelpKeyword;
  1005. try
  1006. {
  1007. SynchronizeBrowsing(ADirView, PrevPath, NewPath, false);
  1008. }
  1009. // EAbort means that we do not know how to synchronize browsing
  1010. // there's no fallback scenario for that
  1011. catch(EAbort &)
  1012. {
  1013. throw;
  1014. }
  1015. catch(Exception & E)
  1016. {
  1017. // what does this say?
  1018. if (Application->Terminated)
  1019. {
  1020. throw;
  1021. }
  1022. else
  1023. {
  1024. Error = true;
  1025. ErrorMoreMessages.reset(ExceptionToMoreMessages(&E));
  1026. ErrorHelpKeyword =
  1027. MergeHelpKeyword(HELP_SYNC_DIR_BROWSE_ERROR, GetExceptionHelpKeyword(&E));
  1028. }
  1029. }
  1030. // this was moved here out of the above catch clause,
  1031. // to avoid deep nesting, what seems to cause some stray access violations
  1032. if (Error)
  1033. {
  1034. if (MoreMessageDialog(FMTLOAD(SYNC_DIR_BROWSE_CREATE2, (NewPath)),
  1035. ErrorMoreMessages.get(), qtConfirmation, qaYes | qaNo,
  1036. ErrorHelpKeyword) == qaYes)
  1037. {
  1038. try
  1039. {
  1040. SynchronizeBrowsing(ADirView, PrevPath, NewPath, true);
  1041. }
  1042. catch(Exception & E)
  1043. {
  1044. if (!Application->Terminated)
  1045. {
  1046. Terminal->ShowExtendedException(&E);
  1047. }
  1048. throw;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1054. }
  1055. }
  1056. }
  1057. catch(Exception & E)
  1058. {
  1059. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1060. // what does this say?
  1061. if (Application->Terminated)
  1062. {
  1063. throw;
  1064. }
  1065. else
  1066. {
  1067. MessageDialog(LoadStr(SYNC_DIR_BROWSE_ERROR), qtInformation, qaOK,
  1068. HELP_SYNC_DIR_BROWSE_ERROR);
  1069. }
  1070. }
  1071. // note the value restorers at the beginning of this block
  1072. }
  1073. }
  1074. //---------------------------------------------------------------------------
  1075. void __fastcall TScpCommanderForm::DoDirViewLoaded(TCustomDirView * ADirView)
  1076. {
  1077. TCustomScpExplorerForm::DoDirViewLoaded(ADirView);
  1078. UpdateControls();
  1079. SynchronizeBrowsing(ADirView);
  1080. }
  1081. //---------------------------------------------------------------------------
  1082. void __fastcall TScpCommanderForm::AddEditLink(TOperationSide Side, bool Add)
  1083. {
  1084. if (GetSide(Side) == osLocal)
  1085. {
  1086. bool Edit = false;
  1087. UnicodeString FileName;
  1088. UnicodeString PointTo;
  1089. bool SymbolicLink = true;
  1090. if (LocalDirView->ItemFocused)
  1091. {
  1092. assert(LocalDirView->ItemFocused->Data);
  1093. PFileRec FileRec = (PFileRec)LocalDirView->ItemFocused->Data;
  1094. Edit = !Add && (UpperCase(FileRec->FileExt) == L"LNK");
  1095. if (Edit)
  1096. {
  1097. UnicodeString FullName = LocalDirView->ItemFullFileName(LocalDirView->ItemFocused);
  1098. FileName = FullName;
  1099. PointTo = ResolveFileShortCut(FullName, false);
  1100. if (PointTo.IsEmpty())
  1101. {
  1102. throw Exception(FMTLOAD(RESOLVE_SHORTCUT_ERROR, (FullName)));
  1103. }
  1104. }
  1105. else
  1106. {
  1107. PointTo = FileRec->FileName;
  1108. }
  1109. }
  1110. if (DoSymlinkDialog(FileName, PointTo, osLocal, SymbolicLink, Edit, false))
  1111. {
  1112. Configuration->Usage->Inc(L"LocalShortcutsCreated");
  1113. assert(SymbolicLink);
  1114. assert(!FileName.IsEmpty());
  1115. assert(!PointTo.IsEmpty());
  1116. if (ExtractFileDrive(FileName) == L"" && FileName[1] != L'\\')
  1117. {
  1118. FileName = IncludeTrailingBackslash(LocalDirView->PathName) + FileName;
  1119. }
  1120. if (ExtractFileDrive(PointTo) == L"" && PointTo[1] != L'\\')
  1121. {
  1122. PointTo = IncludeTrailingBackslash(LocalDirView->PathName) + PointTo;
  1123. }
  1124. if (ExtractFileExt(FileName) == L"")
  1125. {
  1126. FileName = FileName + L".lnk";
  1127. }
  1128. if (Edit)
  1129. {
  1130. DeleteFileChecked(FileName);
  1131. }
  1132. if (!CreateFileShortCut(PointTo, FileName, L""))
  1133. {
  1134. throw Exception(CREATE_SHORTCUT_ERROR);
  1135. }
  1136. }
  1137. }
  1138. else
  1139. {
  1140. TCustomScpExplorerForm::AddEditLink(Side, Add);
  1141. }
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TScpCommanderForm::DoOpenDirectoryDialog(TOpenDirectoryMode Mode,
  1145. TOperationSide Side)
  1146. {
  1147. bool UseLocationProfiles;
  1148. do
  1149. {
  1150. UseLocationProfiles = WinConfiguration->UseLocationProfiles;
  1151. if (UseLocationProfiles)
  1152. {
  1153. TStrings * LocalDirectories = NULL;
  1154. TStrings * RemoteDirectories = NULL;
  1155. try
  1156. {
  1157. LocalDirectories = CreateVisitedDirectories(osLocal);
  1158. RemoteDirectories = CreateVisitedDirectories(osRemote);
  1159. UnicodeString Local = LocalDirView->PathName;
  1160. UnicodeString Remote = RemoteDirView->PathName;
  1161. if (LocationProfilesDialog(Mode, Side, Local, Remote, LocalDirectories,
  1162. RemoteDirectories, Terminal))
  1163. {
  1164. DoOpenBookmark(Local, Remote);
  1165. }
  1166. }
  1167. __finally
  1168. {
  1169. delete LocalDirectories;
  1170. delete RemoteDirectories;
  1171. }
  1172. }
  1173. else
  1174. {
  1175. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1176. TCustomScpExplorerForm::DoOpenDirectoryDialog(Mode, Side);
  1177. }
  1178. // for second and further rounds, always do browse only
  1179. Mode = odBrowse;
  1180. }
  1181. while (UseLocationProfiles != WinConfiguration->UseLocationProfiles);
  1182. }
  1183. //---------------------------------------------------------------------------
  1184. void __fastcall TScpCommanderForm::DoOpenBookmark(UnicodeString Local, UnicodeString Remote)
  1185. {
  1186. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1187. // make sure that whatever path is valid it is opened first and only
  1188. // after that an eventual error is reported
  1189. try
  1190. {
  1191. if (!Local.IsEmpty())
  1192. {
  1193. LocalDirView->Path = Local;
  1194. }
  1195. }
  1196. __finally
  1197. {
  1198. if (!Remote.IsEmpty())
  1199. {
  1200. RemoteDirView->Path = Remote;
  1201. }
  1202. }
  1203. }
  1204. //---------------------------------------------------------------------------
  1205. bool __fastcall TScpCommanderForm::OpenBookmark(UnicodeString Local, UnicodeString Remote)
  1206. {
  1207. bool Result;
  1208. if (WinConfiguration->UseLocationProfiles)
  1209. {
  1210. DoOpenBookmark(Local, Remote);
  1211. Result = true;
  1212. }
  1213. else
  1214. {
  1215. Result = TCustomScpExplorerForm::OpenBookmark(Local, Remote);
  1216. }
  1217. return Result;
  1218. }
  1219. //---------------------------------------------------------------------------
  1220. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1221. TObject * /*Sender*/, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1222. {
  1223. // when drop target is not directory, it is probably file type, which have
  1224. // associated drop handler (such as ZIP file in WinXP). in this case we
  1225. // cannot allow downloading when using shellex.
  1226. // ! this check is duplicated in InternalDDDownload() for non-shellex downloads
  1227. if ((FDDExtMapFile != NULL) &&
  1228. !LocalDirView->ItemIsDirectory(Item))
  1229. {
  1230. DropHandler = false;
  1231. }
  1232. }
  1233. //---------------------------------------------------------------------------
  1234. void __fastcall TScpCommanderForm::LocalFileControlDDDragOver(TObject * /*Sender*/,
  1235. int grfKeyState, TPoint & /*Point*/, int & dwEffect)
  1236. {
  1237. if (IsFileControl(DropSourceControl, osRemote))
  1238. {
  1239. if (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == 0) ||
  1240. (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == MK_SHIFT) &&
  1241. !WinConfiguration->DDAllowMoveInit))
  1242. {
  1243. dwEffect = DROPEFFECT_Copy;
  1244. }
  1245. }
  1246. }
  1247. //---------------------------------------------------------------------------
  1248. bool __fastcall TScpCommanderForm::DDGetTarget(UnicodeString & Directory, bool & Internal)
  1249. {
  1250. bool Result;
  1251. if (!FDDExtTarget.IsEmpty())
  1252. {
  1253. Directory = FDDExtTarget;
  1254. FDDExtTarget = L"";
  1255. Result = true;
  1256. Internal = true;
  1257. }
  1258. else
  1259. {
  1260. Result = TCustomScpExplorerForm::DDGetTarget(Directory, Internal);
  1261. }
  1262. return Result;
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. void __fastcall TScpCommanderForm::DDExtInitDrag(TFileList * FileList,
  1266. bool & Created)
  1267. {
  1268. FDDExtTarget = L"";
  1269. TCustomScpExplorerForm::DDExtInitDrag(FileList, Created);
  1270. }
  1271. //---------------------------------------------------------------------------
  1272. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1273. TObject * /*Sender*/, int dwEffect, UnicodeString SourcePath,
  1274. UnicodeString TargetPath, bool & DoOperation)
  1275. {
  1276. if (IsFileControl(DropSourceControl, osRemote))
  1277. {
  1278. UnicodeString TargetDirectory;
  1279. if (InternalDDDownload(TargetDirectory))
  1280. {
  1281. if (FDDExtMapFile != NULL)
  1282. {
  1283. FDDExtTarget = TargetDirectory;
  1284. }
  1285. else
  1286. {
  1287. assert(FInternalDDDownloadList->Count > 0);
  1288. assert(dwEffect == DROPEFFECT_Copy || dwEffect == DROPEFFECT_Move);
  1289. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1290. TTransferType TransferType = dwEffect == DROPEFFECT_Copy ? ttCopy : ttMove;
  1291. if (FDDMoveSlipped)
  1292. {
  1293. TransferType = ttMove;
  1294. }
  1295. int Options = 0;
  1296. if (CopyParamDialog(tdToLocal, TransferType,
  1297. false, FInternalDDDownloadList, TargetDirectory, CopyParams,
  1298. (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  1299. {
  1300. int Params =
  1301. (TransferType == ttMove ? cpDelete : 0);
  1302. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1303. &CopyParams, Params);
  1304. Configuration->Usage->Inc(L"DownloadsDragDropInternal");
  1305. FInternalDDDownloadList->Clear();
  1306. }
  1307. }
  1308. DoOperation = false;
  1309. }
  1310. }
  1311. }
  1312. //---------------------------------------------------------------------------
  1313. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1314. TObject * /*Sender*/, int dwEffect, UnicodeString /*SourcePath*/,
  1315. UnicodeString /*TargetPath*/)
  1316. {
  1317. if ((dwEffect == DROPEFFECT_Move) &&
  1318. IsFileControl(DropSourceControl, osLocal))
  1319. {
  1320. ReloadLocalDirectory();
  1321. }
  1322. }
  1323. //---------------------------------------------------------------------------
  1324. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1325. {
  1326. SideEnter(osLocal);
  1327. }
  1328. //---------------------------------------------------------------------------
  1329. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1330. {
  1331. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1332. SideEnter(osLocal);
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1336. {
  1337. if (Visible && (FCurrentSide != Side))
  1338. {
  1339. // this may get called yet before controls are initialized
  1340. CommandLineCombo->Strings->Clear();
  1341. FCommandLineComboPopulated = false;
  1342. }
  1343. TCustomScpExplorerForm::SideEnter(Side);
  1344. if (Visible)
  1345. {
  1346. UpdateControls();
  1347. UpdatePanelsPathLabelsStatus();
  1348. }
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. void __fastcall TScpCommanderForm::UpdatePanelsPathLabelsStatus()
  1352. {
  1353. LocalPathLabel->UpdateStatus();
  1354. RemotePathLabel->UpdateStatus();
  1355. }
  1356. //---------------------------------------------------------------------------
  1357. void __fastcall TScpCommanderForm::OpenConsole(UnicodeString Command)
  1358. {
  1359. SaveCommandLine();
  1360. try
  1361. {
  1362. TCustomScpExplorerForm::OpenConsole(Command);
  1363. }
  1364. __finally
  1365. {
  1366. FCommandLineComboPopulated = false;
  1367. }
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. void __fastcall TScpCommanderForm::SaveCommandLine()
  1371. {
  1372. if (FCommandLineComboPopulated)
  1373. {
  1374. CustomWinConfiguration->History[
  1375. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"] =
  1376. CommandLineCombo->Strings;
  1377. }
  1378. }
  1379. //---------------------------------------------------------------------------
  1380. bool __fastcall TScpCommanderForm::ExecuteCommandLine()
  1381. {
  1382. UnicodeString Command = CommandLineCombo->Text;
  1383. bool Result =
  1384. !Command.IsEmpty() &&
  1385. ((FCurrentSide != osRemote) ||
  1386. (Terminal->AllowedAnyCommand(Command) &&
  1387. EnsureCommandSessionFallback(fcAnyCommand)));
  1388. if (Result)
  1389. {
  1390. CommandLinePopulate();
  1391. SaveToHistory(CommandLineCombo->Strings, Command);
  1392. CommandLineCombo->Text = L"";
  1393. if (FCurrentSide == osRemote)
  1394. {
  1395. OpenConsole(Command);
  1396. }
  1397. else
  1398. {
  1399. UnicodeString Program, Params, Dir;
  1400. SplitCommand(Command, Program, Params, Dir);
  1401. if (!ExecuteShell(Program, Params))
  1402. {
  1403. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
  1404. }
  1405. }
  1406. }
  1407. return Result;
  1408. }
  1409. //---------------------------------------------------------------------------
  1410. void __fastcall TScpCommanderForm::CommandLinePopulate()
  1411. {
  1412. if (!FCommandLineComboPopulated)
  1413. {
  1414. TStrings * CommandsHistory;
  1415. CommandsHistory = CustomWinConfiguration->History[
  1416. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"];
  1417. if ((CommandsHistory != NULL) && (CommandsHistory->Count > 0))
  1418. {
  1419. CommandLineCombo->Strings = CommandsHistory;
  1420. }
  1421. else
  1422. {
  1423. CommandLineCombo->Strings->Clear();
  1424. }
  1425. FCommandLineComboPopulated = true;
  1426. }
  1427. }
  1428. //---------------------------------------------------------------------------
  1429. void __fastcall TScpCommanderForm::GoToCommandLine()
  1430. {
  1431. ComponentVisible[fcCommandLinePanel] = true;
  1432. if (CommandLineCombo->Enabled)
  1433. {
  1434. ClickToolbarItem(CommandLineCombo, true);
  1435. }
  1436. }
  1437. //---------------------------------------------------------------------------
  1438. void __fastcall TScpCommanderForm::GoToTree()
  1439. {
  1440. if (FCurrentSide == osLocal)
  1441. {
  1442. ComponentVisible[fcLocalTree] = true;
  1443. LocalDriveView->SetFocus();
  1444. }
  1445. else
  1446. {
  1447. TCustomScpExplorerForm::GoToTree();
  1448. }
  1449. }
  1450. //---------------------------------------------------------------------------
  1451. void __fastcall TScpCommanderForm::PanelExportStore(TOperationSide Side,
  1452. TPanelExport Export, TPanelExportDestination Destination,
  1453. TStrings * ExportData)
  1454. {
  1455. if (Destination == pedCommandLine)
  1456. {
  1457. ComponentVisible[fcCommandLinePanel] = true;
  1458. UnicodeString Buf;
  1459. for (int Index = 0; Index < ExportData->Count; Index++)
  1460. {
  1461. Buf += ExportData->Strings[Index] + L" ";
  1462. }
  1463. CommandLineCombo->Text = CommandLineCombo->Text + Buf;
  1464. }
  1465. else
  1466. {
  1467. TCustomScpExplorerForm::PanelExportStore(Side, Export, Destination, ExportData);
  1468. }
  1469. }
  1470. //---------------------------------------------------------------------------
  1471. int __fastcall TScpCommanderForm::GetStaticComponentsHeight()
  1472. {
  1473. return TCustomScpExplorerForm::GetStaticComponentsHeight() +
  1474. (BottomDock->Visible ? BottomDock->Height : 0) +
  1475. (QueueSeparatorPanel->Visible ? QueueSeparatorPanel->Height : 0) +
  1476. (StatusBar->Visible ? StatusBar->Height : 0);
  1477. }
  1478. //---------------------------------------------------------------------------
  1479. void __fastcall TScpCommanderForm::SysResizing(unsigned int Cmd)
  1480. {
  1481. TCustomScpExplorerForm::SysResizing(Cmd);
  1482. if ((Cmd == SC_MAXIMIZE) ||
  1483. ((Cmd == SC_DEFAULT) && (WindowState != wsMaximized)))
  1484. {
  1485. FNormalPanelsWidth = LocalPanel->Width + RemotePanel->Width;
  1486. }
  1487. else if ((Cmd == SC_RESTORE) ||
  1488. ((Cmd == SC_DEFAULT) && (WindowState == wsMaximized)))
  1489. {
  1490. if (FNormalPanelsWidth >= 0)
  1491. {
  1492. Panel(true)->Width = static_cast<int>(FLeftPanelWidth * FNormalPanelsWidth);
  1493. FNormalPanelsWidth = -1;
  1494. }
  1495. }
  1496. }
  1497. //---------------------------------------------------------------------------
  1498. void __fastcall TScpCommanderForm::Resize()
  1499. {
  1500. TCustomScpExplorerForm::Resize();
  1501. LeftPanelWidth = FLastLeftPanelWidth;
  1502. UpdateControls();
  1503. }
  1504. //---------------------------------------------------------------------------
  1505. void __fastcall TScpCommanderForm::LocalFileControlDDMenuPopup(TObject * /*Sender*/,
  1506. HMENU AMenu, IDataObject * /*DataObj*/, int /*AMinCustCmd*/, int /*grfKeyState*/,
  1507. TPoint & /*pt*/)
  1508. {
  1509. if (IsFileControl(DropSourceControl, osRemote) &&
  1510. !WinConfiguration->DDAllowMoveInit)
  1511. {
  1512. // index of copy item
  1513. int Index = GetMenuDefaultItem(AMenu, TRUE, 0);
  1514. assert(Index >= 0);
  1515. UnicodeString Caption = Dragdrop_MIMoveStr;
  1516. MENUITEMINFO MI;
  1517. memset(&MI, 0, sizeof(MI));
  1518. MI.cbSize = sizeof(MI);
  1519. MI.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
  1520. MI.fType = MFT_STRING;
  1521. MI.wID = 1 /*DragDrop::CmdMove*/;
  1522. MI.dwTypeData = Caption.c_str();
  1523. MI.cch = Caption.Length();
  1524. MI.fState = MFS_ENABLED;
  1525. InsertMenuItem(AMenu, Index, TRUE, &MI);
  1526. if (FDDMoveSlipped)
  1527. {
  1528. SetMenuDefaultItem(AMenu, Index, TRUE);
  1529. }
  1530. FDDMoveSlipped = false;
  1531. }
  1532. }
  1533. //---------------------------------------------------------------------------
  1534. void __fastcall TScpCommanderForm::PathLabelDblClick(TObject * Sender)
  1535. {
  1536. OpenDirectory(Sender == LocalPathLabel ? osLocal : osRemote);
  1537. }
  1538. //---------------------------------------------------------------------------
  1539. void __fastcall TScpCommanderForm::LocalPathLabelGetStatus(
  1540. TCustomPathLabel * /*Sender*/, bool & Active)
  1541. {
  1542. // this strange form is here to make borland compiler work :-)
  1543. Active = Active || LocalDriveView->Focused();
  1544. }
  1545. //---------------------------------------------------------------------------
  1546. void __fastcall TScpCommanderForm::RemotePathLabelGetStatus(
  1547. TCustomPathLabel * /*Sender*/, bool & Active)
  1548. {
  1549. // this strange form is here to make borland compiler work :-)
  1550. Active = Active || RemoteDriveView->Focused();
  1551. }
  1552. //---------------------------------------------------------------------------
  1553. void __fastcall TScpCommanderForm::LocalPathLabelPathClick(
  1554. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1555. {
  1556. if (ComparePaths(Path, LocalDirView->Path))
  1557. {
  1558. OpenDirectory(osLocal);
  1559. }
  1560. else
  1561. {
  1562. LocalDirView->Path = Path;
  1563. }
  1564. }
  1565. //---------------------------------------------------------------------------
  1566. void __fastcall TScpCommanderForm::RemotePathLabelPathClick(
  1567. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1568. {
  1569. if (UnixSamePath(Path, RemoteDirView->Path))
  1570. {
  1571. OpenDirectory(osRemote);
  1572. }
  1573. else
  1574. {
  1575. RemoteDirView->Path = Path;
  1576. }
  1577. }
  1578. //---------------------------------------------------------------------------
  1579. void __fastcall TScpCommanderForm::LocalDirViewFileIconForName(
  1580. TObject * /*Sender*/, TListItem * /*Item*/, UnicodeString & FileName)
  1581. {
  1582. UnicodeString PartialExt = Configuration->PartialExt;
  1583. if (AnsiSameText(ExtractFileExt(FileName), PartialExt))
  1584. {
  1585. FileName.SetLength(FileName.Length() - PartialExt.Length());
  1586. }
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. void __fastcall TScpCommanderForm::LocalDirViewUpdateStatusBar(
  1590. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1591. {
  1592. UpdateFileStatusBar(LocalStatusBar, FileInfo);
  1593. }
  1594. //---------------------------------------------------------------------------
  1595. void __fastcall TScpCommanderForm::RemoteDirViewUpdateStatusBar(
  1596. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1597. {
  1598. UpdateFileStatusBar(RemoteStatusBar, FileInfo);
  1599. }
  1600. //---------------------------------------------------------------------------
  1601. void __fastcall TScpCommanderForm::LocalStatusBarClick(TObject * /*Sender*/)
  1602. {
  1603. LocalDirView->SetFocus();
  1604. }
  1605. //---------------------------------------------------------------------------
  1606. UnicodeString __fastcall TScpCommanderForm::PathForCaption()
  1607. {
  1608. UnicodeString Result;
  1609. if (FCurrentSide == osLocal)
  1610. {
  1611. // for consistency do not show even local path when there is no terminal
  1612. if (Terminal != NULL)
  1613. {
  1614. switch (WinConfiguration->PathInCaption)
  1615. {
  1616. case picShort:
  1617. {
  1618. Result = ExtractFileName(LocalDirView->PathName);
  1619. if (Result.IsEmpty())
  1620. {
  1621. Result = LocalDirView->PathName;
  1622. }
  1623. }
  1624. break;
  1625. case picFull:
  1626. Result = LocalDirView->PathName;
  1627. break;
  1628. }
  1629. }
  1630. }
  1631. else
  1632. {
  1633. Result = TCustomScpExplorerForm::PathForCaption();
  1634. }
  1635. return Result;
  1636. }
  1637. //---------------------------------------------------------------------------
  1638. void __fastcall TScpCommanderForm::GetTransferPresetAutoSelectData(
  1639. TCopyParamRuleData & Data)
  1640. {
  1641. TCustomScpExplorerForm::GetTransferPresetAutoSelectData(Data);
  1642. Data.LocalDirectory = LocalDirView->PathName;
  1643. }
  1644. //---------------------------------------------------------------------------
  1645. void __fastcall TScpCommanderForm::BeforeAction()
  1646. {
  1647. TCustomScpExplorerForm::BeforeAction();
  1648. if (LocalDirView->ItemFocused != NULL)
  1649. {
  1650. LocalDirView->ItemFocused->CancelEdit();
  1651. }
  1652. }
  1653. //---------------------------------------------------------------------------
  1654. void __fastcall TScpCommanderForm::RemoteDirViewPathChange(TCustomDirView * /*Sender*/)
  1655. {
  1656. UpdateRemotePathComboBox(RemotePathComboBox, false);
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. void __fastcall TScpCommanderForm::LocalPathComboUpdateDrives()
  1660. {
  1661. TStrings* Strings = LocalPathComboBox->Strings;
  1662. Strings->BeginUpdate();
  1663. try
  1664. {
  1665. Strings->Clear();
  1666. FLocalPathComboBoxPaths->Clear();
  1667. Strings->Add(LoadStr(SPECIAL_FOLDER_MY_DOCUMENTS));
  1668. FLocalPathComboBoxPaths->AddObject(GetPersonalFolder(),
  1669. (TObject *)DriveInfo->SpecialFolder[CSIDL_PERSONAL]->ImageIndex);
  1670. Strings->Add(LoadStr(SPECIAL_FOLDER_DESKTOP));
  1671. FLocalPathComboBoxPaths->AddObject(GetDesktopFolder(),
  1672. (TObject *)DriveInfo->SpecialFolder[CSIDL_DESKTOP]->ImageIndex);
  1673. for (TDrive Drive = FirstDrive; Drive <= LastDrive; Drive++)
  1674. {
  1675. if (DriveInfo->Data[Drive]->Valid)
  1676. {
  1677. Strings->Add(UnicodeString(L"&") + DriveInfo->GetPrettyName(Drive));
  1678. FLocalPathComboBoxPaths->AddObject(UnicodeString(Drive) + L":\\",
  1679. (TObject *)DriveInfo->GetImageIndex(Drive));
  1680. }
  1681. }
  1682. }
  1683. __finally
  1684. {
  1685. Strings->EndUpdate();
  1686. }
  1687. }
  1688. //---------------------------------------------------------------------------
  1689. void __fastcall TScpCommanderForm::LocalPathComboUpdate()
  1690. {
  1691. // this may get called even after destructor finishes
  1692. // (e.g. from SetDockAllowDrag invoked [indirectly] from StoreParams)
  1693. if (FLocalPathComboBoxPaths != NULL)
  1694. {
  1695. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1696. int Index = 0;
  1697. while ((Index < FLocalPathComboBoxPaths->Count) &&
  1698. !ComparePaths(FLocalPathComboBoxPaths->Strings[Index],
  1699. LocalDirView->Path.SubString(1, FLocalPathComboBoxPaths->Strings[Index].Length())))
  1700. {
  1701. Index++;
  1702. }
  1703. // what to do if not?
  1704. if (Index < FLocalPathComboBoxPaths->Count)
  1705. {
  1706. LocalPathComboBox->ItemIndex = Index;
  1707. }
  1708. }
  1709. }
  1710. //---------------------------------------------------------------------------
  1711. void __fastcall TScpCommanderForm::LocalDirViewPathChange(TCustomDirView * /*Sender*/)
  1712. {
  1713. LocalPathComboUpdate();
  1714. }
  1715. //---------------------------------------------------------------------------
  1716. void __fastcall TScpCommanderForm::LocalPathComboBoxCancel(TObject * /*Sender*/)
  1717. {
  1718. LocalPathComboUpdate();
  1719. }
  1720. //---------------------------------------------------------------------------
  1721. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  1722. TTBXComboBoxItem * /*Sender*/, const UnicodeString AText, int AIndex,
  1723. int & ImageIndex)
  1724. {
  1725. // this may get called even before constructor starts
  1726. // (e.g. from FixControlsPlacement)
  1727. if (FLocalPathComboBoxPaths != NULL)
  1728. {
  1729. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1730. assert(AIndex < FLocalPathComboBoxPaths->Count);
  1731. if (AIndex < 0)
  1732. {
  1733. AIndex = LocalPathComboBox->ItemIndex;
  1734. }
  1735. if (AIndex >= 0)
  1736. {
  1737. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  1738. }
  1739. }
  1740. }
  1741. //---------------------------------------------------------------------------
  1742. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject * /*Sender*/)
  1743. {
  1744. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1745. assert((LocalPathComboBox->ItemIndex >= 0) && (LocalPathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  1746. UnicodeString Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1747. if (Path.Length() == 3)
  1748. {
  1749. LocalDirView->ExecuteDrive(Path[1]);
  1750. }
  1751. else
  1752. {
  1753. LocalDirView->Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1754. }
  1755. }
  1756. //---------------------------------------------------------------------------
  1757. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  1758. {
  1759. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  1760. if ((Item == LocalPathComboBox) ||
  1761. (Item == RemotePathComboBox) ||
  1762. (Item == CommandLineCombo))
  1763. {
  1764. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  1765. }
  1766. }
  1767. //---------------------------------------------------------------------------
  1768. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  1769. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1770. {
  1771. CommandLinePopulate();
  1772. }
  1773. //---------------------------------------------------------------------------
  1774. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  1775. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  1776. {
  1777. InstallPathWordBreakProc(EditControl);
  1778. FCommandLineComboEdit = EditControl;
  1779. FToolbarEditOldWndProc = EditControl->WindowProc;
  1780. EditControl->WindowProc = CommandLineComboEditWndProc;
  1781. }
  1782. //---------------------------------------------------------------------------
  1783. void __fastcall TScpCommanderForm::ExitToolbar()
  1784. {
  1785. CurrentPanel()->SetFocus();
  1786. }
  1787. //---------------------------------------------------------------------------
  1788. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  1789. {
  1790. bool Handled = false;
  1791. if (Message.Msg == WM_CHAR)
  1792. {
  1793. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  1794. {
  1795. case VK_ESCAPE:
  1796. CommandLineCombo->Text = L"";
  1797. ExitToolbar();
  1798. Handled = true;
  1799. break;
  1800. case VK_TAB:
  1801. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1802. ExitToolbar();
  1803. Handled = true;
  1804. break;
  1805. case VK_RETURN:
  1806. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1807. ExitToolbar();
  1808. if (!ExecuteCommandLine())
  1809. {
  1810. // re-enter command line
  1811. // (most probably exited by now as message dialog was shown)
  1812. GoToCommandLine();
  1813. }
  1814. Handled = true;
  1815. break;
  1816. }
  1817. }
  1818. if (!Handled)
  1819. {
  1820. FToolbarEditOldWndProc(Message);
  1821. }
  1822. }
  1823. //---------------------------------------------------------------------------
  1824. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  1825. {
  1826. LocalPathComboUpdateDrives();
  1827. LocalPathComboUpdate();
  1828. }
  1829. //---------------------------------------------------------------------------
  1830. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  1831. {
  1832. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1833. TCustomScpExplorerForm::HomeDirectory(Side);
  1834. }
  1835. //---------------------------------------------------------------------------
  1836. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  1837. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1838. {
  1839. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  1840. }
  1841. //---------------------------------------------------------------------------
  1842. void __fastcall TScpCommanderForm::DoFocusRemotePath(UnicodeString Path)
  1843. {
  1844. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1845. TCustomScpExplorerForm::DoFocusRemotePath(Path);
  1846. }
  1847. //---------------------------------------------------------------------------
  1848. void __fastcall TScpCommanderForm::HistoryGo(TOperationSide Side, int Index)
  1849. {
  1850. TOperationSide OtherSide = ((Side == osLocal) ? osRemote : osLocal);
  1851. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  1852. ((Index < 0) ? (-Index < DirView(OtherSide)->BackCount) : (Index < DirView(OtherSide)->ForwardCount)))
  1853. {
  1854. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1855. TCustomScpExplorerForm::HistoryGo(Side, Index);
  1856. TCustomScpExplorerForm::HistoryGo(OtherSide, Index);
  1857. }
  1858. else
  1859. {
  1860. TCustomScpExplorerForm::HistoryGo(Side, Index);
  1861. }
  1862. }
  1863. //---------------------------------------------------------------------------
  1864. void __fastcall TScpCommanderForm::DirViewHistoryGo(
  1865. TCustomDirView * Sender, int Index, bool & Cancel)
  1866. {
  1867. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  1868. HistoryGo(Side, Index);
  1869. Cancel = true;
  1870. }
  1871. //---------------------------------------------------------------------------
  1872. bool __fastcall TScpCommanderForm::EligibleForImageDisplayMode(TTBCustomItem * Item)
  1873. {
  1874. return
  1875. TCustomScpExplorerForm::EligibleForImageDisplayMode(Item) &&
  1876. ((Item->Parent == NULL) || (Item->Parent->ParentComponent != Toolbar2Toolbar));
  1877. }
  1878. //---------------------------------------------------------------------------
  1879. bool __fastcall TScpCommanderForm::UpdateToolbarDisplayMode()
  1880. {
  1881. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  1882. if (Result)
  1883. {
  1884. // command line combo width needs to be updated as caption visibility has changed
  1885. ToolBarResize(CommandLineToolbar);
  1886. }
  1887. return Result;
  1888. }
  1889. //---------------------------------------------------------------------------
  1890. void __fastcall TScpCommanderForm::QueueLabelUpdateStatus()
  1891. {
  1892. TCustomScpExplorerForm::QueueLabelUpdateStatus();
  1893. // this is here to deactivate panels path labels when moving focus from
  1894. // directory tree to queue
  1895. UpdatePanelsPathLabelsStatus();
  1896. }
  1897. //---------------------------------------------------------------------------
  1898. void __fastcall TScpCommanderForm::LocalDirViewContextPopup(TObject * /*Sender*/,
  1899. TPoint & MousePos, bool & Handled)
  1900. {
  1901. if (!WinConfiguration->ScpCommander.SystemContextMenu && !FForceSystemContextMenu)
  1902. {
  1903. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalOpenMenuItem, dcaOpen);
  1904. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalEditMenuItem, dcaEdit);
  1905. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalCopyMenuItem, dcaCopy);
  1906. DirViewContextPopup(osLocal, fcLocalPopup, MousePos);
  1907. Handled = true;
  1908. }
  1909. }
  1910. //---------------------------------------------------------------------------
  1911. void __fastcall TScpCommanderForm::DisplaySystemContextMenu()
  1912. {
  1913. TAutoFlag Flag(FForceSystemContextMenu);
  1914. if ((FLastContextPopupScreenPoint.x >= 0) && (FLastContextPopupScreenPoint.Y >= 0))
  1915. {
  1916. LocalDirView->DisplayContextMenu(FLastContextPopupScreenPoint);
  1917. }
  1918. else
  1919. {
  1920. LocalDirView->DisplayContextMenuInSitu();
  1921. }
  1922. }
  1923. //---------------------------------------------------------------------------
  1924. void __fastcall TScpCommanderForm::LocalStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  1925. TTBXStatusPanel * Panel)
  1926. {
  1927. FileStatusBarPanelClick(Panel, osLocal);
  1928. }
  1929. //---------------------------------------------------------------------------
  1930. void __fastcall TScpCommanderForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  1931. TTBXStatusPanel *Panel)
  1932. {
  1933. FileStatusBarPanelClick(Panel, osRemote);
  1934. }
  1935. //---------------------------------------------------------------------------