void ToDoList::OnAttach() { // create ToDo in bottom view wxArrayString titles; wxArrayInt widths; titles.Add(_("Type")); widths.Add(64); titles.Add(_("Text")); widths.Add(320); titles.Add(_("User")); widths.Add(64); titles.Add(_("Prio")); widths.Add(48); titles.Add(_("Line")); widths.Add(48); titles.Add(_("Date")); widths.Add(56); titles.Add(_("File")); widths.Add(640); m_pListLog = new ToDoListView(titles, widths, m_Types); m_StandAlone = Manager::Get()->GetConfigManager(_T("todo_list"))->ReadBool(_T("stand_alone"), true); if (!m_StandAlone) { LogManager* msgMan = Manager::Get()->GetLogManager(); m_ListPageIndex = msgMan->SetLog(m_pListLog); msgMan->Slot(m_ListPageIndex).title = _("To Do"); CodeBlocksLogEvent evt(cbEVT_ADD_LOG_WINDOW, m_pListLog, msgMan->Slot(m_ListPageIndex).title, msgMan->Slot(m_ListPageIndex).icon); Manager::Get()->ProcessEvent(evt); } else { m_pListLog->CreateControl(Manager::Get()->GetAppWindow()); m_pListLog->GetWindow()->SetSize(wxSize(352,94)); m_pListLog->GetWindow()->SetInitialSize(wxSize(352,94)); CodeBlocksDockEvent evt(cbEVT_ADD_DOCK_WINDOW); evt.name = _T("TodoListPanev2.0.0"); evt.title = _("Todo list"); evt.pWindow = m_pListLog->GetWindow(); evt.dockSide = CodeBlocksDockEvent::dsFloating; evt.desiredSize.Set(352, 94); evt.floatingSize.Set(352, 94); evt.minimumSize.Set(352, 94); Manager::Get()->ProcessEvent(evt); } m_AutoRefresh = Manager::Get()->GetConfigManager(_T("todo_list"))->ReadBool(_T("auto_refresh"), true); LoadUsers(); LoadTypes(); // register event sink Manager::Get()->RegisterEventSink(cbEVT_APP_STARTUP_DONE, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnAppDoneStartup)); Manager::Get()->RegisterEventSink(cbEVT_EDITOR_OPEN, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparseCurrent)); Manager::Get()->RegisterEventSink(cbEVT_EDITOR_SAVE, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparseCurrent)); Manager::Get()->RegisterEventSink(cbEVT_EDITOR_ACTIVATED, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparseCurrent)); Manager::Get()->RegisterEventSink(cbEVT_EDITOR_CLOSE, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparseCurrent)); Manager::Get()->RegisterEventSink(cbEVT_PROJECT_CLOSE, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparse)); Manager::Get()->RegisterEventSink(cbEVT_PROJECT_ACTIVATE, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparse)); Manager::Get()->RegisterEventSink(cbEVT_PROJECT_FILE_ADDED, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparse)); Manager::Get()->RegisterEventSink(cbEVT_PROJECT_FILE_REMOVED, new cbEventFunctor<ToDoList, CodeBlocksEvent>(this, &ToDoList::OnReparse)); }
BOOL WINAPI RawDllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID) { if (ul_reason_for_call == DLL_PROCESS_ATTACH) { try { LoadTypes(&_Module, hModule); } catch (Exception* e) { DebugTrace(e->get_Reason() << "\n"); return FALSE; } } return TRUE; }
void ToDoList::OnAddItem(cb_unused wxCommandEvent& event) { cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor(); if (!ed) return; EditorColourSet* colour_set = Manager::Get()->GetEditorManager()->GetColourSet(); if (!colour_set) return; HighlightLanguage hlang = colour_set->GetLanguageName(ed->GetLanguage()); bool edIsCCpp = (hlang == _T("C/C++")); CommentToken token = colour_set->GetCommentToken(ed->GetLanguage()); bool hasStreamComments = not token.streamCommentStart.IsEmpty(); bool hasLineComments = not token.lineComment.IsEmpty(); if (!(edIsCCpp||hasLineComments||hasStreamComments)) return; std::bitset<(int)tdctError+1> supportedTdcts; supportedTdcts[tdctLine] = !(token.lineComment.IsEmpty()); supportedTdcts[tdctStream] = !(token.streamCommentStart.IsEmpty()); supportedTdcts[tdctDoxygenLine] = !(token.doxygenLineComment.IsEmpty()); supportedTdcts[tdctDoxygenStream] = !(token.doxygenStreamCommentStart.IsEmpty()); supportedTdcts[tdctWarning] = edIsCCpp; supportedTdcts[tdctError] = edIsCCpp; // display todo dialog AddTodoDlg dlg(Manager::Get()->GetAppWindow(), m_Users, m_Types, supportedTdcts ); PlaceWindow(&dlg); if (dlg.ShowModal() != wxID_OK) return; // Re-load users and types as they might have changed by the user via AddTodoDlg LoadUsers(); LoadTypes(); cbStyledTextCtrl* control = ed->GetControl(); // calculate insertion point int idx = 0; int crlfLen = 0; // length of newline chars int origPos = control->GetCurrentPos(); // keep current position in the document int line = control->GetCurrentLine(); // current line ToDoCommentType CmtType = dlg.GetCommentType(); if (dlg.GetPosition() == tdpCurrent) { idx = control->GetCurrentPos(); // current position in the document // if the style is cpp comments (// ...), there's the possibility that the current position // is somewhere in the middle of a line of code; this would result // in everything after the insertion point to turn into comments // let's double check this with the user if (idx != control->GetLineEndPosition(line) && (CmtType != tdctStream) && (CmtType != tdctDoxygenStream)) { // let's ask the user, and present as options // keep cpp style at current position, switch to c style, add the todo at the end (keeping cpp style) // if user cancels out / do nothing : just return // future idea : check if there's any non white space character // if yes -> in the middle of code // if no -> then only whitespace after the insertion point -> no harm to turn that into comments wxString streamStart = token.streamCommentStart, streamEnd = token.streamCommentEnd; if (CmtType == tdctDoxygenLine && !token.doxygenStreamCommentStart.IsEmpty()) { streamStart = token.doxygenStreamCommentStart; streamEnd = token.doxygenStreamCommentEnd; } AskTypeDlg asktype_dlg(Manager::Get()->GetAppWindow(), streamStart, streamEnd); PlaceWindow(&asktype_dlg); if (asktype_dlg.ShowModal() != wxID_OK) return; switch(asktype_dlg.GetTypeCorrection()) { case tcStay: break; // do nothing, leave things as they are case tcSwitch: if (CmtType == tdctDoxygenLine) CmtType = tdctDoxygenStream; else CmtType = tdctStream; break; case tcMove: default: idx = control->GetLineEndPosition(line); break; } // end switch } } else { if (dlg.GetPosition() == tdpAbove) idx = control->GetLineEndPosition(line - 1); // get previous line's end else if (dlg.GetPosition() == tdpBelow) idx = control->GetLineEndPosition(line); // get current line's end // calculate insertion point by skipping next newline switch (control->GetEOLMode()) { case wxSCI_EOL_CRLF: crlfLen = 2; break; case wxSCI_EOL_CR: // fall-though case wxSCI_EOL_LF: // fall-though default: crlfLen = 1; break; } if (idx > 0) idx += crlfLen; } // make sure insertion point is valid (bug #1300981) if (idx > control->GetLength()) idx = control->GetLength(); // ok, construct todo line text like this: // TODO (mandrav#0#): Implement code to do this and the other... wxString buffer; // start with the comment switch(CmtType) { default: case tdctLine: buffer << token.lineComment; break; case tdctDoxygenLine: buffer << token.doxygenLineComment; break; case tdctDoxygenStream: buffer << token.doxygenStreamCommentStart; break; case tdctWarning: buffer << _T("#warning"); break; case tdctError: buffer << _T("#error"); break; case tdctStream: buffer << token.streamCommentStart; break; } // end switch buffer << _T(" "); // continue with the type buffer << dlg.GetType() << _T(" "); wxString priority = wxString::Format(_T("%d"), dlg.GetPriority()); // do it like this (wx bug with int and streams) // now do the () part buffer << _T("(") << dlg.GetUser() << _T("#") << priority << _T("#") << (dlg.DateRequested() ? (wxDateTime::Today().Format(_T("%x): "))) : _T("): ")); wxString text = dlg.GetText(); // make sure that multi-line notes, don't break the todo if ( (CmtType == tdctWarning) || (CmtType == tdctError) ) { if (text.Replace(_T("\r\n"), _T("\\\r\n")) == 0) text.Replace(_T("\n"), _T("\\\n")); // now see if there were already a backslash before newline if (text.Replace(_T("\\\\\r\n"), _T("\\\r\n")) == 0) text.Replace(_T("\\\\\n"), _T("\\\n")); } else if (CmtType == tdctLine || (CmtType == tdctDoxygenLine)) { wxString lc; if (CmtType == tdctLine) lc = token.lineComment; else lc = token.doxygenLineComment; // comment every line from the todo text if ( text.Replace(_T("\r\n"), _T("\r\n")+lc) == 0 ) text.Replace(_T("\n"), _T("\n")+lc); // indicate (on the first line) that there is some more text if ( text.Replace(_T("\r\n"), _T(" ...\r\n"),false) == 0 ) text.Replace(_T("\n"), _T(" ...\n"),false); } // add the actual text buffer << text; if ( CmtType == tdctStream ) buffer << _T(" ") << token.streamCommentEnd; if ( CmtType == tdctDoxygenStream ) buffer << _T(" ") << token.doxygenStreamCommentEnd; // add newline char(s), only if dlg.GetPosition() != tdpCurrent if (dlg.GetPosition() != tdpCurrent) buffer << GetEOLStr(control->GetEOLMode()); // ok, insert the todo line text control->InsertText(idx, buffer); if (dlg.GetPosition() == tdpAbove) origPos += buffer.Length() + crlfLen; control->GotoPos(origPos); control->EnsureCaretVisible(); ParseCurrent(true); } // end of OnAddItem
void ToDoList::OnAddItem(wxCommandEvent& event) { cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor(); if (!ed) return; // display todo dialog AddTodoDlg dlg(Manager::Get()->GetAppWindow(), m_Users, m_Types); PlaceWindow(&dlg); if (dlg.ShowModal() != wxID_OK) return; // Re-load users and types as they might have changed by the user via AddTodoDlg LoadUsers(); LoadTypes(); cbStyledTextCtrl* control = ed->GetControl(); // calculate insertion point int idx = 0; int crlfLen = 0; // length of newline chars int origPos = control->GetCurrentPos(); // keep current position in the document int line = control->GetCurrentLine(); // current line ToDoCommentType CmtType = dlg.GetCommentType(); if (dlg.GetPosition() == tdpCurrent) { idx = control->GetCurrentPos(); // current position in the document // if the style is cpp comments (// ...), there's the possibility that the current position // is somewhere in the middle of a line of code; this would result // in everything after the insertion point to turn into comments // let's double check this with the user if (idx != control->GetLineEndPosition(line)) { // let's ask the user, and present as options // keep cpp style at current position, switch to c style, add the todo at the end (keeping cpp style) // if user cancels out / do nothing : just return // future idea : check if there's any non white space character // if yes -> in the middle of code // if no -> then only whitespace after the insertion point -> no harm to turn that into comments AskTypeDlg dlg(Manager::Get()->GetAppWindow()); PlaceWindow(&dlg); if (dlg.ShowModal() != wxID_OK) return; switch(dlg.GetTypeCorrection()) { case tcCppStay: break; // do nothing, leave things as they are case tcCpp2C: CmtType = tdctC; break; case tcCppMove: default: idx = control->GetLineEndPosition(line); break; } // end switch } } else { if (dlg.GetPosition() == tdpAbove) idx = control->GetLineEndPosition(line - 1); // get previous line's end else if (dlg.GetPosition() == tdpBelow) idx = control->GetLineEndPosition(line); // get current line's end // calculate insertion point by skipping next newline switch (control->GetEOLMode()) { case wxSCI_EOL_CR: case wxSCI_EOL_LF: crlfLen = 1; break; case wxSCI_EOL_CRLF: crlfLen = 2; break; } if (idx > 0) idx += crlfLen; } // make sure insertion point is valid (bug #1300981) if (idx > control->GetLength()) idx = control->GetLength(); // ok, construct todo line text like this: // TODO (mandrav#0#): Implement code to do this and the other... wxString buffer; // start with the comment switch(CmtType) { case tdctCpp: buffer << _T("// "); break; case tdctDoxygenC: buffer << _T("/** "); break; case tdctDoxygenCPP: buffer << _T("/// "); break; case tdctWarning: buffer << _T("#warning "); break; case tdctError: buffer << _T("#error "); break; default: buffer << _T("/* "); break; } // end switch // continue with the type buffer << dlg.GetType() << _T(" "); wxString priority = wxString::Format(_T("%d"), dlg.GetPriority()); // do it like this (wx bug with int and streams) // now do the () part buffer << _T("(") << dlg.GetUser() << _T("#") << priority << _T("#): "); wxString text = dlg.GetText(); if ( (CmtType != tdctC) && (CmtType != tdctDoxygenC) ) { // make sure that multi-line notes, don't break the todo if (text.Replace(_T("\r\n"), _T("\\\r\n")) == 0) text.Replace(_T("\n"), _T("\\\n")); // now see if there were already a backslash before newline if (text.Replace(_T("\\\\\r\n"), _T("\\\r\n")) == 0) text.Replace(_T("\\\\\n"), _T("\\\n")); } // add the actual text buffer << text; if ( (CmtType == tdctWarning) || (CmtType == tdctError) ) buffer << _T(""); else if ( (CmtType == tdctC) || (CmtType == tdctDoxygenC) ) buffer << _T(" */"); // add newline char(s), only if dlg.GetPosition() != tdpCurrent if (dlg.GetPosition() != tdpCurrent) { switch (control->GetEOLMode()) { // NOTE: maybe this switch, should make it in the SDK (maybe as cbStyledTextCtrl::GetEOLString())??? case wxSCI_EOL_CR: buffer << _T("\n"); break; case wxSCI_EOL_CRLF: buffer << _T("\r\n"); break; case wxSCI_EOL_LF: buffer << _T("\r"); break; } } // ok, insert the todo line text control->InsertText(idx, buffer); if (dlg.GetPosition() == tdpAbove) origPos += buffer.Length() + crlfLen; control->GotoPos(origPos); control->EnsureCaretVisible(); ParseCurrent(true); } // end of OnAddItem