public TotalCommander(ApplicationWindow hostWindow, string totalCommanderPath, bool openNewCommander)
 {
     _totalCommanderFolder = Path.GetFullPath(Path.GetDirectoryName(totalCommanderPath));
     _totalCommanderFileName = Path.GetFileName(totalCommanderPath);
     _openNewCommander = openNewCommander;
     _hostWindow = hostWindow;
 }
        public void NavigateTo(string path, ApplicationWindow hostWindow)
        {
            if (_supportedNavigatorManagers == null || _primaryNavigatorManager == null)
            {
                throw new InvalidOperationException("Please specify supported navigator managers and primary navigator manager.");
            }

            INavigator navigator = null;
            if (hostWindow != null)
            {
                foreach (INavigatorManager navigatorManager in _supportedNavigatorManagers)
                {
                    if (navigatorManager.IsNavigator(hostWindow))
                    {
                        navigator = navigatorManager.GetNavigator(hostWindow);
                        break;
                    }
                }
            }

            if (navigator == null)
            {
                navigator = _primaryNavigatorManager.CreateNavigator();
            }

            navigator.NavigateTo(path);
        }
        public void NavigateTo_ForSupportedNavigatorWindow_NavigatesWithThisNavigator()
        {
            ApplicationWindow window = new ApplicationWindow();

            Mock<INavigator> secondaryNavigatorMock = new Mock<INavigator>();
            _primaryManagerMock.Setup(manager => manager.IsNavigator(window)).Returns(false);
            _secondaryManagerMock.Setup(manager => manager.IsNavigator(window)).Returns(true);
            _secondaryManagerMock.Setup(manager => manager.GetNavigator(window)).Returns(secondaryNavigatorMock.Object);

            _navigationService.NavigateTo("asdasd", window);
            secondaryNavigatorMock.Verify(navigator => navigator.NavigateTo("asdasd"));
        }
        public void NavigateTo_ForNonNavigatorWindow_CreatesNewNavigator()
        {
            ApplicationWindow window = new ApplicationWindow();

            Mock<INavigator> primaryNavigatorMock = new Mock<INavigator>();
            _secondaryManagerMock.Setup(manager => manager.IsNavigator(window)).Returns(false);
            _primaryManagerMock.Setup(manager => manager.IsNavigator(window)).Returns(false);
            _primaryManagerMock.Setup(manager => manager.CreateNavigator()).Returns(primaryNavigatorMock.Object);

            _navigationService.NavigateTo("asdasd", window);
            primaryNavigatorMock.Verify(navigator => navigator.NavigateTo("asdasd"));
        }
        public bool IsNavigator(ApplicationWindow hostWindow)
        {
            uint hostProcessId;
            GetWindowThreadProcessId(hostWindow.Handle, out hostProcessId);

            Process hostProcess = Process.GetProcessById((int)hostProcessId);

            string executablePath = null;
            try
            {
                executablePath = hostProcess.MainModule.FileName;
            }
            catch (Exception)
            {
                //This may happen if hostProcess is not TotalCommander (e.g. Windows Explorer)
            }

            //Ignore case is not very accurate, but should prevent possible case mistakes
            return string.Equals(executablePath, _totalCommanderPath, StringComparison.InvariantCultureIgnoreCase);
        }
 public INavigator GetNavigator(ApplicationWindow hostWindow)
 {
     return new TotalCommander(hostWindow, _totalCommanderPath, false);
 }
        private void GlobalKeyCombinationPressed(object sender, EventArgs e)
        {
            lock (_syncObject)
            {
                _hostWindow = _presentationService.GetActiveWindow();

                _view.ShowView();
            }
        }
 public bool IsNavigator(ApplicationWindow hostWindow)
 {
     InternetExplorer windowsExplorer = GetWindowsExplorer(hostWindow);
     return windowsExplorer != null;
 }
        public INavigator GetNavigator(ApplicationWindow hostWindow)
        {
            InternetExplorer windowsExplorer = GetWindowsExplorer(hostWindow);

            return new WindowsExplorer(windowsExplorer);
        }
        private bool IsExpectedWindow(InternetExplorer actualWindow, ApplicationWindow expectedWindow)
        {
            IntPtr actualHandle = new IntPtr(actualWindow.HWND);
            bool windowHandleIsCorrect = expectedWindow != null && actualHandle == expectedWindow.Handle;

            return windowHandleIsCorrect;
        }
        private InternetExplorer GetWindowsExplorer(ApplicationWindow expectedWindow)
        {
            List<InternetExplorer> explorers = GetAllExplorers();

            InternetExplorer correctExplorer = explorers.FirstOrDefault(e => IsExpectedWindow(e, expectedWindow));

            return correctExplorer;
        }