Piklab – IDE for PIC-microcontroller development
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

994 lines
45 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org> *
  3. * Copyright (C) 2003-2004 Alain Gibaud <alain.gibaud@free.fr> *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. ***************************************************************************/
  10. #include "toplevel.h"
  11. #include <tqpixmap.h>
  12. #include <tqiconset.h>
  13. #include <tqlayout.h>
  14. #include <tqsplitter.h>
  15. #include <tqstringlist.h>
  16. #include <tqtimer.h>
  17. #include <tqprogressbar.h>
  18. #include <tqeventloop.h>
  19. #include <tqapplication.h>
  20. #include <tqtooltip.h>
  21. #include <kstatusbar.h>
  22. #include <tdelocale.h>
  23. #include <kedittoolbar.h>
  24. #include <tdeapplication.h>
  25. #include <tdeconfig.h>
  26. #include <tdeaction.h>
  27. #include <tdecmdlineargs.h>
  28. #include <tdeio/observer.h>
  29. #include <kiconloader.h>
  30. #include <tdepopupmenu.h>
  31. #include <khelpmenu.h>
  32. #include <tdemenubar.h>
  33. #include "gui_debug_manager.h"
  34. #include "hex_editor.h"
  35. #include "project_manager.h"
  36. #include "project.h"
  37. #include "global_config.h"
  38. #include "editor.h"
  39. #include "device_gui.h"
  40. #include "text_editor.h"
  41. #include "new_dialogs.h"
  42. #include "common/global/process.h"
  43. #include "common/gui/misc_gui.h"
  44. #include "common/gui/purl_gui.h"
  45. #include "devices/list/device_list.h"
  46. #include "progs/base/prog_config.h"
  47. #include "progs/list/prog_list.h"
  48. #include "progs/gui/prog_group_ui.h"
  49. #include "editor_manager.h"
  50. #include "tools/list/compile_manager.h"
  51. #include "object_view.h"
  52. #include "config_gen.h"
  53. #include "tools/list/compile_config.h"
  54. #include "watch_view.h"
  55. #include "coff/base/text_coff.h"
  56. #include "tools/list/tool_list.h"
  57. #include "breakpoint_view.h"
  58. #include "main_global.h"
  59. #include "gui_prog_manager.h"
  60. #include "devices/gui/register_view.h"
  61. #include "likeback.h"
  62. #include "console.h"
  63. #include "devices/base/device_group.h"
  64. #include "tools/gui/toolchain_config_center.h"
  65. #include "global_config.h"
  66. //----------------------------------------------------------------------------
  67. KDockWidget *MainWindow::createDock(const TQString &name, const TQPixmap &icon,
  68. const TQString &title, const DockPosition &position)
  69. {
  70. KDockWidget *dock = createDockWidget(name, icon, 0, title);
  71. dock->setDockSite(KDockWidget::DockCenter);
  72. DockData ddata;
  73. ddata.title = title;
  74. ddata.position = position;
  75. ddata.dock = dock;
  76. ddata.action = new ViewMenuAction(dock);
  77. connect(ddata.action, TQT_SIGNAL(activated(TQWidget *)), TQT_SLOT(toggleToolView(TQWidget *)));
  78. _docks += ddata;
  79. initDockPosition(ddata);
  80. return dock;
  81. }
  82. MainWindow::MainWindow()
  83. : _configGenerator(0), _pikloopsProcess(0), _kfindProcess(0), _forceProgramAfterBuild(false)
  84. {
  85. Q_ASSERT( Main::_toplevel==0 );
  86. Main::_toplevel = this;
  87. // status bar
  88. _actionStatus = new TQLabel(statusBar());
  89. statusBar()->addWidget(_actionStatus);
  90. _actionProgress = new TQProgressBar(statusBar());
  91. statusBar()->addWidget(_actionProgress);
  92. _debugStatus = new TQLabel(statusBar());
  93. statusBar()->addWidget(_debugStatus, 0, true);
  94. _editorStatus = new TQLabel(statusBar());
  95. statusBar()->addWidget(_editorStatus, 0, true);
  96. _programmerStatus = new ProgrammerStatusWidget(statusBar());
  97. connect(_programmerStatus, TQT_SIGNAL(configure()), TQT_SLOT(configureProgrammer()));
  98. connect(_programmerStatus, TQT_SIGNAL(selected(const Programmer::Group &)), TQT_SLOT(selectProgrammer(const Programmer::Group &)));
  99. statusBar()->addWidget(_programmerStatus->widget(), 0, true);
  100. _toolStatus = new ToolStatusWidget(statusBar());
  101. connect(_toolStatus, TQT_SIGNAL(configureToolchain()), TQT_SLOT(configureToolchains()));
  102. connect(_toolStatus, TQT_SIGNAL(configure()), TQT_SLOT(configureProject()));
  103. connect(_toolStatus, TQT_SIGNAL(selected(const Tool::Group &)), TQT_SLOT(selectTool(const Tool::Group &)));
  104. statusBar()->addWidget(_toolStatus->widget(), 0, true);
  105. // interface
  106. _mainDock = createDockWidget("main_dock_widget", TQPixmap());
  107. _mainDock->setDockSite(KDockWidget::DockCorner);
  108. _mainDock->setEnableDocking(KDockWidget::DockNone);
  109. setView(_mainDock);
  110. setMainDockWidget(_mainDock);
  111. TDEIconLoader loader;
  112. KDockWidget *dock = createDock("project_manager_dock_widget", PURL::icon(PURL::Project),
  113. i18n("Project Manager"), DockPosition(KDockWidget::DockLeft, 20));
  114. Main::_projectManager = new ProjectManager::View(dock);
  115. connect(TQT_TQOBJECT(Main::_projectManager), TQT_SIGNAL(guiChanged()), TQT_SLOT(updateGUI()));
  116. dock->setWidget(Main::_projectManager);
  117. dock = createDock("watch_view_dock_widget", loader.loadIcon("viewmag", TDEIcon::Small),
  118. i18n("Watch View"), DockPosition("project_manager_dock_widget"));
  119. Main::_watchView = new Register::WatchView(dock);
  120. dock->setWidget(Main::_watchView);
  121. Main::_editorManager = new EditorManager(_mainDock);
  122. _mainDock->setWidget(Main::_editorManager);
  123. connect(TQT_TQOBJECT(Main::_editorManager), TQT_SIGNAL(guiChanged()), TQT_SLOT(updateGUI()));
  124. connect(TQT_TQOBJECT(Main::_editorManager), TQT_SIGNAL(modified(const PURL::Url &)), TQT_TQOBJECT(Main::_projectManager), TQT_SLOT(modified(const PURL::Url &)));
  125. connect(TQT_TQOBJECT(Main::_editorManager), TQT_SIGNAL(statusChanged(const TQString &)), _editorStatus, TQT_SLOT(setText(const TQString &)));
  126. dock = createDock("compile_log_dock_widget", loader.loadIcon("piklab_compile", TDEIcon::Small),
  127. i18n("Compile Log"), DockPosition(KDockWidget::DockBottom, 80));
  128. Main::_compileLog = new Compile::LogWidget(dock);
  129. Main::_compileLog->setFocusPolicy(TQ_NoFocus);
  130. dock->setWidget(Main::_compileLog);
  131. dock = createDock("program_log_dock_widget", loader.loadIcon("piklab_burnchip", TDEIcon::Small),
  132. i18n("Program Log"), DockPosition("compile_log_dock_widget"));
  133. _programLog = new Log::Widget(dock, "program_log");
  134. _programLog->setFocusPolicy(TQ_NoFocus);
  135. dock->setWidget(_programLog);
  136. dock = createDock("breakpoints_dock_widget", loader.loadIcon("piklab_breakpoint_active", TDEIcon::Small),
  137. i18n("Breakpoints"), DockPosition("compile_log_dock_widget"));
  138. Main::_breakpointsView = new Breakpoint::View(dock);
  139. Main::_breakpointsView->setFocusPolicy(TQ_NoFocus);
  140. dock->setWidget(Main::_breakpointsView);
  141. dock = createDock("console_dock_widget", loader.loadIcon("konsole", TDEIcon::Small),
  142. i18n("Konsole"), DockPosition("compile_log_dock_widget"));
  143. Main::_consoleView = new ConsoleView(dock);
  144. dock->setWidget(Main::_consoleView);
  145. // managers
  146. Programmer::manager = new Programmer::GuiManager(TQT_TQOBJECT(this));
  147. Programmer::manager->setView(_programLog);
  148. connect(Programmer::manager, TQT_SIGNAL(actionMessage(const TQString &)), _actionStatus, TQT_SLOT(setText(const TQString &)));
  149. connect(Programmer::manager, TQT_SIGNAL(showProgress(bool)), TQT_SLOT(showProgress(bool)));
  150. connect(Programmer::manager, TQT_SIGNAL(setTotalProgress(uint)), TQT_SLOT(setTotalProgress(uint)));
  151. connect(Programmer::manager, TQT_SIGNAL(setProgress(uint)), TQT_SLOT(setProgress(uint)));
  152. Debugger::manager = new Debugger::GuiManager;
  153. connect(Debugger::manager, TQT_SIGNAL(targetStateChanged()), TQT_SLOT(updateGUI()));
  154. connect(Debugger::manager, TQT_SIGNAL(statusChanged(const TQString &)), _debugStatus, TQT_SLOT(setText(const TQString &)));
  155. connect(Debugger::manager, TQT_SIGNAL(actionMessage(const TQString &)), _actionStatus, TQT_SLOT(setText(const TQString &)));
  156. Main::_compileManager = new Compile::Manager(TQT_TQOBJECT(this));
  157. Main::_compileManager->setView(Main::_compileLog);
  158. connect(Main::_compileManager, TQT_SIGNAL(success()), TQT_SLOT(compileSuccess()));
  159. connect(Main::_compileManager, TQT_SIGNAL(failure()), TQT_SLOT(compileFailure()));
  160. connect(Main::_compileManager, TQT_SIGNAL(updateFile(const Compile::FileData &)),
  161. TQT_SLOT(updateFile(const Compile::FileData &)));
  162. // actions
  163. // file actions
  164. TDEAction *a = KStdAction::openNew(TQT_TQOBJECT(this), TQT_SLOT(newSourceFile()), actionCollection());
  165. a->setText(i18n("&New Source File..."));
  166. (void)new TDEAction(i18n("New hex File..."), "document-new", 0, TQT_TQOBJECT(this), TQT_SLOT(newHexFile()),
  167. actionCollection(), "file_new_hex");
  168. KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(openFile()), actionCollection());
  169. TDERecentFilesAction *recent = KStdAction::openRecent(TQT_TQOBJECT(this), TQT_SLOT(openRecentFile(const KURL &)), actionCollection());
  170. recent->setMaxItems(20);
  171. recent->loadEntries(kapp->config(), "recent-files");
  172. (void)new TDEAction(i18n("Save All"), 0, 0, TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(saveAllFiles()),
  173. actionCollection(), "file_save_all");
  174. KStdAction::close(TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(closeCurrentEditor()), actionCollection());
  175. (void)new TDEAction(i18n("C&lose All"), 0, 0, TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(closeAllEditors()),
  176. actionCollection(), "file_close_all");
  177. (void)new TDEAction(i18n("Close All Others"), 0, 0, TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(closeAllOtherEditors()),
  178. actionCollection(), "file_closeother");
  179. KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(close()), actionCollection());
  180. // edit actions
  181. // view actions
  182. (void)new TDEAction(i18n("Back"), "back", TQt::ALT + TQt::Key_Left,
  183. TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(goBack()), actionCollection(), "history_back");
  184. (void)new TDEAction(i18n("Forward"), "forward", TQt::ALT + TQt::Key_Right,
  185. TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(goForward()), actionCollection(), "history_forward");
  186. (void)new TDEAction(i18n("Switch to..."), 0, TQt::CTRL + TQt::Key_Slash,
  187. TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(switchToEditor()), actionCollection(), "file_switchto");
  188. (void)new TDEAction(i18n("Switch Header/Implementation"), 0, TQt::SHIFT + TQt::Key_F12,
  189. TQT_TQOBJECT(Main::_editorManager), TQT_SLOT(switchHeaderImplementation()), actionCollection(), "view_switch_source");
  190. (void)new TDEAction(TQString(), 0, 0,
  191. Debugger::manager, TQT_SLOT(toggleBreakpoint()), actionCollection(), "toggle_breakpoint");
  192. (void)new TDEAction(TQString(), 0, 0,
  193. Debugger::manager, TQT_SLOT(toggleEnableBreakpoint()), actionCollection(), "enable_breakpoint");
  194. (void)new TDEAction(i18n("Show disassembly location"), 0, 0,
  195. Debugger::manager, TQT_SLOT(showDisassemblyLocation()), actionCollection(), "show_disassembly_location");
  196. TDEActionMenu *toolViewsMenu = new TDEActionMenu( i18n("Tool Views"), 0, "view_tool_views");
  197. connect(toolViewsMenu->popupMenu(), TQT_SIGNAL(aboutToShow()), TQT_SLOT(updateToolViewsActions()));
  198. actionCollection()->insert(toolViewsMenu);
  199. a = new TDEAction(i18n("&Reset Layout"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(resetDockLayout()), actionCollection(), "view_reset_layout");
  200. toolViewsMenu->insert(a);
  201. toolViewsMenu->popupMenu()->insertSeparator();
  202. TQValueList<DockData>::iterator it;
  203. for(it=_docks.begin(); it!=_docks.end(); ++it) toolViewsMenu->insert((*it).action);
  204. // project actions
  205. (void)new TDEAction(i18n("New Project..."), "piklab_createproject", 0,
  206. TQT_TQOBJECT(this), TQT_SLOT(newProject()), actionCollection(), "project_new");
  207. (void)new TDEAction(i18n("Open Project..."), "piklab_openproject", 0,
  208. TQT_TQOBJECT(this), TQT_SLOT(openProject()), actionCollection(), "project_open");
  209. recent = new TDERecentFilesAction(i18n("Open Recent Project"), 0,
  210. TQT_TQOBJECT(this), TQT_SLOT(openRecentProject(const KURL &)), actionCollection(), "project_open_recent");
  211. recent->setMaxItems(20);
  212. recent->loadEntries(kapp->config(), "recent-projects");
  213. (void)new TDEAction(i18n("Project Options..."), "configure", 0,
  214. TQT_TQOBJECT(this), TQT_SLOT(configureProject()), actionCollection(), "project_options");
  215. (void)new TDEAction(i18n("Close Project"), "window-close", 0,
  216. TQT_TQOBJECT(this), TQT_SLOT(closeProject()), actionCollection(), "project_close");
  217. (void)new TDEAction(i18n("Add Source File..."), "piklab_addfile", 0,
  218. TQT_TQOBJECT(Main::_projectManager), TQT_SLOT(insertSourceFiles()), actionCollection(), "project_add_source_file");
  219. (void)new TDEAction(i18n("Add Object File..."), "piklab_addfile", 0,
  220. TQT_TQOBJECT(Main::_projectManager), TQT_SLOT(insertObjectFiles()), actionCollection(), "project_add_object_file");
  221. (void)new TDEAction(i18n("Add Current File"), "piklab_addcurrentfile", 0,
  222. TQT_TQOBJECT(Main::_projectManager), TQT_SLOT(insertCurrentFile()), actionCollection(), "project_add_current_file");
  223. // build actions
  224. (void)new TDEAction(i18n("&Build Project"), "piklab_compile", TQt::Key_F8,
  225. TQT_TQOBJECT(this), TQT_SLOT(buildProject()), actionCollection(), "build_build_project");
  226. (void)new TDEAction(i18n("&Compile File"), 0, TQt::SHIFT + TQt::Key_F8,
  227. TQT_TQOBJECT(this), TQT_SLOT(compileFile()), actionCollection(), "build_compile_file");
  228. (void)new TDEAction(i18n("Clean"), "trashcan_empty", 0,
  229. TQT_TQOBJECT(this), TQT_SLOT(cleanBuild()), actionCollection(), "build_clean");
  230. (void)new TDEAction(i18n("Stop"), "process-stop", 0,
  231. TQT_TQOBJECT(this), TQT_SLOT(stopBuild()), actionCollection(), "build_stop");
  232. // programmer actions
  233. (void)new TDEAction(i18n("&Connect"), "connect_creating", 0,
  234. Programmer::manager, TQT_SLOT(connectDevice()), actionCollection(), "prog_connect");
  235. (void)new TDEToggleAction(i18n("Device Power"), "piklab_power", 0,
  236. Programmer::manager, TQT_SLOT(toggleDevicePower()), actionCollection(), "prog_power");
  237. (void)new TDEAction(i18n("&Disconnect"), "connect_no", 0,
  238. Programmer::manager, TQT_SLOT(disconnectDevice()), actionCollection(), "prog_disconnect");
  239. (void)new TDEAction(i18n("&Program"), "piklab_burnchip", TQt::SHIFT + TQt::Key_F5,
  240. TQT_TQOBJECT(this), TQT_SLOT(program()), actionCollection(), "prog_program");
  241. (void)new TDEAction(i18n("&Verify"), "piklab_verifychip", TQt::SHIFT + TQt::Key_F6,
  242. TQT_TQOBJECT(this), TQT_SLOT(verify()), actionCollection(), "prog_verify");
  243. (void)new TDEAction(i18n("&Read"), "piklab_readchip", TQt::SHIFT + TQt::Key_F7,
  244. TQT_TQOBJECT(this), TQT_SLOT(read()), actionCollection(), "prog_read");
  245. (void)new TDEAction(i18n("&Erase"), "piklab_erasechip", 0,
  246. TQT_TQOBJECT(this), TQT_SLOT(erase()), actionCollection(), "prog_erase");
  247. (void)new TDEAction(i18n("&Blank Check"), "piklab_blankcheck", 0,
  248. TQT_TQOBJECT(this), TQT_SLOT(blankCheck()), actionCollection(), "prog_blank_check");
  249. (void)new TDEAction(i18n("&Run"), "launch", TQt::SHIFT + TQt::Key_F9,
  250. Programmer::manager, TQT_SLOT(run()), actionCollection(), "prog_run");
  251. (void)new TDEAction(i18n("&Stop"), "piklab_stop", 0,
  252. Programmer::manager, TQT_SLOT(halt()), actionCollection(), "prog_stop");
  253. (void)new TDEAction(i18n("R&estart"), "piklab_restart", 0,
  254. Programmer::manager, TQT_SLOT(restart()), actionCollection(), "prog_restart");
  255. (void)new TDEAction(i18n("&Advanced..."), 0, 0,
  256. Programmer::manager , TQT_SLOT(showAdvancedDialog()), actionCollection(), "prog_advanced");
  257. (void)new TDEAction(i18n("Settings..."), "configure", 0,
  258. TQT_TQOBJECT(this), TQT_SLOT(showProgrammerSettings()), actionCollection(), "prog_settings");
  259. // debugger actions
  260. (void)new TDEAction(i18n("&Start"), "launch", TQt::SHIFT + TQt::Key_F9,
  261. Programmer::manager, TQT_SLOT(restart()), actionCollection(), "debug_start");
  262. (void)new TDEAction(i18n("&Run"), "piklab_run", TQt::SHIFT + TQt::Key_F9,
  263. Programmer::manager, TQT_SLOT(run()), actionCollection(), "debug_run");
  264. (void)new TDEAction(i18n("&Step"), "piklab_debug_step", 0,
  265. Programmer::manager, TQT_SLOT(step()), actionCollection(), "debug_next");
  266. //(void)new TDEAction(i18n("Step &In"), "piklab_debug_stepin",
  267. // 0, TQT_TQOBJECT(this), TQT_SLOT(debugStepIn()), actionCollection(), "debug_step_in");
  268. //(void)new TDEAction(i18n("Step &Out"), "piklab_debug_stepout",
  269. // 0, TQT_TQOBJECT(this), TQT_SLOT(debugStepOut()), actionCollection(), "debug_step_out");
  270. (void)new TDEAction(i18n("&Break<Translators: it is the verb>", "&Halt"), "piklab_debughalt", 0,
  271. Programmer::manager, TQT_SLOT(halt()), actionCollection(), "debug_halt");
  272. (void)new TDEAction(i18n("&Disconnect/Stop"), "piklab_stop", 0,
  273. Programmer::manager, TQT_SLOT(disconnectDevice()), actionCollection(), "debug_stop");
  274. (void)new TDEAction(i18n("R&eset"), "piklab_restart", 0,
  275. Programmer::manager, TQT_SLOT(restart()), actionCollection(), "debug_reset");
  276. (void)new TDEAction(i18n("Show Program Counter"), "piklab_program_counter", 0,
  277. Debugger::manager, TQT_SLOT(showPC()), actionCollection(), "debug_show_pc");
  278. (void)new TDEAction(i18n("Clear All Breakpoints"), "remove", 0,
  279. Debugger::manager, TQT_SLOT(clearBreakpoints()), actionCollection(), "debug_clear_breakpoints");
  280. (void)new TDEAction(i18n("Settings..."), "configure", 0,
  281. TQT_TQOBJECT(this), TQT_SLOT(showDebuggerSettings()), actionCollection(), "debug_settings");
  282. // tools
  283. (void)new TDEAction(i18n("&Pikloops..."), 0, 0,
  284. TQT_TQOBJECT(this), TQT_SLOT(runPikloops()), actionCollection(), "tools_pikloops");
  285. (void)new TDEAction(i18n("&Find Files..."), "edit-find", 0,
  286. TQT_TQOBJECT(this), TQT_SLOT(runKfind()), actionCollection(), "tools_kfind");
  287. (void)new TDEAction(i18n("&Device Information..."), "application-vnd.tde.info", 0,
  288. TQT_TQOBJECT(this), TQT_SLOT(showDeviceInfo()), actionCollection(), "tools_device_information");
  289. (void)new TDEAction(i18n("&Config Generator..."), 0, 0,
  290. TQT_TQOBJECT(this), TQT_SLOT(configGenerator()), actionCollection(), "tools_config_generator");
  291. (void)new TDEAction(i18n("&Template Generator..."), 0, 0,
  292. TQT_TQOBJECT(this), TQT_SLOT(templateGenerator()), actionCollection(), "tools_template_generator");
  293. // settings actions
  294. (void)new TDEAction(i18n("Configure Toolchains..."), 0, 0,
  295. TQT_TQOBJECT(this), TQT_SLOT(configureToolchains()), actionCollection(), "options_configure_toolchains");
  296. (void)KStdAction::preferences(TQT_TQOBJECT(this), TQT_SLOT(configure()), actionCollection());
  297. // help
  298. (void)new TDEAction(i18n("Report Bug..."), "likeback_bug", 0,
  299. TQT_TQOBJECT(LikeBack::instance()), TQT_SLOT(iFoundABug()), actionCollection(), "help_report_bug_piklab");
  300. setupGUI();
  301. readDockConfig();
  302. // LikeBack buttons
  303. menuBar()->insertItem(new TQLabel(menuBar())); // #### first widget is put left-most...
  304. MenuBarButton *button = new MenuBarButton("likeback_like", menuBar());
  305. TQToolTip::add(button, i18n("I like..."));
  306. connect(button, TQT_SIGNAL(clicked()), TQT_TQOBJECT(LikeBack::instance()), TQT_SLOT(iLike()));
  307. menuBar()->insertItem(button);
  308. button = new MenuBarButton("likeback_dislike", menuBar());
  309. TQToolTip::add(button, i18n("I do not like..."));
  310. connect(button, TQT_SIGNAL(clicked()), TQT_TQOBJECT(LikeBack::instance()), TQT_SLOT(iDoNotLike()));
  311. menuBar()->insertItem(button);
  312. button = new MenuBarButton("likeback_bug", menuBar());
  313. TQToolTip::add(button, i18n("I found a bug..."));
  314. connect(button, TQT_SIGNAL(clicked()), TQT_TQOBJECT(LikeBack::instance()), TQT_SLOT(iFoundABug()));
  315. menuBar()->insertItem(button);
  316. button = new MenuBarButton("configure", menuBar());
  317. TQToolTip::add(button, i18n("Configure email..."));
  318. connect(button, TQT_SIGNAL(clicked()), TQT_TQOBJECT(LikeBack::instance()), TQT_SLOT(askEMail()));
  319. menuBar()->insertItem(button);
  320. button = new MenuBarButton("help", menuBar());
  321. connect(button, TQT_SIGNAL(clicked()), TQT_TQOBJECT(LikeBack::instance()), TQT_SLOT(showWhatsThisMessage()));
  322. menuBar()->insertItem(button);
  323. TQTimer::singleShot(0, TQT_TQOBJECT(this), TQT_SLOT(initialLoading()));
  324. }
  325. MainWindow::~MainWindow()
  326. {}
  327. void MainWindow::readDockConfig()
  328. {
  329. KDockMainWindow::readDockConfig(kapp->config(), "dock_config");
  330. // if there is a new dock: it is not displayed by default...
  331. TQMap<TQString, TQString> entries = kapp->config()->entryMap("dock_config");
  332. TQValueList<DockData>::iterator it;
  333. for(it=_docks.begin(); it!=_docks.end(); ++it) {
  334. TQMap<TQString, TQString>::const_iterator eit;
  335. for(eit=entries.begin(); eit!=entries.end(); ++eit)
  336. if ( eit.key().startsWith((*it).dock->name()) ) break;
  337. if ( eit==entries.end() ) initDockPosition(*it);
  338. }
  339. // readDockConfig also restore the names/tooltips: what if a new version of the application changes these names...
  340. for(it=_docks.begin(); it!=_docks.end(); ++it) (*it).dock->setTabPageLabel((*it).title);
  341. TQApplication::postEvent(this, new TQEvent(TQEvent::CaptionChange));
  342. }
  343. void MainWindow::initialLoading()
  344. {
  345. ::PBusyCursor bc;
  346. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  347. if ( args->count()!=0 ) { // opened urls provided on the command line
  348. for (int i = 0; i<args->count(); i++) {
  349. PURL::Url url(args->url(i));
  350. if ( url.fileType()==PURL::Project ) {
  351. if ( Main::_projectManager->project()==0 ) Main::_projectManager->openProject(url);
  352. } else Main::_editorManager->openEditor(url);
  353. }
  354. } else { // otherwise reopen last project/files
  355. Main::_projectManager->openProject(GlobalConfig::openedProject());
  356. PURL::UrlList files = GlobalConfig::openedFiles();
  357. PURL::UrlList::const_iterator it = files.begin();
  358. for (; it!=files.end(); ++it) Main::_editorManager->openEditor(*it);
  359. }
  360. updateGUI();
  361. }
  362. void MainWindow::openRecentFile(const KURL &kurl)
  363. {
  364. Main::_editorManager->openFile(PURL::Url(kurl));
  365. }
  366. void MainWindow::configureToolbar()
  367. {
  368. saveMainWindowSettings(TDEGlobal::config(), "MainWindow");
  369. KEditToolbar dlg(actionCollection());
  370. connect(&dlg, TQT_SIGNAL(newToolbarConfig()), TQT_SLOT(applyToolbarSettings()));
  371. dlg.exec();
  372. }
  373. void MainWindow::applyToolbarSettings()
  374. {
  375. createGUI();
  376. applyMainWindowSettings(TDEGlobal::config(), "MainWindow");
  377. }
  378. void MainWindow::configure(ConfigCenter::Type showType)
  379. {
  380. stopOperations();
  381. ConfigCenter dialog(showType, this);
  382. dialog.exec();
  383. Programmer::manager->clear();
  384. updateGUI();
  385. Debugger::manager->update(true);
  386. }
  387. void MainWindow::configureToolchains()
  388. {
  389. stopOperations();
  390. ToolchainsConfigCenter dialog(Main::toolGroup(), this);
  391. dialog.exec();
  392. Programmer::manager->clear();
  393. updateGUI();
  394. Debugger::manager->update(true);
  395. }
  396. void MainWindow::selectProgrammer(const Programmer::Group &group)
  397. {
  398. if ( group.name()==Main::programmerGroup().name() ) return;
  399. bool debugInitialized = Debugger::manager->coff();
  400. stopOperations();
  401. GlobalConfig::writeProgrammerGroup(group);
  402. Programmer::manager->clear();
  403. updateGUI();
  404. if (debugInitialized) Debugger::manager->init();
  405. else Debugger::manager->update(true);
  406. }
  407. void MainWindow::selectTool(const Tool::Group &group)
  408. {
  409. if ( group.name()==Compile::Config::toolGroup(Main::project()).name() ) return;
  410. bool debugInitialized = Debugger::manager->coff();
  411. stopOperations();
  412. Compile::Config::setToolGroup(Main::project(), group);
  413. updateGUI();
  414. if (debugInitialized) Debugger::manager->init();
  415. else Debugger::manager->update(true);
  416. }
  417. void MainWindow::setDevice(const TQString &device)
  418. {
  419. if ( device==i18n(Device::AUTO_DATA.label) ) Compile::Config::setDevice(Main::project(), Device::AUTO_DATA.name);
  420. else Compile::Config::setDevice(Main::project(), device);
  421. updateGUI();
  422. }
  423. void MainWindow::showDeviceInfo()
  424. {
  425. DeviceChooser::Dialog d(Main::device(), (Main::project() ? DeviceChooser::Choose : DeviceChooser::ChooseWithAuto), this);
  426. if ( d.exec() ) {
  427. setDevice(d.device());
  428. updateGUI();
  429. }
  430. }
  431. void MainWindow::configGenerator()
  432. {
  433. PURL::FileType ftype = (Main::currentEditor() ? Main::currentEditor()->fileType() : PURL::Nb_FileTypes);
  434. PURL::SourceFamily family = (ftype!=PURL::Nb_FileTypes ? ftype.data().sourceFamily : PURL::SourceFamily(PURL::SourceFamily::Nb_Types));
  435. PURL::ToolType type = (family!=PURL::SourceFamily::Nb_Types ? family.data().toolType : PURL::ToolType(PURL::ToolType::Assembler));
  436. ConfigGenerator dialog(this);
  437. dialog.set(Main::deviceData(), Main::toolGroup(), type);
  438. dialog.exec();
  439. }
  440. void MainWindow::templateGenerator()
  441. {
  442. PURL::FileType ftype = (Main::currentEditor() ? Main::currentEditor()->fileType() : PURL::Nb_FileTypes);
  443. PURL::SourceFamily family = (ftype!=PURL::Nb_FileTypes ? ftype.data().sourceFamily : PURL::SourceFamily(PURL::SourceFamily::Nb_Types));
  444. PURL::ToolType type = (family!=PURL::SourceFamily::Nb_Types ? family.data().toolType : PURL::ToolType(PURL::ToolType::Assembler));
  445. TemplateGenerator dialog(this);
  446. dialog.set(Main::deviceData(), Main::toolGroup(), type);
  447. dialog.exec();
  448. }
  449. bool MainWindow::queryClose()
  450. {
  451. if ( !stopOperations() ) return false;
  452. Main::setState(Main::Closing);
  453. // save list of opened editors
  454. PURL::UrlList toSave;
  455. const PURL::UrlList files = Main::_editorManager->files();
  456. PURL::UrlList::const_iterator it;
  457. for (it=files.begin(); it!=files.end(); ++it)
  458. if ( !Main::_projectManager->isExternalFile(*it) ) toSave.append(*it);
  459. GlobalConfig::writeOpenedFiles(toSave);
  460. // close editors
  461. if ( !Main::_editorManager->closeAllEditors() ) {
  462. Main::setState(Main::Idle);
  463. return false;
  464. }
  465. // save other settings
  466. ::PBusyCursor bc;
  467. writeDockConfig(kapp->config(), "dock_config");
  468. static_cast<TDERecentFilesAction *>(Main::action("project_open_recent"))->saveEntries(kapp->config(), "recent-projects");
  469. static_cast<TDERecentFilesAction *>(Main::action("file_open_recent"))->saveEntries(kapp->config(), "recent-files");
  470. GlobalConfig::writeOpenedProject(Main::project() ? Main::project()->url() : PURL::Url());
  471. if ( Main::project() ) Main::_projectManager->closeProject();
  472. return true;
  473. }
  474. void MainWindow::newSourceFile()
  475. {
  476. NewFileDialog dialog(Main::project(), this);
  477. if ( dialog.exec()!=TQDialog::Accepted ) return;
  478. if ( !dialog.url().exists() && !dialog.url().create(*Main::_compileLog) ) return;
  479. Main::_editorManager->openEditor(dialog.url());
  480. if ( dialog.addToProject() ) Main::_projectManager->insertFile(dialog.url());
  481. }
  482. void MainWindow::newHexFile()
  483. {
  484. if ( Main::device()==Device::AUTO_DATA.name ) {
  485. MessageBox::sorry(i18n("You need to specify a device to create a new hex file."), Log::Show);
  486. return;
  487. }
  488. TQString s;
  489. for (uint i=0; true; i++) {
  490. s = i18n("Hex") + (i==0 ? TQString() : TQString::number(i));
  491. if ( Main::_editorManager->findEditor(s)==0 ) break;
  492. }
  493. HexEditor *editor = new HexEditor(s, Main::_editorManager);
  494. editor->memoryRead();
  495. Main::_editorManager->addEditor(editor);
  496. }
  497. bool MainWindow::openFile()
  498. {
  499. TQString filter;
  500. filter += PURL::sourceFilter(PURL::SimpleFilter);
  501. filter += "\n" + PURL::filter(PURL::Hex);
  502. filter += "\n" + PURL::projectFilter(PURL::SimpleFilter);
  503. filter += "\n*|" + i18n("All Files");
  504. PURL::Url url = PURL::getOpenUrl(":open_file", filter, this ,i18n("Open File"));
  505. if ( url.fileType()==PURL::Project || url.fileType()==PURL::PikdevProject ) {
  506. stopOperations();
  507. if ( !Main::_projectManager->openProject(url) ) return false;
  508. updateGUI();
  509. return true;
  510. }
  511. return Main::_editorManager->openFile(url);
  512. }
  513. void MainWindow::updateGUI()
  514. {
  515. bool idle = ( Main::_state==Main::Idle );
  516. switch (Main::_state) {
  517. case Main::Closing: return;
  518. case Main::Idle:
  519. showProgress(false);
  520. break;
  521. case Main::Compiling:
  522. _actionStatus->setText(Main::_compileManager->label());
  523. showProgress(true);
  524. makeWidgetDockVisible(Main::_compileLog);
  525. break;
  526. case Main::Programming:
  527. makeWidgetDockVisible(_programLog);
  528. break;
  529. }
  530. // update editor actions
  531. Main::_editorManager->updateTitles();
  532. Main::action("file_save_all")->setEnabled(Main::currentEditor());
  533. Main::action("file_close")->setEnabled(Main::currentEditor());
  534. Main::action("file_close_all")->setEnabled(Main::currentEditor());
  535. Main::action("file_closeother")->setEnabled(Main::_editorManager->nbEditors()>1);
  536. Main::action("options_configure")->setEnabled(idle);
  537. PURL::FileType currentType = (Main::currentEditor() ? Main::currentEditor()->fileType() : PURL::Nb_FileTypes);
  538. bool isSource = (currentType==PURL::Nb_FileTypes ? false : currentType.data().group==PURL::Source);
  539. bool isHeader = (currentType==PURL::Nb_FileTypes ? false : currentType.data().group==PURL::Header);
  540. Main::action("view_switch_source")->setEnabled(isSource || isHeader);
  541. Main::action("history_back")->setEnabled(Main::editorManager().history().hasBack());
  542. Main::action("history_forward")->setEnabled(Main::editorManager().history().hasForward());
  543. Main::action("show_disassembly_location")->setEnabled(Debugger::manager->coff()!=0 && (isSource || isHeader));
  544. // update project
  545. bool inProject = ( Main::currentEditor() && (currentType==PURL::Nb_FileTypes || Main::currentEditor()->url().isEmpty() || Main::_projectManager->contains(Main::currentEditor()->url())) );
  546. if ( Main::project()==0 && !inProject ) {
  547. if ( Main::currentEditor()==0 ) Main::_projectManager->closeProject();
  548. else if ( isSource ) Main::_projectManager->setStandalone(Main::currentEditor()->url(), currentType);
  549. else {
  550. PURL::FileType type;
  551. PURL::Url purl = Main::_projectManager->standaloneGenerator(Main::currentEditor()->url(), type);
  552. if ( type!=PURL::Nb_FileTypes ) Main::_projectManager->setStandalone(purl, type);
  553. else if ( currentType==PURL::Hex ) Main::_projectManager->setStandalone(purl, PURL::Hex);
  554. }
  555. }
  556. if ( Main::currentEditor() ) Main::_projectManager->select(Main::currentEditor());
  557. // update project actions
  558. Main::action("project_new")->setEnabled(idle);
  559. Main::action("project_open")->setEnabled(idle);
  560. Main::action("project_close")->setEnabled(Main::project() && idle);
  561. Main::action("project_options")->setEnabled(Main::project() && idle);
  562. Main::action("project_add_source_file")->setEnabled(Main::project() && idle);
  563. Main::action("project_add_object_file")->setEnabled(Main::project() && idle);
  564. Main::action("project_add_current_file")->setEnabled(Main::project() && !inProject && idle && isSource);
  565. // update build actions
  566. static_cast<PopupButton *>(_toolStatus->widget())->setText(" " + Main::toolGroup().label() + " ");
  567. bool hexProject = ( Main::_projectManager->projectUrl().fileType()==PURL::Hex );
  568. bool customTool = Main::toolGroup().isCustom();
  569. Main::action("build_build_project")->setEnabled((Main::project() || (inProject && !hexProject) ) && idle);
  570. PURL::Url selected = Main::_projectManager->selectedUrl();
  571. bool isSelectedSource = ( !selected.isEmpty() && selected.data().group==PURL::Source );
  572. Main::action("build_compile_file")->setEnabled(!hexProject && (isSource || isSelectedSource) && idle && !customTool);
  573. Main::action("build_clean")->setEnabled((Main::project() || inProject) && idle && !customTool);
  574. Main::action("build_stop")->setEnabled(Main::_state==Main::Compiling);
  575. // update programmer status
  576. PortType ptype = Programmer::GroupConfig::portType(Main::programmerGroup());
  577. static_cast<PopupButton *>(_programmerStatus->widget())->setText(" " + Main::programmerGroup().statusLabel(ptype) + " ");
  578. TQFont f = font();
  579. bool supported = (Main::deviceData() ? Main::programmerGroup().isSupported(Main::deviceData()->name()) : false);
  580. f.setItalic(!supported);
  581. _programmerStatus->widget()->setFont(f);
  582. bool isProgrammer = ( Main::programmerGroup().properties() & ::Programmer::Programmer );
  583. PURL::Url purl = Main::_projectManager->projectUrl();
  584. bool hasHex = ( currentType==PURL::Hex || Main::_projectManager->contains(purl.toFileType(PURL::Hex)) );
  585. Main::action("prog_connect")->setEnabled(isProgrammer && idle);
  586. Main::action("prog_read")->setEnabled(isProgrammer && idle);
  587. Main::action("prog_program")->setEnabled(isProgrammer && hasHex && idle);
  588. Main::action("prog_verify")->setEnabled(isProgrammer && hasHex && idle);
  589. Main::action("prog_erase")->setEnabled(isProgrammer && idle);
  590. Main::action("prog_blank_check")->setEnabled(isProgrammer && idle);
  591. Programmer::State pstate = (Main::programmer() ? Main::programmer()->state() : Programmer::NotConnected);
  592. static_cast<TDEToggleAction *>(Main::action("prog_power"))->setEnabled(isProgrammer && idle && pstate!=Programmer::NotConnected);
  593. Main::action("prog_disconnect")->setEnabled(isProgrammer && idle && pstate!=Programmer::NotConnected);
  594. bool isDebugger = ( Main::programmerGroup().properties() & ::Programmer::Debugger );
  595. bool resetAvailable = ( Main::programmerGroup().properties() & Programmer::CanReleaseReset );
  596. Main::action("prog_run")->setEnabled(idle && resetAvailable && !isDebugger && pstate!=Programmer::Running);
  597. Main::action("prog_stop")->setEnabled(idle && !isDebugger && pstate==Programmer::Running);
  598. Main::action("prog_restart")->setEnabled(idle && !isDebugger && pstate==Programmer::Running);
  599. const Programmer::GroupUI *pgui = static_cast<const Programmer::GroupUI *>(Main::programmerGroup().gui());
  600. Main::action("prog_advanced")->setEnabled(idle && pgui->hasAdvancedDialog());
  601. // update debugger status
  602. Debugger::manager->updateDevice();
  603. Main::action("debug_start")->setEnabled(idle && isDebugger && pstate!=Programmer::Running && pstate!=Programmer::Halted);
  604. Main::action("debug_run")->setEnabled(idle && isDebugger && pstate!=Programmer::Running && !Debugger::manager->isStepping() );
  605. Main::action("debug_halt")->setEnabled(idle && isDebugger && (pstate==Programmer::Running || Debugger::manager->isStepping()) );
  606. Main::action("debug_stop")->setEnabled(idle && isDebugger && (pstate==Programmer::Running || pstate==Programmer::Halted));
  607. Main::action("debug_next")->setEnabled(idle && isDebugger && pstate!=Programmer::Running);
  608. Main::action("debug_reset")->setEnabled(idle && isDebugger && (pstate==Programmer::Running || pstate==Programmer::Halted));
  609. Main::action("debug_show_pc")->setEnabled(idle && isDebugger && Debugger::manager->coff()!=0 && Debugger::manager->pc().isInitialized() );
  610. Main::_projectManager->updateGUI();
  611. // caption
  612. TQString caption;
  613. if ( Main::project() ) caption += Main::project()->name();
  614. if ( Main::currentEditor() ) {
  615. if ( Main::project() ) caption += " - ";
  616. caption += Main::currentEditor()->url().filepath();
  617. }
  618. setCaption(TDEApplication::kApplication()->makeStdCaption(caption));
  619. emit stateChanged();
  620. }
  621. void MainWindow::updateToolViewsActions()
  622. {
  623. TQValueList<DockData>::iterator it;
  624. for(it=_docks.begin(); it!=_docks.end(); ++it) (*it).action->setChecked((*it).dock->mayBeHide());
  625. }
  626. void MainWindow::initDockPosition(const DockData &ddata)
  627. {
  628. const DockPosition &pos = ddata.position;
  629. ddata.dock->manualDock(manager()->getDockWidgetFromName(pos.parent), pos.pos, pos.space);
  630. }
  631. void MainWindow::resetDockLayout()
  632. {
  633. TQValueList<DockData>::iterator it;
  634. for (it=_docks.begin(); it!=_docks.end(); ++it) initDockPosition(*it);
  635. }
  636. void MainWindow::toggleToolView(TQWidget *widget)
  637. {
  638. static_cast<KDockWidget *>(widget)->changeHideShowState();
  639. }
  640. void MainWindow::runKfind()
  641. {
  642. if (_kfindProcess) return;
  643. _kfindProcess = new ::Process::StringOutput;
  644. TQString path;
  645. PURL::Url url = Main::projectManager().projectUrl();
  646. if ( !url.isEmpty() ) path = url.path();
  647. _kfindProcess->setup("kfind", path, false);
  648. connect(_kfindProcess, TQT_SIGNAL(done(int)), TQT_SLOT(kfindDone()));
  649. if ( !_kfindProcess->start(0) )
  650. MessageBox::sorry(i18n("Could not run \"kfind\""), Log::Show);
  651. }
  652. void MainWindow::kfindDone()
  653. {
  654. delete _kfindProcess;
  655. _kfindProcess = 0;
  656. }
  657. void MainWindow::runPikloops()
  658. {
  659. if (_pikloopsProcess) return;
  660. _pikloopsProcess = new ::Process::StringOutput;
  661. _pikloopsProcess->setup("pikloops", TQStringList(), false);
  662. connect(_pikloopsProcess, TQT_SIGNAL(done(int)), TQT_SLOT(pikloopsDone()));
  663. if ( !_pikloopsProcess->start(0) )
  664. MessageBox::detailedSorry(i18n("Could not run \"pikloops\""), i18n("The Pikloops utility (%1) is not installed in your system.").arg("http://pikloops.sourceforge.net"), Log::Show);
  665. }
  666. void MainWindow::pikloopsDone()
  667. {
  668. delete _pikloopsProcess;
  669. _pikloopsProcess = 0;
  670. }
  671. //-----------------------------------------------------------------------------
  672. void MainWindow::compileFile()
  673. {
  674. Editor *e = Main::currentEditor();
  675. if ( e && e->isModified() ) e->save(); // buffer is systematically saved
  676. stopOperations();
  677. Main::_compileLog->clear();
  678. PURL::Url url = (e ? e->url() : Main::_projectManager->selectedUrl());
  679. bool generated = (e ? Main::_projectManager->isExternalFile(url) : false);
  680. if ( Main::project()==0 || !generated ) Main::_projectManager->removeExternalFiles();
  681. url = (!generated ? url : Main::_projectManager->projectUrl());
  682. if ( Main::_compileManager->compileFile(Compile::TodoItem(url, generated)) ) Main::setState(Main::Compiling);
  683. else compileFailure();
  684. }
  685. void MainWindow::buildProject()
  686. {
  687. if ( Main::project()==0 ) {
  688. compileFile();
  689. return;
  690. }
  691. // save modified buffers
  692. PURL::UrlList files = Main::project()->absoluteFiles();
  693. PURL::UrlList::const_iterator it;
  694. for (it=files.begin(); it!=files.end(); ++it) {
  695. // save modified editors
  696. Editor *e = Main::_editorManager->findEditor(*it);
  697. if ( e && e->isModified() ) e->save();
  698. }
  699. bool tmp = _forceProgramAfterBuild;
  700. stopOperations();
  701. _forceProgramAfterBuild = tmp;
  702. Main::_compileLog->clear();
  703. Main::_projectManager->removeExternalFiles();
  704. Compile::LinkType ltype = (Main::programmerGroup().name()=="icd2_debugger" ? Compile::Icd2Linking : Compile::NormalLinking);
  705. if ( Main::_compileManager->buildProject(ltype) ) Main::setState(Main::Compiling);
  706. else compileFailure();
  707. }
  708. void MainWindow::compileFailure()
  709. {
  710. _forceProgramAfterBuild = false;
  711. Main::setState(Main::Idle);
  712. }
  713. void MainWindow::compileSuccess()
  714. {
  715. if ( !Main::_compileManager->compileOnly() ) {
  716. Main::_projectManager->setModified(false);
  717. if ( Main::project()->outputType()==Tool::OutputType::Executable ) {
  718. if ( Debugger::manager->init() ) {
  719. const TQStringList &included = Debugger::manager->coff()->filenames();
  720. TQStringList::const_iterator it;
  721. for (it=included.begin(); it!=included.end(); ++it) {
  722. PURL::Directory dir = (Main::project() ? Main::project()->directory() : Main::projectManager().projectUrl().directory());
  723. PURL::Url url = PURL::Url::fromPathOrUrl(*it).toAbsolute(dir);
  724. if ( !url.exists() ) continue;
  725. Main::_projectManager->addExternalFile(url, ProjectManager::Included);
  726. }
  727. }
  728. if ( _forceProgramAfterBuild || readConfigEntry(BaseGlobalConfig::ProgramAfterBuild).toBool() ) program();
  729. }
  730. }
  731. _forceProgramAfterBuild = false;
  732. Main::setState(Main::Idle);
  733. }
  734. void MainWindow::updateFile(const Compile::FileData &fdata)
  735. {
  736. if ( fdata.actions & Compile::InProject ) {
  737. if ( fdata.actions & Compile::Generated ) Main::_projectManager->addExternalFile(fdata.url, ProjectManager::Generated);
  738. else if ( fdata.actions & Compile::Included ) Main::_projectManager->addExternalFile(fdata.url, ProjectManager::Included);
  739. else Q_ASSERT(false);
  740. }
  741. if ( fdata.actions & Compile::Show ) {
  742. Editor *e = Main::_editorManager->openEditor(fdata.url);
  743. if (e) e->setReadOnly(true);
  744. }
  745. }
  746. void MainWindow::cleanBuild()
  747. {
  748. stopOperations();
  749. Main::_compileLog->clear();
  750. if ( Main::project() ) {
  751. Compile::LinkType ltype = (Main::programmerGroup().name()=="icd2_debugger" ? Compile::Icd2Linking : Compile::NormalLinking);
  752. Main::_compileManager->cleanProject(ltype);
  753. } else {
  754. PURL::FileType type;
  755. PURL::Url url = Main::_projectManager->standaloneGenerator(Main::currentEditor()->url(), type);
  756. Main::_compileManager->cleanFile(url);
  757. }
  758. Main::_projectManager->removeExternalFiles();
  759. }
  760. void MainWindow::stopBuild()
  761. {
  762. Main::_compileManager->kill();
  763. }
  764. //-----------------------------------------------------------------------------
  765. void MainWindow::keyPressEvent(TQKeyEvent *e)
  766. {
  767. if ( e->key()==Key_Escape ) stopOperations();
  768. }
  769. bool MainWindow::stopOperations()
  770. {
  771. if ( Main::_state==Main::Programming ) {
  772. _programLog->log(Log::LineType::Warning, i18n("Programming in progress. Cannot be aborted."));
  773. return false;
  774. }
  775. stopBuild();
  776. Programmer::manager->stop();
  777. Debugger::manager->clear();
  778. return true;
  779. }
  780. void MainWindow::newProject()
  781. {
  782. stopOperations();
  783. Main::_projectManager->newProject();
  784. updateGUI();
  785. Main::_compileLog->clear();
  786. }
  787. void MainWindow::openProject()
  788. {
  789. stopOperations();
  790. Main::_projectManager->openProject();
  791. updateGUI();
  792. Main::_compileLog->clear();
  793. }
  794. void MainWindow::openRecentProject(const KURL &url)
  795. {
  796. stopOperations();
  797. Main::_projectManager->openProject(PURL::Url(url));
  798. updateGUI();
  799. Main::_compileLog->clear();
  800. }
  801. void MainWindow::configureProject()
  802. {
  803. stopOperations();
  804. if ( Main::project()==0 ) configure(ConfigCenter::Standalone);
  805. else Main::_projectManager->editProject();
  806. updateGUI();
  807. }
  808. void MainWindow::closeProject()
  809. {
  810. stopOperations();
  811. Main::_projectManager->closeProject();
  812. updateGUI();
  813. Main::_compileLog->clear();
  814. }
  815. //----------------------------------------------------------------------------
  816. HexEditor *MainWindow::getHexEditor()
  817. {
  818. if ( Main::_projectManager->isModified() || Main::_projectManager->needsRecompile() ) {
  819. MessageBox::Result res = MessageBox::Yes;
  820. if ( !readConfigEntry(BaseGlobalConfig::AutoRebuildModified).toBool() ) {
  821. res = MessageBox::questionYesNoCancel(i18n("The project hex file may not be up-to-date since some project files have been modified."),
  822. i18n("Recompile First"), i18n("Continue Anyway"));
  823. if ( res==MessageBox::Cancel ) return 0;
  824. }
  825. if ( res==MessageBox::Yes ) {
  826. _forceProgramAfterBuild = true;
  827. buildProject();
  828. return 0;
  829. }
  830. }
  831. if ( Main::currentEditor() && Main::currentEditor()->fileType()==PURL::Hex )
  832. return static_cast<HexEditor *>(Main::currentEditor());
  833. PURL::Url purl = Main::_projectManager->projectUrl();
  834. HexEditor *editor = static_cast<HexEditor *>(Main::_editorManager->openEditor(purl.toFileType(PURL::Hex)));
  835. if ( editor==0 ) return 0;
  836. editor->setReadOnly(true);
  837. return editor;
  838. }
  839. void MainWindow::erase()
  840. {
  841. Programmer::manager->erase(Device::MemoryRange());
  842. }
  843. void MainWindow::blankCheck()
  844. {
  845. Programmer::manager->blankCheck(Device::MemoryRange());
  846. }
  847. void MainWindow::program()
  848. {
  849. HexEditor *editor = getHexEditor();
  850. if ( editor==0 ) return;
  851. if ( Main::programmerGroup().isDebugger() && !Main::_projectManager->contains(editor->url()) ) {
  852. MessageBox::sorry(i18n("It is not possible to start a debugging session with an hex file not generated with the current project."), Log::Show);
  853. return;
  854. }
  855. Programmer::manager->program(*editor->memory(), Device::MemoryRange());
  856. }
  857. void MainWindow::verify()
  858. {
  859. HexEditor *editor = getHexEditor();
  860. if ( editor==0 ) return;
  861. Programmer::manager->verify(*editor->memory(), Device::MemoryRange());
  862. }
  863. void MainWindow::read()
  864. {
  865. TQString s = i18n("Read");
  866. Editor *e = Main::_editorManager->findEditor(s);
  867. if (e) Main::_editorManager->closeEditor(e, true);
  868. HexEditor *editor = new HexEditor(s, Main::_editorManager);
  869. editor->setDevice();
  870. if ( Programmer::manager->read(*editor->memory(), Device::MemoryRange()) ) {
  871. editor->memoryRead();
  872. Main::_editorManager->addEditor(editor);
  873. } else delete editor;
  874. }
  875. void MainWindow::showProgress(bool show)
  876. {
  877. if (show) {
  878. PBusyCursor::start();
  879. _actionStatus->show();
  880. _actionProgress->show();
  881. } else {
  882. PBusyCursor::stop();
  883. _actionStatus->hide();
  884. _actionProgress->hide();
  885. }
  886. }
  887. void MainWindow::setTotalProgress(uint nb)
  888. {
  889. //TDEIO::Job *job = new TDEIO::SimpleJob(KURL(), 0, 0, false);
  890. //int id = Observer::self()->newJob(job, true);
  891. //Observer::self()->slotTotalSize(job, total);
  892. //Observer::self()->slotInfoMessage(job, "test");
  893. //tqDebug("set total steps: %i", total);
  894. _actionProgress->setTotalSteps(nb);
  895. _actionProgress->setProgress(0);
  896. TQApplication::eventLoop()->processEvents(TQEventLoop::ExcludeUserInput); // #### DANGER !!!!
  897. }
  898. void MainWindow::setProgress(uint nb)
  899. {
  900. _actionProgress->setProgress(nb);
  901. TQApplication::eventLoop()->processEvents(TQEventLoop::ExcludeUserInput); // #### DANGER !!!!
  902. }