Example #1
0
CodeFormatter::~CodeFormatter()
{
    EventNotifier::Get()->Connect(
        wxEVT_FORMAT_STRING, clSourceFormatEventHandler(CodeFormatter::OnFormatString), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_FORMAT_FILE, clSourceFormatEventHandler(CodeFormatter::OnFormatFile), NULL, this);
    EventNotifier::Get()->Unbind(
        wxEVT_BEFORE_EDITOR_SAVE, clCommandEventHandler(CodeFormatter::OnBeforeFileSave), this);
}
Example #2
0
CodeFormatter::CodeFormatter(IManager* manager)
    : IPlugin(manager)
{
    m_longName = _("Source Code Formatter");
    m_shortName = wxT("Source Code Formatter");

    EventNotifier::Get()->Connect(
        wxEVT_FORMAT_STRING, clSourceFormatEventHandler(CodeFormatter::OnFormatString), NULL, this);
    EventNotifier::Get()->Connect(
        wxEVT_FORMAT_FILE, clSourceFormatEventHandler(CodeFormatter::OnFormatFile), NULL, this);
    m_mgr->GetTheApp()->Connect(ID_TOOL_SOURCE_CODE_FORMATTER,
                                wxEVT_COMMAND_MENU_SELECTED,
                                wxCommandEventHandler(CodeFormatter::OnFormatProject),
                                NULL,
                                this);
    EventNotifier::Get()->Bind(wxEVT_BEFORE_EDITOR_SAVE, clCommandEventHandler(CodeFormatter::OnBeforeFileSave), this);
    
    // Migrate settings if needed
    FormatOptions fmtroptions;
    m_mgr->GetConfigTool()->ReadObject("FormatterOptions", &fmtroptions);
    if(fmtroptions.GetEngine() == kFormatEngineClangFormat) {
        // check to see that the selected clang executable exists
        wxFileName clangFomatExe(fmtroptions.GetClangFormatExe());
        if(fmtroptions.GetClangFormatExe().IsEmpty() || !clangFomatExe.Exists()) {
            // No valid clang executable found, try to locate one
            clClangFormatLocator locator;
            wxString clangFormatPath;
            if(locator.Locate(clangFormatPath)) {
                fmtroptions.SetClangFormatExe(clangFormatPath);
            } else {
                // Change the active engine to AStyle
                fmtroptions.SetEngine(kFormatEngineAStyle);
                fmtroptions.SetClangFormatExe(""); // Clear the non existed executable
            }
            
            
        }
    }
    // Save the options
    EditorConfigST::Get()->WriteObject("FormatterOptions", &fmtroptions);
}