Пример #1
0
        private void CreateProject(object sender, RoutedEventArgs e)
        {
            CreateProjectWindow newProjWin = new CreateProjectWindow();

            if (newProjWin.ShowDialog() == true)
            {
                ProjStruct.CreateProject(newProjWin.SelectedLocation, newProjWin.SelectedLanguage, newProjWin.SelectedType, newProjWin.SelectedFramework, newProjWin.Author, newProjWin.Version);
            }
        }
Пример #2
0
        private void OpenProject(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.InitialDirectory = Properties.Settings.Default.ProjectsDirectory;
            dlg.Filter           = "Project Files (.xml)|*.xml"; // Filter files by extension

            if (dlg.ShowDialog() == true)
            {
                ProjStruct.ReadProject(dlg.FileName, Path.GetDirectoryName(dlg.FileName));
            }
        }
Пример #3
0
        private void ProjectItemSelected(object sender, object projectItem)
        {
            // Remove previous items
            ProjStruct.ClearMethods();

            if (projectItem != null && projectItem.GetType() == typeof(FileItem))
            {
                FileItem selectedItemFile = (FileItem)projectItem;
                FileInfo selectedItem     = selectedItemFile.Info;

                TabItem tab   = (TabItem)TextEditor.Parent;
                Regex   regex = new Regex(@"(private|protected|public) (.+?)\)");

                // Show file contents
                if (tab != null)
                {
                    using (var reader = new StreamReader(selectedItem.FullName, Encoding.UTF8))
                        TextEditor.Text = reader.ReadToEnd();
                    TextEditor.TextArea.TextView.GetVisualTopByDocumentLine(1); // Set to first line (method selection moves line)

                    tab.Header    = selectedItem.Name;
                    tab.FontStyle = FontStyles.Normal;
                }

                // Add selected class methods to method list
                if (selectedItem.Extension == ".cs")
                {
                    using (var reader = new StreamReader(selectedItem.FullName, Encoding.UTF8))
                        while (!reader.EndOfStream)
                        {
                            foreach (Match match in regex.Matches(reader.ReadLine()))
                            {
                                if (match.Groups[2] != null)
                                {
                                    ProjStruct.AddMethod(match.Groups[1].Value, match.Groups[2].Value + ")", selectedItem);
                                }
                            }
                        }                                                                                                   // 1: type, 2: signature
                }
            }
        }
Пример #4
0
        private void CloseProject(object sender, RoutedEventArgs e)
        {
            //TODO: check if anything is not saved
            MessageBoxResult saveResult = MessageBox.Show("Do you want to save your work before closing the project?", "Close Project Save", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

            // Clean up tree view if Cancel was not selected
            if (saveResult != MessageBoxResult.Cancel)
            {
                Project selectedItem = (Project)ProjStruct.ProjectTree.SelectedItem;
                ProjStruct.CloseProject(selectedItem);
            }

            TabItem tab = (TabItem)TextEditor.Parent;

            if (tab != null)
            {
                tab.Content   = "";
                tab.Header    = "No File";
                tab.FontStyle = FontStyles.Italic;
            }
        }
Пример #5
0
        public MainWindow()
        {
            InitializeComponent();

            // Create default projects directory if it doesn't exist (yet or was deleted)
            string projectDir = Properties.Settings.Default.ProjectsDirectory;

            if (projectDir == "")
            {
                Properties.Settings.Default.ProjectsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\" + Constants.ProjectsFolder;
            }

            if (!Directory.Exists(Properties.Settings.Default.ProjectsDirectory))
            {
                Directory.CreateDirectory(Properties.Settings.Default.ProjectsDirectory);
            }

            // Add default settings in case of first run
            if (Properties.Settings.Default.FirstRun)
            {
                // Default languages, types and frameworks
                Properties.Settings.Default.Languages = new List <string>()
                {
                    "C++", "C#"
                };
                Properties.Settings.Default.Types = new List <List <string> >()
                {
                    new List <string>()
                    {
                        "Empty", "Console"
                    }, new List <string>()
                    {
                        "Empty", "WPF"
                    }
                };
                Properties.Settings.Default.Frameworks = new List <string>()
                {
                    "QT", "SDL2", ".NET"
                };

                // Mark first run completed
                Properties.Settings.Default.FirstRun = false;
            }

            // Load settings
            TextEditor.WordWrap = Properties.Settings.Default.TextWrap;
            SelectedLayout      = Properties.Settings.Default.Layout;

            // Load cache
            if (File.Exists(Constants.CacheFile))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Cache));
                using (TextReader reader = new StreamReader(Constants.CacheFile))
                {
                    try
                    {
                        Cache cache = (Cache)serializer.Deserialize(reader);
                        List <OpenProject> openProjects = cache.OpenProjects;
                        foreach (var openProj in openProjects)
                        {
                            ProjStruct.ReadProject(openProj.ProjectFileLocation, openProj.Location);
                        }
                    }
                    catch
                    {
                        //TODO Write to pop-up
                        Console.WriteLine("Error! Cache failed deserializing!");
                    }
                }
            }

            // Start auto-save timer
            DispatcherTimer dt = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(Properties.Settings.Default.AutoSaveInterval)
            };

            dt.Tick += AutoSave;
            dt.Start();
        }