Patch #1072 2006-05-23 04:11

game_ender

Users Changable Dynamic Side Column Width
Download
1072-Users_Changabl.patch (5.2 KB)
Category
Application::Refinement
Status
Rejected
Close date
2006-06-05 09:58
Assigned to
 
Index: src/sdk/editorconfigurationdlg.cpp
===================================================================
--- src/sdk/editorconfigurationdlg.cpp    (revision 2487)
+++ src/sdk/editorconfigurationdlg.cpp    (working copy)
@@ -122,6 +122,7 @@
        XRCCTRL(*this, "chkWordWrap", wxCheckBox)->SetValue(cfg->ReadBool(_T("/word_wrap"), false));
        XRCCTRL(*this, "chkShowLineNumbers", wxCheckBox)->SetValue(cfg->ReadBool(_T("/show_line_numbers"), true));
        XRCCTRL(*this, "chkHighlightCaretLine", wxCheckBox)->SetValue(cfg->ReadBool(_T("/highlight_caret_line"), false));
+       XRCCTRL(*this, "chkDynamicColumnWidth", wxCheckBox)->SetValue(cfg->ReadBool(_T("/dynamic_column_width"), false));
        XRCCTRL(*this, "spnTabSize", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/tab_size"), 4));
        XRCCTRL(*this, "cmbViewWS", wxComboBox)->SetSelection(cfg->ReadInt(_T("/view_whitespace"), 0));
        XRCCTRL(*this, "rbTabText", wxRadioBox)->SetSelection(cfg->ReadBool(_T("/tab_text_relative"), true) ? 1 : 0);
@@ -817,6 +818,7 @@
         cfg->Write(_T("/word_wrap"),             XRCCTRL(*this, "chkWordWrap", wxCheckBox)->GetValue());
         cfg->Write(_T("/show_line_numbers"),     XRCCTRL(*this, "chkShowLineNumbers", wxCheckBox)->GetValue());
         cfg->Write(_T("/highlight_caret_line"), XRCCTRL(*this, "chkHighlightCaretLine", wxCheckBox)->GetValue());
+        cfg->Write(_T("/dynamic_column_width"), XRCCTRL(*this, "chkDynamicColumnWidth", wxCheckBox)->GetValue());
         cfg->Write(_T("/tab_size"),             XRCCTRL(*this, "spnTabSize", wxSpinCtrl)->GetValue());
         cfg->Write(_T("/view_whitespace"),      XRCCTRL(*this, "cmbViewWS", wxComboBox)->GetSelection());
         cfg->Write(_T("/tab_text_relative"),    XRCCTRL(*this, "rbTabText", wxRadioBox)->GetSelection() ? true : false);
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp    (revision 2487)
+++ src/sdk/cbeditor.cpp    (working copy)
@@ -123,7 +123,8 @@
         m_ensure_consistent_line_ends(true),
         m_LastMarginMenuLine(-1),
         m_LastDebugLine(-1),
-        m_useByteOrderMark(false)
+        m_useByteOrderMark(false),
+        m_lineNumbersWidth(0)
     {
         m_encoding = wxLocale::GetSystemEncoding();
     }
@@ -248,6 +249,39 @@
         control->ConvertEOLs(control->GetEOLMode());
     }
 
+    /** Set line number column width */
+    void SetLineNumberColWidth()
+    {
+        ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("editor"));
+        int numberWidth = 0;
+        int dummy = 0;
+
+        // Gets the width of a '0' in pixels
+        m_pOwner->GetTextExtent(_T("0"), &numberWidth, &dummy);
+
+        int lineNumWidth = 1;
+        if(cfg->ReadBool(_T("/dynamic_column_width"), false))
+        {
+            int lineCount = m_pOwner->m_pControl->GetLineCount();
+
+            while (lineCount >= 10)
+            {
+                lineCount /= 10;
+                ++lineNumWidth;
+            }
+        }
+        else
+        {
+            lineNumWidth = 6;
+        }
+
+        if (lineNumWidth != m_lineNumbersWidth) {
+            int pixels = 5 + lineNumWidth * numberWidth;
+            m_pOwner->m_pControl->SetMarginWidth(0, pixels);
+            m_lineNumbersWidth = lineNumWidth;
+        }
+    }
+
     //vars
     bool m_strip_trailing_spaces;
     bool m_ensure_final_line_end;
