From d7f6c969b522888011884677675f18e1339b5aee Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Thu, 12 Jun 2014 06:49:27 +0200 Subject: [PATCH] r2 --- lazproj/coedit.lpi | 14 ++++-- lazproj/coedit.lpr | 2 +- src/ce_common.pas | 14 ++++-- src/ce_d2syn.pas | 2 +- src/ce_editor.lfm | 74 ++++++++++++++++++++------- src/ce_editor.pas | 30 ++++++++--- src/ce_main.lfm | 11 ++++ src/ce_main.pas | 78 +++++++++++++++++++++++++---- src/ce_messages.lfm | 50 ++++++++++-------- src/ce_messages.pas | 26 ++++++++-- src/ce_project.lfm | 34 ++++++------- src/ce_project.pas | 2 +- src/{ce_frame.lfm => ce_widget.lfm} | 5 +- src/{ce_frame.pas => ce_widget.pas} | 5 +- 14 files changed, 258 insertions(+), 89 deletions(-) rename src/{ce_frame.lfm => ce_widget.lfm} (93%) rename src/{ce_frame.pas => ce_widget.pas} (91%) diff --git a/lazproj/coedit.lpi b/lazproj/coedit.lpi index a3f17711..10a95089 100644 --- a/lazproj/coedit.lpi +++ b/lazproj/coedit.lpi @@ -50,6 +50,11 @@ + + + + + @@ -75,7 +80,7 @@ - + @@ -90,6 +95,9 @@ + + + @@ -133,12 +141,12 @@ - + - + diff --git a/lazproj/coedit.lpr b/lazproj/coedit.lpr index 88f75f68..f2ea4977 100644 --- a/lazproj/coedit.lpr +++ b/lazproj/coedit.lpr @@ -7,7 +7,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, - Forms, lazcontrols, ce_main, ce_frame, ce_common, + Forms, lazcontrols, ce_main, ce_widget, ce_common, ce_messages, ce_editor, ce_project, ce_synmemo; {$R *.res} diff --git a/src/ce_common.pas b/src/ce_common.pas index 8ffdfa24..e88c14af 100644 --- a/src/ce_common.pas +++ b/src/ce_common.pas @@ -20,9 +20,17 @@ type (** * An implementer informs when a new document is added, focused or closed. *) - ICEMultiDocEmitter = interface - procedure docChange(const aNewIndex: integer); - procedure docClose(const aNewIndex: integer); + ICEMultiDocEmitter = interface(ICEMultiDocMonitor) + end; + + (** + * An implementer adds some menu actions when its context is valid. + * Called from mainForm to a widget when necessary. + *) + ICEContextualActions = interface + function contextName: string; + function contextActionCount: integer; + function contextAction(index: integer): TBasicAction; end; (***************************************************************************** diff --git a/src/ce_d2syn.pas b/src/ce_d2syn.pas index 3d18c032..dc7b2d7c 100644 --- a/src/ce_d2syn.pas +++ b/src/ce_d2syn.pas @@ -314,7 +314,7 @@ begin fCurrIAttrib.Foreground := clBlack; fCurrIAttrib.FrameEdges:= sfeAround; - fCurrIAttrib.FrameColor:= clRed; + fCurrIAttrib.FrameColor:= clGray; fCommtAttrib.Style := [fsItalic]; fKeywdAttrib.Style := [fsBold]; diff --git a/src/ce_editor.lfm b/src/ce_editor.lfm index 55ba5009..921febc0 100644 --- a/src/ce_editor.lfm +++ b/src/ce_editor.lfm @@ -1,28 +1,28 @@ inherited CEEditorWidget: TCEEditorWidget Left = 1248 - Height = 514 + Height = 517 Top = 89 - Width = 457 + Width = 481 Caption = 'EditorWidget' - ClientHeight = 514 - ClientWidth = 457 + ClientHeight = 517 + ClientWidth = 481 inherited Back: TPanel - Height = 514 - Width = 457 - ClientHeight = 514 - ClientWidth = 457 + Height = 517 + Width = 481 + ClientHeight = 517 + ClientWidth = 481 inherited Content: TScrollBox - Height = 488 - Width = 457 - HorzScrollBar.Page = 453 - VertScrollBar.Page = 484 - ClientHeight = 484 - ClientWidth = 453 + Height = 491 + Width = 481 + HorzScrollBar.Page = 477 + VertScrollBar.Page = 487 + ClientHeight = 487 + ClientWidth = 477 object PageControl: TExtendedNotebook[0] Left = 2 - Height = 480 + Height = 483 Top = 2 - Width = 449 + Width = 473 Align = alClient BorderSpacing.Around = 2 TabOrder = 0 @@ -30,13 +30,49 @@ inherited CEEditorWidget: TCEEditorWidget end end inherited Header: TPanel - Width = 457 + Width = 481 end end object macRecorder: TSynMacroRecorder[1] RecordShortCut = 24658 PlaybackShortCut = 24656 - left = 8 - top = 8 + end + object imgList: TImageList[2] + left = 32 + Bitmap = { + 4C69010000001000000010000000CCCBC900CCCBC900CCCBC900CCCBC900CCCB + C900CCCBC900CCCBC900CDCCCA00D1D0CE00B0AFAD96817F7DFF7F7D7CFF7C7A + 78FFA4A2A1977674720078767400CCCBC900CCCBC900CBCAC800CCCBC900CCCB + C900CCCBC900CCCBC900CECDCB00D2D2D0A77B7876FFEEEDECFFD5D3D2FFC3C2 + C0FF73716EFF9B9997979C9A9800CCCBC900CCCBC900CDCCCA00D0CFCD00D2D1 + CF00D2D1CF00D2D1CF00D3D2D097797775FFF5F5F4FF7E7B79FF787878876C6A + 67FFB9B7B4FF6D6B6AFF706E6D00CCCBC900CDCCCA00D0CFCD007D7B7900817F + 7D0083817E0082807E007F7D7BFFEEEDECFF7F7D7AFF00000033000000158D8D + 8D98B2B0ADFF696865FF6E6C6900CCCBC900CDCCCA00D1D0CE00827F7D008381 + 7F0083818100838180007F7D7CFFD6D4D3FF797775FF6E6C69FF62605E005D5C + 58FFA9A9A2FF5F625AFF64675E00CCCBC900CDCCCA00D2D1CF0083807E008583 + 810083817E00807E7C007D7B79FF777572FFF4F4F5FF575554FF605F5CFFA9A9 + A2FFC78BDFFFC58CDCFFB47ED600CCCBC900CECDCB00D2D1CF00827F7D008482 + 800082807E007E7C7A007A7876FFF5F5F5FF565351FFB6B3B0FFABA7A4FF8687 + 81FFE3B3E3FFCC96C7FFAF7DCFFFCFCECC00CFCECC00D3D2D0967F7D7BFF807E + 7CFF7F7D7BFF7A7876FFF6F5F5FF5B5552FF413B36FF6E655DFF8E8680FFECEA + E6FF898C83FFBA7AB6FF9869CAFFAEADAB00D4D3D1A7787675FFEEEDECFFD7D5 + D5FF797775FFF6F6F6FF5B5652FF00000033000000332F80D1FFB2DEF3FF9289 + 80FFC1BFB8FF777C6EFF00000033B4B3B1AC7A7876FFEAEBEAFF848280FF7A78 + 76FFB9B8B7FF585553FF423B36FF3487D9003880CBFF47CAFFFF22ABFFFF84B1 + D8FF7F7971FF000000339D6BCF007F7D7AFFEEEDECFF83817FFF000000336D6A + 68FF595654FFB9B3AEFF76675AFF3680CEFF49CBFFFF2EACFFFF179DFFFF316B + A2FF000000337E8073009E6BCF007C7A78FFD5D3D2FF77777788A4A4A5000000 + 003375706CFFB4A69DFF2B7CCFFF43C8FFFF2CABFFFF1B9EFFFF3C6D9BFF0000 + 0033877F76007E8073009E6BCF00767472FFC1C1BEFF7F7D7BFFA3A4A474726F + 6CFFA19993FF45B6FCFF8CE8FFFF81D5FFFF159BFFFF3D6D9BFF000000333471 + AA00878076007E8073009E6BCF00A9A7A5AC6A6866FFB7B5B3FFB2B0AEFFAFAB + A8FF665F5BFF5C87A5FF81A8B7FF90D6FFFF376A9BFF000000333A73A6003472 + AB00878076007E8073009E6BCF000000001E9F9C9BAC676564FF676564FF6461 + 60FF7D7874B1566C7EFF4A6784FF5291D9FF000000333B72A5003A73A7003472 + AB00878076007E8073009E6BCF00000000000000001E00000033000000330000 + 00330000001F0000003300000033000000330000000000000000000000000000 + 0000000000000000000000000000 + } end end diff --git a/src/ce_editor.pas b/src/ce_editor.pas index 135c8a3c..76d298dc 100644 --- a/src/ce_editor.pas +++ b/src/ce_editor.pas @@ -7,18 +7,19 @@ interface uses Classes, SysUtils, FileUtil, ExtendedNotebook, Forms, Controls, Graphics, SynEditKeyCmds, ComCtrls, SynEditHighlighter, SynEditHighlighterFoldBase, SynMacroRecorder, - SynPluginSyncroEdit, SynEdit, Dialogs, ExtCtrls, ce_frame, ce_d2syn, ce_synmemo; + SynPluginSyncroEdit, SynEdit, Dialogs, ExtCtrls, ce_widget, ce_d2syn, ce_synmemo; type - { TCEWidgetEditor } - { TCEEditorWidget } - TCEEditorWidget = class(TCEWidget) + imgList: TImageList; PageControl: TExtendedNotebook; macRecorder: TSynMacroRecorder; procedure PageControlChange(Sender: TObject); private + // a TSynPluginSyncroEdit cannot be created from design(comp streaming err.) + fSyncEdit: TSynPluginSyncroEdit; + procedure focusedEditorChanged; function getCurrentEditor: TCESynMemo; function getEditor(index: NativeInt): TCESynMemo; function getEditorCount: NativeInt; @@ -42,9 +43,19 @@ implementation {$R *.lfm} constructor TCEEditorWidget.create(aOwner: TComponent); +var + bmp: TBitmap; begin inherited; fID := 'ID_EDIT'; + fSyncEdit := TSynPluginSyncroEdit.Create(self); + bmp := TBitmap.Create; + try + imgList.GetBitmap(0,bmp); + fSyncEdit.GutterGlyph.Assign(bmp); + finally + bmp.Free; + end; end; destructor TCEEditorWidget.destroy; @@ -73,10 +84,16 @@ begin result := TCESynMemo(pageControl.Pages[index].Controls[0]); end; +procedure TCEEditorWidget.focusedEditorChanged; +begin + macRecorder.Editor := getCurrentEditor; + fSyncEdit.Editor := getCurrentEditor; +end; + procedure TCEEditorWidget.PageControlChange(Sender: TObject); begin //http://bugs.freepascal.org/view.php?id=26320 - macRecorder.Editor := getCurrentEditor; + focusedEditorChanged; end; procedure TCEEditorWidget.addEditor; @@ -94,7 +111,8 @@ begin memo.OnKeyUp := @memoKeyDown; memo.OnMouseDown := @memoMouseDown; // - macRecorder.Editor := memo; //http://bugs.freepascal.org/view.php?id=26320 + //http://bugs.freepascal.org/view.php?id=26320 + focusedEditorChanged; end; procedure TCEEditorWidget.identifierToD2Syn(const aMemo: TCESynMemo); diff --git a/src/ce_main.lfm b/src/ce_main.lfm index 9d07d86a..cf253598 100644 --- a/src/ce_main.lfm +++ b/src/ce_main.lfm @@ -12,6 +12,9 @@ object CEMainForm: TCEMainForm object MenuItem5: TMenuItem Action = actNewFile end + object MenuItem24: TMenuItem + Action = actNewRunnable + end object MenuItem2: TMenuItem Action = actOpenFile end @@ -172,5 +175,13 @@ object CEMainForm: TCEMainForm OnExecute = actMacPlayExecute ShortCut = 24656 end + object actNewRunnable: TAction + Category = 'File' + Caption = 'New runnable module' + OnExecute = actNewRunnableExecute + end + end + object imgList: TImageList + left = 64 end end diff --git a/src/ce_main.pas b/src/ce_main.pas index ebc5b27c..122c5483 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -5,9 +5,9 @@ unit ce_main; interface uses - Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus, - ActnList, ce_common, ce_frame, ce_messages, ce_editor, ce_project, - ce_synmemo; + Classes, SysUtils, FileUtil, SynEditKeyCmds, Forms, Controls, Graphics, + Dialogs, Menus, ActnList, ce_common, ce_widget, ce_messages, ce_editor, + ce_project, ce_synmemo, process; type @@ -19,6 +19,7 @@ type ActCompAndRunFileWithArgs: TAction; Action1: TAction; actCut: TAction; + actNewRunnable: TAction; actMacPlay: TAction; actMacStartStop: TAction; actRedo: TAction; @@ -32,6 +33,7 @@ type Action3: TAction; Action4: TAction; Actions: TActionList; + imgList: TImageList; mainMenu: TMainMenu; MenuItem1: TMenuItem; MenuItem10: TMenuItem; @@ -49,6 +51,7 @@ type MenuItem21: TMenuItem; MenuItem22: TMenuItem; MenuItem23: TMenuItem; + MenuItem24: TMenuItem; MenuItem3: TMenuItem; MenuItem4: TMenuItem; MenuItem5: TMenuItem; @@ -64,6 +67,7 @@ type procedure actMacPlayExecute(Sender: TObject); procedure actMacStartStopExecute(Sender: TObject); procedure actNewFileExecute(Sender: TObject); + procedure actNewRunnableExecute(Sender: TObject); procedure actOpenFileExecute(Sender: TObject); procedure actPasteExecute(Sender: TObject); procedure actRedoExecute(Sender: TObject); @@ -77,6 +81,8 @@ type fEditWidg: TCEEditorWidget; fProjWidg: TCEProjectWidget; // + procedure ProcessOutputToMsg(const aProcess: TProcess); + // procedure newFile; function findFile(const aFilename: string): NativeInt; procedure openFile(const aFilename: string); @@ -87,6 +93,11 @@ type public constructor create(aOwner: TComponent); override; destructor destroy; override; + // + property WidgetList: TCEWidgetList read fWidgList; + property MessageWidget: TCEMessagesWidget read fMesgWidg; + property EditWidget: TCEEditorWidget read fEditWidg; + property ProjectWidget: TCEProjectWidget read fProjWidg; end; var @@ -96,7 +107,7 @@ implementation {$R *.lfm} uses - process, SynMacroRecorder; + SynMacroRecorder; {$REGION std comp methods ******************************************************} constructor TCEMainForm.create(aOwner: TComponent); @@ -279,6 +290,22 @@ begin newFile; end; +procedure TCEMainForm.actNewRunnableExecute(Sender: TObject); +begin + newFile; + fEditWidg.currentEditor.Text := + 'module runnable;' + #13#10 + + '' + #13#10 + + 'import std.stdio;' + #13#10 + + '' + #13#10 + + 'void main(string args[])' + #13#10 + + '{' + #13#10 + + ' writeln("runnable module is just a `toy feature`");' + #13#10 + + ' writeln;' + #13#10 + + ' writeln("coedit just saves a temporar d module before compiling it and running it...");' + #13#10 + + '}' + #13#10; +end; + procedure TCEMainForm.actSaveFileAsExecute(Sender: TObject); begin if fEditWidg = nil then exit; @@ -374,6 +401,38 @@ end; {$ENDREGION} {$REGION run ******************************************************************} +procedure TCEMainForm.ProcessOutputToMsg(const aProcess: TProcess); +const + ioBuffSz = 2048; +var + str: TMemoryStream; + lns: TStringList; + readCnt: LongInt; + readSz: LongInt; + msg: string; +begin + If not (poUsePipes in aProcess.Options) then exit; + // + str := TMemorystream.Create; + lns := TStringList.Create; + readSz := 0; + try + while true do + begin + str.SetSize(readSz + ioBuffSz); + readCnt := aProcess.Output.Read((str.Memory + readSz)^, ioBuffSz); + if readCnt = 0 then break; + Inc(readSz, readCnt); + end; + Str.SetSize(readSz); + lns.LoadFromStream(Str); + for msg in lns do fMesgWidg.addMessage(msg); + finally + str.Free; + lns.Free; + end; +end; + procedure TCEMainForm.compileAndRunFile(const edIndex: NativeInt; const runArgs: string = ''); var dmdproc: TProcess; @@ -385,23 +444,23 @@ begin try temppath := ''; {$IFDEF DEBUG}{$WARNINGS OFF}{$HINTS OFF}{$ENDIF} - fname := temppath + format('temp_%.8x',[NativeInt(@dmdproc)]); + fname := temppath + format('temp_%.8x',[LongWord(@dmdproc)]); {$IFDEF DEBUG}{$WARNINGS ON}{$HINTS ON}{$ENDIF} fEditWidg.editor[edIndex].Lines.SaveToFile(fname + '.d'); - dmdproc.Options:= [poWaitOnExit]; + dmdproc.Options:= [poWaitOnExit,poUsePipes,poStdErrToOutput]; dmdproc.Executable:= 'dmd'; dmdproc.Parameters.Text := '"'+ fname +'.d"'; try dmdproc.Execute; + ProcessOutputToMsg(dmdproc); finally DeleteFile(fname + '.d'); end; - // + output to msgs widget if dmdProc.ExitStatus = 0 then begin - runproc.Options:= [poWaitOnExit,poStderrToOutPut]; + runproc.Options:= [poWaitOnExit,poStderrToOutPut,poUsePipes]; {$IFDEF MSWINDOWS} runproc.Executable := fname + '.exe'; runproc.Parameters.Text := runArgs; @@ -409,8 +468,7 @@ begin runproc.Executable := fname; {$ENDIF} runproc.Execute; - // + output to msgs widget - + ProcessOutputToMsg(runproc); {$IFDEF MSWINDOWS} DeleteFile(fname + '.exe'); DeleteFile(fname + '.obj'); diff --git a/src/ce_messages.lfm b/src/ce_messages.lfm index 390e9d9e..03cc17cb 100644 --- a/src/ce_messages.lfm +++ b/src/ce_messages.lfm @@ -1,36 +1,46 @@ inherited CEMessagesWidget: TCEMessagesWidget - Left = 1248 - Height = 139 - Top = 640 - Width = 652 + Left = 1249 + Height = 186 + Top = 643 + Width = 656 Caption = 'MessagesWidget' - ClientHeight = 139 - ClientWidth = 652 + ClientHeight = 186 + ClientWidth = 656 inherited Back: TPanel - Height = 139 - Width = 652 - ClientHeight = 139 - ClientWidth = 652 + Height = 186 + Width = 656 + ClientHeight = 186 + ClientWidth = 656 inherited Content: TScrollBox - Height = 113 - Width = 652 - HorzScrollBar.Page = 631 - VertScrollBar.Page = 109 - ClientHeight = 109 - ClientWidth = 631 + Height = 160 + Width = 656 + HorzScrollBar.Page = 652 + VertScrollBar.Page = 156 + ClientHeight = 156 + ClientWidth = 652 object List: TListView[0] Left = 2 - Height = 150 + Height = 152 Top = 2 - Width = 627 + Width = 648 Align = alClient + AutoSort = False + AutoWidthLastColumn = True BorderSpacing.Around = 2 - Columns = <> + Columns = < + item + Width = 644 + end> + GridLines = True + IconOptions.Arrangement = iaLeft + ReadOnly = True + RowSelect = True TabOrder = 0 + ViewStyle = vsReport end end inherited Header: TPanel - Width = 652 + Width = 656 end end end diff --git a/src/ce_messages.pas b/src/ce_messages.pas index af60f3a3..8979350f 100644 --- a/src/ce_messages.pas +++ b/src/ce_messages.pas @@ -5,13 +5,12 @@ unit ce_messages; interface uses - Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, - StdCtrls, ComCtrls, ce_frame, ce_common; + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, + ExtCtrls, ComCtrls, ce_widget, ce_common; type - { TCEWidgetMessages } - + { TCEMessagesWidget } TCEMessagesWidget = class(TCEWidget,ICEMultiDocMonitor) List: TListView; private @@ -19,13 +18,22 @@ type constructor create(aOwner: TComponent); override; destructor destroy; override; // + procedure addMessage(const aMsg: string); + // procedure docChange(const aNewIndex: integer); procedure docClose(const aNewIndex: integer); end; + PTCEMessageItem = ^TCEMessageItem; + TCEMessageItem = class(TListItem) + end; + implementation {$R *.lfm} +uses + ce_main; + constructor TCEMessagesWidget.create(aOwner: TComponent); begin inherited; @@ -37,6 +45,16 @@ begin inherited; end; +procedure TCEMessagesWidget.addMessage(const aMsg: string); +var + item: TCEMessageItem; +begin + item := TCEMessageItem.Create(List.Items); + item.Caption := aMsg; + item.Data := mainForm.EditWidget.currentEditor; + List.Items.AddItem(item); +end; + procedure TCEMessagesWidget.docChange(const aNewIndex: integer); begin // can grow the list... diff --git a/src/ce_project.lfm b/src/ce_project.lfm index a268cb37..a7403983 100644 --- a/src/ce_project.lfm +++ b/src/ce_project.lfm @@ -1,28 +1,28 @@ inherited CEProjectWidget: TCEProjectWidget - Left = 1721 - Height = 514 + Left = 1745 + Height = 517 Top = 89 - Width = 180 + Width = 163 Caption = 'ProjectWidget' - ClientHeight = 514 - ClientWidth = 180 + ClientHeight = 517 + ClientWidth = 163 inherited Back: TPanel - Height = 514 - Width = 180 - ClientHeight = 514 - ClientWidth = 180 + Height = 517 + Width = 163 + ClientHeight = 517 + ClientWidth = 163 inherited Content: TScrollBox - Height = 488 - Width = 180 - HorzScrollBar.Page = 176 - VertScrollBar.Page = 484 - ClientHeight = 484 - ClientWidth = 176 + Height = 491 + Width = 163 + HorzScrollBar.Page = 159 + VertScrollBar.Page = 487 + ClientHeight = 487 + ClientWidth = 159 object Tree: TTreeView[0] Left = 2 Height = 206 Top = 2 - Width = 172 + Width = 155 Align = alTop BorderSpacing.Around = 2 DefaultItemHeight = 18 @@ -31,7 +31,7 @@ inherited CEProjectWidget: TCEProjectWidget end end inherited Header: TPanel - Width = 180 + Width = 163 end end end diff --git a/src/ce_project.pas b/src/ce_project.pas index 86ce0bab..53009496 100644 --- a/src/ce_project.pas +++ b/src/ce_project.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, - ComCtrls, ce_common, ce_frame; + ComCtrls, ce_common, ce_widget; type diff --git a/src/ce_frame.lfm b/src/ce_widget.lfm similarity index 93% rename from src/ce_frame.lfm rename to src/ce_widget.lfm index 63ade14d..247af502 100644 --- a/src/ce_frame.lfm +++ b/src/ce_widget.lfm @@ -1,7 +1,7 @@ object CEWidget: TCEWidget - Left = 1180 + Left = 1337 Height = 327 - Top = 523 + Top = 424 Width = 320 Caption = 'CEWidget' ClientHeight = 327 @@ -16,6 +16,7 @@ object CEWidget: TCEWidget BevelOuter = bvNone ClientHeight = 327 ClientWidth = 320 + FullRepaint = False TabOrder = 0 object Content: TScrollBox Left = 0 diff --git a/src/ce_frame.pas b/src/ce_widget.pas similarity index 91% rename from src/ce_frame.pas rename to src/ce_widget.pas index 18f0e698..9109aa22 100644 --- a/src/ce_frame.pas +++ b/src/ce_widget.pas @@ -1,11 +1,12 @@ -unit ce_frame; +unit ce_widget; {$mode objfpc}{$H+} interface uses - Classes, SysUtils, FileUtil, Forms, Controls, ExtCtrls, ce_common; + Classes, SysUtils, FileUtil, DividerBevel, Forms, Controls, ExtCtrls, + ce_common; type