CnPack Forum


 
Subject: 关于IDE便利性方面我有两个想法
wr960204
新警察
Rank: 1



UID 1667
Digest Posts 0
Credits 32
Posts 14
点点分 32
Reading Access 10
Registered 2006-1-14
Status Offline
Post at 2008-9-9 18:05  Profile | Blog | P.M. 
关于IDE便利性方面我有两个想法

1.代码结构Structure窗口自Delphi2007起,就总是自动展开.找到一个类的某个方法非常麻烦,要用肉眼过滤.CN是否可以加一个选项让用户选是否自动收起.
2.可以加一个函数局部变量查看窗口.我以前倒是做过一个.基于源代码分析的.可以看当前函数的局部变量.表现形式是一个表格,第一列是变量名,第二列是变量类型.这样就不用经常函数开头看看有哪些变量都是什么类型了.当时做的是按下快捷键就浮出这个窗口,抬起快捷键就隐藏.不过我对于OpenToolsAPI研究的不太深.基本上一半利用OpenToolsAPI一半利用Hook做的.


这两个想法不知道CN组织能否吸收到IDE专家中去.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6812
Posts 3579
点点分 6812
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-9-9 21:29  Profile | Blog | P.M. 
第一个功能可以写个脚本完成,需要的时候点击或按热键执行即可。但目前D2009不支持脚本专家,因此这功能在D2009下估计也不好完成。

第二个功能估计可以全面设计一下,不局限于只显示局部变量,可以增加对当前方法以及其它内容的显示(根据光标所在位置不同而显示不同内容),但这块工作量与设计量都属于不小的范围,优先级估计会放后点儿了。
Top
wr960204
新警察
Rank: 1



UID 1667
Digest Posts 0
Credits 32
Posts 14
点点分 32
Reading Access 10
Registered 2006-1-14
Status Offline
Post at 2008-9-10 12:07  Profile | Blog | P.M. 
呵呵.第一个功能我昨天晚上倒是实现了很大部分.不过也不完全借助OpenToolsAPI来实现的.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6812
Posts 3579
点点分 6812
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-9-11 19:24  Profile | Blog | P.M. 
第一个功能,在IDE内部加载的bpl或dll专家,可以搜索名为StructureViewForm的Form,以及搜索其下名为VirtualStringTree1的TVirtualStringTree,然后对其进行是否自动展开的设置。

但如何设置其自动展开不太好设置,没找到相关属性。而且TVirtualStringTree也不宜编译进专家吧,没编译的话就没法引用这个Tree,从而无法直接操作。
Top
wr960204
新警察
Rank: 1



UID 1667
Digest Posts 0
Credits 32
Posts 14
点点分 32
Reading Access 10
Registered 2006-1-14
Status Offline
Post at 2008-9-12 15:41  Profile | Blog | P.M. 
我就是调用的TVirtualStringTree的方法.而且我没有用VirtualString.
管理员能不能把邮箱给我.我把我的代码发给你看看.看看是否有参考价值
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6812
Posts 3579
点点分 6812
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-9-12 23:04  Profile | Blog | P.M. 
Top
wr960204
新警察
Rank: 1



UID 1667
Digest Posts 0
Credits 32
Posts 14
点点分 32
Reading Access 10
Registered 2006-1-14
Status Offline
Post at 2008-9-16 13:38  Profile | Blog | P.M. 
算了不发邮件了.直接贴在这个上面吧.
因为TVirtualStringTree的实例你可以获取.那么它的方法也就可以调用了.
方法如下.
因为这个组件是由包vclide120.bpl提供的.那么TVirtualStringTree的方法就会被BPL导出.
我们只要声明一下就够了.对象的成员方法编译后和普通方法没什么区别,只是塞入一个参数Self作为第一个参数而已.所以TVirtualStringTree的方法我们可以把它转换成普通方法
例如我实际上在使用的时候只用到了下面三个方法
procedure SetExpanded(this : TVirtualStringTree;
                      Node: PVirtualNode;
                      Value: Boolean);external 'vclide120.bpl' name '@Idevirtualtrees@TBaseVirtualTree@SetExpanded$qqrp28Idevirtualtrees@TVirtualNodeo';
