|
@@ -2647,376 +2647,6 @@ void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /
|
|
|
QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|
|
|
-class TCustomCommandOptionsDialog : public TCustomDialog
|
|
|
-{
|
|
|
-public:
|
|
|
- __fastcall TCustomCommandOptionsDialog(const TCustomCommandType * Command, TStrings * CustomCommandOptions);
|
|
|
-
|
|
|
- bool __fastcall Execute();
|
|
|
-
|
|
|
-protected:
|
|
|
- virtual void __fastcall DoHelp();
|
|
|
-
|
|
|
-private:
|
|
|
- const TCustomCommandType * FCommand;
|
|
|
- TStrings * FCustomCommandOptions;
|
|
|
- std::vector<TControl *> FControls;
|
|
|
- std::vector<std::vector<UnicodeString> > FValues;
|
|
|
-
|
|
|
- UnicodeString __fastcall HistoryKey(const TCustomCommandType::TOption & Option);
|
|
|
- THistoryComboBox * __fastcall CreateHistoryComboBox(const TCustomCommandType::TOption & Option, const UnicodeString & Value);
|
|
|
- void __fastcall BrowseButtonClick(TObject * Sender);
|
|
|
- void __fastcall LinkLabelClick(TObject * Sender);
|
|
|
- UnicodeString __fastcall SaveHistoryComboBoxValue(TControl * Control, const TCustomCommandType::TOption & Option);
|
|
|
- void __fastcall AddOptionComboBox(
|
|
|
- TComboBox * ComboBox, const UnicodeString & Value, const TCustomCommandType::TOption & Option,
|
|
|
- std::vector<UnicodeString> & Values);
|
|
|
- UnicodeString __fastcall GetComboBoxValue(TControl * Control, const UnicodeString & Default);
|
|
|
-};
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-__fastcall TCustomCommandOptionsDialog::TCustomCommandOptionsDialog(
|
|
|
- const TCustomCommandType * Command, TStrings * CustomCommandOptions) :
|
|
|
- TCustomDialog(HELP_EXTENSION_OPTIONS)
|
|
|
-{
|
|
|
- FCommand = Command;
|
|
|
- FCustomCommandOptions = CustomCommandOptions;
|
|
|
- Caption = FMTLOAD(EXTENSION_OPTIONS_CAPTION, (StripEllipsis(StripHotkey(FCommand->Name))));
|
|
|
- Width = ScaleByTextHeight(this, 400);
|
|
|
-
|
|
|
- for (int Index = 0; Index < FCommand->OptionsCount; Index++)
|
|
|
- {
|
|
|
- const TCustomCommandType::TOption & Option = FCommand->GetOption(Index);
|
|
|
-
|
|
|
- UnicodeString OptionKey = FCommand->GetOptionKey(Option);
|
|
|
- UnicodeString Value;
|
|
|
- if (FCustomCommandOptions->IndexOfName(OptionKey) >= 0)
|
|
|
- {
|
|
|
- Value = FCustomCommandOptions->Values[OptionKey];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Value = Option.Default;
|
|
|
- }
|
|
|
-
|
|
|
- TControl * Control = NULL;
|
|
|
- std::vector<UnicodeString> Values;
|
|
|
- if (Option.Kind == TCustomCommandType::okUnknown)
|
|
|
- {
|
|
|
- Control = NULL;
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okLabel)
|
|
|
- {
|
|
|
- TLabel * Label = CreateLabel(Option.Caption);
|
|
|
- AddText(Label);
|
|
|
- Control = Label;
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okLink)
|
|
|
- {
|
|
|
- TStaticText * Label = new TStaticText(this);
|
|
|
- Label->Caption = Option.Caption;
|
|
|
- if (IsHttpOrHttpsUrl(Label->Caption))
|
|
|
- {
|
|
|
- Label->Caption = SecureUrl(Label->Caption);
|
|
|
- LinkLabel(Label);
|
|
|
- Label->TabStop = true;
|
|
|
- }
|
|
|
- else if (!Option.Default.IsEmpty() && IsHttpOrHttpsUrl(Option.Default))
|
|
|
- {
|
|
|
- Label->OnClick = LinkLabelClick;
|
|
|
- LinkLabel(Label);
|
|
|
- Label->TabStop = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // keep it plain text, as we have no URL
|
|
|
- }
|
|
|
- AddText(Label);
|
|
|
- Control = Label;
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okGroup)
|
|
|
- {
|
|
|
- StartGroup(Option.Caption);
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okSeparator)
|
|
|
- {
|
|
|
- AddSeparator();
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okTextBox)
|
|
|
- {
|
|
|
- Control = CreateHistoryComboBox(Option, Value);
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okFile)
|
|
|
- {
|
|
|
- THistoryComboBox * ComboBox = CreateHistoryComboBox(Option, Value);
|
|
|
- TButton * Button = new TButton(this);
|
|
|
- Button->Parent = GetDefaultParent();
|
|
|
- Button->Width = HelpButton->Width;
|
|
|
- Button->Left = GetDefaultParent()->ClientWidth - Button->Width - HorizontalMargin;
|
|
|
- ComboBox->Width = Button->Left - ComboBox->Left - ScaleByTextHeight(this, 6);
|
|
|
- Button->Top = ComboBox->Top - ScaleByTextHeight(this, 2);
|
|
|
- Button->Tag = Index;
|
|
|
- Button->Caption = LoadStr(EXTENSION_OPTIONS_BROWSE);
|
|
|
- Button->OnClick = BrowseButtonClick;
|
|
|
- ScaleButtonControl(Button);
|
|
|
- AddWinControl(Button);
|
|
|
- Control = ComboBox;
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okDropDownList)
|
|
|
- {
|
|
|
- TComboBox * ComboBox = new TComboBox(this);
|
|
|
- ComboBox->Style = csDropDownList;
|
|
|
-
|
|
|
- AddOptionComboBox(ComboBox, Value, Option, Values);
|
|
|
-
|
|
|
- Control = ComboBox;
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okComboBox)
|
|
|
- {
|
|
|
- TComboBox * ComboBox = new TComboBox(this);
|
|
|
- ComboBox->Style = csDropDown;
|
|
|
-
|
|
|
- AddOptionComboBox(ComboBox, Value, Option, Values);
|
|
|
- if (ComboBox->ItemIndex < 0)
|
|
|
- {
|
|
|
- ComboBox->Text = Value;
|
|
|
- }
|
|
|
-
|
|
|
- Control = ComboBox;
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okCheckBox)
|
|
|
- {
|
|
|
- TCheckBox * CheckBox = CreateAndAddCheckBox(Option.Caption);
|
|
|
-
|
|
|
- CheckBox->Checked =
|
|
|
- (Option.Params.size() >= 1) &&
|
|
|
- (Value == Option.Params[0]);
|
|
|
-
|
|
|
- Control = CheckBox;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DebugFail();
|
|
|
- }
|
|
|
-
|
|
|
- if (Control != NULL)
|
|
|
- {
|
|
|
- Control->Tag = Index;
|
|
|
- }
|
|
|
- FControls.push_back(Control);
|
|
|
- FValues.push_back(Values);
|
|
|
- }
|
|
|
-
|
|
|
- DebugAssert(FCommand->OptionsCount == static_cast<int>(FControls.size()));
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void __fastcall TCustomCommandOptionsDialog::AddOptionComboBox(
|
|
|
- TComboBox * ComboBox, const UnicodeString & Value, const TCustomCommandType::TOption & Option, std::vector<UnicodeString> & Values)
|
|
|
-{
|
|
|
- std::unique_ptr<TStringList> Items(new TStringList());
|
|
|
- int ItemIndex = -1;
|
|
|
-
|
|
|
- TCustomCommandType::TOption::TParams::const_iterator ParamI = Option.Params.begin();
|
|
|
- while (ParamI != Option.Params.end())
|
|
|
- {
|
|
|
- UnicodeString Item = (*ParamI);
|
|
|
- int P = Item.Pos(L"=");
|
|
|
- UnicodeString ParamValue;
|
|
|
- if (P > 0)
|
|
|
- {
|
|
|
- ParamValue = Item.SubString(1, P - 1);
|
|
|
- Item.Delete(1, P);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ParamValue = Item;
|
|
|
- }
|
|
|
- Items->Add(Item);
|
|
|
- if (Value == ParamValue)
|
|
|
- {
|
|
|
- ItemIndex = Items->Count - 1;
|
|
|
- }
|
|
|
- Values.push_back(ParamValue);
|
|
|
- ParamI++;
|
|
|
- }
|
|
|
-
|
|
|
- AddComboBox(ComboBox, CreateLabel(Option.Caption), Items.get(), true);
|
|
|
-
|
|
|
- ComboBox->ItemIndex = ItemIndex;
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void __fastcall TCustomCommandOptionsDialog::LinkLabelClick(TObject * Sender)
|
|
|
-{
|
|
|
- TStaticText * Label = DebugNotNull(dynamic_cast<TStaticText *>(Sender));
|
|
|
- const TCustomCommandType::TOption & Option = FCommand->GetOption(Label->Tag);
|
|
|
- OpenBrowser(SecureUrl(Option.Default));
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void __fastcall TCustomCommandOptionsDialog::BrowseButtonClick(TObject * Sender)
|
|
|
-{
|
|
|
- TButton * Button = DebugNotNull(dynamic_cast<TButton *>(Sender));
|
|
|
- int Index = Button->Tag;
|
|
|
- THistoryComboBox * ComboBox = dynamic_cast<THistoryComboBox *>(FControls[Index]);
|
|
|
-
|
|
|
- std::unique_ptr<TOpenDialog> OpenDialog(new TOpenDialog(Application));
|
|
|
- UnicodeString Caption = FCommand->GetOption(Index).Caption;
|
|
|
- Caption = StripHotkey(Caption);
|
|
|
- if (!Caption.IsEmpty() && (Caption[Caption.Length()] == L':'))
|
|
|
- {
|
|
|
- Caption.SetLength(Caption.Length() - 1);
|
|
|
- }
|
|
|
- OpenDialog->Title = FMTLOAD(EXTENSION_OPTIONS_BROWSE_TITLE, (Caption));
|
|
|
- UnicodeString ExpandedValue = ExpandEnvironmentVariables(ComboBox->Text);
|
|
|
- OpenDialog->FileName = ExpandedValue;
|
|
|
- UnicodeString InitialDir = ExtractFilePath(ExpandedValue);
|
|
|
- if (!InitialDir.IsEmpty())
|
|
|
- {
|
|
|
- OpenDialog->InitialDir = InitialDir;
|
|
|
- }
|
|
|
-
|
|
|
- if (OpenDialog->Execute())
|
|
|
- {
|
|
|
- if (OpenDialog->FileName != ExpandedValue)
|
|
|
- {
|
|
|
- ComboBox->Text = OpenDialog->FileName;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-THistoryComboBox * __fastcall TCustomCommandOptionsDialog::CreateHistoryComboBox(
|
|
|
- const TCustomCommandType::TOption & Option, const UnicodeString & Value)
|
|
|
-{
|
|
|
- THistoryComboBox * ComboBox = new THistoryComboBox(this);
|
|
|
- ComboBox->AutoComplete = false;
|
|
|
- AddComboBox(ComboBox, CreateLabel(Option.Caption));
|
|
|
- ComboBox->Items = CustomWinConfiguration->History[HistoryKey(Option)];
|
|
|
- ComboBox->Text = Value;
|
|
|
- return ComboBox;
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-UnicodeString __fastcall TCustomCommandOptionsDialog::HistoryKey(const TCustomCommandType::TOption & Option)
|
|
|
-{
|
|
|
- UnicodeString Result = FCommand->GetOptionKey(Option);
|
|
|
- Result = CustomWinConfiguration->GetValidHistoryKey(Result);
|
|
|
- return L"CustomCommandOption_" + Result;
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-bool __fastcall TCustomCommandOptionsDialog::Execute()
|
|
|
-{
|
|
|
- bool Result = TCustomDialog::Execute();
|
|
|
-
|
|
|
- if (Result)
|
|
|
- {
|
|
|
- DebugAssert(FCommand->OptionsCount == static_cast<int>(FControls.size()));
|
|
|
-
|
|
|
- for (int Index = 0; Index < FCommand->OptionsCount; Index++)
|
|
|
- {
|
|
|
- const TCustomCommandType::TOption & Option = FCommand->GetOption(Index);
|
|
|
- if ((Option.Kind != TCustomCommandType::okUnknown) &&
|
|
|
- Option.IsControl)
|
|
|
- {
|
|
|
- UnicodeString OptionKey = FCommand->GetOptionKey(Option);
|
|
|
-
|
|
|
- TControl * Control = FControls[Index];
|
|
|
-
|
|
|
- UnicodeString Value;
|
|
|
- if (Option.Kind == TCustomCommandType::okTextBox)
|
|
|
- {
|
|
|
- Value = SaveHistoryComboBoxValue(Control, Option);
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okFile)
|
|
|
- {
|
|
|
- Value = SaveHistoryComboBoxValue(Control, Option);
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okDropDownList)
|
|
|
- {
|
|
|
- Value = GetComboBoxValue(Control, Option.Default);
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okComboBox)
|
|
|
- {
|
|
|
- TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
|
|
|
- Value = GetComboBoxValue(Control, ComboBox->Text);
|
|
|
- }
|
|
|
- else if (Option.Kind == TCustomCommandType::okCheckBox)
|
|
|
- {
|
|
|
- TCheckBox * CheckBox = DebugNotNull(dynamic_cast<TCheckBox *>(Control));
|
|
|
- int Index = (CheckBox->Checked ? 0 : 1);
|
|
|
- Value = (Index < static_cast<int>(Option.Params.size())) ? Option.Params[Index] : UnicodeString();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DebugFail();
|
|
|
- }
|
|
|
-
|
|
|
- // The default value setter deletes the "name" when the value is empty.
|
|
|
- // It would cause us to fall back to the default value, but we want to remember the empty value.
|
|
|
- if (Value.IsEmpty())
|
|
|
- {
|
|
|
- int Index = FCustomCommandOptions->IndexOfName(OptionKey);
|
|
|
- if (Index < 0)
|
|
|
- {
|
|
|
- Index = FCustomCommandOptions->Add(L"");
|
|
|
- }
|
|
|
- UnicodeString Line = OptionKey + FCustomCommandOptions->NameValueSeparator;
|
|
|
- FCustomCommandOptions->Strings[Index] = Line;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- FCustomCommandOptions->Values[OptionKey] = Value;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return Result;
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-UnicodeString __fastcall TCustomCommandOptionsDialog::GetComboBoxValue(
|
|
|
- TControl * Control, const UnicodeString & Default)
|
|
|
-{
|
|
|
- TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
|
|
|
- UnicodeString Result;
|
|
|
- if (ComboBox->ItemIndex < 0)
|
|
|
- {
|
|
|
- Result = Default;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Result = FValues[Control->Tag][ComboBox->ItemIndex];
|
|
|
- }
|
|
|
- return Result;
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-UnicodeString __fastcall TCustomCommandOptionsDialog::SaveHistoryComboBoxValue(
|
|
|
- TControl * Control, const TCustomCommandType::TOption & Option)
|
|
|
-{
|
|
|
- THistoryComboBox * ComboBox = DebugNotNull(dynamic_cast<THistoryComboBox *>(Control));
|
|
|
- ComboBox->SaveToHistory();
|
|
|
- CustomWinConfiguration->History[HistoryKey(Option)] = ComboBox->Items;
|
|
|
- return ComboBox->Text;
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void __fastcall TCustomCommandOptionsDialog::DoHelp()
|
|
|
-{
|
|
|
- UnicodeString HelpPage;
|
|
|
- if (!FCommand->OptionsPage.IsEmpty())
|
|
|
- {
|
|
|
- HelpPage = FCommand->OptionsPage;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- HelpPage = FCommand->HomePage;
|
|
|
- }
|
|
|
-
|
|
|
- if (!HelpPage.IsEmpty())
|
|
|
- {
|
|
|
- OpenBrowser(HelpPage);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- TCustomDialog::DoHelp();
|
|
|
- }
|
|
|
-}
|
|
|
-//---------------------------------------------------------------------------
|
|
|
void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
|
|
|
{
|
|
|
ConfigureCommand();
|
|
@@ -3027,8 +2657,7 @@ void __fastcall TPreferencesDialog::ConfigureCommand()
|
|
|
int Index = CustomCommandsView->ItemIndex;
|
|
|
const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
|
|
|
|
|
|
- std::unique_ptr<TCustomCommandOptionsDialog> Dialog(new TCustomCommandOptionsDialog(Command, FCustomCommandOptions.get()));
|
|
|
- Dialog->Execute();
|
|
|
+ DoCustomCommandOptionsDialog(Command, FCustomCommandOptions.get());
|
|
|
UpdateCustomCommandsView();
|
|
|
}
|
|
|
//---------------------------------------------------------------------------
|