<commit_before>unit frm_main;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_menu, fpg_panel,
  fpg_button, fpg_splitter, fpg_tab, fpg_memo, fpg_label, fpg_grid,
  fpg_tree, fpg_textedit, fpg_mru, synregexpr;

type

  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    pnlMenu: TfpgBevel;
    mainmenu: TfpgMenuBar;
    Toolbar: TfpgBevel;
    btnQuit: TfpgButton;
    btnOpen: TfpgButton;
    btnSave: TfpgButton;
    btnSaveAll: TfpgButton;
    btnTest: TfpgButton;
    pnlStatusBar: TfpgBevel;
    lblStatus: TfpgLabel;
    pnlClientArea: TfpgBevel;
    pnlWindow: TfpgPageControl;
    tsMessages: TfpgTabSheet;
    grdMessages: TfpgStringGrid;
    tsScribble: TfpgTabSheet;
    memScribble: TfpgMemo;
    tsTerminal: TfpgTabSheet;
    Splitter1: TfpgSplitter;
    pnlTool: TfpgPageControl;
    tsProject: TfpgTabSheet;
    tvProject: TfpgTreeView;
    tsFiles: TfpgTabSheet;
    grdFiles: TfpgFileGrid;
    Splitter2: TfpgSplitter;
    grdOpenFiles: TfpgStringGrid;
    Splitter3: TfpgSplitter;
    pcEditor: TfpgPageControl;
    tseditor: TfpgTabSheet;
    TextEditor: TfpgTextEdit;
    mnuFile: TfpgPopupMenu;
    mnuEdit: TfpgPopupMenu;
    mnuSearch: TfpgPopupMenu;
    mnuView: TfpgPopupMenu;
    mnuProject: TfpgPopupMenu;
    mnuRun: TfpgPopupMenu;
    mnuTools: TfpgPopupMenu;
    mnuSettings: TfpgPopupMenu;
    mnuHelp: TfpgPopupMenu;
    {@VFD_HEAD_END: MainForm}
    pmOpenRecentMenu: TfpgPopupMenu;
    miRecentProjects: TfpgMenuItem;
    FRecentFiles: TfpgMRU;
    FRegex: TRegExpr;
    procedure   FormShow(Sender: TObject);
    procedure   FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure   btnQuitClicked(Sender: TObject);
    procedure   btnOpenFileClicked(Sender: TObject);
    procedure   miFileSave(Sender: TObject);
    procedure   miFileSaveAs(Sender: TObject);
    procedure   miSearchProcedureList(Sender: TObject);
    procedure   miAboutFPGuiClicked(Sender: TObject);
    procedure   miAboutIDE(Sender: TObject);
    procedure   miRunMake(Sender: TObject);
    procedure   miRunBuild(Sender: TObject);
    procedure   miRunMake1(Sender: TObject);
    procedure   miRunMake2(Sender: TObject);
    procedure   miRunMake3(Sender: TObject);
    procedure   miRunMake4(Sender: TObject);
    procedure   miConfigureIDE(Sender: TObject);
    procedure   miViewDebug(Sender: TObject);
    procedure   miProjectNew(Sender: TObject);
    procedure   miProjectNewFromTemplate(Sender: TObject);
    procedure   miProjectOptions(Sender: TObject);
    procedure   miProjectOpen(Sender: TObject);
    procedure   miRecentProjectsClick(Sender: TObject; const FileName: String);
    procedure   miProjectSave(Sender: TObject);
    procedure   miProjectSaveAs(Sender: TObject);
    procedure   miProjectAddUnitToProject(Sender: TObject);
    procedure   tvProjectDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
    procedure   TabSheetClosing(Sender: TObject; ATabSheet: TfpgTabSheet);
    procedure   BuildTerminated(Sender: TObject);
    procedure   BuildOutput(Sender: TObject; const ALine: string);
    procedure   UpdateStatus(const AText: TfpgString);
    procedure   SetupProjectTree;
    procedure   PopuplateProjectTree;
    procedure   SetupFilesGrid;
    procedure   AddMessage(const AMsg: TfpgString);
    procedure   ClearMessagesWindow;
    procedure   CloseAllTabs;
    procedure   LoadProject(const AFilename: TfpgString);
    function    OpenEditorPage(const AFilename: TfpgString): TfpgTabSheet;
    procedure   miTest(Sender: TObject);
    function    GetUnitsNode: TfpgTreeNode;
    procedure   UpdateWindowTitle;
    procedure   TextEditDrawLine(Sender: TObject; ALineText: TfpgString; ALineIndex: Integer; ACanvas: TfpgCanvas; ATextRect: TfpgRect; var AllowSelfDraw: Boolean);
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure   AfterCreate; override;
  end;

