Patch #3040 2010-07-27 18:30

weiti83

Add CurrentSelection to the Macros
Download
3040-Add_CurrentSel.patch (1.9 KB)
Category
Application::FeatureAdd
Status
Accepted
Close date
2010-08-11 14:19
Assigned to
mortenmacfly
Index: macrosmanager.cpp
===================================================================
--- macrosmanager.cpp    (Revision 6378)
+++ macrosmanager.cpp    (Arbeitskopie)
@@ -155,6 +155,27 @@
     m_Macros[_T("WORKSPACEDIRECTORY")]  = m_WorkspaceDir;
 }
 
+wxString GetSelectedText()
+{
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
+    if (ed)
+    {
+        cbStyledTextCtrl* stc = ed->GetControl();
+        wxString text = stc->GetSelectedText();
+        if ( text.size() )
+        {
+            return text;
+        }
+        else
+        {
+            int iCurrentPos = stc->GetCurrentPos();
+            return stc->GetTextRange(stc->WordStartPosition(iCurrentPos, true), stc->WordEndPosition(iCurrentPos, true));
+        }
+    }
+
+    return wxT("");
+}
+
 void MacrosManager::RecalcVars(cbProject* project, EditorBase* editor, ProjectBuildTarget* target)
 {
     m_ActiveEditorFilename = wxEmptyString; // invalidate
@@ -340,6 +361,8 @@
     temp_str.Printf(_T("%d"), (m_ActiveEditorColumn>0) ? m_ActiveEditorColumn-1 : -1); // zero based, but keep value for "invalid"
     m_Macros[_T("ACTIVE_EDITOR_COLUMN_0")] = temp_str;
 
+    m_Macros[_T("ACTIVE_EDITOR_SELECTION")]=GetSelectedText();
+
     wxDateTime now(wxDateTime::Now());
     m_Macros[_T("TDAY")]        = now.Format(_T("%Y%m%d"));
     m_Macros[_T("TODAY")]       = now.Format(_T("%Y-%m-%d"));
Index: edit_tool.xrc
===================================================================
--- edit_tool.xrc    (Revision 6378)
+++ edit_tool.xrc    (Arbeitskopie)
@@ -108,6 +108,7 @@
 $${ACTIVE_EDITOR_FILENAME}
 $${ACTIVE_EDITOR_LINE} ($${ACTIVE_EDITOR_LINE_0})
 $${ACTIVE_EDITOR_COLUMN} ($${ACTIVE_EDITOR_COLUMN_0})
+$${ACTIVE_EDITOR_SELECTION}
 $${ALL_PROJECT_FILES}
 $${TARGET_OUTPUT_DIR}
 $${TARGET_NAME}
@@ -150,4 +151,4 @@
       </object>
     </object>
   </object>
-</resource>
\ No newline at end of file
+</resource>