1
0

ScpCommander.cpp 94 KB

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