{@VFD_NEWFORM_DECL}

implementation

uses
  process
  ,fpg_iniutils
  ,fpg_dialogs
  ,fpg_utils
  ,fpg_stringutils
  ,fpg_constants
  ,fpg_widget
  ,frm_configureide
  ,frm_projectoptions
  ,frm_debug
  ,frm_procedurelist
  ,fpg_basegrid
  ,ideconst
  ,idemacros
  ,Project
  ,UnitList
  ,BuilderThread
  {$IFDEF DEBUGSVR}
  ,dbugintf
  {$ENDIF}
  ,ideutils
  ;


const
  cTitle = 'fpGUI IDE - %s';
  cFileFilterTemplate  = '%s (%s)|%s';
  cSourceFiles = '*.pas;*.pp;*.lpr;*.dpr;*.inc';
  cProjectFiles = '*.project';

  { nicely working so far }
  cKeywords = '\s*(begin|end|read|write|try|finally|except|uses|interface'
    + '|implementation|procedure|function|constructor|destructor|property'
    + '|private|public|published|type|class|unit|program|if|then|for|downto|to'
    + '|do|else|while|and|inherited|const|var|initialization|finalization)[^0-9a-zA-Z:=;\)\( ]*';

  cComments1 = '\s*\/\/.*$';

{@VFD_NEWFORM_IMPL}

