ScpCommander.cpp 51 KB

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