ScpCommander.cpp 78 KB

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