📄 ftexteditor.class
字号:
' Gambas class filePUBLIC Name AS StringPUBLIC Path AS StringPUBLIC Editor AS GambasEditorPRIVATE $bModify AS BooleanPUBLIC SUB _new(sPath AS String) DIM sText AS String Path = sPath Name = File.Name(Path) Editor = edtEditor ReadConfig Project.InitMove(ME) sText = File.Load(sPath) 'IF Right(sText) <> "\n" THEN sText = sText & "\n" edtEditor.Text = sText SetReadOnly $bModify = FALSE edtEditor.Reset edtEditor.SetFocus DrawTitleENDPUBLIC SUB ReadConfig() DIM iInd AS Integer DIM iColor AS Integer DIM hTheme AS Integer[] edtEditor.Frozen = TRUE edtEditor.Font = Font[Settings["/Editor/Font", Project.DEFAULT_FONT]] hTheme = FOption.DefaultTheme FOR iInd = 0 TO FEditor.NBR_COLOR - 1 iColor = Val(Settings["/Editor/Color[" & CStr(iInd) & "]", "-1"]) IF iColor = -1 THEN iColor = hTheme[iInd] edtEditor.Colors[iInd] = iColor NEXT edtEditor.ShowChange = Settings["/Editor/ShowChange", TRUE] edtEditor.Frozen = FALSEENDPUBLIC FUNCTION Save() AS Boolean 'Project.Config.WriteString("/Window" &/ Name &/ "Pos", ' CStr(ME.X) & "," & CStr(ME.Y) & "," & CStr(ME.Width) & "," & CStr(ME.Height)) IF NOT $bModify THEN RETURN Save.Begin(Path) File.Save(Path, edtEditor.Text) edtEditor.Reset $bModify = FALSE DrawTitle Save.End()CATCH RETURN Save.Error()ENDPRIVATE SUB DrawTitle() DIM sTitle AS String sTitle = File.Name(Path) & " " & CStr(edtEditor.Line + 1) & ":" & CStr(edtEditor.Column + 1) IF $bModify THEN sTitle = sTitle & " [" & ("modified") & "]" ME.Title = sTitle '& " - " & Project.NameENDPUBLIC SUB Modify(OPTIONAL bReset AS Boolean) IF $bModify <> bReset THEN RETURN $bModify = NOT bReset DrawTitleENDPUBLIC FUNCTION IsModified() AS Boolean RETURN $bModifyENDPUBLIC SUB Form_Resize() edtEditor.Move(0, 0, ME.ClientW, ME.ClientH) 'lblCursor.Move(0, ME.ClientH - lblCursor.Height)ENDPUBLIC SUB edtEditor_Change() ModifyENDPUBLIC SUB edtEditor_Cursor() 'PRINT edtEditor.Line; edtEditor.Column 'lblCursor.Text = CStr(edtEditor.Line + 1) & " : " & CStr(edtEditor.Column + 1) DrawTitleEND'PUBLIC SUB Form_KeyPress(Ascii AS String, Code AS Integer, State AS Integer)'' IF Code = Asc("S") AND State = Mouse.Control THEN' ME.Save' ENDIF''ENDPUBLIC SUB Form_Activate() Project.Activate(ME)ENDPUBLIC SUB Goto(iLine AS Integer, OPTIONAL iColumn AS Integer = -1) DEC iLine IF iColumn < 0 THEN iColumn = edtEditor.Column edtEditor.Goto(iLine, iColumn)ENDPUBLIC SUB GotoCenter(iLine AS Integer, OPTIONAL iColumn AS Integer = -1) Goto(iLine, iColumn) edtEditor.EnsureVisibleENDPUBLIC SUB edtEditor_Menu() mnuEditor.PopupENDPUBLIC SUB mnuSave_Click() SaveEND' PUBLIC SUB mnuFind_Click()'' DIM sSel AS String' DIM iPos AS Integer'' sSel = Left$(Trim(edtEditor.Selection.Text), 64)' iPos = Instr(sSel, gb.NewLine)' IF iPos THEN sSel = Left$(sSel, iPos - 1)'' Project.FindForm.Find(sSel)'' END''' PUBLIC SUB mnuFindNext_Click()'' Project.FindForm.FindNext'' END''' PUBLIC SUB mnuFindPrevious_Click()'' Project.FindForm.FindPrevious'' ENDPUBLIC SUB Rename(sNewName AS String, sNewPath AS String) Name = sNewName Path = sNewPath 'File.Dir(Path) &/ sNewName & "." & File.Ext(Path) DrawTitleENDPUBLIC SUB mnuCut_Click() edtEditor.CutENDPUBLIC SUB mnuCopy_Click() edtEditor.CopyENDPUBLIC SUB mnuPaste_Click() edtEditor.PasteENDPUBLIC SUB mnuUndo_Click() edtEditor.UndoENDPUBLIC SUB mnuRedo_Click() edtEditor.RedoENDPUBLIC SUB mnuGotoLine_Click() DIM iLine AS Integer iLine = FGotoLine.Run(edtEditor.Line + 1) IF iLine <= 0 THEN RETURN GotoCenter(iLine)END' PUBLIC SUB mnuWordWrap_Click()'' edtEditor.Wrap = NOT edtEditor.Wrap' mnuWordWrap.Checked = edtEditor.Wrap'' ENDPUBLIC SUB mnuSelectAll_Click() edtEditor.SelectionENDPRIVATE SUB SetReadOnly() edtEditor.ReadOnly = Project.ReadOnly OR Project.RunningENDPUBLIC SUB OnProjectDebug() SetReadOnlyENDPUBLIC SUB mnuFind_Click() DIM sSel AS String DIM iPos AS Integer DIM sText AS String sSel = Left$(Trim(edtEditor.Selection.Text), 256) iPos = Instr(sSel, gb.NewLine) IF iPos THEN sSel = Left$(sSel, iPos - 1) FFind.Find(sSel)ENDPUBLIC SUB mnuFindNext_Click() FFind.FindNextENDPUBLIC SUB mnuFindPrevious_Click() FFind.FindPreviousEND
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -