Skip to content

Commit

Permalink
clKeyboardManager revamping
Browse files Browse the repository at this point in the history
* Use `clKeyboardShortcut` class as a replacement of wxString.
* Remove the concept of menu and global accelerators.
* Delete `accelerators.conf.default`, migrate them into C++ source.
* Update translation files.
  • Loading branch information
rlbxku1r authored and eranif committed Jan 21, 2022
1 parent 7dea05b commit c88cc6c
Show file tree
Hide file tree
Showing 33 changed files with 5,995 additions and 4,781 deletions.
41 changes: 24 additions & 17 deletions CodeFormatter/codeformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "codeformatter.h"

#include "JSON.h"
#include "asyncprocess.h"
#include "clEditorConfig.h"
#include "clEditorStateLocker.h"
#include "clFilesCollector.h"
#include "clKeyboardManager.h"
#include "clSTCLineKeeper.h"
#include "clWorkspaceManager.h"
#include "codeformatterdlg.h"
Expand All @@ -42,14 +44,14 @@
#include "precompiled_header.h"
#include "procutils.h"
#include "workspace.h"
#include "wx/ffile.h"
#include "wx/log.h"
#include "wx/menu.h"

#include <algorithm>
#include <thread>
#include <wx/app.h> //wxInitialize/wxUnInitialize
#include <wx/ffile.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/menu.h>
#include <wx/msgdlg.h>
#include <wx/progdlg.h>
#include <wx/xrc/xmlres.h>
Expand All @@ -76,7 +78,7 @@ extern "C" char* STDCALL AStyleMain(const char* pSourceIn, const char* pOptions,
void STDCALL ASErrorHandler(int errorNumber, const char* errorMessage)
{
wxString errStr;
errStr << _U(errorMessage) << wxT(" (error ") << errorNumber << wxT(")");
errStr << _U(errorMessage) << " (error " << errorNumber << ")";
CL_DEBUG(errStr.c_str());
}

Expand All @@ -103,10 +105,10 @@ CL_PLUGIN_API IPlugin* CreatePlugin(IManager* manager)
CL_PLUGIN_API PluginInfo* GetPluginInfo()
{
static PluginInfo info;
info.SetAuthor(wxT("Eran Ifrah"));
info.SetName(wxT("Source Code Formatter"));
info.SetAuthor("Eran Ifrah");
info.SetName("Source Code Formatter");
info.SetDescription(_("Source Code Formatter (Supports C/C++/Obj-C/JavaScript/PHP files)"));
info.SetVersion(wxT("v2.0"));
info.SetVersion("v2.0");
return &info;
}

Expand All @@ -127,6 +129,10 @@ CodeFormatter::CodeFormatter(IManager* manager)
EventNotifier::Get()->Bind(wxEVT_PHP_SETTINGS_CHANGED, &CodeFormatter::OnPhpSettingsChanged, this);
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FOLDER, &CodeFormatter::OnContextMenu, this);

clKeyboardManager::Get()->AddAccelerator(
_("Source Code Formatter"),
{ { "format_source", _("Format Current Source"), "Ctrl-I" }, { "formatter_options", _("Options...") } });

m_optionsPhp.Load();
if(!m_mgr->GetConfigTool()->ReadObject("FormatterOptions", &m_options)) {
m_options.AutodetectSettings();
Expand Down Expand Up @@ -178,8 +184,9 @@ void CodeFormatter::OnFormat(wxCommandEvent& e)
}

// get the editor that requires formatting
if(!editor)
if(!editor) {
return;
}

