ccnotepad.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. #pragma once
  2. #include <QMainWindow>
  3. #include <QLabel>
  4. #include <QToolButton>
  5. #include <QMap>
  6. #include <QCloseEvent>
  7. #include <QActionGroup>
  8. #include <qscilexer.h>
  9. #include <QFileSystemWatcher>
  10. #include <QPointer>
  11. #include <QSharedMemory>
  12. #include <QTranslator>
  13. #include <QTimer>
  14. #include <QSettings>
  15. #include "rcglobal.h"
  16. #include "ui_ccnotepad.h"
  17. #include "common.h"
  18. class ScintillaEditView;
  19. class ScintillaHexEditView;
  20. class FindRecords;
  21. class FindResultWin;
  22. class QAction;
  23. class CompareDirs;
  24. class CompareWin;
  25. struct HexFileMgr;
  26. struct TextFileMgr;
  27. #define uos 1
  28. #ifdef Q_OS_WIN
  29. #undef uos
  30. #endif
  31. #ifdef Q_OS_MAC
  32. #undef uos
  33. #endif
  34. enum OpenAttr {
  35. Text = 1,
  36. HexReadOnly,
  37. BigTextReadOnly,
  38. TextReadOnly
  39. };
  40. //打开模式。1 文本 2 二进制 3 大文本只读 4 文本只读
  41. //const char* Open_Attr = "openid";
  42. class CCNotePad : public QMainWindow
  43. {
  44. Q_OBJECT
  45. public:
  46. CCNotePad(bool isMainWindows = true, QWidget *parent = Q_NULLPTR);
  47. ~CCNotePad();
  48. void setCodeBarLabel(CODE_ID id);
  49. void setLineEndBarLabel(RC_LINE_FORM lineEnd);
  50. void initLexerNameToIndex();
  51. static LangType getLangLexerIdByFileExt(QString filePath);
  52. #if 0
  53. static QFont & getTxtFont()
  54. {
  55. return s_txtFont;
  56. }
  57. static QFont & getProLangFont()
  58. {
  59. return s_proLangFont;
  60. }
  61. #endif
  62. bool openFile(QString filePath);
  63. void initTabNewOne();
  64. void setShareMem(QSharedMemory* v)
  65. {
  66. m_shareMem = v;
  67. }
  68. QSharedMemory* getShareMem()
  69. {
  70. return m_shareMem;
  71. }
  72. void receiveEditDrop(QDropEvent* e);
  73. #ifdef Q_OS_WIN
  74. int runAsAdmin(const QString & filePath);
  75. void checkAppFont();
  76. #endif
  77. void syncCurSkinToMenu(int id);
  78. int restoreLastFiles();
  79. signals:
  80. void signSendRegisterKey(QString key);
  81. void signRegisterReplay(int code);
  82. public slots:
  83. void slot_changeChinese();
  84. void slot_changeEnglish();
  85. void slot_actionNewFile_toggle(bool checked);
  86. void slot_actionOpenFile_toggle(bool checked);
  87. void slot_actionSaveFile_toggle(bool checked);
  88. void slot_actionSaveAsFile_toggle(bool checked);
  89. void slot_actionRenameFile_toggle(bool checked);
  90. void slot_actionClose(bool);
  91. void slot_actionCloseNonCurDoc();
  92. void slot_actionCloseLeftAll();
  93. void slot_actionCloseRightAll();
  94. void slot_quit(bool);
  95. void slot_closeAllFile(bool);
  96. void slot_batch_convert();
  97. void slot_batch_rename();
  98. void slot_options();
  99. void slot_donate();
  100. void slot_registerCmd(int cmd, int code);
  101. protected:
  102. void closeEvent(QCloseEvent *event) override;
  103. void dragEnterEvent(QDragEnterEvent* event) override;
  104. void dropEvent(QDropEvent* e) override;
  105. #ifdef Q_OS_WIN
  106. bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
  107. #endif
  108. #ifdef uos
  109. void adjustWInPos(QWidget* pWin);
  110. #endif
  111. private slots:
  112. void slot_editViewMofidyChange();
  113. void slot_tabClose(int index);
  114. void slot_LineNumIndexChange(int line, int index);
  115. void slot_saveAllFile();
  116. void slot_autoSaveFile(bool);
  117. void slot_timerAutoSave();
  118. void slot_tabCurrentChanged(int index);
  119. void slot_copyAvailable(bool select);
  120. void slot_cut();
  121. void slot_copy();
  122. void slot_paste();
  123. void slot_selectAll();
  124. void slot_undo();
  125. void slot_redo();
  126. void slot_zoomin();
  127. void slot_zoomout();
  128. void slot_wordwrap(bool checked);
  129. void slot_allWhite(bool checked);
  130. void slot_indentGuide(bool checked);
  131. void slot_find();
  132. void slot_replace();
  133. void slot_markHighlight();
  134. void slot_clearMark();
  135. void slot_wordHighlight();
  136. void slot_findResultItemDoubleClick(const QModelIndex & index);
  137. void slot_showFindAllInCurDocResult(FindRecords * record);
  138. void slot_showfindAllInOpenDocResult(QVector<FindRecords*>* record, int hits, QString whatFind);
  139. void slot_clearFindResult();
  140. void slot_convertWinLineEnd(bool);
  141. void slot_convertUnixLineEnd(bool);
  142. void slot_convertMacLineEnd(bool);
  143. void slot_openReceneFile();
  144. void slot_gotoline();
  145. void slot_show_spaces(bool check);
  146. void slot_show_line_end(bool check);
  147. void slot_show_all(bool check);
  148. void slot_load_with_gbk();
  149. void slot_load_with_utf8();
  150. void slot_load_with_utf8_bom();
  151. void slot_load_with_utf16_be();
  152. void slot_load_with_utf16_le();
  153. void slot_encode_gbk();
  154. void slot_encode_utf8();
  155. void slot_encode_utf8_bom();
  156. void slot_encode_utf16_be();
  157. void slot_encode_utf16_le();
  158. void slot_lexerActTrig(QAction * action);
  159. void slot_compareFile();
  160. void slot_compareDir();
  161. void slot_binCompare();
  162. void slot_tabBarClicked(int index);
  163. void slot_reOpenTextMode();
  164. void slot_reOpenHexMode();
  165. void slot_selectLeftFile();
  166. void slot_selectRightFile();
  167. void slot_showFileInExplorer();
  168. void slot_openFileInNewWin();
  169. void slot_about();
  170. void slot_fileChange(QString filePath);
  171. void slot_toLightBlueStyle();
  172. void slot_toDefaultStyle();
  173. void slot_toThinBlueStyle();
  174. void slot_toRiceYellow();
  175. void slot_toYellow();
  176. void slot_toSilverStyle();
  177. void slot_toLavenderBlush();
  178. void slot_toMistyRose();
  179. void slot_register();
  180. void slot_slectionChanged();
  181. void slot_preHexPage();
  182. void slot_nextHexPage();
  183. void slot_gotoHexPage();
  184. void slot_hexGotoFile(qint64 addr);
  185. void slot_tabFormatChange(bool tabLenChange, bool useTabChange);
  186. void slot_searchResultShow();
  187. //void slot_txtFontChange(QFont & font);
  188. //void slot_proLangFontChange(QFont &font);
  189. void slot_saveFile(QString fileName, ScintillaEditView * pEdit);
  190. void slot_skinStyleGroup(QAction * action);
  191. void slot_langFormat();
  192. void slot_viewStyleChange(int lexerId, int styleId, QColor & fgColor, QColor & bkColor, QFont & font, bool fontChange);
  193. void slot_removeHeadBlank();
  194. void slot_removeEndBlank();
  195. void slot_removeHeadEndBlank();
  196. void slot_columnBlockEdit();
  197. private:
  198. void initFindResultDockWin();
  199. void enableEditTextChangeSign(ScintillaEditView * pEdit);
  200. void disEnableEditTextChangeSign(ScintillaEditView * pEdit);
  201. bool saveFile(QString fileName, ScintillaEditView * pEdit, bool isBakWrite=true, bool isStatic=false, bool isClearSwpFile=false);
  202. void updateProAfterSaveNewFile(int curTabIndex, QString fileName, ScintillaEditView * pEdit);
  203. void initToolBar();
  204. void setTxtLexer(ScintillaEditView * pEdit);
  205. void saveReceneOpenFile();
  206. void updateSaveAllToolBarStatus();
  207. void initReceneOpenFileMenu();
  208. int findFileIsOpenAtPad(QString filePath);
  209. void updateCurTabSaveStatus();
  210. void setSaveButtonStatus(bool needSave);
  211. void setSaveAllButtonStatus(bool needSave);
  212. void setDocEolMode(ScintillaEditView * pEdit, RC_LINE_FORM endStatus);
  213. void convertDocLineEnd(RC_LINE_FORM endStatus);
  214. void transDocToEncord(CODE_ID destCode);
  215. void syncCurDocEncodeToMenu(QWidget * curEdit);
  216. void syncCurDocLineEndStatusToMenu(QWidget * curEdit);
  217. void syncCurDocLexerToMenu(QWidget* pEdit);
  218. void cmpSelectFile();
  219. void autoSetDocLexer(ScintillaEditView * pEdit);
  220. void updateTitleToCurDocFilePath();
  221. void addWatchFilePath(QString filePath);
  222. void removeWatchFilePath(QString filePath);
  223. bool checkRoladFile(ScintillaEditView * pEdit);
  224. void reloadEditFile(ScintillaEditView * pEidt);
  225. void initFindWindow();
  226. void setToFileRightMenu();
  227. QString getShortName(const QString& name);
  228. bool reloadTextFileWithCode(CODE_ID code);
  229. bool openBigTextFile(QString filePath);
  230. void setWindowTitleMode(QString filePath, OpenAttr attr);
  231. bool openTextFile(QString filePath, bool isCheckHex = true, CODE_ID code=CODE_ID::UNKOWN);
  232. bool openHexFile(QString filePath);
  233. bool showHexFile(ScintillaHexEditView * pEdit, HexFileMgr * hexFile);
  234. bool showBigTextFile(ScintillaEditView * pEdit, TextFileMgr * hexFile);
  235. void initNotePadSqlOptions();
  236. void saveNotePadSqlOptions();
  237. //void saveDefFont();
  238. void savePadUseTimes();
  239. void saveTempFile(ScintillaEditView * pEdit, int index, QSettings& qs);
  240. void closeFileStatic(int index, QSettings& qs);
  241. void closeAllFileStatic();
  242. void restoreCleanNewFile(QString & fileName);
  243. void restoreCleanExistFile(QString & filePath);
  244. void restoreDirtyNewFile(QString & fileName, QString & tempFilePath);
  245. bool restoreDirtyExistFile(QString & fileName, QString & tempFilePath);
  246. ScintillaEditView* newTxtFile(QString Name, int index, QString contentPath="");
  247. void setLangsDescLable(QString &langDesc);
  248. private:
  249. Ui::CCNotePad ui;
  250. QLabel* m_codeStatusLabel;
  251. QLabel* m_lineEndLabel;
  252. QLabel* m_lineNumLabel;
  253. QLabel* m_langDescLabel;
  254. QToolButton* m_saveFile;
  255. QToolButton* m_saveAllFile;
  256. QToolButton* m_autoSaveAFile;
  257. QToolButton* m_cutFile;
  258. QToolButton* m_copyFile;
  259. QToolButton* m_undo;
  260. QToolButton* m_redo;
  261. QMenu* m_tabRightClickMenu;
  262. QDockWidget* m_dockSelectTreeWin;
  263. FindResultWin* m_pResultWin;
  264. //一个用于查找,一个用于排序
  265. QMap <QString,QAction*> m_receneOpenFile;
  266. QList<QString> m_receneOpenFileList;
  267. QActionGroup *m_pEncodeActGroup;
  268. QActionGroup *m_pLineEndActGroup;
  269. QActionGroup *m_pLexerActGroup;
  270. QAction* m_quitAction;
  271. //关闭时,询问保存文件,用户点击了取消,此时不能走关闭程序
  272. //设置一个标志记录该状态,确定最终是否要退出
  273. bool m_isQuitCancel;
  274. QMap<QString, LexerNode> m_lexerNameToIndex;
  275. //监控文件被修改的对象
  276. QFileSystemWatcher* m_fileWatch;
  277. QString m_cmpLeftFilePath;
  278. QString m_cmpRightFilePath;
  279. QPointer<QMainWindow> m_pFindWin;
  280. QSharedMemory* m_shareMem;
  281. //是否主窗口。可以打开多个,但是只有第一个是主窗口
  282. bool m_isMainWindows;
  283. //最近打开的对比文件和目录列表。做一个环形区
  284. //保存在数据库中
  285. int m_receneDirStartPos;
  286. int m_receneFileStartPos;
  287. QList<QAction*> m_receneDirList;
  288. QList<QAction*> m_receneFileList;
  289. QMap<QString, QAction*> m_receneRecrod;
  290. QAction* m_openInNewWinAct;
  291. QAction* m_showFileDirAct;
  292. QAction* m_openWithText;
  293. QAction* m_openWithHex;
  294. QAction* m_selectLeftCmp;
  295. QAction* m_selectRightCmp;
  296. QToolButton* m_wordwrap;
  297. QToolButton* m_allWhite;
  298. QToolButton* m_indentGuide;
  299. //所有打开的notebook均保存起来。关闭时切换share里面保存的地址
  300. static QList<CCNotePad*> *s_padInstances;
  301. //当前打开的二进制文件,保存在这里
  302. QMap<QString, HexFileMgr*> m_hexFileMgr;
  303. QPointer<QWidget> m_pHexGotoWin;
  304. QToolButton* m_preHexPage;
  305. QToolButton* m_nextHexPage;
  306. QToolButton* m_gotoHexPage;
  307. static QList<QString> s_findHistroy;
  308. static int s_padTimes;
  309. //static QFont s_txtFont;
  310. //static QFont s_proLangFont;
  311. int m_curSoftLangs; //当前语言0:自动 1 中文 2 英语
  312. static int s_autoWarp; //自动换行
  313. static int s_indent; //自动缩进
  314. //QString m_txtFontStr;//从数据库读取的字体字符串
  315. //QString m_proLangFontStr;//从数据库读取的字体字符串
  316. QTranslator* m_translator;
  317. QTimer * m_timerAutoSave;
  318. public:
  319. static QString s_lastOpenDirPath;
  320. static int s_restoreLastFile; //自动恢复上次打开的文件
  321. };