| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- //---------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Preferences.h"
- #include <Common.h>
- #include <ScpMain.h>
- #include "VCLCommon.h"
- #include "Tools.h"
- #include "TextsWin.h"
- #include "UserInterface.h"
- #include "WinConfiguration.h"
- //---------------------------------------------------------------------
- #pragma link "GeneralSettings"
- #pragma link "LogSettings"
- #pragma link "XPGroupBox"
- #pragma link "CopyParams"
- #pragma link "UpDownEdit"
- #pragma link "IEComboBox"
- #pragma resource "*.dfm"
- //---------------------------------------------------------------------
- bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode)
- {
- bool Result;
- TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(Application);
- try
- {
- PreferencesDialog->PreferencesMode = APreferencesMode;
- Result = PreferencesDialog->Execute();
- }
- __finally
- {
- delete PreferencesDialog;
- }
- return Result;
- }
- //---------------------------------------------------------------------
- __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
- : TForm(AOwner)
- {
- FPreferencesMode = pmDefault;
- LoggingFrame->OnGetDefaultLogFileName = LoggingGetDefaultLogFileName;
- CopyParamsFrame->Direction = pdAll;
- FEditorFont = new TFont();
- FAfterExternalEditorDialog = false;
- FCustomCommands = new TStringList();
- FCustomCommandChanging = false;
- FCustomCommandDragDest = -1;
- UseSystemFont(this);
- }
- //---------------------------------------------------------------------------
- __fastcall TPreferencesDialog::~TPreferencesDialog()
- {
- LoggingFrame->OnGetDefaultLogFileName = NULL;
- delete FEditorFont;
- delete FCustomCommands;
- }
- //---------------------------------------------------------------------
- bool __fastcall TPreferencesDialog::Execute()
- {
- LoadConfiguration();
- bool Result = (ShowModal() == mrOk);
- if (Result) SaveConfiguration();
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::LoggingGetDefaultLogFileName(
- TObject * /*Sender*/, AnsiString & DefaultLogFileName)
- {
- DefaultLogFileName = "";
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::LoadConfiguration()
- {
- if (FPreferencesMode != pmLogin)
- {
- LoggingFrame->LoadConfiguration();
- GeneralSettingsFrame->LoadConfiguration();
- }
- #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
- BOOLPROP(DefaultDirIsHome);
- BOOLPROP(DeleteToRecycleBin);
- BOOLPROP(DDAllowMove);
- BOOLPROP(DDTransferConfirmation);
- BOOLPROP(DDWarnLackOfTempSpace);
- BOOLPROP(ShowHiddenFiles);
- BOOLPROP(ShowInaccesibleDirectories);
- BOOLPROP(CopyOnDoubleClick);
- BOOLPROP(CopyOnDoubleClickConfirmation);
- BOOLPROP(ConfirmOverwriting);
- BOOLPROP(ConfirmDeleting);
- BOOLPROP(ConfirmClosingSession);
- BOOLPROP(UseLocationProfiles);
- BOOLPROP(ContinueOnError);
- #undef BOOLPROP
- if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
- {
- DDSystemTemporaryDirectoryButton->Checked = true;
- DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
- }
- else
- {
- DDCustomTemporaryDirectoryButton->Checked = true;
- DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
- }
- ExplorerStyleSelectionCheck->Checked =
- WinConfiguration->ScpCommander.ExplorerStyleSelection;
- PreserveLocalDirectoryCheck->Checked =
- WinConfiguration->ScpCommander.PreserveLocalDirectory;
- ShowFullAddressCheck->Checked =
- WinConfiguration->ScpExplorer.ShowFullAddress;
- RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
- IniFileStorageButton->Checked = (Configuration->Storage == stIniFile);
- RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
- // editor
- EditorInternalButton->Checked = WinConfiguration->Editor.Editor == edInternal;
- EditorExternalButton->Checked = WinConfiguration->Editor.Editor == edExternal;
- AnsiString ExternalEditor = WinConfiguration->Editor.ExternalEditor;
- if (!ExternalEditor.IsEmpty())
- {
- TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
- }
- ExternalEditorEdit->Text = ExternalEditor;
- EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
- FEditorFont->Name = WinConfiguration->Editor.FontName;
- FEditorFont->Height = WinConfiguration->Editor.FontHeight;
- FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
- FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
- CopyParamsFrame->Params = Configuration->CopyParam;
- ResumeOnButton->Checked = Configuration->CopyParam.ResumeSupport == rsOn;
- ResumeSmartButton->Checked = Configuration->CopyParam.ResumeSupport == rsSmart;
- ResumeOffButton->Checked = Configuration->CopyParam.ResumeSupport == rsOff;
- ResumeThresholdEdit->Value = Configuration->CopyParam.ResumeThreshold / 1024;
- TransferSheet->TabVisible = WinConfiguration->ExpertMode;
- GeneralSheet->TabVisible = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
- ExplorerSheet->TabVisible = WinConfiguration->ExpertMode;
- CommanderSheet->TabVisible = WinConfiguration->ExpertMode;
- GeneralSheet->TabVisible = (PreferencesMode != pmLogin);
- EditorSheet->TabVisible = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
- StorageGroup->Visible = WinConfiguration->ExpertMode;
- RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
- RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
- FCustomCommands->Assign(WinConfiguration->CustomCommands);
- CustomCommandDescEdit->Text = "";
- CustomCommandEdit->Text = "";
- UpdateCustomCommandsView();
- PuttyPathEdit->FileName = WinConfiguration->PuttyPath;
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::SaveConfiguration()
- {
- Configuration->BeginUpdate();
- try
- {
- if (FPreferencesMode != pmLogin)
- {
- LoggingFrame->SaveConfiguration();
- GeneralSettingsFrame->SaveConfiguration();
- }
- #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
- BOOLPROP(DefaultDirIsHome);
- BOOLPROP(DeleteToRecycleBin);
- BOOLPROP(DDAllowMove);
- BOOLPROP(DDTransferConfirmation);
- BOOLPROP(DDWarnLackOfTempSpace);
- BOOLPROP(ShowHiddenFiles);
- BOOLPROP(ShowInaccesibleDirectories);
- BOOLPROP(CopyOnDoubleClick);
- BOOLPROP(CopyOnDoubleClickConfirmation);
- BOOLPROP(ConfirmOverwriting);
- BOOLPROP(ConfirmDeleting);
- BOOLPROP(ConfirmClosingSession);
- BOOLPROP(UseLocationProfiles);
- BOOLPROP(ContinueOnError);
- #undef BOOLPROP
- if (DDSystemTemporaryDirectoryButton->Checked)
- {
- WinConfiguration->DDTemporaryDirectory = "";
- }
- else
- {
- WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
- }
- Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
- TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
- ScpCommander.ExplorerStyleSelection = ExplorerStyleSelectionCheck->Checked;
- ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
- WinConfiguration->ScpCommander = ScpCommander;
- TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
- ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
- WinConfiguration->ScpExplorer = ScpExplorer;
- Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
- // editor
- WinConfiguration->Editor.Editor =
- (EditorInternalButton->Checked || ExternalEditorEdit->Text.IsEmpty()) ?
- edInternal : edExternal;
- WinConfiguration->Editor.ExternalEditor = ExternalEditorEdit->Text;
- WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
- WinConfiguration->Editor.FontName = FEditorFont->Name;
- WinConfiguration->Editor.FontHeight = FEditorFont->Height;
- WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
- WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
- TCopyParamType 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->CopyParam = CopyParam;
- WinConfiguration->CustomCommands = FCustomCommands;
- WinConfiguration->PuttyPath = PuttyPathEdit->FileName;
- }
- __finally
- {
- Configuration->EndUpdate();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
- {
- if (PreferencesMode != value)
- {
- FPreferencesMode = value;
-
- GeneralSheet->TabVisible = (value != pmLogin);
- LogSheet->TabVisible = (value != pmLogin);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
- {
- switch (PreferencesMode) {
- case pmEditor: PageControl->ActivePage = EditorSheet; break;
- case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
- default: PageControl->ActivePage = PreferencesSheet; break;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
- {
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpdateControls()
- {
- EnableControl(CopyOnDoubleClickConfirmationCheck, CopyOnDoubleClickCheck->Checked);
- EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Checked);
- EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
- EditorFontLabel->Caption = FORMAT("%s, %d pt",
- (FEditorFont->Name, FEditorFont->Size));
- bool CommandComplete = !CustomCommandDescEdit->Text.IsEmpty() &&
- !CustomCommandEdit->Text.IsEmpty();
- EnableControl(AddCommandButton, CommandComplete);
- EnableControl(SaveCommandButton, CommandComplete &&
- CustomCommandsView->Selected &&
- (CustomCommandDescEdit->Text != FCustomCommands->Names[CustomCommandsView->ItemIndex] ||
- CustomCommandEdit->Text != FCustomCommands->Values[
- FCustomCommands->Names[CustomCommandsView->ItemIndex]]));
- EnableControl(RemoveCommandButton, CustomCommandsView->Selected);
- EnableControl(UpCommandButton, CustomCommandsView->ItemIndex > 0);
- EnableControl(DownCommandButton, CustomCommandsView->ItemIndex >= 0 &&
- CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
- {
- TFontDialog * Dialog = new TFontDialog(Application);
- try
- {
- Dialog->Device = fdScreen;
- Dialog->Options = TFontDialogOptions() << fdForceFontExist;
- Dialog->Font = FEditorFont;
- if (Dialog->Execute())
- {
- FEditorFont->Assign(Dialog->Font);
- UpdateControls();
- }
- }
- __finally
- {
- delete Dialog;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ExternalEditorEditExit(TObject * /*Sender*/)
- {
- try
- {
- AnsiString ExternalEditor = ExternalEditorEdit->Text;
- if (!ExternalEditor.IsEmpty())
- {
- TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
- ExternalEditorEdit->Text = ExternalEditor;
- }
- }
- catch(...)
- {
- ExternalEditorEdit->SelectAll();
- ExternalEditorEdit->SetFocus();
- throw;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ExternalEditorEditAfterDialog(
- TObject * /*Sender*/, AnsiString & /*Name*/, bool & Action)
- {
- if (Action)
- {
- FAfterExternalEditorDialog = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::ExternalEditorEditChange(
- TObject *Sender)
- {
- if (FAfterExternalEditorDialog)
- {
- FAfterExternalEditorDialog = false;
- ExternalEditorEditExit(Sender);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
- bool & /*CanClose*/)
- {
- if (ModalResult != mrCancel && ExternalEditorEdit->Focused())
- {
- ExternalEditorEditExit(NULL);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
- {
- if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
- qtConfirmation, qaYes | qaNo, 0) == qaYes)
- {
- AnsiString IconName, Params;
- int SpecialFolder;
- 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
- {
- IconName = AppNameVersion;
- SpecialFolder = Sender == DesktopIconButton ?
- CSIDL_DESKTOPDIRECTORY :CSIDL_COMMON_DESKTOPDIRECTORY;
- }
- 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);
- Item->SubItems->Add(FCustomCommands->Values[FCustomCommands->Names[Index]]);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewSelectItem(
- TObject * /*Sender*/, TListItem * Item, bool Selected)
- {
- if (Item && Selected)
- {
- assert(Item);
- int Index = Item->Index;
- assert(Index >= 0 && Index <= FCustomCommands->Count);
- CustomCommandDescEdit->Text = FCustomCommands->Names[Index];
- CustomCommandEdit->Text = FCustomCommands->Values[FCustomCommands->Names[Index]];
- }
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
- {
- CustomCommandsView->Items->Count = FCustomCommands->Count;
- AdjustListColumnsWidth(CustomCommandsView);
- CustomCommandsView->Invalidate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
- TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
- {
- if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
- {
- RemoveCommandButtonClick(NULL);
- }
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TPreferencesDialog::CustomCommandString(int Index)
- {
- if (CustomCommandDescEdit->Text.Pos("="))
- {
- throw Exception(FMTLOAD(CUSTOM_COMMAND_INVALID, ("=")));
- }
- int I = FCustomCommands->IndexOfName(CustomCommandDescEdit->Text);
- if (I >= 0 && (Index < 0 || I != Index))
- {
- throw Exception(FMTLOAD(CUSTOM_COMMAND_DUPLICATE, (CustomCommandDescEdit->Text)));
- }
- return FORMAT("%s=%s", (CustomCommandDescEdit->Text, CustomCommandEdit->Text));
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
- {
- int Index;
- if (CustomCommandsView->ItemIndex >= 0)
- {
- FCustomCommands->Insert(CustomCommandsView->ItemIndex, CustomCommandString());
- Index = CustomCommandsView->ItemIndex;
- }
- else
- {
- Index = FCustomCommands->Add(CustomCommandString());
- }
- CustomCommandsView->ItemIndex = Index;
- UpdateCustomCommandsView();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::SaveCommandButtonClick(TObject * /*Sender*/)
- {
- assert(CustomCommandsView->ItemIndex >= 0 &&
- CustomCommandsView->ItemIndex < FCustomCommands->Count);
- FCustomCommands->Strings[CustomCommandsView->ItemIndex] =
- CustomCommandString(CustomCommandsView->ItemIndex);
- UpdateCustomCommandsView();
- 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));
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewStartDrag(
- TObject * /*Sender*/, TDragObject *& /*DragObject*/)
- {
- FCustomCommandDragSource = CustomCommandsView->ItemIndex;
- FCustomCommandDragDest = -1;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TPreferencesDialog::AllowCustomCommandsDrag(int X, int Y)
- {
- TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
- FCustomCommandDragDest = Item ? Item->Index : -1;
- return (FCustomCommandDragDest >= 0) && (FCustomCommandDragDest != FCustomCommandDragSource);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
- TObject * /*Sender*/, TObject * Source, int X, int Y)
- {
- if (Source == CustomCommandsView)
- {
- if (AllowCustomCommandsDrag(X, Y))
- {
- CustomCommandMove(FCustomCommandDragSource, FCustomCommandDragDest);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
- TObject * /*Sender*/, TObject * Source, int /*X*/, int /*Y*/,
- TDragState /*State*/, bool & Accept)
- {
- if (Source == CustomCommandsView)
- {
- // cannot use AllowCustomCommandsDrag(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;
- }
- }
- //---------------------------------------------------------------------------
|