ScpCommander.cpp 64 KB

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