public void CloseItem(ITabItem item)
 {
     if (_lDocDict.ContainsKey(item))
     {
         item.FloatClosed -= OnTabFloatClosed;
         LayoutDocument ldoc = _lDocDict[item];
         _lDocDict.Remove(item);
         TabItemCollection.Remove(item);
         if (item.IsFloat)
         {
             LayoutFloatingWindowControl fwctrl = item.FloatControl;
             fwctrl.Close();
             item.IsFloat = false;
         }
         else
         {
             Children.Remove(ldoc);
         }
         if (item is LadderDiagramViewModel)
         {
             IEnumerable <MainTabDiagramItem> fit = DiagramCollection.Where(
                 (MainTabDiagramItem _mtditem) => { return(_mtditem.LDVM_ladder == item); });
             MainTabDiagramItem mtditem = null;
             if (fit.Count() > 0)
             {
                 mtditem = fit.First();
                 DiagramCollection.Remove(mtditem);
             }
         }
         CloseTabItem(this, new RoutedEventArgs());
     }
 }
        public void ShowItem(ITabItem item)
        {
            //bool isnew = false;
            LayoutDocument ldoc = null;

            if (item is FuncBlockViewModel)
            {
                FuncBlockViewModel fbvmodel = (FuncBlockViewModel)item;
                fbvmodel.CodeTextBox.Focus();
            }
            if (item.IsFloat)
            {
                LayoutFloatingWindowControl fwctrl = item.FloatControl;
                fwctrl.Focus();
                return;
            }
            if (!TabItemCollection.Contains(item))
            {
                TabItemCollection.Add(item);
                item.FloatClosed += OnTabFloatClosed;
                ldoc              = new LayoutDocument();
                ldoc.Title        = item.TabHeader;
                if (item is LadderDiagramViewModel)
                {
                    IEnumerable <MainTabDiagramItem> fit = DiagramCollection.Where(
                        (MainTabDiagramItem _mtditem) => { return(_mtditem.LDVM_ladder == item); });
                    MainTabDiagramItem mtditem = null;
                    if (fit.Count() == 0)
                    {
                        mtditem = new MainTabDiagramItem((IProgram)item, ViewMode);
                        DiagramCollection.Add(mtditem);
                    }
                    else
                    {
                        mtditem = fit.First();
                    }
                    ldoc.Content = mtditem;
                }
                else
                {
                    ldoc.Content = item;
                }
                ldoc.IsActiveChanged += OnActiveChanged;
                Children.Add(ldoc);
                _lDocDict.Add(item, ldoc);
                //isnew = true;
            }
            else
            {
                ldoc = _lDocDict[item];
            }
            int ldocid = Children.IndexOf(ldoc);

            SelectedItem         = item;
            SelectedContentIndex = ldocid;
        }
 private void OnTabFloatClosed(object sender, RoutedEventArgs e)
 {
     if (sender is MainTabDiagramItem)
     {
         MainTabDiagramItem mtditem = (MainTabDiagramItem)sender;
         mtditem.IsFloat = false;
         //mtditem.FloatClosed -= OnTabFloatClosed;
         DiagramCollection.Remove(mtditem);
         TabItemCollection.Remove(mtditem.LDVM_ladder);
         _lDocDict.Remove(mtditem.LDVM_ladder);
     }
     else
     {
         ITabItem titem = (ITabItem)sender;
         titem.IsFloat = false;
         //titem.FloatClosed -= OnTabFloatClosed;
         TabItemCollection.Remove(titem);
         _lDocDict.Remove(titem);
     }
     FloatingWinClosed(this, null);
 }
        /// <summary>
        /// 查找指令
        /// </summary>
        private void Find()
        {
            items.Clear();
            // 输入信息非法则不执行
            if (RF_Input.Type == ReplaceFormat.TYPE_INVALID)
            {
                return;
            }
            switch (Mode)
            {
            // 查找当前程序
            case MODE_CURRENT:
                ITabItem currenttab = parent.MainTabControl.SelectedItem;
                if (currenttab is MainTabDiagramItem)
                {
                    MainTabDiagramItem     mtditem  = (MainTabDiagramItem)currenttab;
                    LadderDiagramViewModel ldvmodel = mtditem.LDVM_ladder;
                    Find(ldvmodel);
                }
                if (currenttab is LadderDiagramViewModel)
                {
                    Find((LadderDiagramViewModel)currenttab);
                }
                break;

            // 查找所有程序
            case MODE_ALL:
                ProjectModel pmodel = parent.ProjectModel;
                Find(pmodel.MainRoutine);
                foreach (LadderDiagramViewModel _ldvmodel in pmodel.SubRoutines)
                {
                    Find(_ldvmodel);
                }
                break;
            }
            PropertyChanged(this, new PropertyChangedEventArgs("Items"));
        }