ScpCommander.cpp 51 KB

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