public MainWindow()
        {
            InitializeComponent();

            Model       = new AppModel(this);
            DataContext = Model;

            InitializePreviewBrowser();

            TabControl.ClosingItemCallback = TabControlDragablz_TabItemClosing;

            Loaded   += OnLoaded;
            Drop     += MainWindow_Drop;
            AllowDrop = true;
            KeyUp    += MainWindow_KeyUp;

            // Singleton App startup - server code that listens for other instances
            if (mmApp.Configuration.UseSingleWindow)
            {
                // Listen for other instances launching and pick up
                // forwarded command line arguments
                PipeManager = new NamedPipeManager("MarkdownMonster");
                PipeManager.StartServer();
                PipeManager.ReceiveString += HandleNamedPipe_OpenRequest;
            }

            // Override some of the theme defaults (dark header specifically)
            mmApp.SetThemeWindowOverride(this);
        }
Esempio n. 2
0
        public App()
        {
            initialStartDirectory = Environment.CurrentDirectory;

            SplashScreen splashScreen = new SplashScreen("assets/markdownmonstersplash.png");

            splashScreen.Show(true);

            if (mmApp.Configuration.UseSingleWindow)
            {
                bool isOnlyInstance = false;
                Mutex = new Mutex(true, @"MarkdownMonster", out isOnlyInstance);
                if (!isOnlyInstance)
                {
                    string filesToOpen = " ";
                    var    args        = Environment.GetCommandLineArgs();
                    if (args != null && args.Length > 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 1; i < args.Length; i++)
                        {
                            string file = args[i];

                            // check if file exists and fully qualify to
                            // pass to named pipe
                            if (!File.Exists(file))
                            {
                                file = Path.Combine(initialStartDirectory, file);
                                if (!File.Exists(file))
                                {
                                    file = null;
                                }
                            }

                            if (!string.IsNullOrEmpty(file))
                            {
                                sb.AppendLine(Path.GetFullPath(file));
                            }
                        }
                        filesToOpen = sb.ToString();
                    }
                    var manager = new NamedPipeManager("MarkdownMonster");
                    manager.Write(filesToOpen);

                    splashScreen.Close(TimeSpan.MinValue);

                    // this exits the application
                    Environment.Exit(0);
                }
            }
#if !DEBUG
            //AppDomain currentDomain = AppDomain.CurrentDomain;
            //currentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalErrorHandler);


            DispatcherUnhandledException += App_DispatcherUnhandledException;
#endif
            mmApp.Started = DateTime.UtcNow;
        }
Esempio n. 3
0
        /// <summary>
        /// Checks to see if app is already running and if it is pushes
        /// parameters via NamedPipes to existing running application
        /// and exits this instance.
        ///
        /// Otherwise app just continues
        /// </summary>
        /// <param name="splashScreen"></param>
        private static void CheckCommandLineForSingletonLaunch(SplashScreen splashScreen)
        {
            // fix up the startup path
            string filesToOpen = " ";
            var    args        = Environment.GetCommandLineArgs();

            if (args != null && args.Length > 1)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 1; i < args.Length; i++)
                {
                    string file = args[i];
                    if (string.IsNullOrEmpty(file))
                    {
                        continue;
                    }

                    file = file.TrimEnd('\\');
                    file = Path.GetFullPath(file);
                    sb.AppendLine(file);

                    // write fixed up path arguments
                    args[i] = file;
                }
                filesToOpen = sb.ToString();
            }

            // Update Command Arguments
            commandArgs = args;


            if (!mmApp.Configuration.UseSingleWindow)
            {
                return;
            }

            bool isOnlyInstance;

            Mutex = new Mutex(true, @"MarkdownMonster", out isOnlyInstance);
            if (isOnlyInstance)
            {
                return;
            }

            var manager = new NamedPipeManager("MarkdownMonster");

            manager.Write(filesToOpen);

            splashScreen.Close(TimeSpan.MinValue);

            // Shut down application
            Environment.Exit(0);
        }
