Preferences.cpp 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <Common.h>
  6. #include <math.h>
  7. #include "Preferences.h"
  8. #include "Custom.h"
  9. #include <CoreMain.h>
  10. #include <Terminal.h>
  11. #include <Bookmarks.h>
  12. #include "VCLCommon.h"
  13. #include "GUITools.h"
  14. #include "Tools.h"
  15. #include "TextsCore.h"
  16. #include "TextsWin.h"
  17. #include "HelpWin.h"
  18. #include "WinInterface.h"
  19. #include "WinConfiguration.h"
  20. #include "Setup.h"
  21. #include "ProgParams.h"
  22. #include "Http.h"
  23. //---------------------------------------------------------------------
  24. #pragma link "CopyParams"
  25. #pragma link "UpDownEdit"
  26. #pragma link "ComboEdit"
  27. #ifndef NO_RESOURCES
  28. #pragma link "HistoryComboBox"
  29. #pragma resource "*.dfm"
  30. #endif
  31. //---------------------------------------------------------------------
  32. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  33. TPreferencesDialogData * DialogData)
  34. {
  35. bool Result;
  36. TPreferencesDialog * PreferencesDialog =
  37. new TPreferencesDialog(GetFormOwner(), APreferencesMode);
  38. try
  39. {
  40. Result = PreferencesDialog->Execute(DialogData);
  41. if (Result)
  42. {
  43. Configuration->SaveExplicit();
  44. }
  45. }
  46. __finally
  47. {
  48. delete PreferencesDialog;
  49. }
  50. return Result;
  51. }
  52. //---------------------------------------------------------------------
  53. __fastcall TPreferencesDialog::TPreferencesDialog(
  54. TComponent* AOwner, TPreferencesMode PreferencesMode)
  55. : TForm(AOwner)
  56. {
  57. SetCorrectFormParent(this);
  58. FNoUpdate = 0;
  59. FPreferencesMode = PreferencesMode;
  60. FEditorFont.reset(new TFont());
  61. FEditorFont->Color = clWindowText;
  62. FPanelFont.reset(new TFont());
  63. FPanelFont->Color = clWindowText;
  64. // currently useless
  65. FAfterFilenameEditDialog = false;
  66. FCustomCommandList = new TCustomCommandList();
  67. FCustomCommandChanging = false;
  68. FExtensionList = new TCustomCommandList();
  69. FListViewDragDest = -1;
  70. FCopyParamList = new TCopyParamList();
  71. FEditorList = new TEditorList();
  72. FAutomaticUpdatesPossible = IsInstalled();
  73. FCustomCommandsHintItem = NULL;
  74. FAddedExtensions.reset(CreateSortedStringList());
  75. FCustomCommandOptions.reset(new TStringList());
  76. UseSystemSettings(this);
  77. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  78. FixListColumnWidth(CustomCommandsView, -1);
  79. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  80. FixListColumnWidth(CopyParamListView, -1);
  81. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView3, true);
  82. FixListColumnWidth(EditorListView3, -1);
  83. FOrigCustomCommandsViewWindowProc = CustomCommandsView->WindowProc;
  84. CustomCommandsView->WindowProc = CustomCommandsViewWindowProc;
  85. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  86. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta);
  87. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  88. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  89. HintLabel(ActionsLogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  90. HintLabel(ShellIconsText2);
  91. HotTrackLabel(CopyParamLabel);
  92. HintLabel(PuttyPathHintText, LoadStr(PUTTY_PATTERNS_HINT2));
  93. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  94. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  95. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  96. AutoWorkspaceCombo->Items->AddStrings(Workspaces.get());
  97. AutoSaveWorkspacePasswordsCheck->Caption = LoadStr(SAVE_WORKSPACE_PASSWORDS);
  98. PuttyRegistryStorageKeyEdit->Items->Add(OriginalPuttyRegistryStorageKey);
  99. PuttyRegistryStorageKeyEdit->Items->Add(KittyRegistryStorageKey);
  100. MenuButton(RegisterAsUrlHandlersButton);
  101. MenuButton(EditorFontColorButton);
  102. MenuButton(EditorBackgroundColorButton);
  103. LoadDialogImage(CommanderInterfacePicture, L"Commander");
  104. LoadDialogImage(ExplorerInterfacePicture, L"Explorer");
  105. LinkLabel(UpdatesLink);
  106. LinkAppLabel(BackgroundConfirmationsLink);
  107. HideComponentsPanel(this);
  108. }
  109. //---------------------------------------------------------------------------
  110. __fastcall TPreferencesDialog::~TPreferencesDialog()
  111. {
  112. SAFE_DESTROY(FEditorScrollOnDragOver);
  113. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  114. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  115. delete FCustomCommandList;
  116. FCustomCommandList = NULL;
  117. delete FExtensionList;
  118. FExtensionList = NULL;
  119. delete FCopyParamList;
  120. FCopyParamList = NULL;
  121. delete FEditorList;
  122. FEditorList = NULL;
  123. }
  124. //---------------------------------------------------------------------
  125. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  126. {
  127. PuttyPathEdit->Items = CustomWinConfiguration->History[L"PuttyPath"];
  128. FDialogData = DialogData;
  129. bool Result = (ShowModal() == DefaultResult(this));
  130. if (Result)
  131. {
  132. SaveConfiguration();
  133. CustomWinConfiguration->History[L"PuttyPath"] = PuttyPathEdit->Items;
  134. }
  135. else
  136. {
  137. for (int Index = 0; Index < FAddedExtensions->Count; Index++)
  138. {
  139. DeleteFile(ApiPath(FAddedExtensions->Strings[Index]));
  140. }
  141. }
  142. return Result;
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TPreferencesDialog::LoadLanguages()
  146. {
  147. if (!FLanguagesLoaded)
  148. {
  149. LanguagesView->Items->Clear();
  150. LCID Locale = GUIConfiguration->Locale;
  151. if (Locale == NULL)
  152. {
  153. DebugAssert(GUIConfiguration->AppliedLocale == WinConfiguration->DefaultLocale);
  154. Locale = WinConfiguration->DefaultLocale;
  155. }
  156. TObjectList * Locales = GUIConfiguration->Locales;
  157. for (int Index = 0; Index < Locales->Count; Index++)
  158. {
  159. TListItem * Item = LanguagesView->Items->Add();
  160. TLocaleInfo * LocaleInfo = DebugNotNull(dynamic_cast<TLocaleInfo *>(Locales->Items[Index]));
  161. Item->Caption = LocaleInfo->Name;
  162. Item->Data = LocaleInfo;
  163. Item->Focused = (LocaleInfo->Locale == Locale);
  164. Item->Selected = Item->Focused;
  165. }
  166. AutoSizeListColumnsWidth(LanguagesView);
  167. FLanguagesLoaded = true;
  168. }
  169. }
  170. //---------------------------------------------------------------------------
  171. TTabSheet * __fastcall TPreferencesDialog::FindPageForTreeNode(TTreeNode * Node)
  172. {
  173. for (int pi = 0; pi < PageControl->PageCount; pi++)
  174. {
  175. TTabSheet * Sheet = PageControl->Pages[pi];
  176. if (Sheet->Tag == Node->SelectedIndex)
  177. {
  178. return Sheet;
  179. }
  180. }
  181. DebugFail();
  182. return NULL;
  183. }
  184. //---------------------------------------------------------------------------
  185. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  186. {
  187. Tree->FullExpand();
  188. int i = 0;
  189. while (i < Tree->Items->Count)
  190. {
  191. TTreeNode * Node = Tree->Items->Item[i];
  192. TTabSheet * Sheet = FindPageForTreeNode(Node);
  193. if (DebugNotNull(Sheet))
  194. {
  195. if (Sheet->Enabled)
  196. {
  197. // gets called multiple times occasionally
  198. // (e.g. when called from upload dialog invoked by /upload)
  199. if (!Sheet->Caption.IsEmpty())
  200. {
  201. Node->Text = Sheet->Caption;
  202. Sheet->Caption = L"";
  203. }
  204. }
  205. else
  206. {
  207. Tree->Items->Delete(Node);
  208. i--;
  209. }
  210. }
  211. i++;
  212. }
  213. }
  214. //---------------------------------------------------------------------------
  215. void __fastcall TPreferencesDialog::LoadConfiguration()
  216. {
  217. FNoUpdate++;
  218. try
  219. {
  220. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  221. BOOLPROP(DefaultDirIsHome);
  222. BOOLPROP(PreservePanelState);
  223. BOOLPROP(DeleteToRecycleBin);
  224. BOOLPROP(DDTransferConfirmation);
  225. BOOLPROP(DDWarnLackOfTempSpace);
  226. BOOLPROP(ShowHiddenFiles);
  227. BOOLPROP(RenameWholeName);
  228. BOOLPROP(ShowInaccesibleDirectories);
  229. BOOLPROP(CopyOnDoubleClickConfirmation);
  230. BOOLPROP(ConfirmTransferring);
  231. BOOLPROP(ConfirmOverwriting);
  232. BOOLPROP(ConfirmResume);
  233. BOOLPROP(ConfirmDeleting);
  234. BOOLPROP(ConfirmRecycling);
  235. BOOLPROP(ConfirmExitOnCompletion);
  236. BOOLPROP(ConfirmCommandSession);
  237. BOOLPROP(ContinueOnError);
  238. BOOLPROP(DDAllowMoveInit);
  239. BOOLPROP(BeepOnFinish);
  240. BOOLPROP(TemporaryDirectoryAppendSession);
  241. BOOLPROP(TemporaryDirectoryAppendPath);
  242. BOOLPROP(TemporaryDirectoryDeterministic);
  243. BOOLPROP(TemporaryDirectoryCleanup);
  244. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  245. BOOLPROP(FullRowSelect);
  246. ConfirmClosingSessionCheck2->Checked = WinConfiguration->ConfirmClosingSession;
  247. if (WinConfiguration->DDTransferConfirmation == asAuto)
  248. {
  249. // allow grayed state only initially,
  250. // once the off state is confirmed, never allow returning
  251. // to the undefined state
  252. DDTransferConfirmationCheck->AllowGrayed = true;
  253. }
  254. CheckBoxAutoSwitchLoad(DDTransferConfirmationCheck, WinConfiguration->DDTransferConfirmation);
  255. BeepOnFinishAfterEdit->AsInteger =
  256. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  257. BOOLPROP(BalloonNotifications);
  258. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  259. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  260. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  261. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  262. {
  263. DDSystemTemporaryDirectoryButton->Checked = true;
  264. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  265. }
  266. else
  267. {
  268. DDCustomTemporaryDirectoryButton->Checked = true;
  269. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  270. }
  271. // Commander
  272. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  273. {
  274. NortonLikeModeCombo->ItemIndex = 2;
  275. }
  276. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  277. {
  278. NortonLikeModeCombo->ItemIndex = 1;
  279. }
  280. else
  281. {
  282. NortonLikeModeCombo->ItemIndex = 0;
  283. }
  284. SwappedPanelsCheck->Checked =
  285. WinConfiguration->ScpCommander.SwappedPanels;
  286. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  287. ExplorerKeyboardShortcutsCombo->ItemIndex =
  288. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts ? 1 : 0;
  289. BOOLPROP(UseLocationProfiles);
  290. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  291. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  292. // Local panel
  293. PreserveLocalDirectoryCheck->Checked =
  294. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  295. SystemContextMenuCheck->Checked =
  296. WinConfiguration->ScpCommander.SystemContextMenu;
  297. // Explorer
  298. ShowFullAddressCheck->Checked =
  299. WinConfiguration->ScpExplorer.ShowFullAddress;
  300. // select none when stNul
  301. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  302. IniFileStorageButton2->Checked = (Configuration->Storage == stIniFile);
  303. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  304. // editor
  305. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  306. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  307. if (WinConfiguration->Editor.Encoding == CP_UTF8)
  308. {
  309. EditorEncodingCombo->ItemIndex = 1;
  310. }
  311. else
  312. {
  313. EditorEncodingCombo->ItemIndex = 0;
  314. }
  315. TWinConfiguration::RestoreFont(WinConfiguration->Editor.Font, FEditorFont.get());
  316. FEditorFont->Color = WinConfiguration->Editor.FontColor;
  317. FEditorBackgroundColor = WinConfiguration->Editor.BackgroundColor;
  318. (*FEditorList) = *WinConfiguration->EditorList;
  319. UpdateEditorListView();
  320. FCopyParams = GUIConfiguration->DefaultCopyParam;
  321. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  322. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  323. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  324. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  325. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  326. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  327. (Configuration->SessionReopenAuto / MSecsPerSec) : 5);
  328. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  329. SessionReopenAutoIdleEdit->Value = (GUIConfiguration->SessionReopenAutoIdle > 0 ?
  330. (GUIConfiguration->SessionReopenAutoIdle / MSecsPerSec) : 5);
  331. SessionReopenAutoStallCheck->Checked = (Configuration->SessionReopenAutoStall > 0);
  332. SessionReopenAutoStallEdit->Value = (Configuration->SessionReopenAutoStall > 0 ?
  333. (Configuration->SessionReopenAutoStall / MSecsPerSec) : SecsPerMin);
  334. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / MSecsPerSec);
  335. GeneralSheet->Enabled = WinConfiguration->ExpertMode;
  336. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  337. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  338. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  339. StorageGroup->Visible = WinConfiguration->ExpertMode;
  340. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  341. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  342. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  343. FExtensionList->Assign(WinConfiguration->ExtensionList);
  344. UpdateCustomCommandsView();
  345. FCustomCommandOptions->Assign(WinConfiguration->CustomCommandOptions);
  346. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  347. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  348. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  349. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  350. SelectPuttyRegistryStorageKey(GUIConfiguration->PuttyRegistryStorageKey);
  351. // Queue
  352. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  353. EnableQueueByDefaultCheck->Checked = WinConfiguration->EnableQueueByDefault;
  354. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  355. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  356. QueueIndividuallyCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueIndividually;
  357. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  358. if (!GUIConfiguration->QueueKeepDoneItems)
  359. {
  360. QueueKeepDoneItemsForCombo->ItemIndex = 0;
  361. }
  362. else if (GUIConfiguration->QueueKeepDoneItemsFor < 0)
  363. {
  364. QueueKeepDoneItemsForCombo->ItemIndex = 5;
  365. }
  366. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15)
  367. {
  368. QueueKeepDoneItemsForCombo->ItemIndex = 1;
  369. }
  370. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60)
  371. {
  372. QueueKeepDoneItemsForCombo->ItemIndex = 2;
  373. }
  374. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15 * 60)
  375. {
  376. QueueKeepDoneItemsForCombo->ItemIndex = 3;
  377. }
  378. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60 * 60)
  379. {
  380. QueueKeepDoneItemsForCombo->ItemIndex = 4;
  381. }
  382. if (WinConfiguration->QueueView.Show == qvShow)
  383. {
  384. QueueViewShowButton->Checked = true;
  385. }
  386. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  387. {
  388. QueueViewHideWhenEmptyButton->Checked = true;
  389. }
  390. else
  391. {
  392. QueueViewHideButton->Checked = true;
  393. }
  394. // window
  395. AutoSaveWorkspaceCheck->Checked = WinConfiguration->AutoSaveWorkspace;
  396. AutoWorkspaceCombo->Text =
  397. DefaultStr(WinConfiguration->AutoWorkspace,
  398. // It will rarely happen that LastWorkspace is set, while AutoWorkspace not.
  399. // It can happen only when user saved workspace before opening the Preferences
  400. // dialog for the first time
  401. DefaultStr(WinConfiguration->LastWorkspace, LoadStr(NEW_WORKSPACE)));
  402. AutoSaveWorkspacePasswordsCheck->Checked = WinConfiguration->AutoSaveWorkspacePasswords;
  403. if (WinConfiguration->PathInCaption == picFull)
  404. {
  405. PathInCaptionFullButton->Checked = true;
  406. }
  407. else if (WinConfiguration->PathInCaption == picShort)
  408. {
  409. PathInCaptionShortButton->Checked = true;
  410. }
  411. else
  412. {
  413. PathInCaptionNoneButton->Checked = true;
  414. }
  415. BOOLPROP(MinimizeToTray);
  416. BOOLPROP(ExternalSessionInExistingInstance);
  417. BOOLPROP(KeepOpenWhenNoSession);
  418. BOOLPROP(ShowTips);
  419. // panels
  420. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  421. BOOLPROP(AutoReadDirectoryAfterOp);
  422. BOOLPROP(RefreshRemotePanel);
  423. RefreshRemotePanelIntervalEdit->Value =
  424. int(static_cast<double>(WinConfiguration->RefreshRemotePanelInterval) * SecsPerDay);
  425. switch (WinConfiguration->FormatSizeBytes)
  426. {
  427. case fbNone:
  428. FormatSizeBytesCombo->ItemIndex = 0;
  429. break;
  430. case fbKilobytes:
  431. FormatSizeBytesCombo->ItemIndex = 1;
  432. break;
  433. case fbShort:
  434. FormatSizeBytesCombo->ItemIndex = 2;
  435. break;
  436. default:
  437. DebugFail();
  438. }
  439. bool CustomPanelFont = !WinConfiguration->PanelFont.FontName.IsEmpty();
  440. PanelFontCheck->Checked = CustomPanelFont;
  441. if (CustomPanelFont)
  442. {
  443. TWinConfiguration::RestoreFont(WinConfiguration->PanelFont, FPanelFont.get());
  444. }
  445. else
  446. {
  447. FPanelFont->Assign(WinConfiguration->SystemIconFont);
  448. }
  449. // updates
  450. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  451. if (int(Updates.Period) <= 0)
  452. {
  453. UpdatesPeriodCombo->ItemIndex = 0;
  454. }
  455. else if (int(Updates.Period) <= 1)
  456. {
  457. UpdatesPeriodCombo->ItemIndex = 1;
  458. }
  459. else if (int(Updates.Period) <= 7)
  460. {
  461. UpdatesPeriodCombo->ItemIndex = 2;
  462. }
  463. else
  464. {
  465. UpdatesPeriodCombo->ItemIndex = 3;
  466. }
  467. UpdatesShowOnStartup->Checked = Updates.ShowOnStartup;
  468. UpdatesAuthenticationEmailEdit->Text = Updates.AuthenticationEmail;
  469. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  470. CollectUsageCheck->Checked = Configuration->CollectUsage;
  471. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  472. switch (Updates.ConnectionType)
  473. {
  474. case ctDirect:
  475. default:
  476. UpdatesDirectCheck->Checked = true;
  477. break;
  478. case ctAuto:
  479. UpdatesAutoCheck->Checked = true;
  480. break;
  481. case ctProxy:
  482. UpdatesProxyCheck->Checked = true;
  483. break;
  484. }
  485. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  486. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  487. // presets
  488. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  489. UpdateCopyParamListView();
  490. CopyParamListView->ItemIndex = 0;
  491. BOOLPROP(CopyParamAutoSelectNotice);
  492. // interface
  493. switch (CustomWinConfiguration->Interface)
  494. {
  495. case ifCommander:
  496. CommanderInterfaceButton2->Checked = true;
  497. break;
  498. case ifExplorer:
  499. ExplorerInterfaceButton2->Checked = true;
  500. break;
  501. default:
  502. DebugFail();
  503. break;
  504. }
  505. // security
  506. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  507. SessionRememberPasswordCheck->Checked = GUIConfiguration->SessionRememberPassword;
  508. // network
  509. RetrieveExternalIpAddressButton->Checked = Configuration->ExternalIpAddress.IsEmpty();
  510. CustomExternalIpAddressButton->Checked = !RetrieveExternalIpAddressButton->Checked;
  511. CustomExternalIpAddressEdit->Text = Configuration->ExternalIpAddress;
  512. TryFtpWhenSshFailsCheck->Checked = Configuration->TryFtpWhenSshFails;
  513. // logging
  514. EnableLoggingCheck->Checked = Configuration->Logging;
  515. LogProtocolCombo->ItemIndex = Configuration->LogProtocol;
  516. LogToFileCheck->Checked = Configuration->LogToFile;
  517. LogFileNameEdit3->Text =
  518. !Configuration->LogFileName.IsEmpty() ? Configuration->LogFileName : Configuration->DefaultLogFileName;
  519. if (Configuration->LogFileAppend)
  520. {
  521. LogFileAppendButton->Checked = true;
  522. }
  523. else
  524. {
  525. LogFileOverwriteButton->Checked = true;
  526. }
  527. BOOLPROP(LogSensitive);
  528. EnableActionsLoggingCheck->Checked = Configuration->LogActions;
  529. ActionsLogFileNameEdit->Text = Configuration->ActionsLogFileName;
  530. #undef BOOLPROP
  531. }
  532. __finally
  533. {
  534. FNoUpdate--;
  535. }
  536. UpdateControls();
  537. }
  538. //---------------------------------------------------------------------------
  539. void __fastcall TPreferencesDialog::SaveConfiguration()
  540. {
  541. Configuration->BeginUpdate();
  542. try
  543. {
  544. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  545. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  546. BOOLPROP(DefaultDirIsHome);
  547. BOOLPROP(PreservePanelState);
  548. BOOLPROP(DeleteToRecycleBin);
  549. BOOLPROP(DDWarnLackOfTempSpace);
  550. BOOLPROP(ShowHiddenFiles);
  551. BOOLPROP(RenameWholeName);
  552. BOOLPROP(ShowInaccesibleDirectories);
  553. BOOLPROP(CopyOnDoubleClickConfirmation);
  554. BOOLPROP(ConfirmTransferring);
  555. BOOLPROP(ConfirmOverwriting);
  556. BOOLPROP(ConfirmResume);
  557. BOOLPROP(ConfirmDeleting);
  558. BOOLPROP(ConfirmRecycling);
  559. BOOLPROP(ConfirmExitOnCompletion);
  560. BOOLPROP(ConfirmCommandSession);
  561. BOOLPROP(ContinueOnError);
  562. BOOLPROP(DDAllowMoveInit);
  563. BOOLPROP(BeepOnFinish);
  564. BOOLPROP(TemporaryDirectoryAppendSession);
  565. BOOLPROP(TemporaryDirectoryAppendPath);
  566. BOOLPROP(TemporaryDirectoryDeterministic);
  567. BOOLPROP(TemporaryDirectoryCleanup);
  568. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  569. BOOLPROP(FullRowSelect);
  570. WinConfiguration->ConfirmClosingSession = ConfirmClosingSessionCheck2->Checked;
  571. WinConfiguration->DDTransferConfirmation =
  572. CheckBoxAutoSwitchSave(DDTransferConfirmationCheck);
  573. GUIConfiguration->BeepOnFinishAfter =
  574. static_cast<double>(BeepOnFinishAfterEdit->Value / SecsPerDay);
  575. BOOLPROP(BalloonNotifications);
  576. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  577. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  578. if (DDSystemTemporaryDirectoryButton->Checked)
  579. {
  580. WinConfiguration->DDTemporaryDirectory = L"";
  581. }
  582. else
  583. {
  584. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  585. }
  586. // Commander
  587. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  588. if (NortonLikeModeCombo->ItemIndex == 2)
  589. {
  590. ScpCommander.NortonLikeMode = nlOff;
  591. }
  592. else if (NortonLikeModeCombo->ItemIndex == 1)
  593. {
  594. ScpCommander.NortonLikeMode = nlKeyboard;
  595. }
  596. else
  597. {
  598. ScpCommander.NortonLikeMode = nlOn;
  599. }
  600. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  601. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  602. ScpCommander.ExplorerKeyboardShortcuts =
  603. (ExplorerKeyboardShortcutsCombo->ItemIndex != 0);
  604. BOOLPROP(UseLocationProfiles);
  605. ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  606. ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  607. // Local panel
  608. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  609. ScpCommander.SystemContextMenu = SystemContextMenuCheck->Checked;
  610. WinConfiguration->ScpCommander = ScpCommander;
  611. // Explorer
  612. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  613. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  614. WinConfiguration->ScpExplorer = ScpExplorer;
  615. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  616. // editor
  617. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  618. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  619. switch (EditorEncodingCombo->ItemIndex)
  620. {
  621. case 1:
  622. WinConfiguration->Editor.Encoding = CP_UTF8;
  623. break;
  624. default:
  625. WinConfiguration->Editor.Encoding = CP_ACP;
  626. break;
  627. }
  628. TWinConfiguration::StoreFont(FEditorFont.get(), WinConfiguration->Editor.Font);
  629. WinConfiguration->Editor.FontColor = FEditorFont->Color;
  630. WinConfiguration->Editor.BackgroundColor = FEditorBackgroundColor;
  631. WinConfiguration->EditorList = FEditorList;
  632. // overwrites only TCopyParamType fields
  633. CopyParam = FCopyParams;
  634. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  635. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  636. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  637. CopyParam.ResumeThreshold = ResumeThresholdEdit->AsInteger * 1024;
  638. Configuration->SessionReopenAuto =
  639. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  640. GUIConfiguration->SessionReopenAutoIdle =
  641. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoIdleEdit->AsInteger * MSecsPerSec) : 0);
  642. Configuration->SessionReopenAutoStall =
  643. (SessionReopenAutoStallCheck->Checked ? (SessionReopenAutoStallEdit->AsInteger * MSecsPerSec) : 0);
  644. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->AsInteger * MSecsPerSec);
  645. WinConfiguration->CustomCommandList = FCustomCommandList;
  646. WinConfiguration->ExtensionList = FExtensionList;
  647. WinConfiguration->CustomCommandOptions = FCustomCommandOptions.get();
  648. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  649. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  650. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  651. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  652. // do not overwrite custom keys
  653. if (PuttyRegistryStorageKeyEdit->ItemIndex >= 0)
  654. {
  655. GUIConfiguration->PuttyRegistryStorageKey = PuttyRegistryStorageKeyEdit->Text;
  656. }
  657. // Queue
  658. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  659. WinConfiguration->EnableQueueByDefault = EnableQueueByDefaultCheck->Checked;
  660. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  661. CopyParam.Queue = QueueCheck->Checked;
  662. CopyParam.QueueIndividually = QueueIndividuallyCheck->Checked;
  663. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  664. GUIConfiguration->QueueKeepDoneItems = (QueueKeepDoneItemsForCombo->ItemIndex != 0);
  665. switch (QueueKeepDoneItemsForCombo->ItemIndex)
  666. {
  667. case 0:
  668. GUIConfiguration->QueueKeepDoneItemsFor = 0;
  669. break;
  670. case 1:
  671. GUIConfiguration->QueueKeepDoneItemsFor = 15;
  672. break;
  673. case 2:
  674. GUIConfiguration->QueueKeepDoneItemsFor = 60;
  675. break;
  676. case 3:
  677. GUIConfiguration->QueueKeepDoneItemsFor = 15 * 60;
  678. break;
  679. case 4:
  680. GUIConfiguration->QueueKeepDoneItemsFor = 60 * 60;
  681. break;
  682. default:
  683. GUIConfiguration->QueueKeepDoneItemsFor = -1;
  684. break;
  685. }
  686. if (QueueViewShowButton->Checked)
  687. {
  688. WinConfiguration->QueueView.Show = qvShow;
  689. }
  690. else if (QueueViewHideWhenEmptyButton->Checked)
  691. {
  692. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  693. }
  694. else
  695. {
  696. WinConfiguration->QueueView.Show = qvHide;
  697. }
  698. GUIConfiguration->DefaultCopyParam = CopyParam;
  699. // window
  700. WinConfiguration->AutoSaveWorkspace =
  701. !AutoWorkspaceCombo->Text.IsEmpty() &&
  702. AutoSaveWorkspaceCheck->Checked;
  703. if (!AutoWorkspaceCombo->Text.IsEmpty())
  704. {
  705. WinConfiguration->AutoWorkspace = AutoWorkspaceCombo->Text;
  706. }
  707. WinConfiguration->AutoSaveWorkspacePasswords = AutoSaveWorkspacePasswordsCheck->Checked;
  708. if (PathInCaptionFullButton->Checked)
  709. {
  710. WinConfiguration->PathInCaption = picFull;
  711. }
  712. else if (PathInCaptionShortButton->Checked)
  713. {
  714. WinConfiguration->PathInCaption = picShort;
  715. }
  716. else
  717. {
  718. WinConfiguration->PathInCaption = picNone;
  719. }
  720. BOOLPROP(MinimizeToTray);
  721. BOOLPROP(ExternalSessionInExistingInstance);
  722. BOOLPROP(KeepOpenWhenNoSession);
  723. BOOLPROP(ShowTips);
  724. // panels
  725. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  726. BOOLPROP(AutoReadDirectoryAfterOp);
  727. BOOLPROP(RefreshRemotePanel);
  728. WinConfiguration->RefreshRemotePanelInterval =
  729. static_cast<double>(RefreshRemotePanelIntervalEdit->Value / SecsPerDay);
  730. switch (FormatSizeBytesCombo->ItemIndex)
  731. {
  732. case 0:
  733. WinConfiguration->FormatSizeBytes = fbNone;
  734. break;
  735. case 1:
  736. WinConfiguration->FormatSizeBytes = fbKilobytes;
  737. break;
  738. case 2:
  739. WinConfiguration->FormatSizeBytes = fbShort;
  740. break;
  741. default:
  742. DebugFail();
  743. }
  744. TFontConfiguration PanelFontConfiguration;
  745. if (PanelFontCheck->Checked)
  746. {
  747. TWinConfiguration::StoreFont(FPanelFont.get(), PanelFontConfiguration);
  748. }
  749. WinConfiguration->PanelFont = PanelFontConfiguration;
  750. // updates
  751. WinConfiguration->Updates = SaveUpdates();
  752. Configuration->CollectUsage = CollectUsageCheck->Checked;
  753. // presets
  754. WinConfiguration->CopyParamList = FCopyParamList;
  755. BOOLPROP(CopyParamAutoSelectNotice);
  756. // interface
  757. if (GetInterface() != CustomWinConfiguration->Interface)
  758. {
  759. Configuration->Usage->Inc(L"InterfaceChanges");
  760. }
  761. CustomWinConfiguration->Interface = GetInterface();
  762. // network
  763. Configuration->ExternalIpAddress =
  764. (CustomExternalIpAddressButton->Checked ? CustomExternalIpAddressEdit->Text : UnicodeString());
  765. Configuration->TryFtpWhenSshFails = TryFtpWhenSshFailsCheck->Checked;
  766. // security
  767. GUIConfiguration->SessionRememberPassword = SessionRememberPasswordCheck->Checked;
  768. // logging
  769. Configuration->Logging = EnableLoggingCheck->Checked;
  770. Configuration->LogProtocol = LogProtocolCombo->ItemIndex;
  771. Configuration->LogFileName = LogToFileCheck->Checked ? LogFileNameEdit3->Text : UnicodeString();
  772. Configuration->LogFileAppend = LogFileAppendButton->Checked;
  773. BOOLPROP(LogSensitive);
  774. Configuration->LogActions = EnableActionsLoggingCheck->Checked;
  775. Configuration->ActionsLogFileName = ActionsLogFileNameEdit->Text;
  776. // languages
  777. if (LanguagesView->ItemFocused != NULL)
  778. {
  779. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data);
  780. LCID Locale;
  781. // Do not change the locale settings, unless changed explicitly by user
  782. // to allow an automatic upgrade to new translation once the UI language translation
  783. // becomes available
  784. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  785. {
  786. Locale = NULL;
  787. }
  788. else
  789. {
  790. Locale = LocaleInfo->Locale;
  791. }
  792. GUIConfiguration->Locale = Locale;
  793. }
  794. // This possibly fails, make it last, so that the other settings are preserved.
  795. // Do nothing when no option is selected (i.e. storage is stNul).
  796. if (RegistryStorageButton->Checked)
  797. {
  798. Configuration->Storage = stRegistry;
  799. }
  800. else if (IniFileStorageButton2->Checked)
  801. {
  802. Configuration->Storage = stIniFile;
  803. }
  804. #undef BOOLPROP
  805. }
  806. __finally
  807. {
  808. Configuration->EndUpdate();
  809. }
  810. }
  811. //---------------------------------------------------------------------------
  812. TUpdatesConfiguration __fastcall TPreferencesDialog::SaveUpdates()
  813. {
  814. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  815. if (UpdatesPeriodCombo->ItemIndex == 0)
  816. {
  817. Updates.Period = 0;
  818. }
  819. else if (UpdatesPeriodCombo->ItemIndex == 1)
  820. {
  821. Updates.Period = 1;
  822. }
  823. else if (UpdatesPeriodCombo->ItemIndex == 2)
  824. {
  825. Updates.Period = 7;
  826. }
  827. else
  828. {
  829. Updates.Period = 30;
  830. }
  831. Updates.ShowOnStartup = UpdatesShowOnStartup->Checked;
  832. Updates.AuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  833. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  834. if (UpdatesDirectCheck->Checked)
  835. {
  836. Updates.ConnectionType = ctDirect;
  837. }
  838. else if (UpdatesAutoCheck->Checked)
  839. {
  840. Updates.ConnectionType = ctAuto;
  841. }
  842. else if (UpdatesProxyCheck->Checked)
  843. {
  844. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  845. {
  846. Updates.ConnectionType = ctProxy;
  847. }
  848. else
  849. {
  850. Updates.ConnectionType = ctDirect;
  851. }
  852. }
  853. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  854. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  855. return Updates;
  856. }
  857. //---------------------------------------------------------------------------
  858. TInterface __fastcall TPreferencesDialog::GetInterface()
  859. {
  860. return CommanderInterfaceButton2->Checked ? ifCommander : ifExplorer;
  861. }
  862. //---------------------------------------------------------------------------
  863. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  864. {
  865. // Load only now, particularly so that we have handles allocated already.
  866. // If called before ShowModal, we end up recreating the handles,
  867. // what causes flicker of the currently focused window
  868. LoadConfiguration();
  869. InstallPathWordBreakProc(RandomSeedFileEdit);
  870. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  871. InstallPathWordBreakProc(PuttyPathEdit);
  872. InstallPathWordBreakProc(LogFileNameEdit3);
  873. InstallPathWordBreakProc(ActionsLogFileNameEdit);
  874. ListView_SetExtendedListViewStyle(CustomCommandsView->Handle, (ListView_GetExtendedListViewStyle(CustomCommandsView->Handle) & ~LVS_EX_INFOTIP));
  875. PrepareNavigationTree(NavigationTree);
  876. switch (FPreferencesMode) {
  877. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  878. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  879. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  880. case pmLogging: PageControl->ActivePage = LogSheet; break;
  881. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  882. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  883. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  884. case pmCommander: PageControl->ActivePage = CommanderSheet; break;
  885. case pmEditorInternal: PageControl->ActivePage = EditorInternalSheet; break;
  886. default: PageControl->ActivePage = PreferencesSheet; break;
  887. }
  888. PageControlChange(NULL);
  889. ActiveControl = NavigationTree;
  890. }
  891. //---------------------------------------------------------------------------
  892. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  893. {
  894. UpdateControls();
  895. }
  896. //---------------------------------------------------------------------------
  897. UnicodeString __fastcall TPreferencesDialog::TabSample(UnicodeString Values)
  898. {
  899. UnicodeString Result;
  900. for (int Index = 1; Index <= Values.Length(); Index++)
  901. {
  902. if (Index > 1)
  903. {
  904. Result += L' ';
  905. if (EditorTabSizeEdit->AsInteger > 2)
  906. {
  907. Result += UnicodeString::StringOfChar(L' ', EditorTabSizeEdit->AsInteger - 2);
  908. }
  909. }
  910. Result += Values[Index];
  911. }
  912. return Result;
  913. }
  914. //---------------------------------------------------------------------------
  915. TCustomCommandList * __fastcall TPreferencesDialog::GetCommandList(int Index)
  916. {
  917. if (Index < FCustomCommandList->Count)
  918. {
  919. return FCustomCommandList;
  920. }
  921. else
  922. {
  923. return FExtensionList;
  924. }
  925. }
  926. //---------------------------------------------------------------------------
  927. int __fastcall TPreferencesDialog::GetCommandIndex(int Index)
  928. {
  929. if (Index >= FCustomCommandList->Count)
  930. {
  931. Index -= FCustomCommandList->Count;
  932. }
  933. return Index;
  934. }
  935. //---------------------------------------------------------------------------
  936. int __fastcall TPreferencesDialog::GetListCommandIndex(TCustomCommandList * List)
  937. {
  938. int Index;
  939. if (GetCommandList(CustomCommandsView->ItemIndex) == List)
  940. {
  941. Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  942. }
  943. else
  944. {
  945. Index = -1;
  946. }
  947. return Index;
  948. }
  949. //---------------------------------------------------------------------------
  950. int __fastcall TPreferencesDialog::GetCommandListIndex(TCustomCommandList * List, int Index)
  951. {
  952. if (List == FExtensionList)
  953. {
  954. Index += FCustomCommandList->Count;
  955. }
  956. return Index;
  957. }
  958. //---------------------------------------------------------------------------
  959. void __fastcall TPreferencesDialog::UpdateControls()
  960. {
  961. if (FNoUpdate == 0)
  962. {
  963. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  964. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  965. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  966. EnableControl(ResumeThresholdUnitLabel2, ResumeThresholdEdit->Enabled);
  967. EnableControl(SessionReopenAutoEdit, SessionReopenAutoCheck->Checked);
  968. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  969. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  970. EnableControl(SessionReopenAutoIdleEdit, SessionReopenAutoIdleCheck->Checked);
  971. EnableControl(SessionReopenAutoIdleLabel, SessionReopenAutoIdleEdit->Enabled);
  972. EnableControl(SessionReopenAutoIdleSecLabel, SessionReopenAutoIdleEdit->Enabled);
  973. EnableControl(SessionReopenAutoStallEdit, SessionReopenAutoStallCheck->Checked);
  974. EnableControl(SessionReopenAutoStallLabel, SessionReopenAutoStallEdit->Enabled);
  975. EnableControl(SessionReopenAutoStallSecLabel, SessionReopenAutoStallEdit->Enabled);
  976. EnableControl(SessionReopenTimeoutEdit,
  977. SessionReopenAutoEdit->Enabled || SessionReopenAutoStallCheck->Checked);
  978. EnableControl(SessionReopenTimeoutLabel, SessionReopenTimeoutEdit->Enabled);
  979. EnableControl(SessionReopenTimeoutSecLabel,SessionReopenTimeoutEdit->Enabled);
  980. EnableControl(CopyOnDoubleClickConfirmationCheck,
  981. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  982. TFont * ActualPanelFont = PanelFontCheck->Checked ? FPanelFont.get() : WinConfiguration->SystemIconFont;
  983. UnicodeString PanelFontLabelText;
  984. PanelFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  985. (ActualPanelFont->Name, ActualPanelFont->Size));
  986. PanelFontLabel->Caption = PanelFontLabelText;
  987. if (!SameFont(PanelFontLabel->Font, ActualPanelFont))
  988. {
  989. PanelFontLabel->Font = ActualPanelFont;
  990. }
  991. EnableControl(RefreshRemotePanelIntervalEdit, RefreshRemotePanelCheck->Checked);
  992. EnableControl(RefreshRemoteDirectoryUnitLabel, RefreshRemotePanelCheck->Checked);
  993. UnicodeString EditorFontLabelText;
  994. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  995. (FEditorFont->Name, FEditorFont->Size)) + L"\n\n";
  996. EditorFontLabelText += TabSample(L"ABCD") + L"\n";
  997. EditorFontLabelText += TabSample(L"1234");
  998. EditorFontLabel->Caption = EditorFontLabelText;
  999. TColor EditorFontColor = GetWindowTextColor(FEditorFont->Color);
  1000. if (!SameFont(EditorFontLabel->Font, FEditorFont.get()) ||
  1001. (EditorFontLabel->Font->Color != EditorFontColor))
  1002. {
  1003. std::unique_ptr<TFont> Font(new TFont);
  1004. Font->Assign(FEditorFont.get());
  1005. Font->Color = EditorFontColor;
  1006. EditorFontLabel->Font = Font.get();
  1007. }
  1008. EditorFontLabel->Color = GetWindowColor(FEditorBackgroundColor);
  1009. TCustomCommandList * CommandList = GetCommandList(CustomCommandsView->ItemIndex);
  1010. int CommandIndex = GetCommandIndex(CustomCommandsView->ItemIndex);
  1011. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  1012. bool CustomCommandSelected = CommandSelected && (CommandList == FCustomCommandList);
  1013. bool ExtensionSelected = CommandSelected && (CommandList == FExtensionList);
  1014. EnableControl(EditCommandButton, CustomCommandSelected);
  1015. EditCommandButton->Visible = !ExtensionSelected;
  1016. EnableControl(ConfigureCommandButton, ExtensionSelected && CommandList->Commands[CommandIndex]->AnyOptionWithFlag(TCustomCommandType::ofConfig));
  1017. ConfigureCommandButton->Visible = ExtensionSelected;
  1018. EnableControl(RemoveCommandButton, CommandSelected);
  1019. EnableControl(UpCommandButton, CommandSelected && (CommandIndex > 0));
  1020. EnableControl(DownCommandButton, CommandSelected && (CommandIndex < CommandList->Count - 1));
  1021. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  1022. EnableControl(EditCopyParamButton, CopyParamSelected);
  1023. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  1024. EnableControl(RemoveCopyParamButton,
  1025. CopyParamSelected && (CopyParamListView->ItemIndex >= 1));
  1026. EnableControl(UpCopyParamButton,
  1027. CopyParamSelected && (CopyParamListView->ItemIndex > 1));
  1028. EnableControl(DownCopyParamButton,
  1029. CopyParamSelected &&
  1030. (CopyParamListView->ItemIndex >= 1) &&
  1031. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  1032. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  1033. UnicodeString InfoStr;
  1034. if (CopyParamSelected)
  1035. {
  1036. const TCopyParamType * SelectedCopyParam = GetCopyParam(CopyParamListView->ItemIndex);
  1037. InfoStr = SelectedCopyParam->GetInfoStr(L"; ", 0);
  1038. if (CopyParamListView->ItemIndex >= 1)
  1039. {
  1040. const TCopyParamRule * Rule = FCopyParamList->Rules[CopyParamListView->ItemIndex - 1];
  1041. if (Rule != NULL)
  1042. {
  1043. InfoStr += L"\n" + FORMAT(ReplaceStr(LoadStr(COPY_PARAM_RULE), L"\n", L" "), (Rule->GetInfoStr(L"; ")));
  1044. }
  1045. }
  1046. }
  1047. SetLabelHintPopup(CopyParamLabel, InfoStr);
  1048. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  1049. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  1050. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  1051. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  1052. DDCustomTemporaryDirectoryButton->Checked);
  1053. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  1054. DDAllowMoveInitCheck->Checked);
  1055. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  1056. TemporaryDirectoryCleanupCheck->Checked);
  1057. // allow only when some of the known storages is selected,
  1058. // and particularly do not allow switching storage, when we start with stNul,
  1059. // as that would destroy the stored configuration
  1060. EnableControl(StorageGroup, RegistryStorageButton->Checked || IniFileStorageButton2->Checked);
  1061. IniFileStorageButton2->Caption =
  1062. AnsiReplaceStr(IniFileStorageButton2->Caption, L"(winscp.ini)",
  1063. FORMAT(L"(%s)", (ExpandEnvironmentVariables(Configuration->IniFileStorageName))));
  1064. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  1065. bool EditorSelected = (EditorListView3->Selected != NULL);
  1066. EnableControl(EditEditorButton, EditorSelected);
  1067. EnableControl(RemoveEditorButton, EditorSelected);
  1068. EnableControl(UpEditorButton, EditorSelected &&
  1069. (EditorListView3->ItemIndex > 0));
  1070. EnableControl(DownEditorButton, EditorSelected &&
  1071. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  1072. // updates
  1073. EnableControl(UpdatesAuthenticationEmailEdit, FAutomaticUpdatesPossible);
  1074. EnableControl(UpdatesAuthenticationEmailLabel, UpdatesAuthenticationEmailEdit->Enabled);
  1075. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  1076. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  1077. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  1078. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  1079. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1080. bool IsSiteCommand = false;
  1081. bool IsPasswordCommand = false;
  1082. try
  1083. {
  1084. TRemoteCustomCommand RemoteCustomCommand;
  1085. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1086. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1087. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1088. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1089. IsPasswordCommand = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1090. }
  1091. catch (...)
  1092. {
  1093. // noop
  1094. }
  1095. bool AnyPuttyPath = !PuttyPathEdit->Text.IsEmpty();
  1096. EnableControl(PuttyPasswordCheck2, AnyPuttyPath && !IsPasswordCommand);
  1097. EnableControl(AutoOpenInPuttyCheck, AnyPuttyPath);
  1098. EnableControl(TelnetForFtpInPuttyCheck,
  1099. AnyPuttyPath && !IsSiteCommand);
  1100. EnableControl(PuttyRegistryStorageKeyEdit,
  1101. AnyPuttyPath && !IsSiteCommand);
  1102. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1103. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1104. // network
  1105. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1106. // window
  1107. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1108. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1109. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1110. !Configuration->DisablePasswordStoring &&
  1111. AutoWorkspaceCombo->Enabled);
  1112. // integration
  1113. // There's no quick launch in Windows 7
  1114. EnableControl(QuickLaunchIconButton, !IsWin7());
  1115. MakeDefaultHandlerItem->Visible = IsWinVista();
  1116. // languages
  1117. LanguageChangeLabel->Visible =
  1118. DebugAlwaysTrue(!GUIConfiguration->CanApplyLocaleImmediately) &&
  1119. (LanguagesView->ItemFocused != NULL) &&
  1120. (static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data)->Locale != GUIConfiguration->AppliedLocale);
  1121. // logging
  1122. EnableControl(LogProtocolCombo, EnableLoggingCheck->Checked);
  1123. EnableControl(LogToFileCheck, LogProtocolCombo->Enabled);
  1124. EnableControl(LogFileNameEdit3, LogToFileCheck->Enabled && LogToFileCheck->Checked);
  1125. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1126. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1127. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1128. EnableControl(LogSensitiveCheck, LogProtocolCombo->Enabled);
  1129. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1130. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1131. // interface
  1132. InterfaceChangeLabel->Visible =
  1133. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1134. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1135. }
  1136. }
  1137. //---------------------------------------------------------------------------
  1138. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1139. {
  1140. if (FontDialog(FEditorFont.get()))
  1141. {
  1142. UpdateControls();
  1143. }
  1144. }
  1145. //---------------------------------------------------------------------------
  1146. void __fastcall TPreferencesDialog::EditorFontColorChange(TColor Color)
  1147. {
  1148. FEditorFont->Color = Color;
  1149. UpdateControls();
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall TPreferencesDialog::EditorFontColorButtonClick(TObject * /*Sender*/)
  1153. {
  1154. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1155. // "internal error" when passing menu directly to unique_ptr.
  1156. // Splitting it to two statements seems to help.
  1157. // The same hack exists in TSiteAdvancedDialog::ColorButtonClick
  1158. TPopupMenu * Menu = CreateColorPopupMenu(FEditorFont->Color, EditorFontColorChange);
  1159. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1160. FColorPopupMenu.reset(Menu);
  1161. MenuPopup(Menu, EditorFontColorButton);
  1162. }
  1163. //---------------------------------------------------------------------------
  1164. void __fastcall TPreferencesDialog::EditorBackgroundColorChange(TColor Color)
  1165. {
  1166. FEditorBackgroundColor = Color;
  1167. UpdateControls();
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TPreferencesDialog::EditorBackgroundColorButtonClick(TObject * /*Sender*/)
  1171. {
  1172. // See comment in EditorFontColorButtonClick.
  1173. // We are using session color (contrary to editor text color) for background
  1174. // for a consistency with color selection menu on editor toolbar.
  1175. TTBXPopupMenu * PopupMenu = new TTBXPopupMenu(Application);
  1176. FColorPopupMenu.reset(PopupMenu);
  1177. CreateEditorBackgroundColorMenu(PopupMenu->Items, FEditorBackgroundColor, EditorBackgroundColorChange);
  1178. MenuPopup(FColorPopupMenu.get(), EditorBackgroundColorButton);
  1179. }
  1180. //---------------------------------------------------------------------------
  1181. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1182. {
  1183. if (FontDialog(FPanelFont.get()))
  1184. {
  1185. PanelFontCheck->Checked = true;
  1186. UpdateControls();
  1187. }
  1188. }
  1189. //---------------------------------------------------------------------------
  1190. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1191. bool & /*CanClose*/)
  1192. {
  1193. if (ModalResult == DefaultResult(this))
  1194. {
  1195. ExitActiveControl(this);
  1196. }
  1197. }
  1198. //---------------------------------------------------------------------------
  1199. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1200. {
  1201. UnicodeString IconName, Params;
  1202. int SpecialFolder;
  1203. if (Sender == DesktopIconButton)
  1204. {
  1205. IconName = AppName;
  1206. int Result =
  1207. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1208. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1209. switch (Result)
  1210. {
  1211. case qaYes:
  1212. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1213. break;
  1214. case qaNo:
  1215. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1216. break;
  1217. default:
  1218. Abort();
  1219. break;
  1220. }
  1221. }
  1222. else
  1223. {
  1224. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1225. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1226. {
  1227. if (Sender == SendToHookButton)
  1228. {
  1229. IconName = FMTLOAD(SENDTO_HOOK_NAME2, (AppName));
  1230. SpecialFolder = CSIDL_SENDTO;
  1231. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1232. }
  1233. else if (Sender == QuickLaunchIconButton)
  1234. {
  1235. IconName = L"Microsoft\\Internet Explorer\\Quick Launch\\" +
  1236. AppName;
  1237. SpecialFolder = CSIDL_APPDATA;
  1238. }
  1239. }
  1240. else
  1241. {
  1242. Abort();
  1243. }
  1244. }
  1245. TInstantOperationVisualizer Visualizer;
  1246. CreateDesktopShortCut(IconName,
  1247. Application->ExeName, Params, L"", SpecialFolder);
  1248. }
  1249. //---------------------------------------------------------------------------
  1250. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1251. TListItem * Item)
  1252. {
  1253. // WORKAROUND We get here on Wine after destructor is called
  1254. if ((FCustomCommandList != NULL) && (FExtensionList != NULL))
  1255. {
  1256. int Index = Item->Index;
  1257. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  1258. UnicodeString Caption = StripHotkey(Command->Name);
  1259. Item->Caption = Caption;
  1260. DebugAssert(!Item->SubItems->Count);
  1261. Item->SubItems->Add(Command->Command);
  1262. Item->SubItems->Add(LoadStr(
  1263. FLAGSET(Command->Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1264. }
  1265. }
  1266. //---------------------------------------------------------------------------
  1267. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1268. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1269. {
  1270. UpdateControls();
  1271. }
  1272. //---------------------------------------------------------------------------
  1273. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1274. {
  1275. CustomCommandsView->Items->Count = FCustomCommandList->Count + FExtensionList->Count;
  1276. AutoSizeListColumnsWidth(CustomCommandsView, 1);
  1277. CustomCommandsView->Invalidate();
  1278. // particularly after command is edited/configured, make sure the hint is updated,
  1279. // even if we manage to display a hint for the same command as before the change
  1280. FCustomCommandsHintItem = NULL;
  1281. }
  1282. //---------------------------------------------------------------------------
  1283. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1284. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1285. {
  1286. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1287. {
  1288. RemoveCommandButtonClick(NULL);
  1289. }
  1290. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1291. {
  1292. AddEditCommand(false);
  1293. }
  1294. }
  1295. //---------------------------------------------------------------------------
  1296. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1297. TObject * /*Sender*/)
  1298. {
  1299. if (EditCommandButton->Enabled)
  1300. {
  1301. AddEditCommand(true);
  1302. }
  1303. else if (ConfigureCommandButton->Enabled)
  1304. {
  1305. ConfigureCommand();
  1306. }
  1307. }
  1308. //---------------------------------------------------------------------------
  1309. static int __fastcall AddCommandToList(TCustomCommandList * List, int Index, TCustomCommandType * Command)
  1310. {
  1311. if (Index >= 0)
  1312. {
  1313. List->Insert(Index, Command);
  1314. }
  1315. else
  1316. {
  1317. List->Add(Command);
  1318. Index = List->Count - 1;
  1319. }
  1320. return Index;
  1321. }
  1322. //---------------------------------------------------------------------------
  1323. void __fastcall TPreferencesDialog::AddEditCommand(bool Edit)
  1324. {
  1325. TCustomCommandType Command;
  1326. if (Edit)
  1327. {
  1328. int Index = CustomCommandsView->ItemIndex;
  1329. DebugAssert(GetCommandList(Index) == FCustomCommandList);
  1330. Command = *FCustomCommandList->Commands[GetCommandIndex(Index)];
  1331. }
  1332. TShortCuts ShortCuts;
  1333. if (WinConfiguration->SharedBookmarks != NULL)
  1334. {
  1335. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1336. }
  1337. FCustomCommandList->ShortCuts(ShortCuts);
  1338. FExtensionList->ShortCuts(ShortCuts);
  1339. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1340. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1341. {
  1342. int Index = GetListCommandIndex(FCustomCommandList);
  1343. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1344. if (Edit)
  1345. {
  1346. DebugAssert(Index < FCustomCommandList->Count);
  1347. FCustomCommandList->Change(Index, ACommand);
  1348. }
  1349. else
  1350. {
  1351. Index = AddCommandToList(FCustomCommandList, Index, ACommand);
  1352. }
  1353. UpdateCustomCommandsView();
  1354. CustomCommandsView->ItemIndex = GetCommandListIndex(FCustomCommandList, Index);
  1355. CustomCommandsView->ItemFocused->MakeVisible(false);
  1356. UpdateControls();
  1357. }
  1358. }
  1359. //---------------------------------------------------------------------------
  1360. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1361. TObject * /*Sender*/)
  1362. {
  1363. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1364. int Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1365. if (List == FExtensionList)
  1366. {
  1367. const TCustomCommandType * CustomComand = List->Commands[Index];
  1368. // If the extension was added in this "preferences session", remove the file
  1369. int PathIndex = FAddedExtensions->IndexOf(CustomComand->FileName);
  1370. if (PathIndex >= 0)
  1371. {
  1372. FAddedExtensions->Delete(PathIndex);
  1373. DeleteFile(ApiPath(CustomComand->FileName));
  1374. }
  1375. }
  1376. List->Delete(Index);
  1377. UpdateCustomCommandsView();
  1378. UpdateControls();
  1379. }
  1380. //---------------------------------------------------------------------------
  1381. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1382. {
  1383. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1384. int SourceIndex = GetCommandIndex(Source);
  1385. int DestIndex = GetCommandIndex(Dest);
  1386. List->Move(SourceIndex, DestIndex);
  1387. // workaround for bug in VCL
  1388. CustomCommandsView->ItemIndex = -1;
  1389. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  1390. CustomCommandsView->ItemIndex = Dest;
  1391. UpdateCustomCommandsView();
  1392. UpdateControls();
  1393. }
  1394. //---------------------------------------------------------------------------
  1395. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1396. {
  1397. CustomCommandMove(CustomCommandsView->ItemIndex,
  1398. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1399. }
  1400. //---------------------------------------------------------------------------
  1401. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1402. {
  1403. if (ListView == CopyParamListView)
  1404. {
  1405. return FCopyParamScrollOnDragOver;
  1406. }
  1407. else if (ListView == CustomCommandsView)
  1408. {
  1409. return FCustomCommandsScrollOnDragOver;
  1410. }
  1411. else if (ListView == EditorListView3)
  1412. {
  1413. return FEditorScrollOnDragOver;
  1414. }
  1415. else
  1416. {
  1417. DebugFail();
  1418. return NULL;
  1419. }
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1423. TObject * Sender, TDragObject *& /*DragObject*/)
  1424. {
  1425. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1426. FListViewDragDest = -1;
  1427. ScrollOnDragOver(Sender)->StartDrag();
  1428. }
  1429. //---------------------------------------------------------------------------
  1430. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1431. {
  1432. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1433. return Item ? Item->Index : -1;
  1434. }
  1435. //---------------------------------------------------------------------------
  1436. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1437. {
  1438. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1439. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1443. TObject * Sender, TObject * Source, int X, int Y)
  1444. {
  1445. if (Source == CustomCommandsView)
  1446. {
  1447. if (AllowListViewDrag(Sender, X, Y) &&
  1448. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1449. {
  1450. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1451. }
  1452. }
  1453. }
  1454. //---------------------------------------------------------------------------
  1455. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1456. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1457. {
  1458. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1459. if (Source == Sender)
  1460. {
  1461. int Dest = PointToListViewIndex(Sender, X, Y);
  1462. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1463. {
  1464. Accept = false;
  1465. }
  1466. }
  1467. }
  1468. //---------------------------------------------------------------------------
  1469. void __fastcall TPreferencesDialog::ListViewDragOver(
  1470. TObject * Sender, TObject * Source, int X, int Y,
  1471. TDragState /*State*/, bool & Accept)
  1472. {
  1473. if (Source == Sender)
  1474. {
  1475. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1476. // (when dropped on item itself, when it was dragged over another item before,
  1477. // that another item remains highlighted forever)
  1478. Accept = true;
  1479. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1480. }
  1481. }
  1482. //---------------------------------------------------------------------------
  1483. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1484. {
  1485. if (Index == 0)
  1486. {
  1487. return &FCopyParams;
  1488. }
  1489. else
  1490. {
  1491. return FCopyParamList->CopyParams[Index - 1];
  1492. }
  1493. }
  1494. //---------------------------------------------------------------------------
  1495. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1496. {
  1497. if (Source >= 1 && Source < (1 + FCopyParamList->Count) &&
  1498. Dest >= 0 && Dest < (1 + FCopyParamList->Count))
  1499. {
  1500. if (Dest == 0)
  1501. {
  1502. Dest = 1;
  1503. }
  1504. FCopyParamList->Move(Source - 1, Dest - 1);
  1505. // workaround for bug in VCL
  1506. CopyParamListView->ItemIndex = -1;
  1507. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1508. CopyParamListView->ItemIndex = Dest;
  1509. UpdateCopyParamListView();
  1510. UpdateControls();
  1511. }
  1512. }
  1513. //---------------------------------------------------------------------------
  1514. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1515. TObject * Sender, TObject * Source, int X, int Y)
  1516. {
  1517. if (Source == CopyParamListView)
  1518. {
  1519. if (AllowListViewDrag(Sender, X, Y))
  1520. {
  1521. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1522. }
  1523. }
  1524. }
  1525. //---------------------------------------------------------------------------
  1526. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1527. {
  1528. CopyParamMove(CopyParamListView->ItemIndex,
  1529. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1530. }
  1531. //---------------------------------------------------------------------------
  1532. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1533. TObject * /*Sender*/)
  1534. {
  1535. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1536. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1537. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1538. UpdateCopyParamListView();
  1539. UpdateControls();
  1540. }
  1541. //---------------------------------------------------------------------------
  1542. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1543. {
  1544. int Index = CopyParamListView->ItemIndex;
  1545. bool Result;
  1546. if ((Index == 0) && (Mode == cpmEdit))
  1547. {
  1548. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1549. }
  1550. else
  1551. {
  1552. TCopyParamRuleData * CopyParamRuleData =
  1553. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1554. // negative (when default is selected) means add to the end
  1555. Index--;
  1556. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, FCopyParams);
  1557. if (Result)
  1558. {
  1559. UpdateCopyParamListView();
  1560. CopyParamListView->ItemIndex = Index + 1;
  1561. // when using duplicate button, focus remains on original item
  1562. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1563. }
  1564. }
  1565. if (Result)
  1566. {
  1567. UpdateControls();
  1568. }
  1569. }
  1570. //---------------------------------------------------------------------------
  1571. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1572. {
  1573. AddEditCopyParam(cpmAdd);
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1577. {
  1578. AddEditCopyParam(cpmEdit);
  1579. }
  1580. //---------------------------------------------------------------------------
  1581. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1582. {
  1583. AddEditCopyParam(cpmDuplicate);
  1584. }
  1585. //---------------------------------------------------------------------------
  1586. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1587. TObject * /*Sender*/)
  1588. {
  1589. if (EditCopyParamButton->Enabled)
  1590. {
  1591. AddEditCopyParam(cpmEdit);
  1592. }
  1593. }
  1594. //---------------------------------------------------------------------------
  1595. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1596. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1597. {
  1598. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1599. {
  1600. RemoveCopyParamButtonClick(NULL);
  1601. }
  1602. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1603. {
  1604. AddEditCopyParam(cpmAdd);
  1605. }
  1606. }
  1607. //---------------------------------------------------------------------------
  1608. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1609. {
  1610. if (Source >= 0 && Source < FEditorList->Count &&
  1611. Dest >= 0 && Dest < FEditorList->Count)
  1612. {
  1613. FEditorList->Move(Source, Dest);
  1614. // workaround for bug in VCL
  1615. EditorListView3->ItemIndex = -1;
  1616. EditorListView3->ItemFocused = EditorListView3->Selected;
  1617. EditorListView3->ItemIndex = Dest;
  1618. UpdateEditorListView();
  1619. UpdateControls();
  1620. }
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1624. TObject * Source, int X, int Y)
  1625. {
  1626. if (Source == EditorListView3)
  1627. {
  1628. if (AllowListViewDrag(Sender, X, Y))
  1629. {
  1630. EditorMove(FListViewDragSource, FListViewDragDest);
  1631. }
  1632. }
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1636. {
  1637. EditorMove(EditorListView3->ItemIndex,
  1638. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1639. }
  1640. //---------------------------------------------------------------------------
  1641. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1642. TObject * /*Sender*/)
  1643. {
  1644. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1645. EditorListView3->ItemIndex < FEditorList->Count);
  1646. FEditorList->Delete(EditorListView3->ItemIndex);
  1647. UpdateEditorListView();
  1648. UpdateControls();
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1652. {
  1653. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1654. int Index = EditorListView3->ItemIndex;
  1655. TEditorPreferences * Editor;
  1656. if (Mode == epmEdit)
  1657. {
  1658. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1659. }
  1660. else
  1661. {
  1662. Editor = new TEditorPreferences();
  1663. }
  1664. try
  1665. {
  1666. bool DummyRemember = false;
  1667. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1668. {
  1669. if (Mode == epmEdit)
  1670. {
  1671. FEditorList->Change(Index, Editor);
  1672. }
  1673. else
  1674. {
  1675. if (Index < 0)
  1676. {
  1677. Index = FEditorList->Count;
  1678. FEditorList->Add(Editor);
  1679. }
  1680. else
  1681. {
  1682. FEditorList->Insert(Index, Editor);
  1683. }
  1684. }
  1685. // ownership of the object lost
  1686. Editor = NULL;
  1687. UpdateEditorListView();
  1688. EditorListView3->ItemIndex = Index;
  1689. UpdateControls();
  1690. }
  1691. }
  1692. __finally
  1693. {
  1694. delete Editor;
  1695. }
  1696. }
  1697. //---------------------------------------------------------------------------
  1698. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1699. {
  1700. if (EditEditorButton->Enabled)
  1701. {
  1702. AddEditEditorButtonClick(EditEditorButton);
  1703. }
  1704. }
  1705. //---------------------------------------------------------------------------
  1706. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1707. WORD & Key, TShiftState /*Shift*/)
  1708. {
  1709. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1710. {
  1711. RemoveEditorButtonClick(NULL);
  1712. }
  1713. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1714. {
  1715. AddEditEditorButtonClick(AddEditorButton);
  1716. }
  1717. }
  1718. //---------------------------------------------------------------------------
  1719. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1720. {
  1721. EditorListView3->Items->Count = FEditorList->Count;
  1722. AutoSizeListColumnsWidth(EditorListView3);
  1723. EditorListView3->Invalidate();
  1724. }
  1725. //---------------------------------------------------------------------------
  1726. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1727. TListItem * Item)
  1728. {
  1729. // WORKAROUND We get here on Wine after destructor is called
  1730. if (FEditorList != NULL)
  1731. {
  1732. int Index = Item->Index;
  1733. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  1734. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1735. Item->Caption = Editor->Name;
  1736. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1737. if (Editor->Data->Editor == edExternal)
  1738. {
  1739. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1740. }
  1741. }
  1742. }
  1743. //---------------------------------------------------------------------------
  1744. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1745. TTreeNode * Node)
  1746. {
  1747. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  1748. {
  1749. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  1750. // reshow the accelerators, etc
  1751. ResetSystemSettings(this);
  1752. // This is particularly here to enable EditCopyParamButton,
  1753. // as for some reason CopyParamListView->Selected is NULL until
  1754. // its page is shown for the first time
  1755. UpdateControls();
  1756. }
  1757. }
  1758. //---------------------------------------------------------------------------
  1759. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1760. {
  1761. // this is probably only ever called from FormShow (explicitly)
  1762. bool Found = false;
  1763. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  1764. {
  1765. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1766. {
  1767. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1768. PageControl->ActivePage->Tag)
  1769. {
  1770. NavigationTree->Items->Item[Index]->Selected = true;
  1771. Found = true;
  1772. }
  1773. }
  1774. }
  1775. if (DebugAlwaysTrue(Found))
  1776. {
  1777. UpdateControls();
  1778. }
  1779. }
  1780. //---------------------------------------------------------------------------
  1781. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1782. {
  1783. if (Message.CharCode == VK_TAB)
  1784. {
  1785. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1786. if (Shift.Contains(ssCtrl))
  1787. {
  1788. TTreeNode * Node = NavigationTree->Selected;
  1789. if (!Shift.Contains(ssShift))
  1790. {
  1791. Node = Node->GetNext();
  1792. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1793. }
  1794. else
  1795. {
  1796. if (Node->GetPrev()) Node = Node->GetPrev();
  1797. else
  1798. while (Node->GetNext()) Node = Node->GetNext();
  1799. }
  1800. Node->Selected = True;
  1801. Message.Result = 1;
  1802. return;
  1803. }
  1804. }
  1805. TForm::Dispatch(&Message);
  1806. }
  1807. //---------------------------------------------------------------------------
  1808. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1809. {
  1810. DebugAssert(Message.HelpInfo != NULL);
  1811. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1812. {
  1813. // invoke help for active page (not for whole form), regardless of focus
  1814. // (e.g. even if focus is on control outside pagecontrol)
  1815. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1816. }
  1817. TForm::Dispatch(&Message);
  1818. }
  1819. //---------------------------------------------------------------------------
  1820. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1821. {
  1822. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1823. DebugAssert(M);
  1824. if (M->Msg == CM_DIALOGKEY)
  1825. {
  1826. CMDialogKey(*((TWMKeyDown *)Message));
  1827. }
  1828. else if (M->Msg == WM_HELP)
  1829. {
  1830. WMHelp(*((TWMHelp *)Message));
  1831. }
  1832. else
  1833. {
  1834. TForm::Dispatch(Message);
  1835. }
  1836. }
  1837. //---------------------------------------------------------------------------
  1838. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  1839. TObject * /*Sender*/)
  1840. {
  1841. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  1842. }
  1843. //---------------------------------------------------------------------------
  1844. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  1845. {
  1846. unsigned int Result =
  1847. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  1848. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1849. if (Result == qaYes)
  1850. {
  1851. TInstantOperationVisualizer Visualizer;
  1852. RegisterForDefaultProtocols();
  1853. }
  1854. }
  1855. //---------------------------------------------------------------------------
  1856. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  1857. {
  1858. unsigned int Result =
  1859. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  1860. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1861. if (Result == qaYes)
  1862. {
  1863. TInstantOperationVisualizer Visualizer;
  1864. UnregisterForProtocols();
  1865. }
  1866. }
  1867. //---------------------------------------------------------------------------
  1868. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  1869. {
  1870. TOperationVisualizer Visualizer;
  1871. LaunchAdvancedAssociationUI();
  1872. }
  1873. //---------------------------------------------------------------------------
  1874. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  1875. {
  1876. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  1877. SetFocus();
  1878. }
  1879. //---------------------------------------------------------------------------
  1880. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1881. TObject * /*Sender*/)
  1882. {
  1883. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  1884. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  1885. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1886. {
  1887. TInstantOperationVisualizer Visualizer;
  1888. AddSearchPath(AppPath);
  1889. }
  1890. }
  1891. //---------------------------------------------------------------------------
  1892. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  1893. TObject * Sender)
  1894. {
  1895. EditorFontButtonClick(Sender);
  1896. }
  1897. //---------------------------------------------------------------------------
  1898. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  1899. {
  1900. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  1901. AutoSizeListColumnsWidth(CopyParamListView);
  1902. CopyParamListView->Invalidate();
  1903. }
  1904. //---------------------------------------------------------------------------
  1905. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  1906. TListItem * Item)
  1907. {
  1908. // WORKAROUND We get here on Wine after destructor is called
  1909. if (FCopyParamList != NULL)
  1910. {
  1911. UnicodeString Name;
  1912. UnicodeString Rule;
  1913. int Index = Item->Index;
  1914. if (Index == 0)
  1915. {
  1916. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  1917. }
  1918. else
  1919. {
  1920. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  1921. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  1922. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  1923. }
  1924. Item->Caption = Name;
  1925. Item->SubItems->Add(Rule);
  1926. }
  1927. }
  1928. //---------------------------------------------------------------------------
  1929. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  1930. {
  1931. FormHelp(this);
  1932. }
  1933. //---------------------------------------------------------------------------
  1934. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  1935. TObject * /*Sender*/)
  1936. {
  1937. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  1938. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  1939. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  1940. }
  1941. //---------------------------------------------------------------------------
  1942. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  1943. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1944. {
  1945. FBeforeDialogPath = Name;
  1946. Name = ExpandEnvironmentVariables(Name);
  1947. }
  1948. //---------------------------------------------------------------------------
  1949. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  1950. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1951. {
  1952. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1953. {
  1954. Name = FBeforeDialogPath;
  1955. }
  1956. }
  1957. //---------------------------------------------------------------------------
  1958. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  1959. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1960. {
  1961. AllowCollapse = false;
  1962. }
  1963. //---------------------------------------------------------------------------
  1964. void __fastcall TPreferencesDialog::ListViewEndDrag(
  1965. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  1966. {
  1967. ScrollOnDragOver(Sender)->EndDrag();
  1968. }
  1969. //---------------------------------------------------------------------------
  1970. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  1971. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  1972. {
  1973. if (Value == 0)
  1974. {
  1975. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  1976. Handled = true;
  1977. }
  1978. }
  1979. //---------------------------------------------------------------------------
  1980. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  1981. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  1982. {
  1983. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  1984. {
  1985. Value = 0;
  1986. Handled = true;
  1987. }
  1988. }
  1989. //---------------------------------------------------------------------------
  1990. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  1991. {
  1992. bool Result;
  1993. bool Retry;
  1994. do
  1995. {
  1996. Retry = false;
  1997. Result = !AnyOtherInstanceOfSelf();
  1998. if (!Result)
  1999. {
  2000. unsigned int Answer =
  2001. MessageDialog(
  2002. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2003. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2004. HELP_MASTER_PASSWORD);
  2005. switch (Answer)
  2006. {
  2007. case qaRetry:
  2008. Retry = true;
  2009. break;
  2010. case qaIgnore:
  2011. Result = true;
  2012. break;
  2013. case qaCancel:
  2014. default:
  2015. // noop
  2016. break;
  2017. }
  2018. }
  2019. }
  2020. while (Retry && !Result);
  2021. return Result;
  2022. }
  2023. //---------------------------------------------------------------------------
  2024. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2025. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2026. {
  2027. // Save master password.
  2028. // This is unlikely to fail, as storage is written explicitly already
  2029. // when writing the recrypted passwords
  2030. Configuration->SaveExplicit();
  2031. TQueryType QueryType = qtInformation;
  2032. if (RecryptPasswordErrors->Count > 0)
  2033. {
  2034. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2035. QueryType = qtWarning;
  2036. }
  2037. MoreMessageDialog(
  2038. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2039. }
  2040. //---------------------------------------------------------------------------
  2041. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2042. {
  2043. UnicodeString NewPassword;
  2044. if (DoChangeMasterPasswordDialog(NewPassword))
  2045. {
  2046. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2047. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2048. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2049. }
  2050. }
  2051. //---------------------------------------------------------------------------
  2052. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2053. TObject * /*Sender*/)
  2054. {
  2055. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2056. {
  2057. try
  2058. {
  2059. if (CanSetMasterPassword())
  2060. {
  2061. if (UseMasterPasswordCheck->Checked)
  2062. {
  2063. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2064. }
  2065. else
  2066. {
  2067. if (DoMasterPasswordDialog())
  2068. {
  2069. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2070. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2071. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2072. }
  2073. }
  2074. }
  2075. }
  2076. __finally
  2077. {
  2078. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2079. UpdateControls();
  2080. }
  2081. }
  2082. }
  2083. //---------------------------------------------------------------------------
  2084. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2085. TObject * /*Sender*/)
  2086. {
  2087. if (CanSetMasterPassword())
  2088. {
  2089. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2090. }
  2091. }
  2092. //---------------------------------------------------------------------------
  2093. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2094. {
  2095. std::unique_ptr<TStrings> Data(TextToStringList(GetUsageData()));
  2096. UnicodeString Message =
  2097. Data->Text.IsEmpty() ? MainInstructions(LoadStr(USAGE_DATA_NONE)) : LoadStr(USAGE_DATA2);
  2098. MoreMessageDialog(Message, Data.get(), qtInformation, qaOK, HELP_USAGE);
  2099. }
  2100. //---------------------------------------------------------------------------
  2101. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2102. {
  2103. if (EditCopyParamButton->Enabled)
  2104. {
  2105. AddEditCopyParam(cpmEdit);
  2106. }
  2107. }
  2108. //---------------------------------------------------------------------------
  2109. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2110. TCustomListView * Sender, TListItem * Item,
  2111. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2112. {
  2113. if (Item->Index == 0)
  2114. {
  2115. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2116. }
  2117. }
  2118. //---------------------------------------------------------------------------
  2119. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2120. {
  2121. PuttyRegistryStorageKeyEdit->ItemIndex =
  2122. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2123. }
  2124. //---------------------------------------------------------------------------
  2125. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2126. {
  2127. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2128. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2129. {
  2130. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2131. }
  2132. else if (ContainsText(PuttyPath, KittyExecutable))
  2133. {
  2134. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2135. }
  2136. UpdateControls();
  2137. }
  2138. //---------------------------------------------------------------------------
  2139. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2140. TTreeNode * Node, bool & /*AllowChange*/)
  2141. {
  2142. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2143. // delay load as this can be time consuming
  2144. if (Sheet == LanguagesSheet)
  2145. {
  2146. LoadLanguages();
  2147. }
  2148. }
  2149. //---------------------------------------------------------------------------
  2150. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2151. {
  2152. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2153. }
  2154. //---------------------------------------------------------------------------
  2155. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2156. {
  2157. CommanderInterfaceButton2->SetFocus();
  2158. }
  2159. //---------------------------------------------------------------------------
  2160. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2161. {
  2162. ExplorerInterfaceButton2->SetFocus();
  2163. }
  2164. //---------------------------------------------------------------------------
  2165. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2166. {
  2167. PanelFontButtonClick(Sender);
  2168. }
  2169. //---------------------------------------------------------------------------
  2170. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2171. {
  2172. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2173. {
  2174. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2175. if (!FVerifiedUpdatesAuthenticationEmail.IsEmpty())
  2176. {
  2177. TUpdatesConfiguration Updates = SaveUpdates();
  2178. {
  2179. TInstantOperationVisualizer Visualizer;
  2180. QueryUpdates(Updates);
  2181. }
  2182. UnicodeString AuthenticationError = Updates.Results.AuthenticationError;
  2183. if (!AuthenticationError.IsEmpty())
  2184. {
  2185. AuthenticationError = FormatUpdatesMessage(AuthenticationError);
  2186. if (HasParagraphs(AuthenticationError))
  2187. {
  2188. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2189. }
  2190. else
  2191. {
  2192. AuthenticationError = MainInstructions(AuthenticationError);
  2193. }
  2194. UnicodeString HelpUrl = GetEnableAutomaticUpdatesUrl();
  2195. unsigned int Result =
  2196. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HelpUrl);
  2197. if (Result == qaAbort)
  2198. {
  2199. Abort();
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. //---------------------------------------------------------------------------
  2206. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2207. {
  2208. EnableAutomaticUpdates();
  2209. }
  2210. //---------------------------------------------------------------------------
  2211. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2212. {
  2213. FOrigCustomCommandsViewWindowProc(Message);
  2214. if (Message.Msg == CN_NOTIFY)
  2215. {
  2216. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2217. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2218. {
  2219. // request CDDS_ITEMPOSTPAINT notification
  2220. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2221. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2222. int Index = CustomDraw->nmcd.dwItemSpec;
  2223. int CommandIndex = GetCommandIndex(Index);
  2224. TCustomCommandList * List = GetCommandList(Index);
  2225. // after end of every list, except for the last last list
  2226. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2227. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2228. {
  2229. TRect Rect;
  2230. Rect.Top = CustomDraw->iSubItem;
  2231. Rect.Left = LVIR_BOUNDS;
  2232. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2233. HDC DC = CustomDraw->nmcd.hdc;
  2234. SelectObject(DC, GetStockObject(DC_PEN));
  2235. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2236. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2237. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2238. }
  2239. }
  2240. }
  2241. }
  2242. //---------------------------------------------------------------------------
  2243. void __fastcall TPreferencesDialog::AddExtension()
  2244. {
  2245. const UnicodeString HistoryKey(L"ExtensionPath");
  2246. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2247. UnicodeString Path;
  2248. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2249. HELP_NONE, History.get(), true) &&
  2250. !Path.IsEmpty())
  2251. {
  2252. CustomWinConfiguration->History[HistoryKey] = History.get();
  2253. bool Trusted;
  2254. bool Latest;
  2255. UnicodeString FileName;
  2256. UnicodeString ExtensionPath;
  2257. std::unique_ptr<TStringList> Lines(new TStringList());
  2258. std::unique_ptr<TCustomCommandType> CustomCommand;
  2259. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2260. try
  2261. {
  2262. if (IsUrl)
  2263. {
  2264. UnicodeString Url = Path;
  2265. Url = SecureUrl(Url);
  2266. bool WinSCPURL = IsWinSCPUrl(Url);
  2267. if (WinSCPURL)
  2268. {
  2269. Url = ProgramUrl(Url);
  2270. // The EncodeUrlString should not be necessary, but as we get the value from regitry, let's be safe
  2271. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2272. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2273. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2274. Url = CampaignUrl(Url);
  2275. }
  2276. TOperationVisualizer Visualizer;
  2277. std::unique_ptr<THttp> Http(CreateHttp());
  2278. Http->URL = Url;
  2279. std::unique_ptr<TStrings> Headers(new TStringList());
  2280. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2281. Http->RequestHeaders = Headers.get();
  2282. Http->Get();
  2283. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2284. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2285. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2286. if (FileName.IsEmpty())
  2287. {
  2288. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2289. }
  2290. Lines->Text = Http->Response;
  2291. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2292. }
  2293. else
  2294. {
  2295. if (!FileExists(ApiPath(Path)))
  2296. {
  2297. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2298. }
  2299. Trusted = true;
  2300. Latest = true;
  2301. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2302. FileName = ExtractFileName(Path);
  2303. if (!Id.IsEmpty())
  2304. {
  2305. ExtensionPath = Path;
  2306. }
  2307. LoadScriptFromFile(Path, Lines.get());
  2308. }
  2309. // validate syntax
  2310. CustomCommand.reset(new TCustomCommandType());
  2311. CustomCommand->LoadExtension(Lines.get(), FileName);
  2312. }
  2313. catch (Exception & E)
  2314. {
  2315. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2316. }
  2317. if (!ExtensionPath.IsEmpty())
  2318. {
  2319. int Index = FExtensionList->FindIndexByFileName(Path);
  2320. if (Index > 0)
  2321. {
  2322. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2323. CustomCommandsView->ItemFocused->MakeVisible(false);
  2324. CustomCommandsView->SetFocus();
  2325. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2326. }
  2327. }
  2328. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2329. {
  2330. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2331. }
  2332. if (ExtensionPath.IsEmpty())
  2333. {
  2334. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2335. {
  2336. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2337. if (FileNameOnly.IsEmpty())
  2338. {
  2339. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2340. }
  2341. else
  2342. {
  2343. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2344. }
  2345. }
  2346. }
  2347. if (Trusted ||
  2348. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2349. {
  2350. if (ExtensionPath.IsEmpty())
  2351. {
  2352. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2353. if (!DirectoryExists(UserExtensionsPath) &&
  2354. !ForceDirectories(UserExtensionsPath))
  2355. {
  2356. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2357. }
  2358. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2359. int Counter = 1;
  2360. UnicodeString OriginalExtensionPath = ExtensionPath;
  2361. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2362. while (FileExists(ApiPath(ExtensionPath)))
  2363. {
  2364. Counter++;
  2365. ExtensionPath = LeftStr(OriginalExtensionPath, P - 1) + IntToStr(Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2366. }
  2367. Lines->SaveToFile(ApiPath(ExtensionPath));
  2368. FAddedExtensions->Add(ExtensionPath);
  2369. }
  2370. int Index = GetListCommandIndex(FExtensionList);
  2371. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2372. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2373. CustomCommand->LoadExtension(ExtensionPath);
  2374. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2375. UpdateCustomCommandsView();
  2376. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2377. CustomCommandsView->ItemFocused->MakeVisible(false);
  2378. UpdateControls();
  2379. if (!Latest)
  2380. {
  2381. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2382. }
  2383. if (IsUrl)
  2384. {
  2385. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2386. }
  2387. else
  2388. {
  2389. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2390. }
  2391. }
  2392. }
  2393. }
  2394. //---------------------------------------------------------------------------
  2395. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2396. {
  2397. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2398. {
  2399. AddEditCommand(false);
  2400. }
  2401. else
  2402. {
  2403. AddExtension();
  2404. }
  2405. }
  2406. //---------------------------------------------------------------------------
  2407. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2408. {
  2409. AddEditCommand(false);
  2410. }
  2411. //---------------------------------------------------------------------------
  2412. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2413. {
  2414. AddExtension();
  2415. }
  2416. //---------------------------------------------------------------------------
  2417. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2418. {
  2419. AddEditCommand(true);
  2420. }
  2421. //---------------------------------------------------------------------------
  2422. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2423. {
  2424. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2425. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2426. MenuPopup(AddCommandMenu, AddCommandButton);
  2427. }
  2428. //---------------------------------------------------------------------------
  2429. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2430. {
  2431. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2432. int Index = (Item != NULL) ? Item->Index : -1;
  2433. if (Index != FCustomCommandsHintItem)
  2434. {
  2435. Application->CancelHint();
  2436. UnicodeString Hint;
  2437. if (Index >= 0)
  2438. {
  2439. TCustomCommandList * List = GetCommandList(Index);
  2440. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2441. Hint = StripHotkey(Command->Name);
  2442. if (Command->ShortCut != 0)
  2443. {
  2444. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2445. }
  2446. if (!Command->Description.IsEmpty())
  2447. {
  2448. Hint += L"\n" + Command->Description;
  2449. }
  2450. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get());
  2451. if (List == FExtensionList)
  2452. {
  2453. Hint += L"\n" + Command->FileName;
  2454. }
  2455. }
  2456. CustomCommandsView->Hint = Hint;
  2457. FCustomCommandsHintItem = Index;
  2458. }
  2459. }
  2460. //---------------------------------------------------------------------------
  2461. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2462. {
  2463. PageControl->ActivePage = QueueSheet;
  2464. PageControlChange(NULL);
  2465. QueueNoConfirmationCheck->SetFocus();
  2466. QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
  2467. }
  2468. //---------------------------------------------------------------------------
  2469. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2470. {
  2471. ConfigureCommand();
  2472. }
  2473. //---------------------------------------------------------------------------
  2474. void __fastcall TPreferencesDialog::ConfigureCommand()
  2475. {
  2476. int Index = CustomCommandsView->ItemIndex;
  2477. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  2478. DoCustomCommandOptionsDialog(Command, FCustomCommandOptions.get(), TCustomCommandType::ofConfig, NULL);
  2479. UpdateCustomCommandsView();
  2480. }
  2481. //---------------------------------------------------------------------------
  2482. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2483. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2484. {
  2485. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2486. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2487. {
  2488. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2489. }
  2490. if (LocaleInfo->Completeness < 0)
  2491. {
  2492. Sender->Canvas->Font->Color = clRed;
  2493. }
  2494. else if (LocaleInfo->Completeness < 100)
  2495. {
  2496. Sender->Canvas->Font->Color = clGrayText;
  2497. }
  2498. }
  2499. //---------------------------------------------------------------------------