Example #1
0
        public void StreamChangedCallback(WorkspaceControl Workspace)
        {
            if (ChangingWorkspacesRefCount == 0)
            {
                ChangingWorkspacesRefCount++;

                for (int Idx = 0; Idx < TabControl.GetTabCount(); Idx++)
                {
                    if (TabControl.GetTabData(Idx) == Workspace)
                    {
                        string ProjectFileName = Workspace.SelectedFileName;
                        if (TryOpenProject(ProjectFileName, Idx) == -1)
                        {
                            TabControl.RemoveTab(Idx);
                        }
                        break;
                    }
                }

                ChangingWorkspacesRefCount--;
            }
        }
Example #2
0
        int TryOpenProject(string ProjectFileName, int ReplaceTabIdx = -1)
        {
            Log.WriteLine("Trying to open project {0}", ProjectFileName);

            // Normalize the filename
            ProjectFileName = Path.GetFullPath(ProjectFileName).Replace('/', Path.DirectorySeparatorChar);

            // Make sure the project exists
            if (!File.Exists(ProjectFileName))
            {
                ShowErrorDialog("{0} does not exist.", ProjectFileName);
                return(-1);
            }

            // Check that none of the other tabs already have it open
            for (int TabIdx = 0; TabIdx < TabControl.GetTabCount(); TabIdx++)
            {
                if (ReplaceTabIdx != TabIdx)
                {
                    WorkspaceControl Workspace = (WorkspaceControl)TabControl.GetTabData(TabIdx);
                    if (Workspace.SelectedFileName.Equals(ProjectFileName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        TabControl.SelectTab(TabIdx);
                        return(TabIdx);
                    }
                    else if (ProjectFileName.StartsWith(Workspace.BranchDirectoryName + Path.DirectorySeparatorChar, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (MessageBox.Show(String.Format("{0} is already open under {1}.\n\nWould you like to close it?", Path.GetFileNameWithoutExtension(Workspace.SelectedFileName), Workspace.BranchDirectoryName, Path.GetFileNameWithoutExtension(ProjectFileName)), "Branch already open", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                        {
                            TabControl.RemoveTab(TabIdx);
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                }
            }

            // Make sure the path case is correct. This can cause UBT intermediates to be out of date if the case mismatches.
            ProjectFileName = Utility.GetPathWithCorrectCase(new FileInfo(ProjectFileName));

            // Detect the project settings in a background thread
            using (DetectProjectSettingsTask DetectSettings = new DetectProjectSettingsTask(ProjectFileName, Log))
            {
                string ErrorMessage;
                if (!ModalTaskWindow.Execute(this, DetectSettings, "Opening Project", "Opening project, please wait...", out ErrorMessage))
                {
                    if (!String.IsNullOrEmpty(ErrorMessage))
                    {
                        ShowErrorDialog("{0}", ErrorMessage);
                    }
                    return(-1);
                }

                // Hide the default control if it's visible
                DefaultControl.Hide();

                // Now that we have the project settings, we can construct the tab
                WorkspaceControl Workspace = new WorkspaceControl(this, SqlConnectionString, DataFolder, bRestoreStateOnLoad, OriginalExecutableFileName, ProjectFileName, bUnstable, DetectSettings, Log, Settings);
                Workspace.Parent   = TabPanel;
                Workspace.Location = new Point(0, 0);
                Workspace.Size     = new Size(TabPanel.Width, TabPanel.Height);
                Workspace.Anchor   = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
                Workspace.Hide();

                // Add the tab
                string NewTabName = GetTabName(Workspace);
                if (ReplaceTabIdx == -1)
                {
                    int NewTabIdx = TabControl.InsertTab(-1, NewTabName, Workspace);
                    return(NewTabIdx);
                }
                else
                {
                    TabControl.InsertTab(ReplaceTabIdx + 1, NewTabName, Workspace);
                    TabControl.RemoveTab(ReplaceTabIdx);
                    return(ReplaceTabIdx);
                }
            }
        }
Example #3
0
        int TryOpenProject(DetectProjectSettingsTask ProjectSettings, int ReplaceTabIdx, OpenProjectOptions Options)
        {
            Log.WriteLine("Trying to open project {0}", ProjectSettings.SelectedProject.ToString());

            // Check that none of the other tabs already have it open
            for (int TabIdx = 0; TabIdx < TabControl.GetTabCount(); TabIdx++)
            {
                if (ReplaceTabIdx != TabIdx)
                {
                    WorkspaceControl Workspace = TabControl.GetTabData(TabIdx) as WorkspaceControl;
                    if (Workspace != null)
                    {
                        if (Workspace.SelectedFileName.Equals(ProjectSettings.NewSelectedFileName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            Log.WriteLine("  Already open in tab {0}", TabIdx);
                            if ((Options & OpenProjectOptions.Quiet) == 0)
                            {
                                TabControl.SelectTab(TabIdx);
                            }
                            return(TabIdx);
                        }
                        else if (ProjectSettings.NewSelectedFileName.StartsWith(Workspace.BranchDirectoryName + Path.DirectorySeparatorChar, StringComparison.InvariantCultureIgnoreCase))
                        {
                            if ((Options & OpenProjectOptions.Quiet) == 0 && MessageBox.Show(String.Format("{0} is already open under {1}.\n\nWould you like to close it?", Path.GetFileNameWithoutExtension(Workspace.SelectedFileName), Workspace.BranchDirectoryName, Path.GetFileNameWithoutExtension(ProjectSettings.NewSelectedFileName)), "Branch already open", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                            {
                                Log.WriteLine("  Another project already open in this workspace, tab {0}. Replacing.", TabIdx);
                                TabControl.RemoveTab(TabIdx);
                            }
                            else
                            {
                                Log.WriteLine("  Another project already open in this workspace, tab {0}. Aborting.", TabIdx);
                                return(-1);
                            }
                        }
                    }
                }
            }

            // Hide the default control if it's visible
            DefaultControl.Hide();

            // Remove the current tab. We need to ensure the workspace has been shut down before creating a new one with the same log files, etc...
            if (ReplaceTabIdx != -1)
            {
                WorkspaceControl OldWorkspace = TabControl.GetTabData(ReplaceTabIdx) as WorkspaceControl;
                if (OldWorkspace != null)
                {
                    OldWorkspace.Hide();
                    TabControl.SetTabData(ReplaceTabIdx, new ErrorPanel(ProjectSettings.SelectedProject));
                    OldWorkspace.Dispose();
                }
            }

            // Now that we have the project settings, we can construct the tab
            WorkspaceControl NewWorkspace = new WorkspaceControl(this, ApiUrl, OriginalExecutableFileName, bUnstable, ProjectSettings, Log, Settings);

            NewWorkspace.Parent = TabPanel;
            NewWorkspace.Dock   = DockStyle.Fill;
            NewWorkspace.Hide();

            // Add the tab
            string NewTabName = GetTabName(NewWorkspace);

            if (ReplaceTabIdx == -1)
            {
                int NewTabIdx = TabControl.InsertTab(-1, NewTabName, NewWorkspace);
                Log.WriteLine("  Inserted tab {0}", NewTabIdx);
                return(NewTabIdx);
            }
            else
            {
                Log.WriteLine("  Replacing tab {0}", ReplaceTabIdx);
                TabControl.InsertTab(ReplaceTabIdx + 1, NewTabName, NewWorkspace);
                TabControl.RemoveTab(ReplaceTabIdx);
                return(ReplaceTabIdx);
            }
        }
Example #4
0
        private void CreateErrorPanel(int ReplaceTabIdx, UserSelectedProjectSettings Project, string Message)
        {
            Log.WriteLine(Message ?? "Unknown error");

            ErrorPanel ErrorPanel = new ErrorPanel(Project);

            ErrorPanel.Parent      = TabPanel;
            ErrorPanel.BorderStyle = BorderStyle.FixedSingle;
            ErrorPanel.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250)))));
            ErrorPanel.Location    = new Point(0, 0);
            ErrorPanel.Dock        = DockStyle.Fill;
            ErrorPanel.Hide();

            string SummaryText = String.Format("Unable to open '{0}'.", Project.ToString());

            int NewContentWidth = Math.Max(TextRenderer.MeasureText(SummaryText, ErrorPanel.Font).Width, 400);

            if (!String.IsNullOrEmpty(Message))
            {
                NewContentWidth = Math.Max(NewContentWidth, TextRenderer.MeasureText(Message, ErrorPanel.Font).Width);
            }

            ErrorPanel.SetContentWidth(NewContentWidth);

            List <StatusLine> Lines = new List <StatusLine>();

            StatusLine SummaryLine = new StatusLine();

            SummaryLine.AddText(SummaryText);
            Lines.Add(SummaryLine);

            if (!String.IsNullOrEmpty(Message))
            {
                Lines.Add(new StatusLine()
                {
                    LineHeight = 0.5f
                });

                foreach (string MessageLine in Message.Split('\n'))
                {
                    StatusLine ErrorLine = new StatusLine();
                    ErrorLine.AddText(MessageLine);
                    ErrorLine.LineHeight = 0.8f;
                    Lines.Add(ErrorLine);
                }
            }

            Lines.Add(new StatusLine()
            {
                LineHeight = 0.5f
            });

            StatusLine ActionLine = new StatusLine();

            ActionLine.AddLink("Retry", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { TryOpenProject(Project, TabControl.FindTabIndex(ErrorPanel)); })); });
            ActionLine.AddText(" | ");
            ActionLine.AddLink("Settings", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { EditSelectedProject(ErrorPanel); })); });
            ActionLine.AddText(" | ");
            ActionLine.AddLink("Close", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { TabControl.RemoveTab(TabControl.FindTabIndex(ErrorPanel)); })); });
            Lines.Add(ActionLine);

            ErrorPanel.Set(Lines, null, null, null);

            string NewProjectName = "Unknown";

            if (Project.Type == UserSelectedProjectType.Client && Project.ClientPath != null)
            {
                NewProjectName = Project.ClientPath.Substring(Project.ClientPath.LastIndexOf('/') + 1);
            }
            if (Project.Type == UserSelectedProjectType.Local && Project.LocalPath != null)
            {
                NewProjectName = Project.LocalPath.Substring(Project.LocalPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
            }

            string NewTabName = String.Format("Error: {0}", NewProjectName);

            if (ReplaceTabIdx == -1)
            {
                int TabIdx = TabControl.InsertTab(-1, NewTabName, ErrorPanel);
                TabControl.SelectTab(TabIdx);
            }
            else
            {
                TabControl.InsertTab(ReplaceTabIdx + 1, NewTabName, ErrorPanel);
                TabControl.RemoveTab(ReplaceTabIdx);
                TabControl.SelectTab(ReplaceTabIdx);
            }

            UpdateProgress();
        }
Example #5
0
        AutomationRequestOutput StartAutomatedSync(AutomationRequest Request, bool bForceSync)
        {
            ShowAndActivate();

            BinaryReader Reader      = new BinaryReader(new MemoryStream(Request.Input.Data));
            string       StreamName  = Reader.ReadString();
            string       ProjectPath = Reader.ReadString();

            AutomatedSyncWindow.WorkspaceInfo WorkspaceInfo;
            if (!AutomatedSyncWindow.ShowModal(this, StreamName, ProjectPath, out WorkspaceInfo, Log))
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Canceled));
            }

            if (WorkspaceInfo.bRequiresStreamSwitch)
            {
                // Close any tab containing this window
                for (int ExistingTabIdx = 0; ExistingTabIdx < TabControl.GetTabCount(); ExistingTabIdx++)
                {
                    WorkspaceControl ExistingWorkspace = TabControl.GetTabData(ExistingTabIdx) as WorkspaceControl;
                    if (ExistingWorkspace != null && ExistingWorkspace.ClientName.Equals(WorkspaceInfo.WorkspaceName))
                    {
                        TabControl.RemoveTab(ExistingTabIdx);
                        break;
                    }
                }

                // Switch the stream
                PerforceConnection Perforce = new PerforceConnection(WorkspaceInfo.UserName, WorkspaceInfo.WorkspaceName, WorkspaceInfo.ServerAndPort);
                if (!Perforce.SwitchStream(StreamName, Log))
                {
                    Log.WriteLine("Unable to switch stream");
                    return(new AutomationRequestOutput(AutomationRequestResult.Error));
                }
            }

            UserSelectedProjectSettings SelectedProject = new UserSelectedProjectSettings(WorkspaceInfo.ServerAndPort, WorkspaceInfo.UserName, UserSelectedProjectType.Client, String.Format("//{0}{1}", WorkspaceInfo.WorkspaceName, ProjectPath), null);

            int TabIdx = TryOpenProject(SelectedProject, -1, OpenProjectOptions.None);

            if (TabIdx == -1)
            {
                Log.WriteLine("Unable to open project");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            WorkspaceControl Workspace = TabControl.GetTabData(TabIdx) as WorkspaceControl;

            if (Workspace == null)
            {
                Log.WriteLine("Workspace was unable to open");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            if (!bForceSync && Workspace.CanLaunchEditor())
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Ok, Encoding.UTF8.GetBytes(Workspace.SelectedFileName)));
            }

            Workspace.AddStartupCallback((Control, bCancel) => StartAutomatedSyncAfterStartup(Control, bCancel, Request));
            return(null);
        }
