ScpCommander.cpp 77 KB

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