Add alignment command

Добавлена возможность запуска внешней команды для выравнивания текста
по разделителям. На java написан скрипт для выравнивания списков
align.jar. Запускать командой @java.exe -jar <PATH>\align.jar
которую нужно поместить в bat файл
This commit is contained in:
lsv 2023-05-02 15:55:46 +05:00
parent e9d088baed
commit 2fbed7a6a4
8 changed files with 56 additions and 7 deletions

View file

@ -929,7 +929,7 @@ void ctlSQLBox::OnEndProcess(wxProcessEvent &ev)
}
}
wxString ctlSQLBox::ExternalFormat()
wxString ctlSQLBox::ExternalFormat(int typecmd)
{
wxString msg;
processOutput = wxEmptyString;
@ -945,9 +945,14 @@ wxString ctlSQLBox::ExternalFormat()
return _("Nothing to format.");
wxString formatCmd = settings->GetExtFormatCmd();
wxString msgword = "formatt";
if (typecmd == 1) {
formatCmd = settings->GetExtAlignCmd();
msgword = "align";
}
if (formatCmd.IsEmpty())
{
return _("You need to setup a formatting command");
return _("You need to setup a "+msgword+"ing command");
}
if (process)
@ -967,7 +972,7 @@ wxString ctlSQLBox::ExternalFormat()
delete process;
process = NULL;
processID = 0;
msg = _("Couldn't run formatting command: ") + formatCmd;
msg = _("Couldn't run " + msgword + "ing command: ") + formatCmd;
return msg;
}
process->WriteOutputStream(processInput);
@ -989,7 +994,7 @@ wxString ctlSQLBox::ExternalFormat()
if (process)
{
AbortProcess();
return wxString::Format(_("Formatting command did not respond in %d ms"), timeoutMs);
return wxString::Format(_("" + msgword + "ing command did not respond in %d ms"), timeoutMs);
}
if (processExitCode != 0)
@ -1000,7 +1005,7 @@ wxString ctlSQLBox::ExternalFormat()
}
else if (processOutput.Trim().IsEmpty())
{
return _("Formatting command error: Output is empty.");
return _("" + msgword + "ing command error: Output is empty.");
}
if (isSelected)
@ -1008,7 +1013,7 @@ wxString ctlSQLBox::ExternalFormat()
else
SetText(processOutput);
return _("Formatting complete.");
return _("" + msgword + "ing complete.");
}
void ctlSQLBox::AbortProcess()

View file

@ -108,6 +108,7 @@
#define pickerMacrosFile CTRL_FILEPICKER("pickerMacrosFile")
#define pickerHistoryFile CTRL_FILEPICKER("pickerHistoryFile")
#define pickerExtFormatCmd CTRL_FILEPICKER("pickerExtFormatCmd")
#define pickerExtAlignCmd CTRL_FILEPICKER("pickerExtAlignCmd")
#define txtHistoryMaxQueries CTRL_TEXT("txtHistoryMaxQueries")
#define txtHistoryMaxQuerySize CTRL_TEXT("txtHistoryMaxQuerySize")
#define chkSQLUseSystemBackgroundColour CTRL_CHECKBOX("chkSQLUseSystemBackgroundColour")
@ -339,6 +340,7 @@ frmOptions::frmOptions(frmMain *parent)
pickerMacrosFile->SetPath(settings->GetMacrosFile());
pickerHistoryFile->SetPath(settings->GetHistoryFile());
pickerExtFormatCmd->SetPath(settings->GetExtFormatCmd());
pickerExtAlignCmd->SetPath(settings->GetExtAlignCmd());
txtHistoryMaxQueries->SetValue(NumToStr(settings->GetHistoryMaxQueries()));
txtHistoryMaxQuerySize->SetValue(NumToStr(settings->GetHistoryMaxQuerySize()));
@ -799,6 +801,7 @@ void frmOptions::OnOK(wxCommandEvent &ev)
settings->SetMacrosFile(pickerMacrosFile->GetPath());
settings->SetHistoryFile(pickerHistoryFile->GetPath());
settings->SetExtFormatCmd(pickerExtFormatCmd->GetPath());
settings->SetExtAlignCmd(pickerExtAlignCmd->GetPath());
// Change SQL Syntax colours
if (settings->GetSQLBoxUseSystemBackground() != chkSQLUseSystemBackgroundColour->GetValue())

View file

