/// <summary> /// Closes the spesific tab window and send tabs back into correct places. /// </summary> /// <param name="sender">TabWindow object.</param> /// <param name="e">Event</param> private void CloseWindow(Object sender, CancelEventArgs e) { // Try catch to make sure that the program won't break. try { TabWindow tab = (TabWindow)sender; if (tab.TabablzControl.Items.Count != 0) { // Items have to be moved in to separate collection to remove references to parents. ObservableCollection <MetroTabItem> items = new ObservableCollection <MetroTabItem>(); foreach (MetroTabItem item in tab.TabablzControl.Items) { items.Add(item); } foreach (MetroTabItem item in items) { var parent = (TabablzControl)item.Parent; if (parent != null) { parent.RemoveFromSource(item); } TControl.RemoveFromSource(item); TControl.AddToSource(item); } } // Select one of the tabs; MetroTabItem metroItem = (MetroTabItem)TControl.Items.GetItemAt(0); metroItem.IsSelected = true; } catch { } }
public static void Open(TabWindow window) { if (openWindow != window) { openWindow = window; openWindow.PreActive(); } }
/// <summary> /// Implementation of InterTabClient. /// To open dragged tabs in a different window class than they originated from. /// </summary> /// <param name="interTabClient">InterTabClient</param> /// <param name="partition">Partition</param> /// <param name="source">Source</param> /// <returns>Tab host.</returns> public INewTabHost <Window> GetNewHost(IInterTabClient interTabClient, object partition, TabablzControl source) { TabWindow view = new TabWindow(); view.Owner = App.Current.MainWindow; TControl = source; view.Closing += new CancelEventHandler(CloseWindow); return(new NewTabHost <Window>(view, view.TabablzControl)); //TabablzControl is a names control in the XAML. }
private static string convertToArgument ( TabWindow tabWindow ) { switch ( tabWindow ) { case TabWindow.Source: return "/L"; case TabWindow.Destination: return "/R"; } return string.Empty; }
public void AddTab(TabWindow tab) { var token = tab.Vm.Token; Debug.Assert(!_tabWindows.ContainsKey(token)); Debug.Assert(!string.IsNullOrEmpty(token)); _tabWindows.Add(token, tab); tab.Activated += (sender, args) => _lastTabToken = tab.Vm.Token; }
public static void Open ( string totalCommanderDirectory, string tabPath, TabWindow tabWindow, TabCreation tabCreation ) { string tabWindowArg = convertToArgument( tabWindow ); string newTabArg = convertToArgument( tabCreation ); string paramters = String.Format( "/O {0} /S {1}=\"{2}\"", newTabArg, tabWindowArg, tabPath ); var process = new Process(); process.StartInfo.FileName = Path.Combine( totalCommanderDirectory, "TOTALCMD.EXE" ); process.StartInfo.Arguments = paramters; process.Start(); }
public void Connect(TabWindow window) { if (wnd != null) { return; } wnd = window; SetTitle(window.Title); //Register events, if necessary }
public Tuple <AdvancedTabControl, Window> CreateHost(AdvancedTabControl rpSourceTabControl, string rpSourcePartition) { var rWindow = new TabWindow() { Owner = App.Current.MainWindow }; rWindow.TabControl.DataContext = rpSourceTabControl.DataContext; rWindow.TabControl.TabController = rpSourceTabControl.TabController; rWindow.DockableZone.DockingController = new TabDockingController(); return(Tuple.Create(rWindow.TabControl, (Window)rWindow)); }
public static void Open(TabWindow window, bool clearForward = false) { if (openWindow != window) { if (openWindow != null) { TabWindow cur = openWindow; backStack.Push(delegate() { openWindow = cur; openWindow.PreActive(); }); curCommand = delegate() { openWindow = window; openWindow.PreActive(); }; } if (clearForward) { forwardStack.Clear(); } if (window is ResearchWindow) { if (!ResearchWindow.initialized) { Find.WindowStack.TryRemove(instance); LongEventHandler.QueueLongEvent(DRimEditor.Research.Tree.Initialize, "DRimEditor.Research.BuildingResearchTree", false, null); LongEventHandler.QueueLongEvent(() => openWindow = researchWindow, "", false, null); return; } } if (window is DefExplorerWindow) { if (!DefExplorerWindow.initialized) { Find.WindowStack.TryRemove(instance); LongEventHandler.QueueLongEvent(DefDatabaseBuilder.ResolveImpliedDefs, "BuildingRimEditDatabase", false, null); LongEventHandler.QueueLongEvent(() => openWindow = defExplorerWindow, "", false, null); return; } } openWindow = window; openWindow.PreActive(); } }
private void SwitchWindow(string windowId) { if (!string.IsNullOrEmpty(windowId) && _tabWindows.Any(tw => tw.WindowId == windowId)) { if (_currentTabButton != null) { _currentTabButton.SetCurrent(false); } _currentTabButton = _tabButtons.First(tb => tb.TabId == windowId).Button; _currentTabButton.SetCurrent(true); if (_currentTabWindow != null) { _currentTabWindow.Hide(); } _currentTabWindow = _tabWindows.First(tw => tw.WindowId == windowId); _currentTabWindow.Show(); } }
public override void PreOpen() { base.PreOpen(); closeOnClickedOutside = false; SetRects(); if (!initialized) { researchWindow = new ResearchWindow(); defExplorerWindow = new DefExplorerWindow(); openWindow = profileManagerWindow; backTex = ContentFinder <Texture2D> .Get("Buttons/rimEditBack"); backTexGrey = ContentFinder <Texture2D> .Get("Buttons/rimEditBackGrey"); forwardTex = ContentFinder <Texture2D> .Get("Buttons/rimEditForward"); forwardTexGrey = ContentFinder <Texture2D> .Get("Buttons/rimEditForwardGrey"); initialized = true; } }
public DemoSelectorWindowViewModel(ArticleService articleService, CategoryService categoryService) { OpenBindingsViewCommand = new DelegateCommand(() => { var bindingsWindow = new BindingsWindow { DataContext = new BindingsWindowViewModel() }; bindingsWindow.Show(); }); OpenTabViewCommand = new DelegateCommand(() => { var tabWindow = new TabWindow(); tabWindow.Show(); }); OpenArticleListViewCommand = new DelegateCommand(() => { var articleListWindow = new ArticleListWindow { DataContext = new ArticleListWindowViewModel(articleService, categoryService) }; articleListWindow.Show(); }); }
public void ShowRemoteHost(uint serverId) { Debug.Assert(serverId > 0); Debug.Assert(GlobalData.Instance.ServerList.Any(x => x.Id == serverId)); var server = GlobalData.Instance.ServerList.First(x => x.Id == serverId); // update last conn time server.LastConnTime = DateTime.Now; Server.AddOrUpdate(server); // is connected now! activate it then return. if (server.OnlyOneInstance && _protocolHosts.ContainsKey(serverId.ToString())) { if (_protocolHosts[serverId.ToString()].ParentWindow is TabWindow t) { var s = t.Vm?.Items?.First(x => x.Content?.ProtocolServer?.Id == serverId); if (s != null) { t.Vm.SelectedItem = s; } t.Activate(); } return; } // create new remote session TabWindow tab = null; try { if (server.IsConnWithFullScreen()) { // for those people using 2+ monitors in different scale factors, we will try "mstsc.exe" instead of "PRemoteM". if (Screen.AllScreens.Length > 1 && server is ProtocolServerRDP rdp && rdp.RdpFullScreenFlag == ERdpFullScreenFlag.EnableFullAllScreens) { int factor = (int)(new ScreenInfoEx(Screen.PrimaryScreen).ScaleFactor * 100); // check if screens are in different scale factors bool differentScaleFactorFlag = Screen.AllScreens.Select(screen => (int)(new ScreenInfoEx(screen).ScaleFactor * 100)).Any(factor2 => factor != factor2); if (differentScaleFactorFlag || true) { var tmp = Path.GetTempPath(); var rdpFileName = $"{rdp.DispName}_{rdp.Port}_{rdp.UserName}"; var invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); rdpFileName = invalid.Aggregate(rdpFileName, (current, c) => current.Replace(c.ToString(), "")); var rdpFile = Path.Combine(tmp, rdpFileName + ".rdp"); try { File.WriteAllText(rdpFile, rdp.ToRdpConfig().ToString()); var p = new Process { StartInfo = { FileName = "cmd.exe", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; p.Start(); p.StandardInput.WriteLine("mstsc -admin \"" + rdpFile + "\""); p.StandardInput.WriteLine("exit"); } finally { // delete tmp rdp file, ETA 10s var t = new Task(() => { Thread.Sleep(1000 * 10); if (File.Exists(rdpFile)) { File.Delete(rdpFile); } }); t.Start(); } return; } } var host = ProtocolHostFactory.Get(server); host.OnClosed += OnProtocolClose; host.OnFullScreen2Window += OnFullScreen2Window; AddProtocolHost(host); MoveProtocolHostToFullScreen(host.ConnectionId); host.Conn(); SimpleLogHelper.Debug($@"Start Conn: {server.DispName}({server.GetHashCode()}) by host({host.GetHashCode()}) with full"); } else { switch (SystemConfig.Instance.General.TabMode) { case EnumTabMode.NewItemGoesToGroup: // work in tab by group mode if (_tabWindows.Any(x => x.Value.Vm.Tag == server.GroupName)) { tab = _tabWindows.First(x => x.Value.Vm.Tag == server.GroupName).Value; } break; case EnumTabMode.NewItemGoesToProtocol: // work in tab by protocol mode if (_tabWindows.Any(x => x.Value.Vm.Tag == server.ProtocolDisplayName)) { tab = _tabWindows.First(x => x.Value.Vm.Tag == server.ProtocolDisplayName).Value; } break; default: // work in tab by latest tab mode if (!string.IsNullOrEmpty(_lastTabToken) && _tabWindows.ContainsKey(_lastTabToken)) { tab = _tabWindows[_lastTabToken]; } break; } if (tab == null) { var token = DateTime.Now.Ticks.ToString(); AddTab(new TabWindow(token)); tab = _tabWindows[token]; tab.Show(); _lastTabToken = token; if (SystemConfig.Instance.General.TabMode == EnumTabMode.NewItemGoesToGroup) { tab.Vm.Tag = server.GroupName; } else if (SystemConfig.Instance.General.TabMode == EnumTabMode.NewItemGoesToProtocol) { tab.Vm.Tag = server.ProtocolDisplayName; } } tab.Activate(); var size = tab.GetTabContentSize(); var host = ProtocolHostFactory.Get(server, size.Width, size.Height); host.OnClosed += OnProtocolClose; host.OnFullScreen2Window += OnFullScreen2Window; host.ParentWindow = tab; tab.Vm.Items.Add(new TabItemViewModel() { Content = host, Header = server.DispName, }); tab.Vm.SelectedItem = tab.Vm.Items.Last(); host.Conn(); _protocolHosts.Add(host.ConnectionId, host); SimpleLogHelper.Debug($@"Start Conn: {server.DispName}({server.GetHashCode()}) by host({host.GetHashCode()}) with Tab({tab.GetHashCode()})"); SimpleLogHelper.Debug($@"ProtocolHosts.Count = {_protocolHosts.Count}, FullWin.Count = {_host2FullScreenWindows.Count}, _tabWindows.Count = {_tabWindows.Count}"); } } catch (Exception e) { CloseEmpytTab(); SimpleLogHelper.Error(e); MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void MoveProtocolHostToFullScreen(string connectionId) { if (_protocolHosts.ContainsKey(connectionId)) { var host = _protocolHosts[connectionId]; // remove from old parent TabWindow tab = null; { var tabs = _tabWindows.Values.Where(x => x.Vm.Items.Any(y => y.Content == host)).ToArray(); if (tabs.Length > 0) { tab = tabs.First(); foreach (var t in tabs) { var items = t.Vm.Items.ToArray().Where(x => x.Content == host); foreach (var item in items.ToArray()) { t.Vm.Items.Remove(item); if (t.Vm.Items.Count > 0) { t.Vm.SelectedItem = tab.Vm.Items.First(); } SimpleLogHelper.Debug($@"Remove host({host.GetHashCode()}) from tab({t.GetHashCode()})"); } } } } FullScreenWindow full; if (_host2FullScreenWindows.ContainsKey(connectionId)) { full = _host2FullScreenWindows[connectionId]; full.LastTabToken = ""; // full screen placement if (tab != null) { var screenEx = ScreenInfoEx.GetCurrentScreen(tab); full.Top = screenEx.VirtualWorkingAreaCenter.Y - full.Height / 2; full.Left = screenEx.VirtualWorkingAreaCenter.X - full.Width / 2; full.LastTabToken = _lastTabToken; } full.Show(); full.SetProtocolHost(host); host.ParentWindow = full; host.GoFullScreen(); } else { // move to full full = new FullScreenWindow { LastTabToken = "" }; // full screen placement ScreenInfoEx screenEx; if (tab != null) { screenEx = ScreenInfoEx.GetCurrentScreen(tab); full.LastTabToken = _lastTabToken; } else if (host.ProtocolServer is ProtocolServerRDP rdp && rdp.RdpFullScreenFlag == ERdpFullScreenFlag.EnableFullScreen && rdp.AutoSetting.FullScreenLastSessionScreenIndex >= 0 && rdp.AutoSetting.FullScreenLastSessionScreenIndex < Screen.AllScreens.Length) { screenEx = ScreenInfoEx.GetCurrentScreen(rdp.AutoSetting.FullScreenLastSessionScreenIndex); } else { screenEx = ScreenInfoEx.GetCurrentScreen(App.Window); } full.WindowStartupLocation = WindowStartupLocation.Manual; full.Top = screenEx.VirtualWorkingAreaCenter.Y - full.Height / 2; full.Left = screenEx.VirtualWorkingAreaCenter.X - full.Width / 2; full.SetProtocolHost(host); host.ParentWindow = full; full.Loaded += (sender, args) => { host.GoFullScreen(); }; full.Show(); AddFull(full); }
public INewTabHost <Window> GetNewHost(IInterTabClient interTabClient, object partition, TabablzControl source) { var view = new TabWindow(); return(new NewTabHost <TabWindow>(view, view.TabsContainer)); }
public void ShowRemoteHost(uint id) { Debug.Assert(id > 0); Debug.Assert(GlobalData.Instance.ServerList.Any(x => x.Id == id)); var server = GlobalData.Instance.ServerList.First(x => x.Id == id); // update last conn time server.LastConnTime = DateTime.Now; Server.AddOrUpdate(server); // start conn if (server.OnlyOneInstance && _protocolHosts.ContainsKey(id.ToString())) { _protocolHosts[id.ToString()].ParentWindow?.Activate(); return; } TabWindow tab = null; try { if (server.IsConnWithFullScreen()) { // for those people using 2+ monitor which are in different scale factors, we will try "mstsc.exe" instead of "PRemoteM". if (Screen.AllScreens.Length > 1 && server is ProtocolServerRDP rdp && rdp.RdpFullScreenFlag == ERdpFullScreenFlag.EnableFullAllScreens) { int factor = (int)(new ScreenInfoEx(Screen.PrimaryScreen).ScaleFactor * 100); // check if screens are in different scale factors bool differentScaleFactorFlag = Screen.AllScreens.Select(screen => (int)(new ScreenInfoEx(screen).ScaleFactor * 100)).Any(factor2 => factor != factor2); if (differentScaleFactorFlag) { var tmp = Path.GetTempPath(); var dp = rdp.DispName; var invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); dp = invalid.Aggregate(dp, (current, c) => current.Replace(c.ToString(), "")); var rdpFile = Path.Combine(tmp, dp + ".rdp"); try { File.WriteAllText(rdpFile, rdp.ToRdpConfig().ToString()); var p = new Process { StartInfo = { FileName = "cmd.exe", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; p.Start(); p.StandardInput.WriteLine("mstsc -admin " + rdpFile); p.StandardInput.WriteLine("exit"); } catch (Exception) { throw; } finally { var t = new Task(() => { Thread.Sleep(1000 * 10); if (File.Exists(rdpFile)) { File.Delete(rdpFile); } }); t.Start(); } return; } } var host = ProtocolHostFactory.Get(server); host.OnClosed += OnProtocolClose; host.OnFullScreen2Window += OnFullScreen2Window; AddProtocolHost(host); MoveProtocolHostToFullScreen(host.ConnectionId); host.Conn(); SimpleLogHelper.Debug($@"Start Conn: {server.DispName}({server.GetHashCode()}) by host({host.GetHashCode()}) with full"); } else { if (!string.IsNullOrEmpty(_lastTabToken) && _tabWindows.ContainsKey(_lastTabToken)) { tab = _tabWindows[_lastTabToken]; } else { var token = DateTime.Now.Ticks.ToString(); AddTab(new TabWindow(token)); tab = _tabWindows[token]; tab.Show(); _lastTabToken = token; } tab.Activate(); var size = tab.GetTabContentSize(); var host = ProtocolHostFactory.Get(server, size.Width, size.Height); host.OnClosed += OnProtocolClose; host.OnFullScreen2Window += OnFullScreen2Window; host.ParentWindow = tab; tab.Vm.Items.Add(new TabItemViewModel() { Content = host, Header = server.DispName, }); tab.Vm.SelectedItem = tab.Vm.Items.Last(); host.Conn(); _protocolHosts.Add(host.ConnectionId, host); SimpleLogHelper.Debug($@"Start Conn: {server.DispName}({server.GetHashCode()}) by host({host.GetHashCode()}) with Tab({tab.GetHashCode()})"); SimpleLogHelper.Debug($@"ProtocolHosts.Count = {_protocolHosts.Count}, FullWin.Count = {_host2FullScreenWindows.Count}, _tabWindows.Count = {_tabWindows.Count}"); } } catch (Exception e) { if (tab?.Vm != null && (tab.Vm?.Items?.Count ?? 0) == 0) { CloseTabWindow(tab.Vm.Token); } SimpleLogHelper.Error(e); MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }