Hi Team, Please find the patch for the above description.
As per Dave's suggestion, I have added format submenu in the edit menu. Just move the code for the indent/outdent to BlockIndent function & for commet/uncomment to BlockComment function. And called these function from the event function for the format menus and from the ctlSQLBox::OnKeyDown function, from where it has been moved. -- Regards, Ashesh Vashi EnterpriseDB INDIA: http://www.enterprisedb.com
Index: ctl/ctlSQLBox.cpp =================================================================== --- ctl/ctlSQLBox.cpp (revision 7729) +++ ctl/ctlSQLBox.cpp (working copy) @@ -335,72 +335,41 @@ break; } - // Save the start position - int start = GetSelectionStart(); - - // If more than one line is selected, then we may be doing a block indent. - if (GetSelectedText().Contains(lineEnd)) - { - // Figure out what a tab looks like - wxString newIndent; - if (GetUseTabs()) - newIndent = wxT("\t"); - else - { - for (int x=0; x < GetTabWidth(); x++ ) - newIndent += wxT(" "); - } - - // Block indent (Tab) - if (event.GetKeyCode() == '\t' && event.GetModifiers() == wxMOD_NONE) - { - wxString selection = GetSelectedText(); - selection.Replace(lineEnd, lineEnd + newIndent); - selection.Prepend(newIndent); - ReplaceSelection(selection); - SetSelection(start, start + selection.Length()); - return; - } - - // Block outdent (Shift+Tab) - if (event.GetKeyCode() == '\t' && event.GetModifiers() == wxMOD_SHIFT) - { - wxString selection = GetSelectedText(); - selection.Replace(lineEnd + newIndent, lineEnd); - if (selection.StartsWith(newIndent)) - selection = selection.Right(selection.Length() - newIndent.Length()); - ReplaceSelection(selection); - SetSelection(start, start + selection.Length()); - return; - } + /* + * Moved the code for Indentation and outdentation in BlockIndent(bool outdent) function + */ + if (event.GetKeyCode() == '\t') + { + // Block indent (Tab) + if (event.GetModifiers() == wxMOD_NONE) + { + if (BlockIndent(false)) + return; + } + // Block outdent (Shift+Tab) + else if (event.GetModifiers() == wxMOD_SHIFT) + { + if (BlockIndent(true)) + return; + } } - - // Commenting can be on any text, block or otherwise. - - // Ccomment (Ctrl+k) - if (!GetSelectedText().IsEmpty()) + /* + * Moved the code for the commenting & uncommenting in BlockComment(bool uncomment) function + */ + else if (event.GetKeyCode() == 'K') { - if (event.GetKeyCode() == 'K' && event.GetModifiers() == wxMOD_CONTROL) - { - wxString selection = GetSelectedText(); - selection.Replace(lineEnd, lineEnd + wxT("-- ")); - selection.Prepend(wxT("-- ")); - ReplaceSelection(selection); - SetSelection(start, start + selection.Length()); - return; - } - - // Uncomment (Ctrl+K) - if (event.GetKeyCode() == 'K' && event.GetModifiers() == (wxMOD_CONTROL | wxMOD_SHIFT)) - { - wxString selection = GetSelectedText(); - selection.Replace(lineEnd + wxT("-- "), lineEnd); - if (selection.StartsWith(wxT("-- "))) - selection = selection.Right(selection.Length() - 3); - ReplaceSelection(selection); - SetSelection(start, start + selection.Length()); - return; - } + // Comment (Ctrl+k) + if (event.GetModifiers() == wxMOD_CONTROL) + { + if (BlockComment(false)) + return; + } + // Uncomment (Ctrl+Shift+K) + else if (event.GetModifiers() == (wxMOD_CONTROL | wxMOD_SHIFT)) + { + if (BlockComment(true)) + return; + } } // Autocomplete @@ -461,6 +430,98 @@ event.Skip(); } +bool ctlSQLBox::BlockIndent(bool outdent) +{ + wxString lineEnd; + switch (GetEOLMode()) + { + case wxSTC_EOL_LF: + lineEnd = wxT("\n"); + break; + case wxSTC_EOL_CRLF: + lineEnd = wxT("\r\n"); + break; + case wxSTC_EOL_CR: + lineEnd = wxT("\r"); + break; + } + + // Save the start position + int start = GetSelectionStart(); + + // If more than one line is selected, then we may be doing a block indent/outdent. + if (GetSelectedText().Contains(lineEnd)) + { + // Figure out what a tab looks like + wxString newIndent; + if (GetUseTabs()) + newIndent = wxT("\t"); + else + { + for (int x=0; x < GetTabWidth(); x++ ) + newIndent += wxT(" "); + } + + wxString selection = GetSelectedText(); + // Block indent (Tab) + if (!outdent) + { + selection.Replace(lineEnd, lineEnd + newIndent); + selection.Prepend(newIndent); + } + else + { + selection.Replace(lineEnd + newIndent, lineEnd); + if (selection.StartsWith(newIndent)) + selection = selection.Right(selection.Length() - newIndent.Length()); + } + ReplaceSelection(selection); + SetSelection(start, start + selection.Length()); + return false; + } + return false; +} + +bool ctlSQLBox::BlockComment(bool uncomment) +{ + wxString lineEnd; + switch (GetEOLMode()) + { + case wxSTC_EOL_LF: + lineEnd = wxT("\n"); + break; + case wxSTC_EOL_CRLF: + lineEnd = wxT("\r\n"); + break; + case wxSTC_EOL_CR: + lineEnd = wxT("\r"); + break; + } + + // Save the start position + int start = GetSelectionStart(); + + if (!GetSelectedText().IsEmpty()) + { + wxString selection = GetSelectedText(); + if (!uncomment) + { + selection.Replace(lineEnd, lineEnd + wxT("-- ")); + selection.Prepend(wxT("-- ")); + } + else + { + selection.Replace(lineEnd + wxT("-- "), lineEnd); + if (selection.StartsWith(wxT("-- "))) + selection = selection.Right(selection.Length() - 3); + } + ReplaceSelection(selection); + SetSelection(start, start + selection.Length()); + return true; + } + return false; +} + void ctlSQLBox::OnKillFocus(wxFocusEvent& event) { AutoCompCancel(); Index: include/ctl/ctlSQLBox.h =================================================================== --- include/ctl/ctlSQLBox.h (revision 7729) +++ include/ctl/ctlSQLBox.h (working copy) @@ -56,7 +56,9 @@ bool ReplaceAll(const wxString &find, const wxString &replace, bool wholeWord, bool matchCase, bool useRegexps); bool DoFind(const wxString &find, const wxString &replace, bool doReplace, bool wholeWord, bool matchCase, bool useRegexps, bool startAtTop, bool reverse); void SetAutoIndent(bool on) { m_autoIndent = on; } - void EnableAutoComp(bool on) { m_autocompDisabled = on; } + void EnableAutoComp(bool on) { m_autocompDisabled = on; } + bool BlockIndent(bool outdent=false); + bool BlockComment(bool uncomment=false); CharacterRange RegexFindText(int minPos, int maxPos, const wxString& text); Index: include/frm/menu.h =================================================================== --- include/frm/menu.h (revision 7729) +++ include/frm/menu.h (working copy) @@ -88,6 +88,13 @@ MNU_SHOWINDENTGUIDES, MNU_QUICKREPORT, + MNU_UPPER_CASE, + MNU_LOWER_CASE, + MNU_BLOCK_INDENT, + MNU_BLOCK_OUTDENT, + MNU_COMMENT_TEXT, + MNU_UNCOMMENT_TEXT, + MNU_PLUGINBUTTONLIST, MNU_LINEENDS, Index: include/frm/frmQuery.h =================================================================== --- include/frm/frmQuery.h (revision 7729) +++ include/frm/frmQuery.h (working copy) @@ -155,6 +155,12 @@ void OnToggleOutputPane(wxCommandEvent& event); void OnAuiUpdate(wxAuiManagerEvent& event); void OnDefaultView(wxCommandEvent& event); + void OnChangeToUpperCase(wxCommandEvent& event); + void OnChangeToLowerCase(wxCommandEvent& event); + void OnBlockIndent(wxCommandEvent& event); + void OnBlockOutDent(wxCommandEvent& event); + void OnCommentText(wxCommandEvent& event); + void OnUncommentText(wxCommandEvent& event); void OnTimer(wxTimerEvent & event); @@ -181,6 +187,7 @@ wxMenu *favouritesMenu; wxMenu *macrosMenu; wxMenu *lineEndMenu; + wxMenu *formatMenu; wxString title; wxString lastFilename, lastDir; Index: frm/frmQuery.cpp =================================================================== --- frm/frmQuery.cpp (revision 7729) +++ frm/frmQuery.cpp (working copy) @@ -118,6 +118,12 @@ EVT_MENU(MNU_SCRATCHPAD, frmQuery::OnToggleScratchPad) EVT_MENU(MNU_OUTPUTPANE, frmQuery::OnToggleOutputPane) EVT_MENU(MNU_DEFAULTVIEW, frmQuery::OnDefaultView) +EVT_MENU(MNU_UPPER_CASE, frmQuery::OnChangeToUpperCase) +EVT_MENU(MNU_LOWER_CASE, frmQuery::OnChangeToLowerCase) +EVT_MENU(MNU_BLOCK_INDENT, frmQuery::OnBlockIndent) +EVT_MENU(MNU_BLOCK_OUTDENT, frmQuery::OnBlockOutDent) +EVT_MENU(MNU_COMMENT_TEXT, frmQuery::OnCommentText) +EVT_MENU(MNU_UNCOMMENT_TEXT, frmQuery::OnUncommentText) EVT_MENU(MNU_LF, frmQuery::OnSetEOLMode) EVT_MENU(MNU_CRLF, frmQuery::OnSetEOLMode) EVT_MENU(MNU_CR, frmQuery::OnSetEOLMode) @@ -199,6 +205,18 @@ editMenu->AppendSeparator(); editMenu->Append(MNU_AUTOINDENT, _("&Auto indent"), _("Automatically indent text to the same level as the preceding line"), wxITEM_CHECK); editMenu->Append(MNU_LINEENDS, _("&Line ends"), lineEndMenu); + + editMenu->AppendSeparator(); + formatMenu = new wxMenu(); + formatMenu->Append(MNU_UPPER_CASE, _("&Upper case\tCtrl-U"), _("Change the selected text to upper case")); + formatMenu->Append(MNU_LOWER_CASE, _("&Lower case\tCtrl-Shift-U"), _("Change the selected text to lower case")); + formatMenu->AppendSeparator(); + formatMenu->Append(MNU_BLOCK_INDENT, _("Block &Indent\tTab"), _("Indent the selected block")); + formatMenu->Append(MNU_BLOCK_OUTDENT, _("Block &Outdent\tShift-Tab"), _("Outdent the selected block")); + formatMenu->Append(MNU_COMMENT_TEXT, _("Co&mment Text\tCtrl-K"), _("Comment out the selected texts")); + formatMenu->Append(MNU_UNCOMMENT_TEXT, _("UnComme&nt Text\tCtrl-Shift-K"), _("Uncomment the selected texts")); + editMenu->AppendSubMenu(formatMenu, _("F&ormat")); + menuBar->Append(editMenu, _("&Edit")); queryMenu = new wxMenu(); @@ -2377,7 +2395,36 @@ adjustSizesTimer->Stop(); } +void frmQuery::OnChangeToUpperCase(wxCommandEvent& event) +{ + sqlQuery->UpperCase(); +} +void frmQuery::OnChangeToLowerCase(wxCommandEvent& event) +{ + sqlQuery->LowerCase(); +} + +void frmQuery::OnBlockIndent(wxCommandEvent& event) +{ +sqlQuery->BlockIndent(/*outdent*/ false); +} + +void frmQuery::OnBlockOutDent(wxCommandEvent& event) +{ + sqlQuery->BlockIndent(/*outdent*/ true); +} + +void frmQuery::OnCommentText(wxCommandEvent& event) +{ + sqlQuery->BlockComment(/*uncomment*/ false); +} + +void frmQuery::OnUncommentText(wxCommandEvent& event) +{ + sqlQuery->BlockComment(/*uncomment*/ true); +} + /////////////////////////////////////////////////////// wxWindow *queryToolBaseFactory::StartDialogSql(frmMain *form, pgObject *obj, const wxString &sql) @@ -2577,3 +2624,4 @@ // Write script output m_parent->writeScriptOutput(); } +
-- Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-hackers