Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format on save option #16

Open
wants to merge 1 commit into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.epic.perleditor.actions.*;
import org.epic.perleditor.preferences.MarkOccurrencesPreferences;
import org.epic.perleditor.preferences.PreferenceConstants;
import org.epic.perleditor.preferences.SourceFormatterPreferences;
import org.epic.perleditor.templates.perl.ModuleCompletionHelper;
import org.epic.perleditor.views.PerlOutlinePage;

Expand Down Expand Up @@ -154,6 +155,7 @@ public void doRevertToSaved()
*/
public void doSave(IProgressMonitor monitor)
{
formatIfEnabled();
super.doSave(monitor);
revalidateSyntax();
}
Expand All @@ -164,10 +166,29 @@ public void doSave(IProgressMonitor monitor)
*/
public void doSaveAs()
{
formatIfEnabled();
super.doSaveAs();
revalidateSyntax();
}

/**
* Run a format source action if enabled.
*/
private void formatIfEnabled()
{
IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] {
EditorsUI.getPreferenceStore(),
PerlEditorPlugin.getDefault().getPreferenceStore() });

boolean formatOnSave = store.getBoolean(SourceFormatterPreferences.FORMAT_ON_SAVE);

if (formatOnSave)
{
FormatSourceAction fsa = new FormatSourceAction(this);
fsa.run();
}
}

/**
* The PerlEditor implementation of this AbstractTextEditor method performs
* sets the input of the outline page after AbstractTextEditor has set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public void createFieldEditors() {
SourceFormatterPreferences.SWALLOW_OPTIONAL_BLANK_LINES,
"Swallow optional blank lines",
composite));

addField(
new BooleanFieldEditor(
SourceFormatterPreferences.FORMAT_ON_SAVE,
"Format on save",
composite));

// addField(new SpacerFieldEditor(composite));
// addField(new LabelFieldEditor("Container tightness:", composite));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SourceFormatterPreferences {
public static final String SWALLOW_OPTIONAL_BLANK_LINES ="Formatter.swallowOptionalBlankLines";
public static final String PERLTIDY_OPTIONS = "Formatter.perltidyOptions";
public static final String HTML_EXPORT_OPTIONS = "Formatter.htmlExportOptions";
public static final String FORMAT_ON_SAVE = "Formatter.formatOnSave";


/**
Expand All @@ -44,6 +45,7 @@ public static void initializeDefaultValues(IPreferenceStore store) {
// store.setDefault(CONTAINER_TIGHTNESS_SQUARE_BRACKETS, 1);
store.setDefault(PERLTIDY_OPTIONS, "");
store.setDefault(HTML_EXPORT_OPTIONS, "-toc");
store.setDefault(FORMAT_ON_SAVE, false);
}


Expand Down