Ejemplo n.º 1
0
 public void OpenFile(AsmProjectFile file, int?line = null, int?column = null, int?length = null)
 {
     if (OpenFileAction != null)
     {
         OpenFileAction(file, line, column, length);
     }
 }
Ejemplo n.º 2
0
 public EditorWindow(MainForm form, AsmProjectFile file, Events events)
 {
     MainWindow   = form;
     ProjectFile  = file;
     ModuleEvents = events;
     Text         = ProjectFile.File.Name;
 }
Ejemplo n.º 3
0
 public Task <IEnumerable <BuildError> > ParseErrors(string sourceCode, AsmProjectFile projectFile)
 {
     return(Task.Run(() =>
     {
         try
         {
             return ParseErrorsSync(sourceCode, projectFile);
         }
         catch (IOException ex)
         {
             if (ex.HResult == -2147024864)
             {
                 // This task isn't essential, so just suppress IO errors when file is used by other process
                 return new List <BuildError>();
             }
             Log(new LogData("Error testing assembly: " + ex.Message, LogType.Error));
             throw ex;
         }
         catch (Exception ex)
         {
             Log(new LogData("Error testing assembly: " + ex.Message, LogType.Error));
             throw ex;
         }
     }));
 }
Ejemplo n.º 4
0
 public void OnFilenameChanged(AsmProjectFile projectFile)
 {
     if (FilenameChanged != null)
     {
         FilenameChanged(projectFile);
     }
 }
Ejemplo n.º 5
0
        public ImagePipelineSettings(AsmProjectFile file, ImageRenderControl image)
        {
            _loading = true;
            _file    = file;
            InitializeComponent();

            NewPipelineType.Items.Clear();
            NewPipelineType.Items.AddRange(_imagePipelineChoices.Select(o => o.Value).ToArray());

            if (file.Pipeline != null)
            {
                Pipeline = file.Pipeline.Clone(true);
            }
            PaletteReductionPanel = new PaletteReductionSettings(PipelineAsChr, image)
            {
                Dock = DockStyle.Top
            };
            ChrPipelinePanel = new ChrPipelineSettings(PipelineAsChr, image)
            {
                Dock = DockStyle.Top
            };

            PaletteReductionPanel.PipelineChanged += RegisterChange;
            ChrPipelinePanel.PipelineChanged      += RegisterChange;

            Controls.Add(ChrPipelinePanel);
            Controls.Add(PaletteReductionPanel);

            RefreshLayout();
            _loading = false;
        }
Ejemplo n.º 6
0
 public NavigationData(AsmProjectFile file, Events events)
 {
     Text        = file.File.Name;
     Description = file.File.FullName;
     _navigate   = () => events.OpenFile(file);
     ImageIndex  = 1;
 }
Ejemplo n.º 7
0
 public void AddResult(AsmProjectFile file, List <SearchResult> results, string query)
 {
     if (IsDisposed)
     {
         return;
     }
     BeginInvoke(_addResult, file, results, query);
 }
Ejemplo n.º 8
0
        public TextEditorWindow(MainForm form, AsmProjectFile file, Events moduleEvents) : base(form, file, moduleEvents)
        {
            switch (file.Type)
            {
            case FileType.Source:
            case FileType.Include:
                TextEditor = new Ca65Editor(ProjectFile, moduleEvents);
                break;

            case FileType.Text:
            default:
                TextEditor = new TextEditor();
                TextEditor.ContextMenuStrip = new TextEditorMenu(moduleEvents);
                break;
            }

            InitializeComponent();

            ThreadSafeRefresh        = RefreshEditorContents;
            ThreadSafeRefreshWarning = RefreshWarning;
            TextEditor.TextChanged  += (o, args) =>
            {
                Pristine = false;
                RefreshTitle();
            };

            ProjectFile.ParsedLocalSymbols += ThreadSafeUpdateSymbols;

            var codeEditor = TextEditor as CodeEditor;

            if (codeEditor != null)
            {
                SourceNavigator.Visible = true;
                if (ProjectFile.LocalSymbols != null)
                {
                    SourceNavigator.UpdateSymbols(ProjectFile.LocalSymbols.Where(s => s.Source == ProjectFile.File.FullName));
                }

                codeEditor.ParseErrors          = (code) => form.BuildHandler.ParseErrors(code, ProjectFile);
                codeEditor.AddToWatch           = form.AddWatch;
                codeEditor.AddAddressBreakpoint = (address, types) => { form.AddBreakpoint(address, types, Breakpoint.AddressTypes.Cpu); };
                codeEditor.AddSymbolBreakpoint  = (symbol, types) => { form.AddBreakpoint(-1, types, Breakpoint.AddressTypes.Cpu, symbol); };
                codeEditor.GetCpuMemory         = form.GetCpuMemory;
                codeEditor.ActiveTextAreaControl.Caret.PositionChanged += (sender, args) =>
                {
                    SourceNavigator.CurrentLine = codeEditor.ActiveTextAreaControl.Caret.Line;
                };
                SourceNavigator.Navigated += line =>
                {
                    codeEditor.FocusLine(line, false);
                    codeEditor.Focus();
                };
            }
            _savingLock = new object();
        }
Ejemplo n.º 9
0
        public Ca65Editor(AsmProjectFile file, Events events) : base(file, events)
        {
            _completionDataProvider      = new Ca65Completion(File.Project, GetSymbolDescription, events);
            Document.TextContentChanged += (sender, args) =>
            {
            };

            ActiveTextAreaControl.Caret.PositionChanged += (s, a) => IdentifyLocalLabels();

            _labelStartMarker = new TextMarker(0, 1, TextMarkerType.SolidBlock, Document.HighlightingStrategy.GetColorFor("Highlighted word").BackgroundColor);
            _labelEndMarker   = new TextMarker(0, 0, TextMarkerType.SolidBlock, Document.HighlightingStrategy.GetColorFor("Highlighted word").BackgroundColor);
        }
Ejemplo n.º 10
0
 public Breakpoint GetBreakpoint(AsmProjectFile file = null)
 {
     return(new Breakpoint
     {
         AddressType = (Breakpoint.AddressTypes)AddressType,
         Automatic = Automatic,
         CurrentLine = Line,
         Disabled = Disabled,
         StartAddress = StartAddress,
         EndAddress = EndAddress,
         Symbol = Symbol,
         Type = (Breakpoint.Types)Type,
         File = file
     });
 }
Ejemplo n.º 11
0
 private void RenameFile(AsmProjectFile file, NodeLabelEditEventArgs e)
 {
     foreach (var character in Path.GetInvalidFileNameChars())
     {
         if (e.Label.Contains(character))
         {
             e.CancelEdit = true;
             Program.Error(string.Format("Invalid character '{0}'", character));
             return;
         }
     }
     file.File.MoveTo(Path.Combine(file.File.DirectoryName, e.Label));
     _events.OnFilenameChanged(file);
     _project.Pristine = false;
     // TODO: Update open tabs, and breakpoint list
 }
Ejemplo n.º 12
0
        public void UpdateFromFile(AsmProjectFile fileInfo)
        {
            FileInfo = fileInfo;
            Text     = fileInfo.File.Name;

            switch (fileInfo.Type)
            {
            case FileType.Source:
            case FileType.Include:
                ImageIndex = 6;
                break;

            case FileType.Image:
                ImageIndex = 5;
                break;

            default:
                ImageIndex = 4;
                break;
            }

            if (fileInfo.Mode == CompileMode.LinkerConfig)
            {
                ImageIndex = 7;
            }
            if (fileInfo.Missing)
            {
                ImageIndex = 100;
                ForeColor  = SystemColors.GrayText;
                Text      += " (missing)";
            }
            SelectedImageIndex = ImageIndex;

            if (false && fileInfo.Pipeline != null)             // TODO: Display pipeline output in explorer?
            {
                foreach (var outputFile in fileInfo.Pipeline.OutputFiles)
                {
                    if (outputFile == null)
                    {
                        continue;
                    }

                    var file = new FileInfo(outputFile);
                    Nodes.Add(new PipelineNode(fileInfo, file.Name));
                }
            }
        }
