Code::Blocks  SVN r11506
cbplugin.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 11399 $
6  * $Id: cbplugin.cpp 11399 2018-05-08 21:54:03Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/cbplugin.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/frame.h> // wxFrame
14  #include <wx/menu.h>
15  #include <wx/process.h>
16 
17  #include "cbeditor.h"
18  #include "cbplugin.h"
19  #include "cbproject.h"
20  #include "compiler.h" // GetSwitches
21  #include "configmanager.h"
22  #include "debuggermanager.h"
23  #include "editorcolourset.h"
24  #include "editormanager.h"
25  #include "infowindow.h"
26  #include "logmanager.h"
27  #include "macrosmanager.h"
28  #include "manager.h"
29  #include "projectbuildtarget.h"
30  #include "projectmanager.h"
31  #include "sdk_events.h"
32 #endif
33 
34 #include <wx/toolbar.h>
35 
36 #include "annoyingdialog.h"
37 #include "cbdebugger_interfaces.h"
38 #include "cbstyledtextctrl.h"
39 #include "ccmanager.h"
40 #include "debuggermanager.h"
41 #include "editor_hooks.h"
42 #include "loggers.h"
43 
44 #ifndef __WXMSW__
45  #include <errno.h>
46  // needed for the kill system call
47  #include <signal.h>
48  #include <sys/types.h>
49 #endif
50 
52  m_Type(ptNone),
53  m_IsAttached(false)
54 {
55  SetEvtHandlerEnabled(false);
56 }
57 
59 {
60 }
61 
63 {
64  if (m_IsAttached)
65  return;
66  wxWindow* window = Manager::Get()->GetAppWindow();
67  if (window)
68  {
69  // push ourself in the application's event handling chain...
70  window->PushEventHandler(this);
71  }
72  m_IsAttached = true;
73  OnAttach();
74  SetEvtHandlerEnabled(true);
75 
77  event.SetPlugin(this);
78  // post event in the host's event queue
79  Manager::Get()->ProcessEvent(event);
80 }
81 
82 void cbPlugin::Release(bool appShutDown)
83 {
84  if (!m_IsAttached)
85  return;
86  m_IsAttached = false;
87  SetEvtHandlerEnabled(false);
88  OnRelease(appShutDown);
89 
91  event.SetPlugin(this);
92  // ask the host to process this event immediately
93  // it must be done this way, because if the host references
94  // us (through event.GetEventObject()), we might not be valid at that time
95  // (while, now, we are...)
96  Manager::Get()->ProcessEvent(event);
97 
98  if (appShutDown)
99  return; // nothing more to do, if the app is shutting down
100 
101  wxWindow* window = Manager::Get()->GetAppWindow();
102  if (window)
103  {
104  // remove ourself from the application's event handling chain...
105  window->RemoveEventHandler(this);
106  }
107 }
108 
109 void cbPlugin::NotImplemented(const wxString& log) const
110 {
111  Manager::Get()->GetLogManager()->DebugLog(log + _T(" : not implemented"));
112 }
113 
117 
119 {
120  m_Type = ptCompiler;
121 }
122 
126 
127 cbDebuggerPlugin::cbDebuggerPlugin(const wxString &guiName, const wxString &settingsName) :
128  m_pCompiler(nullptr),
129  m_WaitingCompilerToFinish(false),
130  m_StartType(StartTypeUnknown),
131  m_ActiveConfig(0),
132  m_LogPageIndex(-1),
133  m_lastLineWasNormal(true),
134  m_guiName(guiName),
135  m_settingsName(settingsName)
136 {
137  m_Type = ptDebugger;
138 }
139 
140 
142 {
144 
145  OnAttachReal();
146 
148 
152 
154 
156 
159 }
160 
161 void cbDebuggerPlugin::OnRelease(bool appShutDown)
162 {
164 
165  OnReleaseReal(appShutDown);
166 
168 }
169 
170 void cbDebuggerPlugin::BuildMenu(cb_unused wxMenuBar* menuBar)
171 {
172  if (!IsAttached())
173  return;
175 }
176 
178 {
180  if (!ed)
181  return wxEmptyString;
182  cbStyledTextCtrl* stc = ed->GetControl();
183  if (!stc)
184  return wxEmptyString;
185 
186  wxString selected_text = stc->GetSelectedText();
187  if (selected_text != wxEmptyString)
188  {
189  selected_text.Trim(true);
190  selected_text.Trim(false);
191 
192  wxString::size_type pos = selected_text.find(wxT('\n'));
193  if (pos != wxString::npos)
194  {
195  selected_text.Remove(pos, selected_text.length() - pos);
196  selected_text.Trim(true);
197  selected_text.Trim(false);
198  }
199  // check if the mouse is over the selected text
200  if (mousePosition)
201  {
202  int startPos = stc->GetSelectionStart();
203  int endPos = stc->GetSelectionEnd();
204  int mousePos = stc->PositionFromPointClose(mousePosition->x, mousePosition->y);
205  if (mousePos == wxSCI_INVALID_POSITION)
206  return wxEmptyString;
207  else if (startPos <= mousePos && mousePos <= endPos)
208  return selected_text;
209  else
210  return wxEmptyString;
211  }
212  else
213  return selected_text;
214  }
215 
216  if (mousePosition)
217  {
218  int pos = stc->PositionFromPoint(*mousePosition);
219  int start = stc->WordStartPosition(pos, true);
220  int end = stc->WordEndPosition(pos, true);
221  selected_text = stc->GetTextRange(start, end);
222  }
223  else
224  {
225  int start = stc->WordStartPosition(stc->GetCurrentPos(), true);
226  int end = stc->WordEndPosition(stc->GetCurrentPos(), true);
227  selected_text = stc->GetTextRange(start, end);
228  }
229  return selected_text;
230 }
231 
232 void cbDebuggerPlugin::BuildModuleMenu(const ModuleType type, wxMenu* menu, cb_unused const FileTreeData* data)
233 {
234  if (!IsAttached())
235  return;
236  // we 're only interested in editor menus
237  // we 'll add a "debug watches" entry only when the debugger is running...
238  if (type != mtEditorManager || !menu)
239  return;
241  if (active_plugin != this)
242  return;
243 
244  wxString word;
245  if (IsRunning())
246  {
247  // has to have a word under the caret...
248  word = GetEditorWordAtCaret();
249  }
251 }
252 
254 {
255  return false;
256 }
257 
259 {
261 
262  bool en = (prj && !prj->GetCurrentlyCompilingTarget()) || IsAttachedToProcess();
263  return IsRunning() && en;
264 }
265 
267 {
269 
270  DebuggerManager::RegisteredPlugins::iterator it = allPlugins.find(this);
271  if (it == allPlugins.end())
272  cbAssert(false);
273  cbDebuggerConfiguration *config = it->second.GetConfiguration(m_ActiveConfig);
274  if (!config)
275  return *it->second.GetConfigurations().front();
276  else
277  return *config;
278 }
279 
281 {
282  m_ActiveConfig = index;
283 }
284 
286 {
287  return m_ActiveConfig;
288 }
289 
291 {
293  for (int i = 0; i < edMan->GetEditorsCount(); ++i)
294  {
295  cbEditor* ed = edMan->GetBuiltinEditor(i);
296  if (ed)
297  ed->SetDebugLine(-1);
298  }
299 }
300 
302 {
303  if (setMarker)
304  {
306  for (int i = 0; i < edMan->GetEditorsCount(); ++i)
307  {
308  cbEditor* ed = edMan->GetBuiltinEditor(i);
309  if (ed)
310  ed->SetDebugLine(-1);
311  }
312  }
313  FileType ft = FileTypeOf(filename);
314  if (ft != ftSource && ft != ftHeader && ft != ftResource && ft != ftTemplateSource)
315  {
316  // if the line is >= 0 and ft == ftOther assume, that we are in header without extension
317  if (line < 0 || ft != ftOther)
318  {
319  ShowLog(false);
320  Log(_("Unknown file: ") + filename, Logger::error);
321  InfoWindow::Display(_("Unknown file"), _("File: ") + filename, 5000);
322 
323  return SyncFileUnknown; // don't try to open unknown files
324  }
325  }
326 
328  ProjectFile* f = project ? project->GetFileByFilename(filename, false, true) : nullptr;
329 
330  wxString unixfilename = UnixFilename(filename);
331  wxFileName fname(unixfilename);
332 
333  if (project && fname.IsRelative())
334  fname.MakeAbsolute(project->GetBasePath());
335 
336  // gdb can't work with spaces in filenames, so we have passed it the shorthand form (C:\MYDOCU~1 etc)
337  // revert this change now so the file can be located and opened...
338  // we do this by calling GetLongPath()
340  if (ed)
341  {
342  ed->Show(true);
343  if (f && !ed->GetProjectFile())
344  ed->SetProjectFile(f);
345  ed->GotoLine(line - 1, false);
346  if (setMarker)
347  ed->SetDebugLine(line - 1);
348  return SyncOk;
349  }
350  else
351  {
352  ShowLog(false);
353  Log(_("Cannot open file: ") + filename, Logger::error);
354  InfoWindow::Display(_("Cannot open file"), _("File: ") + filename, 5000);
355 
356  return SyncFileNotFound;
357  }
358 }
359 
360 inline bool HasBreakpoint(cbDebuggerPlugin &plugin, wxString const &filename, int line)
361 {
362  int count = plugin.GetBreakpointsCount();
363  for (int ii = 0; ii < count; ++ii)
364  {
365  const cb::shared_ptr<cbBreakpoint> &b = plugin.GetBreakpoint(ii);
366 
367  if (b->GetLocation() == filename && b->GetLine() == line)
368  return true;
369  }
370  return false;
371 }
372 
373 void cbDebuggerPlugin::EditorLinesAddedOrRemoved(cbEditor* editor, int startline, int lines)
374 {
375  // here we keep the breakpoints in sync with the editors
376  // (whenever lines are added or removed)
377  if (!editor || lines == 0)
378  return;
379 
380  const wxString& filename = editor->GetFilename();
381 
382  std::vector<int> breakpoints_for_file;
383  int count = GetBreakpointsCount();
384  for (int ii = 0; ii < count; ++ii)
385  {
386  const cb::shared_ptr<cbBreakpoint> &b = GetBreakpoint(ii);
387 
388  if (b->GetLocation() == filename)
389  {
390  breakpoints_for_file.push_back(ii);
391  }
392  }
393 
394  if (lines < 0)
395  {
396  // removed lines
397  // make "lines" positive, for easier reading below
398  lines = -lines;
399  int endline = startline + lines - 1;
400 
401  std::vector<cb::shared_ptr<cbBreakpoint> > to_remove;
402 
403  for (std::vector<int>::iterator it = breakpoints_for_file.begin(); it != breakpoints_for_file.end(); ++it)
404  {
405  const cb::shared_ptr<cbBreakpoint> &b = GetBreakpoint(*it);
406  if (b->GetLine() > endline)
407  ShiftBreakpoint(*it, -lines);
408  else if (b->GetLine() >= startline && b->GetLine() <= endline)
409  to_remove.push_back(b);
410  }
411 
412  for (std::vector<cb::shared_ptr<cbBreakpoint> >::iterator it = to_remove.begin(); it != to_remove.end(); ++it)
413  DeleteBreakpoint(*it);
414  }
415  else
416  {
417  for (std::vector<int>::iterator it = breakpoints_for_file.begin(); it != breakpoints_for_file.end(); ++it)
418  {
419  const cb::shared_ptr<cbBreakpoint> &b = GetBreakpoint(*it);
420  if (b->GetLine() > startline)
421  ShiftBreakpoint(*it, lines);
422  }
423  }
424 }
425 
427 {
428  // when an editor opens, look if we have breakpoints for it
429  // and notify it...
430  EditorBase* ed = event.GetEditor();
431  if (ed && ed->IsBuiltinEditor())
432  {
433  cbEditor *editor = static_cast<cbEditor*>(ed);
434  editor->RefreshBreakpointMarkers();
435 
436  if (IsRunning())
437  {
438  wxString filename;
439  int line;
440  GetCurrentPosition(filename, line);
441 
442  wxFileName edFileName(ed->GetFilename());
443  edFileName.Normalize();
444 
445  wxFileName dbgFileName(filename);
446  dbgFileName.Normalize();
447  if (dbgFileName.GetFullPath().IsSameAs(edFileName.GetFullPath()) && line != -1)
448  {
449  editor->SetDebugLine(line - 1);
450  }
451  }
452  }
453  event.Skip(); // must do
454 }
455 
457 {
458  // allow others to catch this
459  event.Skip();
460 
461  if(this != Manager::Get()->GetDebuggerManager()->GetActiveDebugger())
462  return;
463  // when a project is activated and it's not the actively debugged project,
464  // ask the user to end debugging or re-activate the debugged project.
465 
466  if (!IsRunning())
467  return;
468 
469  if (event.GetProject() != GetProject() && GetProject())
470  {
471  wxString msg = _("You can't change the active project while you 're actively debugging another.\n"
472  "Do you want to stop debugging?\n\n"
473  "Click \"Yes\" to stop debugging now or click \"No\" to re-activate the debuggee.");
474  if (cbMessageBox(msg, _("Warning"), wxICON_WARNING | wxYES_NO) == wxID_YES)
475  {
476  Stop();
477  }
478  else
479  {
481  }
482  }
483 }
484 
486 {
487  // allow others to catch this
488  event.Skip();
489 
490  if(this != Manager::Get()->GetDebuggerManager()->GetActiveDebugger())
491  return;
493 
494  // when a project closes, make sure it's not the actively debugged project.
495  // if so, end debugging immediately!
496  if (!IsRunning())
497  return;
498 
499  if (event.GetProject() == GetProject())
500  {
501  AnnoyingDialog dlg(_("Project closed while debugging message"),
502  _("The project you were debugging has closed.\n"
503  "(The application most likely just finished.)\n"
504  "The debugging session will terminate immediately."),
506  dlg.ShowModal();
507  Stop();
508  ResetProject();
509  }
510 }
511 
512 
513 
515 {
517  if (log)
518  {
519  // switch to the debugger log
520  CodeBlocksLogEvent eventSwitchLog(cbEVT_SWITCH_TO_LOG_WINDOW, log);
521  Manager::Get()->ProcessEvent(eventSwitchLog);
523  Manager::Get()->ProcessEvent(eventShowLog);
524 
525  if (clear)
526  log->Clear();
527  }
528 }
529 
531 {
532  if (IsAttached())
533  {
535  level);
536  m_lastLineWasNormal = true;
537  }
538 }
539 
541 {
542  // gdb debug messages
543  if (IsAttached() && HasDebugLog())
544  {
545  Manager::Get()->GetLogManager()->Log((!m_lastLineWasNormal ? wxT("[debug]") : wxT("\n[debug]")) + msg,
546  m_LogPageIndex, level);
547  m_lastLineWasNormal = false;
548  }
549 }
550 
552 {
554 }
555 
557 {
559 }
560 
561 void cbDebuggerPlugin::SetupLog(int normalIndex)
562 {
563  m_LogPageIndex = normalIndex;
564 }
565 
567 {
569 
570  const cbDebuggerConfiguration &config = GetActiveConfig();
571 
572  wxString perspectiveName;
574  {
576  perspectiveName = GetGUIName();
577  break;
579  perspectiveName = GetGUIName() + wxT(":") + config.GetName();
580  break;
582  default:
583  perspectiveName = _("Debugging");
584  }
585 
586  CodeBlocksLayoutEvent switchEvent(cbEVT_SWITCH_VIEW_LAYOUT, perspectiveName);
587 
588  Manager::Get()->GetLogManager()->DebugLog(F(_("Switching layout to \"%s\""), switchEvent.layout.wx_str()));
589 
590  // query the current layout
591  Manager::Get()->ProcessEvent(queryEvent);
592  m_PreviousLayout = queryEvent.layout;
593 
594  // switch to debugging layout
595  Manager::Get()->ProcessEvent(switchEvent);
596 
597  ShowLog(false);
598 }
599 
601 {
603 
604  wxString const &name = !switchEvent.layout.IsEmpty() ? switchEvent.layout : wxString(_("Code::Blocks default"));
605 
606  Manager::Get()->GetLogManager()->DebugLog(F(_("Switching layout to \"%s\""), name.wx_str()));
607 
608  // switch to previous layout
609  Manager::Get()->ProcessEvent(switchEvent);
610 }
611 
612 bool cbDebuggerPlugin::GetDebuggee(wxString &pathToDebuggee, wxString &workingDirectory, ProjectBuildTarget* target)
613 {
614  if (!target)
615  return false;
616 
617  wxString out;
618  switch (target->GetTargetType())
619  {
620  case ttExecutable:
621  case ttConsoleOnly:
622  case ttNative:
623  {
624  out = UnixFilename(target->GetOutputFilename());
625  Manager::Get()->GetMacrosManager()->ReplaceEnvVars(out); // apply env vars
626  wxFileName f(out);
627  f.MakeAbsolute(target->GetParentProject()->GetBasePath());
628  out = f.GetFullPath();
629  Log(_("Adding file: ") + out);
630  ConvertDirectory(out);
631  }
632  break;
633 
634  case ttStaticLib:
635  case ttDynamicLib:
636  // check for hostapp
637  if (target->GetHostApplication().IsEmpty())
638  {
639  cbMessageBox(_("You must select a host application to \"run\" a library..."));
640  return false;
641  }
642  out = UnixFilename(target->GetHostApplication());
643  Manager::Get()->GetMacrosManager()->ReplaceEnvVars(out); // apply env vars
644  Log(_("Adding file: ") + out);
645  ConvertDirectory(out);
646  break;
647 
648  case ttCommandsOnly: // fall through:
649  default:
650  Log(_("Unsupported target type (Project -> Properties -> Build Targets -> Type)"), Logger::error);
651  return false;
652  }
653  if (out.empty())
654  {
655  Log(_("Couldn't find the path to the debuggee!"), Logger::error);
656  return false;
657  }
658 
659  workingDirectory = target->GetWorkingDir();
660  Manager::Get()->GetMacrosManager()->ReplaceEnvVars(workingDirectory);
661  wxFileName cd(workingDirectory);
662  if (cd.IsRelative())
663  cd.MakeAbsolute(target->GetParentProject()->GetBasePath());
664  workingDirectory = cd.GetFullPath();
665 
666  pathToDebuggee = out;
667  return true;
668 }
669 
671 {
672  m_StartType = startType;
674 
675  // compile project/target (if not attaching to a PID)
676  if (!IsAttachedToProcess())
677  {
678  // should we build to make sure project is up-to-date?
680  {
682  m_pCompiler = nullptr;
683  return true;
684  }
685 
686  // make sure the target is compiled
687  const std::vector<cbCompilerPlugin*> &compilers = Manager::Get()->GetPluginManager()->GetCompilerPlugins();
688  if (compilers.empty())
689  m_pCompiler = nullptr;
690  else
691  m_pCompiler = compilers.front();
692  if (m_pCompiler)
693  {
694  // is the compiler already running?
695  if (m_pCompiler->IsRunning())
696  {
697  Log(_("Compiler in use..."));
698  Log(_("Aborting debugging session"));
699  cbMessageBox(_("The compiler is currently in use. Aborting debugging session..."),
700  _("Compiler running"), wxICON_WARNING);
701  return false;
702  }
703 
704  Log(_("Building to ensure sources are up-to-date"));
706  m_pCompiler->Build();
707  // now, when the build is finished, DoDebug will be launched in OnCompilerFinished()
708  }
709  }
710  return true;
711 }
712 
714 {
716  {
718  bool compilerFailed = false;
719  // only proceed if build succeeded
720  if (m_pCompiler && m_pCompiler->GetExitCode() != 0)
721  {
722  AnnoyingDialog dlg(_("Debug anyway?"), _("Build failed, do you want to debug the program?"),
724  if (dlg.ShowModal() != AnnoyingDialog::rtYES)
725  {
727  if (manager->GetIsRunning() && manager->GetIsRunning() == this)
728  manager->SetIsRunning(nullptr);
729  compilerFailed = true;
730  }
731  }
732  ShowLog(false);
733  if (!CompilerFinished(compilerFailed, m_StartType))
734  {
736  if (manager->GetIsRunning() && manager->GetIsRunning() == this)
737  manager->SetIsRunning(nullptr);
738  }
739  }
740 }
741 
742 #ifndef __WXMSW__
743 namespace
744 {
745 wxString MakeSleepCommand()
746 {
747  return wxString::Format(wxT("sleep %lu"), 80000000 + ::wxGetProcessId());
748 }
749 
750 struct ConsoleInfo
751 {
752  ConsoleInfo(const wxString &path = wxEmptyString, int pid = -1) : ttyPath(path), sleepPID(pid) {}
753 
754  bool IsValid() const { return !ttyPath.empty() && sleepPID > 0; }
755 
756  wxString ttyPath;
757  int sleepPID;
758 };
759 
760 ConsoleInfo GetConsoleTty(int consolePID)
761 {
762  // execute the ps x -o command and read PS output to get the /dev/tty field
763  wxArrayString psOutput;
764  wxArrayString psErrors;
765 
766  int result = wxExecute(wxT("ps x -o tty,pid,command"), psOutput, psErrors, wxEXEC_SYNC);
767  if (result != 0)
768  return ConsoleInfo();
769 
770  // find task with our unique sleep time
771  const wxString &uniqueSleepTimeStr = MakeSleepCommand();
772 
773  // search the output of "ps pid" command
774  int count = psOutput.GetCount();
775  for (int i = count - 1; i > -1; --i)
776  {
777  // find the pts/# or tty/# or whatever it's called
778  // by searching the output of "ps x -o tty,pid,command" command.
779  // The output of ps looks like:
780  // TT PID COMMAND
781  // pts/0 13342 /bin/sh ./run.sh
782  // pts/0 13343 /home/pecanpecan/devel/trunk/src/devel/codeblocks
783  // pts/0 13361 /usr/bin/gdb -nx -fullname -quiet -args ./conio
784  // pts/0 13362 xterm -font -*-*-*-*-*-*-20-*-*-*-*-*-*-* -T Program Console -e sleep 93343
785  // pts/2 13363 sleep 93343
786  // ? 13365 /home/pecan/proj/conio/conio
787  // pts/1 13370 ps x -o tty,pid,command
788 
789  const wxString &psCmd = psOutput.Item(i);
790  if (psCmd.Contains(uniqueSleepTimeStr))
791  {
792  // Extract the pid for the line
793  long pidForLine;
794  if (psCmd.AfterFirst(' ').Trim(false).BeforeFirst(' ').Trim(true).ToLong(&pidForLine))
795  {
796  // Check if we are at the correct line. It is possible that there are two lines which contain the
797  // "sleep" string. One for the sleep process and one for the terminal process. We want to skip the
798  // line for the terminal process.
799  if (pidForLine != consolePID)
800  return ConsoleInfo(wxT("/dev/") + psCmd.BeforeFirst(' '), pidForLine);
801  }
802  }
803  }
804  return ConsoleInfo();
805 }
806 
807 struct ConsoleProcessTerminationInfo
808 {
809  ConsoleProcessTerminationInfo() : status(-1), terminated(false) {}
810 
811  bool FailedToStart() const { return terminated && status != 0; }
812 
813  int status;
814  bool terminated;
815 };
816 
817 struct ConsoleProcess : wxProcess
818 {
819  ConsoleProcess(cb::shared_ptr<ConsoleProcessTerminationInfo> cptInfo) : info(cptInfo) {}
820  void OnTerminate(int pid, int status) override
821  {
822  info->terminated = true;
823  info->status = status;
824  }
825  cb::shared_ptr<ConsoleProcessTerminationInfo> info;
826 };
827 
828 } // namespace
829 #endif
830 
832 {
833  consoleTty = wxEmptyString;
834 #ifndef __WXMSW__
835  // Start a terminal and put the shell to sleep with -e sleep 80000.
836  // Fetch the terminal's tty, so we can tell the debugger what TTY to use,
837  // thus redirecting program's stdin/stdout/stderr to the terminal.
838 
839  wxString cmd;
840  int consolePid = 0;
841  // Use the terminal specified by the user in the Settings -> Environment.
842  wxString term = Manager::Get()->GetConfigManager(_T("app"))->Read(_T("/console_terminal"), DEFAULT_CONSOLE_TERM);
843 
844  term.Replace(_T("$TITLE"), wxString(wxT("'"))+_("Program Console")+wxT("'"));
845  cmd << term << _T(" ");
846 
847  const wxString &sleepCommand = MakeSleepCommand();
848  cmd << sleepCommand;
849 
851 
852  // The lifetime of wxProcess objects is very uncertain, so we are using a shared pointer to
853  // prevent us accessing deleted objects.
854  cb::shared_ptr<ConsoleProcessTerminationInfo> processInfo(new ConsoleProcessTerminationInfo);
855  ConsoleProcess *process = new ConsoleProcess(processInfo);
856  consolePid = wxExecute(cmd, wxEXEC_ASYNC, process);
857  if (consolePid <= 0)
858  return -1;
859 
860  // Try to find the TTY. We're using a loop, because some slow machines might make the check fail due
861  // to a slow starting terminal.
862  for (int ii = 0; ii < 100; ++ii)
863  {
864  // First, wait for the terminal to settle down, else PS won't see the sleep task
865  Manager::Yield();
866  ::wxMilliSleep(200);
867 
868  // Try to detect if the terminal command is present or its parameters are valid.
869  if (processInfo->FailedToStart() /*&& ii > 0*/)
870  {
871  Log(F(wxT("Failed to execute terminal command: '%s' (exit code: %d)"),
872  cmd.wx_str(), processInfo->status), Logger::error);
873  break;
874  }
875 
876  // Try to find tty path and pid for the sleep command we've just executed.
877  const ConsoleInfo &info = GetConsoleTty(consolePid);
878 
879  // If there is no sleep command yet, do another iteration after a small delay.
880  if (!info.IsValid())
881  continue;
882 
883  // Try to find if the console window is still alive. Newer terminals like gnome-terminal
884  // try to be easier on resources and use a shared server process. For these terminals the
885  // spawned terminal process exits immediately, but the sleep command is still executed.
886  // If we detect such case we will return the PID for the sleep command instead of the PID
887  // for the terminal.
888  if (kill(consolePid, 0) == -1 && errno == ESRCH) {
889  DebugLog(F(wxT("Using sleep command's PID as console PID %d, TTY %s"),
890  info.sleepPID, info.ttyPath.wx_str()));
891  consoleTty = info.ttyPath;
892  return info.sleepPID;
893  }
894  else
895  {
896  DebugLog(F(wxT("Using terminal's PID as console PID %d, TTY %s"), info.sleepPID, info.ttyPath.wx_str()));
897  consoleTty = info.ttyPath;
898  return consolePid;
899  }
900  }
901  // failed to find the console tty
902  if (consolePid != 0)
903  ::wxKill(consolePid);
904 #endif // !__WWXMSW__
905  return -1;
906 }
907 
909 {
911 }
912 
914 {
915  wxWindow* app = Manager::Get()->GetAppWindow();
916  if (app)
917  app->Raise();
918 }
919 
921 {
925  new Event(this, &cbDebuggerPlugin::CancelValueTooltip));
926 }
927 
928 bool cbDebuggerPlugin::ShowValueTooltip(cb_unused int style)
929 {
930  return false;
931 }
932 
933 // Default implementation does nothing
934 void cbDebuggerPlugin::OnValueTooltip(cb_unused const wxString& token, cb_unused const wxRect& evalRect)
935 {
936 }
937 
939 {
940  event.Skip();
942  {
944  return;
945  }
946 
947  if (Manager::Get()->GetDebuggerManager()->GetInterfaceFactory()->IsValueTooltipShown())
948  return;
949 
950  if (!ShowValueTooltip(event.GetInt()))
951  return;
952 
953  EditorBase* base = event.GetEditor();
954  cbEditor* ed = base && base->IsBuiltinEditor() ? static_cast<cbEditor*>(base) : nullptr;
955  if (!ed)
956  return;
957 
958  if (ed->IsContextMenuOpened())
959  return;
960 
961  // get rid of other calltips (if any) [for example the code completion one, at this time we
962  // want the debugger value call/tool-tip to win and be shown]
963  if (ed->GetControl()->CallTipActive())
964  ed->GetControl()->CallTipCancel();
965 
966  wxPoint pt;
967  pt.x = event.GetX();
968  pt.y = event.GetY();
969 
970  const wxString &token = GetEditorWordAtCaret(&pt);
971  if (!token.empty())
972  {
973  pt = ed->GetControl()->ClientToScreen(pt);
974  OnValueTooltip(token, wxRect(pt.x - 5, pt.y, 10, 10));
975  }
976 }
977 
979 {
981 }
985 
987 {
988  m_Type = ptTool;
989 }
990 
994 
996 {
997  m_Type = ptMime;
998 }
999 
1003 
1005 {
1007 }
1008 
1009 void cbCodeCompletionPlugin::DoAutocomplete(cb_unused const CCToken& token, cb_unused cbEditor* ed)
1010 {
1011  // do nothing: allow (wx)Scintilla to handle the insert
1012 }
1013 
1015 {
1016  DoAutocomplete(CCToken(-1, token), ed);
1017 }
1018 
1020 {
1021  return (Manager::Get()->GetCCManager()->GetProviderFor(ed) == this);
1022 }
1023 
1027 
1029 {
1030  m_Type = ptWizard;
1031 }
1032 
1036 
1038 {
1040 }
1041 
1043 {
1046 }
1047 
1048 void cbSmartIndentPlugin::OnRelease(cb_unused bool appShutDown)
1049 {
1050  EditorHooks::UnregisterHook(m_FunctorId);
1051 }
1052 
1054 {
1055  return Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/auto_indent"), true);
1056 }
1057 
1059 {
1060  return Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/smart_indent"), true);
1061 }
1062 
1064 {
1065  return Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/brace_smart_indent"), true);
1066 }
1067 
1069 {
1070  return Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/brace_completion"), true);
1071 }
1072 
1074 {
1075  return Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/selection_brace_completion"), false);
1076 }
1077 
1079 {
1080  if (stc->GetUseTabs())
1081  indent << _T('\t'); // 1 tab
1082  else
1083  indent << wxString(_T(' '), stc->GetTabWidth()); // n spaces
1084 }
1085 
1086 bool cbSmartIndentPlugin::Indent(cbStyledTextCtrl* stc, wxString &indent, int posInLine)const
1087 {
1088  if (posInLine >= 0)
1089  {
1090  if (stc->GetUseTabs())
1091  indent = wxString(_T('\t'), posInLine/stc->GetTabWidth());
1092  else
1093  indent = wxString(_T(' '), posInLine); // n spaces
1094  return true;
1095  }
1096  return false;
1097 }
1098 
1099 wxString cbSmartIndentPlugin::GetLastNonCommentWord(cbEditor* ed, int position, unsigned int NumberOfWords)const
1100 {
1101  cbStyledTextCtrl* stc = ed->GetControl();
1102  if ( !stc )
1103  return wxEmptyString;
1104 
1105  if ( position == -1 )
1106  position = stc->GetCurrentPos();
1107 
1108 
1109  wxString str;
1110  str.Empty();
1111  int count = 0;
1112  bool foundlf = false; // For the rare case of CR's without LF's
1113  while (position)
1114  {
1115  wxChar c = stc->GetCharAt(--position);
1116  int style = stc->GetStyleAt(position);
1117  bool inComment = stc->IsComment(style);
1118  if (c == _T('\n'))
1119  {
1120  count++;
1121  foundlf = true;
1122  }
1123  else if (c == _T('\r') && !foundlf)
1124  count++;
1125  else
1126  foundlf = false;
1127 
1128  if (count > 1) return str;
1129  if (!inComment && c != _T(' ') && c != _T('\t') && c != _T('\n') && c != _T('\r') )
1130  {
1131  int startpos = stc->WordStartPosition( position, true );
1132  for ( unsigned int i = 1; i < NumberOfWords ; ++i )
1133  startpos = stc->WordStartPosition( startpos - 1, true );
1134  int endpos = stc->WordEndPosition(startpos, true);
1135  str = stc->GetTextRange(startpos, endpos);
1136  return str;
1137  }
1138  }
1139  return str;
1140 }
1141 
1143 {
1144  return GetLastNonWhitespaceChars(ed, position, 1)[0];
1145 }
1146 
1147 wxString cbSmartIndentPlugin::GetLastNonWhitespaceChars(cbEditor* ed, int position, unsigned int NumberOfChars)const
1148 {
1149  cbStyledTextCtrl* stc = ed->GetControl();
1150  if ( !stc )
1151  return wxEmptyString;
1152 
1153  if (position == -1)
1154  position = stc->GetCurrentPos();
1155 
1156  int count = 0; // Used to count the number of blank lines
1157  bool foundlf = false; // For the rare case of CR's without LF's
1158  while (position)
1159  {
1160  wxChar c = stc->GetCharAt(--position);
1161  int style = stc->GetStyleAt(position);
1162  bool inComment = stc->IsComment(style);
1163  if (c == _T('\n'))
1164  {
1165  count++;
1166  foundlf = true;
1167  }
1168  else if (c == _T('\r') && !foundlf)
1169  count++;
1170  else
1171  foundlf = false;
1172  if (count > 1) return wxEmptyString;
1173  if (!inComment && c != _T(' ') && c != _T('\t') && c != _T('\n') && c != _T('\r'))
1174  return stc->GetTextRange(position-NumberOfChars+1, position+1);
1175  }
1176  return wxEmptyString;
1177 }
1178 
1180 {
1181  if (position == -1)
1182  position = stc->GetCurrentPos();
1183 
1184  while (position < stc->GetLength())
1185  {
1186  wxChar c = stc->GetCharAt(position);
1187  if ( c == _T('\n') || c == _T('\r') )
1188  {
1189  if ( pos ) *pos = position;
1190  return 0;
1191  }
1192  if ( c != _T(' ') && c != _T('\t') )
1193  {
1194  if ( pos ) *pos = position;
1195  return c;
1196  }
1197  position++;
1198  }
1199 
1200  return 0;
1201 }
1202 
1203 int cbSmartIndentPlugin::FindBlockStart(cbStyledTextCtrl* stc, int position, wxChar blockStart, wxChar blockEnd, cb_unused bool skipNested)const
1204 {
1205  int lvl = 0;
1206  wxChar b = stc->GetCharAt(position);
1207  while (b)
1208  {
1209  if (b == blockEnd)
1210  ++lvl;
1211  else if (b == blockStart)
1212  {
1213  if (lvl == 0)
1214  return position;
1215  --lvl;
1216  }
1217  --position;
1218  b = stc->GetCharAt(position);
1219  }
1220  return -1;
1221 }
1222 
1223 int cbSmartIndentPlugin::FindBlockStart(cbStyledTextCtrl* stc, int position, wxString blockStart, wxString blockEnd, bool CaseSensitive)const
1224 {
1225  int pos = position;
1226  int pb, pe;
1227  int lvl = 0;
1228 
1229  int flags = wxSCI_FIND_WHOLEWORD;
1230  if ( CaseSensitive )
1231  flags |= wxSCI_FIND_MATCHCASE;
1232 
1233  do
1234  {
1235  pb = stc->FindText(pos, 0, blockStart, flags);
1236  pe = stc->FindText(pos, 0, blockEnd, flags);
1237  if ( pe > pb )
1238  {
1239  pos = pe;
1240  ++lvl;
1241  continue;
1242  }
1243  pos = pb;
1244  if ( lvl == 0 ) return pb;
1245  --lvl;
1246  }
1247  while( pos != -1 );
1248 
1249  return -1;
1250 }
1251 
1252 //ToDo: Is this c++ only?
1254 {
1255  int curr_position = stc->GetCurrentPos();
1256  int position = curr_position;
1257  int min_brace_position = position;
1258  int closing_braces = 0;
1259  bool found_brace = false;
1260  bool has_braces = false;
1261 
1262  while (position)
1263  {
1264  wxChar c = stc->GetCharAt(--position);
1265 
1266  int style = stc->GetStyleAt(position);
1267  if (style == string_style)
1268  continue;
1269 
1270  if (c == _T(';'))
1271  {
1272  found_brace = false;
1273  break;
1274  }
1275  else if (c == _T(')'))
1276  {
1277  ++closing_braces;
1278  has_braces = true;
1279  }
1280  else if (c == _T('('))
1281  {
1282  has_braces = true;
1283  if (closing_braces > 0)
1284  --closing_braces;
1285  else if (!found_brace)
1286  {
1287  min_brace_position = position + 1;
1288  found_brace = true;
1289  break;
1290  }
1291  }
1292  else if (c == _T('\n') && position + 1 != curr_position && !has_braces)
1293  {
1294  break;
1295  }
1296  }
1297 
1298  if (!found_brace)
1299  return -1;
1300 
1301  int tab_characters = 0;
1302 
1303  while (position)
1304  {
1305  wxChar c = stc->GetCharAt(--position);
1306  if (c == _T('\n') && position + 1 != curr_position)
1307  {
1308  break;
1309  }
1310  else if (c == _T('\t'))
1311  ++tab_characters;
1312  }
1313 
1314  if (stc->GetUseTabs())
1315  {
1316  position -= tab_characters * stc->GetTabWidth();
1317  }
1318  return min_brace_position - position - 1;
1319 }
1320 
1322 {
1323  if (position == -1)
1324  position = stc->GetCurrentPos();
1325 
1326  while (position < stc->GetLength())
1327  {
1328  wxChar c = stc->GetCharAt(position);
1329  if ( c == _T('\n') || c == _T('\r') )
1330  {
1331  if ( pos ) *pos = position;
1332  return 0;
1333  }
1334  if ( c != _T(' ') && c != _T('\t') )
1335  {
1336  if ( pos ) *pos = position;
1337  return c;
1338  }
1339  position++;
1340  }
1341 
1342  return 0;
1343 }
1344 
1346 {
1347  EditorBase* eb = event.GetEditor();
1348  if (eb && eb->IsBuiltinEditor())
1349  {
1350  cbEditor* ed = static_cast<cbEditor *>(eb);
1351  OnCCDone(ed);
1352  }
1353 }
void Attach()
Attach is not a virtual function, so you can&#39;t override it.
Definition: cbplugin.cpp:62
ProjectFile * GetFileByFilename(const wxString &filename, bool isRelative=true, bool isUnixFilename=false)
Access a file of the project.
Definition: cbproject.cpp:1049
int wxKill(long pid, wxSignal sig=wxSIGTERM, wxKillError *rc=NULL, int flags=wxKILL_NOCHILDREN)
bool BraceSmartIndentEnabled() const
Definition: cbplugin.cpp:1063
wxString F(const wxChar *msg,...)
sprintf-like function
Definition: logmanager.h:20
bool GetUseTabs() const
Retrieve whether tabs will be used in indentation.
EVTIMPORT const wxEventType cbEVT_EDITOR_TOOLTIP
Definition: sdk_events.cpp:88
static void Display(const wxString &title, const wxString &message, unsigned int delay=5000, unsigned int hysteresis=1)
Definition: infowindow.cpp:294
void SetActiveConfig(int index)
Definition: cbplugin.cpp:280
bool CallTipActive()
Is there an active call tip?
virtual void GetCurrentPosition(wxString &filename, int &line)=0
void OnRelease(bool appShutDown) override
Definition: cbplugin.cpp:1048
cbDebuggerPlugin * GetActiveDebugger()
Definition: globals.h:27
int WordEndPosition(int pos, bool onlyWordCharacters)
Get position of end of word.
TextCtrlLogger * GetLogger(int &index)
EVTIMPORT const wxEventType cbEVT_EDITOR_CC_DONE
Definition: sdk_events.cpp:93
PluginManager * GetPluginManager() const
Definition: manager.cpp:444
virtual int GetExitCode() const =0
Get the exit code of the last build process.
void SetupLog(int normalIndex)
Definition: cbplugin.cpp:561
static bool GetFlag(Flags flag)
#define wxICON_WARNING
void SetIsRunning(cbPlugin *plugin)
This method should be called when the applications is started by a plugin.
void OnProjectActivated(CodeBlocksEvent &event)
Definition: cbplugin.cpp:456
static Perspective GetPerspective()
wxChar GetNextNonWhitespaceCharOnLine(cbStyledTextCtrl *stc, int position=-1, int *pos=nullptr) const
Definition: cbplugin.cpp:1179
EVTIMPORT const wxEventType cbEVT_SWITCH_VIEW_LAYOUT
Definition: sdk_events.cpp:138
ConfigManager * GetConfigManager(const wxString &name_space) const
Definition: manager.cpp:474
Base class for debugger plugins.
Definition: cbplugin.h:397
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
bool IsComment(int style)
Is style classified as comment for current language?
wxString m_PreviousLayout
Definition: cbplugin.h:638
void OnCompilerFinished(CodeBlocksEvent &event)
Definition: cbplugin.cpp:713
EVTIMPORT const wxEventType cbEVT_COMPILER_FINISHED
Definition: sdk_events.cpp:149
cbDebuggerConfiguration & GetActiveConfig()
Definition: cbplugin.cpp:266
bool AutoIndentEnabled() const
Definition: cbplugin.cpp:1053
DLLIMPORT const wxString DEFAULT_CONSOLE_TERM
Definition: globals.cpp:59
virtual const wxString & GetHostApplication() const
Read the target&#39;s host application.
size_t length() const
wxString layout
Layout&#39;s name.
Definition: sdk_events.h:170
void OnProjectClosed(CodeBlocksEvent &event)
Definition: cbplugin.cpp:485
EVTIMPORT const wxEventType cbEVT_PLUGIN_ATTACHED
Definition: sdk_events.cpp:74
void SwitchToPreviousLayout()
Definition: cbplugin.cpp:600
void MarkAsStopped()
Definition: cbplugin.cpp:908
bool UnregisterDebugger(cbDebuggerPlugin *plugin)
Called to unregister a debugger plugin.
unsigned long wxGetProcessId()
void GotoLine(int line, bool centerOnScreen=true) override
Move the caret at the specified line.
Definition: cbeditor.cpp:2223
int FindBlockStart(cbStyledTextCtrl *stc, int position, wxChar blockStart, wxChar blockEnd, bool skipNested=true) const
bool HasDebugLog() const
Definition: cbplugin.cpp:551
#define wxSCI_FIND_WHOLEWORD
Definition: wxscintilla.h:257
bool ReadBool(const wxString &name, bool defaultVal=false)
bool SmartIndentEnabled() const
Definition: cbplugin.cpp:1058
void BringCBToFront()
Definition: cbplugin.cpp:913
virtual int GetBreakpointsCount() const =0
bool EnsureBuildUpToDate(StartType startType)
Definition: cbplugin.cpp:670
EVTIMPORT const wxEventType cbEVT_PLUGIN_RELEASED
Definition: sdk_events.cpp:75
Target produces an executable.
const wxString & GetName() const
virtual void CleanupWhenProjectClosed(cbProject *project)=0
EVTIMPORT const wxEventType cbEVT_PROJECT_ACTIVATE
Definition: sdk_events.cpp:99
virtual void OnAttachReal()=0
Event used to request from the main app to add a log.
Definition: sdk_events.h:182
int RunNixConsole(wxString &consoleTty)
Definition: cbplugin.cpp:831
bool BuildToolBar(wxToolBar *toolBar) override
Definition: cbplugin.cpp:253
#define _T(string)
FileType
Known file types.
Definition: globals.h:49
cbProject * GetProject() const
Definition: sdk_events.h:41
bool m_lastLineWasNormal
Definition: cbplugin.h:647
int GetSelectionStart() const
Returns the position at the start of the selection.
#define wxYES_NO
void ProcessValueTooltip(CodeBlocksEvent &event)
Definition: cbplugin.cpp:938
DLLIMPORT FileType FileTypeOf(const wxString &filename)
Definition: globals.cpp:285
void Log(const wxString &msg, Logger::level level=Logger::info)
Definition: cbplugin.cpp:530
Definition: globals.h:26
SyncEditorResult SyncEditor(const wxString &filename, int line, bool setMarker=true)
Definition: cbplugin.cpp:301
EVTIMPORT const wxEventType cbEVT_EDITOR_TOOLTIP_CANCEL
Definition: sdk_events.cpp:89
PluginType m_Type
Holds the plugin&#39;s type.
Definition: cbplugin.h:229
wxString & Remove(size_t pos)
wxChar GetLastNonWhitespaceChar(cbEditor *ed, int position=-1) const
forward search to the next character which is not a whitespace
Definition: cbplugin.cpp:1142
void OnEditorOpened(CodeBlocksEvent &event)
Definition: cbplugin.cpp:426
wxString AfterFirst(wxUniChar ch) const
#define wxT(string)
Represents a file in a Code::Blocks project.
Definition: projectfile.h:39
ProjectBuildTarget * GetCurrentlyCompilingTarget()
Get a pointer to the currently compiling target.
Definition: cbproject.h:478
void RegisterValueTooltip()
Definition: cbplugin.cpp:920
bool empty() const
size_t find(const wxString &str, size_t nStart=0) const
A generic Code::Blocks event.
Definition: sdk_events.h:20
void ShowLog(bool clear)
Definition: cbplugin.cpp:514
virtual wxString GetOutputFilename()
Read the target&#39;s output filename.
virtual cbProject * GetParentProject()
void Release(bool appShutDown)
Release is not a virtual function, so you can&#39;t override it.
Definition: cbplugin.cpp:82
wxWindow * GetAppWindow() const
Definition: manager.cpp:424
int GetIndexOfActiveConfig() const
Definition: cbplugin.cpp:285
int WordStartPosition(int pos, bool onlyWordCharacters)
Get position of start of word.
EditorManager * GetEditorManager() const
Definition: manager.cpp:434
virtual TargetType GetTargetType() const
Read the target&#39;s type.
void Indent(cbStyledTextCtrl *stc, wxString &indent) const
Definition: cbplugin.cpp:1078
wxUSE_UNICODE_dependent wxChar
wxString GetSelectedText()
Retrieve the selected text.
bool SelectionBraceCompletionEnabled() const
Definition: cbplugin.cpp:1073
wxString BeforeFirst(wxUniChar ch, wxString *rest=NULL) const
ProjectManager * GetProjectManager() const
Functions returning pointers to the respective sub-manager instances.
Definition: manager.cpp:429
bool Contains(const wxString &str) const
DebuggerManager * GetDebuggerManager() const
Definition: manager.cpp:484
virtual const wxString & GetFilename() const
Get the editor&#39;s filename (if applicable).
Definition: editorbase.h:45
DLLIMPORT wxString UnixFilename(const wxString &filename, wxPathFormat format=wxPATH_NATIVE)
Definition: globals.cpp:228
Event functor class.
Definition: cbfunctor.h:37
Represents a Code::Blocks project.
Definition: cbproject.h:96
bool GetDebuggee(wxString &pathToDebuggee, wxString &workingDirectory, ProjectBuildTarget *target)
Definition: cbplugin.cpp:612
void SwitchToDebuggingLayout()
Definition: cbplugin.cpp:566
int PositionFromPointClose(int x, int y)
Find the position from a point within the window but return wxSCI_INVALID_POSITION if not close to te...
void CancelValueTooltip(CodeBlocksEvent &event)
Definition: cbplugin.cpp:978
#define wxSCI_FIND_MATCHCASE
Definition: wxscintilla.h:258
wxArtID wxART_QUESTION
null_pointer_t nullptr
Definition: nullptr.cpp:16
cbStyledTextCtrl * GetControl() const
Returns a pointer to the underlying cbStyledTextCtrl object (which itself is the wxWindows implementa...
Definition: cbeditor.cpp:842
cbPlugin * GetIsRunning() const
Return a pointer to the plugin which is running the application.
virtual void OnValueTooltip(const wxString &token, const wxRect &evalRect)
Definition: cbplugin.cpp:934
const CompilerPlugins & GetCompilerPlugins() const
ModuleType
The type of module offering a context menu.
Definition: globals.h:38
void Clear() override
Definition: loggers.cpp:162
void Empty()
void CallTipCancel()
Cancel calltip only if not jumping braces via tab.
virtual void RefreshBreakpointMarkers()
Refresh all markers for the breakpoints (only the markers for the current debugger will be shown) ...
Definition: cbeditor.cpp:2379
int GetTabWidth() const
Retrieve the visible size of a tab.
bool m_IsAttached
Holds the "attached" state.
Definition: cbplugin.h:232
Target produces a dynamic library.
size_t Replace(const wxString &strOld, const wxString &strNew, bool replaceAll=true)
virtual void OnRelease(cb_optional bool appShutDown)
Any descendent plugin should override this virtual method and perform any necessary de-initialization...
Definition: cbplugin.h:221
a logger which prints messages to a wxTextCtrl
Definition: loggers.h:90
cbEditor * GetBuiltinActiveEditor()
Definition: editormanager.h:95
void RemoveAllEventSinksFor(void *owner)
Definition: manager.cpp:570
bool IsSameAs(const wxString &s, bool caseSensitive=true) const
int FindText(int minPos, int maxPos, const wxString &text, int flags=0, int *findEnd=NULL)
Find some text in the document.
Target produces a native binary.
Base class that all "editors" should inherit from.
Definition: editorbase.h:30
LogManager * GetLogManager() const
Definition: manager.cpp:439
cbCompilerPlugin * m_pCompiler
Definition: cbplugin.h:639
int GetCurrentPos() const
Returns the position of the caret.
EVTIMPORT const wxEventType cbEVT_SWITCH_TO_LOG_WINDOW
Definition: sdk_events.cpp:165
wxString & Item(size_t nIndex)
Structure representing a generic token, passed between CC plugins and CCManager.
Definition: cbplugin.h:746
cbProject * GetActiveProject()
Retrieve the active project.
wxString Read(const wxString &key, const wxString &defaultVal=wxEmptyString)
virtual wxString GetBasePath() const
Read the target&#39;s base path, e.g. if GetFilename() returns "/usr/local/bin/xxx", base path will retur...
virtual bool IsContextMenuOpened() const
Is there a context (right click) menu open.
Definition: editorbase.cpp:441
void ClearActiveMarkFromAllEditors()
Definition: cbplugin.cpp:290
size_t size_type
virtual wxString GetWorkingDir()
Read the target&#39;s working dir for execution (valid only for executable targets)
wxString GetLongPath() const
const wxStringCharType * wx_str() const
wxString GetTextRange(int startPos, int endPos)
Retrieve a range of text.
virtual bool IsBuiltinEditor() const
Is this a built-in editor?
Definition: editorbase.cpp:209
virtual void OnAttach()
Any descendent plugin should override this virtual method and perform any necessary initialization...
Definition: cbplugin.h:210
wxString wxEmptyString
bool BraceCompletionEnabled() const
Definition: cbplugin.cpp:1068
virtual bool IsRunning() const =0
Is the plugin currently compiling?
virtual void HideValueTooltip()=0
void OnAttach() override
Any descendent plugin should override this virtual method and perform any necessary initialization...
Definition: cbplugin.cpp:141
virtual void Stop()=0
Stop the debugging process (exit debugging).
virtual cbProject * GetProject()=0
MacrosManager * GetMacrosManager() const
Definition: manager.cpp:454
cbEditor * Open(const wxString &filename, int pos=0, ProjectFile *data=nullptr)
const wxString & _(const wxString &string)
wxString & Trim(bool fromRight=true)
virtual void EditorLinesAddedOrRemoved(cbEditor *editor, int startline, int lines)
Notify the debugger that lines were added or removed in an editor.
Definition: cbplugin.cpp:373
int GetSelectionEnd() const
Returns the position at the end of the selection.
cbEditor * GetBuiltinEditor(EditorBase *eb)
std::map< cbDebuggerPlugin *, PluginData > RegisteredPlugins
#define cbAssert(expr)
Definition: cbexception.h:48
virtual void DeleteBreakpoint(cb::shared_ptr< cbBreakpoint > breakpoint)=0
static void Yield()
Whenever you need to call wxYield(), call Manager::Yield(). It&#39;s safer.
Definition: manager.cpp:221
int GetFirstBraceInLine(cbStyledTextCtrl *stc, int string_style) const
Get the first brace in the line according to the line style.
Definition: cbplugin.cpp:1253
int PositionFromPoint(wxPoint pt) const
Find the position from a point within the window.
wxArtID wxART_WARNING
Target produces a static library.
void BuildMenu(wxMenuBar *menuBar) override
Definition: cbplugin.cpp:170
bool ToLong(long *val, int base=10) const
void SetProjectFile(ProjectFile *project_file, bool preserve_modified=false)
Set the ProjectFile pointer associated with this editor.
Definition: cbeditor.cpp:885
wxChar GetNextNonWhitespaceCharOfLine(cbStyledTextCtrl *stc, int position=-1, int *pos=nullptr) const
Get the last non-whitespace character from position in line.
Definition: cbplugin.cpp:1321
EVTIMPORT const wxEventType cbEVT_QUERY_VIEW_LAYOUT
Definition: sdk_events.cpp:136
void SetProject(cbProject *project, bool refresh=true)
Set the active project.
A file editor.
Definition: cbeditor.h:43
bool IsEmpty() const
int GetCharAt(int pos) const
Returns the character byte at the position.
virtual bool ToolMenuEnabled() const
Definition: cbplugin.cpp:258
bool IsProviderFor(cbEditor *ed)
Has this plugin been selected to provide content for the editor.
Definition: cbplugin.cpp:1019
RegisteredPlugins const & GetAllDebuggers() const
wxString GetGUIName() const
Definition: cbplugin.h:618
The entry point singleton for working with projects.
level
Definition: logger.h:37
static const size_t npos
void ReplaceEnvVars(wxString &buffer)
Definition: macrosmanager.h:32
Target produces a console executable (without GUI) (distinction between ttExecutable and ttConsoleOnl...
virtual cb::shared_ptr< cbBreakpoint > GetBreakpoint(int index)=0
bool IsRelative(wxPathFormat format=wxPATH_NATIVE) const
virtual wxString GetEditorWordAtCaret(const wxPoint *mousePosition=NULL)
Definition: cbplugin.cpp:177
void Log(const wxString &msg, int i=app_log, Logger::level lv=Logger::info)
Definition: logmanager.h:140
cbPlugin()
In default cbPlugin&#39;s constructor the associated PluginInfo structure is filled with default values...
Definition: cbplugin.cpp:51
~cbPlugin() override
cbPlugin destructor.
Definition: cbplugin.cpp:58
#define wxSCI_INVALID_POSITION
Definition: wxscintilla.h:70
void DebugLog(const wxString &msg, Logger::level lv=Logger::info)
Definition: logmanager.h:146
virtual void ShiftBreakpoint(int index, int lines_to_shift)=0
bool ProcessEvent(CodeBlocksEvent &event)
Definition: manager.cpp:246
void wxMilliSleep(unsigned long milliseconds)
int ShowModal() override
StartType m_StartType
Definition: cbplugin.h:642
bool m_WaitingCompilerToFinish
Definition: cbplugin.h:640
void RegisterEventSink(wxEventType eventType, IEventFunctorBase< CodeBlocksEvent > *functor)
Definition: manager.cpp:550
virtual bool IsRunning() const =0
Is the plugin currently debugging?
DLLIMPORT HookFunctorBase * UnregisterHook(int id, bool deleteHook=true)
Unregister a previously registered project loading/saving hook.
int GetStyleAt(int pos) const
Returns the style byte at the position.
virtual void SetDebugLine(int line)
Highlight the line the debugger will execute next.
Definition: cbeditor.cpp:2447
void BuildContextMenu(wxMenu &menu, const wxString &word_at_caret, bool is_running)
virtual void ResetProject()=0
bool HasBreakpoint(cbDebuggerPlugin &plugin, wxString const &filename, int line)
Definition: cbplugin.cpp:360
Represents a Code::Blocks project build target.
bool Normalize(int flags=wxPATH_NORM_ALL, const wxString &cwd=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
EVTIMPORT const wxEventType cbEVT_PROJECT_CLOSE
Definition: sdk_events.cpp:96
virtual int Build(ProjectBuildTarget *target=nullptr)=0
Build the project/target.
size_t GetCount() const
ProjectFile * GetProjectFile() const
Read the ProjectFile pointer associated with this editor.
Definition: cbeditor.h:123
EVTIMPORT const wxEventType cbEVT_EDITOR_OPEN
Definition: sdk_events.cpp:81
bool IsAttached() const
See whether this plugin is attached or not.
Definition: cbplugin.h:187
virtual bool SupportsFeature(cbDebuggerFeature::Flags flag)=0
virtual bool ShowValueTooltip(int style)
Definition: cbplugin.cpp:928
bool MakeAbsolute(const wxString &cwd=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
virtual bool CompilerFinished(bool compilerFailed, StartType startType)
Called when the compilation has finished.
Definition: cbplugin.h:578
void OnRelease(bool appShutDown) override
Definition: cbplugin.cpp:161
virtual void NotImplemented(const wxString &log) const
This method logs a "Not implemented" message and is provided for convenience only.
Definition: cbplugin.cpp:109
void OnCCDoneEvent(CodeBlocksEvent &event)
Definition: cbplugin.cpp:1345
wxString GetFullPath(wxPathFormat format=wxPATH_NATIVE) const
void OnAttach() override
Any descendent plugin should override this virtual method and perform any necessary initialization...
Definition: cbplugin.cpp:1042
bool RegisterDebugger(cbDebuggerPlugin *plugin)
Called to register a debugger plugin.
Definition: globals.h:28
Provides a HookFunctor which redirects the Call() of a cbSmartIndentPlugin so only the interface of c...
Definition: editor_hooks.h:103
virtual void ConvertDirectory(wxString &str, wxString base=_T(""), bool relative=true)=0
cbDebuggerPlugin(const wxString &guiName, const wxString &settingsName)
Definition: cbplugin.cpp:127
bool wxGetKeyState(wxKeyCode key)
wxString GetLastNonCommentWord(cbEditor *ed, int position=-1, unsigned int NumberOfWords=1) const
(reverse) search for the last word which is not comment
Definition: cbplugin.cpp:1099
static wxString Format(const wxString &format,...)
wxString GetLastNonWhitespaceChars(cbEditor *ed, int position=-1, unsigned int NumberOfChars=1) const
(reverse) search for the last characters, which are not whitespace and not comment ...
Definition: cbplugin.cpp:1147
void BuildModuleMenu(const ModuleType type, wxMenu *menu, const FileTreeData *data=nullptr) override
Definition: cbplugin.cpp:232
Dialog that contains a "Don&#39;t annoy me" checkbox.
virtual void DoAutocomplete(const CCToken &token, cbEditor *ed)
Callback for inserting the selected autocomplete entry into the editor.
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
Definition: globals.cpp:1395
virtual void OnReleaseReal(bool appShutDown)=0
cbDebugInterfaceFactory * GetInterfaceFactory()
void DebugLog(const wxString &msg, Logger::level level=Logger::info)
Definition: cbplugin.cpp:540
EVTIMPORT const wxEventType cbEVT_SHOW_LOG_MANAGER
Definition: sdk_events.cpp:167
virtual bool IsAttachedToProcess() const =0
long wxExecute(const wxString &command, int flags=wxEXEC_ASYNC, wxProcess *callback=NULL, const wxExecuteEnv *env=NULL)
Event used to request from the main app to manage the view layouts.
Definition: sdk_events.h:158
Target only runs commands in pre-build and/or post-build steps.
DLLIMPORT int RegisterHook(HookFunctorBase *functor)
Register a project loading/saving hook.