Exemplo n.º 1
0
        /// <summary>
        /// Apply the base configuration for all <see cref="TabItem"/> <see langword="objects"/> in the <see cref="TabCollection"/>
        /// </summary>
        /// <param name="_tab">The tab to configure</param>
        /// <param name="_showContent">Whether or not to show the tab after configuration</param>
        private void ConfigurateTab(TabItem _tab, bool _showContent)
        {
            #region On Click Behaviour
            _tab.OnClick = (o, e) =>
            {
                ITabItem other = FindTab(item => item.IsVisible == true);
                if (other != null)
                {
                    MinimizeTab(other);
                }

                OpenTab(_tab);
            };
            #endregion

            #region On Close Behaviour
            _tab.OnCloseClick = (o, e) =>
            {
                CloseTab(_tab);
            };
            #endregion

            Tabs.Add(_tab);

            _tab.Construct(tabDisplay, contentArea);

            if (_showContent)
            {
                MinimizeTab(FindTab(item => item.IsVisible == true && item.ID != _tab.ID));
            }
        }
Exemplo n.º 2
0
 protected override void RemoveContent(ITabItem tab, View content, int index)
 {
     if (Content == _contentContainer.Content)
     {
         _contentContainer.Content = null;
     }
 }
Exemplo n.º 3
0
        private View GetOrCreateConent(ITabItem tab)
        {
            if (!(Tabs?.Any() == true && ContentTemplate != null))
            {
                return(null);
            }
            View element = null;

            if (!(_tabViews.TryGetValue(tab, out element)))
            {
                var selector = ContentTemplate as DataTemplateSelector;
                if (selector != null)
                {
                    var template = selector.SelectTemplate(tab, this);
                    element = template?.CreateContent() as View;
                }
                else
                {
                    element = (View)ContentTemplate.CreateContent();
                }
                if (element == null)
                {
                    throw new InvalidOperationException(
                              "Could not instantiate content. Please make sure that your ContentTemplate is configured correctly.");
                }
                _tabViews[tab]         = element;
                element.BindingContext = tab;
            }
            return(element);
        }
Exemplo n.º 4
0
        protected override void InsertTitle(ITabItem tab, int index)
        {
            var title = CreateTitle(tab);

            _titleContainer.Children.Insert(index, title);
            UpdateTabLayout(CurrentTab);
        }
Exemplo n.º 5
0
        private ViewButton CreateTitle(ITabItem tabItem)
        {
            View title    = null;
            var  selector = TitleTemplate as DataTemplateSelector;

            if (selector != null)
            {
                var template = selector.SelectTemplate(tabItem, this);
                title = template?.CreateContent() as View;
            }
            else
            {
                title = (View)TitleTemplate.CreateContent();
            }
            if (title == null)
            {
                throw new InvalidOperationException(
                          "Could not instantiate title. Please make sure that your TitleTemplate is configured correctly.");
            }

            title.BindingContext = tabItem;
            var button = new ViewButton()
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            button.Content  = title;
            button.Clicked += ViewButtonOnClicked;
            return(button);
        }
Exemplo n.º 6
0
 public TabItemView Item(ITabItem item)
 {
     this.item = item;
     text.Text(item.TabName);
     UpdateTabState();
     return(this);
 }