Ejemplo n.º 13
0
        public void FocusNode(AsmProjectFile projectFile)
        {
            var node = GetNode <FileNode>(Nodes, n => n.FileInfo == projectFile);

            if (node == null)
            {
                return;
            }
            var parent = node.Parent;

            while (parent != null)
            {
                parent.Expand();
                parent = parent.Parent;
            }
            SelectedNode = node;
        }
Ejemplo n.º 14
0
            public FileImportInfo(AsmProjectFile projectFile)
            {
                ProjectFile      = projectFile;
                IncludeInProject = true;

                if (projectFile.GetRelativePath().StartsWith("bin/"))
                {
                    IncludeInProject = false;
                }
                if (projectFile.File.Name.StartsWith("."))
                {
                    IncludeInProject = false;
                }
                if (projectFile.File.Extension == ".nes")
                {
                    IncludeInProject = false;
                }
            }
Ejemplo n.º 15
0
        private void DeleteFile(AsmProjectFile file)
        {
            var choice = MessageBox.Show(this, string.Format("Do you want to delete '{0}' permanently?\nThis action cannot be undone", file.File.Name), "Delete file", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (choice != DialogResult.OK)
            {
                return;
            }

            try
            {
                file.File.Delete();
            }
            catch (Exception ex)
            {
                Program.Error("Failed deleting file:\n" + ex.Message, ex);
            }
            _project.RemoveProjectFile(file);
            // TODO: What if file is open in an editor window
        }
Ejemplo n.º 16
0
        private void GoToFile(string fileReference)
        {
            AsmProjectFile foundFile = null;

            try
            {
                var matchFiles = new[] {
                    Path.Combine(File.GetRelativeDirectory(), fileReference).Replace('\\', '/'),
                    fileReference.Replace('\\', '/')
                };
                var completeMatch = matchFiles.Select(mf => new DirectoryInfo(Path.Combine(File.Project.Directory.FullName, mf)).FullName);
                foundFile = File.Project.Files.FirstOrDefault(f =>
                                                              completeMatch.Any(mf => mf.Equals(f.File.FullName, StringComparison.InvariantCultureIgnoreCase)) ||
                                                              matchFiles.Any(mf => mf.Equals(f.GetRelativePath(), StringComparison.InvariantCultureIgnoreCase)));
            }
            catch
            {
                return;
            }
            if (foundFile != null)
            {
                ModuleEvents.OpenFile(foundFile);
            }
        }
Ejemplo n.º 17
0
        private IEnumerable <BuildError> ParseErrorsSync(string sourceCode, AsmProjectFile projectFile)
        {
            var errors        = new List <BuildError>();
            var projectFolder = projectFile.Project.Directory.FullName;
            var sourceFile    = Path.Combine(Path.GetTempPath(), @"ca65temp.s");
            var objectFile    = Path.Combine(Path.GetTempPath(), @"ca65temp.o");
            var configuration = projectFile.Project.CurrentConfiguration;

            File.WriteAllText(sourceFile, sourceCode);
            using (var process = new Process())
            {
                process.StartInfo           = GetAsmParams(projectFolder);
                process.EnableRaisingEvents = true;
                process.OutputDataReceived += OutputReceived;
                process.ErrorDataReceived  += (s, e) =>
                {
                    if (e.Data != null)
                    {
                        errors.Add(new BuildError(e.Data));
                    }
                };

                var fileDirectory = projectFile.GetRelativeDirectory();
                process.StartInfo.Arguments = string.Format("\"{0}\" -o \"{1}\" -t nes --cpu {2}{4} -I .{3}",
                                                            sourceFile,
                                                            objectFile,
                                                            projectFile.Project.GetTargetCpu(),
                                                            string.IsNullOrWhiteSpace(fileDirectory) ? "" : " -I \"" + fileDirectory + "\"",
                                                            string.Join("", configuration.Symbols.Select(s => " -D " + s)));

                process.Start();
                process.BeginErrorReadLine();
                process.WaitForExit();
            }
            return(errors.Where(e => e.File == sourceFile));
        }
Ejemplo n.º 18
0
        public CodeEditor(AsmProjectFile file, Events events)
        {
            File         = file;
            ModuleEvents = events;
            Document.FormattingStrategy = new Ca65Formatting();
            _fileCompletionDataProvider = new FileCompletion(new[] { file.Project.Directory, file.File.Directory },
                                                             () => {
                _forcedAutoCompleteWindow = true;
                ShowIntellisense('/', 0);
            });

            ActiveTextAreaControl.TextArea.InsertLeftMargin(1,
                                                            new CpuAddressMargin(ActiveTextAreaControl.TextArea,
                                                                                 GetDebugLine,
                                                                                 file.Project.Type == ProjectType.Snes ? 6 : 4));

            Menu         = new CodeMenu(events);
            Menu.Enabled = true;
            Menu.Name    = "Menu";
            Menu.Size    = new Size(108, 70);
            ActiveTextAreaControl.TextArea.ContextMenuStrip = Menu;
            Menu.Opening += (sender, e) =>
            {
                var word = GetAsmWord(ActiveTextAreaControl.Caret.Position);
                Menu.CurrentWord = word;
            };
            Menu.GoToDefinition = GoToSymbol;
            Menu.AddToWatch     = () =>
            {
                var word = GetAsmWord(ActiveTextAreaControl.Caret.Position);
                if (word == null)
                {
                    return;
                }
                switch (word.WordType)
                {
                case AsmWord.AsmWordType.NumberWord:
                case AsmWord.AsmWordType.NumberByte:
                    AddToWatch(word.Word, word.WordType == AsmWord.AsmWordType.NumberWord);
                    break;

                case AsmWord.AsmWordType.LabelReference:
                case AsmWord.AsmWordType.LabelAbsolute:
                case AsmWord.AsmWordType.LabelDefinition:
                case AsmWord.AsmWordType.AddressReference:
                    AddToWatch(word.Word, false);
                    break;
                }
            };
            Menu.BreakOnAccess = (type) =>
            {
                var word = GetAsmWord(ActiveTextAreaControl.Caret.Position);
                if (word == null)
                {
                    return;
                }
                switch (word.WordType)
                {
                case AsmWord.AsmWordType.NumberWord:
                case AsmWord.AsmWordType.NumberByte:
                    AddAddressBreakpoint(AddressReference.ParseNumber(word.Word), type);
                    break;

                case AsmWord.AsmWordType.LabelReference:
                case AsmWord.AsmWordType.LabelAbsolute:
                case AsmWord.AsmWordType.LabelDefinition:
                    AddSymbolBreakpoint(word.Word, type);
                    break;
                }
            };
            Menu.ToggleBreakpoint = ToggleBreakpointAtCaret;


            Document.HighlightingStrategy = new Ca65Highlighting(File.Project.Type);
            var testMarker = new TextMarker(0, 0, TextMarkerType.SolidBlock, Document.HighlightingStrategy.GetColorFor("Highlighted word").BackgroundColor);

            Document.MarkerStrategy.AddMarker(testMarker);

            /*ActiveTextAreaControl.TextArea.MouseMove += (sender, e) =>
             *      {
             *              //Document.MarkerStrategy.RemoveMarker(testMarker);
             *              //ActiveTextAreaControl.TextArea.Invalidate();
             *
             *              var textPosition = new Point(e.Location.X - ActiveTextAreaControl.TextArea.LeftMargins.Where(m => m.IsVisible).Sum(m => m.Size.Width), e.Location.Y);
             *              if (textPosition.X < 0 || textPosition.Y < 0) return;
             *
             *              var position = ActiveTextAreaControl.TextArea.TextView.GetLogicalPosition(textPosition);
             *              if (position.Line >= Document.TotalNumberOfLines) return;
             *
             *              var line = Document.GetLineSegment(position.Line);
             *              if (line == null) return;
             *              var word = line.GetWord(position.Column);
             *              if (word == null || word.IsWhiteSpace) return;
             *
             *              return;
             *              //word.SyntaxColor = new HighlightColor(word.Color, Color.DarkGray, true, false);
             *              Document.MarkerStrategy.AddMarker(testMarker);
             *              testMarker.Offset = word.Offset + line.Offset;
             *              testMarker.Length = word.Length;
             *              ActiveTextAreaControl.TextArea.Invalidate();
             *      };*/

            var lineAddressToolTip = new ToolTip();

            ActiveTextAreaControl.TextArea.ToolTipRequest += (s, e) =>
            {
                Document.MarkerStrategy.RemoveMarker(testMarker);
                ActiveTextAreaControl.TextArea.Invalidate();

                if (e.ToolTipShown || e.LogicalPosition.Line >= Document.TotalNumberOfLines)
                {
                    return;
                }
                var line = Document.GetLineSegment(e.LogicalPosition.Line);
                if (line == null)
                {
                    return;
                }
                lineAddressToolTip.Hide(FindForm());
                var word = e.InDocument ? GetAsmWord(e.LogicalPosition) : null;
                if (word == null || word.IsWhiteSpace || word.WordType == AsmWord.AsmWordType.Comment)
                {
                    var debugLine = GetDebugLine(line.LineNumber);
                    if (debugLine == null || debugLine.CpuAddress == null)
                    {
                        return;
                    }

                    testMarker.Offset = line.Offset;
                    testMarker.Length = line.Length;
                    Document.MarkerStrategy.AddMarker(testMarker);
                    //e.ShowToolTip(WatchValue.FormatHexAddress(debugLine.Address));
                    lineAddressToolTip.Show(
                        WatchValue.FormatHexAddress(debugLine.CpuAddress.Value),
                        FindForm(),
                        PointToScreen(new Point(-60, e.MousePosition.Y))
                        , 3000                         // TODO: Use a custom form object, not tooltips
                        );
                    return;
                }

                testMarker.Offset = word.Offset + line.Offset;
                testMarker.Length = word.Length;
                Document.MarkerStrategy.AddMarker(testMarker);
                ActiveTextAreaControl.TextArea.Invalidate();

                switch (word.WordType)
                {
                case AsmWord.AsmWordType.LabelAbsolute:
                case AsmWord.AsmWordType.LabelReference:
                case AsmWord.AsmWordType.LabelDefinition:
                case AsmWord.AsmWordType.Macro:
                    e.ShowToolTip(GetSymbolDescription(word.Word));
                    break;

                case AsmWord.AsmWordType.AddressReference:
                    e.ShowToolTip(GetParsedAddress(word.Word));
                    break;

                case AsmWord.AsmWordType.Command:
                    var command = Ca65Parser.GetCommandFromWord(word.Word);
                    if (command != null)
                    {
                        e.ShowToolTip(command.ToString());
                    }
                    break;

                case AsmWord.AsmWordType.Opcode:
                    var opcode = OpcodeParser.GetOpcodeFromWord(word.Word, File.Project.Type);
                    if (opcode != null)
                    {
                        e.ShowToolTip(opcode.ToString());
                    }
                    break;

                default:
                    e.ShowToolTip(word.Word);
                    break;
                }
            };

            Document.DocumentAboutToBeChanged += (s, arts) =>
            {
                _changedSinceLastCheck = true;
            };
            //Document.LineCountChanged += (sender, args) => RefreshErrorInfo();
            Document.LineLengthChanged += (s, args) =>
            {
                if (Document.MarkerStrategy.GetMarkers(args.LineSegment.Offset).Any(m => m is ErrorMarker))
                {
                    RefreshErrorInfo();
                }
            };

            ActiveTextAreaControl.Caret.PositionChanged += (s, a) =>
            {
                QueueCareInformation();

                if (ActiveTextAreaControl.Caret.Line == _caretLine)
                {
                    return;
                }
                _caretLine = ActiveTextAreaControl.Caret.Line;
                RefreshErrorInfo();
            };

            ActiveTextAreaControl.TextArea.KeyUp += delegate(object sender, KeyEventArgs e)
            {
                /*if (e.KeyCode == Program.Keys[Brewmaster.Settings.Feature.GoToDefinition])
                 * {
                 *      GoToSymbol();
                 *      return;
                 * }*/
                //if (e.KeyCode == Keys.Escape) return;
                if (NavigationKeys.Contains(e.KeyCode))
                {
                    return;
                }

                ShowIntellisense((char)e.KeyValue, 1);
                _forcedAutoCompleteWindow = false;

                HighlightOpcodeOnLine();
            };

            ActiveTextAreaControl.TextArea.IconBarMargin.MouseDown += (sender, mousepos, buttons) =>
            {
                if (buttons != MouseButtons.Left)
                {
                    return;
                }
                var line = ActiveTextAreaControl.TextArea.TextView.GetLogicalLine(mousepos.Y);
                AddBreakpointMarker(line);
                RefreshBreakpointsInProject();
            };
            Document.DocumentChanged += (sender, args) =>
            {
                var changed = false;
                foreach (var bp in Document.BookmarkManager.Marks.OfType <BreakpointMarker>())
                {
                    if (bp.GlobalBreakpoint.CurrentLine != bp.LineNumber + 1)
                    {
                        changed = true;
                    }
                    bp.GlobalBreakpoint.CurrentLine = bp.LineNumber + 1;
                }

                if (changed)
                {
                    RefreshBreakpointsInProject();
                }
            };
        }
Ejemplo n.º 19
0
 public FileNode(AsmProjectFile fileInfo)
 {
     UpdateFromFile(fileInfo);
 }
Ejemplo n.º 20
0
 public PipelineNode(AsmProjectFile fileInfo, string fileName)
 {
     _projectFile = fileInfo;
     Text         = fileName;
 }
Ejemplo n.º 21
0
        // END

        protected DataPipeline(AsmProjectFile file, DateTime?lastProcessed = null)
        {
            File          = file;
            LastProcessed = lastProcessed;
        }
Ejemplo n.º 22
0
 public SearchResultLineNode(AsmProjectFile file, SearchResult result, string query)
 {
     Query  = query;
     Result = result;
     Text   = string.Format("Line {0}, char {1}: ", result.Line, result.Column + 1);           // Columns are 1-indexed on the user end
 }
Ejemplo n.º 23
0
 public SearchResultNode(AsmProjectFile file, List <SearchResult> results, string query)
 {
     Text = string.Format("{0} ({1})", file.File.FullName, results.Count);
     Nodes.AddRange(results.Select(r => new SearchResultLineNode(file, r, query)).ToArray());
 }
Ejemplo n.º 24
0
 protected SaveableEditorWindow(MainForm form, AsmProjectFile file, Events events) : base(form, file, events)
 {
 }
Ejemplo n.º 25
0
 public ImageWindow(MainForm form, AsmProjectFile file, Events events) : base(form, file, events)
 {
     Pristine = true;
 }
Ejemplo n.º 26
0
 public ChrPipeline(AsmProjectFile file, string chrOutput, string paletteOutput, DateTime?lastProcessed = null) : base(file, lastProcessed)
 {
     ChrOutput         = chrOutput;
     PaletteOutput     = paletteOutput;
     PaletteAssignment = new Dictionary <Color, int>();
 }
Ejemplo n.º 27
0
 private void MoveFileToPipeline(AsmProjectFile file)
 {
     file.Mode         = CompileMode.ContentPipeline;
     _project.Pristine = false;
     RefreshTree();
 }