Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

wrap char mode feature added for Editor Tweak plugin

(1/7) > >>

ollydbg:
When I try to edit a text file which contains some Chinese words, I see that the wrap word feature is ugly.
See the original view (no wrap enabled)

Now, when wrap word enabled, you can see the long Chinese sentence was treated as a single word, so there will be long empty spaces after the word "efg".


As I see the Scintilla component support "wrap char" feature, I just enabled it, and now it looks better.


The document said in http://www.scintilla.org/ScintillaDoc.html#LineWrapping

--- Quote ---SCI_SETWRAPMODE(int wrapMode)
SCI_GETWRAPMODE
Set wrapMode to SC_WRAP_WORD (1) to enable wrapping on word boundaries, SC_WRAP_CHAR (2) to enable wrapping between any characters, and to SC_WRAP_NONE (0) to disable line wrapping. SC_WRAP_CHAR is preferred to SC_WRAP_WORD for Asian languages where there is no white space between words.

--- End quote ---

Patch is below:

--- Code: ---From a65d48522278281a0106ce22b74d7c5c3a89dfb1 Mon Sep 17 00:00:00 2001
From: asmwarrior <asmwarrior@gmail.com>
Date: Thu, 19 Sep 2013 18:11:27 +0800
Subject: [PATCH] * EditorTweaks: introduce wrap char mode

---
 src/plugins/contrib/EditorTweaks/EditorTweaks.cpp | 31 +++++++++++++++++++----
 src/plugins/contrib/EditorTweaks/EditorTweaks.h   |  1 +
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/plugins/contrib/EditorTweaks/EditorTweaks.cpp b/src/plugins/contrib/EditorTweaks/EditorTweaks.cpp
index cfa8062..88939af 100644
--- a/src/plugins/contrib/EditorTweaks/EditorTweaks.cpp
+++ b/src/plugins/contrib/EditorTweaks/EditorTweaks.cpp
@@ -42,6 +42,7 @@ namespace
 
 int id_et                     = wxNewId();
 int id_et_WordWrap            = wxNewId();
+int id_et_CharWrap            = wxNewId();
 int id_et_ShowLineNumbers     = wxNewId();
 int id_et_TabChar             = wxNewId();
 int id_et_TabIndent           = wxNewId();
@@ -75,6 +76,7 @@ int id_et_ScrollTimer         = wxNewId();
 // events handling
 BEGIN_EVENT_TABLE(EditorTweaks, cbPlugin)
     EVT_UPDATE_UI(id_et_WordWrap, EditorTweaks::OnUpdateUI)
+    EVT_UPDATE_UI(id_et_CharWrap, EditorTweaks::OnUpdateUI)
     EVT_UPDATE_UI(id_et_ShowLineNumbers, EditorTweaks::OnUpdateUI)
     EVT_UPDATE_UI(id_et_TabChar, EditorTweaks::OnUpdateUI)
     EVT_UPDATE_UI(id_et_TabIndent, EditorTweaks::OnUpdateUI)
@@ -91,6 +93,7 @@ BEGIN_EVENT_TABLE(EditorTweaks, cbPlugin)
 
 
     EVT_MENU(id_et_WordWrap, EditorTweaks::OnWordWrap)
+    EVT_MENU(id_et_CharWrap, EditorTweaks::OnCharWrap)
     EVT_MENU(id_et_ShowLineNumbers, EditorTweaks::OnShowLineNumbers)
     EVT_MENU(id_et_TabChar, EditorTweaks::OnTabChar)
     EVT_MENU(id_et_TabIndent, EditorTweaks::OnTabIndent)
@@ -276,7 +279,8 @@ void EditorTweaks::BuildMenu(wxMenuBar* menuBar)
 
     wxMenu *submenu=m_tweakmenu; //_("Editor Tweaks")
 
-    submenu->AppendCheckItem( id_et_WordWrap, _( "Word wrap" ), _( "Wrap text" ) );
+    submenu->AppendCheckItem( id_et_WordWrap, _( "Word wrap" ), _( "Wrap word" ) );
+    submenu->AppendCheckItem( id_et_CharWrap, _( "Char wrap" ), _( "Wrap char" ) );
     submenu->AppendCheckItem( id_et_ShowLineNumbers, _( "Show Line Numbers" ), _( "Show Line Numbers" ) );
     submenu->AppendSeparator();
     submenu->AppendCheckItem( id_et_TabChar, _( "Use Tab Character" ), _( "Use Tab Character" ) );
@@ -359,7 +363,8 @@ void EditorTweaks::UpdateUI()
     wxMenu *submenu = m_tweakmenu; //_("Editor Tweaks") TODO: Retrieve actual menu
 
     m_isUpdatingUI = true; // ignore events the following can trigger
-    submenu->Check(id_et_WordWrap,ed->GetControl()->GetWrapMode()>0);
+    submenu->Check(id_et_WordWrap,ed->GetControl()->GetWrapMode()==wxSCI_WRAP_WORD);
+    submenu->Check(id_et_CharWrap,ed->GetControl()->GetWrapMode()==wxSCI_WRAP_CHAR);
     submenu->Check(id_et_ShowLineNumbers,ed->GetControl()->GetMarginWidth(0)>0);
     submenu->Check(id_et_TabChar,ed->GetControl()->GetUseTabs());
     submenu->Check(id_et_TabIndent,ed->GetControl()->GetTabIndents());