function GetNodeAt(this : TVirtualStringTree;
             X, Y: Integer): PVirtualNode;
             external 'vclide120.bpl'
            name '@Idevirtualtrees@TBaseVirtualTree@GetNodeAt$qqrii';
function GetText(this : TVirtualStringTree; Node: PVirtualNode; Column: Cardinal): WideString;
           external 'vclide120.bpl' name '@Idevirtualtrees@TCustomVirtualStringTree@GetText$qqrp28Idevirtualtrees@TVirtualNodei';
当然这些方法用到的类型都要声明一次.
下面是我用到的类型声明.都是从VirtualTree的源代码中抄过来的.还有我自己用到的声明.
Type


  TCheckType = (
    ctNone,
    ctTriStateCheckBox,
    ctCheckBox,
    ctRadioButton,
    ctButton
  );
  TCheckState = (
    csUncheckedNormal,  // unchecked and not pressed
    csUncheckedPressed, // unchecked and pressed
    csCheckedNormal,    // checked and not pressed
    csCheckedPressed,   // checked and pressed
    csMixedNormal,      // 3-state check box and not pressed
    csMixedPressed      // 3-state check box and pressed
  );

  TVirtualNodeState = (
    vsInitialized,       // Set after the node has been initialized.
    vsChecking,          // Node's check state is changing, avoid propagation.
    vsCutOrCopy,         // Node is selected as cut or copy and paste source.
    vsDisabled,          // Set if node is disabled.
    vsDeleting,          // Set when the node is about to be freed.
    vsExpanded,          // Set if the node is expanded.
    vsHasChildren,       // Indicates the presence of child nodes without actually setting them.
    vsVisible,           // Indicate whether the node is visible or not (independant of the expand states of its parents).
    vsSelected,          // Set if the node is in the current selection.
    vsInitialUserData,   // Set if (via AddChild or InsertNode) initial user data has been set which requires OnFreeNode.
    vsAllChildrenHidden, // Set if vsHasChildren is set and no child node has the vsVisible flag set.
    vsClearing,          // A node's children are being deleted. Don't register structure change event.
    vsMultiline,         // Node text is wrapped at the cell boundaries instead of being shorted.
    vsHeightMeasured,    // Node height has been determined and does not need a recalculation.
    vsToggling           // Set when a node is expanded/collapsed to prevent recursive calls.
  );
  TVirtualNodeStates = set of TVirtualNodeState;

  PVirtualNode = ^TVirtualNode;

  TVirtualNode = packed record
    Index,                   // index of node with regard to its parent
    ChildCount: Cardinal;    // number of child nodes
    NodeHeight: Word;        // height in pixels
    States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
    Align: Byte;             // line/button alignment
    CheckState: TCheckState; // indicates the current check state (e.g. checked, pressed etc.)
    CheckType: TCheckType;   // indicates which check type shall be used for this node
    Dummy: Byte;             // dummy value to fill DWORD boundary
    TotalCount,              // sum of this node, all of its child nodes and their child nodes etc.
    TotalHeight: Cardinal;   // height in pixels this node covers on screen including the height of all of its
                             // children
    // Note: Some copy routines require that all pointers (as well as the data area) in a node are
    //       located at the end of the node! Hence if you want to add new member fields (except pointers to internal
    //       data) then put them before field Parent.
    Parent,                  // reference to the node's parent (for the root this contains the treeview)
    PrevSibling,             // link to the node's previous sibling or nil if it is the first node
    NextSibling,             // link to the node's next sibling or nil if it is the last node
    FirstChild,              // link to the node's first child...
    LastChild: PVirtualNode; // link to the node's last child...
    Data: record end;        // this is a placeholder, each node gets extra data determined by NodeDataSize
  end;


  TVTUpdateState = (
    usBegin,       // The tree just entered the update state (BeginUpdate call for the first time).
    usBeginSynch,  // The tree just entered the synch update state (BeginSynch call for the first time).
    usSynch,       // Begin/EndSynch has been called but the tree did not change the update state.
    usUpdate,      // Begin/EndUpdate has been called but the tree did not change the update state.
    usEnd,         // The tree just left the update state (EndUpdate called for the last level).
    usEndSynch     // The tree just left the synch update state (EndSynch called for the last level).
  );
  TVSTTextType = (
    ttNormal,      // normal label of the node, this is also the text which can be edited
    ttStatic       // static (non-editable) text after the normal text
  );

  TVirtualNodeInitState = (
    ivsDisabled,
    ivsExpanded,
    ivsHasChildren,
    ivsMultiline,
    ivsSelected
  );

  TVirtualStringTree = class(TCustomControl)
  private
    FBorderStyle: TBorderStyle;
    FHeader: TObject;
    FRoot: PVirtualNode;
  end;

  TVirtualNodeInitStates = set of TVirtualNodeInitState;

  TUpdating = procedure (Sender: TVirtualStringTree; State: TVTUpdateState) of object;
  TExpanding = procedure (Sender: TVirtualStringTree; Node: PVirtualNode; var Allowed: Boolean) of object;
  TInitNode = procedure(Sender: TVirtualStringTree; ParentNode, Node: PVirtualNode;
               var InitialStates: TVirtualNodeInitStates) of Object;
  TGetText = procedure(Sender: TVirtualStringTree; Node: PVirtualNode; Column: Cardinal; TextType: TVSTTextType;
               var Text: WideString) of Object;

