ScpCommander.cpp 90 KB

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