Example #6
0
        private void CreateErrorPanel(int ReplaceTabIdx, string ProjectFileName, string Message)
        {
            Log.WriteLine(Message);

            ErrorPanel ErrorPanel = new ErrorPanel(ProjectFileName);

            ErrorPanel.Parent      = TabPanel;
            ErrorPanel.BorderStyle = BorderStyle.FixedSingle;
            ErrorPanel.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250)))));
            ErrorPanel.Location    = new Point(0, 0);
            ErrorPanel.Size        = new Size(TabPanel.Width, TabPanel.Height);
            ErrorPanel.Anchor      = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            ErrorPanel.Hide();

            string SummaryText = String.Format("Unable to open '{0}'.", ProjectFileName);

            int NewContentWidth = Math.Max(Math.Max(TextRenderer.MeasureText(SummaryText, ErrorPanel.Font).Width, TextRenderer.MeasureText(Message, ErrorPanel.Font).Width), 400);

            ErrorPanel.SetContentWidth(NewContentWidth);

            List <StatusLine> Lines = new List <StatusLine>();

            StatusLine SummaryLine = new StatusLine();

            SummaryLine.AddText(SummaryText);
            Lines.Add(SummaryLine);

            Lines.Add(new StatusLine()
            {
                LineHeight = 0.5f
            });

            StatusLine ErrorLine = new StatusLine();

            ErrorLine.AddText(Message);
            Lines.Add(ErrorLine);

            Lines.Add(new StatusLine()
            {
                LineHeight = 0.5f
            });

            StatusLine ActionLine = new StatusLine();

            ActionLine.AddLink("Close", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { TabControl.RemoveTab(TabControl.FindTabIndex(ErrorPanel)); })); });
            ActionLine.AddText(" | ");
            ActionLine.AddLink("Retry", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { TryOpenProject(ProjectFileName, TabControl.FindTabIndex(ErrorPanel)); })); });
            ActionLine.AddText(" | ");
            ActionLine.AddLink("Open another...", FontStyle.Bold | FontStyle.Underline, () => { BeginInvoke(new MethodInvoker(() => { BrowseForProject(TabControl.FindTabIndex(ErrorPanel)); })); });
            Lines.Add(ActionLine);

            ErrorPanel.Set(Lines);

            string NewTabName = "Error: " + Path.GetFileName(ProjectFileName);

            if (ReplaceTabIdx == -1)
            {
                int TabIdx = TabControl.InsertTab(-1, NewTabName, ErrorPanel);
                TabControl.SelectTab(TabIdx);
            }
            else
            {
                TabControl.InsertTab(ReplaceTabIdx + 1, NewTabName, ErrorPanel);
                TabControl.RemoveTab(ReplaceTabIdx);
                TabControl.SelectTab(ReplaceTabIdx);
            }

            UpdateProgress();
        }