mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Format on Save
This commit is contained in:
parent
f41365a58e
commit
e34dee7438
5 changed files with 18 additions and 3 deletions
|
@ -1324,7 +1324,7 @@ namespace IDE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mWakaTime != null)
|
if (mWakaTime != null)
|
||||||
mWakaTime.QueueFile(path, projectSource.mProject.mProjectName, true);
|
mWakaTime.QueueFile(path, projectSource.mProject.mProjectName, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1489,6 +1489,11 @@ namespace IDE
|
||||||
{
|
{
|
||||||
if ((sourceViewPanel.HasUnsavedChanges()) || (forcePath != null))
|
if ((sourceViewPanel.HasUnsavedChanges()) || (forcePath != null))
|
||||||
{
|
{
|
||||||
|
if (gApp.mSettings.mEditorSettings.mFormatOnSave)
|
||||||
|
{
|
||||||
|
sourceViewPanel.ReformatDocument(true);
|
||||||
|
}
|
||||||
|
|
||||||
if ((forcePath == null) && (sourceViewPanel.mFilePath == null))
|
if ((forcePath == null) && (sourceViewPanel.mFilePath == null))
|
||||||
{
|
{
|
||||||
return SaveFileAs(sourceViewPanel);
|
return SaveFileAs(sourceViewPanel);
|
||||||
|
|
|
@ -598,6 +598,7 @@ namespace IDE
|
||||||
public bool mShowLineNumbers = true;
|
public bool mShowLineNumbers = true;
|
||||||
public bool mFreeCursorMovement;
|
public bool mFreeCursorMovement;
|
||||||
public FileRecoveryKind mEnableFileRecovery = .Yes;
|
public FileRecoveryKind mEnableFileRecovery = .Yes;
|
||||||
|
public bool mFormatOnSave = false;
|
||||||
|
|
||||||
public void Serialize(StructuredData sd)
|
public void Serialize(StructuredData sd)
|
||||||
{
|
{
|
||||||
|
@ -621,6 +622,7 @@ namespace IDE
|
||||||
sd.Add("ShowLineNumbers", mShowLineNumbers);
|
sd.Add("ShowLineNumbers", mShowLineNumbers);
|
||||||
sd.Add("FreeCursorMovement", mFreeCursorMovement);
|
sd.Add("FreeCursorMovement", mFreeCursorMovement);
|
||||||
sd.Add("EnableFileRecovery", mEnableFileRecovery);
|
sd.Add("EnableFileRecovery", mEnableFileRecovery);
|
||||||
|
sd.Add("FormatOnSave", mFormatOnSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deserialize(StructuredData sd)
|
public void Deserialize(StructuredData sd)
|
||||||
|
@ -648,6 +650,7 @@ namespace IDE
|
||||||
sd.Get("ShowLineNumbers", ref mShowLineNumbers);
|
sd.Get("ShowLineNumbers", ref mShowLineNumbers);
|
||||||
sd.Get("FreeCursorMovement", ref mFreeCursorMovement);
|
sd.Get("FreeCursorMovement", ref mFreeCursorMovement);
|
||||||
sd.GetEnum<FileRecoveryKind>("EnableFileRecovery", ref mEnableFileRecovery);
|
sd.GetEnum<FileRecoveryKind>("EnableFileRecovery", ref mEnableFileRecovery);
|
||||||
|
sd.Get("FormatOnSave", ref mFormatOnSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDefaults()
|
public void SetDefaults()
|
||||||
|
|
|
@ -123,6 +123,7 @@ namespace IDE.ui
|
||||||
AddPropertiesItem(category, "Show Line Numbers", "mShowLineNumbers");
|
AddPropertiesItem(category, "Show Line Numbers", "mShowLineNumbers");
|
||||||
AddPropertiesItem(category, "Free Cursor Movement", "mFreeCursorMovement");
|
AddPropertiesItem(category, "Free Cursor Movement", "mFreeCursorMovement");
|
||||||
AddPropertiesItem(category, "Enable File Recovery", "mEnableFileRecovery");
|
AddPropertiesItem(category, "Enable File Recovery", "mEnableFileRecovery");
|
||||||
|
AddPropertiesItem(category, "Format on Save", "mFormatOnSave");
|
||||||
|
|
||||||
category.Open(true, true);
|
category.Open(true, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace IDE.ui
|
||||||
|
|
||||||
UndoBatchStart mUndoBatchStart;
|
UndoBatchStart mUndoBatchStart;
|
||||||
PersistentTextPosition mTrackedCursorPosition;
|
PersistentTextPosition mTrackedCursorPosition;
|
||||||
|
EditWidgetContent.LineAndColumn? mVirtualCursorPos;
|
||||||
PersistentTextPosition mSelStartPostion;
|
PersistentTextPosition mSelStartPostion;
|
||||||
PersistentTextPosition mSelEndPostion;
|
PersistentTextPosition mSelEndPostion;
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ namespace IDE.ui
|
||||||
editWidgetContent.mData.mUndoManager.Add(firstUndoAction);
|
editWidgetContent.mData.mUndoManager.Add(firstUndoAction);
|
||||||
editWidgetContent.mData.mUndoManager.Add(new EditWidgetContent.SetCursorAction(editWidgetContent));
|
editWidgetContent.mData.mUndoManager.Add(new EditWidgetContent.SetCursorAction(editWidgetContent));
|
||||||
|
|
||||||
|
mVirtualCursorPos = editWidgetContent.mVirtualCursorPos;
|
||||||
mTrackedCursorPosition = new PersistentTextPosition((int32)editWidgetContent.CursorTextPos);
|
mTrackedCursorPosition = new PersistentTextPosition((int32)editWidgetContent.CursorTextPos);
|
||||||
editWidgetContent.PersistentTextPositions.Add(mTrackedCursorPosition);
|
editWidgetContent.PersistentTextPositions.Add(mTrackedCursorPosition);
|
||||||
|
|
||||||
|
@ -54,6 +56,10 @@ namespace IDE.ui
|
||||||
var editWidgetContent = (SourceEditWidgetContent)mEditWidget.Content;
|
var editWidgetContent = (SourceEditWidgetContent)mEditWidget.Content;
|
||||||
editWidgetContent.CursorTextPos = mTrackedCursorPosition.mIndex;
|
editWidgetContent.CursorTextPos = mTrackedCursorPosition.mIndex;
|
||||||
editWidgetContent.PersistentTextPositions.Remove(mTrackedCursorPosition);
|
editWidgetContent.PersistentTextPositions.Remove(mTrackedCursorPosition);
|
||||||
|
|
||||||
|
if ((mVirtualCursorPos != null) && (editWidgetContent.CursorLineAndColumn.mColumn == 0))
|
||||||
|
editWidgetContent.CursorLineAndColumn = .(editWidgetContent.CursorLineAndColumn.mLine, mVirtualCursorPos.Value.mColumn);
|
||||||
|
|
||||||
delete mTrackedCursorPosition;
|
delete mTrackedCursorPosition;
|
||||||
|
|
||||||
if (mSelStartPostion != null)
|
if (mSelStartPostion != null)
|
||||||
|
|
|
@ -4389,7 +4389,7 @@ namespace IDE.ui
|
||||||
base.FindNext(dir);
|
base.FindNext(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReformatDocument()
|
public void ReformatDocument(bool ignoreSelection = false)
|
||||||
{
|
{
|
||||||
if (!mIsBeefSource)
|
if (!mIsBeefSource)
|
||||||
return;
|
return;
|
||||||
|
@ -4442,7 +4442,7 @@ namespace IDE.ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mEditWidget.Content.HasSelection())
|
if ((mEditWidget.Content.HasSelection()) && (!ignoreSelection))
|
||||||
parser.ReformatInto(mEditWidget, mEditWidget.Content.mSelection.Value.MinPos, mEditWidget.Content.mSelection.Value.MaxPos);
|
parser.ReformatInto(mEditWidget, mEditWidget.Content.mSelection.Value.MinPos, mEditWidget.Content.mSelection.Value.MaxPos);
|
||||||
else
|
else
|
||||||
parser.ReformatInto(mEditWidget, 0, text.Length);
|
parser.ReformatInto(mEditWidget, 0, text.Length);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue