pascalabcnet/VisualPascalABCNET/Workbench/FileOperations.cs

606 lines
24 KiB
C#
Raw Normal View History

// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
2015-06-02 22:52:35 +03:00
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
2015-05-14 22:35:07 +03:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.FormsDesigner;
Implement programming languages integration functionality (#3001) * Make standardModules Dictionary instead of LanguageId usage * Create new common string constants for pascal language * Add LanguagesData class template * Move some compiler directive string constants to Compiler project * Extract LanguagesData class to separate file Also extracted RuntimeServiceModule (IO-modules) management to new functions. * Fix pabcnetc crashing (KeyNotFoundException) * Make similar change in pabcnetc_clear * Return PABCExtensions in DomConverter.cs * Return compiler string constants to Tree Converter * Rename MoveSystemUnitForward method * Rename system unit variable * Add new parser load error (localized versions) * Fix pascal language name constant * Add system units property to parsers * Add LanguageKits directory with a test file * Implement language integrator Был реализован загрузчик комплектов дополнительных языков (всех кроме Pascal). Был пересмотрен подход к реализации ParsersController и этот класс сделан синглтоном. Добавлена загрузка стандартных модулей языков в CompilerOptions. * Squashed commit of the following: commit 8f9dc7e5a0dbe2516a2af44d8ef843b7c30e2292 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Mon Mar 11 20:33:13 2024 +0300 fix #3050 commit 90363ced454216ef44c4919bb694b1a2c786b4b5 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Sun Mar 3 21:37:25 2024 +0300 Недобитки при сортировке строк commit c9d7ba7758d1cb4f41348f5cc9095b0350e0c005 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Sat Mar 2 13:32:14 2024 +0300 Order и OrderDescending для строк с Ordinal commit 6fbc0200bf4b413940a459f8b5d96c4597f561f4 Author: AlexanderZemlyak <92867056+AlexanderZemlyak@users.noreply.github.com> Date: Tue Feb 27 23:21:26 2024 +0300 Fix interface loop dependency check (#3047) Tests for problematic case were added commit e4d63bfef9ef22c3a21375b542d5540a593916e5 Author: bormant <bormant@mail.ru> Date: Tue Feb 27 23:18:25 2024 +0300 Fix typo: C (ru) -> C (en) (#3042) commit 0d37232d21ce81d3443ad680b21b865a2b2fe017 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Tue Feb 27 19:15:08 2024 +0300 School - исправление пустого диапазона простых и IP-адресов commit 9fd4c7f3388b7e9b5cd6dbae1d619fa11827e30d Merge: 3cca2a89 6027083b Author: Ivan Bondarev <ibond84@googlemail.com> Date: Wed Feb 21 20:57:10 2024 +0100 Merge branch 'master' of https://github.com/pascalabcnet/pascalabcnet commit 3cca2a894940cf585772464d55ac5f4bcf8e01ae Author: Ivan Bondarev <ibond84@googlemail.com> Date: Wed Feb 21 20:56:49 2024 +0100 fix in formatter
2024-03-13 22:16:40 +03:00
using PascalABCCompiler;
2015-05-14 22:35:07 +03:00
using VisualPascalABCPlugins;
using WeifenLuo.WinFormsUI.Docking;
namespace VisualPascalABC
{
public partial class Form1 : IWorkbenchFileService
{
List<string> temp_open_files = new List<string>();
public List<string> LastOpenFiles;
private VisualStates visualStates = new VisualStates();
2015-05-14 22:35:07 +03:00
internal Dictionary<string, CodeFileDocumentControl> OpenDocuments = new Dictionary<string, CodeFileDocumentControl>();
internal Dictionary<string, WebBrowserControl> OpenBrowserDocuments = new Dictionary<string, WebBrowserControl>();
private int MaxLastOpenFiles = 10;
private int MaxCharsInLastOpenFileName = 80;
public CodeFileDocumentControl OpenFileAndNoSelection(string FileName)
{
CodeFileDocumentControl tp = FindTab(FileName);
if (tp != null)
return tp;
tp = AddNewProgramToTab(MainDockPanel, FileName);
AddLastFile(FileName);
tp.LoadFromFile(FileName);
tp.DocumentSavedToDisk = true;
ShowAddedBreakpoints(tp);
return tp;
}
public bool OpenFile(string FileName, string PreferedFileName, bool not_open_designer=false)
{
CodeFileDocumentControl tp = FindTab(FileName);
bool IsNewFile = FileName == null;
if (tp == null)
{
if (!IsNewFile && !File.Exists(FileName))
{
MessageBox.Show(string.Format(PascalABCCompiler.StringResources.Get("!FILE_NOT_FOUND{0}"), FileName), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
visualStates.FileOpened = true;//?????
if (!IsNewFile)
openFileDialog1.InitialDirectory = Path.GetDirectoryName(FileName);
if (!IsBlankNewProgram(CurrentCodeFileDocument))
{
if (IsNewFile)
if (PreferedFileName == null)
FileName = InstNameNewProgramm(MainDockPanel);
else
FileName = PreferedFileName;
tp = AddNewProgramToTab(MainDockPanel, FileName);
}
else
if (!IsNewFile)
{
CheckErrorListAndClear(CurrentCodeFileDocument.FileName);
WorkbenchServiceFactory.CodeCompletionParserController.CloseFile(CurrentCodeFileDocument.FileName);
OpenDocuments.Remove(Tools.FileNameToLower(CurrentCodeFileDocument.FileName));
CurrentCodeFileDocument.FileName = FileName;
SetTabPageText(CurrentCodeFileDocument);
if (!WorkbenchServiceFactory.RunService.HasRunArgument(FileName.ToLower()))
WorkbenchServiceFactory.RunService.AddRunArgument(FileName.ToLower(), "");
tp = CurrentCodeFileDocument;
}
if (!IsNewFile)
{
AddLastFile(FileName);
WatcherService.AddWatcher(FileName);
int ticks = Environment.TickCount;
tp.LoadFromFile(FileName);
//MessageBox.Show((Environment.TickCount-ticks).ToString());
tp.DocumentSavedToDisk = true;
//ivan added
ShowAddedBreakpoints(tp);
//ShowAddedBreakpoints(tabControl1.TabPages[TabIndex]);
}
//CloseButtonsEnabled = OpenDocuments.Count > 1;
ChangedSelectedTab();
Деактивация кнопок, связанных с Intellisense, для языков без Intellisense + разделение ILanguageInformation на два интерфейса (#3378) * Refactor language information classes * Implement SimpleLanguageInformation abstract class * Move some properties to SimpleLanguageInformation * Implement format and debug buttons disabling if Intellisense is not supported for current language * Add Intellisense available check in FormsExtensions to deactivate menu items if needed * Change function interfaces in VisibilityService * Replace CodeCompletionController.CurrentParser null checks with IntellisenseAvailable method call * Refactor IParser and BaseParser to deduplicate code * Fix BuildTreeInSpecialMode in SPythonParser * Add SimpleParser class for new languages without Intellisense * Delete duplicate SetDebugButtonsEnabled function * Add Intellisense available check in RunService when attaching debugger * Delete inner check in SetDebugButtonsEnabled to improve architecture * Change CurrentParser property in CodeCompletion to be CurrentLanguage * Divide ILanguageInformation into two interfaces (creating new ILanguageIntellisenseSupport) * Fix LanguageIntellisenseSupport initialization in BaseLanguage * Fix RunService fictive_attach logic * Disable Intellisense parsing for languages without Intellisense support * Add DefaultLanguageInformation abstract class * Add default implementation for SetSemanticConstants in BaseLanguage * Simplify IParser interface * Update developer guide documentation
2026-01-27 22:25:28 +03:00
if (FileName != null // SS 09.08.08
&& CodeCompletion.CodeCompletionController.IntellisenseAvailable())
2015-05-14 22:35:07 +03:00
WorkbenchServiceFactory.CodeCompletionParserController.RegisterFileForParsing(FileName);
}
if (tp != null)
{
if (MainDockPanel.ActiveDocument != tp)
{
CurrentCodeFileDocument = tp;
}
}
if (FileName != null)
{
string filename = Tools.FileNameToLower(FileName);
if (OpenDocuments.ContainsKey(filename))
OpenDocuments[filename] = tp;
else
OpenDocuments.Add(filename, tp);
CloseButtonsEnabled = OpenDocuments.Count > 1;//Ivan 09.08.08 err 195
}
visualStates.FileOpened = false;
//ssyy
if (!IsNewFile)
{
if (Path.GetExtension(FileName) == ".pas")
Implement programming languages integration functionality (#3001) * Make standardModules Dictionary instead of LanguageId usage * Create new common string constants for pascal language * Add LanguagesData class template * Move some compiler directive string constants to Compiler project * Extract LanguagesData class to separate file Also extracted RuntimeServiceModule (IO-modules) management to new functions. * Fix pabcnetc crashing (KeyNotFoundException) * Make similar change in pabcnetc_clear * Return PABCExtensions in DomConverter.cs * Return compiler string constants to Tree Converter * Rename MoveSystemUnitForward method * Rename system unit variable * Add new parser load error (localized versions) * Fix pascal language name constant * Add system units property to parsers * Add LanguageKits directory with a test file * Implement language integrator Был реализован загрузчик комплектов дополнительных языков (всех кроме Pascal). Был пересмотрен подход к реализации ParsersController и этот класс сделан синглтоном. Добавлена загрузка стандартных модулей языков в CompilerOptions. * Squashed commit of the following: commit 8f9dc7e5a0dbe2516a2af44d8ef843b7c30e2292 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Mon Mar 11 20:33:13 2024 +0300 fix #3050 commit 90363ced454216ef44c4919bb694b1a2c786b4b5 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Sun Mar 3 21:37:25 2024 +0300 Недобитки при сортировке строк commit c9d7ba7758d1cb4f41348f5cc9095b0350e0c005 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Sat Mar 2 13:32:14 2024 +0300 Order и OrderDescending для строк с Ordinal commit 6fbc0200bf4b413940a459f8b5d96c4597f561f4 Author: AlexanderZemlyak <92867056+AlexanderZemlyak@users.noreply.github.com> Date: Tue Feb 27 23:21:26 2024 +0300 Fix interface loop dependency check (#3047) Tests for problematic case were added commit e4d63bfef9ef22c3a21375b542d5540a593916e5 Author: bormant <bormant@mail.ru> Date: Tue Feb 27 23:18:25 2024 +0300 Fix typo: C (ru) -> C (en) (#3042) commit 0d37232d21ce81d3443ad680b21b865a2b2fe017 Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Tue Feb 27 19:15:08 2024 +0300 School - исправление пустого диапазона простых и IP-адресов commit 9fd4c7f3388b7e9b5cd6dbae1d619fa11827e30d Merge: 3cca2a89 6027083b Author: Ivan Bondarev <ibond84@googlemail.com> Date: Wed Feb 21 20:57:10 2024 +0100 Merge branch 'master' of https://github.com/pascalabcnet/pascalabcnet commit 3cca2a894940cf585772464d55ac5f4bcf8e01ae Author: Ivan Bondarev <ibond84@googlemail.com> Date: Wed Feb 21 20:56:49 2024 +0100 fix in formatter
2024-03-13 22:16:40 +03:00
{
2015-05-14 22:35:07 +03:00
string XMLFile = Path.ChangeExtension(FileName, string_consts.xml_form_extention);
if (File.Exists(XMLFile))
{
if (not_open_designer)
{
if (VisualPascalABC.VisualPABCSingleton.MainForm._currentCodeFileDocument.DesignerAndCodeTabs != null)
{
//VisualPascalABC.Form1.Form1_object.CahngedSelectedTab();
VisualPascalABC.VisualPABCSingleton.MainForm._currentCodeFileDocument.DesignerAndCodeTabs.SelectedTab =
VisualPascalABC.VisualPABCSingleton.MainForm._currentCodeFileDocument.TextPage;
}
}
else
_currentCodeFileDocument.AddDesigner(XMLFile);
}
}
}
return true;
}
public void OpenFileWithForm()
{
OpenFile(null, null);
CurrentCodeFileDocument.AddDesigner(null);
}
public CodeFileDocumentControl OpenFileForDebug(string FileName)
{
CodeFileDocumentControl tp = FindTab(FileName);
bool IsNewFile = FileName == null;
if (tp == null)
{
visualStates.FileOpened = true;//?????
if (!IsNewFile && !File.Exists(FileName))
{
Refactoring of Compiler.cs (#2984) * Add first comments * Finish commenting for Compile and CompileUnit * Write TODO sections * Add a few clarifications * splitted some functions from compile * Written some methods from Compile to functions * Update variable names * Refactor - stage 1 Refactor GetUsesSection and IsPossibleNameSpace * Refactor - stage 2 Rename a few functions and variables * Correct an inaccuracy * Added comments, look through CompileUnit * Rename a few functions and add new comments * Split CompileUnit to Subfunctions Add IsUnitCompiled, IsUnitInPCU, InitializeNewUnit, GetSourceCode, GenSyntaxTree, GenUnitDocumentation, CheckDLLDirectiveOnlyForLibraries, MatchErrorsToBadNodes, CheckIfUnitModule, SetUseDLLForSystemUnits, CompileInterfaceDependencies, CompileCurrentUnitInterface, GetImplementationUsesSection, CompileImplementationDependencies, CompileCurrentUnitImplementation * Added some TODOs * Return uses_unit_in original name Renaming of syntax tree nodes leads to internal compiler errors * Extract GenerateILCode method * Add checking if recompilation needed method Needs to be discussed and revised * Add functions for catch blocks in Compile * Extract building semantic tree method Creating main function to be moved to another class * Rename UnitsSortedList * Edit CompileUnitsFromDelayedList method * Change a few variable names, make CreateRCFile function and add comments * Make code more "user-friendly" * Add TODOs 31.11.23 * Create PrebuildSemanticTreeActionsMethod * Refactor semantic checks section in initialize new unit method * Refactor Adding standard units to uses method * Return file_name and compiler_directives original names to avoid internal compilation errors * Refactor GetReferences Method * Initial refactoring of IncludeNamespaces function * Create three more methods and wrap important code in regions * Add TODO's * Resolve merge conflicts * Add returned value to ConstructSyntaxTree method * Fix UnitsSortedList NotFoundError in PCUWriter * Workaround commit * Update PABCSystem after tests' changes * Rename syntax trees in some methods * Delete CurrentSyntaxUnit variable * Revert unnecessary project files changes * Squashed commit of the following: commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:29 2023 +0300 added links to identarranger commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:03 2023 +0300 Change extension for verybasic to yavb commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:33:57 2023 +0300 Change Program Example commit 86971488341ed6bf13c39e13a513d7ac0c51c285 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:28:59 2023 +0300 Add IndentArranger to Compile commit 2ce50bbbf9db22c4243b247b870f6935ce206d26 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 17 10:00:31 2023 +0300 Add Semicolon After Each Statement commit 796309d340e8d8ba730ff9418fa376f34fb7fd36 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Wed Nov 15 18:49:11 2023 +0300 Add Alpha Version of Python-style If-statement commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227 Merge: ab4ce5b0 0162b637 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:54:26 2023 +0300 Merge branch 'IndentArranger' into VeryBasicLanguage commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:53:51 2023 +0300 Fixes from seminar commit af74012289d0d08517c13499a2a66cb543fc06d2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 18:57:29 2023 +0300 finally working! fully implemented compatibility commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 11:58:16 2023 +0300 more compatibility with pabc Now verybasic statements translate to pascal compiler added .bat script for autobuilding verybasic commit 0162b6376b8fe970704f26213bf9f0f670dfb12e Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:06:14 2023 +0300 Update test.txt commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:05:36 2023 +0300 Add Indent and Unindent Keywords to Generated File commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 10 21:25:52 2023 +0300 Add Generation of Output File commit 306f033d0176ab559e3622b8505427dbe2e0e203 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:42:18 2023 +0300 Update IndentArranger.sln commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:41:22 2023 +0300 Add IndentArranger commit 1f4556c4573dae154fcc167b41ff6ab9e8122136 Author: Владислав Крылов <krylov@sfedu.ru> Date: Mon Nov 6 22:48:36 2023 +0300 Made my own VeryBasicParser project Copied some code from SaushkinParser Tried to compile it and implement into Pascal Doesn't work due to grammatik issue * Squashed commit of the following: commit 4e73d9ac3ffef68312f06a74dc83afffcf3ccbee Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 15:08:10 2023 +0300 Fixed GPPG (i think so at least) commit e5cfc220828b37fb2f35e565683019716ec3f0ce Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:44:27 2023 +0300 Update Compiler.cs commit 4698e2e75a5f3b4f523a8bc7733a50e8abb4fca1 Merge: 22aaf2b2 f4d7599f Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:54 2023 +0300 Merge branch 'IndentArrangerTemp' into VeryBasicLanguage commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:29 2023 +0300 added links to identarranger commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:03 2023 +0300 Change extension for verybasic to yavb commit 22aaf2b2508278a9ffce525ffed52419bf72c23f Merge: c326174f 61294c6e Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:26:36 2023 +0300 Merge branch 'IndentArrangerTemp' into VeryBasicLanguage commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:33:57 2023 +0300 Change Program Example commit 86971488341ed6bf13c39e13a513d7ac0c51c285 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:28:59 2023 +0300 Add IndentArranger to Compile commit c326174ff5ecccf9c4f76d58aea4653f047af049 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 19 15:03:19 2023 +0300 Added UniversalParserHelper and GPPG ShiftReduceParser moved to another project UniversalParserHelper project added, most of it copied from SaushkinParser commit 2ce50bbbf9db22c4243b247b870f6935ce206d26 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 17 10:00:31 2023 +0300 Add Semicolon After Each Statement commit 796309d340e8d8ba730ff9418fa376f34fb7fd36 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Wed Nov 15 18:49:11 2023 +0300 Add Alpha Version of Python-style If-statement commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227 Merge: ab4ce5b0 0162b637 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:54:26 2023 +0300 Merge branch 'IndentArranger' into VeryBasicLanguage commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:53:51 2023 +0300 Fixes from seminar commit af74012289d0d08517c13499a2a66cb543fc06d2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 18:57:29 2023 +0300 finally working! fully implemented compatibility commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 11:58:16 2023 +0300 more compatibility with pabc Now verybasic statements translate to pascal compiler added .bat script for autobuilding verybasic commit 0162b6376b8fe970704f26213bf9f0f670dfb12e Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:06:14 2023 +0300 Update test.txt commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:05:36 2023 +0300 Add Indent and Unindent Keywords to Generated File commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 10 21:25:52 2023 +0300 Add Generation of Output File commit 306f033d0176ab559e3622b8505427dbe2e0e203 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:42:18 2023 +0300 Update IndentArranger.sln commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:41:22 2023 +0300 Add IndentArranger commit 1f4556c4573dae154fcc167b41ff6ab9e8122136 Author: Владислав Крылов <krylov@sfedu.ru> Date: Mon Nov 6 22:48:36 2023 +0300 Made my own VeryBasicParser project Copied some code from SaushkinParser Tried to compile it and implement into Pascal Doesn't work due to grammatik issue * Changed GPPG project NET Framework version, added .dll to gitignore * Adding UniversalParserHelper to project, trying to include VeryBasic * Managed dependencies and got VeryBasicLanguage to work * Change extension of a test program * Rebuild changes What should be added to .gitignore? * Fix bug related to err0524_res_unit.pas * Rebuild Parser * Change Indent and Unindent tokens * Add Symbol Table to ParserABC.y * Change Indent Space Number to 2 * Add While Loop * Add Some Operations to Parser * Make Initialization Node at the Beginning of a program * Create Grammar.txt * Test program added * Add ELIF and SyntaxHighlight * Fix TableSymbol * Add Division * Add Method Call * Add For Loop * Rename SPython Parser Folder * Add documented comments for CompileUnit method * Added Errors to SPython Added Errors.cs Removed link to PABCSaushkinParser Minor fixes * Create default constructor for SourceContext * Move null check of currentUnit to upper level in CompileUnit * Move CreateMainFunction method from Compiler to TreeConverter class * Add gppg and parserhelper to visualpascalabcnet dependencies * Updated installer files to include GPPG and UniversalParserHelper * Rename GPPG to ShiftReduceParser * Fix ShiftReduceParser project dependencies * Fix ShiftReduceParserDependencies second iteration * Workaround commit * Update PABCSystem after tests' changes * Refactor ConvertDirectives method * Get rid of legacy standard modules code * Return varBeginOffset and beginOffset calculation to Compiler class Размещение метода в SyntaxTreeToSemanticTreeConverter не целесообразно. В комментарии видимо имелось в виду что-то другое. * Workaround commit * Update PABCSystem after tests' changes * Revert SPython changes Оставляем только изменения связанные с рефакторингом. * Update .gitignore Co-authored-by: Sun Serega <sunserega2@gmail.com> * Resolve a few Sun Serega treds * Delete comments in ParsersController.cs * Replace specific path with path variable in Studio.bat * Add comment in Studio.bat file and return FileName in CompilerError.cs * Fix TreeSubsidiary.cs encoding and sectCore.nsh indents * Return old version of TestRunner.exe * Rename some variables and polish a few methods * Uncomment accidentally commented code * Replace spaces with tabs * Changed dll name from GPPG * Revert "Changed dll name from GPPG" This reverts commit c485cc8cb787809b7e9dfa8a361e75f17ed39893. * Update .gitignore * Delete Libraries/ShiftReduceParser.dll * Delete bin\ShiftReduceParser.dll * Replace tabs with spaces * Update encoding in Studio.bat * Fix bug with PABCrtl excluded files * Refactor StandardModule class * Add null checks to make debuging easier * Delete unnecessary null checks in SymTable.cs --------- Co-authored-by: Владислав Крылов <krylov@sfedu.ru> Co-authored-by: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Co-authored-by: Sun Serega <sunserega2@gmail.com>
2023-12-18 22:33:27 +03:00
//MessageBox.Show(string.Format(PascalABCCompiler.StringResources.Get("!FILE_NOT_FOUND{0}"), file_name), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
2015-05-14 22:35:07 +03:00
bool exists = false;
foreach (string s in search_debug_paths)
{
FileName = String.Concat(s, Path.DirectorySeparatorChar, Path.GetFileName(FileName));
if (File.Exists(FileName))
{
tp = FindTab(FileName);
if (tp != null)
{
CurrentCodeFileDocument = tp;
//(CurrentTabPage.ag as CodeFileDocumentControl).DocumentSavedToDisk = !IsNewFile;
visualStates.FileOpened = false;
AddDebugPage(CurrentCodeFileDocument);
return CurrentCodeFileDocument;
}
else
{
exists = true;
break;
}
}
}
if (!exists)
{
visualStates.FileOpened = false;
return null;
}
}
openFileDialog1.InitialDirectory = Path.GetDirectoryName(FileName);
if (!IsBlankNewProgram(CurrentCodeFileDocument))
{
if (IsNewFile)
FileName = InstNameNewProgramm(MainDockPanel);
tp = AddNewProgramToTab(MainDockPanel, FileName);
}
else
if (!IsNewFile)
{
Refactoring of Compiler.cs (#2984) * Add first comments * Finish commenting for Compile and CompileUnit * Write TODO sections * Add a few clarifications * splitted some functions from compile * Written some methods from Compile to functions * Update variable names * Refactor - stage 1 Refactor GetUsesSection and IsPossibleNameSpace * Refactor - stage 2 Rename a few functions and variables * Correct an inaccuracy * Added comments, look through CompileUnit * Rename a few functions and add new comments * Split CompileUnit to Subfunctions Add IsUnitCompiled, IsUnitInPCU, InitializeNewUnit, GetSourceCode, GenSyntaxTree, GenUnitDocumentation, CheckDLLDirectiveOnlyForLibraries, MatchErrorsToBadNodes, CheckIfUnitModule, SetUseDLLForSystemUnits, CompileInterfaceDependencies, CompileCurrentUnitInterface, GetImplementationUsesSection, CompileImplementationDependencies, CompileCurrentUnitImplementation * Added some TODOs * Return uses_unit_in original name Renaming of syntax tree nodes leads to internal compiler errors * Extract GenerateILCode method * Add checking if recompilation needed method Needs to be discussed and revised * Add functions for catch blocks in Compile * Extract building semantic tree method Creating main function to be moved to another class * Rename UnitsSortedList * Edit CompileUnitsFromDelayedList method * Change a few variable names, make CreateRCFile function and add comments * Make code more "user-friendly" * Add TODOs 31.11.23 * Create PrebuildSemanticTreeActionsMethod * Refactor semantic checks section in initialize new unit method * Refactor Adding standard units to uses method * Return file_name and compiler_directives original names to avoid internal compilation errors * Refactor GetReferences Method * Initial refactoring of IncludeNamespaces function * Create three more methods and wrap important code in regions * Add TODO's * Resolve merge conflicts * Add returned value to ConstructSyntaxTree method * Fix UnitsSortedList NotFoundError in PCUWriter * Workaround commit * Update PABCSystem after tests' changes * Rename syntax trees in some methods * Delete CurrentSyntaxUnit variable * Revert unnecessary project files changes * Squashed commit of the following: commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:29 2023 +0300 added links to identarranger commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:03 2023 +0300 Change extension for verybasic to yavb commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:33:57 2023 +0300 Change Program Example commit 86971488341ed6bf13c39e13a513d7ac0c51c285 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:28:59 2023 +0300 Add IndentArranger to Compile commit 2ce50bbbf9db22c4243b247b870f6935ce206d26 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 17 10:00:31 2023 +0300 Add Semicolon After Each Statement commit 796309d340e8d8ba730ff9418fa376f34fb7fd36 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Wed Nov 15 18:49:11 2023 +0300 Add Alpha Version of Python-style If-statement commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227 Merge: ab4ce5b0 0162b637 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:54:26 2023 +0300 Merge branch 'IndentArranger' into VeryBasicLanguage commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:53:51 2023 +0300 Fixes from seminar commit af74012289d0d08517c13499a2a66cb543fc06d2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 18:57:29 2023 +0300 finally working! fully implemented compatibility commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 11:58:16 2023 +0300 more compatibility with pabc Now verybasic statements translate to pascal compiler added .bat script for autobuilding verybasic commit 0162b6376b8fe970704f26213bf9f0f670dfb12e Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:06:14 2023 +0300 Update test.txt commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:05:36 2023 +0300 Add Indent and Unindent Keywords to Generated File commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 10 21:25:52 2023 +0300 Add Generation of Output File commit 306f033d0176ab559e3622b8505427dbe2e0e203 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:42:18 2023 +0300 Update IndentArranger.sln commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:41:22 2023 +0300 Add IndentArranger commit 1f4556c4573dae154fcc167b41ff6ab9e8122136 Author: Владислав Крылов <krylov@sfedu.ru> Date: Mon Nov 6 22:48:36 2023 +0300 Made my own VeryBasicParser project Copied some code from SaushkinParser Tried to compile it and implement into Pascal Doesn't work due to grammatik issue * Squashed commit of the following: commit 4e73d9ac3ffef68312f06a74dc83afffcf3ccbee Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 15:08:10 2023 +0300 Fixed GPPG (i think so at least) commit e5cfc220828b37fb2f35e565683019716ec3f0ce Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:44:27 2023 +0300 Update Compiler.cs commit 4698e2e75a5f3b4f523a8bc7733a50e8abb4fca1 Merge: 22aaf2b2 f4d7599f Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:54 2023 +0300 Merge branch 'IndentArrangerTemp' into VeryBasicLanguage commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:29 2023 +0300 added links to identarranger commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:43:03 2023 +0300 Change extension for verybasic to yavb commit 22aaf2b2508278a9ffce525ffed52419bf72c23f Merge: c326174f 61294c6e Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 22 11:26:36 2023 +0300 Merge branch 'IndentArrangerTemp' into VeryBasicLanguage commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:33:57 2023 +0300 Change Program Example commit 86971488341ed6bf13c39e13a513d7ac0c51c285 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Tue Nov 21 09:28:59 2023 +0300 Add IndentArranger to Compile commit c326174ff5ecccf9c4f76d58aea4653f047af049 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 19 15:03:19 2023 +0300 Added UniversalParserHelper and GPPG ShiftReduceParser moved to another project UniversalParserHelper project added, most of it copied from SaushkinParser commit 2ce50bbbf9db22c4243b247b870f6935ce206d26 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 17 10:00:31 2023 +0300 Add Semicolon After Each Statement commit 796309d340e8d8ba730ff9418fa376f34fb7fd36 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Wed Nov 15 18:49:11 2023 +0300 Add Alpha Version of Python-style If-statement commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227 Merge: ab4ce5b0 0162b637 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:54:26 2023 +0300 Merge branch 'IndentArranger' into VeryBasicLanguage commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56 Author: Владислав Крылов <krylov@sfedu.ru> Date: Wed Nov 15 16:53:51 2023 +0300 Fixes from seminar commit af74012289d0d08517c13499a2a66cb543fc06d2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 18:57:29 2023 +0300 finally working! fully implemented compatibility commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2 Author: Владислав Крылов <krylov@sfedu.ru> Date: Sun Nov 12 11:58:16 2023 +0300 more compatibility with pabc Now verybasic statements translate to pascal compiler added .bat script for autobuilding verybasic commit 0162b6376b8fe970704f26213bf9f0f670dfb12e Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:06:14 2023 +0300 Update test.txt commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Sun Nov 12 10:05:36 2023 +0300 Add Indent and Unindent Keywords to Generated File commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Fri Nov 10 21:25:52 2023 +0300 Add Generation of Output File commit 306f033d0176ab559e3622b8505427dbe2e0e203 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:42:18 2023 +0300 Update IndentArranger.sln commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5 Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Date: Thu Nov 9 20:41:22 2023 +0300 Add IndentArranger commit 1f4556c4573dae154fcc167b41ff6ab9e8122136 Author: Владислав Крылов <krylov@sfedu.ru> Date: Mon Nov 6 22:48:36 2023 +0300 Made my own VeryBasicParser project Copied some code from SaushkinParser Tried to compile it and implement into Pascal Doesn't work due to grammatik issue * Changed GPPG project NET Framework version, added .dll to gitignore * Adding UniversalParserHelper to project, trying to include VeryBasic * Managed dependencies and got VeryBasicLanguage to work * Change extension of a test program * Rebuild changes What should be added to .gitignore? * Fix bug related to err0524_res_unit.pas * Rebuild Parser * Change Indent and Unindent tokens * Add Symbol Table to ParserABC.y * Change Indent Space Number to 2 * Add While Loop * Add Some Operations to Parser * Make Initialization Node at the Beginning of a program * Create Grammar.txt * Test program added * Add ELIF and SyntaxHighlight * Fix TableSymbol * Add Division * Add Method Call * Add For Loop * Rename SPython Parser Folder * Add documented comments for CompileUnit method * Added Errors to SPython Added Errors.cs Removed link to PABCSaushkinParser Minor fixes * Create default constructor for SourceContext * Move null check of currentUnit to upper level in CompileUnit * Move CreateMainFunction method from Compiler to TreeConverter class * Add gppg and parserhelper to visualpascalabcnet dependencies * Updated installer files to include GPPG and UniversalParserHelper * Rename GPPG to ShiftReduceParser * Fix ShiftReduceParser project dependencies * Fix ShiftReduceParserDependencies second iteration * Workaround commit * Update PABCSystem after tests' changes * Refactor ConvertDirectives method * Get rid of legacy standard modules code * Return varBeginOffset and beginOffset calculation to Compiler class Размещение метода в SyntaxTreeToSemanticTreeConverter не целесообразно. В комментарии видимо имелось в виду что-то другое. * Workaround commit * Update PABCSystem after tests' changes * Revert SPython changes Оставляем только изменения связанные с рефакторингом. * Update .gitignore Co-authored-by: Sun Serega <sunserega2@gmail.com> * Resolve a few Sun Serega treds * Delete comments in ParsersController.cs * Replace specific path with path variable in Studio.bat * Add comment in Studio.bat file and return FileName in CompilerError.cs * Fix TreeSubsidiary.cs encoding and sectCore.nsh indents * Return old version of TestRunner.exe * Rename some variables and polish a few methods * Uncomment accidentally commented code * Replace spaces with tabs * Changed dll name from GPPG * Revert "Changed dll name from GPPG" This reverts commit c485cc8cb787809b7e9dfa8a361e75f17ed39893. * Update .gitignore * Delete Libraries/ShiftReduceParser.dll * Delete bin\ShiftReduceParser.dll * Replace tabs with spaces * Update encoding in Studio.bat * Fix bug with PABCrtl excluded files * Refactor StandardModule class * Add null checks to make debuging easier * Delete unnecessary null checks in SymTable.cs --------- Co-authored-by: Владислав Крылов <krylov@sfedu.ru> Co-authored-by: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com> Co-authored-by: Sun Serega <sunserega2@gmail.com>
2023-12-18 22:33:27 +03:00
//CheckErrorListAndClear((tabControl1.TabPages[TabIndex].ag as CodeFileDocumentControl).file_name);
2015-05-14 22:35:07 +03:00
CurrentCodeFileDocument.FileName = FileName;
if (!ProjectFactory.Instance.ProjectLoaded)
SetTabPageText(CurrentCodeFileDocument);
tp = CurrentCodeFileDocument;
}
if (!IsNewFile)
{
AddLastFile(FileName);
WatcherService.AddWatcher(FileName);
tp.LoadFromFile(FileName);
tp.DocumentSavedToDisk = true;
//ivan added
ShowAddedBreakpoints(tp);
//ShowAddedBreakpoints(tabControl1.TabPages[TabIndex]);
}
CloseButtonsEnabled = OpenDocuments.Count > 1;
}
if (tp != null)
{
CurrentCodeFileDocument = tp;
if (tp.DesignerAndCodeTabs != null)
tp.DesignerAndCodeTabs.SelectedTab = tp.TextPage;
//(CurrentTabPage.ag as CodeFileDocumentControl).DocumentSavedToDisk = !IsNewFile;
}
visualStates.FileOpened = false;
AddDebugPage(CurrentCodeFileDocument);
//CahngedSelectedTab();
return CurrentCodeFileDocument;
}
ICodeFileDocument VisualPascalABCPlugins.IWorkbenchFileService.OpenFileForDebug(string FileName)
{
return OpenFileForDebug(FileName);
}
public void RenameFile(string OldFileName, string NewFileName)
{
CodeFileDocumentControl cfdc = FindTab(OldFileName);
if (cfdc == null)
{
try
{
File.Copy(OldFileName, NewFileName);
File.Delete(OldFileName);
}
catch
{
}
return;
}
SaveFileAs(cfdc, NewFileName);
try
{
File.Delete(OldFileName);
}
catch
{
}
}
public void CloseFile(CodeFileDocumentControl tp, bool ask_for_save = true)
{
string FileName = tp.FileName.ToLower();
string exeName = tp.EXEFileName;
if (WorkbenchServiceFactory.RunService.IsRun(exeName))
WorkbenchServiceFactory.RunService.Stop(exeName);
if (ask_for_save)
if (tp.DocumentChanged && !tp.FromMetadata)
if (!QuestionAndSaveFile(tp))
{
SaveCanceled = true;
return;
}
if (tp.DocumentSavedToDisk)
AddLastFile(CurrentSourceFileName);
if (LastSelectedTab != null && !LastSelectedTab.IsDisposed)
CurrentCodeFileDocument = LastSelectedTab;
if (tp == ActiveCodeFileDocument)
ActiveCodeFileDocument = null;
OutputTextBoxs.Remove(tp);
OpenDocuments.Remove(Tools.FileNameToLower(tp.FileName));
//RunArgumentsTable.Remove(tp);
tp.Dispose();
CheckErrorListAndClear(FileName);
WatcherService.RemoveWatcher(FileName);
if (OpenDocuments.Count == 1)
{
CloseButtonsEnabled = false;
}
SaveAllButtonsEnabled = !AllSaved();
WorkbenchServiceFactory.CodeCompletionParserController.CloseFile(FileName);
WorkbenchServiceFactory.CodeCompletionParserController.ParseInformationUpdated -= tp.TextEditor.UpdateFolding;
CodeCompletionKeyHandler.Detach(tp.TextEditor);
tp.TextEditor.Document.DocumentChanged -= tp.Document_DocumentChanged;
tp.TextEditor.Document.TextContent = "";
tp.TextEditor.Document.DocumentChanged += tp.Document_DocumentChanged;
GC.Collect();
}
public void CloseFile(string FileName)
{
CodeFileDocumentControl tp = FindTab(FileName);
if (tp != null)
{
CloseFile(tp);
if (OpenDocuments.Count == 0)
{
OpenFile(null, null);
}
}
}
private void CloseFilesAndSaveState()
{
foreach (CodeFileDocumentControl cfdc in this.OpenDocuments.Values)
{
temp_open_files.Add(cfdc.FileName);
}
CloseAllButThis(null);
}
public void ReloadFile(string FileName)
{
CodeFileDocumentControl tab = FindTab(FileName);
if (tab != null)
{
tab.LoadFromFile(FileName);
tab.DocumentChanged = false;
SetTabPageText(tab);
}
}
private void RestoreFiles()
{
foreach (string s in temp_open_files)
{
if (File.Exists(s))
OpenFile(s, null);
else
OpenFile(null, null);
}
temp_open_files.Clear();
}
public void SetFileAsChanged(string FileName)
{
CodeFileDocumentControl tab = FindTab(FileName);
if (tab != null)
{
tab.DocumentChanged = true;
SetTabPageText(tab);
}
}
private void SaveSelFile(CodeFileDocumentControl TbPage)
{
SaveSelFileAs(TbPage, TbPage.FileName);
}
private void SaveSelFileAs(CodeFileDocumentControl TbPage, string FileName)
{
if (!TbPage.DocumentSavedToDisk)
ExecuteSaveAs(TbPage);
else
SaveFileAs(TbPage, FileName);
}
internal void SaveFileAs(CodeFileDocumentControl TbPage, string FileName)
{
try
{
if (TbPage.DesignerAndCodeTabs != null)
{
TbPage.GenerateDesignerCode(null);
}
CodeFileDocumentControl dt = TbPage;
WatcherService.DisableWatcher(FileName);
//dt.TextEditor.Encoding = VisualEnvironmentCompiler.DefaultFileEncoding;
2017-11-26 19:35:27 +03:00
if (!dt.TextEditor.CanSaveWithCurrentEncoding() || true)
2015-05-14 22:35:07 +03:00
{
dt.TextEditor.Encoding = Encoding.UTF8;
dt.TextEditor.SaveFile(FileName);
dt.TextEditor.Encoding = VisualEnvironmentCompiler.DefaultFileEncoding;
}
else
dt.TextEditor.SaveFile(FileName);
WatcherService.EnableWatcher(FileName);
OpenDocuments.Remove(Tools.FileNameToLower(dt.FileName));
OpenDocuments.Add(Tools.FileNameToLower(FileName), TbPage);
WorkbenchServiceFactory.CodeCompletionParserController.RenameFile(dt.FileName, FileName);
TbPage.SaveFormFile(FileName);
dt.DocumentChanged = false;
dt.FileName = FileName;
dt.DocumentSavedToDisk = true;
dt.SetHighlightingStrategyForFile(FileName);
SetTabPageText(TbPage);
if (!WorkbenchServiceFactory.RunService.HasRunArgument(FileName.ToLower()))
WorkbenchServiceFactory.RunService.AddRunArgument(FileName.ToLower(), "");
if (TbPage == CurrentCodeFileDocument)
UpdateSaveButtonsEnabled();
}
catch (Exception)
2015-05-14 22:35:07 +03:00
{
MessageBox.Show(String.Format(Form1StringResources.Get("SAVE_FILE_ERROR_TEXT{0}"), FileName), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
2015-10-11 19:50:08 +03:00
public bool SaveAll(bool Question)
2015-05-14 22:35:07 +03:00
{
if (ProjectFactory.Instance.ProjectLoaded && Question)
{
return SaveAllInProject() != 2;
}
SaveCanceled = false;
CodeFileDocumentControl[] l = new CodeFileDocumentControl[OpenDocuments.Values.Count];
OpenDocuments.Values.CopyTo(l, 0);
foreach (CodeFileDocumentControl tp in l)
if (tp.DocumentChanged && !tp.FromMetadata)
if (Question)
{
if (!QuestionAndSaveFile(tp))
{
SaveCanceled = true;
return false;
}
}
else
SaveSelFile(tp);
UpdateSaveButtonsEnabled();
return true;
}
void IWorkbenchFileService.CloseAllButThis(ICodeFileDocument nonCloseTab)
{
this.CloseAllButThis(nonCloseTab as CodeFileDocumentControl);
}
2015-05-14 22:35:07 +03:00
void CloseAllButThis(CodeFileDocumentControl nonCloseTab)
{
SaveCanceled = false;
CodeFileDocumentControl bakTab = CurrentCodeFileDocument;
/*foreach (TabPage tbPage in tabControl1.TabPages)
if (tbPage != tabControl1.SelectedTab)
CloseFile(tbPage);*/
List<CodeFileDocumentControl> to_close = new List<CodeFileDocumentControl>();
foreach (CodeFileDocumentControl tbPage in OpenDocuments.Values)
{
if (SaveCanceled) break;
if (tbPage != nonCloseTab)
{
if (tbPage == bakTab)
bakTab = null;
to_close.Add(tbPage);
}
}
if (!SaveCanceled)
foreach (CodeFileDocumentControl tbPage in to_close)
{
tbPage.Close();
}
if (bakTab != null)
if (bakTab != CurrentCodeFileDocument)
CurrentCodeFileDocument = bakTab;
List<WebBrowserControl> todelete = new List<WebBrowserControl>();
foreach (WebBrowserControl browserTab in OpenBrowserDocuments.Values)
todelete.Add(browserTab);
foreach (WebBrowserControl browserTab in todelete)
browserTab.Close();
//OpenBrowserDocuments.Clear();
}
bool QuestionAndSaveFile(CodeFileDocumentControl tp)
{
CurrentCodeFileDocument = tp;
DialogResult result = MessageBox.Show(string.Format(Form1StringResources.Get("SAVE_CHANGES_IN_FILE{0}"), Path.GetFileName(tp.FileName)), PascalABCCompiler.StringResources.Get("!CONFIRM"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
SaveSelFile(CurrentCodeFileDocument);
else
if (result == DialogResult.Cancel)
return false;
return true;
}
private void ExecuteSaveAs(CodeFileDocumentControl TbPage)
{
//if (TbPage.DesignerAndCodeTabs != null)
//{
// TbPage.GenerateDesignerCode();
//}
CodeFileDocumentControl bakTab = CurrentCodeFileDocument;
CurrentCodeFileDocument = TbPage;
var s = Path.GetFileName(CurrentSourceFileName);
if (s.ToLower().StartsWith("program"))
s = "";
saveFileDialog1.FileName = s;
2015-05-14 22:35:07 +03:00
string id = Path.GetDirectoryName(CurrentSourceFileName);
if (id == "")
{
if (WorkbenchStorage.WorkingDirectoryExsist)
saveFileDialog1.InitialDirectory = WorkbenchStorage.WorkingDirectory;
}
else
saveFileDialog1.InitialDirectory = Path.GetDirectoryName(CurrentSourceFileName);
DialogResult dr = saveFileDialog1.ShowDialog();
CurrentCodeFileDocument = bakTab;
}
string GetLastFileCaption(string FullFileName)
{
if (FullFileName.Length > MaxCharsInLastOpenFileName + 5)
{
string DriveName = Path.GetPathRoot(FullFileName);//FullFileName.Substring(0, 3);
string FileName = Path.GetFileName(FullFileName);
int FreeSpace = MaxCharsInLastOpenFileName - DriveName.Length - FileName.Length;
string DirectoryName = Path.GetDirectoryName(FullFileName);
if (FreeSpace > 0 && DirectoryName.Length > FreeSpace)
DirectoryName = DirectoryName.Substring(DirectoryName.Length - FreeSpace);
else
return FullFileName;
return DriveName + "..." + DirectoryName + "\\" + FileName;
}
return FullFileName;
}
bool ReplaceLastFile(string OldFileName, string NewFileName)
{
ToolStripMenuItem mI;
for (int i = 0; i < LastOpenFiles.Count; i++)
if (LastOpenFiles[i].ToLower() == OldFileName.ToLower())
{
LastOpenFiles.RemoveAt(i);
LastOpenFiles.Insert(0, NewFileName);
mI = (ToolStripMenuItem)miRecentFiles.DropDownItems[i];
miRecentFiles.DropDownItems.RemoveAt(i);
mI.Text = GetLastFileCaption(NewFileName);
mI.Tag = NewFileName;
miRecentFiles.DropDownItems.Insert(0, mI);
return true;
}
return false;
}
void AddLastFile(string FileName)
{
if (Path.GetDirectoryName(FileName) == "") return;
ToolStripMenuItem mI;
if (ReplaceLastFile(FileName, FileName)) return;
if (LastOpenFiles.Count >= MaxLastOpenFiles)
{
LastOpenFiles.RemoveAt(LastOpenFiles.Count - 1);
miRecentFiles.DropDownItems.RemoveAt(miRecentFiles.DropDownItems.Count - 1);
}
LastOpenFiles.Insert(0, FileName);
mI = new ToolStripMenuItem();
mI.Text = GetLastFileCaption(FileName);
mI.Tag = FileName;
miRecentFiles.DropDownItems.Insert(0, mI);
mI.Click += new System.EventHandler(this.OpenLastFile_ToolStripMenuItem_Click);
// mI.ToolTipText = mI.Text;
}
private string InstNameNewProgramm(DockPanel tabControl)
{
int NumbNewProg = 1;
string FileNameFormat = Path.Combine(WorkbenchStorage.WorkingDirectory, UserOptions.DefaultSourceFileNameFormat), FileName;
while (true)
{
FileName = string.Format(FileNameFormat, NumbNewProg);
if (FindTab(FileName) == null && !File.Exists(FileName))
return FileName;
NumbNewProg++;
}
}
bool IsBlankNewProgram(CodeFileDocumentControl tp)
{
return (!tp.DocumentSavedToDisk && !tp.DocumentChanged);
}
internal bool IsForm(string FileName)
{
string XMLFile = Path.ChangeExtension(FileName, string_consts.xml_form_extention);
return File.Exists(XMLFile);
}
internal bool AllSaved()
{
foreach (CodeFileDocumentControl tp in OpenDocuments.Values)
if (tp.DocumentChanged) return false;
return true;
}
void IWorkbenchFileService.PrintActiveDocument()
{
ExecPrint();
}
2015-05-14 22:35:07 +03:00
public void ExecPrint()
{
printDialog1.AllowSelection = true;
printDialog1.Document = this.CurrentCodeFileDocument.TextEditor.PrintDocument;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
printDialog1.Document.Print();
}
}
}
}