[译]CodePlotter Remoded 1.6-用于VC6,.NET,Delphi,C ++ Builder和VB编码器的独立版本
By robot-v1.0
本文链接 https://www.kyfws.com/applications/codeplotter-remoded-1-6-a-standalone-version-for-v-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 12 分钟阅读 - 5627 个词 阅读量 0[译]CodePlotter Remoded 1.6-用于VC6,.NET,Delphi,C ++ Builder和VB编码器的独立版本
原文地址:https://www.codeproject.com/Articles/4577/CodePlotter-Remoded-1-6-A-standalone-version-for-V
原文作者:.dan.g.
译文由本站 robot-v1.0 翻译
前言
A ‘Visio-like’ tool for adding and editing ascii diagrams in your source code
一个"类似于Visio"的工具,用于在源代码中添加和编辑ASCII图
前言(Preface)
为了防止那些可能抱怨这不是一个新项目的人(无论出于何种原因),我要指出以下三点:(To preempt those who may complain that this is not a new project (for whatever reason) I have the following three points to make:)
- 我同意这不是一个全新的项目(请参阅原始文章)(I agree that it is not an entirely new project (see the original article))
- 但是,如果我不将其重新发布到"工具"部分,那么请求它的人(.NET,Delphi,C ++ Builder等用户)将找不到它.(However, if I don’t repost it to the ‘Tools’ section the very people who requested it (.NET, Delphi, C++ Builder, etc users) will not find it.)
- 如果您花时间阅读这篇文章,您会发现它的某些方面与原始文章完全不同.(If you take to time to read the article you will see that there are aspects of it that are entirely diffrent from those of the original article.)
介绍(Introduction)
当我最初将CodePlotter写为VC6插件时,我非常意识到.NET用户可能也对类似工具感兴趣.(When I first wrote CodePlotter as a VC6 addin I was very aware that .NET users might also be interested in a similar tool.)
但是,当时我没有看到一种简单的方法来解决此问题,除非编写了.NET特定的插件.(At the time however I did not see an easy way to resolve this except by writing a .NET specific addin.)
因此,按照鸵鸟的最佳传统,我忽略了这个问题,一直等到我被迫处理.(So in the best tradition of ostrichs I ignored the issue and waited until I was forced to deal with it.)
在适当的时候,一个或两个.NET用户发表了评论,表示对VC7/.NET的CodePlotter加载项感兴趣,我知道我将不得不处理它,尤其是因为有很多人投票支持它.(In due time one or two .NET users posted comments expressing an interest in a CodePlotter addin for VC7/.NET and I knew that I would have to deal with it, especially since so many people were voting it up.)
现在,当我尝试将ProjectZip移植到.NET时,我已经对VC7插件进行了短暂的尝试,这并不是一个可怕的体验!(Now, I had already made a short foray into VC7 addins when I tried to port ProjectZip to .NET and wasn’t that a scary experience!)
我不知道微软在重新设计VC7插件体系结构时会想到什么,但是这肯定不是VC6插件的可移植性-我无法在很短的时间内做出对象模型的头和尾.(I don’t know what Microsoft thought they were up to when they redesigned the plugin architecture for VC7 but it certainly was not portability of VC6 addins - I could not make head nor tail of the object model in the short time that I tried.)
幸运的是,一位还涉猎VB和Delphi的C ++ Builder编码器帮助了我,并要求提供独立的可执行文件.(Fortunately, a C++ Builder coder who also dabbles in VB and Delphi came to my rescue and asked for a standalone executable .)
我认为这闻起来像是一个不容错过的机会.并且可能使我不必编写.NET端口.(This, I thought, smells like an opportunity not to be missed; and may yet save me from having to write a .NET port.)
另一个海报要求将CodePlotter加载项中的模式对话框设置为无模式,以便在绘制图时可以滚动其代码.但是,这会产生另一个问题,因为该插件依赖于选择内容而不会发生变化,因此可以将编辑后的图粘贴到原始图的顶部.(Still another poster asked for the modal dialog in the CodePlotter addin to be made modeless so that he could scroll his code as he drew the diagram. This however generates another problem because the addin relied on the selection not changing so that it could paste the edited diagram over the top of the original diagram.)
因此,可执行文件开始看起来像是一种出色的解决方案,因为尽管它会失去与VC6的紧密结合,但远远超出了独立应用程序的灵活性.(An executable was therefore beginning to look like an excellent solution, since although it would lose its tight coupling with VC6, this would more than be made up for by the considerably greater flexibility of a standalone application.)
修改了CodePlotter(CodePlotter Remoded)
首先采用的设计将使用户:(The first design to take form would have the user:)
- 将图以其代码复制并粘贴到CodePlotter界面中(copy and paste the diagram in their code into the CodePlotter interface)
- 编辑图(edit the diagram)
- 复制(以某种方式)并将该图粘贴回其代码中.(copy (somehow) and paste the diagram back into their code.) 我认为这没关系,但缺少VC6插件的一些技巧,这在它如何使用对象模型的选择机制来选择和替换代码图方面显得较为模糊(回想起来,这也是其最大的限制)因为用户无权在代码中的任何其他位置插入图表,除非随后手动复制和粘贴.(This was okay I thought but lacked some of the finesse of the VC6 addin which was much slicker in how it used the selection mechanism of the object model to both select and replace the code diagram (a feature that in retrospect, was also its greatest constraint since the user has no scope for inserting the diagram at any other place in the code except by manually copying and pasting it afterwards) .)
我离开了片刻,后来又想了一下,我发现我的大脑已经在"复制和粘贴"与"剪贴板"之间建立了联系.(I left it for a bit and later when I got to thinking about it some more I found that my brain had made the link between ‘copying and pasting’ and the ‘clipboard’.)
虽然这不是一次令人兴奋或令人印象深刻的飞跃,但是却是一笔宝贵的飞跃,因为它使我能够将剪贴板的编程用法假定为难题的最后一部分.迄今为止可能缺少的光滑度的那一块.(Not a tremendously exciting or impressive leap but a valuable one nonetheless since it allowed me to postulate the programmatic use of the clipboard as the final piece in the puzzle; the piece that would possibly give it the slickness it was so far missing.)
因此,我搜索了所有旧代码,看是否有一些入门知识,并且遇到了以下片段:(So I searched back through all my old code to see if I had something to get me started and I came across the following fragment:)
OpenClipboard();
CString sText((LPCTSTR)::GetClipboardData(CF_TEXT));
CloseClipboard();
e,尽管如此,我肯定不是那么容易(我敢肯定,有些人会渴望告诉我这到底有多困难),但是确实如此.(Gee, I though, surely it can’t be this easy (and I’m sure some of you will be itching to tell me just how difficult it really should be), but it was.)
因此,我要做的就是确保只要剪贴板内容发生更改,都会通过以下方式通知CodePlotter(So all I had to do then was ensure CodePlotter was notified whenever the clipboard contents changed, via) SetClipboardViewer(),
然后我就被定了.(and I was set.)
在我启动并运行基本实现后才发现的最后一个问题是,如何防止用户每次想要编辑图时都必须手动运行CodePlotter,而同时又不占用用户宝贵的空间.任务栏.(One final matter that was not discovered until I had the basic implementation up and running was how to prevent the user from having to run CodePlotter manually every time they wanted to edit a diagram, whilst at the same time not having it take up valuable space in the taskbar.)
您已经猜到了-我们的朋友可以将系统托盘救出.(You’ve guessed it - our friend the system tray to the rescue.)
所以它的工作方式是这样的:(So the way it works is this:)
- 第一次要使用CodePlotter时,每个会话都需要手动启动,除非您将其添加到启动文件夹中.(The first time you want to use CodePlotter each session requires a manual start, unless you add it to your startup folder.)
- 此后,它作为图标驻留在系统托盘中,直到检测到您刚刚将图复制到剪贴板后,它便显示了已解析的图.(Thereafter it resides as an icon in the system tray until it detects that you’ve just copied a diagram to the clipboard, whereupon it shows itself with the diagram already parsed.)
- 完成编辑后,该图将自动复制回剪贴板,以便您粘贴回代码中.(When you’re done editing, the diagram is automatically copied back to the clipboard for you to paste back into your code.)
安装CodePlotter就像…(Installing CodePlotter is as easy as…)
- 将可执行文件放到" … \程序文件\ Microsoft Visual Studio \ common \ tools"文件夹中(drop the executable into your “…\program files\microsoft visual studio\common\tools” folder)
- 从"工具|自定义… |工具"选项卡中为CodePlotter创建新工具(Create a new tool for CodePlotter from the ‘Tools|Customize…|Tools’ tab)
- 将工具添加到工具栏以便于访问(Add the tool to your toolbar for easy access)
使用CodePlotter(Using CodePlotter)
有关使用CodePlotter的简短教程,我将在(For a short tutorial on using CodePlotter I will refer you to this same section in the) 来源文章(original article) .(.)
仅在独立版本中提供的其他功能包括:(Other features only present in the standalone version include:)
- 一个"复制"按钮,用于将当前图表复制到剪贴板,而无需关闭对话框.(A ‘Copy’ button for copying the current diagram to the clipboard without having to dismiss the dialog.)
- 系统托盘上下文菜单,用于退出或显示CodePlotter.(A system tray context menu for exiting or displaying CodePlotter.)
内部CodePlotter(Inside CodePlotter)
该部分与(This section too is essentially unchanged from the) 来源文章(original article) 除了不必复制代码外,CodePlotter exe会从Addin项目中大量借用.(except that in order not to have to copy the code, the CodePlotter exe borrows heavily from the Addin project.)
这比听起来要重要得多,因为我在家也使用Visual SourceSafe(VSS).(This is more significant than it sounds because I also use Visual SourceSafe (VSS) at home.)
这里的要点是,VC6与VSS集成时不允许在同一硬盘驱动器目录中驻留多个项目(我曾期望在同一文件夹中仅包含两个.dsp文件并自由共享代码).(The beef here is that VC6 when integrated with VSS does not allow more than one project to reside in the same hard drive directory (I had anticipated simply having two .dsp files in the same folder and share the code freely).)
所以我必须有两个不同的项目文件夹.(So I had to have two distinct project folder.)
我知道,我想我会很棘手,并使用VSS的共享功能在每个项目文件夹中都有共享代码的副本.这样,每个项目似乎都具有自己的副本,而实际上它们是相同的VSS文件.(I know, I thought, I’ll be really tricky and use VSS’s share functionality to have a copy of the shared code in each of the project folders. That way each project will appear to have its own copy whilst in fact they are the same VSS file.)
半个小时后,我记得为什么这是一个非常糟糕的主意–如果将文件检出到一个文件夹,然后从另一个文件夹中检入,则很容易丢失更改并最终完全损坏(对那些想知道我是否在发誓的人来说,这是"打击".(Half an hour later I remembered why this is a really bad idea – if the file is checked out to one folder and you check it back in from the other then it really easy to lose changes and end up completely b**red (that’s ‘battered’ to you folk out there who were wondering if I was swearing).)
因此,在经过大约3次错误的启动之后,我决定采用KISS(保持简单,愚蠢)方法– CodePlotter可执行项目将通过将外接程序项目中的文件包含在VC6的"工作空间|文件"选项卡中来共享它们.(So after about 3 false starts I decided for the KISS (keep it simple, stupid) approach – the CodePlotter executable project would share files from the addin project by including them in the Workspace|Files tab in VC6.)
这有什么重要意义?(What’s so significant about that?)
好的,标准源文件是可以的,我们一直都在这样做,但这是我第一次尝试共享.rc文件.(Well, standard source files are ok, we do that all the time, but it was the first time I’d tried sharing an .rc file.)
我已经知道VC6,除了在相当大的压力下,并带有大量的咒语和有趣的握手,不会允许您在同一项目中拥有两个.rc文件,因此我只是检查了默认文件并添加了addin的.rc文件,就像我有其他共享源文件.(I knew already that VC6, except under considerable duress and with much incanting of spells and funny handshakes, will not let you have two .rc files in the same project so I just checked away the default one and added the addin’s .rc file just as I had the other shared source files.)
但是后来我碰到了另一个障碍,.rc2文件(无论如何,该文件的意义是什么.我知道它的意图是什么,但我发誓我从未见过有应用程序在使用它-请有人向我展示它的真实用法) .(But then I hit another snag, the .rc2 file (just what is the point of that file anyway. I know what its intention is but I swear I have never seen an app use it – please someone show me a bonafide use for it).)
问题是.rc文件通过相对路径(相对于项目根目录)包括了该路径,因此,尽管我在原始位置中编译了插件的.rc文件,但预处理程序仍希望在独立文件夹中找到CodePlotterAddin.rc2.(The problem is that the .rc file includes this by relative path – relative to the project root that is – so although i was compiling the addin’s .rc file in its original location the preprocessor wanted to locate CodePlotterAddin.rc2 in the standalone’s folder.)
因此,我做了任何优秀的黑客所做的事情.没错,我只是删除了它以使其消失,而且令人惊讶的是它起作用了.或多或少.(So I did what any good hacker does. That’s right, I simply deleted it to make it go away, and surprisingly enough it worked. More or less.)
.rc文件需要更多的绑定才能删除对它的所有引用,还需要一个虚拟的.tlb文件来阻止预处理器吐出虚拟文件(.tlb文件是类型库,如果没有该库,插件将不会导出该文件.与VC6通信所必需的接口–我知道这一点,因为我也尝试删除它!)(A bit more bodging of the .rc file to remove all references to it was required, as was a dummy .tlb file to stop the preprocessor from spitting the dummy (the .tlb file is the type library without which the addin would not export the necessary interfaces to communicate with VC6 – I know this because I tried deleting it too!))
进一步的工作(Further Work)
- 键盘编辑(Keyboard editing)
- 从与目标框相对的一侧开始时更好的路径查找(当前实现产生了一些非常违反直觉的解决方案)(Better path finding when starting from the side opposite to the target box (the current implementation produces some very counter-intuitive solutions))
- 菱形盒子(Diamond shaped boxes)
版权(Copyright)
此处提供了该代码,供您不受限制地使用和滥用,除了您不能修改它并以自己的身份将其传递出去.(The code is supplied here for you to use and abuse without restriction, except that you may not modify it and pass it off as your own.)
历史(History)
-
**1.0(1.0)**初始发行(Initial Release)
-
1.1(1.1)
- 就地编辑文本框(感谢(In-place editing of box text (thanks to)=[阿宾] =(=[ Abin ]=))())
- 改进的路径查找(感谢(Improved path finding (thanks to)to_be_unknown(to_be_unknown))())
- 修复了与移动箱子时调整大小有关的错误(感谢(fixed bug relating to boxes resizing when moved (thanks to)to_be_unknown(to_be_unknown))())
-
1.2(1.2)
- 改进了图表验证(感谢(improved diagram verification (thanks to)sunil_g7(sunil_g7))())
- 为所有非拖放编辑添加了上下文菜单(context menus added for all non-drag’n’drop editing)
- 编辑框文本时可以使用Enter/Esc键(Enter/Escape keys can be used when editing box text)
-
1.3(1.3)
- 重做的UI(reworked UI)
- 可调整大小(并在会话之间记住)(感谢(resizeable (and remembered between sessions) (thanks to)匿名(Anonymous))())
- 编码者希望使用VB,NSBasic或C的其他注释样式(感谢(Alternative comment styles for coder’s wishing to working VB, NSBasic or C (thanks to)阿德里安`尼古拉耶夫(Adrian Nicolaiev)(Adrian Nicolaiev))())
-
1.4(1.4)
- 在上下文菜单中添加了"翻转连接"以反转连接的方向(感谢(‘Flip Connecton’ added to context menu to reverse a connection’s direction (thanks to)拉尔夫`韦策尔(Ralph Wetzel))())
- 按键编辑所选框的文本(感谢(press to edit the selected box’s text (thanks to)匿名(Anonymous))())
-
1.6(1.6)
- 修复了"复制"按钮的错误(感谢(‘Copy’ button bug fixed (thanks to)罗伯特`埃瑟里奇(Robert Etheridge))())
- 暂时删除了"调整框大小以适合"命令(感谢(‘Resize box to fit’ command removed for now (thanks to)罗伯特`埃瑟里奇(Robert Etheridge))())
- 在连接的开始和结束处," “和”#“都由箭头代替(建议使用('' and ‘#’ replaced by arrows at both the start and end of a connection (suggested by)罗伯特`埃瑟里奇(Robert Etheridge))())
- 用户可以定义可视页面宽度以指导行长(自动考虑之前的任何注释长度)(建议由(user can define visual page width for guidance on line length (automatically takes any preceding comment length into account) (suggested by)罗伯特`埃瑟里奇(Robert Etheridge))())
- 一些小的速度改进(some minor speed improvements)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 VC7.1 C++ VC6 WinXP Win2003 Win2K MFC Visual-Studio Dev 新闻 翻译