Exemplo n.º 7
0
        public void Find(string word = null)
        {
            if (word != null)
            {
                TB_Input.Text = word;
            }
            Initialize(false);
            if (TB_Input.Text.Length <= 0)
            {
                return;
            }
            switch (Mode)
            {
            case MODE_CURRENT:
                ITabItem currenttab = parent.MainTabControl.SelectedItem;
                if (currenttab is FuncBlockViewModel)
                {
                    FuncBlockViewModel fbvmodel = (FuncBlockViewModel)currenttab;
                    Find(fbvmodel);
                }
                break;

            case MODE_ALL:
                ProjectModel pmodel = parent.ProjectModel;
                Find(pmodel.LibFuncBlock);
                foreach (FuncBlockViewModel fbvmodel in pmodel.FuncBlocks)
                {
                    Find(fbvmodel);
                }
                break;
            }
            PropertyChanged(this, new PropertyChangedEventArgs("Items"));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 查找
        /// </summary>
        private void Find()
        {
            Initialize();
            if (TB_Input.Text.Length <= 0)
            {
                return;
            }
            switch (Mode)
            {
            // 当前文本
            case MODE_CURRENT:
                ITabItem currenttab = parent.MainTabControl.SelectedItem;
                if (currenttab is FuncBlockViewModel)
                {
                    FuncBlockViewModel fbvmodel = (FuncBlockViewModel)currenttab;
                    Find(fbvmodel);
                }
                break;

            // 所有文本
            case MODE_ALL:
                ProjectModel pmodel = parent.ProjectModel;
                Find(pmodel.LibFuncBlock);
                foreach (FuncBlockViewModel fbvmodel in pmodel.FuncBlocks)
                {
                    Find(fbvmodel);
                }
                break;
            }
            PropertyChanged(this, new PropertyChangedEventArgs("Items"));
        }
Exemplo n.º 9
0
        public async Task <ITabHandler> add(string title, string position = LocalConstant.TabPositionBottom)
        {
            if (this._addonInfomation is null)
            {
                throw new InvalidOperationException("Not Initialized!");
            }

            var     tabInfo = DIFactory.Provider.GetRequiredService <ITabInfomation>();
            TabType type    = position switch
            {
                LocalConstant.TabPositionTop => TabType.Top,
                _ => TabType.Bottom
            };

            tabInfo.Initialize(this._addonInfomation, title, type);

            ITabItem item    = this._container.AddTab(tabInfo);
            var      handler = new TabHandler(item);

            await item.WaitUntilInitialize();

            if (this._addonInfomation.HasPermission(PermissionNames.Resource))
            {
                var path = Path.Combine(AppContext.BaseDirectory, FileFolder.AddonsFolder, this._addonInfomation.PackageID.Value, AddonConstant.ResourceDirectoryName);
                if (Directory.Exists(path))
                {
                    item.SetVirtualHostName(AddonConstant.ResourceHost, path);
                }
            }

            return(handler);
        }

        #endregion
    }
Exemplo n.º 10
0
 private void SaveCommand(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
 {
     if (MainTabControl.Items.Count == 0)
     {
         MessageBox.Show("No tab opened.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     else
     {
         ITabItem current = (ITabItem)MainTabControl.SelectedContent;
         string   text    = current.GetPlainText();
         Console.WriteLine(text);
         SaveFileDialog saveDialog = new SaveFileDialog();
         saveDialog.Filter   = "Encrypted File (*.*)|*.*|Plain File (*.*)|*.*";
         saveDialog.Title    = "Save As";
         saveDialog.FileName = ((TabItem)MainTabControl.Items[MainTabControl.SelectedIndex]).Header as string;
         if (saveDialog.ShowDialog() == true)
         {
             try
             {
                 if (saveDialog.FilterIndex == 1)
                 {
                     Crypt.EncryptToFile(saveDialog.FileName, text, FDF1Checkbox.IsChecked, GetSelectedKeyIndex());
                 }
                 else
                 {
                     File.WriteAllText(saveDialog.FileName, text);
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Something went wrong.\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
             }
         }
     }
 }
Exemplo n.º 11
0
 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());
     }
 }
        /// <summary>
        /// Called when the implementer has been navigated to.
        /// </summary>
        /// <param name="navigationContext">The navigation context.</param>
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            if (navigationContext != null && navigationContext.Parameters.Any(p => p.Key.EqualsIgnoreCase("TabIndex")))
            {
                var tabIndex = navigationContext.Parameters["TabIndex"];
                ActiveTabItemIndex = !string.IsNullOrEmpty(tabIndex) ? int.Parse(tabIndex) : 0;
            }
            else
            {
                ActiveTabItemIndex = 0;
            }

            ITabItem tab = TabItems[ActiveTabItemIndex];

            if (tab != null)
            {
                if (!tab.IsActive)
                {
                    tab.IsActive = true;
                }
                else
                {
                    tab.OnIsActive();
                }
            }

            if (ActiveTabItemIndex == 0)
            {
                EventAggregator.GetEvent <SetContextualHelpContextEvent>().Publish("MANAGING YOUR DATASETS LIBRARY");
            }
        }
