| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491 |
- //---------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <StrUtils.hpp>
- #include <Common.h>
- #include "Preferences.h"
- #include <CoreMain.h>
- #include <Terminal.h>
- #include "VCLCommon.h"
- #include "GUITools.h"
- #include "Tools.h"
- #include "TextsWin.h"
- #include "HelpWin.h"
- #include "WinInterface.h"
- #include "WinConfiguration.h"
- #include "Setup.h"
- //---------------------------------------------------------------------
- #pragma link "GeneralSettings"
- #pragma link "LogSettings"
- #pragma link "CopyParams"
- #pragma link "UpDownEdit"
- #pragma link "IEComboBox"
- #pragma link "HistoryComboBox"
- #pragma link "PasswordEdit"
- #ifndef NO_RESOURCES
- #pragma resource "*.dfm"
- #endif
- //---------------------------------------------------------------------
- bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
- TPreferencesDialogData * DialogData)
- {
- bool Result;
- TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(Application);
- try
- {
- PreferencesDialog->PreferencesMode = APreferencesMode;
- Result = PreferencesDialog->Execute(DialogData);
- }
- __finally
- {
- delete PreferencesDialog;
- }
- return Result;
- }
- //---------------------------------------------------------------------
- __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
- : TForm(AOwner)
- {
- SetCorrectFormParent(this);
- FNoUpdate = 0;
- FPreferencesMode = pmDefault;
- FEditorFont = new TFont();
- FEditorFont->Color = clWindowText;
- // color tends to reset in object inspector
- EditorFontLabel->Color = clWindow;
- // currently useless
- FAfterFilenameEditDialog = false;
- FCustomCommands = new TCustomCommands();
- FCustomCommandChanging = false;
- FListViewDragDest = -1;
- FCopyParamList = new TCopyParamList();
- FEditorList = new TEditorList();
- UseSystemSettings(this);
- FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
- FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
- FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView2, true);
- ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
- LoggingFrame->Init();
- InstallPathWordBreakProc(RandomSeedFileEdit);
- InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
- InstallPathWordBreakProc(PuttyPathEdit);
- HintLabel(ShellIconsText);
- }
- //---------------------------------------------------------------------------
- __fastcall TPreferencesDialog::~TPreferencesDialog()
- {
- SAFE_DESTROY(FEditorScrollOnDragOver);
- SAFE_DESTROY(FCopyParamScrollOnDragOver);
- SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
- delete FEditorFont;
- delete FCustomCommands;
- delete FCopyParamList;
- delete FEditorList;
- }
- //---------------------------------------------------------------------
- bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
- {
- FDialogData = DialogData;
- LoadConfiguration();
- CopyParamsFrame->BeforeExecute();
- bool Result = (ShowModal() == mrOk);
- if (Result)
- {
- CopyParamsFrame->AfterExecute();
- SaveConfiguration();
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
- {
- Tree->FullExpand();
- int i = 0;
- while (i < Tree->Items->Count)
- {
- if ((!WinConfiguration->ExpertMode &&
- Tree->Items->Item[i]->SelectedIndex & 128))
- {
- Tree->Items->Delete(Tree->Items->Item[i]);
- }
- else
- {
- for (int pi = 0; pi < PageControl->PageCount; pi++)
- {
- if (PageControl->Pages[pi]->Tag == (Tree->Items->Item[i]->SelectedIndex & 127))
- {
- if (PageControl->Pages[pi]->Enabled)
- {
- Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
- PageControl->Pages[pi]->Hint = "";
- }
- else
- {
- Tree->Items->Delete(Tree->Items->Item[i]);
- i--;
- }
- break;
- }
- }
- i++;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::LoadConfiguration()
- {
- FNoUpdate++;
- try
- {
- if (FPreferencesMode != pmLogin)
- {
- LoggingFrame->LoadConfiguration();
- GeneralSettingsFrame->LoadConfiguration();
- }
- #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
- BOOLPROP(DefaultDirIsHome);
- BOOLPROP(PreservePanelState);
- BOOLPROP(DeleteToRecycleBin);
- BOOLPROP(DDTransferConfirmation);
- BOOLPROP(DDWarnLackOfTempSpace);
- BOOLPROP(ShowHiddenFiles);
- BOOLPROP(RenameWholeName);
- BOOLPROP(ShowInaccesibleDirectories);
- BOOLPROP(CopyOnDoubleClickConfirmation);
- BOOLPROP(ConfirmTransferring);
- BOOLPROP(ConfirmOverwriting);
- BOOLPROP(ConfirmResume);
- BOOLPROP(ConfirmDeleting);
- BOOLPROP(ConfirmRecycling);
- BOOLPROP(ConfirmClosingSession);
- BOOLPROP(ConfirmExitOnCompletion);
- BOOLPROP(UseLocationProfiles);
- BOOLPROP(ConfirmCommandSession);
- BOOLPROP(ContinueOnError);
- BOOLPROP(DDAllowMoveInit);
- BOOLPROP(BeepOnFinish);
- BOOLPROP(TemporaryDirectoryCleanup);
- BOOLPROP(ConfirmTemporaryDirectoryCleanup);
- BeepOnFinishAfterEdit->AsInteger =
- static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * (24*60*60);
- BOOLPROP(BalloonNotifications);
- CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
- CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
- DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
- DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
- DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
- if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
- {
- DDSystemTemporaryDirectoryButton->Checked = true;
- DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
- }
- else
- {
- DDCustomTemporaryDirectoryButton->Checked = true;
- DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
- }
- if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
- {
- NortonLikeModeCombo->ItemIndex = 2;
- }
- else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
- {
- NortonLikeModeCombo->ItemIndex = 1;
- }
- else
- {
- NortonLikeModeCombo->ItemIndex = 0;
- }
- PreserveLocalDirectoryCheck->Checked =
- WinConfiguration->ScpCommander.PreserveLocalDirectory;
- SwappedPanelsCheck->Checked =
- WinConfiguration->ScpCommander.SwappedPanels;
- FullRowSelectCheck->Checked = WinConfiguration->ScpCommander.FullRowSelect;
- TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
- ShowFullAddressCheck->Checked =
- WinConfiguration->ScpExplorer.ShowFullAddress;
- RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
- IniFileStorageButton2->Checked = (Configuration->Storage == stIniFile);
- RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
- // editor
- EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
- EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
- FEditorFont->Name = WinConfiguration->Editor.FontName;
- FEditorFont->Height = WinConfiguration->Editor.FontHeight;
- FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
- FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
- (*FEditorList) = *WinConfiguration->EditorList;
- UpdateEditorListView();
- CopyParamsFrame->Params = GUIConfiguration->DefaultCopyParam;
- ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
- ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
- ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
- ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
- SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
- SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
- SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
- (Configuration->SessionReopenAuto / 1000): 5);
- TransferSheet->Enabled = WinConfiguration->ExpertMode;
- GeneralSheet->Enabled = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
- ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
- CommanderSheet->Enabled = WinConfiguration->ExpertMode;
- GeneralSheet->Enabled = (PreferencesMode != pmLogin);
- EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
- StorageGroup->Visible = WinConfiguration->ExpertMode;
- RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
- RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
- FCustomCommands->Assign(WinConfiguration->CustomCommands);
- UpdateCustomCommandsView();
- PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
- PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
- AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
- TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
- // Queue
- QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
- QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
- QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
- QueueIndividuallyCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueIndividually;
- QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
- RememberPasswordCheck->Checked = GUIConfiguration->QueueRememberPassword;
- if (WinConfiguration->QueueView.Show == qvShow)
- {
- QueueViewShowButton->Checked = true;
- }
- else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
- {
- QueueViewHideWhenEmptyButton->Checked = true;
- }
- else
- {
- QueueViewHideButton->Checked = true;
- }
- // window
- if (WinConfiguration->PathInCaption == picFull)
- {
- PathInCaptionFullButton->Checked = true;
- }
- else if (WinConfiguration->PathInCaption == picShort)
- {
- PathInCaptionShortButton->Checked = true;
- }
- else
- {
- PathInCaptionNoneButton->Checked = true;
- }
- BOOLPROP(MinimizeToTray);
- // panels
- DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
- BOOLPROP(AutoReadDirectoryAfterOp);
- // updates
- TUpdatesConfiguration Updates = WinConfiguration->Updates;
- if (int(Updates.Period) <= 0)
- {
- UpdatesNeverButton->Checked = true;
- }
- else if (int(Updates.Period) <= 1)
- {
- UpdatesDailyButton->Checked = true;
- }
- else if (int(Updates.Period) <= 7)
- {
- UpdatesWeeklyButton->Checked = true;
- }
- else
- {
- UpdatesMonthlyButton->Checked = true;
- }
- ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
- switch (Updates.ConnectionType)
- {
- case ctDirect:
- default:
- UpdatesDirectCheck->Checked = true;
- break;
- case ctAuto:
- UpdatesAutoCheck->Checked = true;
- break;
- case ctProxy:
- UpdatesProxyCheck->Checked = true;
- break;
- }
- UpdatesProxyHostEdit->Text = Updates.ProxyHost;
- UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
- // presets
- (*FCopyParamList) = *WinConfiguration->CopyParamList;
- UpdateCopyParamListView();
- BOOLPROP(CopyParamAutoSelectNotice);
- // interface
- if (WinConfiguration->Theme == "OfficeXP")
- {
- ThemeCombo->ItemIndex = 1;
- }
- else if (WinConfiguration->Theme == "Office2003")
- {
- ThemeCombo->ItemIndex = 2;
- }
- else
- {
- ThemeCombo->ItemIndex = 0;
- }
- #undef BOOLPROP
- }
- __finally
- {
- FNoUpdate--;
- }
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::SaveConfiguration()
- {
- Configuration->BeginUpdate();
- try
- {
- TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
- if (FPreferencesMode != pmLogin)
- {
- LoggingFrame->SaveConfiguration();
- GeneralSettingsFrame->SaveConfiguration();
- }
- #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
- BOOLPROP(DefaultDirIsHome);
- BOOLPROP(PreservePanelState);
- BOOLPROP(DeleteToRecycleBin);
- BOOLPROP(DDTransferConfirmation);
- BOOLPROP(DDWarnLackOfTempSpace);
- BOOLPROP(ShowHiddenFiles);
- BOOLPROP(RenameWholeName);
- BOOLPROP(ShowInaccesibleDirectories);
- BOOLPROP(CopyOnDoubleClickConfirmation);
- BOOLPROP(ConfirmTransferring);
- BOOLPROP(ConfirmOverwriting);
- BOOLPROP(ConfirmResume);
- BOOLPROP(ConfirmDeleting);
- BOOLPROP(ConfirmRecycling);
- BOOLPROP(ConfirmClosingSession);
- BOOLPROP(ConfirmExitOnCompletion);
- BOOLPROP(UseLocationProfiles);
- BOOLPROP(ConfirmCommandSession);
- BOOLPROP(ContinueOnError);
- BOOLPROP(DDAllowMoveInit);
- BOOLPROP(BeepOnFinish);
- BOOLPROP(TemporaryDirectoryCleanup);
- BOOLPROP(ConfirmTemporaryDirectoryCleanup);
- GUIConfiguration->BeepOnFinishAfter =
- static_cast<double>(BeepOnFinishAfterEdit->Value / (24*60*60));
- BOOLPROP(BalloonNotifications);
- WinConfiguration->ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
- WinConfiguration->ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
- WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
- WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
- if (DDSystemTemporaryDirectoryButton->Checked)
- {
- WinConfiguration->DDTemporaryDirectory = "";
- }
- else
- {
- WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
- }
- Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
- TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
- if (NortonLikeModeCombo->ItemIndex == 2)
- {
- ScpCommander.NortonLikeMode = nlOff;
- }
- else if (NortonLikeModeCombo->ItemIndex == 1)
- {
- ScpCommander.NortonLikeMode = nlKeyboard;
- }
- else
- {
- ScpCommander.NortonLikeMode = nlOn;
- }
- ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
- ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
- ScpCommander.FullRowSelect = FullRowSelectCheck->Checked;
- ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
- WinConfiguration->ScpCommander = ScpCommander;
- TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
- ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
- WinConfiguration->ScpExplorer = ScpExplorer;
- Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
- // editor
- WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
- WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
- WinConfiguration->Editor.FontName = FEditorFont->Name;
- WinConfiguration->Editor.FontHeight = FEditorFont->Height;
- WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
- WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
- WinConfiguration->EditorList = FEditorList;
- // overwrites only TCopyParamType fields
- CopyParam = CopyParamsFrame->Params;
- if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
- if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
- if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
- CopyParam.ResumeThreshold = ResumeThresholdEdit->Value * 1024;
- Configuration->SessionReopenAuto =
- (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->Value * 1000) : 0);
- GUIConfiguration->SessionReopenAutoIdle =
- (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoEdit->Value * 1000) : 0);
- WinConfiguration->CustomCommands = FCustomCommands;
- GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
- GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
- WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
- WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
- // Queue
- GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
- GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
- CopyParam.Queue = QueueCheck->Checked;
- CopyParam.QueueIndividually = QueueIndividuallyCheck->Checked;
- CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
- GUIConfiguration->QueueRememberPassword = RememberPasswordCheck->Checked;
- if (QueueViewShowButton->Checked)
- {
- WinConfiguration->QueueView.Show = qvShow;
- }
- else if (QueueViewHideWhenEmptyButton->Checked)
- {
- WinConfiguration->QueueView.Show = qvHideWhenEmpty;
- }
- else
- {
- WinConfiguration->QueueView.Show = qvHide;
- }
- GUIConfiguration->DefaultCopyParam = CopyParam;
- // window
- if (PathInCaptionFullButton->Checked)
- {
- WinConfiguration->PathInCaption = picFull;
- }
- else if (PathInCaptionShortButton->Checked)
- {
- WinConfiguration->PathInCaption = picShort;
- }
- else
- {
- WinConfiguration->PathInCaption = picNone;
- }
- BOOLPROP(MinimizeToTray);
- // panels
- WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
- BOOLPROP(AutoReadDirectoryAfterOp);
- // updates
- TUpdatesConfiguration Updates = WinConfiguration->Updates;
- if (UpdatesNeverButton->Checked)
- {
- Updates.Period = 0;
- }
- else if (UpdatesDailyButton->Checked)
- {
- Updates.Period = 1;
- }
- else if (UpdatesWeeklyButton->Checked)
- {
- Updates.Period = 7;
- }
- else
- {
- Updates.Period = 30;
- }
- Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
- if (UpdatesDirectCheck->Checked)
- {
- Updates.ConnectionType = ctDirect;
- }
- else if (UpdatesAutoCheck->Checked)
- {
- Updates.ConnectionType = ctAuto;
- }
- else if (UpdatesProxyCheck->Checked)
- {
- if (!UpdatesProxyHostEdit->Text.IsEmpty())
- {
- Updates.ConnectionType = ctProxy;
- }
- else
- {
- Updates.ConnectionType = ctDirect;
- }
- }
- Updates.ProxyHost = UpdatesProxyHostEdit->Text;
- Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
- WinConfiguration->Updates = Updates;
- // presets
- WinConfiguration->CopyParamList = FCopyParamList;
- BOOLPROP(CopyParamAutoSelectNotice);
- // interface
- if (ThemeCombo->ItemIndex == 1)
- {
- WinConfiguration->Theme = "OfficeXP";
- }
- else if (ThemeCombo->ItemIndex == 2)
- {
- WinConfiguration->Theme = "Office2003";
- }
- else
- {
- WinConfiguration->Theme = "Default";
- }
- #undef BOOLPROP
- }
- __finally
- {
- Configuration->EndUpdate();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
- {
- if (PreferencesMode != value)
- {
- FPreferencesMode = value;
- GeneralSheet->Enabled = (value != pmLogin);
- LogSheet->Enabled = (value != pmLogin);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
- {
- PrepareNavigationTree(NavigationTree);
- switch (PreferencesMode) {
- case pmEditor: PageControl->ActivePage = EditorSheet; break;
- case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
- case pmQueue: PageControl->ActivePage = QueueSheet; break;
- case pmTransfer: PageControl->ActivePage = TransferSheet; break;
- case pmLogging: PageControl->ActivePage = LogSheet; break;
- case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
- case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
- case pmEditors: PageControl->ActivePage = EditorSheet; break;
- default: PageControl->ActivePage = PreferencesSheet; break;
- }
- PageControlChange(NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
- {
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TPreferencesDialog::TabSample(AnsiString Values)
- {
- AnsiString Result;
- for (int Index = 1; Index <= Values.Length(); Index++)
- {
- if (Index > 1)
- {
- Result += ' ';
- if (EditorTabSizeEdit->AsInteger > 2)
- {
- Result += AnsiString::StringOfChar(' ', EditorTabSizeEdit->AsInteger - 2);
- }
- }
- Result += Values[Index];
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpdateControls()
- {
- if (FNoUpdate == 0)
- {
- EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
- EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
- EnableControl(BalloonNotificationsCheck, TTrayIcon::SupportsBalloons());
- EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
- EnableControl(ResumeThresholdUnitLabel, ResumeThresholdEdit->Enabled);
- EnableControl(SessionReopenAutoEdit,
- SessionReopenAutoCheck->Checked || SessionReopenAutoIdleCheck->Checked);
- EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
- EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
- EnableControl(CopyOnDoubleClickConfirmationCheck,
- (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
- AnsiString EditorFontLabelText;
- EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
- (FEditorFont->Name, FEditorFont->Size)) + "\n\n";
- EditorFontLabelText += TabSample("ABCD") + "\n";
- EditorFontLabelText += TabSample("1234");
- EditorFontLabel->Caption = EditorFontLabelText;
- EditorFontLabel->Font = FEditorFont;
- bool CommandSelected = (CustomCommandsView->Selected != NULL);
- EnableControl(EditCommandButton, CommandSelected);
- EnableControl(RemoveCommandButton, CommandSelected);
- EnableControl(UpCommandButton, CommandSelected &&
- CustomCommandsView->ItemIndex > 0);
- EnableControl(DownCommandButton, CommandSelected &&
- (CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1));
- bool CopyParamSelected = (CopyParamListView->Selected != NULL);
- EnableControl(EditCopyParamButton, CopyParamSelected);
- EnableControl(DuplicateCopyParamButton, CopyParamSelected);
- EnableControl(RemoveCopyParamButton, CopyParamSelected);
- EnableControl(UpCopyParamButton, CopyParamSelected &&
- (CopyParamListView->ItemIndex > 0));
- EnableControl(DownCopyParamButton, CopyParamSelected &&
- (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
- EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
- EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
- EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
- EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
- EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
- DDCustomTemporaryDirectoryButton->Checked);
- EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
- DDAllowMoveInitCheck->Checked);
- EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
- TemporaryDirectoryCleanupCheck->Checked);
- IniFileStorageButton2->Caption =
- AnsiReplaceStr(IniFileStorageButton2->Caption, "winscp.ini",
- ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName)));
- EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
- bool EditorSelected = (EditorListView2->Selected != NULL);
- EnableControl(EditEditorButton, EditorSelected);
- EnableControl(RemoveEditorButton, EditorSelected);
- EnableControl(UpEditorButton, EditorSelected &&
- (EditorListView2->ItemIndex > 0));
- EnableControl(DownEditorButton, EditorSelected &&
- (EditorListView2->ItemIndex < EditorListView2->Items->Count - 1));
- EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
- EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
- EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
- EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
- EnableControl(PuttyPasswordCheck2, !PuttyPathEdit->Text.IsEmpty());
- EnableControl(AutoOpenInPuttyCheck, PuttyPasswordCheck2->Enabled);
- EnableControl(TelnetForFtpInPuttyCheck, PuttyPasswordCheck2->Enabled);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
- {
- if (FontDialog(FEditorFont))
- {
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::FilenameEditExit(TObject * Sender)
- {
- // duplicated in TExternalEditorDialog::FilenameEditExit
- THistoryComboBox * FilenameEdit = dynamic_cast<THistoryComboBox *>(Sender);
- try
- {
- AnsiString Filename = FilenameEdit->Text;
- if (!Filename.IsEmpty())
- {
- ReformatFileNameCommand(Filename);
- FilenameEdit->Text = Filename;
- }
- ControlChange(Sender);
- }
- catch(...)
- {
- FilenameEdit->SelectAll();
- FilenameEdit->SetFocus();
- throw;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::FilenameEditChange(
- TObject * Sender)
- {
- // duplicated in TExternalEditorDialog::FilenameEditChange
- if (FAfterFilenameEditDialog)
- {
- FAfterFilenameEditDialog = false;
- FilenameEditExit(Sender);
- }
- else
- {
- ControlChange(Sender);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
- bool & /*CanClose*/)
- {
- if (ModalResult != mrCancel)
- {
- ExitActiveControl(this);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
- {
- AnsiString IconName, Params;
- int SpecialFolder;
- if (Sender == DesktopIconButton)
- {
- IconName = AppNameVersion;
- int Result =
- MessageDialog(LoadStr(CREATE_DESKTOP_ICON), qtConfirmation,
- qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
- switch (Result)
- {
- case qaYes:
- SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
- break;
- case qaNo:
- SpecialFolder = CSIDL_DESKTOPDIRECTORY;
- break;
- default:
- Abort();
- break;
- }
- }
- else
- {
- if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
- qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
- {
- if (Sender == SendToHookButton)
- {
- IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppNameVersion));
- SpecialFolder = CSIDL_SENDTO;
- Params = "/upload";
- }
- else if (Sender == QuickLaunchIconButton)
- {
- IconName = "Microsoft\\Internet Explorer\\Quick Launch\\" +
- AppNameVersion;
- SpecialFolder = CSIDL_APPDATA;
- }
- }
- else
- {
- Abort();
- }
- }
- CreateDesktopShortCut(IconName,
- Application->ExeName, Params, "", SpecialFolder);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
- TListItem * Item)
- {
- assert(FCustomCommands);
- int Index = Item->Index;
- assert(Index >= 0 && Index <= FCustomCommands->Count);
- Item->Caption = StringReplace(FCustomCommands->Names[Index], "&", "",
- TReplaceFlags() << rfReplaceAll);
- assert(!Item->SubItems->Count);
- AnsiString Name = FCustomCommands->Names[Index];
- Item->SubItems->Add(FCustomCommands->Values[Name]);
- int Params = FCustomCommands->Params[Name];
- Item->SubItems->Add(LoadStr(
- FLAGSET(Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
- AnsiString ParamsStr;
- #define ADDPARAM(PARAM, STR) \
- if (FLAGSET(Params, PARAM)) \
- ParamsStr += (ParamsStr.IsEmpty() ? "" : "/") + LoadStr(STR);
- ADDPARAM(ccApplyToDirectories, CUSTOM_COMMAND_DIRECTORIES);
- ADDPARAM(ccRecursive, CUSTOM_COMMAND_RECURSE);
- #undef ADDPARAM
- Item->SubItems->Add(ParamsStr);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ListViewSelectItem(
- TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
- {
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
- {
- CustomCommandsView->Items->Count = FCustomCommands->Count;
- AdjustListColumnsWidth(CustomCommandsView, FCustomCommands->Count);
- CustomCommandsView->Invalidate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
- TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
- {
- if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
- {
- RemoveCommandButtonClick(NULL);
- }
- if (AddCommandButton->Enabled && (Key == VK_INSERT))
- {
- AddEditCommandButtonClick(AddCommandButton);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
- TObject * /*Sender*/)
- {
- if (EditCommandButton->Enabled)
- {
- AddEditCommandButtonClick(EditCommandButton);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::AddEditCommandButtonClick(TObject * Sender)
- {
- bool Edit = (Sender == EditCommandButton);
- AnsiString Description;
- AnsiString Command;
- int Params = 0;
- if (Edit)
- {
- int Index = CustomCommandsView->ItemIndex;
- assert(Index >= 0 && Index <= FCustomCommands->Count);
- Description = FCustomCommands->Names[Index];
- Command = FCustomCommands->Values[Description];
- Params = FCustomCommands->Params[Description];
- }
- if (DoCustomCommandDialog(Description, Command, Params, FCustomCommands,
- (Edit ? ccmEdit : ccmAdd), 0, NULL))
- {
- int Index = CustomCommandsView->ItemIndex;
- AnsiString Record = FORMAT("%s=%s", (Description, Command));
- if (Edit)
- {
- FCustomCommands->Strings[Index] = Record;
- }
- else
- {
- if (Index >= 0)
- {
- FCustomCommands->Insert(Index, Record);
- }
- else
- {
- Index = FCustomCommands->Add(Record);
- }
- }
- FCustomCommands->Params[Description] = Params;
- UpdateCustomCommandsView();
- CustomCommandsView->ItemIndex = Index;
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
- TObject * /*Sender*/)
- {
- assert(CustomCommandsView->ItemIndex >= 0 &&
- CustomCommandsView->ItemIndex < FCustomCommands->Count);
- FCustomCommands->Delete(CustomCommandsView->ItemIndex);
- UpdateCustomCommandsView();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
- {
- if (Source >= 0 && Source < FCustomCommands->Count &&
- Dest >= 0 && Dest < FCustomCommands->Count)
- {
- FCustomCommands->Move(Source, Dest);
- // workaround for bug in VCL
- CustomCommandsView->ItemIndex = -1;
- CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
- CustomCommandsView->ItemIndex = Dest;
- UpdateCustomCommandsView();
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
- {
- CustomCommandMove(CustomCommandsView->ItemIndex,
- CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
- }
- //---------------------------------------------------------------------------
- TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
- {
- if (ListView == CopyParamListView)
- {
- return FCopyParamScrollOnDragOver;
- }
- else if (ListView == CustomCommandsView)
- {
- return FCustomCommandsScrollOnDragOver;
- }
- else if (ListView == EditorListView2)
- {
- return FEditorScrollOnDragOver;
- }
- else
- {
- assert(false);
- return NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ListViewStartDrag(
- TObject * Sender, TDragObject *& /*DragObject*/)
- {
- FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
- FListViewDragDest = -1;
- ScrollOnDragOver(Sender)->StartDrag();
- }
- //---------------------------------------------------------------------------
- bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
- {
- TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
- FListViewDragDest = Item ? Item->Index : -1;
- return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
- TObject * Sender, TObject * Source, int X, int Y)
- {
- if (Source == CustomCommandsView)
- {
- if (AllowListViewDrag(Sender, X, Y))
- {
- CustomCommandMove(FListViewDragSource, FListViewDragDest);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ListViewDragOver(
- TObject * Sender, TObject * Source, int X, int Y,
- TDragState /*State*/, bool & Accept)
- {
- if (Source == Sender)
- {
- // cannot use AllowListViewDrag(X, Y) because of bug in VCL
- // (when dropped on item itself, when it was dragged over another item before,
- // that another item remains highlighted forever)
- Accept = true;
- ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
- {
- if (Source >= 0 && Source < FCopyParamList->Count &&
- Dest >= 0 && Dest < FCopyParamList->Count)
- {
- FCopyParamList->Move(Source, Dest);
- // workaround for bug in VCL
- CopyParamListView->ItemIndex = -1;
- CopyParamListView->ItemFocused = CopyParamListView->Selected;
- CopyParamListView->ItemIndex = Dest;
- UpdateCopyParamListView();
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
- TObject * Sender, TObject * Source, int X, int Y)
- {
- if (Source == CopyParamListView)
- {
- if (AllowListViewDrag(Sender, X, Y))
- {
- CopyParamMove(FListViewDragSource, FListViewDragDest);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
- {
- CopyParamMove(CopyParamListView->ItemIndex,
- CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
- TObject * /*Sender*/)
- {
- assert(CopyParamListView->ItemIndex >= 0 &&
- CopyParamListView->ItemIndex < FCopyParamList->Count);
- FCopyParamList->Delete(CopyParamListView->ItemIndex);
- UpdateCopyParamListView();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::AddEditCopyParamButtonClick(
- TObject * Sender)
- {
- TCopyParamPresetMode Mode;
- if (Sender == EditCopyParamButton)
- {
- Mode = cpmEdit;
- }
- else if (Sender == DuplicateCopyParamButton)
- {
- Mode = cpmDuplicate;
- }
- else
- {
- Mode = cpmAdd;
- }
- int Index = CopyParamListView->ItemIndex;
- TCopyParamRuleData * CopyParamRuleData =
- (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
- if (DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData))
- {
- UpdateCopyParamListView();
- CopyParamListView->ItemIndex = Index;
- // when using duplicate button, focu remains on original item
- CopyParamListView->ItemFocused = CopyParamListView->Selected;
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
- TObject * /*Sender*/)
- {
- if (EditCopyParamButton->Enabled)
- {
- AddEditCopyParamButtonClick(EditCopyParamButton);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
- TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
- {
- if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
- {
- RemoveCopyParamButtonClick(NULL);
- }
- if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
- {
- AddEditCopyParamButtonClick(AddCopyParamButton);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
- {
- if (Source >= 0 && Source < FEditorList->Count &&
- Dest >= 0 && Dest < FEditorList->Count)
- {
- FEditorList->Move(Source, Dest);
- // workaround for bug in VCL
- EditorListView2->ItemIndex = -1;
- EditorListView2->ItemFocused = EditorListView2->Selected;
- EditorListView2->ItemIndex = Dest;
- UpdateEditorListView();
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorListView2DragDrop(TObject * Sender,
- TObject * Source, int X, int Y)
- {
- if (Source == EditorListView2)
- {
- if (AllowListViewDrag(Sender, X, Y))
- {
- EditorMove(FListViewDragSource, FListViewDragDest);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
- {
- EditorMove(EditorListView2->ItemIndex,
- EditorListView2->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
- TObject * /*Sender*/)
- {
- assert(EditorListView2->ItemIndex >= 0 &&
- EditorListView2->ItemIndex < FEditorList->Count);
- FEditorList->Delete(EditorListView2->ItemIndex);
- UpdateEditorListView();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
- {
- TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
- int Index = EditorListView2->ItemIndex;
- TEditorPreferences * Editor;
- if (Mode == epmEdit)
- {
- Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
- }
- else
- {
- Editor = new TEditorPreferences();
- }
- try
- {
- bool DummyRemember = false;
- if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
- {
- if (Mode == epmEdit)
- {
- FEditorList->Change(Index, Editor);
- }
- else
- {
- if (Index < 0)
- {
- Index = FEditorList->Count;
- FEditorList->Add(Editor);
- }
- else
- {
- FEditorList->Insert(Index, Editor);
- }
- }
- // ownership of the object lost
- Editor = NULL;
- UpdateEditorListView();
- EditorListView2->ItemIndex = Index;
- UpdateControls();
- }
- }
- __finally
- {
- delete Editor;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorListView2DblClick(TObject * /*Sender*/)
- {
- if (EditEditorButton->Enabled)
- {
- AddEditEditorButtonClick(EditEditorButton);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorListView2KeyDown(TObject * /*Sender*/,
- WORD & Key, TShiftState /*Shift*/)
- {
- if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
- {
- RemoveEditorButtonClick(NULL);
- }
- if (AddEditorButton->Enabled && (Key == VK_INSERT))
- {
- AddEditEditorButtonClick(AddEditorButton);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpdateEditorListView()
- {
- EditorListView2->Items->Count = FEditorList->Count;
- AdjustListColumnsWidth(EditorListView2, FEditorList->Count);
- EditorListView2->Invalidate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorListView2Data(TObject * /*Sender*/,
- TListItem * Item)
- {
- int Index = Item->Index;
- assert(Index >= 0 && Index <= FEditorList->Count);
- const TEditorPreferences * Editor = FEditorList->Editors[Index];
- Item->Caption = Editor->Data->FileMask.Masks;
- Item->SubItems->Add(Editor->Name);
- if (Editor->Data->Editor == edExternal)
- {
- Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
- TTreeNode *Node)
- {
- if (Node->SelectedIndex)
- {
- for (Integer Index = 0; Index < PageControl->PageCount; Index++)
- {
- if (PageControl->Pages[Index]->Tag == (Node->SelectedIndex & 127))
- {
- PageControl->ActivePage = PageControl->Pages[Index];
- // reshow the accelerators, etc
- ResetSystemSettings(this);
- return;
- }
- }
- }
- assert(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
- {
- bool Found = false;
- if (PageControl->ActivePage->Tag)
- {
- for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
- {
- if ((NavigationTree->Items->Item[Index]->SelectedIndex & 127) ==
- PageControl->ActivePage->Tag)
- {
- NavigationTree->Items->Item[Index]->Selected = true;
- Found = true;
- }
- }
- }
- assert(Found);
- if (Found)
- {
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
- {
- if (Message.CharCode == VK_TAB)
- {
- TShiftState Shift = KeyDataToShiftState(Message.KeyData);
- if (Shift.Contains(ssCtrl))
- {
- TTreeNode * Node = NavigationTree->Selected;
- if (!Shift.Contains(ssShift))
- {
- Node = Node->GetNext();
- if (!Node) Node = NavigationTree->Items->GetFirstNode();
- }
- else
- {
- if (Node->GetPrev()) Node = Node->GetPrev();
- else
- while (Node->GetNext()) Node = Node->GetNext();
- }
- Node->Selected = True;
- Message.Result = 1;
- return;
- }
- }
- TForm::Dispatch(&Message);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
- {
- assert(Message.HelpInfo != NULL);
- if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
- {
- // invoke help for active page (not for whole form), regardless of focus
- // (e.g. even if focus is on control outside pagecontrol)
- Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
- }
- TForm::Dispatch(&Message);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::Dispatch(void *Message)
- {
- TMessage * M = reinterpret_cast<TMessage*>(Message);
- assert(M);
- if (M->Msg == CM_DIALOGKEY)
- {
- CMDialogKey(*((TWMKeyDown *)Message));
- }
- else if (M->Msg == WM_HELP)
- {
- WMHelp(*((TWMHelp *)Message));
- }
- else
- {
- TForm::Dispatch(Message);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::RegisterAsUrlHandlerButtonClick(
- TObject * /*Sender*/)
- {
- if (MessageDialog(LoadStr(CONFIRM_REGISTER_URL),
- qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL) == qaYes)
- {
- RegisterAsUrlHandler();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
- {
- ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
- SetFocus();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
- TObject * /*Sender*/)
- {
- AnsiString AppPath = ExtractFilePath(Application->ExeName);
- if (MessageDialog(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath)),
- qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
- {
- AddSearchPath(AppPath);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
- TObject * Sender)
- {
- EditorFontButtonClick(Sender);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpdateCopyParamListView()
- {
- CopyParamListView->Items->Count = FCopyParamList->Count;
- AdjustListColumnsWidth(CopyParamListView, FCopyParamList->Count);
- CopyParamListView->Invalidate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
- TListItem * Item)
- {
- int Index = Item->Index;
- assert(Index >= 0 && Index <= FCopyParamList->Count);
- Item->Caption = StringReplace(FCopyParamList->Names[Index], "&", "",
- TReplaceFlags() << rfReplaceAll);
- Item->SubItems->Add(BooleanToStr(FCopyParamList->Rules[Index] != NULL));
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CopyParamListViewInfoTip(
- TObject * /*Sender*/, TListItem * Item, AnsiString & InfoTip)
- {
- int Index = Item->Index;
- assert(Index >= 0 && Index <= FCopyParamList->Count);
- const TCopyParamType * CopyParam = FCopyParamList->CopyParams[Index];
- const TCopyParamRule * Rule = FCopyParamList->Rules[Index];
- InfoTip = CopyParam->GetInfoStr("; ", 0);
- if (Rule != NULL)
- {
- InfoTip += "\n-\n" + Rule->GetInfoStr("; ");
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
- {
- FormHelp(this);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
- TObject * /*Sender*/)
- {
- BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY),
- LoadStr(PREFERENCES_PUTTY_FILTER), false, false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::PuttyPathResetButtonClick(
- TObject * /*Sender*/)
- {
- PuttyPathEdit->Text = WinConfiguration->DefaultPuttyPath;
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ExportButtonClick(TObject * /*Sender*/)
- {
- AnsiString PersonalDirectory;
- ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalDirectory);
- AnsiString FileName = IncludeTrailingBackslash(PersonalDirectory) +
- ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName));
- if (SaveDialog(LoadStr(EXPORT_CONF_TITLE), LoadStr(EXPORT_CONF_FILTER), "ini", FileName))
- {
- Configuration->Export(FileName);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::PathEditBeforeDialog(
- TObject * /*Sender*/, AnsiString & Name, bool & /*Action*/)
- {
- FBeforeDialogPath = Name;
- Name = ExpandEnvironmentVariables(Name);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::PathEditAfterDialog(
- TObject * /*Sender*/, AnsiString & Name, bool & /*Action*/)
- {
- if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
- {
- Name = FBeforeDialogPath;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
- TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
- {
- AllowCollapse = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ListViewEndDrag(
- TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
- {
- ScrollOnDragOver(Sender)->EndDrag();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::RandomSeedFileEditCreateEditDialog(
- TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
- {
- USEDPARAM(DialogKind);
- assert(DialogKind == dkOpen);
- Dialog = CreateOpenDialog(dynamic_cast<TComponent *>(Sender));
- }
- //---------------------------------------------------------------------------
|