@@ -259,6 +293,8 @@
     wxFontEncoding m_encoding;
     bool m_useByteOrderMark;
 
+    int m_lineNumbersWidth;
+
 };
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -350,8 +386,8 @@
 //    Manager::Get()->GetMessageManager()->DebugLog(_T("ctor: Filename=%s\nShort=%s"), m_Filename.c_str(), m_Shortname.c_str());
 
     CreateEditor();
+    m_IsOK = Open();
     SetEditorStyle();
-    m_IsOK = Open();
 
     // if !m_IsOK then it's a new file, so set the modified flag ON
     if (!m_IsOK && filename.IsEmpty())
@@ -579,8 +615,7 @@
     // line numbering
     m_pControl->SetMarginType(0, wxSCI_MARGIN_NUMBER);
        if (mgr->ReadBool(_T("/show_line_numbers"), true))
-        m_pControl->SetMarginWidth(0, mgr->ReadInt(_T("/margin/width"), 48));
-
+        m_pData->SetLineNumberColWidth();
     else
         m_pControl->SetMarginWidth(0, 0);
 
@@ -1871,6 +1906,9 @@
 
             line = m_pControl->MarkerPrevious(line - 1, 1 << BREAKPOINT_MARKER);
         }
+
+        // Adjust line numbers column
+        m_pData->SetLineNumberColWidth();
     }
 }
 
Index: src/sdk/resources/editor_configuration.xrc
===================================================================
--- src/sdk/resources/editor_configuration.xrc    (revision 2487)
+++ src/sdk/resources/editor_configuration.xrc    (working copy)
@@ -319,6 +319,12 @@
                                 <checked>1</checked>
                               </object>
                             </object>
+                            <object class="sizeritem">
+
download for full patch...
game_ender 2006-05-23 04:27

This patch make all the requested changes to patch 1066.

pchris 2006-05-23 06:46

Hello!

Great teamwork here :D

But there are two things I don't understand:

1) Why is the checkbox located on the General Settings tab? I think it belongs to the "Gutter, margins and caret" page.

2) This patch makes sethjackson's patch completely unnecessary. It would be better to combine them in a way like this:

If dynamic margin is not checked, the value of the box would be used, and this is defaulted to 48, so everyone will be happy ;)

If it is checked, the type-in field could be disabled.

Regards, Defender

game_ender 2006-05-23 13:36

I can't seem to find the patch by sethjackson you are talking about, but I will try to find it.

1)You are right, this really should go in "Gutter, margins and caret", that was just a mistake on my part.

2) You are saying there should be two settings here : One is a text box (or spinner), that is only valid (you can grey it out) if you don't have dynamic checked. I not have it use raw pixels, just tell it how many numbers you want to show. GetTextExtent, can take care of the rest.

game_ender 2006-05-23 13:37

I can't seem to find the patch by sethjackson you are talking about, but I will try to find it.

1)You are right, this really should go in "Gutter, margins and caret", that was just a mistake on my part.

2) You are saying there should be two settings here : One is a text box (or spinner), that is only valid (you can grey it out) if you don't have dynamic checked. I not have it use raw pixels, just tell it how many numbers you want to show. GetTextExtent, can take care of the rest.

game_ender 2006-05-23 13:41

Found the patch, number 1063, I should of been playing close attention to community patch list. Those change will be easy to roll into my patch. I should be able to do them tonight.

pchris 2006-05-23 14:21

I have combined the patches now, I think it will work, now I'm testing.

You can see it in a few minutes ;)

Regards, Defender

game_ender 2006-05-23 14:27

Sethjackson's patch (#1065) was applied as revision 2485, you should just be able to update your working copy and then make the needed changes. For now, I would just post the updated patch somewhere the forum so it can be tested before I update this patch.

mandrav 2006-06-05 09:58

Applied a more recent patch (or so I think!).