ScpCommander.cpp 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558
  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. if (Directory.IsEmpty() || SamePaths(Directory, OtherLocalDirView->Path))
  468. {
  469. OtherLocalDirView->ReloadDirectory();
  470. OtherLocalDriveView->ValidateDirectory(OtherLocalDriveView->Selected);
  471. }
  472. TCustomScpExplorerForm::ReloadLocalDirectory();
  473. }
  474. //---------------------------------------------------------------------------
  475. void __fastcall TScpCommanderForm::BatchStart(void *& Storage)
  476. {
  477. Storage = new bool;
  478. *static_cast<bool*>(Storage) = LocalDirView->WatchForChanges;
  479. LocalDirView->WatchForChanges = false;
  480. LocalDriveView->WatchDirectory = false;
  481. OtherLocalDirView->WatchForChanges = false;
  482. OtherLocalDriveView->WatchDirectory = false;
  483. TCustomScpExplorerForm::BatchStart(Storage);
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TScpCommanderForm::BatchEnd(void * Storage)
  487. {
  488. TCustomScpExplorerForm::BatchEnd(Storage);
  489. DebugAssert(Storage != NULL);
  490. LocalDirView->WatchForChanges = *static_cast<bool*>(Storage);
  491. LocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  492. OtherLocalDirView->WatchForChanges = LocalDirView->WatchForChanges;
  493. OtherLocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  494. delete Storage;
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TScpCommanderForm::StartingDisconnected()
  498. {
  499. TCustomScpExplorerForm::StartingDisconnected();
  500. LocalDefaultDirectory();
  501. }
  502. //---------------------------------------------------------------------------
  503. void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
  504. {
  505. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = false;
  506. TCustomScpExplorerForm::TerminalChanged(Replaced);
  507. if (Terminal)
  508. {
  509. // we will load completelly different directory, so particularly
  510. // do not attempt to select previously selected directory
  511. LocalDirView->ContinueSession(false);
  512. // reset home directory
  513. LocalDirView->HomeDirectory = L"";
  514. if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  515. {
  516. UnicodeString LocalDirectory = Terminal->StateData->LocalDirectory;
  517. if (!LocalDirectory.IsEmpty())
  518. {
  519. try
  520. {
  521. LocalDirView->Path = LocalDirectory;
  522. }
  523. catch(Exception & E)
  524. {
  525. if (!Terminal->SessionData->UpdateDirectories)
  526. {
  527. Terminal->ShowExtendedException(&E);
  528. }
  529. }
  530. }
  531. }
  532. FFirstTerminal = false;
  533. // Happens when opening a connection from a command-line (StartingDisconnected was not called),
  534. // which does not have a local directory set yet.
  535. if (LocalDirView->Path.IsEmpty())
  536. {
  537. LocalDefaultDirectory();
  538. }
  539. if (WinConfiguration->DefaultDirIsHome &&
  540. !Terminal->SessionData->UpdateDirectories)
  541. {
  542. LocalDirView->HomeDirectory = Terminal->SessionData->LocalDirectoryExpanded;
  543. }
  544. if (WinConfiguration->PreservePanelState &&
  545. !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  546. {
  547. if (Terminal->LocalExplorerState != NULL)
  548. {
  549. LocalDirView->RestoreState(Terminal->LocalExplorerState);
  550. }
  551. else
  552. {
  553. LocalDirView->ClearState();
  554. }
  555. NonVisualDataModule->SynchronizeBrowsingAction2->Checked = Terminal->StateData->SynchronizeBrowsing;
  556. }
  557. }
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TScpCommanderForm::DoLocalDefaultDirectory(TDirView * DirView, const UnicodeString & LastPath)
  561. {
  562. bool DocumentsDir = true;
  563. if (!LastPath.IsEmpty())
  564. {
  565. try
  566. {
  567. DirView->Path = LastPath;
  568. DocumentsDir = false;
  569. }
  570. catch (...)
  571. {
  572. }
  573. }
  574. if (DocumentsDir)
  575. {
  576. try
  577. {
  578. DirView->HomeDirectory = L"";
  579. UnicodeString HomeDrive = DriveInfo->GetDriveKey(DirView->HomeDirectory);
  580. if (DriveInfo->Get(HomeDrive)->DriveType == DRIVE_REMOTE)
  581. {
  582. DirView->Path = DriveInfo->AnyValidPath();
  583. }
  584. else
  585. {
  586. DirView->ExecuteHomeDirectory();
  587. }
  588. }
  589. catch(Exception & E)
  590. {
  591. ShowExtendedException(NULL, &E);
  592. DirView->Path = ExtractFilePath(Application->ExeName);
  593. }
  594. }
  595. }
  596. //---------------------------------------------------------------------------
  597. void __fastcall TScpCommanderForm::LocalDefaultDirectory()
  598. {
  599. DoLocalDefaultDirectory(LocalDirView, WinConfiguration->ScpCommander.LocalPanel.LastPath);
  600. }
  601. //---------------------------------------------------------------------------
  602. void __fastcall TScpCommanderForm::ConfigurationChanged()
  603. {
  604. TCustomScpExplorerForm::ConfigurationChanged();
  605. if (WinConfiguration->DefaultDirIsHome && Terminal &&
  606. !Terminal->SessionData->UpdateDirectories)
  607. {
  608. LocalDirView->HomeDirectory = Terminal->SessionData->LocalDirectoryExpanded;
  609. }
  610. else
  611. {
  612. LocalDirView->HomeDirectory = L"";
  613. }
  614. LocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  615. LocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  616. OtherLocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  617. OtherLocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  618. LocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  619. LocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  620. OtherLocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  621. OtherLocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  622. LocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  623. OtherLocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  624. LocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  625. LocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  626. OtherLocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  627. OtherLocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  628. LocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  629. OtherLocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  630. RemoteDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  631. LocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  632. LocalDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  633. OtherLocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  634. OtherLocalDriveView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  635. LocalDirView->TimeoutShellIconRetrieval = WinConfiguration->TimeoutShellIconRetrieval;
  636. LocalDirView->UseIconUpdateThread = WinConfiguration->UseIconUpdateThread;
  637. OtherLocalDirView->TimeoutShellIconRetrieval = WinConfiguration->TimeoutShellIconRetrieval;
  638. OtherLocalDirView->UseIconUpdateThread = WinConfiguration->UseIconUpdateThread;
  639. UpdateRowSelect(LocalDirView);
  640. UpdateRowSelect(OtherLocalDirView);
  641. // See also LocalDirViewDDTargetHasDropHandler
  642. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  643. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  644. OtherLocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  645. OtherLocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  646. if (Panel(true)->Left > Panel(false)->Left)
  647. {
  648. DisableAlign();
  649. try
  650. {
  651. int AWidth = ClientWidth;
  652. Panel(false)->Align = alClient;
  653. // In bidi mode it gets swapped to alRight, what does not work with the rest of this logic
  654. Splitter->Align = alLeft;
  655. Panel(true)->Align = alLeft;
  656. TControl * ControlsOrder[] =
  657. { Panel(true), Splitter, Panel(false) };
  658. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  659. Panel(true)->TabOrder = 0;
  660. Panel(false)->TabOrder = 1;
  661. ClientWidth = AWidth;
  662. LeftPanelWidth = FLastLeftPanelWidth;
  663. }
  664. __finally
  665. {
  666. EnableAlign();
  667. }
  668. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  669. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  670. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  671. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  672. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  673. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction2->ShortCut, NonVisualDataModule->RemoteChangePathAction2->ShortCut);
  674. SWAP(UnicodeString, NonVisualDataModule->CommanderLocalPanelAction->Caption, NonVisualDataModule->CommanderRemotePanelAction->Caption);
  675. SWAP(UnicodeString, NonVisualDataModule->CommanderLocalPanelAction->Hint, NonVisualDataModule->CommanderRemotePanelAction->Hint);
  676. }
  677. if ((RemoteDrivePanel->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  678. {
  679. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  680. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  681. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  682. // save value only if it was set yet
  683. if (FPanelsRestored)
  684. {
  685. // TODO_OTHER_LOCAL
  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. // TODO_OTHER_LOCAL
  711. if (TreeOnLeft)
  712. {
  713. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  714. RemoteDrivePanel->Width = RemotePanel.DriveViewWidth;
  715. }
  716. else
  717. {
  718. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  719. RemoteDrivePanel->Height = RemotePanel.DriveViewHeight;
  720. }
  721. // in case it trigges config-changed event (does not),
  722. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  723. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  724. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  725. }
  726. if (FExplorerKeyboardShortcuts != WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  727. {
  728. SetShortcuts();
  729. }
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TScpCommanderForm::SetShortcuts()
  733. {
  734. // set common norton shorcuts to our actions
  735. NonVisualDataModule->CommanderShortcuts();
  736. FExplorerKeyboardShortcuts = WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts;
  737. }
  738. //---------------------------------------------------------------------------
  739. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  740. {
  741. bool SwappedPanels = WinConfiguration->ScpCommander.SwappedPanels;
  742. if (IsRightToLeft())
  743. {
  744. SwappedPanels = !SwappedPanels;
  745. }
  746. return (SwappedPanels == Left ? RemotePanel : LocalPanel);
  747. }
  748. //---------------------------------------------------------------------------
  749. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  750. {
  751. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  752. }
  753. //---------------------------------------------------------------------------
  754. void __fastcall TScpCommanderForm::SetLeftPanelWidth(double value)
  755. {
  756. double Total = LocalPanel->Width + RemotePanel->Width;
  757. FLeftPanelWidth = value;
  758. if (value * Total != Panel(true)->Width)
  759. {
  760. Panel(true)->Width = static_cast<int>(value * Total);
  761. UpdateControls();
  762. }
  763. }
  764. //---------------------------------------------------------------------------
  765. double __fastcall TScpCommanderForm::GetLeftPanelWidth()
  766. {
  767. return FLeftPanelWidth;
  768. }
  769. //---------------------------------------------------------------------------
  770. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  771. {
  772. double Left = Panel(true)->Width;
  773. double Total = LocalPanel->Width + RemotePanel->Width;
  774. FLeftPanelWidth = Left / Total;
  775. FLastLeftPanelWidth = LeftPanelWidth;
  776. UpdateControls();
  777. }
  778. //---------------------------------------------------------------------------
  779. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  780. int &NewSize, bool & /*Accept*/)
  781. {
  782. // When splitter is drag so far to right, that width contraint of remote panel would
  783. // be violated, it doesn't stop, but extend form width.
  784. // Following prevents this behavior.
  785. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  786. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  787. }
  788. //---------------------------------------------------------------------------
  789. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  790. {
  791. LeftPanelWidth = 0.5;
  792. }
  793. //---------------------------------------------------------------------------
  794. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  795. {
  796. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  797. DebugAssert(Splitter != NULL);
  798. TControl * DriveView;
  799. TControl * OtherDriveView;
  800. if (Splitter == LocalPanelSplitter)
  801. {
  802. DriveView = LocalDriveView;
  803. OtherDriveView = RemoteDrivePanel;
  804. }
  805. else
  806. {
  807. DriveView = RemoteDrivePanel;
  808. OtherDriveView = LocalDriveView;
  809. }
  810. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  811. DebugAssert(DriveView->Visible);
  812. if (OtherDriveView->Visible)
  813. {
  814. if (TreeOnLeft)
  815. {
  816. DriveView->Width = OtherDriveView->Width;
  817. }
  818. else
  819. {
  820. DriveView->Height = OtherDriveView->Height;
  821. }
  822. }
  823. else
  824. {
  825. if (TreeOnLeft)
  826. {
  827. OtherDriveView->Width = DriveView->Width;
  828. }
  829. else
  830. {
  831. OtherDriveView->Height = DriveView->Height;
  832. }
  833. OtherDriveView->Visible = true;
  834. }
  835. FixControlsPlacement();
  836. }
  837. //---------------------------------------------------------------------------
  838. void __fastcall TScpCommanderForm::UpdateControls()
  839. {
  840. // Before TCustomScpExplorerForm disables them (when disconnecting)
  841. bool DirViewWasFocused = DirView(osOther)->Focused();
  842. bool DriveViewWasFocused = DriveView(osOther)->Focused();
  843. TCustomScpExplorerForm::UpdateControls();
  844. UnicodeString SplitterLongHint = Splitter->Hint;
  845. int P = SplitterLongHint.Pos(L"|");
  846. if (P == 0)
  847. {
  848. P = SplitterLongHint.Pos(L"\n");
  849. }
  850. SplitterLongHint.Delete(1, P);
  851. Splitter->Hint = FORMAT(L"%0.0f%%\n%s", (LeftPanelWidth*100, SplitterLongHint));
  852. UnicodeString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  853. (!IsSideLocalBrowser(FCurrentSide) ? L"$" : L">");
  854. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  855. {
  856. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  857. // command line combo width needs to be updated as caption width has probably changed
  858. ToolBarResize(CommandLineToolbar);
  859. }
  860. LocalDirView->DarkMode = WinConfiguration->UseDarkTheme();
  861. LocalDriveView->DarkMode = LocalDirView->DarkMode;
  862. OtherLocalDirView->DarkMode = LocalDirView->DarkMode;
  863. OtherLocalDriveView->DarkMode = LocalDirView->DarkMode;
  864. LocalDirView->Color = PanelColor();
  865. LocalDriveView->Color = LocalDirView->Color;
  866. OtherLocalDirView->Color = LocalDirView->Color;
  867. OtherLocalDriveView->Color = LocalDirView->Color;
  868. LocalDirView->Font->Color = GetWindowTextColor(LocalDirView->Color);
  869. LocalDriveView->Font->Color = LocalDirView->Font->Color;
  870. OtherLocalDirView->Font->Color = LocalDirView->Font->Color;
  871. OtherLocalDriveView->Font->Color = LocalDirView->Font->Color;
  872. // TODO_OTHER_LOCAL
  873. bool LocalSide = (FCurrentSide == osLocal);
  874. TAction * CurrentCopyAction = LocalSide ? NonVisualDataModule->LocalCopyAction : NonVisualDataModule->RemoteCopyAction;
  875. if (CurrentCopyItem->Action != CurrentCopyAction)
  876. {
  877. CurrentCopyItem->Action = CurrentCopyAction;
  878. CurrentCopyToolbar2Item->Action = CurrentCopyAction;
  879. UpdateToolbar2ItemCaption(CurrentCopyToolbar2Item);
  880. CurrentCopyNonQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyNonQueueAction : NonVisualDataModule->RemoteCopyNonQueueAction;
  881. CurrentCopyQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyQueueAction : NonVisualDataModule->RemoteCopyQueueAction;
  882. TAction * CurrentMoveAction = LocalSide ? NonVisualDataModule->LocalMoveAction : NonVisualDataModule->RemoteMoveAction;
  883. CurrentMoveItem->Action = CurrentMoveAction;
  884. CurrentMoveToolbar2Item->Action = CurrentMoveAction;
  885. UpdateToolbar2ItemCaption(CurrentMoveToolbar2Item);
  886. }
  887. CommandLineCombo->Enabled = IsSideLocalBrowser(FCurrentSide) || CanConsole();
  888. CommandLinePromptLabel->Enabled = CommandLineCombo->Enabled;
  889. // Ad hoc hack to disable the drop down menu, when all its items (and all other buttons on the toolbar) are disabled,
  890. // otherwise it shines too much on the toolbar.
  891. RemoteNewSubmenuItem->Enabled = DirViewEnabled(osRemote);
  892. bool HasTerminal = (Terminal != NULL);
  893. RemoteDirView->Visible = (Terminal != NULL);
  894. RemoteDriveView->Visible = HasTerminal;
  895. OtherLocalDirView->Visible = !HasTerminal;
  896. OtherLocalDriveView->Visible = !HasTerminal;
  897. bool LocalOnLeft = (Panel(true) == LocalPanel);
  898. LocalMenuButton->Caption = LoadStr(HasTerminal ? LOCAL_MENU_CAPTION : (LocalOnLeft ? LEFT_MENU_CAPTION : RIGHT_MENU_CAPTION));
  899. RemoteMenuButton->Caption = LoadStr(HasTerminal ? REMOTE_MENU_CAPTION : (LocalOnLeft ? RIGHT_MENU_CAPTION : LEFT_MENU_CAPTION));
  900. if (DirViewWasFocused)
  901. {
  902. if (DirView(osOther)->Enabled)
  903. {
  904. DirView(osOther)->SetFocus();
  905. }
  906. else
  907. {
  908. LocalDirView->SetFocus();
  909. }
  910. }
  911. if (DriveViewWasFocused)
  912. {
  913. if (DriveView(osOther)->Enabled)
  914. {
  915. DriveView(osOther)->SetFocus();
  916. }
  917. else
  918. {
  919. LocalDriveView->SetFocus();
  920. }
  921. }
  922. if (RemotePathLabel->FocusControl != DirView(osOther))
  923. {
  924. if (DebugAlwaysTrue(RemotePathLabel->FocusControl != NULL))
  925. {
  926. dynamic_cast<TCustomDirView *>(RemotePathLabel->FocusControl)->PathLabel = NULL;
  927. }
  928. DirView(osOther)->PathLabel = RemotePathLabel;
  929. RemotePathLabel->UnixPath = !IsSideLocalBrowser(osOther);
  930. DirView(osOther)->UpdateStatusBar();
  931. }
  932. }
  933. //---------------------------------------------------------------------------
  934. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  935. {
  936. DebugAssert((Side == osLocal) || (Side == osRemote));
  937. TTBXComboBoxItem * PathComboBox;
  938. if (Side == osLocal)
  939. {
  940. PathComboBox = LocalPathComboBox;
  941. }
  942. else
  943. {
  944. PathComboBox = RemotePathComboBox;
  945. }
  946. ClickToolbarItem(PathComboBox, false);
  947. }
  948. //---------------------------------------------------------------------------
  949. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  950. {
  951. switch (Component) {
  952. case fcToolBar2: return Toolbar2Toolbar; // name changed to enforce change of default visibility
  953. case fcStatusBar: return StatusBar;
  954. case fcLocalStatusBar: return LocalStatusBar;
  955. case fcRemoteStatusBar: return RemoteStatusBar;
  956. case fcCommandLinePanel: return CommandLineToolbar;
  957. case fcLocalTree: return LocalDriveView;
  958. case fcSessionToolbar: return SessionToolbar;
  959. case fcCustomCommandsBand: return CustomCommandsToolbar;
  960. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  961. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  962. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  963. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  964. case fcLocalPopup: return reinterpret_cast<TControl *>(NonVisualDataModule->LocalFilePopup);
  965. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(RemotePathComboBox);
  966. case fcCommanderMenuBand: return MenuToolbar;
  967. case fcCommanderSessionBand: return SessionToolbar;
  968. case fcCommanderPreferencesBand: return PreferencesToolbar;
  969. case fcCommanderSortBand: return SortToolbar;
  970. case fcCommanderCommandsBand: return CommandsToolbar;
  971. case fcCommanderUpdatesBand: return UpdatesToolbar;
  972. case fcCommanderTransferBand: return TransferToolbar;
  973. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  974. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  975. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  976. case fcCommanderLocalFileBand: return LocalFileToolbar;
  977. case fcCommanderLocalSelectionBand: return LocalSelectionToolbar;
  978. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  979. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  980. case fcCommanderRemoteFileBand: return RemoteFileToolbar;
  981. case fcCommanderRemoteSelectionBand: return RemoteSelectionToolbar;
  982. default: return TCustomScpExplorerForm::GetComponent(Component);
  983. }
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TScpCommanderForm::FixControlsPlacement()
  987. {
  988. TCustomScpExplorerForm::FixControlsPlacement();
  989. QueueSeparatorPanel->Visible = QueuePanel->Visible;
  990. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  991. TControl * ControlsOrder[] =
  992. { BottomDock, QueueSeparatorPanel, QueueSplitter, QueuePanel, StatusBar };
  993. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  994. TControl * LocalControlsOrder[] =
  995. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  996. LocalDirView, LocalBottomDock, LocalStatusBar };
  997. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  998. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  999. TControl * RemoteControlsOrder[] =
  1000. { RemoteTopDock, RemotePathLabel, RemoteDrivePanel, RemotePanelSplitter,
  1001. RemoteDirPanel, RemoteBottomDock, RemoteStatusBar };
  1002. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1003. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  1004. MakeFocusedItemVisible(LocalDirView);
  1005. MakeFocusedItemVisible(OtherLocalDirView);
  1006. }
  1007. //---------------------------------------------------------------------------
  1008. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  1009. {
  1010. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  1011. }
  1012. //---------------------------------------------------------------------------
  1013. void __fastcall TScpCommanderForm::CompareDirectories()
  1014. {
  1015. LocalDirView->CompareFiles(DirView(osOther), false,
  1016. WinConfiguration->ScpCommander.CompareCriterias());
  1017. DirView(osOther)->CompareFiles(LocalDirView, false,
  1018. WinConfiguration->ScpCommander.CompareCriterias());
  1019. if (LocalDirView->SelCount + DirView(osOther)->SelCount == 0)
  1020. {
  1021. UnicodeString Message = MainInstructions(LoadStr(COMPARE_NO_DIFFERENCES));
  1022. MessageDialog(Message, qtInformation, qaOK, HELP_COMPARE_NO_DIFFERENCES);
  1023. }
  1024. }
  1025. //---------------------------------------------------------------------------
  1026. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  1027. {
  1028. DebugAssert(!IsLocalBrowserMode());
  1029. UnicodeString LocalDirectory = LocalDirView->PathName;
  1030. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1031. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, -1);
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  1035. {
  1036. DebugAssert(!IsLocalBrowserMode());
  1037. UnicodeString LocalDirectory = LocalDirView->PathName;
  1038. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  1039. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  1040. TSynchronizeMode Mode =
  1041. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  1042. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  1043. int Params = GUIConfiguration->SynchronizeParams;
  1044. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, Params, SaveMode, -1) >= 0)
  1045. {
  1046. if (SaveMode)
  1047. {
  1048. GUIConfiguration->SynchronizeModeAuto = Mode;
  1049. }
  1050. }
  1051. }
  1052. //---------------------------------------------------------------------------
  1053. void __fastcall TScpCommanderForm::ExploreLocalDirectory(TOperationSide Side)
  1054. {
  1055. DebugAssert(IsSideLocalBrowser(Side));
  1056. OpenFolderInExplorer(DirView(Side)->Path);
  1057. }
  1058. //---------------------------------------------------------------------------
  1059. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  1060. TListItem *Item, bool &AllowExec)
  1061. {
  1062. DebugAssert(Item);
  1063. TDirView * ADirView = DebugNotNull(dynamic_cast<TDirView *>(Sender));
  1064. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  1065. DirectoryExists(ApiPath(ResolveFileShortCut(ADirView->ItemFullFileName(Item), true))))
  1066. {
  1067. AllowExec = true;
  1068. }
  1069. else
  1070. {
  1071. DoDirViewExecFile(Sender, Item, AllowExec);
  1072. }
  1073. }
  1074. //---------------------------------------------------------------------------
  1075. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  1076. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  1077. bool &Accept)
  1078. {
  1079. // LocalDirViewDDDragEnter is duplication of
  1080. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  1081. // literal type of 'DataObj' parameter.Actual type is however same
  1082. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  1086. bool DragDrop)
  1087. {
  1088. // TODO
  1089. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  1090. (DropSourceControl == LocalDirView);
  1091. }
  1092. //---------------------------------------------------------------------------
  1093. void __fastcall TScpCommanderForm::FileOperationProgress(
  1094. TFileOperationProgressType & ProgressData)
  1095. {
  1096. // Heuristic: When operation finishes and DD targed is local dir view,
  1097. // we suppose that drag&drop download finished, so local dir view should be
  1098. // reloaded
  1099. // TODO
  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. // TODO_OTHER_LOCAL
  1491. DebugAssert(!IsLocalBrowserMode());
  1492. bool Result;
  1493. if (WinConfiguration->UseLocationProfiles)
  1494. {
  1495. DoOpenBookmark(Bookmark->Local, Bookmark->Remote);
  1496. Result = true;
  1497. }
  1498. else
  1499. {
  1500. Result = TCustomScpExplorerForm::OpenBookmark(Side, Bookmark);
  1501. }
  1502. return Result;
  1503. }
  1504. //---------------------------------------------------------------------------
  1505. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1506. TObject * Sender, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1507. {
  1508. // When drop target is not directory, it is probably file type, which have
  1509. // associated drop handler (such as EXE file). In this case we
  1510. // cannot allow drop when when using shellex,
  1511. // as drop handlers are disabled, so drop would error
  1512. // (see TShellExtension.DropHandler assignment in ConfigurationChanged),
  1513. if (WinConfiguration->DDFakeFile &&
  1514. !DebugNotNull(dynamic_cast<TDirView *>(Sender))->ItemIsDirectory(Item))
  1515. {
  1516. DropHandler = false;
  1517. }
  1518. }
  1519. //---------------------------------------------------------------------------
  1520. bool __fastcall TScpCommanderForm::DDGetTarget(
  1521. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  1522. {
  1523. bool Result;
  1524. if (!FDDFakeFileTarget.IsEmpty())
  1525. {
  1526. Directory = FDDFakeFileTarget;
  1527. FDDFakeFileTarget = L"";
  1528. Result = true;
  1529. CounterName = L"DownloadsDragDropInternal";
  1530. ForceQueue = false;
  1531. }
  1532. else
  1533. {
  1534. Result = TCustomScpExplorerForm::DDGetTarget(Directory, ForceQueue, CounterName);
  1535. }
  1536. return Result;
  1537. }
  1538. //---------------------------------------------------------------------------
  1539. void __fastcall TScpCommanderForm::DDFakeFileInitDrag(TFileList * FileList,
  1540. bool & Created)
  1541. {
  1542. FDDFakeFileTarget = L"";
  1543. TCustomScpExplorerForm::DDFakeFileInitDrag(FileList, Created);
  1544. }
  1545. //---------------------------------------------------------------------------
  1546. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1547. TObject * /*Sender*/, int dwEffect, UnicodeString SourcePath,
  1548. UnicodeString TargetPath, bool Paste, bool & DoOperation)
  1549. {
  1550. if (IsFileControl(DropSourceControl, osRemote) && !IsLocalBrowserMode())
  1551. {
  1552. UnicodeString TargetDirectory;
  1553. if (InternalDDDownload(TargetDirectory))
  1554. {
  1555. // See TCustomScpExplorerForm::QueueDDProcessDropped
  1556. if (FDDExtMapFile != NULL)
  1557. {
  1558. FDDFakeFileTarget = TargetDirectory;
  1559. }
  1560. else
  1561. {
  1562. DebugAssert(FInternalDDDownloadList->Count > 0);
  1563. DebugAssert(dwEffect == DROPEFFECT_COPY || dwEffect == DROPEFFECT_MOVE);
  1564. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1565. TTransferType TransferType = dwEffect == DROPEFFECT_COPY ? ttCopy : ttMove;
  1566. int Options =
  1567. FLAGMASK(DraggingAllFilesFromDirView(osRemote, FInternalDDDownloadList), coAllFiles);
  1568. bool NoConfirmation = Paste ? false : (WinConfiguration->DDTransferConfirmation == asOff);
  1569. if (CopyParamDialog(tdToLocal, TransferType,
  1570. false, FInternalDDDownloadList, TargetDirectory, CopyParams, NoConfirmation, true, Options))
  1571. {
  1572. int Params =
  1573. (TransferType == ttMove ? cpDelete : 0);
  1574. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1575. &CopyParams, Params);
  1576. Configuration->Usage->Inc(L"DownloadsDragDropInternal");
  1577. FInternalDDDownloadList->Clear();
  1578. }
  1579. }
  1580. DoOperation = false;
  1581. }
  1582. }
  1583. }
  1584. //---------------------------------------------------------------------------
  1585. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1586. TObject * /*Sender*/, int dwEffect, UnicodeString /*SourcePath*/,
  1587. UnicodeString /*TargetPath*/)
  1588. {
  1589. if ((dwEffect == DROPEFFECT_MOVE) &&
  1590. IsFileControl(DropSourceControl, osLocal))
  1591. {
  1592. ReloadLocalDirectory();
  1593. }
  1594. }
  1595. //---------------------------------------------------------------------------
  1596. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1597. {
  1598. SideEnter(osLocal);
  1599. }
  1600. //---------------------------------------------------------------------------
  1601. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1602. {
  1603. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1604. SideEnter(osLocal);
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1608. {
  1609. if (Visible && (IsSideLocalBrowser(FCurrentSide) != IsSideLocalBrowser(Side)))
  1610. {
  1611. // this may get called yet before controls are initialized
  1612. CommandLineCombo->Strings->Clear();
  1613. FCommandLineComboPopulated = false;
  1614. }
  1615. TCustomScpExplorerForm::SideEnter(Side);
  1616. if (Visible)
  1617. {
  1618. UpdateControls();
  1619. UpdatePanelsPathLabelsStatus();
  1620. }
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TScpCommanderForm::UpdatePanelsPathLabelsStatus()
  1624. {
  1625. // TODO_OTHER_LOCAL
  1626. LocalPathLabel->UpdateStatus();
  1627. RemotePathLabel->UpdateStatus();
  1628. }
  1629. //---------------------------------------------------------------------------
  1630. void __fastcall TScpCommanderForm::OpenConsole(UnicodeString Command)
  1631. {
  1632. SaveCommandLine();
  1633. try
  1634. {
  1635. TCustomScpExplorerForm::OpenConsole(Command);
  1636. }
  1637. __finally
  1638. {
  1639. FCommandLineComboPopulated = false;
  1640. }
  1641. }
  1642. //---------------------------------------------------------------------------
  1643. void __fastcall TScpCommanderForm::SaveCommandLine()
  1644. {
  1645. if (FCommandLineComboPopulated)
  1646. {
  1647. CustomWinConfiguration->History[
  1648. !IsSideLocalBrowser(FCurrentSide) ? L"Commands" : L"LocalCommands"] =
  1649. CommandLineCombo->Strings;
  1650. }
  1651. }
  1652. //---------------------------------------------------------------------------
  1653. bool __fastcall TScpCommanderForm::ExecuteCommandLine()
  1654. {
  1655. UnicodeString Command = CommandLineCombo->Text;
  1656. bool Result =
  1657. !NonVisualDataModule->Busy &&
  1658. !Command.IsEmpty() &&
  1659. (IsSideLocalBrowser(FCurrentSide) ||
  1660. (Terminal->AllowedAnyCommand(Command) &&
  1661. EnsureCommandSessionFallback(fcAnyCommand)));
  1662. if (Result)
  1663. {
  1664. CommandLinePopulate();
  1665. SaveToHistory(CommandLineCombo->Strings, Command);
  1666. CommandLineCombo->Text = L"";
  1667. if (!IsSideLocalBrowser(FCurrentSide))
  1668. {
  1669. OpenConsole(Command);
  1670. }
  1671. else
  1672. {
  1673. ExecuteShellChecked(Command);
  1674. }
  1675. }
  1676. return Result;
  1677. }
  1678. //---------------------------------------------------------------------------
  1679. void __fastcall TScpCommanderForm::CommandLinePopulate()
  1680. {
  1681. if (!FCommandLineComboPopulated)
  1682. {
  1683. TStrings * CommandsHistory;
  1684. CommandsHistory = CustomWinConfiguration->History[
  1685. !IsSideLocalBrowser(FCurrentSide) ? L"Commands" : L"LocalCommands"];
  1686. if ((CommandsHistory != NULL) && (CommandsHistory->Count > 0))
  1687. {
  1688. CommandLineCombo->Strings = CommandsHistory;
  1689. }
  1690. else
  1691. {
  1692. CommandLineCombo->Strings->Clear();
  1693. }
  1694. FCommandLineComboPopulated = true;
  1695. }
  1696. }
  1697. //---------------------------------------------------------------------------
  1698. void __fastcall TScpCommanderForm::GoToCommandLine()
  1699. {
  1700. ComponentVisible[fcCommandLinePanel] = true;
  1701. if (CommandLineCombo->Enabled)
  1702. {
  1703. ClickToolbarItem(CommandLineCombo, true);
  1704. }
  1705. }
  1706. //---------------------------------------------------------------------------
  1707. void __fastcall TScpCommanderForm::GoToTree()
  1708. {
  1709. if (FCurrentSide == osLocal)
  1710. {
  1711. ComponentVisible[fcLocalTree] = true;
  1712. LocalDriveView->SetFocus();
  1713. }
  1714. else
  1715. {
  1716. TCustomScpExplorerForm::GoToTree();
  1717. }
  1718. }
  1719. //---------------------------------------------------------------------------
  1720. void __fastcall TScpCommanderForm::PanelExportStore(TOperationSide Side,
  1721. TPanelExport Export, TPanelExportDestination Destination,
  1722. TStrings * ExportData)
  1723. {
  1724. if (Destination == pedCommandLine)
  1725. {
  1726. ComponentVisible[fcCommandLinePanel] = true;
  1727. UnicodeString Buf;
  1728. for (int Index = 0; Index < ExportData->Count; Index++)
  1729. {
  1730. Buf += ExportData->Strings[Index] + L" ";
  1731. }
  1732. CommandLineCombo->Text = CommandLineCombo->Text + Buf;
  1733. }
  1734. else
  1735. {
  1736. TCustomScpExplorerForm::PanelExportStore(Side, Export, Destination, ExportData);
  1737. }
  1738. }
  1739. //---------------------------------------------------------------------------
  1740. int __fastcall TScpCommanderForm::GetStaticComponentsHeight()
  1741. {
  1742. return TCustomScpExplorerForm::GetStaticComponentsHeight() +
  1743. (BottomDock->Visible ? BottomDock->Height : 0) +
  1744. (QueueSeparatorPanel->Visible ? QueueSeparatorPanel->Height : 0) +
  1745. (StatusBar->Visible ? StatusBar->Height : 0);
  1746. }
  1747. //---------------------------------------------------------------------------
  1748. void __fastcall TScpCommanderForm::SysResizing(unsigned int Cmd)
  1749. {
  1750. TCustomScpExplorerForm::SysResizing(Cmd);
  1751. if ((Cmd == SC_MAXIMIZE) ||
  1752. ((Cmd == SC_DEFAULT) && (WindowState != wsMaximized)))
  1753. {
  1754. FNormalPanelsWidth = LocalPanel->Width + RemotePanel->Width;
  1755. }
  1756. else if ((Cmd == SC_RESTORE) ||
  1757. ((Cmd == SC_DEFAULT) && (WindowState == wsMaximized)))
  1758. {
  1759. if (FNormalPanelsWidth >= 0)
  1760. {
  1761. Panel(true)->Width = static_cast<int>(FLeftPanelWidth * FNormalPanelsWidth);
  1762. FNormalPanelsWidth = -1;
  1763. }
  1764. }
  1765. }
  1766. //---------------------------------------------------------------------------
  1767. void __fastcall TScpCommanderForm::Resize()
  1768. {
  1769. TCustomScpExplorerForm::Resize();
  1770. LeftPanelWidth = FLastLeftPanelWidth;
  1771. UpdateControls();
  1772. }
  1773. //---------------------------------------------------------------------------
  1774. void __fastcall TScpCommanderForm::PathLabelDblClick(TObject * Sender)
  1775. {
  1776. if (!NonVisualDataModule->Busy)
  1777. {
  1778. OpenDirectory(Sender == LocalPathLabel ? osLocal : osRemote);
  1779. }
  1780. }
  1781. //---------------------------------------------------------------------------
  1782. void __fastcall TScpCommanderForm::LocalPathLabelGetStatus(
  1783. TCustomPathLabel * /*Sender*/, bool & Active)
  1784. {
  1785. // WORKAROUND this strange form is here to make borland compiler work :-)
  1786. Active = Active || LocalDriveView->Focused();
  1787. }
  1788. //---------------------------------------------------------------------------
  1789. void __fastcall TScpCommanderForm::RemotePathLabelGetStatus(
  1790. TCustomPathLabel * /*Sender*/, bool & Active)
  1791. {
  1792. // WORKAROUND this strange form is here to make borland compiler work :-)
  1793. Active = Active || DriveView(osOther)->Focused();
  1794. }
  1795. //---------------------------------------------------------------------------
  1796. void __fastcall TScpCommanderForm::DoPathLabelPathClick(TOperationSide Side, const UnicodeString & Path)
  1797. {
  1798. if (!NonVisualDataModule->Busy)
  1799. {
  1800. TCustomDirView * ADirView = DirView(Side);
  1801. bool Same;
  1802. if (IsSideLocalBrowser(Side))
  1803. {
  1804. Same = SamePaths(Path, ADirView->Path);
  1805. }
  1806. else
  1807. {
  1808. Same = UnixSamePath(Path, ADirView->Path);
  1809. }
  1810. if (Same)
  1811. {
  1812. OpenDirectory(Side);
  1813. }
  1814. else
  1815. {
  1816. ADirView->Path = Path;
  1817. }
  1818. }
  1819. }
  1820. //---------------------------------------------------------------------------
  1821. void __fastcall TScpCommanderForm::LocalPathLabelPathClick(
  1822. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1823. {
  1824. DoPathLabelPathClick(osLocal, Path);
  1825. }
  1826. //---------------------------------------------------------------------------
  1827. void __fastcall TScpCommanderForm::RemotePathLabelPathClick(
  1828. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1829. {
  1830. DoPathLabelPathClick(osOther, Path);
  1831. }
  1832. //---------------------------------------------------------------------------
  1833. void __fastcall TScpCommanderForm::LocalDirViewFileIconForName(
  1834. TObject * /*Sender*/, TListItem * /*Item*/, UnicodeString & FileName)
  1835. {
  1836. UnicodeString PartialExt = Configuration->PartialExt;
  1837. if (AnsiSameText(ExtractFileExt(FileName), PartialExt))
  1838. {
  1839. FileName.SetLength(FileName.Length() - PartialExt.Length());
  1840. }
  1841. if (WinConfiguration->LocalIconsByExt)
  1842. {
  1843. FileName = ExtractFileName(FileName);
  1844. }
  1845. }
  1846. //---------------------------------------------------------------------------
  1847. void __fastcall TScpCommanderForm::LocalDirViewUpdateStatusBar(
  1848. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1849. {
  1850. UpdateFileStatusBar(LocalStatusBar, FileInfo, osLocal);
  1851. }
  1852. //---------------------------------------------------------------------------
  1853. void __fastcall TScpCommanderForm::RemoteDirViewUpdateStatusBar(
  1854. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1855. {
  1856. UpdateFileStatusBar(RemoteStatusBar, FileInfo, osRemote);
  1857. }
  1858. //---------------------------------------------------------------------------
  1859. void __fastcall TScpCommanderForm::OtherLocalDirViewUpdateStatusBar(TObject *, const TStatusFileInfo & FileInfo)
  1860. {
  1861. UpdateFileStatusBar(RemoteStatusBar, FileInfo, osOther);
  1862. }
  1863. //---------------------------------------------------------------------------
  1864. void __fastcall TScpCommanderForm::LocalStatusBarClick(TObject * /*Sender*/)
  1865. {
  1866. LocalDirView->SetFocus();
  1867. }
  1868. //---------------------------------------------------------------------------
  1869. UnicodeString __fastcall TScpCommanderForm::PathForCaption()
  1870. {
  1871. UnicodeString Result;
  1872. if (IsSideLocalBrowser(FCurrentSide))
  1873. {
  1874. // for consistency do not show even local path when there is no terminal
  1875. if (Terminal != NULL)
  1876. {
  1877. switch (WinConfiguration->PathInCaption)
  1878. {
  1879. case picShort:
  1880. {
  1881. Result = ExtractFileName(GetCurrentLocalBrowser()->PathName);
  1882. if (Result.IsEmpty())
  1883. {
  1884. Result = GetCurrentLocalBrowser()->PathName;
  1885. }
  1886. }
  1887. break;
  1888. case picFull:
  1889. Result = GetCurrentLocalBrowser()->PathName;
  1890. break;
  1891. }
  1892. }
  1893. }
  1894. else
  1895. {
  1896. Result = TCustomScpExplorerForm::PathForCaption();
  1897. }
  1898. return Result;
  1899. }
  1900. //---------------------------------------------------------------------------
  1901. void __fastcall TScpCommanderForm::GetTransferPresetAutoSelectData(
  1902. TCopyParamRuleData & Data)
  1903. {
  1904. TCustomScpExplorerForm::GetTransferPresetAutoSelectData(Data);
  1905. Data.LocalDirectory = LocalDirView->PathName;
  1906. }
  1907. //---------------------------------------------------------------------------
  1908. void __fastcall TScpCommanderForm::RemoteDirViewPathChange(TCustomDirView * /*Sender*/)
  1909. {
  1910. UpdateRemotePathComboBox(false);
  1911. ResetIncrementalSearch();
  1912. }
  1913. //---------------------------------------------------------------------------
  1914. void __fastcall TScpCommanderForm::UpdateImages()
  1915. {
  1916. TCustomScpExplorerForm::UpdateImages();
  1917. TImageList * ImageList = ShellImageListForControl(this, ilsSmall);
  1918. RemotePathComboBox->Images = ImageList;
  1919. RemotePathComboBox->SubMenuImages = ImageList;
  1920. LocalPathComboBox->Images = ImageList;
  1921. LocalPathComboBox->SubMenuImages = ImageList;
  1922. }
  1923. //---------------------------------------------------------------------------
  1924. void __fastcall TScpCommanderForm::LocalPathComboUpdateDrives()
  1925. {
  1926. FLocalSpecialPaths = 0;
  1927. TStrings* Strings = LocalPathComboBox->Strings;
  1928. Strings->BeginUpdate();
  1929. try
  1930. {
  1931. Strings->Clear();
  1932. FLocalPathComboBoxPaths->Clear();
  1933. Strings->Add(LoadStr(SPECIAL_FOLDER_MY_DOCUMENTS));
  1934. FLocalPathComboBoxPaths->AddObject(GetPersonalFolder(),
  1935. (TObject *)DriveInfo->SpecialFolder[CSIDL_PERSONAL]->ImageIndex);
  1936. FLocalSpecialPaths++;
  1937. Strings->Add(LoadStr(SPECIAL_FOLDER_DESKTOP));
  1938. FLocalPathComboBoxPaths->AddObject(GetDesktopFolder(),
  1939. (TObject *)DriveInfo->SpecialFolder[CSIDL_DESKTOP]->ImageIndex);
  1940. FLocalSpecialPaths++;
  1941. std::unique_ptr<TStrings> Drives(LocalDriveView->GetDrives());
  1942. for (int Index = 0; Index < Drives->Count; Index++)
  1943. {
  1944. UnicodeString Drive = Drives->Strings[Index];
  1945. if (DriveInfo->Get(Drive)->Valid)
  1946. {
  1947. UnicodeString Caption = DriveInfo->GetPrettyName(Drive);
  1948. if (DriveInfo->IsRealDrive(Drive))
  1949. {
  1950. Caption.Insert(L"&", 0);
  1951. }
  1952. Strings->Add(Caption);
  1953. UnicodeString RootPath = DriveInfo->GetDriveRoot(Drive);
  1954. int ImageIndex = DriveInfo->GetImageIndex(Drive);
  1955. FLocalPathComboBoxPaths->AddObject(RootPath, reinterpret_cast<TObject *>(ImageIndex));
  1956. }
  1957. }
  1958. }
  1959. __finally
  1960. {
  1961. Strings->EndUpdate();
  1962. }
  1963. if (IsLocalBrowserMode())
  1964. {
  1965. UpdateRemotePathComboBox(false);
  1966. }
  1967. }
  1968. //---------------------------------------------------------------------------
  1969. void __fastcall TScpCommanderForm::LocalPathComboUpdate(TCustomDirView * ADirView, TTBXComboBoxItem * PathComboBox)
  1970. {
  1971. // this may get called even after destructor finishes
  1972. // (e.g. from SetDockAllowDrag invoked [indirectly] from StoreParams)
  1973. if (FLocalPathComboBoxPaths != NULL)
  1974. {
  1975. DebugAssert(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  1976. int Index = 0;
  1977. while ((Index < FLocalPathComboBoxPaths->Count) &&
  1978. !SamePaths(FLocalPathComboBoxPaths->Strings[Index],
  1979. ADirView->Path.SubString(1, FLocalPathComboBoxPaths->Strings[Index].Length())))
  1980. {
  1981. Index++;
  1982. }
  1983. // what to do if not?
  1984. if (Index < FLocalPathComboBoxPaths->Count)
  1985. {
  1986. PathComboBox->ItemIndex = Index;
  1987. }
  1988. }
  1989. }
  1990. //---------------------------------------------------------------------------
  1991. void __fastcall TScpCommanderForm::DoLocalDirViewPathChange(TCustomDirView * Sender, TTBXComboBoxItem * PathComboBox)
  1992. {
  1993. LocalPathComboUpdate(Sender, PathComboBox);
  1994. ResetIncrementalSearch();
  1995. if (IsUncPath(Sender->Path))
  1996. {
  1997. Configuration->Usage->Inc(L"BrowsedUncPath");
  1998. }
  1999. }
  2000. //---------------------------------------------------------------------------
  2001. void __fastcall TScpCommanderForm::LocalDirViewPathChange(TCustomDirView * Sender)
  2002. {
  2003. DoLocalDirViewPathChange(Sender, LocalPathComboBox);
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. void __fastcall TScpCommanderForm::LocalPathComboBoxCancel(TObject * /*Sender*/)
  2007. {
  2008. LocalPathComboUpdate(LocalDirView, LocalPathComboBox);
  2009. }
  2010. //---------------------------------------------------------------------------
  2011. void __fastcall TScpCommanderForm::DoLocalPathComboBoxAdjustImageIndex(
  2012. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex, int & ImageIndex)
  2013. {
  2014. // this may get called even before constructor starts
  2015. // (e.g. from FixControlsPlacement)
  2016. if (FLocalPathComboBoxPaths != NULL)
  2017. {
  2018. TTBXComboBoxItem * PathComboBox = DebugNotNull(dynamic_cast<TTBXComboBoxItem *>(Sender));
  2019. DebugAssert(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  2020. DebugAssert(AIndex < FLocalPathComboBoxPaths->Count);
  2021. if (AIndex < 0)
  2022. {
  2023. AIndex = PathComboBox->ItemIndex;
  2024. }
  2025. if (AIndex >= 0)
  2026. {
  2027. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  2028. }
  2029. }
  2030. }
  2031. //---------------------------------------------------------------------------
  2032. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  2033. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex,
  2034. int & ImageIndex)
  2035. {
  2036. DoLocalPathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2037. }
  2038. //---------------------------------------------------------------------------
  2039. void __fastcall TScpCommanderForm::DoLocalPathComboBoxItemClick(TDirView * ADirView, TTBXComboBoxItem * PathComboBox)
  2040. {
  2041. DebugAssert(FLocalPathComboBoxPaths->Count == PathComboBox->Strings->Count);
  2042. DebugAssert((PathComboBox->ItemIndex >= 0) && (PathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  2043. UnicodeString Path = FLocalPathComboBoxPaths->Strings[PathComboBox->ItemIndex];
  2044. if (PathComboBox->ItemIndex >= FLocalSpecialPaths)
  2045. {
  2046. ADirView->ExecuteDrive(DriveInfo->GetDriveKey(Path));
  2047. }
  2048. else
  2049. {
  2050. ADirView->Path = Path;
  2051. }
  2052. }
  2053. //---------------------------------------------------------------------------
  2054. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject *)
  2055. {
  2056. DoLocalPathComboBoxItemClick(LocalDirView, LocalPathComboBox);
  2057. }
  2058. //---------------------------------------------------------------------------
  2059. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  2060. {
  2061. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  2062. if ((Item == LocalPathComboBox) ||
  2063. (Item == RemotePathComboBox) ||
  2064. (Item == CommandLineCombo))
  2065. {
  2066. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  2067. }
  2068. }
  2069. //---------------------------------------------------------------------------
  2070. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  2071. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2072. {
  2073. CommandLinePopulate();
  2074. }
  2075. //---------------------------------------------------------------------------
  2076. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  2077. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  2078. {
  2079. InstallPathWordBreakProc(EditControl);
  2080. FCommandLineComboEdit = EditControl;
  2081. FToolbarEditOldWndProc = EditControl->WindowProc;
  2082. EditControl->WindowProc = CommandLineComboEditWndProc;
  2083. }
  2084. //---------------------------------------------------------------------------
  2085. void __fastcall TScpCommanderForm::ExitToolbar()
  2086. {
  2087. CurrentPanel()->SetFocus();
  2088. }
  2089. //---------------------------------------------------------------------------
  2090. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  2091. {
  2092. bool Handled = false;
  2093. if (Message.Msg == WM_CHAR)
  2094. {
  2095. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  2096. {
  2097. case VK_ESCAPE:
  2098. CommandLineCombo->Text = L"";
  2099. ExitToolbar();
  2100. Handled = true;
  2101. break;
  2102. case VK_TAB:
  2103. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  2104. ExitToolbar();
  2105. Handled = true;
  2106. break;
  2107. case VK_RETURN:
  2108. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  2109. ExitToolbar();
  2110. if (!ExecuteCommandLine())
  2111. {
  2112. // re-enter command line
  2113. // (most probably exited by now as message dialog was shown)
  2114. GoToCommandLine();
  2115. }
  2116. Handled = true;
  2117. break;
  2118. }
  2119. }
  2120. if (!Handled)
  2121. {
  2122. FToolbarEditOldWndProc(Message);
  2123. }
  2124. }
  2125. //---------------------------------------------------------------------------
  2126. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  2127. {
  2128. LocalPathComboUpdateDrives();
  2129. LocalPathComboUpdate(LocalDirView, LocalPathComboBox);
  2130. if (IsLocalBrowserMode())
  2131. {
  2132. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2133. }
  2134. }
  2135. //---------------------------------------------------------------------------
  2136. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  2137. {
  2138. bool SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction2->Checked;
  2139. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2140. TCustomScpExplorerForm::HomeDirectory(Side);
  2141. if (SynchronizeBrowsing)
  2142. {
  2143. TCustomScpExplorerForm::HomeDirectory(GetOtherSize(Side));
  2144. }
  2145. }
  2146. //---------------------------------------------------------------------------
  2147. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  2148. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2149. {
  2150. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  2151. }
  2152. //---------------------------------------------------------------------------
  2153. void __fastcall TScpCommanderForm::DoFocusRemotePath(TTerminal * Terminal, const UnicodeString & Path)
  2154. {
  2155. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2156. TCustomScpExplorerForm::DoFocusRemotePath(Terminal, Path);
  2157. }
  2158. //---------------------------------------------------------------------------
  2159. TOperationSide __fastcall TScpCommanderForm::GetOtherSize(TOperationSide Side)
  2160. {
  2161. Side = GetSide(Side);
  2162. return ReverseOperationSide(Side);
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TScpCommanderForm::HistoryGo(TOperationSide Side, int Index)
  2166. {
  2167. TOperationSide OtherSide = GetOtherSize(Side);
  2168. if (NonVisualDataModule->SynchronizeBrowsingAction2->Checked &&
  2169. ((Index < 0) ? (-Index < DirView(OtherSide)->BackCount) : (Index < DirView(OtherSide)->ForwardCount)))
  2170. {
  2171. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  2172. TCustomScpExplorerForm::HistoryGo(Side, Index);
  2173. TCustomScpExplorerForm::HistoryGo(OtherSide, Index);
  2174. }
  2175. else
  2176. {
  2177. TCustomScpExplorerForm::HistoryGo(Side, Index);
  2178. }
  2179. }
  2180. //---------------------------------------------------------------------------
  2181. void __fastcall TScpCommanderForm::DirViewHistoryGo(
  2182. TCustomDirView * Sender, int Index, bool & Cancel)
  2183. {
  2184. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  2185. HistoryGo(Side, Index);
  2186. Cancel = true;
  2187. }
  2188. //---------------------------------------------------------------------------
  2189. bool __fastcall TScpCommanderForm::EligibleForImageDisplayMode(TTBCustomItem * Item)
  2190. {
  2191. return
  2192. TCustomScpExplorerForm::EligibleForImageDisplayMode(Item) &&
  2193. ((Item->Parent == NULL) || (Item->Parent->ParentComponent != Toolbar2Toolbar));
  2194. }
  2195. //---------------------------------------------------------------------------
  2196. bool __fastcall TScpCommanderForm::UpdateToolbarDisplayMode()
  2197. {
  2198. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  2199. if (Result)
  2200. {
  2201. // command line combo width needs to be updated as caption visibility has changed
  2202. ToolBarResize(CommandLineToolbar);
  2203. }
  2204. return Result;
  2205. }
  2206. //---------------------------------------------------------------------------
  2207. void __fastcall TScpCommanderForm::QueueLabelUpdateStatus()
  2208. {
  2209. TCustomScpExplorerForm::QueueLabelUpdateStatus();
  2210. // this is here to deactivate panels path labels when moving focus from
  2211. // directory tree to queue
  2212. UpdatePanelsPathLabelsStatus();
  2213. }
  2214. //---------------------------------------------------------------------------
  2215. void __fastcall TScpCommanderForm::DoLocalDirViewContextPopup(TOperationSide Side, TPoint & MousePos, bool & Handled)
  2216. {
  2217. if (!WinConfiguration->ScpCommander.SystemContextMenu && !FForceSystemContextMenu)
  2218. {
  2219. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalOpenMenuItem, dcaOpen);
  2220. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalEditMenuItem, dcaEdit);
  2221. DirViewContextPopupDefaultItem(Side, NonVisualDataModule->LocalCopyMenuItem, dcaCopy);
  2222. DirViewContextPopup(Side, fcLocalPopup, MousePos);
  2223. Handled = true;
  2224. }
  2225. }
  2226. //---------------------------------------------------------------------------
  2227. void __fastcall TScpCommanderForm::LocalDirViewContextPopup(TObject *, TPoint & MousePos, bool & Handled)
  2228. {
  2229. DoLocalDirViewContextPopup(osLocal, MousePos, Handled);
  2230. }
  2231. //---------------------------------------------------------------------------
  2232. void __fastcall TScpCommanderForm::OtherLocalDirViewContextPopup(TObject *, TPoint & MousePos, bool & Handled)
  2233. {
  2234. DoLocalDirViewContextPopup(osOther, MousePos, Handled);
  2235. }
  2236. //---------------------------------------------------------------------------
  2237. void __fastcall TScpCommanderForm::DisplaySystemContextMenu()
  2238. {
  2239. TAutoFlag Flag(FForceSystemContextMenu);
  2240. if ((FLastContextPopupScreenPoint.x >= 0) && (FLastContextPopupScreenPoint.Y >= 0))
  2241. {
  2242. DirView(osCurrent)->DisplayContextMenu(FLastContextPopupScreenPoint);
  2243. }
  2244. else
  2245. {
  2246. DirView(osCurrent)->DisplayContextMenuInSitu();
  2247. }
  2248. }
  2249. //---------------------------------------------------------------------------
  2250. void __fastcall TScpCommanderForm::LocalStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2251. TTBXStatusPanel * Panel)
  2252. {
  2253. FileStatusBarPanelClick(Panel, osLocal);
  2254. }
  2255. //---------------------------------------------------------------------------
  2256. void __fastcall TScpCommanderForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2257. TTBXStatusPanel *Panel)
  2258. {
  2259. FileStatusBarPanelClick(Panel, osRemote);
  2260. }
  2261. //---------------------------------------------------------------------------
  2262. void __fastcall TScpCommanderForm::GoToAddress()
  2263. {
  2264. OpenDirectory(GetSide(osCurrent));
  2265. }
  2266. //---------------------------------------------------------------------------
  2267. void __fastcall TScpCommanderForm::RemotePathLabelMaskClick(TObject * /*Sender*/)
  2268. {
  2269. Filter(osRemote);
  2270. }
  2271. //---------------------------------------------------------------------------
  2272. void __fastcall TScpCommanderForm::LocalPathLabelMaskClick(TObject * /*Sender*/)
  2273. {
  2274. Filter(osLocal);
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TScpCommanderForm::LocalOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2278. {
  2279. CreateOpenDirMenu(LocalOpenDirButton, osLocal);
  2280. }
  2281. //---------------------------------------------------------------------------
  2282. void __fastcall TScpCommanderForm::RemoteOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2283. {
  2284. CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
  2285. }
  2286. //---------------------------------------------------------------------------
  2287. void __fastcall TScpCommanderForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
  2288. {
  2289. if (IsSideLocalBrowser(Side))
  2290. {
  2291. TInstantOperationVisualizer Visualizer;
  2292. dynamic_cast<TDirView *>(DirView(Side))->CopyToClipBoard(OnFocused);
  2293. }
  2294. else
  2295. {
  2296. TCustomScpExplorerForm::CopyFilesToClipboard(Side, OnFocused);
  2297. }
  2298. }
  2299. //---------------------------------------------------------------------------
  2300. void __fastcall TScpCommanderForm::PasteFromClipBoard()
  2301. {
  2302. if (DoesClipboardContainOurFiles() && (IsSideLocalBrowser(osCurrent)))
  2303. {
  2304. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  2305. {
  2306. ClipboardDownload(DirView(osCurrent)->Path, !WinConfiguration->ConfirmTransferring, false);
  2307. }
  2308. }
  2309. else
  2310. {
  2311. TCustomScpExplorerForm::PasteFromClipBoard();
  2312. }
  2313. }
  2314. //---------------------------------------------------------------------------
  2315. void __fastcall TScpCommanderForm::FileColorsChanged()
  2316. {
  2317. TCustomScpExplorerForm::FileColorsChanged();
  2318. DoFileColorsChanged(LocalDirView);
  2319. DoFileColorsChanged(OtherLocalDirView);
  2320. }
  2321. //---------------------------------------------------------------------------
  2322. void __fastcall TScpCommanderForm::BrowseFile()
  2323. {
  2324. DebugAssert(!IsLocalBrowserMode());
  2325. TCustomScpExplorerForm::BrowseFile();
  2326. if (LocalDirView->ItemFocused != NULL)
  2327. {
  2328. LocalDirView->ItemFocused->Selected = true;
  2329. }
  2330. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  2331. // Select the panel that has the file, with preference on the remote panel
  2332. if (RemoteDirView->ItemFocused->Selected)
  2333. {
  2334. ScpCommander.CurrentPanel = osRemote;
  2335. }
  2336. else if (LocalDirView->ItemFocused->Selected)
  2337. {
  2338. ScpCommander.CurrentPanel = osLocal;
  2339. }
  2340. WinConfiguration->ScpCommander = ScpCommander;
  2341. }
  2342. //---------------------------------------------------------------------------
  2343. void __fastcall TScpCommanderForm::ThemeChanged()
  2344. {
  2345. TCustomScpExplorerForm::ThemeChanged();
  2346. LocalDirView->Perform(WM_THEMECHANGED, 0, 0);
  2347. OtherLocalDirView->Perform(WM_THEMECHANGED, 0, 0);
  2348. }
  2349. //---------------------------------------------------------------------------
  2350. void __fastcall TScpCommanderForm::OtherLocalDirViewEnter(TObject *)
  2351. {
  2352. // Actually identical to LocalDirViewEnter
  2353. SideEnter(osOther);
  2354. }
  2355. //---------------------------------------------------------------------------
  2356. void __fastcall TScpCommanderForm::OtherLocalDriveViewEnter(TObject *)
  2357. {
  2358. MakeNextInTabOrder(OtherLocalDirView, OtherLocalDriveView);
  2359. SideEnter(osOther);
  2360. }
  2361. //---------------------------------------------------------------------------
  2362. void __fastcall TScpCommanderForm::DoRemotePathComboBoxAdjustImageIndex(
  2363. TTBXComboBoxItem * Sender, const UnicodeString AText, int AIndex, int & ImageIndex)
  2364. {
  2365. if (!IsLocalBrowserMode())
  2366. {
  2367. TCustomScpExplorerForm::DoRemotePathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2368. }
  2369. else
  2370. {
  2371. DoLocalPathComboBoxAdjustImageIndex(Sender, AText, AIndex, ImageIndex);
  2372. }
  2373. }
  2374. //---------------------------------------------------------------------------
  2375. void __fastcall TScpCommanderForm::DoRemotePathComboBoxCancel(TObject * Sender)
  2376. {
  2377. if (!IsLocalBrowserMode())
  2378. {
  2379. TCustomScpExplorerForm::DoRemotePathComboBoxCancel(Sender);
  2380. }
  2381. else
  2382. {
  2383. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2384. }
  2385. }
  2386. //---------------------------------------------------------------------------
  2387. void __fastcall TScpCommanderForm::OtherLocalDirViewPathChange(TCustomDirView * Sender)
  2388. {
  2389. DebugAssert(IsLocalBrowserMode());
  2390. DoLocalDirViewPathChange(Sender, RemotePathComboBox);
  2391. }
  2392. //---------------------------------------------------------------------------
  2393. void __fastcall TScpCommanderForm::DoRemotePathComboBoxItemClick(TObject * Sender)
  2394. {
  2395. if (!IsLocalBrowserMode())
  2396. {
  2397. TCustomScpExplorerForm::DoRemotePathComboBoxItemClick(Sender);
  2398. }
  2399. else
  2400. {
  2401. DoLocalPathComboBoxItemClick(OtherLocalDirView, RemotePathComboBox);
  2402. }
  2403. }
  2404. //---------------------------------------------------------------------------
  2405. void __fastcall TScpCommanderForm::UpdateRemotePathComboBox(bool TextOnly)
  2406. {
  2407. if (!IsLocalBrowserMode())
  2408. {
  2409. TCustomScpExplorerForm::UpdateRemotePathComboBox(TextOnly);
  2410. }
  2411. else
  2412. {
  2413. if (!TextOnly)
  2414. {
  2415. RemotePathComboBox->Strings->Assign(LocalPathComboBox->Strings);
  2416. }
  2417. LocalPathComboUpdate(OtherLocalDirView, RemotePathComboBox);
  2418. }
  2419. }