⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucatexpert.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 5 页
字号:


{Creates the dialog to edit the options.
~param Options the options to edit }
constructor TFormCatExpert.Create(Options: TOptionWrapper);
var         Settings      :TOptionCatExpertFormSettings; //to read ini settings
begin
 inherited Create(nil);                //create the form

 FOptions := Options;                  //save the options




{$IFNDEF LINUX}

 //create the rich edit control to show the help text of options
 RichEditHelpText := TRichEdit.Create(Self);
 with RichEditHelpText do
  begin
   Parent := Self;
   Left := 13;
   Top := 296;
   Width := 337;
   Height := 97;
   Hint := 'The help text for the selected option extracted from the HTML ' +
           'file "Documentation\options.html".';
   Anchors := [akLeft, akRight, akBottom];
   TabOrder := 6;
   ScrollBars := ssVertical;
   HelpContext := 26005;
   ReadOnly := True;
   WantReturns := False;
   Font.Name := 'Arial';
   Font.Height := -12;
  end;

 //create the splitter component to resize the tree view and the rich edit
 PanelSplitter := TPanel.Create(Self);
 with PanelSplitter do
  begin
   Parent := Self;
   Left := 13;
   Top := 293;
   Width := 337;
   Height := 4;
   Cursor := crVSplit;
   BevelInner := bvRaised;
   Anchors := [akLeft, akRight, akBottom];
   HelpContext := 26006;
   TabOrder := 8;
   OnMouseDown := PanelSplitterMouseDown;
   OnMouseMove := PanelSplitterMouseMove;
  end;

 //create a timer to be used to resize the tree view and the rich edit
 //~[em after] the form has been resized
 TimerResize := TTimer.Create(Self);
 TimerResize.Enabled := False;
 TimerResize.Interval := 1;
 TimerResize.OnTimer := TimerResizeTimer;

{$ENDIF}

 //create the (fixed) TreeView
 TreeView :=
{$IFDEF VER120}
             TFixedTreeView
{$ELSE}
             TTreeView
{$ENDIF}
                           .Create(Self);
 with TreeView do
  begin
   Parent := Self;
   Name := 'TreeView';
   Left := 13;
   Top := 33;
   Width := 337;
{$IFDEF LINUX}
   Height := 360;
{$ELSE}
   Height := RichEditHelpText.Top - Top - 2;
{$ENDIF}
//   Hint := 'All available options to edit them.';
   HelpContext := 26001;
   Anchors := [akLeft, akTop, akRight, akBottom];
{$IFNDEF LINUX}
   HideSelection := False;
   RightClickSelect := True;
   ShowLines := False;
{$ENDIF}
   Images := ImageList;
   Indent := 17;
   ShowButtons := False;
   TabOrder := 0;
   OnChange := TreeViewChange;
   OnCollapsed := TreeViewCollapsed;
   OnDblClick := TreeViewDblClick;
   OnEditing := TreeViewEditing;
   OnExpanded := TreeViewExpanded;
  end;
 LabelOptions.FocusControl := TreeView;

 FillComboBox;                         //add list of classes
 ComboBoxTopics.ItemIndex := ComboBoxTopics.Items.Count - 1;
 RadioGroupShowOptions.ItemIndex := 0;
// ComboBoxTopics.OnChange(nil);         //create the outline of the options


 if FOptions.DefaultTopic = '' then
  Caption := 'Options by Category'
 else
  Caption := 'Options of ' + FOptions.DefaultTopic + ' by Category';

{
 //read the state of the check box, to decide, whether options should be
 //saved common by their individual topics
 CheckBoxByHierarchy.Checked := Ini.ReadBool(TFormMainIniSection,
                                             'SaveByHierarchy',
                                             CheckBoxByHierarchy.Checked);
}

 TreeView.OnEdited := TreeViewEdited;

