srcfilewin.cpp 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2004-2007 Kevin Kofler
  4. Copyright (C) 2006 Joey Adams
  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, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include "srcfilewin.h"
  18. #include <QVariant>
  19. #include <QImage>
  20. #include <QPixmap>
  21. #include <QString>
  22. #include <QRegExp>
  23. #include <QApplication>
  24. #include <QLabel>
  25. #include <QStatusBar>
  26. #include <QTimer>
  27. #include <QDateTime>
  28. #include <Q3DragObject>
  29. #include <QDir>
  30. #include <QClipboard>
  31. #include <QShortcut>
  32. #include <QEventLoop>
  33. #include <QLayout>
  34. #include <QToolButton>
  35. #include <Q3ListBox>
  36. #include <QKeyEvent>
  37. #include <QResizeEvent>
  38. #include <Q3PopupMenu>
  39. #include <QEvent>
  40. #include <QCloseEvent>
  41. #include <QTextCodec>
  42. #include <QAssistantClient>
  43. #include <kparts/factory.h>
  44. #include <klibloader.h>
  45. #include <ktexteditor/editor.h>
  46. #include <ktexteditor/document.h>
  47. #include <ktexteditor/view.h>
  48. #include <ktexteditor/cursor.h>
  49. #include <ktexteditor/range.h>
  50. #include <ktexteditor/highlightinginterface.h>
  51. #include <ktexteditor/configinterface.h>
  52. #include <kconfig.h>
  53. #include <ktexteditor/configpage.h>
  54. #include <kfiledialog.h>
  55. #include <kurl.h>
  56. #include <kmessagebox.h>
  57. #include <kdirwatch.h>
  58. #include <kfinddialog.h>
  59. #include <kfind.h>
  60. #include <kreplacedialog.h>
  61. #include <kreplace.h>
  62. #include <kicontheme.h>
  63. #include <kicon.h>
  64. #include <kiconloader.h>
  65. #include <kpushbutton.h>
  66. #include <kstandardaction.h>
  67. #include <cstdio>
  68. #include <cstdlib>
  69. #include "ktigcc.h"
  70. #include "mainform.h"
  71. #include "tpr.h"
  72. #include "preferences.h"
  73. #include "projectoptions.h"
  74. #include "srcfile.h"
  75. #include "functions.h"
  76. #include "completion.h"
  77. #if defined(Q_WS_X11)
  78. #include <kwindowsystem.h>
  79. #define ACTIVATE_WINDOW(winid) KWindowSystem::activateWindow(winid)
  80. #elif defined(Q_WS_WIN)
  81. #include <windows.h>
  82. #define ACTIVATE_WINDOW(winid) SetForegroundWindow(winid)
  83. #else
  84. #define ACTIVATE_WINDOW(winid) ((void)0)
  85. #endif
  86. using std::puts;
  87. using std::exit;
  88. #define TIGCC_TPR_Filter "*.tpr|TIGCC Projects (*.tpr)\n"
  89. #define TIGCC_H_Filter "*.h|Header Files (*.h)\n"
  90. #define TIGCC_C_Filter "*.c|C Files (*.c)\n"
  91. #define TIGCC_S_Filter "*.s|GNU Assembly Files (*.s)\n"
  92. #define TIGCC_ASM_Filter "*.asm|A68k Assembly Files (*.asm)\n"
  93. #define TIGCC_QLL_Filter "*.qll|Quill Files (*.qll)\n"
  94. #define TIGCC_O_Filter "*.o|Object Files (*.o)\n"
  95. #define TIGCC_A_Filter "*.a|Archive Files (*.a)\n"
  96. #define TIGCC_TXT_Filter "*.txt|Text Files (*.txt)\n"
  97. #define TIGCCAllFilter "*|All Files (*)"
  98. enum {TIGCCOpenProjectFileFilter,TIGCCAddFilesFilter};
  99. #define THIS (static_cast<SourceFile *>(this))
  100. #define CURRENT_VIEW (THIS->kateView)
  101. #define HL_MODE ((THIS->hlEnabled && *(THIS->hlEnabled))?THIS->hlMode:"None")
  102. // For some reason, this flag is not in the public ConfigFlags enum.
  103. #define CF_REMOVE_TRAILING_DYN 0x4000000
  104. class KReplaceWithSelectionS : public KReplace {
  105. public:
  106. KReplaceWithSelectionS(const QString &pattern, const QString &replacement,
  107. long options, QWidget *parent=0) :
  108. KReplace(pattern,replacement,options,parent), m_haveSelection(FALSE) {}
  109. void setSelection(int selStartLine, int selStartCol,
  110. int selEndLine, int selEndCol)
  111. {
  112. m_haveSelection=TRUE;
  113. m_selStartLine=selStartLine;
  114. m_selStartCol=selStartCol;
  115. m_selEndLine=selEndLine;
  116. m_selEndCol=selEndCol;
  117. }
  118. void setSelection(const KTextEditor::Range &selRange)
  119. {
  120. m_haveSelection=TRUE;
  121. selRange.start().position(m_selStartLine,m_selStartCol);
  122. selRange.end().position(m_selEndLine,m_selEndCol);
  123. }
  124. int replaceCurrentLine;
  125. void invalidateSelection() {m_haveSelection=FALSE;}
  126. bool haveSelection() {return m_haveSelection;}
  127. int selStartLine() {return m_selStartLine;}
  128. int selStartCol() {return m_selStartCol;}
  129. int selEndLine() {return m_selEndLine;}
  130. int selEndCol() {return m_selEndCol;}
  131. // Override to ask for restarting when replacing in a selection.
  132. bool shouldRestart(bool forceAsking=FALSE, bool showNumMatches=TRUE)
  133. {
  134. return KReplace::shouldRestart(forceAsking||m_haveSelection,showNumMatches);
  135. }
  136. protected:
  137. virtual bool validateMatch(const QString &text, int index, int matchedlength)
  138. {
  139. if (!KReplace::validateMatch(text,index,matchedlength)) return FALSE;
  140. if (!m_haveSelection) return TRUE;
  141. if (replaceCurrentLine==m_selStartLine && replaceCurrentLine==m_selEndLine)
  142. return (index>=m_selStartCol)&&(index+matchedlength<=m_selEndCol);
  143. else if (replaceCurrentLine==m_selStartLine)
  144. return (index>=m_selStartCol);
  145. else if (replaceCurrentLine==m_selEndLine)
  146. return (index+matchedlength<=m_selEndCol);
  147. else
  148. return (replaceCurrentLine>=m_selStartLine&&replaceCurrentLine<=m_selEndLine);
  149. }
  150. private:
  151. bool m_haveSelection;
  152. int m_selStartLine, m_selStartCol, m_selEndLine, m_selEndCol;
  153. };
  154. void SourceFileWindow::initBase()
  155. {
  156. QPixmap smallIcon(":/images/ktigcc.png");
  157. QPixmap largeIcon(":/images/icon.png");
  158. QIcon windowIcon(smallIcon);
  159. windowIcon.addPixmap(largeIcon);
  160. setWindowIcon(windowIcon);
  161. #ifdef Q_WS_X11
  162. KWindowSystem::setIcons(winId(),largeIcon,smallIcon);
  163. #endif
  164. sourceFiles.append(THIS);
  165. THIS->dirWatch=new KDirWatch(this);
  166. setCaption(caption()+" - "+THIS->fileName);
  167. THIS->te_popup = new Q3PopupMenu(this);
  168. THIS->te_popup->insertItem("&Open file at cursor",0);
  169. THIS->te_popup->insertItem("&Find symbol declaration",1);
  170. THIS->te_popup->insertSeparator();
  171. THIS->te_popup->insertItem("&Undo",2);
  172. THIS->te_popup->insertItem("&Redo",3);
  173. THIS->te_popup->insertSeparator();
  174. THIS->te_popup->insertItem("&Clear",4);
  175. THIS->te_popup->insertItem("Cu&t",5);
  176. THIS->te_popup->insertItem("Cop&y",6);
  177. THIS->te_popup->insertItem("&Paste",7);
  178. THIS->te_popup->insertSeparator();
  179. THIS->te_popup->insertItem("&Select all",8);
  180. THIS->te_popup->insertSeparator();
  181. THIS->te_popup->insertItem("&Increase indent",9);
  182. THIS->te_popup->insertItem("&Decrease indent",10);
  183. connect(THIS->te_popup,SIGNAL(aboutToShow()),this,SLOT(te_popup_aboutToShow()));
  184. connect(THIS->te_popup,SIGNAL(activated(int)),this,SLOT(te_popup_activated(int)));
  185. THIS->kfinddialog = static_cast<KFindDialog *>(NULL);
  186. THIS->kreplace = static_cast<KReplaceWithSelectionS *>(NULL);
  187. THIS->kateView=static_cast<KTextEditor::View *>(NULL);
  188. THIS->kateView=reinterpret_cast<KTextEditor::View *>(createView(THIS->fileName,HL_MODE,
  189. THIS->isASMFile?preferences.tabWidthAsm:THIS->isCFile?preferences.tabWidthC:8));
  190. int rightStatusSize=size().width();
  191. int line, col;
  192. CURRENT_VIEW->cursorPosition().position(line,col);
  193. THIS->rowStatusLabel=new QLabel(QString("%1").arg(line+1),this);
  194. THIS->rowStatusLabel->setAlignment(Qt::AlignRight);
  195. THIS->rowStatusLabel->setMaximumWidth(30);
  196. statusBar()->addWidget(THIS->rowStatusLabel,1);
  197. THIS->colStatusLabel=new QLabel(QString("%1").arg(col+1),this);
  198. THIS->colStatusLabel->setAlignment(Qt::AlignRight);
  199. THIS->colStatusLabel->setMaximumWidth(30);
  200. statusBar()->addWidget(THIS->colStatusLabel,1);
  201. THIS->charsStatusLabel=new QLabel(QString("%1 Characters").arg(CURRENT_VIEW->document()->text().length()),this);
  202. THIS->charsStatusLabel->setMaximumWidth(100);
  203. statusBar()->addWidget(THIS->charsStatusLabel,1);
  204. THIS->rightStatusLabel=new QLabel(THIS->fileName,this);
  205. THIS->rightStatusLabel->setMaximumWidth(rightStatusSize-160>0?rightStatusSize-160:0);
  206. statusBar()->addWidget(THIS->rightStatusLabel,1);
  207. statusBar()->setSizeGripEnabled(FALSE);
  208. connect(statusBar(),SIGNAL(messageChanged(const QString &)),this,SLOT(statusBar_messageChanged(const QString &)));
  209. connect(THIS->dirWatch,SIGNAL(created(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
  210. connect(THIS->dirWatch,SIGNAL(dirty(const QString &)),this,SLOT(KDirWatch_dirty(const QString &)));
  211. THIS->dirWatch->addFile(THIS->fileName);
  212. THIS->dirWatch->startScan();
  213. connect(clipboard,SIGNAL(dataChanged()),this,SLOT(clipboard_dataChanged()));
  214. centralWidget()->layout()->add(CURRENT_VIEW);
  215. CURRENT_VIEW->show();
  216. editUndoAction->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  217. editRedoAction->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  218. editClearAction->setEnabled(CURRENT_VIEW->selection());
  219. editCutAction->setEnabled(CURRENT_VIEW->selection());
  220. editCopyAction->setEnabled(CURRENT_VIEW->selection());
  221. editPasteAction->setEnabled(!clipboard->text().isNull());
  222. THIS->shortcuts[0]=new QShortcut(Qt::ALT+Qt::Key_Backspace,this);
  223. THIS->shortcuts[1]=new QShortcut(Qt::SHIFT+Qt::ALT+Qt::Key_Backspace,this);
  224. THIS->shortcuts[2]=new QShortcut(Qt::SHIFT+Qt::Key_Delete,this);
  225. THIS->shortcuts[3]=new QShortcut(Qt::CTRL+Qt::Key_Insert,this);
  226. THIS->shortcuts[4]=new QShortcut(Qt::SHIFT+Qt::Key_Insert,this);
  227. THIS->shortcuts[5]=new QShortcut(Qt::Key_F1,this);
  228. THIS->shortcuts[6]=new QShortcut(Qt::Key_Enter,this);
  229. THIS->shortcuts[7]=new QShortcut(Qt::Key_Return,this);
  230. THIS->shortcuts[8]=new QShortcut(Qt::CTRL+Qt::Key_J,this);
  231. THIS->shortcuts[9]=new QShortcut(Qt::CTRL+Qt::Key_Space,this);
  232. THIS->shortcuts[10]=new QShortcut(Qt::CTRL+Qt::Key_M,this);
  233. THIS->shortcuts[0]->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  234. THIS->shortcuts[1]->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  235. THIS->shortcuts[2]->setEnabled(CURRENT_VIEW->selection());
  236. THIS->shortcuts[3]->setEnabled(CURRENT_VIEW->selection());
  237. THIS->shortcuts[4]->setEnabled(!clipboard->text().isNull());
  238. THIS->shortcuts[5]->setEnabled(TRUE);
  239. THIS->shortcuts[6]->setEnabled(TRUE);
  240. THIS->shortcuts[7]->setEnabled(TRUE);
  241. THIS->shortcuts[8]->setEnabled(TRUE);
  242. THIS->shortcuts[9]->setEnabled(TRUE);
  243. THIS->shortcuts[10]->setEnabled(TRUE);
  244. connect(THIS->shortcuts[0],SIGNAL(activated()),this,SLOT(shortcut_0_activated()));
  245. connect(THIS->shortcuts[1],SIGNAL(activated()),this,SLOT(shortcut_1_activated()));
  246. connect(THIS->shortcuts[2],SIGNAL(activated()),this,SLOT(shortcut_2_activated()));
  247. connect(THIS->shortcuts[3],SIGNAL(activated()),this,SLOT(shortcut_3_activated()));
  248. connect(THIS->shortcuts[4],SIGNAL(activated()),this,SLOT(shortcut_4_activated()));
  249. connect(THIS->shortcuts[5],SIGNAL(activated()),this,SLOT(shortcut_5_activated()));
  250. connect(THIS->shortcuts[6],SIGNAL(activated()),this,SLOT(shortcut_6_activated()));
  251. connect(THIS->shortcuts[7],SIGNAL(activated()),this,SLOT(shortcut_7_activated()));
  252. connect(THIS->shortcuts[8],SIGNAL(activated()),this,SLOT(shortcut_8_activated()));
  253. connect(THIS->shortcuts[9],SIGNAL(activated()),this,SLOT(shortcut_9_activated()));
  254. connect(THIS->shortcuts[10],SIGNAL(activated()),this,SLOT(shortcut_10_activated()));
  255. if (preferences.useSystemIcons) {
  256. // Set the preferred icon size so system toolbar icons don't get annoying
  257. // padding.
  258. int toolbarIconSize=KIconLoader().currentSize(K3Icon::MainToolbar);
  259. setIconSize(QSize(toolbarIconSize,toolbarIconSize));
  260. fileSaveAction->setIcon(KIcon("document-save"));
  261. fileAddToProjectAction->setIcon(KIcon("edit-add"));
  262. fileCompileAction->setIcon(KIcon("compfile"));
  263. filePrintAction->setIcon(KIcon("document-print"));
  264. filePrintQuicklyAction->setIcon(KIcon("document-print"));
  265. editClearAction->setIcon(KIcon("edit-delete"));
  266. editCutAction->setIcon(KIcon("edit-cut"));
  267. editCopyAction->setIcon(KIcon("edit-copy"));
  268. editPasteAction->setIcon(KIcon("edit-paste"));
  269. findFindAction->setIcon(KIcon("edit-find"));
  270. if (KIconLoader::global()->iconPath("edit-find-replace",K3Icon::Small,TRUE).isEmpty())
  271. findReplaceAction->setIcon(KIcon("file-find"));
  272. else
  273. findReplaceAction->setIcon(KIcon("edit-find-replace"));
  274. editUndoAction->setIcon(KIcon("edit-undo"));
  275. editRedoAction->setIcon(KIcon("edit-redo"));
  276. findFunctionsAction->setIcon(KIcon("view-tree"));
  277. editIncreaseIndentAction->setIcon(KIcon("format-indent-more"));
  278. editDecreaseIndentAction->setIcon(KIcon("format-indent-less"));
  279. }
  280. QToolButton *findFunctionsButton=static_cast<QToolButton *>(toolBar
  281. ->widgetForAction(findFunctionsAction));
  282. THIS->findFunctionsPopup=new Q3PopupMenu(findFunctionsButton);
  283. connect(THIS->findFunctionsPopup,SIGNAL(aboutToShow()),
  284. this,SLOT(findFunctionsPopup_aboutToShow()));
  285. connect(THIS->findFunctionsPopup,SIGNAL(aboutToHide()),
  286. this,SLOT(findFunctionsPopup_aboutToHide()));
  287. connect(THIS->findFunctionsPopup,SIGNAL(activated(int)),
  288. this,SLOT(findFunctionsPopup_activated(int)));
  289. findFunctionsButton->setPopupMode(QToolButton::MenuButtonPopup);
  290. findFunctionsButton->setMenu(THIS->findFunctionsPopup);
  291. if (THIS->isTextFile) findFunctionsAction->setEnabled(FALSE);
  292. }
  293. void SourceFileWindow::destroy()
  294. {
  295. MainForm::deleteErrorsForSrcFile(this);
  296. if (THIS->kreplace) delete THIS->kreplace;
  297. if (THIS->kfinddialog) {
  298. findHistory=THIS->kfinddialog->findHistory();
  299. delete THIS->kfinddialog;
  300. }
  301. for (int i=0; i<11; i++) delete THIS->shortcuts[i];
  302. delete THIS->te_popup;
  303. delete THIS->rowStatusLabel;
  304. delete THIS->colStatusLabel;
  305. delete THIS->charsStatusLabel;
  306. delete THIS->rightStatusLabel;
  307. THIS->dirWatch->removeFile(THIS->fileName);
  308. delete THIS->dirWatch;
  309. if (THIS->kateView) delete THIS->kateView->document();
  310. sourceFiles.remove(THIS);
  311. }
  312. void SourceFileWindow::te_popup_aboutToShow()
  313. {
  314. THIS->te_popup->setItemEnabled(0,findOpenFileAtCursorAction->isEnabled());
  315. THIS->te_popup->setItemEnabled(1,findFindSymbolDeclarationAction->isEnabled());
  316. THIS->te_popup->setItemEnabled(2,editUndoAction->isEnabled());
  317. THIS->te_popup->setItemEnabled(3,editRedoAction->isEnabled());
  318. THIS->te_popup->setItemEnabled(4,editClearAction->isEnabled());
  319. THIS->te_popup->setItemEnabled(5,editCutAction->isEnabled());
  320. THIS->te_popup->setItemEnabled(6,editCopyAction->isEnabled());
  321. THIS->te_popup->setItemEnabled(7,editPasteAction->isEnabled());
  322. THIS->te_popup->setItemEnabled(8,editSelectAllAction->isEnabled());
  323. THIS->te_popup->setItemEnabled(9,editIncreaseIndentAction->isEnabled());
  324. THIS->te_popup->setItemEnabled(10,editDecreaseIndentAction->isEnabled());
  325. }
  326. void SourceFileWindow::te_popup_activated(int index)
  327. {
  328. switch (index) {
  329. case 0: findOpenFileAtCursor(); break;
  330. case 1: findFindSymbolDeclaration(); break;
  331. case 2: editUndo(); break;
  332. case 3: editRedo(); break;
  333. case 4: editClear(); break;
  334. case 5: editCut(); break;
  335. case 6: editCopy(); break;
  336. case 7: editPaste(); break;
  337. case 8: editSelectAll(); break;
  338. case 9: editIncreaseIndent(); break;
  339. case 10: editDecreaseIndent(); break;
  340. default: break;
  341. }
  342. }
  343. void SourceFileWindow::shortcutActivated(int index)
  344. {
  345. if (CURRENT_VIEW && CURRENT_VIEW->hasFocus()) {
  346. switch (index) {
  347. case 0: editUndo(); break;
  348. case 1: editRedo(); break;
  349. case 2: editCut(); break;
  350. case 3: editCopy(); break;
  351. case 4: editPaste(); break;
  352. case 5: // F1 context help
  353. {
  354. int line,col,i;
  355. CURRENT_VIEW->cursorPosition().position(line,col);
  356. QString textLine=CURRENT_VIEW->document()->line(line);
  357. QString wordUnderCursor;
  358. for (i=col-1;i>=0;i--) {
  359. QChar c=textLine[i];
  360. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  361. || c=='_' || c=='$' || c=='#')
  362. wordUnderCursor.prepend(c);
  363. }
  364. int len=textLine.length();
  365. for (i=col;i<len;i++) {
  366. QChar c=textLine[i];
  367. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  368. || c=='_' || c=='$' || c=='#')
  369. wordUnderCursor.append(c);
  370. }
  371. // always open at least the index
  372. force_qt_assistant_page(1);
  373. assistant->openAssistant();
  374. if (wordUnderCursor.isEmpty()) return;
  375. QString docFile=lookup_doc_keyword(wordUnderCursor);
  376. if (docFile.isEmpty()) return;
  377. // wait for Qt Assistant to actually open
  378. while (!assistant->isOpen())
  379. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
  380. assistant->showPage(QString(tigcc_base)+QString("/doc/html/")+docFile);
  381. break;
  382. }
  383. case 6:
  384. case 7:
  385. // keyReturn is not in any interface, but it's a public slot...
  386. CURRENT_VIEW->qt_metacall(QMetaObject::InvokeMetaMethod,
  387. CURRENT_VIEW->metaObject()->indexOfMethod("keyReturn()"),NULL);
  388. current_view_newLineHook();
  389. break;
  390. case 8:
  391. new TemplatePopup(CURRENT_VIEW);
  392. break;
  393. case 9:
  394. case 10:
  395. // Completion only operates on C files.
  396. if (THIS->isCFile) {
  397. // Disable newLineHook.
  398. THIS->shortcuts[6]->setEnabled(FALSE);
  399. THIS->shortcuts[7]->setEnabled(FALSE);
  400. new CompletionPopup(CURRENT_VIEW,THIS->fileName,THIS->mainForm,this);
  401. }
  402. break;
  403. default: break;
  404. }
  405. } else if (index == 6 || index == 7) {
  406. QKeyEvent *keyEvent=new QKeyEvent(QEvent::KeyPress,Qt::Key_Return,'\n',0,"\n");
  407. QApplication::postEvent(focusWidget(),keyEvent);
  408. }
  409. }
  410. void SourceFileWindow::shortcut_0_activated()
  411. {
  412. shortcutActivated(0);
  413. }
  414. void SourceFileWindow::shortcut_1_activated()
  415. {
  416. shortcutActivated(1);
  417. }
  418. void SourceFileWindow::shortcut_2_activated()
  419. {
  420. shortcutActivated(2);
  421. }
  422. void SourceFileWindow::shortcut_3_activated()
  423. {
  424. shortcutActivated(3);
  425. }
  426. void SourceFileWindow::shortcut_4_activated()
  427. {
  428. shortcutActivated(4);
  429. }
  430. void SourceFileWindow::shortcut_5_activated()
  431. {
  432. shortcutActivated(5);
  433. }
  434. void SourceFileWindow::shortcut_6_activated()
  435. {
  436. shortcutActivated(6);
  437. }
  438. void SourceFileWindow::shortcut_7_activated()
  439. {
  440. shortcutActivated(7);
  441. }
  442. void SourceFileWindow::shortcut_8_activated()
  443. {
  444. shortcutActivated(8);
  445. }
  446. void SourceFileWindow::shortcut_9_activated()
  447. {
  448. shortcutActivated(9);
  449. }
  450. void SourceFileWindow::shortcut_10_activated()
  451. {
  452. shortcutActivated(10);
  453. }
  454. void SourceFileWindow::completionPopup_closed()
  455. {
  456. // Restore newLineHook.
  457. THIS->shortcuts[6]->setEnabled(TRUE);
  458. THIS->shortcuts[7]->setEnabled(TRUE);
  459. }
  460. void *SourceFileWindow::createView(const QString &fileName, const QString &hlModeName, unsigned tabWidth)
  461. {
  462. // Create Document object.
  463. KParts::Factory *factory = (KParts::Factory *)
  464. KLibLoader::self()->factory ("katepart");
  465. if (!factory) qFatal("Failed to load KatePart");
  466. KTextEditor::Document *doc = (KTextEditor::Document *)
  467. factory->createPart(0,THIS->mainForm,"KTextEditor::Document");
  468. // Open the file.
  469. doc->setEncoding(preferences.useCalcCharset?"TI-89":QTextCodec::codecForLocale()->name());
  470. doc->openUrl(KUrl(fileName));
  471. // Create View object.
  472. KTextEditor::View *newView = (KTextEditor::View *) doc->createView(centralWidget());
  473. newView->hide();
  474. newView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored,0,0));
  475. // Set highlighting mode.
  476. KTextEditor::HighlightingInterface *hliface
  477. =qobject_cast<KTextEditor::HighlightingInterface*>(newView->document());
  478. hliface->setHighlighting(hlModeName);
  479. // Set options.
  480. KTextEditor::ConfigInterface *configiface
  481. =qobject_cast<KTextEditor::ConfigInterface*>(newView);
  482. configiface->setConfigValue("dynamic-word-wrap",false);
  483. if (preferences.removeTrailingSpaces) {
  484. sendCommand(newView,"set-remove-trailing-space 1");
  485. sendCommand(newView,"set-remove-trailing-space-save 1");
  486. } else {
  487. sendCommand(newView,"set-remove-trailing-space 0");
  488. sendCommand(newView,"set-remove-trailing-space-save 0");
  489. }
  490. setTabWidth(newView,tabWidth);
  491. connect(newView,SIGNAL(cursorPositionChanged(KTextEditor::View*,const KTextEditor::Cursor&)),this,SLOT(current_view_cursorPositionChanged(KTextEditor::View*,const KTextEditor::Cursor&)));
  492. connect(newView,SIGNAL(textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)),
  493. this,SLOT(current_view_textInserted(KTextEditor::View*,const KTextEditor::Cursor&,const QString&)));
  494. connect(newView,SIGNAL(selectionChanged(KTextEditor::View*)),this,SLOT(current_view_selectionChanged(KTextEditor::View*)));
  495. connect(newView->document(),SIGNAL(textChanged(KTextEditor::Document*)),this,SLOT(current_view_textChanged(KTextEditor::Document*)));
  496. connect(newView->document(),SIGNAL(undoChanged()),this,SLOT(current_view_undoChanged()));
  497. newView->setContextMenu(THIS->te_popup);
  498. newView->setCursorPosition(KTextEditor::Cursor(0,0));
  499. return newView;
  500. }
  501. // Returns 1 if the source file should not be closed, 0 if it can be closed.
  502. int SourceFileWindow::savePrompt(void)
  503. {
  504. int result;
  505. if (!CURRENT_VIEW) return 0;
  506. while (CURRENT_VIEW->document()->isModified()) { // "while" in case saving fails!
  507. result=KMessageBox::questionYesNoCancel(this,QString("The file \'%1\' has been modified. Do you want to save the changes?").arg(THIS->fileName),QString::null,KStandardGuiItem::save(),KStandardGuiItem::discard());
  508. if (result==KMessageBox::Yes)
  509. fileSave();
  510. else if (result==KMessageBox::No)
  511. return 0;
  512. else
  513. return 1;
  514. }
  515. return 0;
  516. }
  517. void SourceFileWindow::removeTrailingSpacesFromView(void *view)
  518. {
  519. if (!preferences.removeTrailingSpaces) return;
  520. KTextEditor::View *kateView=reinterpret_cast<KTextEditor::View *>(view);
  521. KTextEditor::Document *doc=kateView->document();
  522. doc->startEditing();
  523. unsigned numLines=doc->lines();
  524. for (unsigned i=0; i<numLines; i++) {
  525. QString line=doc->line(i);
  526. int whitespace=line.find(QRegExp("\\s+$"));
  527. if (whitespace>=0) doc->removeText(KTextEditor::Range(i,whitespace,i,line.length()));
  528. }
  529. doc->endEditing();
  530. }
  531. void SourceFileWindow::fileSave()
  532. {
  533. THIS->dirWatch->removeFile(THIS->fileName);
  534. if (!CURRENT_VIEW->document()->save()) {
  535. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(THIS->fileName));
  536. THIS->dirWatch->addFile(THIS->fileName);
  537. } else {
  538. THIS->dirWatch->addFile(THIS->fileName);
  539. removeTrailingSpacesFromView(CURRENT_VIEW);
  540. CURRENT_VIEW->document()->setModified(FALSE);
  541. }
  542. }
  543. void SourceFileWindow::fileSaveAs()
  544. {
  545. QString saveFileName=MainForm::SGetFileName(KFileDialog::Saving,
  546. (THIS->fileName.endsWith(".h")?TIGCC_H_Filter TIGCCAllFilter:
  547. THIS->fileName.endsWith(".c")?TIGCC_C_Filter TIGCCAllFilter:
  548. THIS->fileName.endsWith(".s")?TIGCC_S_Filter TIGCCAllFilter:
  549. THIS->fileName.endsWith(".asm")?TIGCC_ASM_Filter TIGCCAllFilter:
  550. THIS->fileName.endsWith(".qll")?TIGCC_QLL_Filter TIGCCAllFilter:
  551. THIS->fileName.endsWith(".txt")?TIGCC_TXT_Filter TIGCCAllFilter:
  552. TIGCCAllFilter),"Save Source File",this);
  553. if (saveFileName.isEmpty())
  554. return;
  555. THIS->dirWatch->removeFile(THIS->fileName);
  556. mkdir_multi(saveFileName);
  557. if (!CURRENT_VIEW->document()->saveAs(saveFileName)) {
  558. KMessageBox::error(this,QString("Can't save to \'%1\'").arg(saveFileName));
  559. THIS->dirWatch->addFile(THIS->fileName);
  560. } else {
  561. THIS->fileName=saveFileName;
  562. THIS->dirWatch->addFile(saveFileName);
  563. removeTrailingSpacesFromView(CURRENT_VIEW);
  564. CURRENT_VIEW->document()->setModified(FALSE);
  565. updateRightStatusLabel();
  566. }
  567. }
  568. void SourceFileWindow::fileAddToProject()
  569. {
  570. THIS->mainForm->adoptSourceFile(THIS);
  571. }
  572. void SourceFileWindow::fileCompile()
  573. {
  574. THIS->mainForm->compileSourceFile(THIS);
  575. }
  576. void SourceFileWindow::filePrint()
  577. {
  578. if (CURRENT_VIEW) CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Print))->trigger();
  579. }
  580. void SourceFileWindow::filePrintQuickly()
  581. {
  582. // This still shows the print dialog, but then KDE 3.5 Kate did that too
  583. // despite having 2 nominally different APIs (print and printDialog).
  584. if (CURRENT_VIEW) CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Print))->trigger();
  585. }
  586. void SourceFileWindow::applyPreferences()
  587. {
  588. // Apply the KatePart preferences and treeview icons.
  589. KParts::Factory *factory=(KParts::Factory *)
  590. KLibLoader::self()->factory("katepart");
  591. if (!factory) qFatal("Failed to load KatePart");
  592. KTextEditor::Document *doc=(KTextEditor::Document *)
  593. factory->createPart(0,this,"KTextEditor::Document");
  594. KTextEditor::Editor *editor=doc->editor();
  595. int numConfigPages=editor->configPages();
  596. for (int i=0; i<numConfigPages; i++) {
  597. if (editor->configPageName(i)=="Fonts & Colors") {
  598. KTextEditor::ConfigPage *configPage=editor->configPage(i,this);
  599. configPage->apply();
  600. delete configPage;
  601. break;
  602. }
  603. }
  604. delete doc;
  605. KTextEditor::View *kateView=CURRENT_VIEW;
  606. if (kateView) {
  607. QString fileText=kateView->document()->text();
  608. if (preferences.removeTrailingSpaces) {
  609. sendCommand(kateView,"set-remove-trailing-space 1");
  610. sendCommand(kateView,"set-remove-trailing-space-save 1");
  611. } else {
  612. sendCommand(kateView,"set-remove-trailing-space 0");
  613. sendCommand(kateView,"set-remove-trailing-space-save 0");
  614. }
  615. setTabWidth(kateView,THIS->isASMFile?preferences.tabWidthAsm:
  616. THIS->isCFile?preferences.tabWidthC:8);
  617. // Kate seems really insisting on making it a pain to update syntax highlighting settings.
  618. KTextEditor::HighlightingInterface *hliface
  619. =qobject_cast<KTextEditor::HighlightingInterface*>(kateView->document());
  620. hliface->setHighlighting(HL_MODE);
  621. // Force redrawing to get the tab width right, repaint() is ignored for some reason.
  622. kateView->hide();
  623. kateView->show();
  624. }
  625. // Apply the icon preferences.
  626. if (preferences.useSystemIcons) {
  627. // Set the preferred icon size so system toolbar icons don't get annoying
  628. // padding.
  629. int toolbarIconSize=KIconLoader().currentSize(K3Icon::MainToolbar);
  630. setIconSize(QSize(toolbarIconSize,toolbarIconSize));
  631. fileSaveAction->setIcon(KIcon("document-save"));
  632. fileAddToProjectAction->setIcon(KIcon("edit-add"));
  633. fileCompileAction->setIcon(KIcon("compfile"));
  634. filePrintAction->setIcon(KIcon("document-print"));
  635. filePrintQuicklyAction->setIcon(KIcon("document-print"));
  636. editClearAction->setIcon(KIcon("edit-delete"));
  637. editCutAction->setIcon(KIcon("edit-cut"));
  638. editCopyAction->setIcon(KIcon("edit-copy"));
  639. editPasteAction->setIcon(KIcon("edit-paste"));
  640. findFindAction->setIcon(KIcon("edit-find"));
  641. if (KIconLoader::global()->iconPath("edit-find-replace",K3Icon::Small,TRUE).isEmpty())
  642. findReplaceAction->setIcon(KIcon("file-find"));
  643. else
  644. findReplaceAction->setIcon(KIcon("edit-find-replace"));
  645. editUndoAction->setIcon(KIcon("edit-undo"));
  646. editRedoAction->setIcon(KIcon("edit-redo"));
  647. findFunctionsAction->setIcon(KIcon("view-tree"));
  648. editIncreaseIndentAction->setIcon(KIcon("format-indent-more"));
  649. editDecreaseIndentAction->setIcon(KIcon("format-indent-less"));
  650. } else {
  651. setIconSize(QSize(20,20));
  652. fileSaveAction->setIcon(QIcon(QPixmap(":/images/02.png")));
  653. fileAddToProjectAction->setIcon(QIcon(QPixmap(":/images/08.png")));
  654. fileCompileAction->setIcon(QIcon(QPixmap(":/images/09.png")));
  655. filePrintAction->setIcon(QIcon(QPixmap(":/images/03.png")));
  656. filePrintQuicklyAction->setIcon(QIcon(QPixmap(":/images/03.png")));
  657. editClearAction->setIcon(QIcon(QPixmap(":/images/04.png")));
  658. editCutAction->setIcon(QIcon(QPixmap(":/images/05.png")));
  659. editCopyAction->setIcon(QIcon(QPixmap(":/images/06.png")));
  660. editPasteAction->setIcon(QIcon(QPixmap(":/images/07.png")));
  661. findFindAction->setIcon(QIcon(QPixmap(":/images/13.png")));
  662. findReplaceAction->setIcon(QIcon(QPixmap(":/images/14.png")));
  663. editUndoAction->setIcon(QIcon(QPixmap(":/images/16.png")));
  664. editRedoAction->setIcon(QIcon(QPixmap(":/images/17.png")));
  665. findFunctionsAction->setIcon(QIcon(QPixmap(":/images/18.png")));
  666. editIncreaseIndentAction->setIcon(QIcon(QPixmap(":/images/19.png")));
  667. editDecreaseIndentAction->setIcon(QIcon(QPixmap(":/images/20.png")));
  668. }
  669. }
  670. void SourceFileWindow::editUndo()
  671. {
  672. if (CURRENT_VIEW)
  673. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->trigger();
  674. }
  675. void SourceFileWindow::editRedo()
  676. {
  677. if (CURRENT_VIEW)
  678. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->trigger();
  679. }
  680. void SourceFileWindow::editClear()
  681. {
  682. if (CURRENT_VIEW)
  683. CURRENT_VIEW->removeSelectionText();
  684. }
  685. void SourceFileWindow::editCut()
  686. {
  687. if (CURRENT_VIEW)
  688. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Cut))->trigger();
  689. }
  690. void SourceFileWindow::editCopy()
  691. {
  692. if (CURRENT_VIEW)
  693. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Copy))->trigger();
  694. }
  695. void SourceFileWindow::editPaste()
  696. {
  697. if (CURRENT_VIEW)
  698. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::PasteText))->trigger();
  699. }
  700. void SourceFileWindow::editSelectAll()
  701. {
  702. if (CURRENT_VIEW)
  703. CURRENT_VIEW->action(KStandardAction::name(KStandardAction::SelectAll))->trigger();
  704. }
  705. void SourceFileWindow::editIncreaseIndent()
  706. {
  707. if (CURRENT_VIEW)
  708. CURRENT_VIEW->action("tools_indent")->trigger();
  709. }
  710. void SourceFileWindow::editDecreaseIndent()
  711. {
  712. if (CURRENT_VIEW)
  713. CURRENT_VIEW->action("tools_unindent")->trigger();
  714. }
  715. void SourceFileWindow::findFind()
  716. {
  717. if (THIS->kfinddialog)
  718. ACTIVATE_WINDOW(THIS->kfinddialog->winId());
  719. else {
  720. // Never set hasSelection because finding in selection doesn't really make
  721. // sense with my non-modal find dialog setup.
  722. THIS->kfinddialog=new KFindDialog(this,KFind::FromCursor,findHistory);
  723. THIS->kfinddialog->setModal(false);
  724. connect(THIS->kfinddialog, SIGNAL(okClicked()), this, SLOT(findFind_next()));
  725. connect(THIS->kfinddialog, SIGNAL(cancelClicked()), this, SLOT(findFind_stop()));
  726. THIS->kfinddialog->show();
  727. }
  728. }
  729. void SourceFileWindow::findFind_next()
  730. {
  731. // Use a local KFind object. The search will need to be restarted next time
  732. // this function is called because of the non-modality of the find dialog.
  733. KFind *kfind=new KFind(THIS->kfinddialog->pattern(),THIS->kfinddialog->options(),this,THIS->kfinddialog);
  734. // Initialize.
  735. bool findBackwards=!!(THIS->kfinddialog->options()&KFind::FindBackwards);
  736. int findCurrentCol;
  737. kfind=new KFind(THIS->kfinddialog->pattern(),THIS->kfinddialog->options(),this,THIS->kfinddialog);
  738. kfind->closeFindNextDialog(); // don't use this, a non-modal KFindDialog is used instead
  739. connect(kfind,SIGNAL(highlight(const QString &,int,int)),
  740. this,SLOT(findFind_highlight(const QString &,int,int)));
  741. if (THIS->kfinddialog->options()&KFind::FromCursor) {
  742. if (CURRENT_VIEW->selection()) {
  743. if (findBackwards) {
  744. CURRENT_VIEW->selectionRange().start().position(THIS->findCurrentLine,findCurrentCol);
  745. if ((--findCurrentCol)==-1) {
  746. if (!THIS->findCurrentLine) goto skip_data;
  747. THIS->findCurrentLine--;
  748. }
  749. } else {
  750. CURRENT_VIEW->selectionRange().end().position(THIS->findCurrentLine,findCurrentCol);
  751. }
  752. } else {
  753. CURRENT_VIEW->cursorPosition().position(THIS->findCurrentLine,findCurrentCol);
  754. }
  755. } else {
  756. THIS->findCurrentLine=findBackwards?(CURRENT_VIEW->document()->lines()-1):0;
  757. findCurrentCol=-1;
  758. }
  759. kfind->setData(CURRENT_VIEW->document()->line(THIS->findCurrentLine),findCurrentCol);
  760. skip_data:;
  761. // Now find the next occurrence.
  762. KFind::Result result;
  763. KTextEditor::View *currView=CURRENT_VIEW;
  764. int currNumLines=CURRENT_VIEW->document()->lines();
  765. do {
  766. if (kfind->needData()) {
  767. if (findBackwards?!THIS->findCurrentLine:(THIS->findCurrentLine>=currNumLines)) {
  768. // Try restarting the search.
  769. currNumLines=currView->document()->lines();
  770. THIS->findCurrentLine=findBackwards?currNumLines-1:0;
  771. do {
  772. if (kfind->needData()) {
  773. if (findBackwards?!THIS->findCurrentLine:(THIS->findCurrentLine>=currNumLines))
  774. goto not_found_current;
  775. if (findBackwards) THIS->findCurrentLine--; else THIS->findCurrentLine++;
  776. kfind->setData(currView->document()->line(THIS->findCurrentLine));
  777. }
  778. result=kfind->find();
  779. } while (result==KFind::NoMatch);
  780. break;
  781. not_found_current:
  782. KMessageBox::error(this,QString("Text \'%1\' not found").arg(THIS->kfinddialog->pattern()));
  783. delete kfind;
  784. return;
  785. } else if (findBackwards) THIS->findCurrentLine--; else THIS->findCurrentLine++;
  786. kfind->setData(currView->document()->line(THIS->findCurrentLine));
  787. }
  788. result=kfind->find();
  789. } while (result==KFind::NoMatch);
  790. delete kfind;
  791. }
  792. #define unused_text text __attribute__((unused))
  793. void SourceFileWindow::findFind_highlight(const QString &unused_text, int matchingindex, int matchedlength)
  794. {
  795. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(THIS->findCurrentLine,matchingindex+matchedlength));
  796. CURRENT_VIEW->setSelection(KTextEditor::Range(THIS->findCurrentLine,matchingindex,
  797. THIS->findCurrentLine,matchingindex+matchedlength));
  798. }
  799. void SourceFileWindow::findFind_stop()
  800. {
  801. if (THIS->kfinddialog) {
  802. findHistory=THIS->kfinddialog->findHistory();
  803. THIS->kfinddialog->deleteLater();
  804. }
  805. THIS->kfinddialog=static_cast<KFindDialog *>(NULL);
  806. }
  807. void SourceFileWindow::findReplace()
  808. {
  809. if (THIS->kreplace) {
  810. KDialog *replaceNextDialog=THIS->kreplace->replaceNextDialog();
  811. if (replaceNextDialog)
  812. ACTIVATE_WINDOW(replaceNextDialog->winId());
  813. return;
  814. }
  815. KReplaceDialog kreplacedialog(this,((CURRENT_VIEW&&CURRENT_VIEW->selection()
  816. &&!CURRENT_VIEW->selectionRange().onSingleLine())?
  817. KFind::SelectedText:0)|KFind::FromCursor,
  818. findHistory,replacementHistory,
  819. CURRENT_VIEW&&CURRENT_VIEW->selection());
  820. if (kreplacedialog.exec()!=QDialog::Accepted)
  821. return;
  822. findHistory=kreplacedialog.findHistory();
  823. replacementHistory=kreplacedialog.replacementHistory();
  824. THIS->kreplace=new KReplaceWithSelectionS(kreplacedialog.pattern(),kreplacedialog.replacement(),
  825. kreplacedialog.options(),this);
  826. // Connect signals to code which handles highlighting of found text, and
  827. // on-the-fly replacement.
  828. connect(THIS->kreplace,SIGNAL(highlight(const QString &,int,int)),
  829. this,SLOT(findReplace_highlight(const QString &,int,int)));
  830. // Connect findNext signal - called when pressing the button in the dialog.
  831. connect(THIS->kreplace,SIGNAL(findNext()),this,SLOT(findReplace_next()));
  832. // Connect replace signal - called when doing a replacement.
  833. connect(THIS->kreplace,SIGNAL(replace(const QString &,int,int,int)),
  834. this,SLOT(findReplace_replace(const QString &,int,int,int)));
  835. // Connect dialogClosed signal - called when closing the Replace Next dialog.
  836. connect(THIS->kreplace,SIGNAL(dialogClosed()),this,SLOT(findReplace_stop()));
  837. // Initialize.
  838. bool findBackwards=!!(THIS->kreplace->options()&KFind::FindBackwards);
  839. int replaceCurrentCol;
  840. if (CURRENT_VIEW) {
  841. if (THIS->kreplace->options()&KFind::SelectedText) {
  842. THIS->kreplace->setSelection(CURRENT_VIEW->selectionRange());
  843. if (findBackwards) {
  844. THIS->kreplace->replaceCurrentLine=THIS->kreplace->selEndLine();
  845. replaceCurrentCol=THIS->kreplace->selEndCol();
  846. } else {
  847. THIS->kreplace->replaceCurrentLine=THIS->kreplace->selStartLine();
  848. replaceCurrentCol=THIS->kreplace->selStartCol();
  849. }
  850. THIS->kreplace->setOptions(THIS->kreplace->options()&~KFind::FromCursor);
  851. } else if (THIS->kreplace->options()&KFind::FromCursor) {
  852. if (CURRENT_VIEW->selection()) {
  853. if (findBackwards) {
  854. CURRENT_VIEW->selectionRange().start().position(THIS->kreplace->replaceCurrentLine,
  855. replaceCurrentCol);
  856. if ((--replaceCurrentCol)==-1) {
  857. if (!THIS->kreplace->replaceCurrentLine) goto skip_data;
  858. THIS->kreplace->replaceCurrentLine--;
  859. }
  860. } else {
  861. CURRENT_VIEW->selectionRange().end().position(THIS->kreplace->replaceCurrentLine,
  862. replaceCurrentCol);
  863. }
  864. } else {
  865. CURRENT_VIEW->cursorPosition().position(THIS->kreplace->replaceCurrentLine,replaceCurrentCol);
  866. // Don't prompt for restarting if we actually searched the entire document.
  867. if (findBackwards?(THIS->kreplace->replaceCurrentLine==(CURRENT_VIEW->document()->lines()-1)
  868. && replaceCurrentCol==(CURRENT_VIEW->document()->lineLength(THIS->kreplace->replaceCurrentLine)))
  869. :(!THIS->kreplace->replaceCurrentLine&&!replaceCurrentCol))
  870. THIS->kreplace->setOptions(THIS->kreplace->options()&~KFind::FromCursor);
  871. }
  872. } else {
  873. THIS->kreplace->replaceCurrentLine=findBackwards?(CURRENT_VIEW->document()->lines()-1):0;
  874. replaceCurrentCol=-1;
  875. }
  876. THIS->kreplace->setData(CURRENT_VIEW->document()->line(THIS->kreplace->replaceCurrentLine),replaceCurrentCol);
  877. }
  878. skip_data:
  879. // Now find the next occurrence.
  880. findReplace_next(TRUE);
  881. }
  882. void SourceFileWindow::findReplace_next()
  883. {
  884. findReplace_next(FALSE);
  885. }
  886. void SourceFileWindow::findReplace_next(bool firstTime)
  887. {
  888. bool findBackwards=!!(THIS->kreplace->options()&KFind::FindBackwards);
  889. // Reinitialize.
  890. if (!firstTime) {
  891. int replaceCurrentCol;
  892. // Non-first-time always continues from cursor.
  893. if (CURRENT_VIEW->selection()) {
  894. if (findBackwards) {
  895. CURRENT_VIEW->selectionRange().start().position(THIS->kreplace->replaceCurrentLine,
  896. replaceCurrentCol);
  897. if ((--replaceCurrentCol)==-1) {
  898. if (!THIS->kreplace->replaceCurrentLine) goto skip_data;
  899. THIS->kreplace->replaceCurrentLine--;
  900. }
  901. } else {
  902. CURRENT_VIEW->selectionRange().end().position(THIS->kreplace->replaceCurrentLine,
  903. replaceCurrentCol);
  904. }
  905. } else {
  906. CURRENT_VIEW->cursorPosition().position(THIS->kreplace->replaceCurrentLine,
  907. replaceCurrentCol);
  908. }
  909. THIS->kreplace->setData(CURRENT_VIEW->document()->line(THIS->kreplace->replaceCurrentLine),replaceCurrentCol);
  910. }
  911. skip_data:;
  912. // Now find the next occurrence.
  913. KFind::Result result;
  914. KTextEditor::View *currView=CURRENT_VIEW;
  915. int currNumLines=0;
  916. if (CURRENT_VIEW) currNumLines=CURRENT_VIEW->document()->lines();
  917. do {
  918. if (THIS->kreplace->needData()) {
  919. if (THIS->kreplace->haveSelection()
  920. ?(findBackwards?(THIS->kreplace->replaceCurrentLine<=THIS->kreplace->selStartLine())
  921. :(THIS->kreplace->replaceCurrentLine>=THIS->kreplace->selEndLine()))
  922. :(findBackwards?!THIS->kreplace->replaceCurrentLine:(THIS->kreplace->replaceCurrentLine>=currNumLines))) {
  923. if (THIS->kreplace->shouldRestart()) {
  924. // Drop "From cursor" and "Selected text" options.
  925. THIS->kreplace->setOptions(THIS->kreplace->options()&~(KFind::FromCursor
  926. |KFind::SelectedText));
  927. THIS->kreplace->invalidateSelection();
  928. // Reinitialize.
  929. THIS->kreplace->replaceCurrentLine=findBackwards?(CURRENT_VIEW->document()->lines()-1):0;
  930. THIS->kreplace->setData(CURRENT_VIEW->document()->line(THIS->kreplace->replaceCurrentLine));
  931. // Start again as if it was the first time.
  932. findReplace_next(TRUE);
  933. return;
  934. } else {
  935. findReplace_stop();
  936. return;
  937. }
  938. } else if (findBackwards) THIS->kreplace->replaceCurrentLine--; else THIS->kreplace->replaceCurrentLine++;
  939. THIS->kreplace->setData(currView->document()->line(THIS->kreplace->replaceCurrentLine));
  940. }
  941. result=THIS->kreplace->replace();
  942. } while (result==KFind::NoMatch);
  943. }
  944. void SourceFileWindow::findReplace_highlight(const QString &unused_text, int matchingindex, int matchedlength)
  945. {
  946. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(THIS->kreplace->replaceCurrentLine,matchingindex+matchedlength));
  947. CURRENT_VIEW->setSelection(KTextEditor::Range(THIS->kreplace->replaceCurrentLine,matchingindex,
  948. THIS->kreplace->replaceCurrentLine,matchingindex+matchedlength));
  949. }
  950. void SourceFileWindow::findReplace_replace(const QString &text, int replacementIndex, int replacedLength, int matchedLength)
  951. {
  952. bool update=!!(THIS->kreplace->options()&KReplaceDialog::PromptOnReplace);
  953. bool haveSelection=THIS->kreplace->haveSelection();
  954. // The initializations are redundant, but g++ doesn't understand this, and the
  955. // self-initialization trick doesn't work either (-Wno-init-self is ignored).
  956. int selStartLine=0, selStartCol=0, selEndLine=0, selEndCol=0;
  957. if (haveSelection) {
  958. selStartLine=THIS->kreplace->selStartLine();
  959. selStartCol=THIS->kreplace->selStartCol();
  960. selEndLine=THIS->kreplace->selEndLine();
  961. selEndCol=THIS->kreplace->selEndCol();
  962. }
  963. CURRENT_VIEW->document()->startEditing();
  964. CURRENT_VIEW->document()->insertText(KTextEditor::Cursor(THIS->kreplace->replaceCurrentLine,replacementIndex),
  965. text.mid(replacementIndex,replacedLength));
  966. // We can't put the cursor back now because this breaks editBegin/editEnd.
  967. int line,col;
  968. CURRENT_VIEW->cursorPosition().position(line,col);
  969. bool updateCursor=(line==THIS->kreplace->replaceCurrentLine
  970. && col==replacementIndex+replacedLength);
  971. CURRENT_VIEW->document()->removeText(KTextEditor::Range(THIS->kreplace->replaceCurrentLine,replacementIndex+replacedLength,
  972. THIS->kreplace->replaceCurrentLine,replacementIndex+replacedLength+matchedLength));
  973. CURRENT_VIEW->document()->endEditing();
  974. if (updateCursor)
  975. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(THIS->kreplace->replaceCurrentLine,replacementIndex));
  976. if (update) {
  977. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(THIS->kreplace->replaceCurrentLine,replacementIndex+replacedLength));
  978. CURRENT_VIEW->setSelection(KTextEditor::Range(THIS->kreplace->replaceCurrentLine,replacementIndex,
  979. THIS->kreplace->replaceCurrentLine,replacementIndex+replacedLength));
  980. CURRENT_VIEW->repaint();
  981. }
  982. if (haveSelection) {
  983. // Restore selection, updating coordinates if necessary.
  984. THIS->kreplace->setSelection(selStartLine,selStartCol,selEndLine,
  985. (THIS->kreplace->replaceCurrentLine==selEndLine)
  986. ?(selEndCol+replacedLength-matchedLength)
  987. :selEndCol);
  988. }
  989. }
  990. void SourceFileWindow::findReplace_stop()
  991. {
  992. if (THIS->kreplace) THIS->kreplace->deleteLater();
  993. THIS->kreplace=static_cast<KReplaceWithSelectionS *>(NULL);
  994. }
  995. void SourceFileWindow::findFunctions()
  996. {
  997. THIS->functionDialog=new FunctionDialog(this);
  998. connect(THIS->functionDialog->functionListBox,SIGNAL(highlighted(int)),
  999. this,SLOT(findFunctions_functionListBox_highlighted(int)));
  1000. connect(THIS->functionDialog->functionListBox,SIGNAL(selected(int)),
  1001. this,SLOT(findFunctions_functionListBox_selected(int)));
  1002. connect(THIS->functionDialog->prototypeButton,SIGNAL(clicked()),
  1003. this,SLOT(findFunctions_prototypeButton_clicked()));
  1004. connect(THIS->functionDialog->implementationButton,SIGNAL(clicked()),
  1005. this,SLOT(findFunctions_implementationButton_clicked()));
  1006. THIS->functionDialog->functionListBox->clear();
  1007. THIS->sourceFileFunctions=getFunctions(CURRENT_VIEW->document()->text(),
  1008. THIS->isASMFile);
  1009. for (SourceFileFunctions::Iterator it=THIS->sourceFileFunctions.begin();
  1010. it!=THIS->sourceFileFunctions.end(); ++it)
  1011. THIS->functionDialog->functionListBox->insertItem((*it).name);
  1012. THIS->functionDialog->exec();
  1013. delete THIS->functionDialog;
  1014. }
  1015. void SourceFileWindow::findFunctions_functionListBox_highlighted(int index)
  1016. {
  1017. if (index>=0) {
  1018. THIS->functionDialog->prototypeButton->setEnabled(
  1019. THIS->sourceFileFunctions[index].prototypeLine>=0);
  1020. THIS->functionDialog->implementationButton->setEnabled(
  1021. THIS->sourceFileFunctions[index].implementationLine>=0);
  1022. } else {
  1023. THIS->functionDialog->prototypeButton->setEnabled(FALSE);
  1024. THIS->functionDialog->implementationButton->setEnabled(FALSE);
  1025. }
  1026. }
  1027. void SourceFileWindow::findFunctions_functionListBox_selected(int index)
  1028. {
  1029. if (index>=0) {
  1030. int line=THIS->sourceFileFunctions[index].implementationLine>=0
  1031. ?THIS->sourceFileFunctions[index].implementationLine
  1032. :THIS->sourceFileFunctions[index].prototypeLine;
  1033. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line,0));
  1034. THIS->functionDialog->accept();
  1035. }
  1036. }
  1037. void SourceFileWindow::findFunctions_prototypeButton_clicked()
  1038. {
  1039. int index=THIS->functionDialog->functionListBox->currentItem();
  1040. if (index>=0 && THIS->sourceFileFunctions[index].prototypeLine>=0) {
  1041. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(
  1042. THIS->sourceFileFunctions[index].prototypeLine,0));
  1043. THIS->functionDialog->accept();
  1044. }
  1045. }
  1046. void SourceFileWindow::findFunctions_implementationButton_clicked()
  1047. {
  1048. int index=THIS->functionDialog->functionListBox->currentItem();
  1049. if (index>=0 && THIS->sourceFileFunctions[index].implementationLine>=0) {
  1050. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(
  1051. THIS->sourceFileFunctions[index].implementationLine,0));
  1052. THIS->functionDialog->accept();
  1053. }
  1054. }
  1055. void SourceFileWindow::findFunctionsPopup_aboutToShow()
  1056. {
  1057. THIS->findFunctionsPopup->clear();
  1058. THIS->sourceFileFunctions=getFunctions(CURRENT_VIEW->document()->text(),
  1059. THIS->isASMFile);
  1060. int idx=0;
  1061. for (SourceFileFunctions::Iterator it=THIS->sourceFileFunctions.begin();
  1062. it!=THIS->sourceFileFunctions.end(); ++it,++idx)
  1063. THIS->findFunctionsPopup->insertItem((*it).name,idx);
  1064. }
  1065. void SourceFileWindow::findFunctionsPopup_aboutToHide()
  1066. {
  1067. QTimer::singleShot(0,this,SLOT(findFunctionsPopup_aboutToHide_async()));
  1068. }
  1069. void SourceFileWindow::findFunctionsPopup_aboutToHide_async()
  1070. {
  1071. THIS->findFunctionsPopup->clear();
  1072. }
  1073. void SourceFileWindow::findFunctionsPopup_activated(int id)
  1074. {
  1075. int line=THIS->sourceFileFunctions[id].implementationLine>=0
  1076. ?THIS->sourceFileFunctions[id].implementationLine
  1077. :THIS->sourceFileFunctions[id].prototypeLine;
  1078. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line,0));
  1079. }
  1080. void SourceFileWindow::findOpenFileAtCursor()
  1081. {
  1082. int line,col,i;
  1083. CURRENT_VIEW->cursorPosition().position(line,col);
  1084. QString textLine=CURRENT_VIEW->document()->line(line);
  1085. int l=textLine.length();
  1086. bool quotesInLine=textLine.contains("\"");
  1087. QString fileName;
  1088. for (i=col;i>=0;i--) {
  1089. QChar c=textLine[i];
  1090. if (!((quotesInLine && c==' ') || (c>='A' && c<='Z') || (c>='a' && c<='z')
  1091. || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
  1092. break;
  1093. fileName.prepend(c);
  1094. }
  1095. for (i=col+1;i<l;i++) {
  1096. QChar c=textLine[i];
  1097. if (!((quotesInLine && c==' ') || (c>='A' && c<='Z') || (c>='a' && c<='z')
  1098. || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
  1099. break;
  1100. fileName.append(c);
  1101. }
  1102. THIS->mainForm->findAndOpenFile(fileName,THIS->category);
  1103. }
  1104. void SourceFileWindow::findFindSymbolDeclaration()
  1105. {
  1106. QString fileText=CURRENT_VIEW->document()->text();
  1107. // "Find symbol declaration" only operates on C files.
  1108. if (THIS->isCFile) {
  1109. QString fileName=THIS->fileName;
  1110. QString symbolFile;
  1111. unsigned symbolLine;
  1112. bool systemHeader;
  1113. int line,col,i;
  1114. CURRENT_VIEW->cursorPosition().position(line,col);
  1115. QString textLine=CURRENT_VIEW->document()->line(line);
  1116. QString wordUnderCursor;
  1117. for (i=col-1;i>=0;i--) {
  1118. QChar c=textLine[i];
  1119. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  1120. || c=='_' || c=='$' || c=='#')
  1121. wordUnderCursor.prepend(c);
  1122. }
  1123. int len=textLine.length();
  1124. for (i=col;i<len;i++) {
  1125. QChar c=textLine[i];
  1126. if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')
  1127. || c=='_' || c=='$' || c=='#')
  1128. wordUnderCursor.append(c);
  1129. }
  1130. if (findSymbolInFile(wordUnderCursor,fileText,fileName,THIS->mainForm,
  1131. symbolFile,symbolLine,systemHeader)
  1132. && !symbolFile.isNull()) {
  1133. if (symbolFile==fileName)
  1134. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(symbolLine,0));
  1135. else {
  1136. THIS->mainForm->openHeader(symbolFile,systemHeader,symbolLine);
  1137. if (!systemHeader)
  1138. ACTIVATE_WINDOW(THIS->mainForm->winId());
  1139. }
  1140. }
  1141. }
  1142. }
  1143. void SourceFileWindow::updateSizes()
  1144. {
  1145. int rightStatusSize=size().width();
  1146. THIS->rowStatusLabel->setMaximumWidth(30);
  1147. THIS->colStatusLabel->setMaximumWidth(30);
  1148. THIS->charsStatusLabel->setMaximumWidth(100);
  1149. THIS->rightStatusLabel->setMaximumWidth(rightStatusSize-160>0?rightStatusSize-160:0);
  1150. }
  1151. void SourceFileWindow::resizeEvent(QResizeEvent *event)
  1152. {
  1153. QMainWindow::resizeEvent(event);
  1154. if (event->size()==event->oldSize()) return;
  1155. updateSizes();
  1156. }
  1157. void SourceFileWindow::statusBar_messageChanged(const QString & message)
  1158. {
  1159. if (message.isNull())
  1160. // Make sure no labels which should be hidden are shown.
  1161. updateRightStatusLabel();
  1162. }
  1163. void SourceFileWindow::updateRightStatusLabel()
  1164. {
  1165. int rightStatusSize=size().width();
  1166. int line, col;
  1167. CURRENT_VIEW->cursorPosition().position(line,col);
  1168. THIS->rowStatusLabel->setMaximumWidth(30);
  1169. THIS->rowStatusLabel->setText(QString("%1").arg(line+1));
  1170. THIS->colStatusLabel->setMaximumWidth(30);
  1171. THIS->colStatusLabel->setText(QString("%1").arg(col+1));
  1172. THIS->charsStatusLabel->setMaximumWidth(100);
  1173. THIS->charsStatusLabel->setText(QString("%1 Characters").arg(CURRENT_VIEW->document()->text().length()));
  1174. THIS->rightStatusLabel->setMaximumWidth(rightStatusSize-160>0?rightStatusSize-160:0);
  1175. THIS->rightStatusLabel->setText(THIS->fileName);
  1176. }
  1177. void SourceFileWindow::current_view_cursorPositionChanged(KTextEditor::View *view, const KTextEditor::Cursor &newPosition)
  1178. {
  1179. if (CURRENT_VIEW==view && !disableViewEvents) {
  1180. int line, col;
  1181. newPosition.position(line,col);
  1182. THIS->rowStatusLabel->setText(QString("%1").arg(line+1));
  1183. THIS->colStatusLabel->setText(QString("%1").arg(col+1));
  1184. }
  1185. }
  1186. void SourceFileWindow::current_view_textChanged(KTextEditor::Document *document)
  1187. {
  1188. if (disableViewEvents) return;
  1189. if (CURRENT_VIEW && CURRENT_VIEW->document()==document) {
  1190. THIS->charsStatusLabel->setText(QString("%1 Characters").arg(CURRENT_VIEW->document()->text().length()));
  1191. if (projectCompletion.contains(THIS->fileName))
  1192. projectCompletion[THIS->fileName].dirty=TRUE;
  1193. if (preferences.deleteOverwrittenErrors) MainForm::deleteOverwrittenErrorsIn(THIS);
  1194. }
  1195. if (THIS->kreplace) THIS->kreplace->invalidateSelection();
  1196. }
  1197. void SourceFileWindow::current_view_undoChanged()
  1198. {
  1199. if (CURRENT_VIEW && !disableViewEvents) {
  1200. editUndoAction->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  1201. editRedoAction->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  1202. THIS->shortcuts[0]->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Undo))->isEnabled());
  1203. THIS->shortcuts[1]->setEnabled(CURRENT_VIEW->action(KStandardAction::name(KStandardAction::Redo))->isEnabled());
  1204. }
  1205. }
  1206. void SourceFileWindow::current_view_selectionChanged(KTextEditor::View *view)
  1207. {
  1208. if (CURRENT_VIEW==view && !disableViewEvents) {
  1209. editClearAction->setEnabled(view->selection());
  1210. editCutAction->setEnabled(view->selection());
  1211. editCopyAction->setEnabled(view->selection());
  1212. THIS->shortcuts[2]->setEnabled(view->selection());
  1213. THIS->shortcuts[3]->setEnabled(view->selection());
  1214. }
  1215. }
  1216. void SourceFileWindow::current_view_textInserted(KTextEditor::View *view, const KTextEditor::Cursor &position, const QString &text)
  1217. {
  1218. int line,col;
  1219. position.position(line,col);
  1220. if (preferences.autoBlocks && text=="{"
  1221. && col==view->document()->lineLength(line)-1) {
  1222. KTextEditor::Document *doc=view->document();
  1223. // Only for C files.
  1224. if (THIS->isCFile) {
  1225. QString indent=doc->line(line);
  1226. // Only if the line was all whitespace, otherwise wait for Enter to be
  1227. // pressed (prevents annoying the user while typing a string or something).
  1228. if (indent.contains(QRegExp("^\\s*\\{$"))) {
  1229. indent=indent.remove('{');
  1230. QString cursorLine=indent+"\t";
  1231. doc->startEditing();
  1232. doc->insertLine(line+1,cursorLine);
  1233. doc->insertLine(line+2,indent+"}");
  1234. doc->endEditing();
  1235. view->setCursorPosition(KTextEditor::Cursor(line+1,cursorLine.length()));
  1236. }
  1237. }
  1238. }
  1239. // Completion only operates on C files.
  1240. if (text=="(" && THIS->isCFile)
  1241. new ArgHintPopup(view,THIS->fileName,THIS->mainForm);
  1242. }
  1243. void SourceFileWindow::current_view_newLineHook()
  1244. {
  1245. int line,col;
  1246. CURRENT_VIEW->cursorPosition().position(line,col);
  1247. KTextEditor::Document *doc=CURRENT_VIEW->document();
  1248. if (preferences.autoBlocks && line && doc->line(line-1).endsWith("{")) {
  1249. // Only for C files.
  1250. if (THIS->isCFile) {
  1251. QString indent=doc->line(line-1);
  1252. // Remove everything starting from the first non-whitespace character.
  1253. indent=indent.remove(QRegExp("(?!\\s).*$"));
  1254. QString cursorLine=indent+"\t";
  1255. doc->startEditing();
  1256. doc->removeText(KTextEditor::Range(line,0,line,col));
  1257. doc->insertLine(line,cursorLine);
  1258. doc->insertText(KTextEditor::Cursor(line+1,0),indent+"}");
  1259. doc->endEditing();
  1260. CURRENT_VIEW->setCursorPosition(KTextEditor::Cursor(line,cursorLine.length()));
  1261. }
  1262. }
  1263. }
  1264. void SourceFileWindow::clipboard_dataChanged()
  1265. {
  1266. if (CURRENT_VIEW) {
  1267. editPasteAction->setEnabled(!clipboard->text().isNull());
  1268. THIS->shortcuts[4]->setEnabled(!clipboard->text().isNull());
  1269. }
  1270. }
  1271. void SourceFileWindow::closeEvent(QCloseEvent *e)
  1272. {
  1273. if (!fileCloseAction->isEnabled() || savePrompt())
  1274. e->ignore();
  1275. else {
  1276. e->accept();
  1277. deleteLater();
  1278. }
  1279. }
  1280. void SourceFileWindow::KDirWatch_dirty(const QString &fileName)
  1281. {
  1282. if (!fileName.compare(THIS->fileName)) {
  1283. if (KMessageBox::questionYesNo(this,
  1284. QString("The file \'%1\' has been changed by another program. "
  1285. "Do you want to reload it?").arg(fileName),"File Changed")
  1286. ==KMessageBox::Yes) {
  1287. CURRENT_VIEW->document()->setModified(FALSE);
  1288. disableViewEvents=TRUE;
  1289. CURRENT_VIEW->document()->documentReload();
  1290. disableViewEvents=FALSE;
  1291. updateRightStatusLabel();
  1292. }
  1293. }
  1294. }
  1295. /*
  1296. * Constructs a SourceFileWindow as a child of 'parent', with the
  1297. * name 'name' and widget flags set to 'f'.
  1298. *
  1299. */
  1300. SourceFileWindow::SourceFileWindow(QWidget* parent, const char* name, Qt::WindowFlags fl)
  1301. : QMainWindow(parent, name, fl)
  1302. {
  1303. setupUi(this);
  1304. (void)statusBar();
  1305. }
  1306. /*
  1307. * Destroys the object and frees any allocated resources
  1308. */
  1309. SourceFileWindow::~SourceFileWindow()
  1310. {
  1311. destroy();
  1312. // no need to delete child widgets, Qt does it all for us
  1313. }
  1314. /*
  1315. * Sets the strings of the subwidgets using the current
  1316. * language.
  1317. */
  1318. void SourceFileWindow::languageChange()
  1319. {
  1320. retranslateUi(this);
  1321. }