zoukankan      html  css  js  c++  java
  • 基础框架平台——基础管理框架——GUI抽象设计(视图)

    通过开源项目SHARPDEVELOP项目的核心框架的学习分析说明基础管理框架的抽象设计。
    先把这几天面向接口编程的学习小结一下,C#语言关于接口编成的内容:
    1、接口允许多继承,类只能继承与一个基类,但是可以从一个基类、多个接口派生;
    2、接口只是定义说明,并不具体实现,提供组件/模块之间的交互规范。
    3、接口描述一个系统中相对稳定部分的结构,是系统的最高层抽象。

    抛开菜单管理器具体的菜单项、工具条的功能按钮、面板内具体的内容、视图的具体内容,将所有具体

    GUI内容的操作抽象成为一组抽象的内容接口(contentinterfaces),试图通过接口来定义基础管理框架管

    理界面的GUI高层抽象。

    每个视图或者面板包含的内容可能拥有的一组接口:
    1,ICanBeDirty
         定义视图内容的变化标志IsDirty,和变化事件DirtyChanged。在工作台管理器的保存视图内容事件

    中调用。
    2,IClipboardHandler
         定义视图内容是否可以剪切、复制、粘贴、删除、全选状态剪切、复制、粘贴、删除、全选方法。

    在文本编辑器的实现中会大量被调用。
    3,IContextHelpProvider
         定义对内容提供帮助的方法。在按“F1”键时,会调用。
    5,IMementoCapable
         定义创建新GUI对象记忆和恢复GUI对象记忆方法。
    6,IPrintable
         定义打印文档属性,打印设置,打印调用方法。
    7,IUndoHandler
         定义是否可以继续Undo,是否可以继续Redo属性,和Undo,Redo方法。
    8,IViewContentMemento
         定义创建新视图内容对象记忆和恢复视图内容对象记忆方法。
     

    下面介绍框架核心“视图”的理解:


    在windows标准窗体中,视图是的工作是用来做具体事情,视图是可以作为一个文件进行保存,如果打开

    多个 视图,那么在关闭工作台窗体之前,需要通知非活动的视图保存,而每个视图是否需要保存则由是

    否修改标识来记录。


    因此,视图接口在GUI的抽象是这样来定义的 :
    1,IViewContent 继承IBaseViewContent,ICanBeDirty

      /// <summary>
        
    /// IViewContent is the base interface for all editable data
        
    /// inside SharpDevelop.
        
    /// </summary>

        public interface IViewContent : IBaseViewContent, ICanBeDirty
        
    {
            
    /// <summary>
            
    /// A generic name for the file, when it does have no file name
            
    /// (e.g. newly created files)
            
    ///新建文件的默认名称
            
    /// </summary>

            string UntitledName
            
    {
                
    get;
                
    set;
            }


            
    /// <summary>
            
    /// This is the whole name of the content, e.g. the file name or
            
    /// the url depending on the type of the content.
            
    ///文件名
            
    /// </summary>
            
    /// <returns>
            
    /// Title Name, if not set it returns UntitledName
            
    ///如果没有文件名,则返回默认文件名
            
    /// </returns>

            string TitleName
            
    {
                
    get;
                
    set;
            }


            
    /// <summary>
            
    /// Returns the file name (if any) assigned to this view.
            
    /// </summary>

            string FileName
            
    {
                
    get;
                
    set;
            }


            
    /// <summary>
            
    /// If this property returns true the view is untitled.
            
    /// </summary>
            
    /// <returns>
            
    /// True, if TitleName not set.
            
    /// </returns>

            //是否已经命名标题
            bool IsUntitled
            
    {
                
    get;
            }


            
    /// <summary>
            
    /// If this property returns true the content could not be altered.
            
    /// </summary>

            //是否视图修改
            bool IsReadOnly
            
    {
                
    get;
            }


            
    /// <summary>
            
    /// If this property returns true the content can't be written.
            
    /// </summary>

             
            
    bool IsViewOnly
            
    {
                
    get;
            }


            
    /// <summary>
            
    /// Gets the list of secondary view contents attached to this view content.
            
    /// </summary>

            List<ISecondaryViewContent> SecondaryViewContents
            
    {
                
    get;
            }


            
    /// <summary>
            
    /// Saves this content to the last load/save location.
            
    /// </summary>

            void Save();

            
    /// <summary>
            
    /// Saves the content to the location <code>fileName</code>
            
    /// </summary>

            void Save(string fileName);

            
    /// <summary>
            
    /// Loads the content from the location <code>fileName</code>
            
    /// </summary>

            void Load(string fileName);

            
    /// <summary>
            
    /// Is called each time the name for the content has changed.
            
    /// </summary>

            event EventHandler TitleNameChanged;

            
    event EventHandler Saving;
            
    event EventHandler Saved;
        }


    2、IBaseViewContent
     

     1  public interface IBaseViewContent
     2    {
     3        /// <summary>
     4        /// 返回视图包含的控件
     5 /// </summary>

     6        Control Control
     7        {
     8            get;
     9        }

    10
    11        /// <summary>
    12        /// 获取、设置工作台窗体接口
    13        /// </summary>

    14        IWorkbenchWindow WorkbenchWindow
    15        {
    16            get;
    17            set;
    18        }

    19
    20        /// <summary>
    21        /// 当一个或多个视图内容附着在单窗体window
    22        /// 程序时,获取tab页的标题,
    23        /// </summary>

    24        string TabPageText
    25        {
    26            get;
    27        }

    28
    29        /// <summary>
    30        /// 当视图在windows内切换时触发
    31        /// -> 发生在tab控件内(在选中事件前触发)
    32        /// -> 发生在工作台内.
    33        /// </summary>

    34        void SwitchedTo();
    35
    36        /// <summary>
    37        /// 当tab分页被选中时触发,
    38        /// 不是windows窗体选中时触发
    39        /// </summary>

    40        void Selected();
    41
    42        /// <summary>
    43        /// Is called just before the view content is deselected inside the window
    44        /// tab before the other window is selected. NOT when the windows is deselected.
    45        /// </summary>

    46        void Deselecting();
    47
    48        /// <summary>
    49        /// Is called when the view content is deselected inside the window
    50        /// tab before the other window is selected. NOT when the windows is deselected.
    51        /// </summary>

    52        void Deselected();
    53
    54        /// <summary>
    55        /// 重新初始化视图
    56        /// 重新初始化视图包含的内容
    57        /// </summary>

    58        void RedrawContent();
    59    }

    3、ICanBeDirty

     1      /// <summary>
     2        /// Interface for classes that implement the IsDirty property and the DirtyChanged event.
     3        /// 定义类的修改属性,修改变化事件接口
     4        /// </summary>

     5        public interface ICanBeDirty
     6        {
     7            /// <summary>
     8            /// If this property returns true the content has changed since
     9            /// the last load/save operation.
    10            /// 当视图内容改变时,返回true
    11            /// </summary>

    12            bool IsDirty
    13            {
    14                get;
    15                set;
    16            }

    17
    18            /// <summary>
    19            /// Is called when the content is changed after a save/load operation
    20            /// and this signals that changes could be saved.
    21            /// </summary>

    22            event EventHandler DirtyChanged;
    23        }



    4,ISecondaryViewContent

       /// <summary>
        
    /// The base interface for secondary view contents
        
    /// (designer, doc viewer etc.)
        
    /// </summary>

        public interface ISecondaryViewContent : IBaseViewContent
        
    {
            
    /// <summary>
            
    /// Is called before the save operation of the main IViewContent
            
    /// 在保存主视图内容之前触发
            
    /// </summary>

            void NotifyBeforeSave();

            
    //在保存主视图内容成功之后触发,参数:是否保存成功
            void NotifyAfterSave(bool successful);
        }

    请园子里的各位大哥,给小弟一些指点。我这样理解
     


     

  • 相关阅读:
    中介者模式
    观察者模式
    javascript深入理解js闭包
    外观模式
    模板方法模式
    浅析C#深拷贝与浅拷贝
    C#浅拷贝与深拷贝区别
    6个重要的.NET概念:栈,堆,值类型,引用类型,装箱,拆箱
    原型模式
    设计模式总结
  • 原文地址:https://www.cnblogs.com/bobzhangfw/p/625853.html
Copyright © 2011-2022 走看看