コード例 #1
0
        string _resourceCurrentType = ".jpg,.png,.gif,.bmp"; //暂时写法
        #endregion

        #region 公共属性

        #endregion

        #region 公共方法

        #endregion

        #region 内部方法

        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            //panelPreview.Update();
            //panelPreview.Refresh();
            panelPreview.Paint += new PaintEventHandler(panelPreview_Paint);
            //Graphics g = panelPreview.CreateGraphics();

            resourceFilePaths = new List <MyListItem>();
            MyListFolderItem myFolderResouce = new MyListFolderItem(Service.Sdsite.CurrentDocument.Resources, null);

            myResourceCurrentItem = myFolderResouce;
            resourceFilePaths.Add(myFolderResouce);

            listViewFodel.MultiSelect               = false;
            listViewFodel.SmallImageList            = new ImageList();
            listViewFodel.SmallImageList.ColorDepth = ColorDepth.Depth32Bit;
            listViewFodel.SmallImageList.ImageSize  = new Size(16, 16);

            listViewFodel.LargeImageList            = new ImageList();
            listViewFodel.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;

            listViewFodel.View = View.LargeIcon; //资源文件初始打开为缩略图
            myResourceCurrentItem.ListShowView = View.LargeIcon;
            myResourceCurrentItem.BreviaryMap  = true;

            InitListView(myFolderResouce, listViewFodel, _resourceCurrentType);

            comboBoxType.SelectedIndex = 0;
        }
コード例 #2
0
        /// <summary>
        /// //上一级
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void parentResToolStripButton_Click(object sender, EventArgs e)
        {
            if (myResourceCurrentItem is MyListFolderItem)
            {
                resourceFilesListView.LargeImageList.Images.Clear();
                resourceFilesListView.SmallImageList.Images.Clear();

                MyListItem myCurrent = (myResourceCurrentItem as MyListFolderItem).FolderItemParant;

                if (!myCurrent.BreviaryMap)
                {
                    resourceFilesListView.LargeImageList.ImageSize = new Size(32, 32); //不是缩略图的恢复大小
                }
                if (myCurrent.FolderItemParant == null)
                {
                    parentResToolStripButton.Enabled = false; //到根了
                    InitListView(resourceFilePaths[0], resourceFilesListView, _resourceCurrentType);
                    myResourceCurrentItem = resourceFilePaths[0];
                }
                else
                {
                    myResourceCurrentItem = myCurrent;
                    InitListView(myCurrent, resourceFilesListView, _resourceCurrentType);
                }
                SetResourceMenuCheckState(myResourceCurrentItem);
            }
        }
コード例 #3
0
        /// <summary>
        /// 根据当前文件夹显示的方式,设置菜单是否选中
        /// </summary>
        private void SetLocalPageMenuCheckState(MyListItem myitem)
        {
            ToolStripDropDownButton toolStripButton = (ToolStripDropDownButton)localpagesToolStrip.Items["viewsPageToolStripDropDownButton"];

            string strCheckName = "";

            if (myitem.ListShowView == View.LargeIcon)
            {
                strCheckName = "largeIconViewPageToolStripMenuItem";
            }
            else if (myitem.ListShowView == View.SmallIcon)
            {
                strCheckName = "smallIconViewPageToolStripMenuItem";
            }
            else if (myitem.ListShowView == View.List)
            {
                strCheckName = "listViewPageToolStripMenuItem";
            }
            else if (myitem.ListShowView == View.Details)
            {
                strCheckName = "detailsViewPageToolStripMenuItem";
            }
            foreach (ToolStripItem item in toolStripButton.DropDownItems)
            {
                if (item is ToolStripMenuItem && item.Name.Equals(strCheckName))
                {
                    (item as ToolStripMenuItem).Checked = true;
                }
                else
                {
                    (item as ToolStripMenuItem).Checked = false;
                }
            }
        }
コード例 #4
0
 public MyListFolderItem(FolderXmlElement element, MyListItem parantFolder)
     : base(element)
 {
     _element     = element;
     this.Text    = _element.Title;
     ListShowView = View.LargeIcon;
     _myItemParnt = parantFolder;
     BreviaryMap  = true; //缩略图
 }
コード例 #5
0
 /// <summary>
 /// 判断item是否在列表中
 /// </summary>
 /// <returns></returns>
 private MyListItem ItemContains(List <MyListItem> listPaths, MyListItem myItem)
 {
     foreach (MyListItem item in listPaths)
     {
         //本来是判断绝对路径,删除时将对应listPaths中项目也删除,但遍历的时候,List中内容以便,
         //编译器就报错,说List中内容已变,暂时不删除List中内容,但这样有可能路径就相同了,所以这里用ID
         if (item.Element.Id == myItem.Element.Id)
         {
             return(item);
         }
     }
     return(null);
 }
コード例 #6
0
        private void ContextMenuStrip_Opening(object sender, CancelEventArgs e)
        {
            if (IsInsertLink || resourceFilesListView.SelectedItems.Count != 1)
            {
                e.Cancel = true;
                return;
            }
            MyListItem myitem = resourceFilesListView.SelectedItems[0] as MyListItem;

            if (!(myitem is MyListFileItem))
            {
                e.Cancel = true;
                return;
            }
        }
コード例 #7
0
        private void localPagesListView_DoubleClick(object sender, EventArgs e)
        {
            if (localPagesListView.SelectedItems.Count > 0)
            {
                MyListItem myitem = localPagesListView.SelectedItems[0] as MyListItem;
                if (myitem is MyListFileItem)
                {
                    //模拟使用过的图片
                    //string df = myitem.Element.Title;
                    //string sf = Path.GetDirectoryName(myitem.Element.AbsoluteFilePath);
                    Service.RecentFiles.AddFilePath(Service.RecentFiles.RecentOpenLocalPageFiles, myitem.Element.AbsoluteFilePath);

                    XmlDocument xmlDoc = new XmlDocument();
                    XmlElement  xmlEle = xmlDoc.CreateElement("Page");
                    ((MyListFileItem)myitem).XmlAttribute = xmlEle;

                    string strUrl = "[url:]" + ((MyListFileItem)myitem).Element.Id;
                    ((MyListFileItem)myitem).XmlAttribute.SetAttribute("src", strUrl);

                    if (((MyListFileItem)myitem).XmlAttribute != null)
                    { //进行了高级设置
                        XmlElement ele = ((MyListFileItem)myitem).XmlAttribute;
                        foreach (XmlAttribute att in ele.Attributes)
                        {
                            _XmlElement.SetAttribute(att.Name, att.Value);
                        }
                    }

                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MyListItem item = ItemContains(localFilePaths, myitem);
                    if (item == null)
                    {
                        localFilePaths.Add(myitem); //没有打开过,添加
                    }
                    else
                    {
                        myitem = item;
                    }
                    myPageCurrentItem = myitem;
                    InitListView(myPageCurrentItem, localPagesListView, _localPageCurrentType);
                    parentPageToolStripButton.Enabled = true;// (myitem.Element.AbsoluteFilePath != Service.Sdsite.CurrentDocument.Resources.AbsoluteFilePath);
                }
                SetLocalPageMenuCheckState(myPageCurrentItem);
            }
        }
コード例 #8
0
        private void deletePageToolStripButton_Click(object sender, EventArgs e)
        {
            if (localPagesListView.SelectedItems.Count <= 0)
            {
                return;
            }
            if (MessageService.Show("${res:Tree.msg.delete}", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            SdsiteXmlDocument doc      = Service.Sdsite.CurrentDocument;
            MyListItem        deleItem = localPagesListView.SelectedItems[0] as MyListItem;

            doc.DeleteItem(deleItem.Element);
            localPagesListView.Items.Remove(deleItem);
        }
コード例 #9
0
        /// <summary>
        ///  保存/替换文件
        /// </summary>
        /// <param name="isReplace">true 替换文件 , false 只保存</param>
        /// <returns>保存/替换成功 返回TRUE 失败 FALSE</returns>
        private bool SaveOrReplaceFile(bool isReplace, string fileName)
        {
            SdsiteXmlDocument doc = Service.Sdsite.CurrentDocument;

            if (isReplace)
            {
                DialogResult result = MessageService.Show("${res:Tree.msg.coverFile}", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Cancel)
                {
                    return(false);
                }

                //旧文件删除
                foreach (MyListItem item in listViewFodel.Items)
                {
                    if (item is MyListFileItem)
                    {
                        MyListFileItem fileItem = item as MyListFileItem;
                        if (fileName.Equals(fileItem.Element.FileName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            MyListItem deleItem = fileItem as MyListItem;
                            doc.DeleteItem(deleItem.Element);
                            listViewFodel.Items.Remove(deleItem);
                        }
                    }
                }
            }
            //保存新文件
            if (myResourceCurrentItem != null)
            {
                string strSrcFile = Path.Combine(myResourceCurrentItem.Element.AbsoluteFilePath, fileName);
                _image.Save(strSrcFile, _imgFormat);
                FileSimpleExXmlElement fileEle = doc.CreateFileElement(myResourceCurrentItem.Element as FolderXmlElement, strSrcFile);
                InitListView(myResourceCurrentItem, listViewFodel, _resourceCurrentType);

                this.DialogResult = DialogResult.OK;
            }



            return(true);
        }
コード例 #10
0
        private void parentPageToolStripButton_Click(object sender, EventArgs e)
        {//页面上一级
            if (myPageCurrentItem is MyListFolderItem)
            {
                MyListItem myCurrent = (myPageCurrentItem as MyListFolderItem).FolderItemParant;

                if (myCurrent.FolderItemParant == null)
                {
                    parentPageToolStripButton.Enabled = false; //到根了
                    InitListView(localFilePaths[0], localPagesListView, _localPageCurrentType);
                    myPageCurrentItem = localFilePaths[0];
                }
                else
                {
                    myPageCurrentItem = myCurrent;
                    InitListView(myCurrent, localPagesListView, _localPageCurrentType);
                }
                SetLocalPageMenuCheckState(myPageCurrentItem);
            }
        }
コード例 #11
0
        /// <summary>
        /// 为欲保存的图片选择路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listViewFodel_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listViewFodel.SelectedItems.Count > 0)
            {
                MyListItem myitem = listViewFodel.SelectedItems[0] as MyListItem;
                if (myitem is MyListFileItem)
                {
                    #region 替换该文件

                    if (SaveOrReplaceFile(true, ((MyListFileItem)myitem).Element.FileName))
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                    #endregion
                }
                else
                {
                    #region  择文件夹

                    MyListItem item = ItemContains(resourceFilePaths, myitem);
                    if (item == null)
                    {
                        resourceFilePaths.Add(myitem); //没有打开过,添加
                    }
                    else
                    {
                        myitem = item;
                    }
                    myResourceCurrentItem = myitem;
                    listViewFodel.SmallImageList.Images.Clear();
                    listViewFodel.LargeImageList.Images.Clear();
                    InitListView(myResourceCurrentItem, listViewFodel, _resourceCurrentType);
                    parentResToolStripButton.Enabled = true;// (myitem.Element.AbsoluteFilePath != Service.Sdsite.CurrentDocument.Resources.AbsoluteFilePath);
                    SetResourceMenuCheckState(myResourceCurrentItem);

                    #endregion
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// 根据当前文件夹显示的方式,设置菜单是否选中
        /// </summary>
        private void SetResourceMenuCheckState(MyListItem myitem)
        {
            ToolStripDropDownButton toolStripButton = (ToolStripDropDownButton)resourceFilesToolStrip.Items["viewsResToolStripDropDownButton"];

            string strCheckName = "";

            if (myitem.ListShowView == View.LargeIcon && myitem.BreviaryMap)
            {
                strCheckName = "thumbnailViewResToolStripMenuItem";
            }
            else if (myitem.ListShowView == View.LargeIcon && !myitem.BreviaryMap)
            {
                strCheckName = "largeIconViewResToolStripMenuItem";
            }
            else if (myitem.ListShowView == View.SmallIcon)
            {
                strCheckName = "smallIconViewResToolStripMenuItem";
            }
            else if (myitem.ListShowView == View.List)
            {
                strCheckName = "listViewResToolStripMenuItem";
            }
            else if (myitem.ListShowView == View.Details)
            {
                strCheckName = "detailsViewResToolStripMenuItem";
            }
            foreach (ToolStripItem item in toolStripButton.DropDownItems)
            {
                if (item is ToolStripMenuItem && item.Name.Equals(strCheckName))
                {
                    (item as ToolStripMenuItem).Checked = true;
                }
                else
                {
                    (item as ToolStripMenuItem).Checked = false;
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// 加载项目
        /// </summary>
        /// <param name="initPath"></param>
        private void InitListView(MyListItem folderEle, ListViewEx listView, string FilterType)
        {
            listView.Items.Clear();

            // listView.FolderName = folderEle.Element.AbsoluteFilePath;

            CreateHeader(listView); //列表头
            //加载子文件夹
            foreach (XmlNode node in folderEle._element.ChildNodes)
            {
                if (node is FolderXmlElement && !(node is TmpltFolderXmlElement) && !(node is ResourcesXmlElement))
                {
                    FolderXmlElement folder = (FolderXmlElement)node;
                    if (folder.IsDeleted)
                    {
                        continue;
                    }

                    MyListFolderItem mylvi = new MyListFolderItem(folder, folderEle);
                    if (mainTabControl.SelectedIndex != 0)
                    {
                        mylvi.BreviaryMap = false;
                    }
                    string folderPath = folder.AbsoluteFilePath.Substring(0, folder.AbsoluteFilePath.Length - 1);
                    mylvi.Text = Path.GetFileName(folderPath);
                    mylvi.Text = folder.Title;

                    listView.Items.Add(mylvi);
                }
            }
            //加载子文件
            InitListViewSubFile(folderEle._element.ChildNodes, listView, FilterType);


            if (folderEle.BreviaryMap && folderEle.ListShowView == View.LargeIcon)
            {//缩略图
                listView.LargeImageList.Images.Clear();
                listView.LargeImageList.ImageSize = new Size(96, 96);
                foreach (MyListItem lvitem in listView.Items)
                {
                    // if (lvitem is MyFileItem1)
                    {
                        string fullPath = lvitem.Element.AbsoluteFilePath;
                        lvitem.ImageIndex = listView.LargeImageList.Images.Add(listView.GetThumbNail(fullPath), Color.Transparent);
                    }
                }
            }
            else
            {
                listView.LargeImageList.ImageSize = new Size(32, 32);
                //加载图标
                foreach (MyListItem lvitem in listView.Items)
                {
                    string fullPath = lvitem.Element.AbsoluteFilePath;
                    KeyValuePair <string, Image> keyImg = GetImageAndKey(fullPath, GetSystemIconType.ExtensionSmall);
                    if (!listView.SmallImageList.Images.ContainsKey(keyImg.Key))
                    {
                        listView.SmallImageList.Images.Add(keyImg.Key, keyImg.Value);
                    }
                    KeyValuePair <string, Image> keyLargeImg = GetImageAndKey(fullPath, GetSystemIconType.ExtensionLarge);
                    if (!listView.LargeImageList.Images.ContainsKey(keyLargeImg.Key))
                    {
                        listView.LargeImageList.Images.Add(keyLargeImg.Key, keyLargeImg.Value);
                    }
                    lvitem.ImageKey = keyImg.Key;
                }
            }

            if (folderEle is MyListFolderItem)
            {
                listView.View = folderEle.ListShowView;
            }
        }
コード例 #14
0
        private void imageToolStripMenuItem_Click(object sender, EventArgs e)
        {//导入资源
            SdsiteXmlDocument doc            = Service.Sdsite.CurrentDocument;
            MyListItem        importFolder   = null;
            string            openfileFilter = "";

            ToolStripMenuItem menuItem = (ToolStripMenuItem)(sender);

            switch (menuItem.Name)
            {
            case "imageToolStripMenuItem":
                openfileFilter = "PIC files (*.jpg,*.gif)|*.jpg;*.gif;";
                break;

            case "medioFileToolStripMenuItem":
                openfileFilter  = "Audio files (*.mp3,*.mdi,*.wma,*.wav)|*.mp3;*.mid;*.wma;*.wav;|";
                openfileFilter += "Media files (*.rmvb,*.rm,*.avi,*.wmv)|*.rmvb;*.rm;*.avi;*.wmv;|";
                openfileFilter += "Flash files (.swf)|*.swf;";
                break;

            case "documentFileToolStripMenuItem":
                openfileFilter = "doc files (*.txt,*.doc)|*.txt;*.doc;";
                break;

            case "compressFileNewToolStripMenuItem":
                openfileFilter = "Compress files (*.rar,*.zip)|*.rar;*.zip;";
                break;
            }

            FormOpenFileDialog OpenFile = new FormOpenFileDialog();

            OpenFile.OpenDialog.Multiselect = true;
            OpenFile.OpenDialog.Filter      = openfileFilter;
            if (OpenFile.ShowDialog(this) == DialogResult.OK)
            {
                string[] fileNames = OpenFile.OpenDialog.FileNames;
                foreach (string srcFilePath in fileNames)
                {
                    if (resourceFilesListView.SelectedItems.Count > 0 && resourceFilesListView.SelectedItems[0] is MyListFolderItem)
                    {
                        importFolder = (resourceFilesListView.SelectedItems[0] as MyListItem);
                        MyListItem item = ItemContains(resourceFilePaths, importFolder);
                        if (item != null)
                        {
                            importFolder = item;
                        }
                        parentResToolStripButton.Enabled = true;
                        myResourceCurrentItem            = importFolder;
                    }
                    else
                    {
                        importFolder = myResourceCurrentItem;
                    }
                    FileSimpleExXmlElement fileEle = doc.CreateFileElement(importFolder._element as FolderXmlElement, srcFilePath);
                }
                if (importFolder != null)
                {
                    InitListView(importFolder, resourceFilesListView, _resourceCurrentType);
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// 双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void resourceFilesListView_DoubleClick(object sender, EventArgs e)
        {
            if (resourceFilesListView.SelectedItems.Count > 0)
            {
                MyListItem myitem = resourceFilesListView.SelectedItems[0] as MyListItem;
                if (myitem is MyListFileItem)
                {
                    #region  择的是文件

                    Service.RecentFiles.AddFilePath(Service.RecentFiles.RecentOpenImageFiles, myitem.Element.AbsoluteFilePath);
                    XmlElement ele = null;
                    if (((MyListFileItem)myitem).XmlAttribute != null)
                    { //进行了高级设置
                        ele = ((MyListFileItem)myitem).XmlAttribute;
                    }
                    else
                    {//没有设置过,设置默认的属性
                        #region 默认属性
                        switch (((MyListFileItem)myitem).ItemMediaType)
                        {
                        case MediaFileType.None:
                            break;

                        case MediaFileType.Pic:
                            ele = (XmlElement)InsertPicCodeForm.GetDefaultPicHtml(myitem.Element.AbsoluteFilePath, myitem.Element.Id).ToXmlNode();
                            break;

                        case MediaFileType.Flash:
                            break;

                        case MediaFileType.Audio:
                            break;

                        case MediaFileType.Video:
                            break;

                        default:
                            Debug.Fail("未知的type:" + ((MyListFileItem)myitem).ItemMediaType.ToString());
                            break;
                        }
                        #endregion
                    }
                    if (ele != null)
                    {
                        foreach (XmlAttribute att in ele.Attributes)
                        {
                            _XmlElement.SetAttribute(att.Name, att.Value);
                        }
                    }
                    this.DialogResult = DialogResult.OK;

                    #endregion
                }
                else
                {
                    #region  择文件夹

                    MyListItem item = ItemContains(resourceFilePaths, myitem);
                    if (item == null)
                    {
                        resourceFilePaths.Add(myitem); //没有打开过,添加
                    }
                    else
                    {
                        myitem = item;
                    }
                    myResourceCurrentItem = myitem;
                    resourceFilesListView.SmallImageList.Images.Clear();
                    resourceFilesListView.LargeImageList.Images.Clear();
                    InitListView(myResourceCurrentItem, resourceFilesListView, _resourceCurrentType);
                    parentResToolStripButton.Enabled = true;// (myitem.Element.AbsoluteFilePath != Service.Sdsite.CurrentDocument.Resources.AbsoluteFilePath);
                    SetResourceMenuCheckState(myResourceCurrentItem);

                    #endregion
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// 资源的高级设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResourceHighSetting_Click(object sender, EventArgs e)
        {
            if (resourceFilesListView.SelectedItems.Count != 1)
            {
                return;                                                 //不支持多选
            }
            MyListItem myitem = resourceFilesListView.SelectedItems[0] as MyListItem;

            if (myitem is MyListFileItem)
            {
                BaseForm        form         = new BaseForm();
                XhtmlTagElement xhtmlElement = null;// new XhtmlTagElement();
                XhtmlSection    _section     = new XhtmlSection();
                string          strHref      = "[url: " + ((MyListFileItem)myitem).Element.Id + "]";
                switch (((MyListFileItem)myitem).ItemMediaType)
                {
                case MediaFileType.None:
                    break;

                case MediaFileType.Pic:
                    #region 图片
                {
                    xhtmlElement = _section.CreateXhtmlImg();
                    ((XhtmlTags.Img)xhtmlElement).Src = strHref;
                    form = new InsertPicCodeForm(xhtmlElement, ((MyListFileItem)myitem).Element.AbsoluteFilePath);
                    break;
                }

                    #endregion
                case MediaFileType.Flash:
                    #region Flash
                {
                    xhtmlElement = _section.CreateXhtmlFlash();

                    CssSection style = new CssSection();
                    ((XhtmlTags.Flash)xhtmlElement).Builder(style, "", strHref, Xhtml.Align.left, "", -1, -1, "", "", "");
                    form = new InsertFlashCodeForm(xhtmlElement, ((MyListFileItem)myitem).Element.AbsoluteFilePath);

                    break;
                }

                    #endregion
                case MediaFileType.Audio:
                    #region Audio
                {
                    xhtmlElement = _section.CreateXhtmlObject();
                    //((XhtmlTags.Object)xhtmlElement).Src = strHref;
                    form = new InsertAudioCodeForm(xhtmlElement, ((MyListFileItem)myitem).Element.AbsoluteFilePath);
                    break;
                }

                    #endregion
                case MediaFileType.Video:
                    #region Video
                {
                    xhtmlElement = _section.CreateXhtmlObject();
                    //((XhtmlTags.Object)xhtmlElement).Src = strHref;
                    form = new InsertVideoCodeForm(xhtmlElement, ((MyListFileItem)myitem).Element.AbsoluteFilePath);
                    break;
                }

                    #endregion
                default:
                    Debug.Fail("未知的type:" + ((MyListFileItem)myitem).ItemMediaType.ToString());
                    break;
                }
                if (form.ShowDialog() == DialogResult.OK)
                {
                    ((MyListFileItem)myitem).XmlAttribute = (XmlElement)xhtmlElement.ToXmlNode();
                }
            }
        }