{$IFNDEF LINUX}
// ActiveControl := TreeView;         //focus the treeview to select an option
{$ENDIF}

 OnShortCut := FormShortCut;        //register short-cut handler

 //get object to load the settings from
 Settings := TOptionCatExpertFormSettings(TOptionCatExpertFormSettings.
                                                       GetSettings(ClassName));
 if not Assigned(Settings) then        //no object initialized?
  begin                                  //create a new object
   Settings := TOptionCatExpertFormSettings.Create(ClassName);
   Settings.ReadValues(Self);            //initialize with the default values
   Settings.Initialize;                  //and read from the ini file
  end;
 Settings.SetValuesToForm(Self);       //initialize form with read values
 CheckBoxByHierarchy.Checked := Settings.SaveByHierarchy;
{$IFNDEF LINUX}
 //set height of tree view and rich edit
// RichEditHelpText.Height := Settings.RichEditHeight;
 ResizeTreeView(StatusBar.Top - Settings.RichEditHeight -
                TreeView.Top - 2 - 9);
{$ENDIF}

end;

{Frees the dialog. }
destructor TFormCatExpert.Destroy;
var        Settings      :TOptionCatExpertFormSettings; //to save the settings
begin
 SaveOption(False);                      //save currently edited option

 //get object to save the settings in
 Settings := TOptionCatExpertFormSettings(TOptionCatExpertFormSettings.
                                                       GetSettings(ClassName));
 if Assigned(Settings) then
  Settings.ReadValues(Self);                    //save current settings

{
 //write the currently state of the check box, to decide, whether options
 //should be saved common by their individual topic
 Ini.WriteBool(TFormMainIniSection, 'SaveByHierarchy',
               CheckBoxByHierarchy.Checked);
}

 inherited Destroy;                      //free the form
end;






{Called when the user finishes editing the value of an option directly in the
 tree view.
~param Sender the sender of the event, ~[link TreeView]
~param Node   the currently selected and edited node
~param S      in: the text set by the user;
              out: the new text for the node }
procedure TFormCatExpert.TreeViewEdited(Sender: TObject; Node: TTreeNode;
                                        var S: {$IFDEF LINUX} WideString
                                               {$ELSE}        String {$ENDIF});
var       Descr         :TOptionDescription; //type of the option
          Value         :TOptionValue;       //value of the option
begin
 Assert(Node.ImageIndex = Ord(iiOption));

 //get description of the option
 FOptions.Description(Cardinal(Node.Data), Descr);


{$IFDEF LINUX}
 //remove the name of the option if still in the text
 if Copy(S, 1, Length(Descr.Name) + 1) = Descr.Name + ':' then
  Delete(S, 1, Length(Descr.Name) + Ord(S[Length(Descr.Name) + 2] = ' '));
{$ENDIF}



 //try to interpret the edited text as a value for the option
 if StringToValue(S, Value, Descr) then
  begin
   FOptions.Option[Cardinal(Node.Data)] := Value;  //set the value

   //get new value of option (just in case there have been some adjustments)
   Value := FOptions.Option[Cardinal(Node.Data)];

   case Descr.DataType of             //show its value depending on its type
     otString:      TEdit(FEditControl).Text := Value.StrData;
     otBoolean:     TCheckBox(FEditControl).Checked := Value.BoolData;
     otInteger:
{$IFNDEF USENORMALSPINEDIT}
                    TGVSpinEdit(FEditControl).Value := Value.IntData;
{$ELSE}
                    TSpinEdit(FEditControl).Value := Value.IntData;
{$ENDIF}
     otReal:
{$IFNDEF USENORMALSPINEDIT}
                    TExtSpinEdit(FEditControl).Value := Value.RealData;
{$ELSE}
                    TSpinEdit(FEditControl).Value := Round(Value.RealData *
                                                           1000);
{$ENDIF}
     otEnumeration: TComboBox(FEditControl).ItemIndex := Value.EnumData;
     otSet:         TSetButton(FEditControl).Init(Descr.SetNames,
                                                  Value.SetData);
   end;

   //set the text of the node with the name and value of the option
   S := Descr.Name + ': ' + ValueToString(Value, Descr);
   if ooChangesOtherOptions in Descr.Options then //other options changed, too?
    RefreshAllNodes;                                //refresh all nodes
  end
 else
  S := Node.Text;                     //just use the original text
end;






{$IFNDEF LINUX}

{Called when a key is pressed.
~param Msg     the data of the message of a key being pressed
~param Handled if the event is a shortcut that has been handled }
procedure TFormCatExpert.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
 //F2 is pressed and the TreeView has currently the focus?
 Handled := (Msg.CharCode = VK_F2) and
            TreeView.Enabled and (ActiveControl = TreeView) and
            Assigned(TreeView.Selected) and        //and an option is selected?
            (TreeView.Selected.ImageIndex = Ord(iiOption));
 if Handled then
  if TreeView.IsEditing then               //option is currently being edited?
   TreeView.Selected.EndEdit(False)          //end the editing
  else
   TreeView.Selected.EditText                //start the editing
 else
  begin
   //if currently the component to edit the option is focused
   Handled := (Msg.CharCode = VK_F2) and
              TreeView.Enabled and Assigned(FEditControl) and
              (ActiveControl = FEditControl);
   if Handled then
    TreeView.SetFocus                        //change focus to the TreeView
   else
    begin
     //if F3 is pressed and the component to edit the option is not focused
     Handled := (Msg.CharCode = VK_F4) and
                Assigned(FEditControl) and (ActiveControl <> FEditControl) and
                (KeyDataToShiftState(Msg.KeyData) * [ssAlt, ssCtrl] = []);
     if Handled then
      FEditControl.SetFocus;
    end;                                       //focus the component now
  end;

 if not Handled then
  begin
   Handled := (Msg.CharCode = VK_F3) or      //F3 or Ctrl-F pressed?
              ((Msg.CharCode = Ord('F')) and
               (ssCtrl in KeyDataToShiftState(Msg.KeyData)));
   if Handled then                           //searching an option?
    DoSearch(Msg.CharCode = VK_F3);
  end;
end;

{$ELSE}

{Called when a key is pressed.
~param Key     the pressed key
~param Shift   the state of special modifying keys
~param Handled if the event is a shortcut that has been handled }
procedure TFormCatExpert.FormShortCut(Key: Integer; Shift: TShiftState; var Handled: Boolean);
begin
 //F2 is pressed and the TreeView has currently the focus?
 Handled := (Key = Key_F2) and
            TreeView.Enabled and (ActiveControl = TreeView) and
            assigned(TreeView.Selected) and        //and an option is selected?
            (TreeView.Selected.ImageIndex = Ord(iiOption));
 if Handled then
  TreeView.Selected.EditText                //start the editing
 else
  begin
   //if currently the component to edit the option is focused
   Handled := (Key = Key_F2) and
              TreeView.Enabled and Assigned(FEditControl) and
              (ActiveControl = FEditControl);
   if Handled then
    TreeView.SetFocus                        //change focus to the TreeView
   else
    begin
     //if F3 is pressed and the component to edit the option is not focused
     Handled := (Key = Key_F4) and
                Assigned(FEditControl) and (ActiveControl <> FEditControl) and
                (Shift * [ssAlt, ssCtrl] = []);
     if Handled then
      FEditControl.SetFocus;
    end;                                       //focus the component now
  end;

 if not Handled then
  begin
   Handled := (Key = Key_F3) or              //F3 or Ctrl-F pressed?
              ((Key = Ord('F')) and (ssCtrl in Shift));
   if Handled then                           //searching an option?
    DoSearch(Key = Key_F3);
  end;
end;

{$ENDIF}




{$IFNDEF LINUX}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -