Exemplo n.º 1
0
        /// <summary>
        /// Phone模式附加标题右键菜单
        /// </summary>
        /// <param name="p_elem">标题元素</param>
        /// <param name="p_win">所属窗口</param>
        public static void OnPhoneTitleTapped(FrameworkElement p_elem, Win p_win)
        {
            if (p_elem == null || p_win == null)
            {
                return;
            }

            p_elem.RightTapped += (s, e) =>
            {
                if (_menu == null)
                {
                    _menu = new Menu {
                        IsContextMenu = true, Placement = MenuPosition.BottomLeft
                    };
                    var item = new Mi {
                        ID = "取消自启动"
                    };
                    item.Click += (o, a) => Startup.DelAutoStart();
                    _menu.Items.Add(item);

                    item = new Mi {
                        ID = "设置自启动"
                    };
                    item.Click += SetAutoStart;
                    _menu.Items.Add(item);

                    item = new Mi {
                        ID = "系统监视"
                    };
                    item.Click += (o, a) => SysTrace.ShowBox();
                    _menu.Items.Add(item);
                }

                var autoStart = AtState.GetAutoStart();
                if (autoStart != null &&
                    autoStart.WinType == p_win.GetType().AssemblyQualifiedName &&
                    (p_win.Params == null || autoStart.Params == JsonSerializer.Serialize(p_win.Params, JsonOptions.UnsafeSerializer)))
                {
                    _menu.Items[0].Visibility = Visibility.Visible;
                    _menu.Items[1].Visibility = Visibility.Collapsed;
                }
                else
                {
                    _menu.Items[0].Visibility = Visibility.Collapsed;
                    _menu.Items[1].Visibility = Visibility.Visible;
                    _currentWin = p_win;
                }
                _ = _menu.OpenContextMenu(default, p_elem);
Exemplo n.º 2
0
        /// <summary>
        /// 关闭窗口并从缓存中移除,激活下一窗口
        /// </summary>
        /// <param name="p_win">窗口</param>
        internal async Task <bool> CloseWin(Win p_win)
        {
            int index = Items.IndexOf(p_win);

            if (index < 0)
            {
                return(false);
            }

            // 触发关闭前事件,外部判断是否允许关闭
            if (!await p_win.AllowClose())
            {
                return(false);
            }

            Items.RemoveAt(index);

            // 若待关闭的窗口为激活状态
            if (MainWin == p_win)
            {
                if (Items.Count > 0)
                {
                    // 激活下一窗口
                    MainWin = index < Items.Count ? Items[index] : Items[Items.Count - 1];
                }
                else
                {
                    // 无激活窗口时显示主页
                    MainWin = HomeWin;
                }
            }
            else if (LeftWin == p_win)
            {
                LeftWin = null;
            }
            else if (RightWin == p_win)
            {
                RightWin = null;
            }

            // 关闭后
            p_win.AfterClosed();
            GC.Collect();
            return(true);
        }
Exemplo n.º 3
0
        static void ShowMenu(Point p_pos)
        {
            if (_menu == null)
            {
                _menu = new Menu {
                    IsContextMenu = true
                };
                var item = new Mi {
                    ID = "取消自启动"
                };
                item.Click += (s, a) => Startup.DelAutoStart();
                _menu.Items.Add(item);
                item = new Mi {
                    ID = "设置自启动"
                };
                item.Click += SetAutoStart;
                _menu.Items.Add(item);
                item = new Mi {
                    ID = "恢复窗口默认布局"
                };
                item.Click += ResetWinLayout;
                _menu.Items.Add(item);
                item = new Mi {
                    ID = "关闭其他"
                };
                item.Click += CloseOtherWin;
                _menu.Items.Add(item);
                item = new Mi {
                    ID = "停靠在左侧"
                };
                item.Click += DockLeft;
                _menu.Items.Add(item);
                item = new Mi {
                    ID = "停靠在右侧"
                };
                item.Click += DockRight;
                _menu.Items.Add(item);
            }

            var autoStart = AtState.GetAutoStart();
            Win win       = _currentItem._win;

            if (autoStart != null &&
                win != null &&
                autoStart.WinType == win.GetType().AssemblyQualifiedName &&
                (win.Params == null || autoStart.Params == JsonSerializer.Serialize(win.Params, JsonOptions.UnsafeSerializer)))
            {
                _menu.Items[0].Visibility = Visibility.Visible;
                _menu.Items[1].Visibility = Visibility.Collapsed;
            }
            else
            {
                _menu.Items[0].Visibility = Visibility.Collapsed;
                _menu.Items[1].Visibility = Visibility.Visible;
            }

            if (win != null)
            {
                if (win.AllowResetLayout)
                {
                    _menu.Items[2].Visibility = Visibility.Visible;
                }
                else
                {
                    // 主区内容为Win
                    Tabs tabs = (Tabs)win.GetValue(Win.MainTabsProperty);
                    if (tabs != null &&
                        tabs.Items.Count > 0 &&
                        tabs.Items[0].Content is Win cw &&
                        cw.AllowResetLayout)
                    {
                        _menu.Items[2].Visibility = Visibility.Visible;
                    }
                    else
                    {
                        _menu.Items[2].Visibility = Visibility.Collapsed;
                    }
                }
Exemplo n.º 4
0
        /// <summary>
        /// 加载Windows模式桌面
        /// </summary>
        static void LoadDesktop()
        {
            Desktop desktop = new Desktop();

            // 主页
            if (_homePageType != null)
            {
                Win win = Activator.CreateInstance(_homePageType) as Win;
                if (win != null)
                {
                    if (string.IsNullOrEmpty(win.Title))
                    {
                        win.Title = "主页";
                    }
                    win.Icon        = Icons.主页;
                    desktop.HomeWin = win;
                }
            }

            // 自启动
            AutoStartInfo autoStart;

            if (!string.IsNullOrEmpty(_launchArgs))
            {
                // 带启动参数的自启动
                LaunchFreely(_launchArgs);
                _launchArgs = null;
            }
            else if ((autoStart = AtState.GetAutoStart()) != null)
            {
                // 用户设置的自启动
                bool suc  = false;
                Type type = Type.GetType(autoStart.WinType);
                if (type != null)
                {
                    try
                    {
                        Win win = null;
                        if (string.IsNullOrEmpty(autoStart.Params))
                        {
                            win = (Win)Activator.CreateInstance(type);
                        }
                        else
                        {
                            var par = JsonSerializer.Deserialize(autoStart.Params, Type.GetType(autoStart.ParamsType));
                            win = (Win)Activator.CreateInstance(type, par);
                        }

                        if (win != null)
                        {
                            win.Title = string.IsNullOrEmpty(autoStart.Title) ? "自启动" : autoStart.Title;
                            Icons icon;
                            if (Enum.TryParse(autoStart.Icon, out icon))
                            {
                                win.Icon = icon;
                            }

                            desktop.ShowNewWin(win);
                            suc = true;
                        }
                    }
                    catch { }
                }
                if (!suc)
                {
                    AtState.DelAutoStart();
                }
            }

            if (desktop.MainWin == null)
            {
                desktop.MainWin = desktop.HomeWin;
            }
            SysVisual.RootContent = desktop;
        }
Exemplo n.º 5
0
        void ChangeRightWin(Win p_oldWin, Win p_newWin)
        {
            if (_grid == null)
            {
                return;
            }

            Splitter splitter;

            if (p_oldWin != null)
            {
                _grid.Children.Remove(p_oldWin);
                splitter = (from item in _grid.Children.OfType <Splitter>()
                            where Grid.GetColumn(item) == 3
                            select item).FirstOrDefault();
                if (splitter != null)
                {
                    splitter.CloseLeft  -= OnRightCloseLeftWin;
                    splitter.CloseRight -= OnRightCloseRightWin;
                    _grid.Children.Remove(splitter);
                }
                _grid.ColumnDefinitions[3].Width = new GridLength(0d);
                _grid.ColumnDefinitions[4].Width = new GridLength(0d);
            }

            if (p_newWin != null)
            {
                // 若窗口已加载,先移除
                if (p_newWin == LeftWin)
                {
                    LeftWin = null;
                }
                else if (p_newWin == MainWin)
                {
                    MainWin = null;
                }

                Grid.SetColumn(p_newWin, 4);
                _grid.Children.Add(p_newWin);

                splitter             = new Splitter();
                splitter.CloseLeft  += OnRightCloseLeftWin;
                splitter.CloseRight += OnRightCloseRightWin;
                Grid.SetColumn(splitter, 3);
                _grid.Children.Add(splitter);

                _grid.ColumnDefinitions[3].Width = GridLength.Auto;
                double width = p_newWin.GetSplitWidth();
                if (width > 0)
                {
                    // 可通过SplitWidth附加属性自定义宽度
                    _grid.ColumnDefinitions[4].Width = new GridLength(width);
                }
                else
                {
                    if (_grid.ColumnDefinitions[0].Width.Value > 0)
                    {
                        // 左侧已停靠
                        _grid.ColumnDefinitions[0].Width = new GridLength(SysVisual.ViewWidth / 3);
                        _grid.ColumnDefinitions[4].Width = new GridLength(SysVisual.ViewWidth / 3);
                    }
                    else
                    {
                        _grid.ColumnDefinitions[4].Width = new GridLength(SysVisual.ViewWidth / 2);
                    }
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// 显示新窗口并缓存
 /// </summary>
 /// <param name="p_win">窗口</param>
 internal void ShowNewWin(Win p_win)
 {
     // 不再判断是否包含
     MainWin = p_win;
     Items.Add(p_win);
 }
Exemplo n.º 7
0
        static void OnIsActivedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Win win = (Win)d;

            win.IsActivedChanged?.Invoke(win, EventArgs.Empty);
        }
Exemplo n.º 8
0
 internal void SetWin(Win p_win)
 {
     _win = p_win;
     _win.IsActivedChanged += OnIsActivedChanged;
     ToggleSelectedState();
 }
Exemplo n.º 9
0
Arquivo: Ex.cs Projeto: Daoting/dt
 /// <summary>
 /// 设置Win停靠在两侧时的宽度
 /// </summary>
 public static void SetSplitWidth(this Win d, double value)
 {
     d.SetValue(SplitWidthProperty, value);
 }
Exemplo n.º 10
0
Arquivo: Ex.cs Projeto: Daoting/dt
 /// <summary>
 /// 获取Win停靠在两侧时的宽度
 /// </summary>
 public static double GetSplitWidth(this Win d)
 {
     return((double)d.GetValue(SplitWidthProperty));
 }