Exemple #1
0
        private void MenuFileOpen_Click(object sender, EventArgs e)
        {
            FileItem file = FileIOUI.Open(this);

            if (file == null)
            {
                return;
            }

            if (file.Extension == "ns")
            {
                TabPage logsTab = Logs.TabPages[Logs.TabPages.IndexOfKey("IDE")];
                Logs.SelectedTab = logsTab;

                try
                {
                    Program.Solution = JsonConvert.DeserializeObject <SolutionDTO>(file.Contents);
                }
                catch (Exception ex)
                {
                    Program.Log("Can't parse solution file. Details: " + ex.Message);
                    Alert.Error("Невозможно распознать файл решения");
                }

                if (Program.Solution == null)
                {
                    return;
                }

                Program.Solution.Location = file.Location;

                TreeNode solution = new TreeNode(Program.Solution.Name + " (проектов: " + Program.Solution.Projects.Count + ")");
                solution.ToolTipText = Program.Solution.Location;

                SolutionExplorer.Nodes.Clear();
                SolutionExplorer.Nodes.Add(solution);

                Control logs = logsTab.Controls[0];
                logs.Text = "";

                foreach (ProjectDTO project in Program.Solution.Projects)
                {
                    string projectDir  = file.Location + "/" + project.Location + "/";
                    string projectText = project.Location + " (" + Program.Solution.Location + project.Location + ")";

                    TreeNode[] prjContents = FileItem.BuildDirectoryTree(projectDir);

                    if (prjContents == null)
                    {
                        SolutionExplorer.Nodes[0].Nodes.Add(new TreeNode(project.Location + " [Ошибка]"));

                        logs.Text += "[warn] Не удалось загрузить проект " + projectText + ". Каталог проекта не найден.";
                    }
                    else
                    {
                        TreeNode projectNode = new TreeNode(project.Location, prjContents);
                        projectNode.ToolTipText = projectDir;
                        projectNode.Expand();

                        SolutionExplorer.Nodes[0].Nodes.Add(projectNode);

                        logs.Text += "[ ok ] Загружен проект: " + projectText;
                    }

                    logs.Text += "\r\n";
                }

                SolutionExplorer.Sort();
                SolutionExplorer.Nodes[0].Expand();
            }
            else
            {
                _openTab(file);
            }
        }