Patch #3355 2012-11-01 14:20

alpha0010

EditorTweaks: Aligner - Auto
Download
3355-EditorTweaks_A.patch (7.6 KB)
Category
Plugin::FeatureAdd
Status
Accepted
Close date
2012-11-11 13:13
Assigned to
mortenmacfly
Index: src/plugins/contrib/EditorTweaks/EditorTweaks.cpp
===================================================================
--- src/plugins/contrib/EditorTweaks/EditorTweaks.cpp    (revision 8526)
+++ src/plugins/contrib/EditorTweaks/EditorTweaks.cpp    (working copy)
@@ -40,34 +40,35 @@
 
 }
 
-int id_et= wxNewId();
-int id_et_WordWrap= wxNewId();
-int id_et_ShowLineNumbers= wxNewId();
-int id_et_TabChar = wxNewId();
-int id_et_TabIndent = wxNewId();
-int id_et_TabSize2 = wxNewId();
-int id_et_TabSize4 = wxNewId();
-int id_et_TabSize6 = wxNewId();
-int id_et_TabSize8 = wxNewId();
-int id_et_ShowEOL = wxNewId();
+int id_et                     = wxNewId();
+int id_et_WordWrap            = wxNewId();
+int id_et_ShowLineNumbers     = wxNewId();
+int id_et_TabChar             = wxNewId();
+int id_et_TabIndent           = wxNewId();
+int id_et_TabSize2            = wxNewId();
+int id_et_TabSize4            = wxNewId();
+int id_et_TabSize6            = wxNewId();
+int id_et_TabSize8            = wxNewId();
+int id_et_ShowEOL             = wxNewId();
 int id_et_StripTrailingBlanks = wxNewId();
 int id_et_EnsureConsistentEOL = wxNewId();
-int id_et_EOLCRLF = wxNewId();
-int id_et_EOLCR = wxNewId();
-int id_et_EOLLF = wxNewId();
-int id_et_Fold1= wxNewId();
-int id_et_Fold2= wxNewId();
-int id_et_Fold3= wxNewId();
-int id_et_Fold4= wxNewId();
-int id_et_Fold5= wxNewId();
-int id_et_Unfold1= wxNewId();
-int id_et_Unfold2= wxNewId();
-int id_et_Unfold3= wxNewId();
-int id_et_Unfold4= wxNewId();
-int id_et_Unfold5= wxNewId();
-int id_et_align_others= wxNewId();
-int id_et_SuppressInsertKey= wxNewId();
-int id_et_ConvertBraces= wxNewId();
+int id_et_EOLCRLF             = wxNewId();
+int id_et_EOLCR               = wxNewId();
+int id_et_EOLLF               = wxNewId();
+int id_et_Fold1               = wxNewId();
+int id_et_Fold2               = wxNewId();
+int id_et_Fold3               = wxNewId();
+int id_et_Fold4               = wxNewId();
+int id_et_Fold5               = wxNewId();
+int id_et_Unfold1             = wxNewId();
+int id_et_Unfold2             = wxNewId();
+int id_et_Unfold3             = wxNewId();
+int id_et_Unfold4             = wxNewId();
+int id_et_Unfold5             = wxNewId();
+int id_et_align_others        = wxNewId();
+int id_et_align_auto          = wxNewId();
+int id_et_SuppressInsertKey   = wxNewId();
+int id_et_ConvertBraces       = wxNewId();
 
 // events handling
 BEGIN_EVENT_TABLE(EditorTweaks, cbPlugin)
@@ -114,7 +116,8 @@
 
     EVT_MENU(id_et_SuppressInsertKey, EditorTweaks::OnSuppressInsert)
     EVT_MENU(id_et_ConvertBraces, EditorTweaks::OnConvertBraces)
     EVT_MENU(id_et_align_others, EditorTweaks::OnAlignOthers)
+    EVT_MENU(id_et_align_auto, EditorTweaks::OnAlignAuto)
 END_EVENT_TABLE()
 
 // constructor
@@ -573,14 +592,15 @@
     for ( unsigned int i = 0; i < AlignerMenuEntries.size() ; i++ )
         alignerMenu->Append(AlignerMenuEntries[i].id, AlignerMenuEntries[i].MenuName + _T("\t")  + _T("[") + AlignerMenuEntries[i].ArgumentString + _T("]"));
     alignerMenu->AppendSeparator();
-    alignerMenu->Append(id_et_align_others, _T("more ..."));
+    alignerMenu->Append(id_et_align_auto,   _T("Auto"));
+    alignerMenu->Append(id_et_align_others, _T("More ..."));
 
     // attach aligner menu
     menu->AppendSeparator();
     menu->Append(wxID_ANY, _T("Aligner"), alignerMenu);
 
     return; // DISABLED ALL OF THE STUFF BELOW (IT IS ALREADY IN THE MAIN MENU BAR)
-
+#if 0
     // build "editor tweaks" menu
     wxMenu *submenu=new wxMenu(); //_("Editor Tweaks")
 
@@ -642,7 +662,7 @@
     submenu->Append( id_et_EnsureConsistentEOL, _( "Make EOLs Consistent Now" ), _( "Convert End-of-Line Characters to the Active Setting" ) );
 
     menu->Append(wxID_ANY, _T("Editor Tweaks"), submenu);
-
+#endif
 }
 
 void EditorTweaks::OnWordWrap(wxCommandEvent &/*event*/)
@@ -945,6 +965,86 @@
     }
 }
 
+void EditorTweaks::OnAlignAuto(wxCommandEvent& WXUNUSED(event))
+{
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+    if (!ed)
+        return;
+    cbStyledTextCtrl* stc = ed->GetControl();
+    if (!stc)
+        return;
+    int line_start = wxSCI_INVALID_POSITION;
+    int line_end   = wxSCI_INVALID_POSITION;
+    if (!GetSelectionLines(line_start, line_end))
+        return;
+    wxArrayString lines;
+    for (int i = line_start; i <= line_end; ++i)
+        lines.Add(stc->GetLine(i));
+    if (lines.GetCount() < 2)
+        return;
+    int lexer = stc->GetLexer();
+    wxArrayString out;
+    for (size_t i = 0; i < lines.GetCount(); ++i)
+    {
+        lines[i].Replace(wxT("\t"), wxT(" "));
+        // buffer assignment operators and commas in C++
+        if (lexer == wxSCI_LEX_CPP)
+        {
+            const wxString op = wxT("=<>!+-*/%&^| "); // do not split compound operators
+            for (int j = lines[i].Length() - 2; j >= 0; --j)
+            {
+                if (   lines[i][j] == wxT(',')
+                    || (lines[i][j] == w
download for full patch...
mortenmacfly 2012-11-07 10:12

This patch needs an update according the latest changes in SVN (this time I am not guilty... ;-))-

alpha0010 2012-11-08 01:01

Updated to trunk.