const
  StructureViewFormClassName = 'TStructureViewForm';
  StructureViewFormName = 'StructureViewForm';
  VTreeClassName = 'TVirtualStringTree';
var
  StructureViewForm : TCustomForm = nil;


procedure SetExpanded(this : TVirtualStringTree;
                      Node: PVirtualNode;
                      Value: Boolean);external 'vclide120.bpl' name '@Idevirtualtrees@TBaseVirtualTree@SetExpanded$qqrp28Idevirtualtrees@TVirtualNodeo';
function GetNodeAt(this : TVirtualStringTree;
             X, Y: Integer): PVirtualNode;
             external 'vclide120.bpl'
            name '@Idevirtualtrees@TBaseVirtualTree@GetNodeAt$qqrii';
function GetText(this : TVirtualStringTree; Node: PVirtualNode; Column: Cardinal): WideString;
           external 'vclide120.bpl' name '@Idevirtualtrees@TCustomVirtualStringTree@GetText$qqrp28Idevirtualtrees@TVirtualNodei';
Top
wr960204
新警察
Rank: 1



UID 1667
Digest Posts 0
Credits 32
Posts 14
点点分 32
Reading Access 10
Registered 2006-1-14
Status Offline
Post at 2008-9-16 13:42  Profile | Blog | P.M. 
然后我还接管了VirtualTreeView的一些事件.
这个就比较容易了.因为这些事件都是Published.它们都具有RTTI信息.
直接获取到这些事件.然后保存起来.付给这些事件新的方法地址.在方法中调用旧的事件即可.
有点像Hook技术.
基本上自动收缩展开的功能实现了.但我对openToolsAPI不是特别熟悉.有些地方处理的还不太好.
例如切换代码编辑器的标签切换代码我都不知道怎么获取通知.所以还有些小问题.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6812
Posts 3579
点点分 6812
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-9-19 19:49  Profile | Blog | P.M. 
有道理。其实这种调用bpl导出方法来实现对未知的类的操作在CnWizards里头也有,像编辑器部分操作等也都涉及到了。只是当时思维局限在IDE内部的实现的类了,没想到VirtualTree这个开源的第三方组件也能这样。

不过在CnWizards中,这个功能点暂时还不太好整合,功能分类还不太明确,不晓得放哪儿比较好。
Top
 




All times are GMT++8, the time now is 2024-9-19 08:54

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.007613 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP