Example #1
0
        public void OpenFile(FileItem file)
        {
            //If it is already open, focus it
            if (file.OpenFile != null)
            {
                tabStrip.SelectedItem = file.OpenFile.TabPage;
                file.OpenFile.Editor.Focus();
                return;
            }

            bool editorReadOnly = Options.Editor.ReadOnlyOutput &&
                                  file.IsDecendantOf(ProjectProperties.CurrentProjectPropperties.OutputFolder);
            //Otherwise make a new tab
            file.OpenFile = new OpenFileData();
            file.OpenFile.File = file;
            file.OpenFile.Editor = new MyEditor(this, editorReadOnly);
            //If we have another editor, get font styles from that (to save memmory)
            if (openFiles.Count > 0)
                file.OpenFile.Editor.SetFontScheme(openFiles[0].Editor.GetFontScheme());
            else
            {
                file.OpenFile.Editor.AddFontStyle(GalaxyKeywords.InMethodKeywords.mod, GalaxyKeywords.InMethodKeywords.words);
                file.OpenFile.Editor.AddFontStyle(GalaxyKeywords.OutMethodKeywords.mod, GalaxyKeywords.OutMethodKeywords.words);
                file.OpenFile.Editor.AddFontStyle(GalaxyKeywords.SystemExpressions.mod, GalaxyKeywords.SystemExpressions.words);
                file.OpenFile.Editor.AddFontStyle(GalaxyKeywords.InitializerKeywords.mod, GalaxyKeywords.InitializerKeywords.words);
                //file.OpenFile.Editor.AddFontStyle(GalaxyKeywords.TriggerKeywords.mod, GalaxyKeywords.TriggerKeywords.words);
                file.OpenFile.Editor.AddFontStyle(GalaxyKeywords.Primitives.mod, GalaxyKeywords.Primitives.words);
            }
            file.OpenFile.Editor.Dock = DockStyle.Fill;

            file.OpenFile.Editor.Tag = file.OpenFile;

            file.OpenFile.TabPage = new FATabStripItem(file == null ? "Untitled" : file.Text, null);
            file.OpenFile.TabPage.Margin = new Padding(0);
            file.OpenFile.TabPage.Padding = new Padding(0);
            file.OpenFile.TabPage.Tag = file.OpenFile;

            StreamReader reader = file.File.OpenText();
            file.OpenFile.Editor.Text = reader.ReadToEnd();
            reader.Close();
            file.OpenFile.Editor.SetHiddenBlocks(file.ClosedBlocks);

            file.OpenFile.TabPage.Controls.Add(file.OpenFile.Editor);
            tabStrip.AddTab(file.OpenFile.TabPage);
            openFiles.Add(file.OpenFile);

            file.OpenFile.Editor.OnTextEdited += MyEditor_TextEdited;

            tabStrip.SelectedItem = file.OpenFile.TabPage;
            tabStrip_TabStripItemSelectionChanged(null);
            file.OpenFile.Editor.Focus();
        }
Example #2
0
        private void MakeNewFile()
        {
            if (openProjectDir == null)
            {//Open an unsaved file

            }
            else
            {//Make file, and open it
                //Find it's position in the gui tree
                TreeNode folderNode = projectView.SelectedNode ?? ProjectProperties.CurrentProjectPropperties.SrcFolder.GUINode;

                DirItem markedChild = (DirItem) folderNode.Tag;
                FolderItem parentFolder = (FolderItem) (markedChild.Parent ?? markedChild);
                if (markedChild is FolderItem)
                    parentFolder = (FolderItem) markedChild;

                //Find a default unique name
                string name = "New file.galaxy++";
                int i = 1;
                while (parentFolder.Children.Any(child => child.Text == name))
                {
                    i++;
                    name = "New file" + i + ".galaxy++";
                }

                //Create the file
                FileInfo fileInfo = new FileInfo(parentFolder.Dir.FullName + "\\" + name);
                fileInfo.CreateText().Close();
                FileItem newFile = new FileItem(parentFolder, name);

                compiler.AddSourceFile(newFile);

                newFile.GUINode = new TreeNode(name);

                newFile.GUINode.Tag = newFile;
                newFile.GUINode.ImageIndex = newFile.GUINode.SelectedImageIndex = 2;

                //Insert into tree
                int insertAt = parentFolder.Children.IndexOf(markedChild) + 1;
                if (insertAt == 0 || insertAt == parentFolder.Children.Count)
                {
                    parentFolder.Children.Add(newFile);
                    parentFolder.GUINode.Nodes.Add(newFile.GUINode);
                }
                else
                {
                    parentFolder.Children.Insert(insertAt, newFile);
                    parentFolder.GUINode.Nodes.Insert(insertAt, newFile.GUINode);
                }
                ProjectProperties.CurrentProjectPropperties.Save();
                UploadedChangesToMap = false;
                UploadToMap();

                projectView.SelectedNode = newFile.GUINode;
                newFile.GUINode.EnsureVisible();
                BeginRename(newFile.GUINode);

                //Find nearest folder
                /*TreeNode folderNode = projectView.SelectedNode;
                DirectoryInfo dir;
                FindNearestFolderNode(ref folderNode, out dir);
                //Get desired filename
                String filename = GetUniqueStringDialog("New File", "Name", ".galaxy++", dir.GetFiles(),
                                                        "The file can not be created because another file of same name already exists in that folder.");
                if (filename == null) return;

                FileInfo file = new FileInfo(dir.FullName + "\\" + filename);
                file.CreateText().Close();
                TreeNode node = new TreeNode(file.Name);
                node.Tag = file;
                node.ImageIndex = node.SelectedImageIndex = 2;
                (folderNode ?? projectView.Nodes[0]).Nodes.Add(node);
                node.EnsureVisible();
                projectView.SelectedNode = node;
                compiler.AddSourceFile(file);
                OpenFile(file);*/
            }
        }
Example #3
0
 public void FocusFile(FileItem file)
 {
     if (file.OpenFile == null)
         OpenFile(file);
     else
         tabStrip.SelectedItem = file.OpenFile.TabPage;
 }
 private TextPoint GetTextPointFromIndex(FileItem file, int index)
 {
     string text = GetText(file);
     TextPoint point = new TextPoint(0, 0);
     while (index > 0)
     {
         index--;
         if (text[index] == '\n')
             point.Line++;
         else if (point.Line == 0)
             point.Pos++;
     }
     return point;
 }
 private string GetText(FileItem file)
 {
     if (file.OpenFile != null)
     {
         if (!CBMatchCase.Checked)
             return file.OpenFile.Editor.Text.ToLower();
         return file.OpenFile.Editor.Text;
     }
     //Open the file
     StreamReader stream = new StreamReader(file.File.OpenRead());
     string text = stream.ReadToEnd();
     stream.Close();
     if (!CBMatchCase.Checked)
         text = text.ToLower();
     return text;
 }
        private FileItem GetPreviousFile(FileItem file)
        {
            if (RBCurrent.Checked)
                return file;

            List<FileItem> files = GetAllFiles();
            int i = files.IndexOf(currentPosition.File);
            i++;
            if (i < 0)
                i += files.Count;
            return files[i];
        }
        private FileItem GetNextFile(FileItem file)
        {
            if (RBCurrent.Checked)
                return file;

            List<FileItem> files = GetAllFiles();
            int i = files.IndexOf(currentPosition.File);
            i = (i + 1)%files.Count;
            return files[i];
        }
 private int GetIndexFromTextpoint(FileItem file, TextPoint point)
 {
     string text = GetText(file);
     int index = 0;
     while (point.Line > 0 || point.Pos > 0)
     {
         if (text[index] == '\n')
             point.Line--;
         else if (point.Line == 0)
             point.Pos--;
         index++;
     }
     return index;
 }