@ -173,6 +173,7 @@ BEGIN_EVENT_TABLE(frmQuery, pgFrame)
EVT_MENU(MNU_DOUBLEQUOTE_TEXT, frmQuery::OnDoubleText)
EVT_MENU(MNU_UNDOUBLEQUOTE_TEXT,frmQuery::OnUnDoubleText)
EVT_MENU(MNU_EXTERNALFORMAT, frmQuery::OnExternalFormat)
EVT_MENU(MNU_EXTERNALALIGN, frmQuery::OnExternalAlign)
EVT_MENU(MNU_LF, frmQuery::OnSetEOLMode)
EVT_MENU(MNU_CRLF, frmQuery::OnSetEOLMode)
EVT_MENU(MNU_CR, frmQuery::OnSetEOLMode)
@ -392,6 +393,7 @@ frmQuery::frmQuery(frmMain *form, const wxString &_title, pgConn *_conn, const w
formatMenu->Append(MNU_UNDOUBLEQUOTE_TEXT, _("Undouble the single quote\tCtrl-Shift-'"), _("Undouble the single quote"));
formatMenu->AppendSeparator();
formatMenu->Append(MNU_EXTERNALFORMAT, _("External Format\tCtrl-Shift-F"), _("Call external formatting command"));
formatMenu->Append(MNU_EXTERNALALIGN, _("External Align\tCtrl-Shift-A"), _("Call external align command"));
editMenu->AppendSubMenu(formatMenu, _("F&ormat"));
editMenu->Append(MNU_LINEENDS, _("&Line ends"), lineEndMenu);
editMenu->Append(MNU_AUTOREPLACE_MANAGE, _("Manage autoreplace..."), _("Edit and delete autoreplace strings"));
@ -4070,6 +4072,16 @@ void frmQuery::OnExternalFormat(wxCommandEvent &event)
sqlQuery->SetFocus(); // could loose focus after running formatting process
}
}
void frmQuery::OnExternalAlign(wxCommandEvent& event)
{
if (FindFocus()->GetId() == CTL_SQLQUERY)
{
wxBusyCursor wait;
SetStatusText(_("Running formatting command..."), STATUSPOS_MSGS);
SetStatusText(sqlQuery->ExternalFormat(1), STATUSPOS_MSGS);
sqlQuery->SetFocus(); // could loose focus after running formatting process
}
}
wxBitmap frmQuery::CreateBitmap(const wxColour &colour)
{

View file

@ -81,7 +81,7 @@ public:
bool BlockComment(bool uncomment = false);
bool BlockDouble(bool undouble = false);
void UpdateLineNumber();
wxString ExternalFormat();
wxString ExternalFormat(int typecmd = 0);
void AbortProcess();
void SetDefFunction(wxArrayString &name, wxArrayString &def);
CharacterRange RegexFindText(int minPos, int maxPos, const wxString &text);

View file

@ -262,6 +262,7 @@ private:
void OnDoubleText(wxCommandEvent& event);
void OnUnDoubleText(wxCommandEvent& event);
void OnExternalFormat(wxCommandEvent &event);
void OnExternalAlign(wxCommandEvent& event);
void OnDeleteCurrent(wxCommandEvent &event);
void OnDeleteAll(wxCommandEvent &event);

View file

@ -119,6 +119,7 @@ enum
MNU_DOUBLEQUOTE_TEXT,
MNU_UNDOUBLEQUOTE_TEXT,
MNU_EXTERNALFORMAT,
MNU_EXTERNALALIGN,
MNU_PLUGINBUTTONLIST,

View file

@ -477,6 +477,16 @@ public:
{
Write(wxT("ExtFormatCmd"), newval);
}
wxString GetExtAlignCmd()
{
wxString s;
Read(wxT("ExtAlignCmd"), &s, wxEmptyString);
return s;
}
void SetExtAlignCmd(const wxString& newval)
{
Write(wxT("ExtAlignCmd"), newval);
}
long GetExtFormatTimeout() const
{
long l;

View file

@ -535,6 +535,23 @@
<flag>wxEXPAND|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="stExtAlignCmd">
<label>External alignment utlity</label>
</object>
<flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
<object class="sizeritem">
<object class="wxFilePickerCtrl" name="pickerExtAlignCmd">
<message>Select utility to format text</message>
<wildcard>*</wildcard>
<style>wxFLP_OPEN|wxFLP_USE_TEXTCTRL</style>
<tooltip>A command line utility which reads STDIN and directs output to STDOUT.</tooltip>
</object>
<flag>wxEXPAND|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="stASUTPstyle">
<label>Enable ASUTP style</label>