procedure TMainForm.btnQuitClicked(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.btnOpenFileClicked(Sender: TObject);
var
  s: TfpgString;
begin
  s := SelectFileDialog(sfdOpen, Format(cFileFilterTemplate, ['Source Files', cSourceFiles, cSourceFiles]));
  if s <> '' then
  begin
    OpenEditorPage(s);
  end;
end;

procedure TMainForm.miFileSave(Sender: TObject);
var
  s: TfpgString;<commit_msg>ide: adds syntax highlighting support for {...} style comments.<commit_after>unit frm_main;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_menu, fpg_panel,
  fpg_button, fpg_splitter, fpg_tab, fpg_memo, fpg_label, fpg_grid,
  fpg_tree, fpg_textedit, fpg_mru, synregexpr;

type

  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    pnlMenu: TfpgBevel;
    mainmenu: TfpgMenuBar;
    Toolbar: TfpgBevel;
    btnQuit: TfpgButton;
    btnOpen: TfpgButton;
    btnSave: TfpgButton;
    btnSaveAll: TfpgButton;
    btnTest: TfpgButton;
    pnlStatusBar: TfpgBevel;
    lblStatus: TfpgLabel;
    pnlClientArea: TfpgBevel;
    pnlWindow: TfpgPageControl;
    tsMessages: TfpgTabSheet;
    grdMessages: TfpgStringGrid;
    tsScribble: TfpgTabSheet;
    memScribble: TfpgMemo;
    tsTerminal: TfpgTabSheet;
    Splitter1: TfpgSplitter;
    pnlTool: TfpgPageControl;
    tsProject: TfpgTabSheet;
    tvProject: TfpgTreeView;
    tsFiles: TfpgTabSheet;
    grdFiles: TfpgFileGrid;
    Splitter2: TfpgSplitter;
    grdOpenFiles: TfpgStringGrid;
    Splitter3: TfpgSplitter;
    pcEditor: TfpgPageControl;
    tseditor: TfpgTabSheet;
    TextEditor: TfpgTextEdit;
    mnuFile: TfpgPopupMenu;
    mnuEdit: TfpgPopupMenu;
    mnuSearch: TfpgPopupMenu;
    mnuView: TfpgPopupMenu;
    mnuProject: TfpgPopupMenu;
    mnuRun: TfpgPopupMenu;
    mnuTools: TfpgPopupMenu;
    mnuSettings: TfpgPopupMenu;
    mnuHelp: TfpgPopupMenu;
    {@VFD_HEAD_END: MainForm}
    pmOpenRecentMenu: TfpgPopupMenu;
    miRecentProjects: TfpgMenuItem;
    FRecentFiles: TfpgMRU;
    FRegex: TRegExpr;
    procedure   FormShow(Sender: TObject);
    procedure   FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure   btnQuitClicked(Sender: TObject);
    procedure   btnOpenFileClicked(Sender: TObject);
    procedure   miFileSave(Sender: TObject);
    procedure   miFileSaveAs(Sender: TObject);
    procedure   miSearchProcedureList(Sender: TObject);
    procedure   miAboutFPGuiClicked(Sender: TObject);
    procedure   miAboutIDE(Sender: TObject);
    procedure   miRunMake(Sender: TObject);
    procedure   miRunBuild(Sender: TObject);
    procedure   miRunMake1(Sender: TObject);
    procedure   miRunMake2(Sender: TObject);
    procedure   miRunMake3(Sender: TObject);
    procedure   miRunMake4(Sender: TObject);
    procedure   miConfigureIDE(Sender: TObject);
    procedure   miViewDebug(Sender: TObject);
    procedure   miProjectNew(Sender: TObject);
    procedure   miProjectNewFromTemplate(Sender: TObject);
    procedure   miProjectOptions(Sender: TObject);
    procedure   miProjectOpen(Sender: TObject);
    procedure   miRecentProjectsClick(Sender: TObject; const FileName: String);
    procedure   miProjectSave(Sender: TObject);
    procedure   miProjectSaveAs(Sender: TObject);
    procedure   miProjectAddUnitToProject(Sender: TObject);
    procedure   tvProjectDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
    procedure   TabSheetClosing(Sender: TObject; ATabSheet: TfpgTabSheet);
    procedure   BuildTerminated(Sender: TObject);
    procedure   BuildOutput(Sender: TObject; const ALine: string);
    procedure   UpdateStatus(const AText: TfpgString);
    procedure   SetupProjectTree;
    procedure   PopuplateProjectTree;
    procedure   SetupFilesGrid;
    procedure   AddMessage(const AMsg: TfpgString);
    procedure   ClearMessagesWindow;
    procedure   CloseAllTabs;
    procedure   LoadProject(const AFilename: TfpgString);
    function    OpenEditorPage(const AFilename: TfpgString): TfpgTabSheet;
    procedure   miTest(Sender: TObject);
    function    GetUnitsNode: TfpgTreeNode;
    procedure   UpdateWindowTitle;
    procedure   TextEditDrawLine(Sender: TObject; ALineText: TfpgString; ALineIndex: Integer; ACanvas: TfpgCanvas; ATextRect: TfpgRect; var AllowSelfDraw: Boolean);
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure   AfterCreate; override;
  end;

{@VFD_NEWFORM_DECL}

implementation

uses
  process
  ,fpg_iniutils
  ,fpg_dialogs
  ,fpg_utils
  ,fpg_stringutils
  ,fpg_constants
  ,fpg_widget
  ,frm_configureide
  ,frm_projectoptions
  ,frm_debug
  ,frm_procedurelist
  ,fpg_basegrid
  ,ideconst
  ,idemacros
  ,Project
  ,UnitList
  ,BuilderThread
  {$IFDEF DEBUGSVR}
  ,dbugintf
  {$ENDIF}
  ,ideutils
  ;


const
  cTitle = 'fpGUI IDE - %s';
  cFileFilterTemplate  = '%s (%s)|%s';
  cSourceFiles = '*.pas;*.pp;*.lpr;*.dpr;*.inc';
  cProjectFiles = '*.project';

  { nicely working so far }
  cKeywords = '\s*(begin|end|read|write|try|finally|except|uses|interface'
    + '|implementation|procedure|function|constructor|destructor|property'
    + '|private|public|published|type|class|unit|program|if|then|for|downto|to'
    + '|do|else|while|and|inherited|const|var|initialization|finalization)[^0-9a-zA-Z:=;\)\( ]*';

  cComments1 = '(\s*\/\/.*$)|(\s*\{.*\})';

{@VFD_NEWFORM_IMPL}

procedure TMainForm.btnQuitClicked(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.btnOpenFileClicked(Sender: TObject);
var
  s: TfpgString;
begin
  s := SelectFileDialog(sfdOpen, Format(cFileFilterTemplate, ['Source Files', cSourceFiles, cSourceFiles]));
  if s <> '' then
  begin
    OpenEditorPage(s);
  end;
end;

procedure TMainForm.miFileSave(Sender: TObject);
var
  s: TfpgString;
{'fraction_non_alphanumeric': 0.09553072625698324, 'fraction_numerical': 0.00186219739292365, 'mean_word_length': 4.5110312981015905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3609563', 'n_tokens_mistral': 3820, 'n_tokens_neox': 3775, 'n_words': 732}