ScpCommander.cpp 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850
  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 "Glyphs.h"
  15. #include "NonVisual.h"
  16. #include "Tools.h"
  17. #include "WinConfiguration.h"
  18. #include "TerminalManager.h"
  19. //---------------------------------------------------------------------------
  20. #pragma package(smart_init)
  21. #pragma link "CustomDirView"
  22. #pragma link "CustomScpExplorer"
  23. #pragma link "CustomUnixDirView"
  24. #pragma link "IEListView"
  25. #pragma link "NortonLikeListView"
  26. #pragma link "UnixDirView"
  27. #pragma link "DirView"
  28. #pragma link "PathLabel"
  29. #pragma link "HistoryComboBox"
  30. #pragma link "CustomDriveView"
  31. #pragma link "DriveView"
  32. #pragma link "UnixDriveView"
  33. #pragma link "TB2Dock"
  34. #pragma link "TB2Item"
  35. #pragma link "TB2Toolbar"
  36. #pragma link "TBX"
  37. #pragma link "TB2ExtItems"
  38. #pragma link "TBXExtItems"
  39. #pragma link "TBXLists"
  40. #pragma link "TBXStatusBars"
  41. #pragma link "TBXToolPals"
  42. #ifndef NO_RESOURCES
  43. #pragma resource "*.dfm"
  44. #endif
  45. //---------------------------------------------------------------------------
  46. __fastcall TScpCommanderForm::TScpCommanderForm(TComponent* Owner)
  47. : TCustomScpExplorerForm(Owner)
  48. {
  49. FCurrentSide = osLocal;
  50. FLastLeftPanelWidth = LeftPanelWidth;
  51. FNormalPanelsWidth = -1;
  52. FSynchronisingBrowse = false;
  53. FFirstTerminal = true;
  54. FInternalDDDownloadList = new TStringList();
  55. FLocalPathComboBoxPaths = new TStringList();
  56. RemotePathComboBox->Images = FSystemImageList;
  57. RemotePathComboBox->SubMenuImages = FSystemImageList;
  58. LocalPathComboBox->Images = FSystemImageList;
  59. LocalPathComboBox->SubMenuImages = FSystemImageList;
  60. LocalPathComboUpdateDrives();
  61. LocalBackButton->LinkSubitems = HistoryMenu(osLocal, true)->Items;
  62. LocalForwardButton->LinkSubitems = HistoryMenu(osLocal, false)->Items;
  63. RemoteBackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  64. RemoteForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  65. TopDock->PopupMenu = NonVisualDataModule->CommanderBarPopup;
  66. StatusBar->PopupMenu = TopDock->PopupMenu;
  67. QueueDock->PopupMenu = TopDock->PopupMenu;
  68. BottomDock->PopupMenu = TopDock->PopupMenu;
  69. LocalTopDock->PopupMenu = NonVisualDataModule->LocalPanelPopup;
  70. LocalPathLabel->PopupMenu = LocalTopDock->PopupMenu;
  71. LocalStatusBar->PopupMenu = LocalTopDock->PopupMenu;
  72. LocalDriveView->PopupMenu = LocalTopDock->PopupMenu;
  73. LocalBottomDock->PopupMenu = LocalTopDock->PopupMenu;
  74. RemoteTopDock->PopupMenu = NonVisualDataModule->RemotePanelPopup;
  75. RemotePathLabel->PopupMenu = RemoteTopDock->PopupMenu;
  76. RemoteStatusBar->PopupMenu = RemoteTopDock->PopupMenu;
  77. RemoteDriveView->PopupMenu = RemoteTopDock->PopupMenu;
  78. RemoteBottomDock->PopupMenu = RemoteTopDock->PopupMenu;
  79. // set common norton shorcuts to our actions
  80. NonVisualDataModule->CommanderShortcuts();
  81. Splitter->ShowHint = True;
  82. reinterpret_cast<TLabel*>(Splitter)->OnDblClick = SplitterDblClick;
  83. reinterpret_cast<TLabel*>(LocalPanelSplitter)->OnDblClick = PanelSplitterDblClick;
  84. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = PanelSplitterDblClick;
  85. CommandLineCombo->Text = "";
  86. FCommandLineComboPopulated = false;
  87. for (int i = 0; i < ToolbarToolbar->Items->Count; i++)
  88. {
  89. TTBCustomItem * Item = ToolbarToolbar->Items->Items[i];
  90. Item->Caption =
  91. ShortCutToText(Item->ShortCut) + " " +
  92. Trim(StringReplace(StripHotkey(Item->Caption),
  93. "...", "", TReplaceFlags() << rfReplaceAll << rfIgnoreCase));
  94. }
  95. LocalDirView->Font = Screen->IconFont;
  96. NonVisualDataModule->InitMenus(this);
  97. NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
  98. }
  99. //---------------------------------------------------------------------------
  100. __fastcall TScpCommanderForm::~TScpCommanderForm()
  101. {
  102. delete FInternalDDDownloadList;
  103. SAFE_DESTROY(FLocalPathComboBoxPaths);
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TScpCommanderForm::RestoreFormParams()
  107. {
  108. assert(WinConfiguration);
  109. TCustomScpExplorerForm::RestoreFormParams();
  110. RestoreForm(WinConfiguration->ScpCommander.WindowParams, this);
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TScpCommanderForm::RestoreParams()
  114. {
  115. assert(Configuration);
  116. // IDE often looses this link
  117. LocalDirView->HeaderImages = GlyphsModule->ArrowImages;
  118. TCustomScpExplorerForm::RestoreParams();
  119. LeftPanelWidth = WinConfiguration->ScpCommander.LocalPanelWidth;
  120. LoadToolbarsLayoutStr(WinConfiguration->ScpCommander.ToolbarsLayout);
  121. StatusBar->Visible = WinConfiguration->ScpCommander.StatusBar;
  122. #define RESTORE_PANEL_PARAMS(PANEL) \
  123. PANEL ## DirView->ColProperties->ParamsStr = WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams; \
  124. PANEL ## StatusBar->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar; \
  125. PANEL ## DriveView->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.DriveView; \
  126. if (PANEL ## DriveView->Align == alTop) \
  127. PANEL ## DriveView->Height = WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight; \
  128. else \
  129. PANEL ## DriveView->Width = WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth
  130. RESTORE_PANEL_PARAMS(Local);
  131. RESTORE_PANEL_PARAMS(Remote);
  132. #undef RESTORE_PANEL_PARAMS
  133. FPanelsRestored = true;
  134. // just to make sure
  135. LocalDirView->DirColProperties->ExtVisible = false;
  136. RemoteDirView->UnixColProperties->ExtVisible = false;
  137. NonVisualDataModule->SynchronizeBrowsingAction->Checked = WinConfiguration->SynchronizeBrowsing;
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TScpCommanderForm::StoreParams()
  141. {
  142. assert(WinConfiguration);
  143. WinConfiguration->BeginUpdate();
  144. try
  145. {
  146. WinConfiguration->ScpCommander.ToolbarsLayout = GetToolbarsLayoutStr();
  147. WinConfiguration->ScpCommander.LocalPanelWidth = LeftPanelWidth;
  148. WinConfiguration->ScpCommander.StatusBar = StatusBar->Visible;
  149. SaveCommandLine();
  150. WinConfiguration->ScpCommander.CurrentPanel = FCurrentSide;
  151. #define STORE_PANEL_PARAMS(PANEL) \
  152. WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams = PANEL ## DirView->ColProperties->ParamsStr; \
  153. WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar = PANEL ## StatusBar->Visible; \
  154. WinConfiguration->ScpCommander.PANEL ## Panel.DriveView = PANEL ## DriveView->Visible; \
  155. if (PANEL ## DriveView->Align == alTop) \
  156. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight = PANEL ## DriveView->Height; \
  157. else \
  158. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth = PANEL ## DriveView->Width
  159. STORE_PANEL_PARAMS(Local);
  160. STORE_PANEL_PARAMS(Remote);
  161. #undef RESTORE_PANEL_PARAMS
  162. WinConfiguration->ScpCommander.WindowParams = StoreForm(this);
  163. WinConfiguration->SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  164. TCustomScpExplorerForm::StoreParams();
  165. }
  166. __finally
  167. {
  168. WinConfiguration->EndUpdate();
  169. }
  170. }
  171. //---------------------------------------------------------------------------
  172. void __fastcall TScpCommanderForm::UpdateTerminal(TTerminal * Terminal)
  173. {
  174. TCustomScpExplorerForm::UpdateTerminal(Terminal);
  175. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  176. assert(ManagedTerminal != NULL);
  177. SAFE_DESTROY(ManagedTerminal->LocalExplorerState);
  178. if (WinConfiguration->PreservePanelState)
  179. {
  180. ManagedTerminal->LocalExplorerState = LocalDirView->SaveState();
  181. ManagedTerminal->SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  182. }
  183. assert(LocalDirView != NULL);
  184. ManagedTerminal->LocalDirectory = LocalDirView->PathName;
  185. }
  186. //---------------------------------------------------------------------------
  187. void __fastcall TScpCommanderForm::UpdateSessionData(TSessionData * Data)
  188. {
  189. TCustomScpExplorerForm::UpdateSessionData(Data);
  190. assert(LocalDirView);
  191. Data->LocalDirectory = LocalDirView->PathName;
  192. }
  193. //---------------------------------------------------------------------------
  194. bool __fastcall TScpCommanderForm::InternalDDDownload(AnsiString & TargetDirectory)
  195. {
  196. assert(IsFileControl(FDDTargetControl, osLocal));
  197. bool Result = false;
  198. if (FDDTargetControl == LocalDirView)
  199. {
  200. if (LocalDirView->DropTarget)
  201. {
  202. // when drop target is not directory, it is probably file type, which have
  203. // associated drop handler (such as ZIP file in WinXP). in this case we
  204. // must leave drop handling to destination application.
  205. // ! this check is duplicated in LocalDirViewDDTargetHasDropHandler()
  206. // for shellex downloads
  207. if (LocalDirView->ItemIsDirectory(LocalDirView->DropTarget))
  208. {
  209. TargetDirectory = LocalDirView->ItemFullFileName(LocalDirView->DropTarget);
  210. Result = true;
  211. }
  212. }
  213. else
  214. {
  215. TargetDirectory = IncludeTrailingBackslash(LocalDirView->Path);
  216. Result = true;
  217. }
  218. }
  219. else if (FDDTargetControl == LocalDriveView)
  220. {
  221. assert(LocalDriveView->DropTarget != NULL);
  222. TargetDirectory = LocalDriveView->NodePathName(LocalDriveView->DropTarget);
  223. Result = true;
  224. }
  225. else
  226. {
  227. assert(false);
  228. Abort();
  229. }
  230. return Result;
  231. }
  232. //---------------------------------------------------------------------------
  233. bool __fastcall TScpCommanderForm::CopyParamDialog(TTransferDirection Direction,
  234. TTransferType Type, bool Temp, TStrings * FileList, AnsiString & TargetDirectory,
  235. TGUICopyParamType & CopyParam, bool Confirm, bool DragDrop)
  236. {
  237. bool Result = false;
  238. // Temp means d&d here so far, may change in future!
  239. if (Temp && (Direction == tdToLocal) &&
  240. IsFileControl(FDDTargetControl, osLocal))
  241. {
  242. Result = InternalDDDownload(TargetDirectory);
  243. if (Result)
  244. {
  245. assert(FileList->Count > 0);
  246. FInternalDDDownloadList->Assign(FileList);
  247. }
  248. }
  249. else if (!Temp && TargetDirectory.IsEmpty())
  250. {
  251. if (Direction == tdToLocal)
  252. {
  253. TargetDirectory = IncludeTrailingBackslash(LocalDirView->Path);
  254. }
  255. else
  256. {
  257. TargetDirectory = UnixIncludeTrailingBackslash(RemoteDirView->Path);
  258. }
  259. }
  260. if (!Result)
  261. {
  262. Result = TCustomScpExplorerForm::CopyParamDialog(Direction, Type, Temp,
  263. FileList, TargetDirectory, CopyParam, Confirm, DragDrop);
  264. }
  265. return Result;
  266. }
  267. //---------------------------------------------------------------------------
  268. void __fastcall TScpCommanderForm::DoShow()
  269. {
  270. ActiveControl = (WinConfiguration->ScpCommander.CurrentPanel == osLocal ?
  271. (TCustomDirView *)LocalDirView : (TCustomDirView *)RemoteDirView);
  272. TCustomScpExplorerForm::DoShow();
  273. UpdateControls();
  274. }
  275. //---------------------------------------------------------------------------
  276. Boolean __fastcall TScpCommanderForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  277. {
  278. #define FLAG ((TActionFlag)(Action->Tag))
  279. return
  280. // always require Commander flag
  281. (FLAG & afCommander) &&
  282. // if action is execution or update, we don't require any other flag
  283. // if we check for shortcut, we require proper dirview to be selected
  284. ((Allowed != aaShortCut) ||
  285. ((FLAG & afLocal) && (FCurrentSide == osLocal)) ||
  286. ((FLAG & afRemote) && (FCurrentSide == osRemote))
  287. );
  288. #undef FLAG
  289. }
  290. //---------------------------------------------------------------------------
  291. TCustomDirView * __fastcall TScpCommanderForm::DirView(TOperationSide Side)
  292. {
  293. Side = GetSide(Side);
  294. if (Side == osLocal)
  295. {
  296. return LocalDirView;
  297. }
  298. else
  299. {
  300. return TCustomScpExplorerForm::DirView(Side);
  301. }
  302. }
  303. //---------------------------------------------------------------------------
  304. bool __fastcall TScpCommanderForm::IsFileControl(TObject * Control,
  305. TOperationSide Side)
  306. {
  307. return
  308. ((Side == osLocal) &&
  309. ((Control == LocalDirView) || (Control == LocalDriveView))) ||
  310. TCustomScpExplorerForm::IsFileControl(Control, Side);
  311. }
  312. //---------------------------------------------------------------------------
  313. void __fastcall TScpCommanderForm::ReloadLocalDirectory(const AnsiString Directory)
  314. {
  315. if (Directory.IsEmpty() || ComparePaths(Directory, LocalDirView->Path))
  316. {
  317. LocalDirView->ReloadDirectory();
  318. LocalDriveView->ValidateDirectory(LocalDriveView->Selected);
  319. }
  320. TCustomScpExplorerForm::ReloadLocalDirectory();
  321. }
  322. //---------------------------------------------------------------------------
  323. void __fastcall TScpCommanderForm::BatchStart(void *& Storage)
  324. {
  325. Storage = new bool;
  326. *static_cast<bool*>(Storage) = LocalDirView->WatchForChanges;
  327. LocalDirView->WatchForChanges = false;
  328. LocalDriveView->WatchDirectory = false;
  329. TCustomScpExplorerForm::BatchStart(Storage);
  330. }
  331. //---------------------------------------------------------------------------
  332. void __fastcall TScpCommanderForm::BatchEnd(void * Storage)
  333. {
  334. TCustomScpExplorerForm::BatchEnd(Storage);
  335. assert(Storage != NULL);
  336. LocalDirView->WatchForChanges = *static_cast<bool*>(Storage);
  337. LocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  338. delete Storage;
  339. }
  340. //---------------------------------------------------------------------------
  341. void __fastcall TScpCommanderForm::TerminalChanged()
  342. {
  343. if (Terminal)
  344. {
  345. bool WasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  346. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  347. TCustomScpExplorerForm::TerminalChanged();
  348. // we will load completelly different directory, so particularly
  349. // do not attempt to select previously selected directory
  350. LocalDirView->ContinueSession(false);
  351. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  352. assert(ManagedTerminal != NULL);
  353. // reset home directory
  354. LocalDirView->HomeDirectory = "";
  355. if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  356. {
  357. AnsiString LocalDirectory = ManagedTerminal->LocalDirectory;
  358. bool DocumentsDir = LocalDirectory.IsEmpty();
  359. if (!DocumentsDir)
  360. {
  361. try
  362. {
  363. LocalDirView->Path = LocalDirectory;
  364. }
  365. catch(Exception & E)
  366. {
  367. DocumentsDir = true;
  368. Terminal->ShowExtendedException(&E);
  369. }
  370. }
  371. if (DocumentsDir)
  372. {
  373. try
  374. {
  375. LocalDirView->HomeDirectory = "";
  376. LocalDirView->ExecuteHomeDirectory();
  377. }
  378. catch(Exception & E)
  379. {
  380. Terminal->ShowExtendedException(&E);
  381. LocalDirView->Path = ExtractFilePath(Application->ExeName);
  382. }
  383. }
  384. }
  385. FFirstTerminal = false;
  386. if (WinConfiguration->DefaultDirIsHome &&
  387. !Terminal->SessionData->UpdateDirectories)
  388. {
  389. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  390. }
  391. if (WinConfiguration->PreservePanelState &&
  392. (ManagedTerminal->LocalExplorerState != NULL) &&
  393. !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  394. {
  395. LocalDirView->RestoreState(ManagedTerminal->LocalExplorerState);
  396. NonVisualDataModule->SynchronizeBrowsingAction->Checked = ManagedTerminal->SynchronizeBrowsing;
  397. }
  398. else if (WasSynchronisingBrowsing &&
  399. SameText(ExtractFileName(LocalDirView->PathName),
  400. UnixExtractFileName(RemoteDirView->PathName)))
  401. {
  402. NonVisualDataModule->SynchronizeBrowsingAction->Checked = true;
  403. }
  404. }
  405. else
  406. {
  407. TCustomScpExplorerForm::TerminalChanged();
  408. }
  409. }
  410. //---------------------------------------------------------------------------
  411. void __fastcall TScpCommanderForm::ConfigurationChanged()
  412. {
  413. TCustomScpExplorerForm::ConfigurationChanged();
  414. if (WinConfiguration->DefaultDirIsHome && Terminal &&
  415. !Terminal->SessionData->UpdateDirectories)
  416. {
  417. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  418. }
  419. else
  420. {
  421. LocalDirView->HomeDirectory = "";
  422. }
  423. LocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  424. LocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  425. LocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  426. LocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  427. LocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  428. LocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  429. LocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  430. RemoteDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  431. bool RowSelectChange = (LocalDirView->RowSelect != WinConfiguration->ScpCommander.FullRowSelect);
  432. LocalDirView->RowSelect = WinConfiguration->ScpCommander.FullRowSelect;
  433. RemoteDirView->RowSelect = WinConfiguration->ScpCommander.FullRowSelect;
  434. if (RowSelectChange)
  435. {
  436. // selection is not redrawn automatically when RowSelect changes
  437. LocalDirView->Invalidate();
  438. RemoteDirView->Invalidate();
  439. }
  440. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler =
  441. !WinConfiguration->DDExtEnabled;
  442. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler =
  443. !WinConfiguration->DDExtEnabled;
  444. if ((LocalPanel->Left > RemotePanel->Left) != WinConfiguration->ScpCommander.SwappedPanels)
  445. {
  446. int AWidth = ClientWidth;
  447. Panel(false)->Align = alClient;
  448. Panel(true)->Align = alLeft;
  449. TControl * ControlsOrder[] =
  450. { Panel(true), Splitter, Panel(false) };
  451. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  452. Panel(true)->TabOrder = 0;
  453. Panel(false)->TabOrder = 1;
  454. ClientWidth = AWidth;
  455. LeftPanelWidth = FLastLeftPanelWidth;
  456. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  457. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  458. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  459. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  460. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  461. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction->ShortCut,
  462. NonVisualDataModule->RemoteChangePathAction->ShortCut);
  463. }
  464. if ((RemoteDriveView->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  465. {
  466. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  467. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  468. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  469. // save value only is it was set yet
  470. if (FPanelsRestored)
  471. {
  472. if (TreeOnLeft)
  473. {
  474. // want to be on left, so it is on top, saving height
  475. LocalPanel.DriveViewHeight = LocalDriveView->Height;
  476. RemotePanel.DriveViewHeight = RemoteDriveView->Height;
  477. }
  478. else
  479. {
  480. LocalPanel.DriveViewWidth = LocalDriveView->Width;
  481. RemotePanel.DriveViewWidth = RemoteDriveView->Width;
  482. }
  483. }
  484. TAlign NonClientAlign = (TreeOnLeft ? alLeft : alTop);
  485. LocalDriveView->Align = NonClientAlign;
  486. LocalPanelSplitter->Align = NonClientAlign;
  487. RemoteDriveView->Align = NonClientAlign;
  488. RemotePanelSplitter->Align = NonClientAlign;
  489. FixControlsPlacement();
  490. if (TreeOnLeft)
  491. {
  492. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  493. RemoteDriveView->Width = RemotePanel.DriveViewWidth;
  494. }
  495. else
  496. {
  497. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  498. RemoteDriveView->Height = RemotePanel.DriveViewHeight;
  499. }
  500. // in case it trigges config-changed event (does not),
  501. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  502. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  503. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  504. }
  505. }
  506. //---------------------------------------------------------------------------
  507. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  508. {
  509. return (WinConfiguration->ScpCommander.SwappedPanels == Left ?
  510. RemotePanel : LocalPanel);
  511. }
  512. //---------------------------------------------------------------------------
  513. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  514. {
  515. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  516. }
  517. //---------------------------------------------------------------------------
  518. void __fastcall TScpCommanderForm::SetLeftPanelWidth(float value)
  519. {
  520. float Total = LocalPanel->Width + RemotePanel->Width;
  521. FLeftPanelWidth = value;
  522. if (value * Total != Panel(true)->Width)
  523. {
  524. Panel(true)->Width = value * Total;
  525. UpdateControls();
  526. }
  527. }
  528. //---------------------------------------------------------------------------
  529. float __fastcall TScpCommanderForm::GetLeftPanelWidth()
  530. {
  531. return FLeftPanelWidth;
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  535. {
  536. float Left = Panel(true)->Width;
  537. float Total = LocalPanel->Width + RemotePanel->Width;
  538. FLeftPanelWidth = Left / Total;
  539. FLastLeftPanelWidth = LeftPanelWidth;
  540. UpdateControls();
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  544. int &NewSize, bool & /*Accept*/)
  545. {
  546. // When splitter is drag so far to right, that width contraint of remote panel would
  547. // be violated, it doesn't stop, but extend form width.
  548. // Following prevents this behaviour.
  549. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  550. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  551. }
  552. //---------------------------------------------------------------------------
  553. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  554. {
  555. LeftPanelWidth = 0.5;
  556. }
  557. //---------------------------------------------------------------------------
  558. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  559. {
  560. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  561. assert(Splitter != NULL);
  562. TCustomDriveView * DriveView;
  563. TCustomDriveView * OtherDriveView;
  564. if (Splitter == LocalPanelSplitter)
  565. {
  566. DriveView = LocalDriveView;
  567. OtherDriveView = RemoteDriveView;
  568. }
  569. else
  570. {
  571. DriveView = RemoteDriveView;
  572. OtherDriveView = LocalDriveView;
  573. }
  574. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  575. assert(DriveView->Visible);
  576. if (OtherDriveView->Visible)
  577. {
  578. if (TreeOnLeft)
  579. {
  580. DriveView->Width = OtherDriveView->Width;
  581. }
  582. else
  583. {
  584. DriveView->Height = OtherDriveView->Height;
  585. }
  586. }
  587. else
  588. {
  589. if (TreeOnLeft)
  590. {
  591. OtherDriveView->Width = DriveView->Width;
  592. }
  593. else
  594. {
  595. OtherDriveView->Height = DriveView->Height;
  596. }
  597. OtherDriveView->Visible = true;
  598. }
  599. FixControlsPlacement();
  600. }
  601. //---------------------------------------------------------------------------
  602. void __fastcall TScpCommanderForm::UpdateControls()
  603. {
  604. TCustomScpExplorerForm::UpdateControls();
  605. AnsiString SplitterLongHint = Splitter->Hint;
  606. SplitterLongHint.Delete(1, SplitterLongHint.Pos("|"));
  607. Splitter->Hint = FORMAT("%0.0f%%|%s", (LeftPanelWidth*100, SplitterLongHint));
  608. AnsiString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  609. ((FCurrentSide == osRemote) ? "$" : ">");
  610. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  611. {
  612. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  613. // command line combo width needs to be updated as caption width has probably changed
  614. ToolBarResize(CommandLineToolbar);
  615. }
  616. LocalDirView->Color = (SessionColor != 0 ? SessionColor : clWindow);
  617. LocalDriveView->Color = LocalDirView->Color;
  618. }
  619. //---------------------------------------------------------------------------
  620. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  621. {
  622. assert((Side == osLocal) || (Side == osRemote));
  623. TTBXComboBoxItem * PathComboBox;
  624. if (Side == osLocal)
  625. {
  626. PathComboBox = LocalPathComboBox;
  627. }
  628. else
  629. {
  630. PathComboBox = RemotePathComboBox;
  631. }
  632. ClickToolbarItem(PathComboBox, false);
  633. }
  634. //---------------------------------------------------------------------------
  635. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  636. {
  637. switch (Component) {
  638. case fcToolBar: return ToolbarToolbar;
  639. case fcStatusBar: return StatusBar;
  640. case fcLocalStatusBar: return LocalStatusBar;
  641. case fcRemoteStatusBar: return RemoteStatusBar;
  642. case fcSessionCombo: return reinterpret_cast<TControl*>(SessionCombo);
  643. case fcCommandLinePanel: return CommandLineToolbar;
  644. case fcLocalTree: return LocalDriveView;
  645. case fcSessionToolbar: return SessionToolbar;
  646. case fcCustomCommandsBand: return CustomCommandsToolbar;
  647. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  648. case fcColorPalette: return reinterpret_cast<TControl*>(SessionColorPalette);
  649. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  650. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  651. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  652. case fcCommanderMenuBand: return MenuToolbar;
  653. case fcCommanderSessionBand: return SessionToolbar;
  654. case fcCommanderPreferencesBand: return PreferencesToolbar;
  655. case fcCommanderSelectionBand: return SelectionToolbar;
  656. case fcCommanderToolbarBand: return CommandToolbar;
  657. case fcCommanderSortBand: return SortToolbar;
  658. case fcCommanderCommandsBand: return CommandsToolbar;
  659. case fcCommanderUpdatesBand: return UpdatesToolbar;
  660. case fcCommanderTransferBand: return TransferToolbar;
  661. case fcCommanderUploadDownloadBand: return UploadDownloadToolbar;
  662. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  663. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  664. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  665. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  666. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  667. default: return TCustomScpExplorerForm::GetComponent(Component);
  668. }
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TScpCommanderForm::FixControlsPlacement()
  672. {
  673. TCustomScpExplorerForm::FixControlsPlacement();
  674. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  675. TControl * ControlsOrder[] =
  676. { BottomDock, QueueSplitter, QueuePanel, StatusBar };
  677. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  678. TControl * LocalControlsOrder[] =
  679. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  680. LocalDirView, LocalBottomDock, LocalStatusBar };
  681. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  682. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  683. TControl * RemoteControlsOrder[] =
  684. { RemoteTopDock, RemotePathLabel, RemoteDriveView, RemotePanelSplitter,
  685. RemoteDirView, RemoteBottomDock, RemoteStatusBar };
  686. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  687. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  688. if (LocalDirView->ItemFocused != NULL)
  689. {
  690. LocalDirView->ItemFocused->MakeVisible(false);
  691. }
  692. }
  693. //---------------------------------------------------------------------------
  694. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  695. {
  696. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  697. }
  698. //---------------------------------------------------------------------------
  699. void __fastcall TScpCommanderForm::CompareDirectories()
  700. {
  701. LocalDirView->CompareFiles(RemoteDirView, false,
  702. WinConfiguration->ScpCommander.CompareCriterias());
  703. RemoteDirView->CompareFiles(LocalDirView, false,
  704. WinConfiguration->ScpCommander.CompareCriterias());
  705. if (LocalDirView->SelCount + RemoteDirView->SelCount == 0)
  706. {
  707. MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
  708. HELP_COMPARE_NO_DIFFERENCES);
  709. }
  710. }
  711. //---------------------------------------------------------------------------
  712. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  713. {
  714. AnsiString LocalDirectory = LocalDirView->PathName;
  715. AnsiString RemoteDirectory = RemoteDirView->PathName;
  716. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, false);
  717. }
  718. //---------------------------------------------------------------------------
  719. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  720. {
  721. AnsiString LocalDirectory = LocalDirView->PathName;
  722. AnsiString RemoteDirectory = RemoteDirView->PathName;
  723. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  724. TSynchronizeMode Mode =
  725. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  726. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  727. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode,
  728. SaveMode, false))
  729. {
  730. if (SaveMode)
  731. {
  732. GUIConfiguration->SynchronizeModeAuto = Mode;
  733. }
  734. }
  735. }
  736. //---------------------------------------------------------------------------
  737. void __fastcall TScpCommanderForm::ExploreLocalDirectory()
  738. {
  739. if ((int)ShellExecute(Application->Handle, "explore",
  740. (char*)LocalDirView->Path.data(), NULL, NULL, SW_SHOWNORMAL) <= 32)
  741. {
  742. throw Exception(FORMAT(EXPLORE_LOCAL_DIR_ERROR, (LocalDirView->Path)));
  743. }
  744. }
  745. //---------------------------------------------------------------------------
  746. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  747. TListItem *Item, bool &AllowExec)
  748. {
  749. assert(Item);
  750. if ((UpperCase(PFileRec(Item->Data)->FileExt) == "LNK") &&
  751. DirectoryExists(ResolveFileShortCut(LocalDirView->ItemFullFileName(Item), true)))
  752. {
  753. AllowExec = true;
  754. }
  755. else
  756. {
  757. DoDirViewExecFile(Sender, Item, AllowExec);
  758. }
  759. }
  760. //---------------------------------------------------------------------------
  761. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  762. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  763. bool &Accept)
  764. {
  765. // LocalDirViewDDDragEnter is duplication of
  766. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  767. // literal type of 'DataObj' parameter.Actual type is however same
  768. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  769. }
  770. //---------------------------------------------------------------------------
  771. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  772. bool DragDrop)
  773. {
  774. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  775. (DropSourceControl == LocalDirView);
  776. }
  777. //---------------------------------------------------------------------------
  778. void __fastcall TScpCommanderForm::FileOperationProgress(
  779. TFileOperationProgressType & ProgressData, TCancelStatus & Cancel)
  780. {
  781. // Heuristic: When operation finishes and DD targed is local dir view,
  782. // we suppose that drag&drop download finished, so local dir view should be
  783. // reloaded
  784. if (!ProgressData.InProgress && FProgressForm &&
  785. IsFileControl(FDDTargetControl, osLocal) &&
  786. ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
  787. {
  788. ReloadLocalDirectory();
  789. }
  790. TCustomScpExplorerForm::FileOperationProgress(ProgressData, Cancel);
  791. }
  792. //---------------------------------------------------------------------------
  793. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  794. AnsiString PrevPath, AnsiString & NewPath, bool Create)
  795. {
  796. if (ADirView == LocalDirView)
  797. {
  798. Terminal->ExceptionOnFail = true;
  799. try
  800. {
  801. AnsiString FullPrevPath = IncludeTrailingBackslash(PrevPath);
  802. if (LocalDirView->Path.SubString(1, FullPrevPath.Length()) == FullPrevPath)
  803. {
  804. NewPath = UnixIncludeTrailingBackslash(RemoteDirView->Path) +
  805. ToUnixPath(LocalDirView->Path.SubString(FullPrevPath.Length() + 1,
  806. LocalDirView->Path.Length() - FullPrevPath.Length()));
  807. }
  808. else if (FullPrevPath.SubString(1, LocalDirView->Path.Length()) == LocalDirView->Path)
  809. {
  810. NewPath = RemoteDirView->Path;
  811. while (!ComparePaths(FullPrevPath, LocalDirView->Path))
  812. {
  813. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  814. {
  815. Abort();
  816. }
  817. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  818. FullPrevPath = ExtractFilePath(ExcludeTrailingBackslash(FullPrevPath));
  819. }
  820. }
  821. else
  822. {
  823. Abort();
  824. }
  825. if (Create)
  826. {
  827. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  828. RemoteDirView->CreateDirectoryEx(NewPath, &Properties);
  829. }
  830. RemoteDirView->Path = NewPath;
  831. }
  832. __finally
  833. {
  834. Terminal->ExceptionOnFail = false;
  835. }
  836. }
  837. else
  838. {
  839. AnsiString FullPrevPath = UnixIncludeTrailingBackslash(PrevPath);
  840. if (RemoteDirView->Path.SubString(1, FullPrevPath.Length()) == FullPrevPath)
  841. {
  842. NewPath = IncludeTrailingBackslash(LocalDirView->Path) +
  843. FromUnixPath(RemoteDirView->Path.SubString(FullPrevPath.Length() + 1,
  844. RemoteDirView->Path.Length() - FullPrevPath.Length()));
  845. }
  846. else if (FullPrevPath.SubString(1, RemoteDirView->Path.Length()) == RemoteDirView->Path)
  847. {
  848. AnsiString NewLocalPath;
  849. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  850. while (!UnixComparePaths(FullPrevPath, RemoteDirView->Path))
  851. {
  852. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  853. if (NewLocalPath == NewPath)
  854. {
  855. Abort();
  856. }
  857. NewPath = NewLocalPath;
  858. FullPrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(FullPrevPath));
  859. }
  860. }
  861. else
  862. {
  863. Abort();
  864. }
  865. if (Create)
  866. {
  867. LocalDirView->CreateDirectory(NewPath);
  868. }
  869. LocalDirView->Path = NewPath;
  870. }
  871. }
  872. //---------------------------------------------------------------------------
  873. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  874. {
  875. AnsiString PrevPath = FPrevPath[ADirView == LocalDirView];
  876. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  877. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  878. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  879. {
  880. bool PrevNoTransferPresetAutoSelect = FNoTransferPresetAutoSelect;
  881. FNoTransferPresetAutoSelect = true;
  882. FSynchronisingBrowse = true;
  883. try
  884. {
  885. try
  886. {
  887. AnsiString NewPath;
  888. try
  889. {
  890. SynchronizeBrowsing(ADirView, PrevPath, NewPath, false);
  891. }
  892. // EAbort means that we do not know how to synchronize browsing
  893. // there's no fallback scenario for that
  894. catch(EAbort &)
  895. {
  896. throw;
  897. }
  898. catch(Exception & E)
  899. {
  900. // what does this say?
  901. if (Application->Terminated)
  902. {
  903. throw;
  904. }
  905. else
  906. {
  907. Terminal->ShowExtendedException(&E);
  908. if (MessageDialog(FMTLOAD(SYNC_DIR_BROWSE_CREATE, (NewPath)), qtInformation, qaYes | qaNo,
  909. HELP_SYNC_DIR_BROWSE_ERROR) == qaYes)
  910. {
  911. try
  912. {
  913. SynchronizeBrowsing(ADirView, PrevPath, NewPath, true);
  914. }
  915. catch(Exception & E)
  916. {
  917. if (!Application->Terminated)
  918. {
  919. Terminal->ShowExtendedException(&E);
  920. }
  921. throw;
  922. }
  923. }
  924. else
  925. {
  926. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  927. }
  928. }
  929. }
  930. }
  931. catch(Exception & E)
  932. {
  933. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  934. // what does this say?
  935. if (Application->Terminated)
  936. {
  937. throw;
  938. }
  939. else
  940. {
  941. MessageDialog(LoadStr(SYNC_DIR_BROWSE_ERROR), qtInformation, qaOK,
  942. HELP_SYNC_DIR_BROWSE_ERROR);
  943. }
  944. }
  945. }
  946. __finally
  947. {
  948. FSynchronisingBrowse = false;
  949. FNoTransferPresetAutoSelect = PrevNoTransferPresetAutoSelect;
  950. }
  951. }
  952. }
  953. //---------------------------------------------------------------------------
  954. void __fastcall TScpCommanderForm::DoDirViewLoaded(TCustomDirView * ADirView)
  955. {
  956. TCustomScpExplorerForm::DoDirViewLoaded(ADirView);
  957. UpdateControls();
  958. SynchronizeBrowsing(ADirView);
  959. }
  960. //---------------------------------------------------------------------------
  961. void __fastcall TScpCommanderForm::AddEditLink(bool Add)
  962. {
  963. if (FCurrentSide == osLocal)
  964. {
  965. bool Edit = false;
  966. AnsiString FileName;
  967. AnsiString PointTo;
  968. bool SymbolicLink = true;
  969. if (LocalDirView->ItemFocused)
  970. {
  971. assert(LocalDirView->ItemFocused->Data);
  972. PFileRec FileRec = (PFileRec)LocalDirView->ItemFocused->Data;
  973. Edit = !Add && (UpperCase(FileRec->FileExt) == "LNK");
  974. if (Edit)
  975. {
  976. AnsiString FullName = LocalDirView->ItemFullFileName(LocalDirView->ItemFocused);
  977. FileName = FullName;
  978. PointTo = ResolveFileShortCut(FullName, false);
  979. if (PointTo.IsEmpty())
  980. {
  981. throw Exception(FMTLOAD(RESOLVE_SHORTCUT_ERROR, (FullName)));
  982. }
  983. }
  984. else
  985. {
  986. PointTo = FileRec->FileName;
  987. }
  988. }
  989. if (DoSymlinkDialog(FileName, PointTo, osLocal, SymbolicLink, Edit, false))
  990. {
  991. assert(SymbolicLink);
  992. assert(!FileName.IsEmpty());
  993. assert(!PointTo.IsEmpty());
  994. if (ExtractFileDrive(FileName) == "" && FileName[1] != '\\')
  995. {
  996. FileName = IncludeTrailingBackslash(LocalDirView->PathName) + FileName;
  997. }
  998. if (ExtractFileDrive(PointTo) == "" && PointTo[1] != '\\')
  999. {
  1000. PointTo = IncludeTrailingBackslash(LocalDirView->PathName) + PointTo;
  1001. }
  1002. if (ExtractFileExt(FileName) == "")
  1003. {
  1004. FileName = FileName + ".lnk";
  1005. }
  1006. if (Edit && !DeleteFile(FileName))
  1007. {
  1008. throw Exception(FMTLOAD(DELETE_LOCAL_FILE_ERROR, (FileName)));
  1009. }
  1010. if (!CreateFileShortCut(PointTo, FileName, ""))
  1011. {
  1012. throw Exception(CREATE_SHORTCUT_ERROR);
  1013. }
  1014. }
  1015. }
  1016. else
  1017. {
  1018. TCustomScpExplorerForm::AddEditLink(Add);
  1019. }
  1020. }
  1021. //---------------------------------------------------------------------------
  1022. void __fastcall TScpCommanderForm::DoOpenDirectoryDialog(TOpenDirectoryMode Mode,
  1023. TOperationSide Side)
  1024. {
  1025. bool UseLocationProfiles;
  1026. do
  1027. {
  1028. UseLocationProfiles = WinConfiguration->UseLocationProfiles;
  1029. if (UseLocationProfiles)
  1030. {
  1031. TStrings * LocalDirectories = NULL;
  1032. TStrings * RemoteDirectories = NULL;
  1033. try
  1034. {
  1035. LocalDirectories = CreateVisitedDirectories(osLocal);
  1036. RemoteDirectories = CreateVisitedDirectories(osRemote);
  1037. AnsiString Local = LocalDirView->PathName;
  1038. AnsiString Remote = RemoteDirView->PathName;
  1039. if (LocationProfilesDialog(Mode, Side, Local, Remote, LocalDirectories,
  1040. RemoteDirectories, Terminal))
  1041. {
  1042. DoOpenBookmark(Local, Remote);
  1043. }
  1044. }
  1045. __finally
  1046. {
  1047. delete LocalDirectories;
  1048. delete RemoteDirectories;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. bool WasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  1054. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1055. try
  1056. {
  1057. TCustomScpExplorerForm::DoOpenDirectoryDialog(Mode, Side);
  1058. }
  1059. __finally
  1060. {
  1061. NonVisualDataModule->SynchronizeBrowsingAction->Checked = WasSynchronisingBrowsing;
  1062. }
  1063. }
  1064. // for second and further rounds, always do browse only
  1065. Mode = odBrowse;
  1066. }
  1067. while (UseLocationProfiles != WinConfiguration->UseLocationProfiles);
  1068. }
  1069. //---------------------------------------------------------------------------
  1070. void __fastcall TScpCommanderForm::DoOpenBookmark(AnsiString Local, AnsiString Remote)
  1071. {
  1072. bool WasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  1073. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1074. try
  1075. {
  1076. // make sure that whatever path is valid it is opened first and only
  1077. // after that an eventual error is reported
  1078. try
  1079. {
  1080. if (!Local.IsEmpty())
  1081. {
  1082. LocalDirView->Path = Local;
  1083. }
  1084. }
  1085. __finally
  1086. {
  1087. if (!Remote.IsEmpty())
  1088. {
  1089. RemoteDirView->Path = Remote;
  1090. }
  1091. }
  1092. }
  1093. __finally
  1094. {
  1095. NonVisualDataModule->SynchronizeBrowsingAction->Checked = WasSynchronisingBrowsing;
  1096. }
  1097. }
  1098. //---------------------------------------------------------------------------
  1099. bool __fastcall TScpCommanderForm::OpenBookmark(AnsiString Local, AnsiString Remote)
  1100. {
  1101. bool Result;
  1102. if (WinConfiguration->UseLocationProfiles)
  1103. {
  1104. DoOpenBookmark(Local, Remote);
  1105. Result = true;
  1106. }
  1107. else
  1108. {
  1109. Result = TCustomScpExplorerForm::OpenBookmark(Local, Remote);
  1110. }
  1111. return Result;
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1115. TObject * /*Sender*/, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1116. {
  1117. // when drop target is not directory, it is probably file type, which have
  1118. // associated drop handler (such as ZIP file in WinXP). in this case we
  1119. // cannot allow downloading when using shellex.
  1120. // ! this check is duplicated in InternalDDDownload() for non-shellex downloads
  1121. if ((FDDExtMapFile != NULL) &&
  1122. !LocalDirView->ItemIsDirectory(Item))
  1123. {
  1124. DropHandler = false;
  1125. }
  1126. }
  1127. //---------------------------------------------------------------------------
  1128. void __fastcall TScpCommanderForm::LocalFileControlDDDragOver(TObject * /*Sender*/,
  1129. int grfKeyState, TPoint & /*Point*/, int & dwEffect)
  1130. {
  1131. if (IsFileControl(DropSourceControl, osRemote))
  1132. {
  1133. if (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == 0) ||
  1134. (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == MK_SHIFT) &&
  1135. !WinConfiguration->DDAllowMoveInit))
  1136. {
  1137. dwEffect = DROPEFFECT_Copy;
  1138. }
  1139. }
  1140. }
  1141. //---------------------------------------------------------------------------
  1142. bool __fastcall TScpCommanderForm::DDGetTarget(AnsiString & Directory)
  1143. {
  1144. bool Result;
  1145. if (!FDDExtTarget.IsEmpty())
  1146. {
  1147. Directory = FDDExtTarget;
  1148. FDDExtTarget = "";
  1149. Result = true;
  1150. }
  1151. else
  1152. {
  1153. Result = TCustomScpExplorerForm::DDGetTarget(Directory);
  1154. }
  1155. return Result;
  1156. }
  1157. //---------------------------------------------------------------------------
  1158. void __fastcall TScpCommanderForm::DDExtInitDrag(TFileList * FileList,
  1159. bool & Created)
  1160. {
  1161. FDDExtTarget = "";
  1162. TCustomScpExplorerForm::DDExtInitDrag(FileList, Created);
  1163. }
  1164. //---------------------------------------------------------------------------
  1165. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1166. TObject * /*Sender*/, int dwEffect, AnsiString SourcePath,
  1167. AnsiString TargetPath, bool & DoOperation)
  1168. {
  1169. if (IsFileControl(DropSourceControl, osRemote))
  1170. {
  1171. AnsiString TargetDirectory;
  1172. if (InternalDDDownload(TargetDirectory))
  1173. {
  1174. if (FDDExtMapFile != NULL)
  1175. {
  1176. FDDExtTarget = TargetDirectory;
  1177. }
  1178. else
  1179. {
  1180. assert(FInternalDDDownloadList->Count > 0);
  1181. assert(dwEffect == DROPEFFECT_Copy || dwEffect == DROPEFFECT_Move);
  1182. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1183. TTransferType TransferType = dwEffect == DROPEFFECT_Copy ? ttCopy : ttMove;
  1184. if (FDDMoveSlipped)
  1185. {
  1186. TransferType = ttMove;
  1187. }
  1188. if (CopyParamDialog(tdToLocal, TransferType,
  1189. false, FInternalDDDownloadList, TargetDirectory, CopyParams,
  1190. WinConfiguration->DDTransferConfirmation, true))
  1191. {
  1192. int Params =
  1193. (TransferType == ttMove ? cpDelete : 0) |
  1194. (CopyParams.NewerOnly ? cpNewerOnly : 0);
  1195. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1196. &CopyParams, Params);
  1197. FInternalDDDownloadList->Clear();
  1198. }
  1199. }
  1200. DoOperation = false;
  1201. }
  1202. }
  1203. }
  1204. //---------------------------------------------------------------------------
  1205. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1206. TObject * /*Sender*/, int dwEffect, AnsiString /*SourcePath*/,
  1207. AnsiString /*TargetPath*/)
  1208. {
  1209. if ((dwEffect == DROPEFFECT_Move) &&
  1210. IsFileControl(DropSourceControl, osLocal))
  1211. {
  1212. ReloadLocalDirectory();
  1213. }
  1214. }
  1215. //---------------------------------------------------------------------------
  1216. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1217. {
  1218. SideEnter(osLocal);
  1219. }
  1220. //---------------------------------------------------------------------------
  1221. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1222. {
  1223. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1224. SideEnter(osLocal);
  1225. }
  1226. //---------------------------------------------------------------------------
  1227. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1228. {
  1229. if (Visible && (FCurrentSide != Side))
  1230. {
  1231. // this may get called yet before controls are initialized
  1232. CommandLineCombo->Strings->Clear();
  1233. FCommandLineComboPopulated = false;
  1234. }
  1235. TCustomScpExplorerForm::SideEnter(Side);
  1236. if (Visible)
  1237. {
  1238. UpdateControls();
  1239. LocalPathLabel->UpdateStatus();
  1240. RemotePathLabel->UpdateStatus();
  1241. }
  1242. }
  1243. //---------------------------------------------------------------------------
  1244. void __fastcall TScpCommanderForm::OpenConsole(AnsiString Command)
  1245. {
  1246. SaveCommandLine();
  1247. try
  1248. {
  1249. TCustomScpExplorerForm::OpenConsole(Command);
  1250. }
  1251. __finally
  1252. {
  1253. FCommandLineComboPopulated = false;
  1254. }
  1255. }
  1256. //---------------------------------------------------------------------------
  1257. void __fastcall TScpCommanderForm::SaveCommandLine()
  1258. {
  1259. if (FCommandLineComboPopulated)
  1260. {
  1261. CustomWinConfiguration->History[
  1262. FCurrentSide == osRemote ? "Commands" : "LocalCommands"] =
  1263. CommandLineCombo->Strings;
  1264. }
  1265. }
  1266. //---------------------------------------------------------------------------
  1267. bool __fastcall TScpCommanderForm::ExecuteCommandLine()
  1268. {
  1269. AnsiString Command = CommandLineCombo->Text;
  1270. bool Result =
  1271. !Command.IsEmpty() &&
  1272. ((FCurrentSide != osRemote) ||
  1273. (Terminal->AllowedAnyCommand(Command) &&
  1274. EnsureCommandSessionFallback(fcAnyCommand)));
  1275. if (Result)
  1276. {
  1277. CommandLinePopulate();
  1278. SaveToHistory(CommandLineCombo->Strings, Command);
  1279. CommandLineCombo->Text = "";
  1280. if (FCurrentSide == osRemote)
  1281. {
  1282. OpenConsole(Command);
  1283. }
  1284. else
  1285. {
  1286. AnsiString Program, Params, Dir;
  1287. SplitCommand(Command, Program, Params, Dir);
  1288. if (!ExecuteShell(Program, Params))
  1289. {
  1290. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
  1291. }
  1292. }
  1293. }
  1294. return Result;
  1295. }
  1296. //---------------------------------------------------------------------------
  1297. void __fastcall TScpCommanderForm::CommandLinePopulate()
  1298. {
  1299. if (!FCommandLineComboPopulated)
  1300. {
  1301. TStrings * CommandsHistory;
  1302. CommandsHistory = CustomWinConfiguration->History[
  1303. FCurrentSide == osRemote ? "Commands" : "LocalCommands"];
  1304. if ((CommandsHistory != NULL) && (CommandsHistory->Count > 0))
  1305. {
  1306. CommandLineCombo->Strings = CommandsHistory;
  1307. }
  1308. else
  1309. {
  1310. CommandLineCombo->Strings->Clear();
  1311. }
  1312. FCommandLineComboPopulated = true;
  1313. }
  1314. }
  1315. //---------------------------------------------------------------------------
  1316. void __fastcall TScpCommanderForm::GoToCommandLine()
  1317. {
  1318. ComponentVisible[fcCommandLinePanel] = true;
  1319. if (CommandLineCombo->Enabled)
  1320. {
  1321. ClickToolbarItem(CommandLineCombo, true);
  1322. }
  1323. }
  1324. //---------------------------------------------------------------------------
  1325. void __fastcall TScpCommanderForm::GoToTree()
  1326. {
  1327. if (FCurrentSide == osLocal)
  1328. {
  1329. ComponentVisible[fcLocalTree] = true;
  1330. LocalDriveView->SetFocus();
  1331. }
  1332. else
  1333. {
  1334. TCustomScpExplorerForm::GoToTree();
  1335. }
  1336. }
  1337. //---------------------------------------------------------------------------
  1338. void __fastcall TScpCommanderForm::PanelExportStore(TOperationSide Side,
  1339. TPanelExport Export, TPanelExportDestination Destination,
  1340. TStringList * ExportData)
  1341. {
  1342. if (Destination == pedCommandLine)
  1343. {
  1344. ComponentVisible[fcCommandLinePanel] = true;
  1345. AnsiString Buf;
  1346. for (int Index = 0; Index < ExportData->Count; Index++)
  1347. {
  1348. Buf += ExportData->Strings[Index] + " ";
  1349. }
  1350. CommandLineCombo->Text = CommandLineCombo->Text + Buf;
  1351. }
  1352. else
  1353. {
  1354. TCustomScpExplorerForm::PanelExportStore(Side, Export, Destination, ExportData);
  1355. }
  1356. }
  1357. //---------------------------------------------------------------------------
  1358. int __fastcall TScpCommanderForm::GetStaticComponentsHeight()
  1359. {
  1360. return TCustomScpExplorerForm::GetStaticComponentsHeight() +
  1361. (BottomDock->Visible ? BottomDock->Height : 0) +
  1362. (StatusBar->Visible ? StatusBar->Height : 0);
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. void __fastcall TScpCommanderForm::SysResizing(unsigned int Cmd)
  1366. {
  1367. TCustomScpExplorerForm::SysResizing(Cmd);
  1368. if ((Cmd == SC_MAXIMIZE) ||
  1369. ((Cmd == SC_DEFAULT) && (WindowState != wsMaximized)))
  1370. {
  1371. FNormalPanelsWidth = LocalPanel->Width + RemotePanel->Width;
  1372. }
  1373. else if ((Cmd == SC_RESTORE) ||
  1374. ((Cmd == SC_DEFAULT) && (WindowState == wsMaximized)))
  1375. {
  1376. if (FNormalPanelsWidth >= 0)
  1377. {
  1378. Panel(true)->Width = FLeftPanelWidth * FNormalPanelsWidth;
  1379. FNormalPanelsWidth = -1;
  1380. }
  1381. }
  1382. }
  1383. //---------------------------------------------------------------------------
  1384. void __fastcall TScpCommanderForm::Resize()
  1385. {
  1386. TCustomScpExplorerForm::Resize();
  1387. LeftPanelWidth = FLastLeftPanelWidth;
  1388. UpdateControls();
  1389. }
  1390. //---------------------------------------------------------------------------
  1391. void __fastcall TScpCommanderForm::LocalFileControlDDMenuPopup(TObject * /*Sender*/,
  1392. HMENU AMenu, IDataObject * /*DataObj*/, int /*AMinCustCmd*/, int /*grfKeyState*/,
  1393. TPoint & /*pt*/)
  1394. {
  1395. if (IsFileControl(DropSourceControl, osRemote) &&
  1396. !WinConfiguration->DDAllowMoveInit)
  1397. {
  1398. // index of copy item
  1399. int Index = GetMenuDefaultItem(AMenu, TRUE, 0);
  1400. assert(Index >= 0);
  1401. AnsiString Caption = Dragdrop_MIMoveStr;
  1402. MENUITEMINFO MI;
  1403. memset(&MI, 0, sizeof(MI));
  1404. MI.cbSize = sizeof(MI);
  1405. MI.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
  1406. MI.fType = MFT_STRING;
  1407. MI.wID = 1 /*DragDrop::CmdMove*/;
  1408. MI.dwTypeData = Caption.c_str();
  1409. MI.cch = Caption.Length();
  1410. MI.fState = MFS_ENABLED;
  1411. InsertMenuItem(AMenu, Index, TRUE, &MI);
  1412. if (FDDMoveSlipped)
  1413. {
  1414. SetMenuDefaultItem(AMenu, Index, TRUE);
  1415. }
  1416. FDDMoveSlipped = false;
  1417. }
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TScpCommanderForm::PathLabelDblClick(TObject * Sender)
  1421. {
  1422. OpenDirectory(Sender == LocalPathLabel ? osLocal : osRemote);
  1423. }
  1424. //---------------------------------------------------------------------------
  1425. void __fastcall TScpCommanderForm::LocalPathLabelGetStatus(
  1426. TCustomPathLabel * /*Sender*/, bool & Active)
  1427. {
  1428. // this strange form is here to make borland compiler work :-)
  1429. Active = Active || LocalDriveView->Focused();
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TScpCommanderForm::RemotePathLabelGetStatus(
  1433. TCustomPathLabel * /*Sender*/, bool & Active)
  1434. {
  1435. // this strange form is here to make borland compiler work :-)
  1436. Active = Active || RemoteDriveView->Focused();
  1437. }
  1438. //---------------------------------------------------------------------------
  1439. void __fastcall TScpCommanderForm::LocalPathLabelPathClick(
  1440. TCustomPathLabel * /*Sender*/, AnsiString Path)
  1441. {
  1442. if (ComparePaths(Path, LocalDirView->Path))
  1443. {
  1444. OpenDirectory(osLocal);
  1445. }
  1446. else
  1447. {
  1448. LocalDirView->Path = Path;
  1449. }
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. void __fastcall TScpCommanderForm::RemotePathLabelPathClick(
  1453. TCustomPathLabel * /*Sender*/, AnsiString Path)
  1454. {
  1455. if (UnixComparePaths(Path, RemoteDirView->Path))
  1456. {
  1457. OpenDirectory(osRemote);
  1458. }
  1459. else
  1460. {
  1461. RemoteDirView->Path = Path;
  1462. }
  1463. }
  1464. //---------------------------------------------------------------------------
  1465. void __fastcall TScpCommanderForm::LocalDirViewFileIconForName(
  1466. TObject * /*Sender*/, TListItem * /*Item*/, AnsiString & FileName)
  1467. {
  1468. AnsiString PartialExt = Configuration->PartialExt;
  1469. if (SameText(ExtractFileExt(FileName), PartialExt))
  1470. {
  1471. FileName.SetLength(FileName.Length() - PartialExt.Length());
  1472. }
  1473. }
  1474. //---------------------------------------------------------------------------
  1475. void __fastcall TScpCommanderForm::LocalDirViewUpdateStatusBar(
  1476. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1477. {
  1478. UpdateFileStatusBar(LocalStatusBar, FileInfo, 0);
  1479. }
  1480. //---------------------------------------------------------------------------
  1481. void __fastcall TScpCommanderForm::RemoteDirViewUpdateStatusBar(
  1482. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1483. {
  1484. UpdateFileStatusBar(RemoteStatusBar, FileInfo, 0);
  1485. }
  1486. //---------------------------------------------------------------------------
  1487. void __fastcall TScpCommanderForm::LocalStatusBarClick(TObject * /*Sender*/)
  1488. {
  1489. LocalDirView->SetFocus();
  1490. }
  1491. //---------------------------------------------------------------------------
  1492. AnsiString __fastcall TScpCommanderForm::PathForCaption()
  1493. {
  1494. AnsiString Result;
  1495. if (FCurrentSide == osLocal)
  1496. {
  1497. // for consistency do not show even local path when there is no terminal
  1498. if (Terminal != NULL)
  1499. {
  1500. switch (WinConfiguration->PathInCaption)
  1501. {
  1502. case picShort:
  1503. {
  1504. Result = ExtractFileName(LocalDirView->PathName);
  1505. if (Result.IsEmpty())
  1506. {
  1507. Result = LocalDirView->PathName;
  1508. }
  1509. }
  1510. break;
  1511. case picFull:
  1512. Result = LocalDirView->PathName;
  1513. break;
  1514. }
  1515. }
  1516. }
  1517. else
  1518. {
  1519. Result = TCustomScpExplorerForm::PathForCaption();
  1520. }
  1521. return Result;
  1522. }
  1523. //---------------------------------------------------------------------------
  1524. void __fastcall TScpCommanderForm::GetTransferPresetAutoSelectData(
  1525. TCopyParamRuleData & Data)
  1526. {
  1527. TCustomScpExplorerForm::GetTransferPresetAutoSelectData(Data);
  1528. Data.LocalDirectory = LocalDirView->PathName;
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. void __fastcall TScpCommanderForm::BeforeAction()
  1532. {
  1533. TCustomScpExplorerForm::BeforeAction();
  1534. if (LocalDirView->ItemFocused != NULL)
  1535. {
  1536. LocalDirView->ItemFocused->CancelEdit();
  1537. }
  1538. }
  1539. //---------------------------------------------------------------------------
  1540. void __fastcall TScpCommanderForm::RemoteDirViewPathChange(TCustomDirView * /*Sender*/)
  1541. {
  1542. UpdateRemotePathComboBox(RemotePathComboBox, false);
  1543. }
  1544. //---------------------------------------------------------------------------
  1545. void __fastcall TScpCommanderForm::LocalPathComboUpdateDrives()
  1546. {
  1547. TStrings* Strings = LocalPathComboBox->Strings;
  1548. Strings->BeginUpdate();
  1549. try
  1550. {
  1551. Strings->Clear();
  1552. FLocalPathComboBoxPaths->Clear();
  1553. Strings->Add(LoadStr(SPECIAL_FOLDER_MY_DOCUMENTS));
  1554. FLocalPathComboBoxPaths->AddObject(DriveInfo->SpecialFolder[CSIDL_PERSONAL]->Location,
  1555. (TObject *)DriveInfo->SpecialFolder[CSIDL_PERSONAL]->ImageIndex);
  1556. Strings->Add(LoadStr(SPECIAL_FOLDER_DESKTOP));
  1557. FLocalPathComboBoxPaths->AddObject(DriveInfo->SpecialFolder[CSIDL_DESKTOP]->Location,
  1558. (TObject *)DriveInfo->SpecialFolder[CSIDL_DESKTOP]->ImageIndex);
  1559. for (TDrive Drive = FirstDrive; Drive <= LastDrive; Drive++)
  1560. {
  1561. if (DriveInfo->Data[Drive]->Valid)
  1562. {
  1563. Strings->Add(AnsiString("&") + DriveInfo->GetPrettyName(Drive));
  1564. FLocalPathComboBoxPaths->AddObject(AnsiString(Drive) + ":\\",
  1565. (TObject *)DriveInfo->GetImageIndex(Drive));
  1566. }
  1567. }
  1568. }
  1569. __finally
  1570. {
  1571. Strings->EndUpdate();
  1572. }
  1573. }
  1574. //---------------------------------------------------------------------------
  1575. void __fastcall TScpCommanderForm::LocalPathComboUpdate()
  1576. {
  1577. // this may get called even after destructor finishes
  1578. // (e.g. from SetDockAllowDrag invoked [indirectly] from StoreParams)
  1579. if (FLocalPathComboBoxPaths != NULL)
  1580. {
  1581. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1582. int Index = 0;
  1583. while ((Index < FLocalPathComboBoxPaths->Count) &&
  1584. !ComparePaths(FLocalPathComboBoxPaths->Strings[Index],
  1585. LocalDirView->Path.SubString(1, FLocalPathComboBoxPaths->Strings[Index].Length())))
  1586. {
  1587. Index++;
  1588. }
  1589. assert(Index < FLocalPathComboBoxPaths->Count);
  1590. if (Index < FLocalPathComboBoxPaths->Count)
  1591. {
  1592. LocalPathComboBox->ItemIndex = Index;
  1593. }
  1594. }
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TScpCommanderForm::LocalDirViewPathChange(TCustomDirView * /*Sender*/)
  1598. {
  1599. LocalPathComboUpdate();
  1600. }
  1601. //---------------------------------------------------------------------------
  1602. void __fastcall TScpCommanderForm::LocalPathComboBoxCancel(TObject * /*Sender*/)
  1603. {
  1604. LocalPathComboUpdate();
  1605. }
  1606. //---------------------------------------------------------------------------
  1607. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  1608. TTBXComboBoxItem * /*Sender*/, const AnsiString AText, int AIndex,
  1609. int & ImageIndex)
  1610. {
  1611. // this may get called even before constructor starts
  1612. // (e.g. from FixControlsPlacement)
  1613. if (FLocalPathComboBoxPaths != NULL)
  1614. {
  1615. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1616. assert(AIndex < FLocalPathComboBoxPaths->Count);
  1617. if (AIndex < 0)
  1618. {
  1619. AIndex = LocalPathComboBox->ItemIndex;
  1620. }
  1621. if (AIndex >= 0)
  1622. {
  1623. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  1624. }
  1625. }
  1626. }
  1627. //---------------------------------------------------------------------------
  1628. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject * /*Sender*/)
  1629. {
  1630. assert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1631. assert((LocalPathComboBox->ItemIndex >= 0) && (LocalPathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  1632. AnsiString Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1633. if (Path.Length() == 3)
  1634. {
  1635. LocalDirView->ExecuteDrive(Path[1]);
  1636. }
  1637. else
  1638. {
  1639. LocalDirView->Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1640. }
  1641. }
  1642. //---------------------------------------------------------------------------
  1643. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  1644. {
  1645. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  1646. if ((Item == LocalPathComboBox) ||
  1647. (Item == RemotePathComboBox) ||
  1648. (Item == CommandLineCombo))
  1649. {
  1650. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  1651. }
  1652. }
  1653. //---------------------------------------------------------------------------
  1654. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  1655. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1656. {
  1657. CommandLinePopulate();
  1658. }
  1659. //---------------------------------------------------------------------------
  1660. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  1661. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  1662. {
  1663. InstallPathWordBreakProc(EditControl);
  1664. FCommandLineComboEdit = EditControl;
  1665. FToolbarEditOldWndProc = EditControl->WindowProc;
  1666. EditControl->WindowProc = CommandLineComboEditWndProc;
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. void __fastcall TScpCommanderForm::ExitToolbar()
  1670. {
  1671. CurrentPanel()->SetFocus();
  1672. }
  1673. //---------------------------------------------------------------------------
  1674. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  1675. {
  1676. bool Handled = false;
  1677. if (Message.Msg == WM_CHAR)
  1678. {
  1679. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  1680. {
  1681. case VK_ESCAPE:
  1682. CommandLineCombo->Text = "";
  1683. ExitToolbar();
  1684. Handled = true;
  1685. break;
  1686. case VK_TAB:
  1687. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1688. ExitToolbar();
  1689. Handled = true;
  1690. break;
  1691. case VK_RETURN:
  1692. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1693. ExitToolbar();
  1694. if (!ExecuteCommandLine())
  1695. {
  1696. // re-enter command line
  1697. // (most probably exited by now as message dialog was shown)
  1698. GoToCommandLine();
  1699. }
  1700. Handled = true;
  1701. break;
  1702. }
  1703. }
  1704. if (!Handled)
  1705. {
  1706. FToolbarEditOldWndProc(Message);
  1707. }
  1708. }
  1709. //---------------------------------------------------------------------------
  1710. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  1711. {
  1712. LocalPathComboUpdateDrives();
  1713. LocalPathComboUpdate();
  1714. }
  1715. //---------------------------------------------------------------------------
  1716. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  1717. {
  1718. bool WasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  1719. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1720. try
  1721. {
  1722. TCustomScpExplorerForm::HomeDirectory(Side);
  1723. }
  1724. __finally
  1725. {
  1726. NonVisualDataModule->SynchronizeBrowsingAction->Checked = WasSynchronisingBrowsing;
  1727. }
  1728. }
  1729. //---------------------------------------------------------------------------
  1730. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  1731. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1732. {
  1733. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  1734. }
  1735. //---------------------------------------------------------------------------
  1736. void __fastcall TScpCommanderForm::DoFocusRemotePath(AnsiString Path)
  1737. {
  1738. bool WasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  1739. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1740. try
  1741. {
  1742. TCustomScpExplorerForm::DoFocusRemotePath(Path);
  1743. }
  1744. __finally
  1745. {
  1746. NonVisualDataModule->SynchronizeBrowsingAction->Checked = WasSynchronisingBrowsing;
  1747. }
  1748. }
  1749. //---------------------------------------------------------------------------