ScpCommander.cpp 58 KB

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