int selStart = wxNOT_FOUND, selEnd = wxNOT_FOUND;
if(editor->GetSelectionStart() != wxNOT_FOUND && editor->GetSelectionStart() < editor->GetSelectionEnd()) {
Expand Down Expand Up @@ -568,7 +575,7 @@ void CodeFormatter::DoFormatWithAstyle(wxString& content, const bool& appendEOL)
bool useTabs = m_mgr->GetEditorSettings()->GetIndentUsesTabs();
int tabWidth = m_mgr->GetEditorSettings()->GetTabWidth();
int indentWidth = m_mgr->GetEditorSettings()->GetIndentWidth();
options << (useTabs && tabWidth == indentWidth ? wxT(" -t") : wxT(" -s")) << indentWidth;
options << (useTabs && tabWidth == indentWidth ? " -t" : " -s") << indentWidth;

char* textOut = AStyleMain(_C(content), _C(options), ASErrorHandler, ASMemoryAlloc);
content.clear();
Expand Down Expand Up @@ -663,8 +670,8 @@ void CodeFormatter::OnFormatOptions(wxCommandEvent& e)
wxUnusedVar(e);

wxString cppSampleFile, phpSampleFile, cppSample, phpSample;
cppSampleFile << m_mgr->GetStartupDirectory() << wxT("/astyle.sample");
phpSampleFile << m_mgr->GetStartupDirectory() << wxT("/php.sample");
cppSampleFile << m_mgr->GetStartupDirectory() << "/astyle.sample";
phpSampleFile << m_mgr->GetStartupDirectory() << "/php.sample";
ReadFileWithConversion(cppSampleFile, cppSample);
ReadFileWithConversion(phpSampleFile, phpSample);

Expand Down Expand Up @@ -739,11 +746,11 @@ void CodeFormatter::OnFormatString(clSourceFormatEvent& e)
int CodeFormatter::DoGetGlobalEOL() const
{
OptionsConfigPtr options = m_mgr->GetEditorSettings();
if(options->GetEolMode() == wxT("Unix (LF)")) {
if(options->GetEolMode() == "Unix (LF)") {
return 2;
} else if(options->GetEolMode() == wxT("Mac (CR)")) {
} else if(options->GetEolMode() == "Mac (CR)") {
return 1;
} else if(options->GetEolMode() == wxT("Windows (CRLF)")) {
} else if(options->GetEolMode() == "Windows (CRLF)") {
return 0;
} else {
// set the EOL by the hosting OS
Expand All @@ -760,12 +767,12 @@ wxString CodeFormatter::DoGetGlobalEOLString() const
{
switch(DoGetGlobalEOL()) {
case 0:
return wxT("\r\n");
return "\r\n";
case 1:
return wxT("\r");
return "\r";
case 2:
default:
return wxT("\n");
return "\n";
}
}

Expand Down
32 changes: 19 additions & 13 deletions CodeLiteDiff/codelitediff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,39 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "codelitediff.h"

#include "DiffFoldersFrame.h"
#include "DiffSideBySidePanel.h"
#include "NewFileComparison.h"
#include "clDiffFrame.h"
#include "clKeyboardManager.h"
#include "codelitediff.h"
#include "event_notifier.h"
#include "file_logger.h"
#include "macros.h"
#include "wx/menu.h"

#include <wx/ffile.h>
#include <wx/menu.h>
#include <wx/xrc/xmlres.h>
#include "DiffFoldersFrame.h"

static CodeLiteDiff* thePlugin = NULL;

// Define the plugin entry point
CL_PLUGIN_API IPlugin* CreatePlugin(IManager* manager)
{
if(thePlugin == 0) { thePlugin = new CodeLiteDiff(manager); }
if(thePlugin == 0) {
thePlugin = new CodeLiteDiff(manager);
}
return thePlugin;
}

CL_PLUGIN_API PluginInfo* GetPluginInfo()
{
static PluginInfo info;
info.SetAuthor(wxT("Eran Ifrah"));
info.SetName(wxT("Diff Plugin"));
info.SetAuthor("Eran Ifrah");
info.SetName("Diff Plugin");
info.SetDescription(_("CodeLite Diff Plugin"));
info.SetVersion(wxT("v1.0"));
info.SetVersion("v1.0");
return &info;
}

Expand All @@ -61,16 +65,16 @@ CodeLiteDiff::CodeLiteDiff(IManager* manager)
: IPlugin(manager)
{
m_longName = _("CodeLite Diff Plugin");
m_shortName = wxT("Diff Plugin");
m_shortName = "Diff Plugin";

Bind(wxEVT_MENU, &CodeLiteDiff::OnDiff, this, XRCID("diff_compare_with"));
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_TAB_LABEL, &CodeLiteDiff::OnTabContextMenu, this);
clKeyboardManager::Get()->AddGlobalAccelerator("diff_new_comparison", "Ctrl-Shift-C",
"Plugins::Diff Tool::New File Comparison");
clKeyboardManager::Get()->AddGlobalAccelerator("diff_new_folder", "Ctrl-Alt-F",
"Plugins::Diff Tool::New Folder Comparison");
wxTheApp->Bind(wxEVT_MENU, &CodeLiteDiff::OnNewDiff, this, XRCID("diff_new_comparison"));
wxTheApp->Bind(wxEVT_MENU, &CodeLiteDiff::OnNewDiffFolder, this, XRCID("diff_new_folder"));

clKeyboardManager::Get()->AddAccelerator(_("Diff Tool"),
{ { "diff_new_comparison", _("New File Comparison"), "Ctrl-Shift-C" },
{ "diff_new_folder", _("New Folder Comparison"), "Ctrl-Alt-F" } });
}

CodeLiteDiff::~CodeLiteDiff() {}
Expand Down Expand Up @@ -180,7 +184,9 @@ wxFileName CodeLiteDiff::SaveEditorToTmpfile(IEditor* editor) const
tpath << wxFileName::GetPathSeparator() << "CLdiff" << wxFileName::GetPathSeparator();
wxFileName::Mkdir(tpath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
wxFileName tmpFile(wxFileName::CreateTempFileName(tpath + editor->GetFileName().GetName()));
if(!tmpFile.IsOk()) { return wxFileName(); }
if(!tmpFile.IsOk()) {
return wxFileName();
}

tmpFile.SetExt(editor->GetFileName().GetExt());
wxFFile fp(tmpFile.GetFullPath(), "w+b");
Expand Down
Loading

0 comments on commit c88cc6c

Please sign in to comment.