コード例 #1
0
        public async void CloseTab(HostedWindowItem hostedWindowItem)
        {
            await tabCloseSemaphore.WaitAsync();

            try
            {
                var index = tabs.IndexOf(hostedWindowItem.TabItem);
                if (index == -1)
                {
                    return;
                }

                TabClosing?.Invoke(this, new TabCloseEventArgs
                {
                    WindowHandle  = hostedWindowItem.WindowHandle,
                    RemainingTabs = tabs.Count - 1,
                });
                tabs[index].Exiting = true;
                SetTabReferenceSize(tabs.Count - 1);

                var activeIndex = ActiveTabIndex;
                if (tabs.Count > 1 && activeIndex == index)
                {
                    if (index == tabs.Count - 1)
                    {
                        ActivateTab(tabs.Count - 2);
                    }
                    else
                    {
                        ActivateTab(index + 1);
                    }
                }

                await Task.Delay(200);

                tabs.RemoveAt(index);

                TabClosed?.Invoke(this, new TabCloseEventArgs
                {
                    WindowHandle  = hostedWindowItem.WindowHandle,
                    RemainingTabs = tabs.Count,
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception in CloseTab: " + ex.ToString());
            }
            finally
            {
                tabCloseSemaphore.Release();
            }
        }
コード例 #2
0
        private async Task ContainTargetWindow(HostedWindowItem item)
        {
            var target = item.WindowHandle;

            MyHost host;

            if ((App.Current as App).TargetWindowHosts.ContainsKey(target))
            {
                host = (App.Current as App).TargetWindowHosts[target];
            }
            else
            {
                host = new MyHost(target);
                (App.Current as App).TargetWindowHosts[target] = host;
            }

            if (host.Parent == null)
            {
                WindowContainer.Child = host;
            }
            else if (host.Parent != null && host.Parent != WindowContainer)
            {
                MessageBox.Show("ContainTargetWindow failed. The host has another parent.");
                return;
            }

            // TODO: Try to make it faster on console launch. But how?
            var dpi = VisualTreeHelper.GetDpi(this);

            if (item.Dpi != dpi.PixelsPerInchX)
            {
                ConsoleFunctions.SendDpiChangedMessage(target, (int)dpi.PixelsPerInchX);
                item.Dpi = dpi.PixelsPerInchX;
            }

            await Task.Delay(10);

            int style    = Win32Functions.GetWindowLongPtr(target, Win32Functions.GWL_STYLE).ToInt32();
            int newStyle = style & ~(Win32Functions.WS_CHILD);

            Win32Functions.SetWindowLongPtr(new HandleRef(this, target), Win32Functions.GWL_STYLE, new IntPtr(newStyle));

            await Task.Delay(10);

            MaximizeWindow(target, Win32.Enums.ShowWindowCommands.Normal);
            Win32Functions.SetForegroundWindow(target);
        }
コード例 #3
0
        private async void AttachToWindow(HostedWindowItem item)
        {
            try
            {
                await ContainTargetWindow(item);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                TabsContainer.CloseTab(item);
            }

            try
            {
                if (Properties.Settings.Default.TransparentTerminalEnabled)
                {
                    SetWindowOpacity(item.WindowHandle, Properties.Settings.Default.TerminalTransparencyAmount);
                }
            }
            catch { }
        }
コード例 #4
0
        private async Task CreateTabForWindow(IntPtr handle, string title)
        {
            await Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, (Action)(() =>
            {
                var windowItem = new HostedWindowItem
                {
                    WindowHandle = handle,
                };
                var tabItem = new Model.UI.TabItem
                {
                    IsActive = true,
                    Title = title,
                    HostedWindowItem = windowItem,
                };
                windowItem.TabItem = tabItem;
                this.Title = title;

                TabsContainer.AddTab(tabItem);

                this.ForcePaint();
            }));
        }
コード例 #5
0
 public static void OpenFind(HostedWindowItem console)
 {
     Win32Functions.PostMessage(console.WindowHandle, Win32Functions.WM_SYSCOMMAND, new IntPtr(SC_FIND_SECRET), IntPtr.Zero);
 }
コード例 #6
0
 public static void OpenProperties(HostedWindowItem console)
 {
     Win32Functions.PostMessage(console.WindowHandle, Win32Functions.WM_SYSCOMMAND, new IntPtr(SC_PROPERTIES_SECRET), IntPtr.Zero);
 }