ScpCommander.cpp 69 KB

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