Пример #1
0
        int TryOpenProject(UserSelectedProjectSettings Project, int ReplaceTabIdx, OpenProjectOptions Options = OpenProjectOptions.None)
        {
            Log.WriteLine("Detecting settings for {0}", Project);
            using (DetectProjectSettingsTask DetectProjectSettings = new DetectProjectSettingsTask(Project, DataFolder, CacheFolder, new PrefixedTextWriter("  ", Log)))
            {
                string ErrorMessage;

                ModalTaskResult Result;
                if ((Options & OpenProjectOptions.Quiet) != 0)
                {
                    Result = ModalTask.Execute(this, DetectProjectSettings, "Opening Project", "Opening project, please wait...", out ErrorMessage);
                }
                else
                {
                    Result = PerforceModalTask.Execute(this, Project.LocalPath, Project.ServerAndPort, Project.UserName, DetectProjectSettings, "Opening Project", "Opening project, please wait...", Log, out ErrorMessage);
                }

                if (Result != ModalTaskResult.Succeeded)
                {
                    CreateErrorPanel(ReplaceTabIdx, Project, ErrorMessage);
                    return(-1);
                }
                return(TryOpenProject(DetectProjectSettings, ReplaceTabIdx, Options));
            }
        }
 int TryOpenProject(UserSelectedProjectSettings Project, int ReplaceTabIdx, OpenProjectOptions Options = OpenProjectOptions.None)
 {
     using (DetectProjectSettingsTask DetectProjectSettings = new DetectProjectSettingsTask(Project, DataFolder, Log))
     {
         string ErrorMessage;
         if (ModalTask.Execute(this, DetectProjectSettings, "Opening Project", "Opening project, please wait...", out ErrorMessage) != ModalTaskResult.Succeeded)
         {
             if (!String.IsNullOrEmpty(ErrorMessage) && (Options & OpenProjectOptions.Quiet) == 0)
             {
                 CreateErrorPanel(ReplaceTabIdx, Project, ErrorMessage);
             }
             return(-1);
         }
         return(TryOpenProject(DetectProjectSettings, ReplaceTabIdx, Options));
     }
 }
Пример #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);
            }
        }