ScpCommander.cpp 78 KB

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