@@ -639,10 +644,14 @@ void EditorTweaks::BuildModuleMenu(const ModuleType type, wxMenu* menu, const Fi
 
     menu->Append(id_et,_("Editor Tweaks"),submenu);
 
-    submenu->AppendCheckItem( id_et_WordWrap, _( "Word wrap" ), _( "Wrap text" ) );
-    if (ed->GetControl()->GetWrapMode()>0)
+    submenu->AppendCheckItem( id_et_WordWrap, _( "Word wrap" ), _( "Wrap word" ) );
+    if (ed->GetControl()->GetWrapMode()==wxSCI_WRAP_WORD)
         submenu->Check(id_et_WordWrap,true);
 
+    submenu->AppendCheckItem( id_et_CharWrap, _( "Char wrap" ), _( "Wrap char" ) );
+    if (ed->GetControl()->GetWrapMode()==wxSCI_WRAP_CHAR)
+        submenu->Check(id_et_CharWrap,true);
+
     submenu->AppendCheckItem( id_et_ShowLineNumbers, _( "Show Line Numbers" ), _( "Show Line Numbers" ) );
     if (ed->GetControl()->GetMarginWidth(0)>0)
         submenu->Check(id_et_ShowLineNumbers,true);
@@ -704,14 +713,26 @@ void EditorTweaks::OnWordWrap(wxCommandEvent &/*event*/)
     if (!ed || !ed->GetControl() || m_isUpdatingUI)
         return;
 
-    bool enabled=ed->GetControl()->GetWrapMode()>0;
+    bool enabled=ed->GetControl()->GetWrapMode()==wxSCI_WRAP_WORD;
 
     if (enabled)
         ed->GetControl()->SetWrapMode(wxSCI_WRAP_NONE);
     else
         ed->GetControl()->SetWrapMode(wxSCI_WRAP_WORD);
+}
+
+void EditorTweaks::OnCharWrap(wxCommandEvent &/*event*/)
+{
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+    if (!ed || !ed->GetControl() || m_isUpdatingUI)
+        return;
 
+    bool enabled=ed->GetControl()->GetWrapMode()==wxSCI_WRAP_CHAR;
 
+    if (enabled)
+        ed->GetControl()->SetWrapMode(wxSCI_WRAP_NONE);
+    else
+        ed->GetControl()->SetWrapMode(wxSCI_WRAP_CHAR);
 }
 
 void EditorTweaks::OnShowLineNumbers(wxCommandEvent &/*event*/)
diff --git a/src/plugins/contrib/EditorTweaks/EditorTweaks.h b/src/plugins/contrib/EditorTweaks/EditorTweaks.h
index aa15f9a..86c3074 100644
--- a/src/plugins/contrib/EditorTweaks/EditorTweaks.h
+++ b/src/plugins/contrib/EditorTweaks/EditorTweaks.h
@@ -106,6 +106,7 @@ class EditorTweaks : public cbPlugin
         void OnKeyPress(wxKeyEvent& event);
         void OnChar(wxKeyEvent& event);
         void OnWordWrap(wxCommandEvent &event);
+        void OnCharWrap(wxCommandEvent &event);
         void OnShowLineNumbers(wxCommandEvent &event);
         void OnTabChar(wxCommandEvent &event);
         void OnTabIndent(wxCommandEvent &event);
--
1.8.4.msysgit.0


--- End code ---

Comments?

oBFusCATed:
Calling ed->GetControl() at every line is plain ugly. Please save it in a variable and use it instead.

ollydbg:

--- Quote from: oBFusCATed on September 19, 2013, 12:23:12 pm ---Calling ed->GetControl() at every line is plain ugly. Please save it in a variable and use it instead.

--- End quote ---
No, I did not do that. Wrap mode is set once for the whole editor, no need for each lines.

oBFusCATed:

--- Code: ---void EditorTweaks::OnCharWrap(wxCommandEvent &/*event*/)
+{
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+    if (!ed || !ed->GetControl() || m_isUpdatingUI)
+        return;
 
+    bool enabled=ed->GetControl()->GetWrapMode()==wxSCI_WRAP_CHAR;
 
+    if (enabled)
+        ed->GetControl()->SetWrapMode(wxSCI_WRAP_NONE);
+    else
+        ed->GetControl()->SetWrapMode(wxSCI_WRAP_CHAR);
 }

--- End code ---

Count the number of occurrences of ed->GetControl() and then count the number of lines of the function:)

ollydbg:

--- Quote from: oBFusCATed on September 19, 2013, 02:34:06 pm ---
--- Code: ---void EditorTweaks::OnCharWrap(wxCommandEvent &/*event*/)
+{
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+    if (!ed || !ed->GetControl() || m_isUpdatingUI)
+        return;
 
+    bool enabled=ed->GetControl()->GetWrapMode()==wxSCI_WRAP_CHAR;
 
+    if (enabled)
+        ed->GetControl()->SetWrapMode(wxSCI_WRAP_NONE);
+    else
+        ed->GetControl()->SetWrapMode(wxSCI_WRAP_CHAR);
 }

--- End code ---

Count the number of occurrences of ed->GetControl() and then count the number of lines of the function:)


--- End quote ---
OK, the function name cause confusion. :)
This function is a menu click handler. There was a function named "OnWordWrap", so I add this one named "OnCharWrap".

Navigation

[0] Message Index

[#] Next page

Go to full version