/// <summary> /// Starts the application. /// </summary> private void Application_Startup(object sender, StartupEventArgs e) { //Loads associated extension files and files by command-line. if (e.Args.Length >= 1) { //Loads the project and displays the main interface with it. if (File.Exists(e.Args[0])) { MainDisplay display = new MainDisplay( Project.Load(e.Args[0]), e.Args[0]); display.Show(); } //Displays a new project dialog on failure to load. else { DlgNewProject dlg = new DlgNewProject(); dlg.Show(); } } //Displays a new project dialog for new files. else { DlgNewProject dlg = new DlgNewProject(); dlg.Show(); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var initial = e.Args.Length > 0 ? e.Args[0] : null; _mainWindow = new MainDisplay(initial); _mainWindow.Show(); }
/// <summary> /// Creates a new project. /// </summary> private void GuiNew_Click(object sender, RoutedEventArgs e) { MainDisplay display = new MainDisplay(); //Show the new display and close this one. display.Show(); gui.Close(); }
/// <summary> /// Opens a project. /// </summary> private void GuiOpen_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.CheckPathExists = true; dlg.DefaultExt = ".mdat"; dlg.Filter = GlobalStrings.FilterOpenSaveDatabase; dlg.Title = GlobalStrings.CaptionLoadDatabase; bool?result = dlg.ShowDialog(); if (result == true) { //Constructs the project from the file, then uses //it to construct the visuals. MainDisplay display = new MainDisplay(Project.Load(dlg.FileName), dlg.FileName); //Show the new display and close this one. display.Show(); gui.Close(); } }
/// <summary> /// Creates a new project dialog. /// </summary> public DlgNewProject() { gui = new DlgNewProjectGui(); gui.GuiNew.Click += GuiNew_Click; gui.GuiOpen.Click += GuiOpen_Click; gui.KeyDown += Gui_KeyDown; //Gets recently-opened URLs. var recentFiles = Utils.GetRecentlyOpened().Split('|').ToList(); //Adds an entry for each recent file. for (int i = 0; i < recentFiles.Count; i++) { //Skips files that don't exist. if (!File.Exists(recentFiles[i])) { continue; } //Builds a button for each file to open it. TextBlock txtblk = new TextBlock(); txtblk.Tag = recentFiles[i].ToString(); txtblk.Text = Path.GetFileName(recentFiles[i]); txtblk.ToolTip = txtblk.Tag; txtblk.Margin = new Thickness(4); txtblk.HorizontalAlignment = HorizontalAlignment.Center; if (txtblk.Text.Length > 40) { txtblk.Text = txtblk.Text.Substring(0, 40) + "..."; } //Highlights in bold when hovering the mouse. txtblk.MouseEnter += (a, b) => { txtblk.FontWeight = FontWeights.Bold; }; txtblk.MouseLeave += (a, b) => { txtblk.FontWeight = FontWeights.Normal; }; //Attempts to load the given file. txtblk.MouseDown += (a, b) => { if (File.Exists((string)txtblk.Tag)) { //Constructs project from the file. MainDisplay display = new MainDisplay(Project.Load((string)txtblk.Tag), (string)txtblk.Tag); //Shows the new display and close this one. display.Show(); gui.Close(); } else { //Removes the file if it can't be found. MessageBox.Show(GlobalStrings.DlgProjectNotFoundA + (string)txtblk.Tag + GlobalStrings.DlgProjectNotFoundB); Utils.RegRemoveRecentlyOpen((string)txtblk.Tag); gui.GuiPanel.Children.Remove(txtblk); } }; gui.GuiPanel.Children.Add(txtblk); } //Constructs a textblock noting recent files. if (gui.GuiPanel.Children.Count > 0) { TextBlock txtblkRecentFiles = new TextBlock(); txtblkRecentFiles.Text = GlobalStrings.NewProjectRecent; txtblkRecentFiles.Foreground = Brushes.DarkGray; txtblkRecentFiles.Margin = new Thickness(4); txtblkRecentFiles.HorizontalAlignment = HorizontalAlignment.Center; gui.GuiPanel.Children.Insert(0, txtblkRecentFiles); } }