public DocumentView OpenFile(string filePath, bool restoreView) { string extension = Path.GetExtension(filePath); // is it a project? if (extension.ToUpper() == ".SSPROJ") { OpenProject(filePath); return(null); } // if the file is already open, just switch to it DocumentTab tab = GetDocument(filePath); if (tab != null) { tab.Activate(); return(tab.View); } // the IDE will look for a file opener explicitly declaring the file extension. // if that fails, then use the default opener (if any). DocumentView view = null; try { string fileExtension = Path.GetExtension(filePath); if (fileExtension.StartsWith(".")) // remove dot from extension { fileExtension = fileExtension.Substring(1); } var plugins = from name in PluginManager.GetNames <IFileOpener>() let plugin = PluginManager.Get <IFileOpener>(name) where plugin.FileExtensions.Contains(fileExtension) select plugin; IFileOpener defaultOpener = PluginManager.Get <IFileOpener>(Core.Settings.FileOpener); IFileOpener opener = plugins.FirstOrDefault() ?? defaultOpener; if (opener != null) { view = opener.Open(filePath); } else { MessageBox.Show(string.Format("Sphere Studio doesn't know how to open that type of file and no default file opener is available. Tip: Open Configuration Manager and check your plugins.\n\nFile Type: {0}\n\nPath to File:\n{1}", fileExtension.ToLower(), filePath), @"Unable to Open File", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (IOException) { return(null); } if (view != null) { AddDocument(view, filePath, restoreView); } return(view); }
internal DocumentTab AddDocument(DocumentView view, string filepath = null, bool restoreView = false) { DocumentTab tab = new DocumentTab(this, view, filepath, restoreView); tab.Closed += (sender, e) => _tabs.Remove(tab); tab.Activate(); _tabs.Add(tab); return(tab); }
void menuDocumentItem_Click(object sender, EventArgs e) { DocumentTab tab = GetDocument(((ToolStripItem)sender).Tag as string); if (tab != null) { tab.Activate(); } else { SelectDockPane((string)((ToolStripMenuItem)sender).Tag); } }
private void MainDock_ActiveDocumentChanged(object sender, EventArgs e) { if (MainDock.ActiveDocument == null) { return; } DockContent content = MainDock.ActiveDocument as DockContent; if (content.Tag is DocumentTab) { if (_activeTab != null) { _activeTab.Deactivate(); } _activeTab = content.Tag as DocumentTab; _activeTab.Activate(); } UpdateControls(); }
private void IDEForm_Shown(object sender, EventArgs e) { bool isFirstRun = !Core.Settings.GetBoolean("setupComplete", false); if (isFirstRun) { MessageBox.Show(@"Hello! It's your first time here! I would love to help you " + @"set a few things up!", @"Welcome First Timer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); Core.Settings.SetValue("setupComplete", true); menuConfigManager_Click(null, EventArgs.Empty); } if (!String.IsNullOrWhiteSpace(_defaultActiveName)) { DocumentTab tab = GetDocument(_defaultActiveName); if (tab != null) { tab.Activate(); } } }
private void IDEForm_Load(object sender, EventArgs e) { Location = new Point(Ide.Properties.Settings.Default.WindowX, Ide.Properties.Settings.Default.WindowY); Size = new Size(Ide.Properties.Settings.Default.WindowWidth, Ide.Properties.Settings.Default.WindowHeight); WindowState = Ide.Properties.Settings.Default.WindowMaxed ? FormWindowState.Maximized : FormWindowState.Normal; // this works around glitchy WeifenLuo behavior when messing with panel // visibility before the form loads. if (Core.Settings.AutoOpenLastProject && Core.Project != null) { StartVisible = !Core.Project.User.StartHidden; DocumentTab tab = GetDocument(Core.Project.User.ActiveDocument); if (tab != null) { tab.Activate(); } } else { StartVisible = Core.Settings.UseStartPage; } }
private void menuStartPage_Click(object sender, EventArgs e) { StartVisible = true; _startTab.Activate(); }
/// <summary> /// Loads a Sphere Studio project into the IDE. /// </summary> /// <param name="fileName">The filename of the project.</param> /// <param name="usePluginWarning">Whether to show a warning if required plugins are missing.</param> public void OpenProject(string fileName, bool usePluginWarning = true) { if (string.IsNullOrEmpty(fileName)) { return; } Project pj = SphereStudio.Ide.Project.Open(fileName); IStarter starter = PluginManager.Get <IStarter>(pj.User.Engine); ICompiler compiler = PluginManager.Get <ICompiler>(pj.Compiler); if (usePluginWarning && (starter == null || compiler == null)) { var answer = MessageBox.Show( string.Format("One or more plugins required to work on '{0}' are either disabled or not installed. Please open Configuration Manager and check your plugins.\n\nCompiler required:\n{1}\n\nIf you continue, data may be lost. Open this project anyway?", pj.Name, pj.Compiler), "Proceed with Caution", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (answer == DialogResult.No) { return; } } if (!CloseCurrentProject()) { return; } Core.Project = pj; RefreshProject(); if (LoadProject != null) { LoadProject(null, EventArgs.Empty); } HelpLabel.Text = @"Game project loaded successfully!"; StartVisible = true; string[] docs = Core.Project.User.Documents; foreach (string s in docs) { if (string.IsNullOrWhiteSpace(s)) { continue; } try { OpenFile(s, true); } catch (Exception) { } } // if the form is not visible, don't try to mess with the panels. // it will be done in Form_Load. if (Visible) { if (Core.Project.User.StartHidden) { StartVisible = false; } DocumentTab tab = GetDocument(Core.Project.User.ActiveDocument); if (tab != null) { tab.Activate(); } } Text = string.Format("{3} - {0} {1} {2}", Versioning.Name, Versioning.Version, Environment.Is64BitProcess ? "x64" : "x86", Project.Name); UpdateEngineList(); UpdateControls(); }