Esempio n. 4
0
        /// <summary>
        /// Checks to see if app is already running and if it is pushes
        /// parameters via NamedPipes to existing running application
        /// and exits this instance.
        ///
        /// Otherwise app just continues
        /// </summary>
        /// <param name="splashScreen"></param>
        private void CheckCommandLineForSingletonLaunch(SplashScreen splashScreen)
        {
            // fix up the startup path
            string        filesToOpen = " ";
            StringBuilder sb          = new StringBuilder();

            for (int i = 0; i < CommandArgs.Length; i++)
            {
                string file = CommandArgs[i];
                if (string.IsNullOrEmpty(file))
                {
                    continue;
                }

                if (!file.StartsWith("-"))
                {
                    file = file.TrimEnd('\\');
                    file = Path.GetFullPath(file);
                }

                sb.AppendLine(file);

                // write fixed up path arguments
                CommandArgs[i] = file;
            }

            filesToOpen = sb.ToString();


            if (!mmApp.Configuration.UseSingleWindow)
            {
                return;
            }

            Mutex = new Mutex(true, @"MarkdownMonster", out bool isOnlyInstance);
            if (isOnlyInstance)
            {
                return;
            }

            _noStart = true;

            var manager = new NamedPipeManager("MarkdownMonster");

            manager.Write(filesToOpen);

            splashScreen?.Close(TimeSpan.MinValue);

            // Shut down application
            Environment.Exit(0);
        }
Esempio n. 5
0
        public App()
        {
            SplashScreen splashScreen = new SplashScreen("assets/markdownmonstersplash.png");

            splashScreen.Show(true);

            if (mmApp.Configuration.UseSingleWindow)
            {
                bool isOnlyInstance = false;
                Mutex = new Mutex(true, @"MarkdownMonster", out isOnlyInstance);
                if (!isOnlyInstance)
                {
                    string filesToOpen = " ";
                    var    args        = Environment.GetCommandLineArgs();
                    if (args != null && args.Length > 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 1; i < args.Length; i++)
                        {
                            sb.AppendLine(args[i]);
                        }
                        filesToOpen = sb.ToString();
                    }
                    var manager = new NamedPipeManager("MarkdownMonster");
                    manager.Write(filesToOpen);

                    splashScreen.Close(TimeSpan.MinValue);

                    // this exits the application
                    Environment.Exit(0);
                }
            }

            //AppDomain currentDomain = AppDomain.CurrentDomain;
            //currentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalErrorHandler);

            DispatcherUnhandledException += App_DispatcherUnhandledException;

            mmApp.Started = DateTime.UtcNow;
        }
Esempio n. 6
0
        /// <summary>
        /// Checks to see if app is already running and if it is pushes
        /// parameters via NamedPipes to existing running application
        /// and exits this instance.
        ///
        /// Otherwise app just continues
        /// </summary>
        /// <param name="splashScreen"></param>
        private void CheckCommandLineForSingletonLaunch(SplashScreen splashScreen)
        {
            if (App.ForceNewWindow || !mmApp.Configuration.UseSingleWindow)
            {
                return;
            }

            // fix up the startup path
            string        filesToOpen = " ";
            StringBuilder sb          = new StringBuilder();

            for (int i = 0; i < CommandArgs.Length; i++)
            {
                string file = CommandArgs[i];
                if (string.IsNullOrEmpty(file))
                {
                    continue;
                }

                if (file.Equals("untitled", StringComparison.OrdinalIgnoreCase) ||
                    file.StartsWith("untitled.", StringComparison.OrdinalIgnoreCase) ||
                    file.StartsWith("markdownmonster:") ||
                    file.StartsWith("markdown:"))
                {
                    // just append as is - form file opener will decode
                    sb.AppendLine(file);
                }
                else if (!file.StartsWith("-"))
                {
                    file = file.TrimEnd('\\');
                    try
                    {
                        file = Path.GetFullPath(file);
                    }
                    catch
                    {
                        mmApp.Log($"Invalid startup command line file (skipping): {file}", logLevel: LogLevels.Error);
                        continue;
                    }

                    sb.AppendLine(file);
                }

                // write fixed up path arguments
                CommandArgs[i] = file;
            }

            filesToOpen = sb.ToString();

            Mutex = new Mutex(true, @"MarkdownMonster", out bool isOnlyInstance);
            if (isOnlyInstance)
            {
                return;
            }

            _noStart = true;

            var manager = new NamedPipeManager("MarkdownMonster");

            manager.Write(filesToOpen);

            splashScreen?.Close(TimeSpan.MinValue);

            // Shut down application
            Environment.Exit(0);
        }