Exemplo n.º 13
0
 private void InsertTab(ITabItem tab, int index)
 {
     InsertTitle(tab, index);
     if (tab.IsSelected)
     {
         CurrentTab = Tabs?.FirstOrDefault();
     }
 }
Exemplo n.º 14
0
 private void SelectTab(ITabItem tab)
 {
     if (tab != null)
     {
         SelectTitle(tab);
         SelectContent(tab);
     }
 }
Exemplo n.º 15
0
 public void RenameItem(ITabItem item)
 {
     if (_lDocDict.ContainsKey(item))
     {
         LayoutDocument ldoc = _lDocDict[item];
         ldoc.Title = item.TabHeader;
     }
 }
Exemplo n.º 16
0
 protected override void RemoveTitle(ITabItem tab, int index)
 {
     if (index >= 0)
     {
         _titleContainer.Children.RemoveAt(index);
     }
     UpdateTabLayout(CurrentTab);
 }
Exemplo n.º 17
0
        public void OpenTab(string header, ITabItem content)
        {
            TabItem tab = new TabItem();

            tab.Header  = header;
            tab.Content = content;
            MainTabControl.Items.Add(tab);
            MainTabControl.SelectedIndex = MainTabControl.Items.IndexOf(tab);
        }
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
0
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        /// <param name="_tab">The tab to open</param>
        /// <returns><inheritdoc/></returns>
        public override bool OpenTab(ITabItem _tab)
        {
            if (_tab != null)
            {
                _tab.Show();
                return(true);
            }

            return(false);
        }
Exemplo n.º 20
0
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        /// <param name="_tab">The tab to minimize</param>
        /// <returns><see langword="True"/> if the tab could be minimized; Otherwise, if not, <see langword="false"/></returns>
        public override bool MinimizeTab(ITabItem _tab)
        {
            if (_tab != null)
            {
                _tab.Show(false);
                return(true);
            }

            return(false);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Determines whether the specified <see cref="iFactr.UI.ITabItem"/> is equal to this instance.
        /// </summary>
        /// <param name="other">The <see cref="iFactr.UI.ITabItem"/> to compare with this instance.</param>
        /// <returns><c>true</c> if the specified <see cref="iFactr.UI.ITabItem"/> is equal to this instance;
        /// otherwise, <c>false</c>.</returns>
        public bool Equals(ITabItem other)
        {
            TabItem item = other as TabItem;

            if (item != null)
            {
                return(Pair == item.Pair);
            }

            return(Pair == other);
        }
Exemplo n.º 22
0
        public bool Equals(ITabItem other)
        {
            var item = other as iFactr.UI.TabItem;

            if (item != null)
            {
                return(item.Equals(this));
            }

            return(base.Equals(other));
        }
Exemplo n.º 23
0
        public async void ReopenClosedTab(object sender, RoutedEventArgs e)
        {
            if (!isRestoringClosedTab && RecentlyClosedTabs.Any())
            {
                isRestoringClosedTab = true;
                ITabItem lastTab = RecentlyClosedTabs.Last();
                RecentlyClosedTabs.Remove(lastTab);
                await MainPageViewModel.AddNewTabByParam(lastTab.TabItemArguments.InitialPageType, lastTab.TabItemArguments.NavigationArg);

                isRestoringClosedTab = false;
            }
        }
Exemplo n.º 24
0
 private void OnActiveChanged(object sender, EventArgs e)
 {
     if (sender is LayoutDocument)
     {
         LayoutDocument ldoc = (LayoutDocument)(sender);
         if (ldoc.Content != SelectedItem)
         {
             ITabItem _SelectedItem = SelectedItem;
             SelectedItem = (ITabItem)(ldoc.Content);
         }
     }
 }
Exemplo n.º 25
0
        public void AddTabItem(ITabItem tabItem)
        {
            if (!TabItems.Any(item => item.Id == tabItem.Id))
            {
                InvokeAsync(() =>
                {
                    this.TabItems.Add(tabItem);
                    this.TabEvents.Add(AddedEvent);

                    StateHasChanged();
                });
            }
        }
Exemplo n.º 26
0
 protected override void OnChildrenCollectionChanged()
 {
     base.OnChildrenCollectionChanged();
     foreach (ITabItem tab in TabItemCollection)
     {
         if (tab.IsFloat)
         {
             continue;
         }
         if (!_lDocDict.ContainsKey(tab))
         {
             continue;
         }
         LayoutDocument ldoc = _lDocDict[tab];
         if (!Children.Contains(ldoc))
         {
             CloseItem(tab);
             return;
         }
     }
     foreach (var child in Children)
     {
         ITabItem tab = null;
         if (child.Content is MainTabDiagramItem)
         {
             tab = ((MainTabDiagramItem)(child.Content)).LDVM_ladder;
         }
         else if (child.Content is ITabItem)
         {
             tab = (ITabItem)(child.Content);
         }
         if (tab != null && !TabItemCollection.Contains(tab))
         {
             TabItemCollection.Add(tab);
             _lDocDict.Add(tab, (LayoutDocument)child);
         }
         if (child.IconSource == null && child.Content is MainTabDiagramItem)
         {
             child.ImageSource = IconManager.RoutineImage;
         }
         else if (child.IconSource == null && child.Content is FuncBlockViewModel)
         {
             child.ImageSource = IconManager.FuncImage;
         }
         else if (child.IconSource == null && child.Content is ModbusTableViewModel)
         {
             child.ImageSource = IconManager.ModbusImage;
         }
     }
 }
Exemplo n.º 27
0
        private void RemoveTab(ITabItem tab, int index)
        {
            RemoveTitle(tab, index);
            View content = null;

            if (_tabViews.TryGetValue(tab, out content))
            {
                RemoveContent(tab, content, index);
                _tabViews.Remove(tab);
            }
            if (tab.IsSelected)
            {
                CurrentTab = Tabs?.FirstOrDefault();
            }
        }
Exemplo n.º 28
0
        private void OnCurrentTabChanged(object sender, SelectionChangedEventArgs e)
        {
            ITabItem currenttab = parent.MainTabControl.SelectedItem;

            if (currenttab is FuncBlockViewModel)
            {
                Visibility = Visibility.Visible;
                if (Mode == MODE_CURRENT)
                {
                    Find();
                }
            }
            else
            {
                Visibility = Visibility.Hidden;
            }
        }
Exemplo n.º 29
0
        public void SetLoadingIndicatorStatus(ITabItem item, bool loading)
        {
            var tabItem = ContainerFromItem(item) as Control;

            if (tabItem is null)
            {
                return;
            }

            if (loading)
            {
                VisualStateManager.GoToState(tabItem, "Loading", false);
            }
            else
            {
                VisualStateManager.GoToState(tabItem, "NotLoading", false);
            }
        }
Exemplo n.º 30
0
        public Controls.ITabItem CreateTabItem(string filename, IHighlightsHelper hightlightsHelper)
        {
            IRequest req = Kernel.CreateRequest(typeof(ITabItem), null, new IParameter[] { new Parameter("filename", filename, false), new Parameter("hightlightsHelper", hightlightsHelper, false) }, false, false);

            if (!Kernel.CanResolve(req))
            {
                Kernel.Bind <ITabItem>()
                .To <FileWatcherTabItem>()
                .WithConstructorArgument("filename", filename)
                .WithConstructorArgument("hightlightsHelper", hightlightsHelper);
            }

            ITabItem tab = Kernel.Get <ITabItem>();

            Kernel.Unbind <ITabItem>();

            return(tab);
        }
 /// <summary>
 /// Removes the tab from the current collection.
 /// </summary>
 /// <param name="tab">The tab.</param>
 public void RemoveTab(ITabItem tab)
 {
     Tabs.Remove(tab);
 }