simple_notepad_10.e 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. class SIMPLE_NOTEPAD_10
  2. insert
  3. IUP_INTERFACE
  4. create {ANY}
  5. make
  6. feature {ANY}
  7. ml: IUP_MULTILINE
  8. cfg: IUP_CONFIG
  9. str_find (str, str_to_find, casesensitive: STRING; pos: INTEGER): INTEGER
  10. do
  11. if str.count.is_equal(0) or str_to_find.count.is_equal(0) then
  12. Result := -1
  13. elseif casesensitive.is_equal("OFF") then
  14. str.to_lower
  15. str_to_find.to_lower
  16. end
  17. Result := str.substring_index(str_to_find, pos)
  18. end
  19. read_file (file_name: STRING): STRING
  20. local
  21. tfr: TEXT_FILE_READ
  22. str: STRING
  23. ms: IUP_MESSAGE
  24. do
  25. create str.make_empty
  26. create tfr.connect_to(file_name)
  27. if tfr.is_connected then
  28. from
  29. tfr.read_line
  30. until
  31. tfr.end_of_input
  32. loop
  33. str.append(tfr.last_string)
  34. str.append_character('%N')
  35. tfr.read_line
  36. end
  37. str.append(tfr.last_string)
  38. tfr.disconnect
  39. else
  40. str.append("Fail when reading from file: ")
  41. str.append(file_name)
  42. create ms.message("Error", str)
  43. end
  44. Result := str
  45. end
  46. write_file (file_name, text: STRING): INTEGER
  47. local
  48. tfw: TEXT_FILE_WRITE
  49. ms: IUP_MESSAGE
  50. str: STRING
  51. do
  52. create tfw.connect_to(file_name)
  53. if tfw.is_connected then
  54. tfw.put_string(text)
  55. tfw.disconnect
  56. Result := 1
  57. else
  58. str.make_empty
  59. str.append("Fail when writing to file: ")
  60. str.append(file_name)
  61. create ms.message("Error", str)
  62. Result := 0
  63. end
  64. end
  65. --********************************** Callbacks *****************************************
  66. edit_menu_open_cb (m: IUP_MENU): STRING
  67. local
  68. cb: IUP_CLIPBOARD
  69. item_p, item_c, item_cp, item_del: IUP_MENU_ITEM
  70. do
  71. cb := get_clipboard
  72. item_p ::= m.get_dialog_child("ITEM_PASTE")
  73. item_c ::= m.get_dialog_child("ITEM_CUT")
  74. item_cp ::= m.get_dialog_child("ITEM_COPY")
  75. item_del ::= m.get_dialog_child("ITEM_DELETE")
  76. if cb.is_text_available then
  77. item_p.set_active(True)
  78. else
  79. item_p.set_active(False)
  80. end
  81. if ml.get_selected_text.is_empty then
  82. item_c.set_active(False)
  83. item_cp.set_active(False)
  84. item_del.set_active(False)
  85. else
  86. item_c.set_active(True)
  87. item_cp.set_active(True)
  88. item_del.set_active(True)
  89. end
  90. Result := "IUP_DEFAULT"
  91. end
  92. item_recent_cb (c: IUP_CONFIG): STRING
  93. local
  94. text: STRING
  95. do
  96. text := read_file(c.get_title)
  97. ml.set_value(text)
  98. Result := "IUP_DEFAULT"
  99. end
  100. config_recent_cb (c: IUP_CONFIG): STRING
  101. local
  102. file, text: STRING
  103. do
  104. file := c.get_title
  105. text := read_file(file)
  106. ml.set_value(text)
  107. Result := "IUP_DEFAULT"
  108. end
  109. multitext_caret_cb (m: IUP_TEXT; lin, col, pos: INTEGER): STRING
  110. local
  111. lbl_statusbar: IUP_LABEL
  112. str: STRING
  113. do
  114. if lbl_statusbar ?:= m.get_dialog_child("STATUSBAR") then
  115. lbl_statusbar ::= m.get_dialog_child("STATUSBAR")
  116. str := "Line "
  117. str.append(lin.to_string)
  118. str.append(", Col ")
  119. str.append(col.to_string)
  120. lbl_statusbar.set_title(str)
  121. end
  122. Result := "IUP_DEFAULT"
  123. end
  124. item_open_action_cb (widget: IUP_WIDGET): STRING
  125. local
  126. status: INTEGER
  127. rv, name, text: STRING
  128. fd: IUP_FILE_DIALOG
  129. do
  130. create fd.file_dialog
  131. fd.set_dialog_type("OPEN")
  132. fd.set_ext_filter("Text files|*.txt|All Files|*.*|")
  133. fd.set_title("Select a text file")
  134. rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  135. if rv.is_equal("IUP_NOERROR") then
  136. status := fd.get_status
  137. if status.is_equal(0) then
  138. name := fd.get_value
  139. text := read_file(name)
  140. cfg.update_recent_file_menu(name)
  141. ml.set_value(text)
  142. end
  143. end
  144. fd.destroy
  145. Result := "IUP_DEFAULT"
  146. end
  147. item_saveas_action_cb (widget: IUP_WIDGET): STRING
  148. local
  149. status, r: INTEGER
  150. rv, name, text: STRING
  151. fd: IUP_FILE_DIALOG
  152. do
  153. create fd.file_dialog
  154. fd.set_dialog_type("SAVE")
  155. fd.set_ext_filter("Text files|*.txt|All Files|*.*|")
  156. fd.set_title("Select a text file")
  157. rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  158. if rv.is_equal("IUP_NOERROR") then
  159. status := fd.get_status
  160. if not status.is_equal(-1) then
  161. name := fd.get_value
  162. text := ml.get_value
  163. r := write_file(name, text)
  164. if r.is_equal(1) then
  165. cfg.update_recent_file_menu(name)
  166. end
  167. end
  168. end
  169. fd.destroy
  170. Result := "IUP_DEFAULT"
  171. end
  172. item_font_action_cb (widget: IUP_MENU_ITEM): STRING
  173. local
  174. status: INTEGER
  175. rv, ft, selected: STRING
  176. fd: IUP_FONT_DIALOG
  177. do
  178. create fd.font_dialog
  179. ft := ml.get_font
  180. fd.set_value(ft)
  181. rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  182. if rv.is_equal("IUP_NOERROR") then
  183. status := fd.get_status
  184. if status.is_equal(1) then
  185. selected := fd.get_value
  186. ml.set_font(selected)
  187. cfg.set_variable_string("MainWindow", "Font", selected)
  188. end
  189. end
  190. fd.destroy
  191. Result := "IUP_DEFAULT"
  192. end
  193. item_help_action_cb (widget: IUP_MENU_ITEM): STRING
  194. local
  195. i: INTEGER
  196. do
  197. i := iup_open.help("https://notabug.org/GermanGT/eiffel-iup")
  198. Result := "IUP_DEFAULT"
  199. end
  200. item_about_action_cb (widget: IUP_MENU_ITEM): STRING
  201. local
  202. ms: IUP_MESSAGE
  203. do
  204. create ms.message("About"," Simple Notepad%N%NAutors:%N Gustavo Lyrio%N Antonio Scuri")
  205. Result := "IUP_DEFAULT"
  206. end
  207. item_exit_action_cb (widget: IUP_MENU_ITEM): STRING
  208. local
  209. i: INTEGER
  210. d: IUP_DIALOG
  211. do
  212. d := widget.get_dialog
  213. cfg.save_dialog (d, "MainWindow")
  214. i := cfg.save
  215. cfg.destroy
  216. Result := "IUP_CLOSE"
  217. end
  218. close_dialog_cb (d: IUP_DIALOG): STRING
  219. local
  220. i: INTEGER
  221. do
  222. cfg.save_dialog (d, "MainWindow")
  223. i := cfg.save
  224. cfg.destroy
  225. Result := "IUP_CLOSE"
  226. end
  227. goto_ok_action_cb(widget: IUP_BUTTON): STRING
  228. local
  229. line_count, line: INTEGER
  230. txt: IUP_TEXT
  231. ms: IUP_MESSAGE
  232. do
  233. if txt ?:= widget.get_dialog_child("LINE_TEXT") then
  234. txt ::= widget.get_dialog_child("LINE_TEXT")
  235. line_count := widget.get_attribute_integer("TEXT_LINECOUNT")
  236. line := txt.get_value.to_integer
  237. if line < 1 and line >= line_count then
  238. create ms.message("Error", "Invalid line number.")
  239. Result := "IUP_DEFAULT"
  240. end
  241. widget.get_dialog.set_attribute_integer("STATUS", 1)
  242. Result := "IUP_CLOSE"
  243. end
  244. end
  245. goto_cancel_action_cb(widget: IUP_BUTTON): STRING
  246. do
  247. widget.get_dialog.set_attribute_integer("STATUS", 0)
  248. Result := "IUP_CLOSE"
  249. end
  250. item_goto_action_cb (widget: IUP_WIDGET): STRING
  251. local
  252. dlg, d: IUP_DIALOG
  253. vbox: IUP_VBOX
  254. hbox: IUP_HBOX
  255. bt_ok, bt_cancel: IUP_BUTTON
  256. f: IUP_FILL
  257. lbl: IUP_LABEL
  258. txt: IUP_TEXT
  259. str, s: STRING
  260. line_count, line, pos: INTEGER
  261. item: IUP_MENU_ITEM
  262. do
  263. line_count := ml.get_line_count
  264. str := "Line Number [1-"
  265. str.append_string(ml.get_line_count.to_string)
  266. str.append_string("]:")
  267. create lbl.label(str)
  268. create txt.text
  269. txt.set_mask("IUP_MASK_UINT") -- unsigned integer numbers only
  270. txt.set_name("LINE_TEXT")
  271. txt.set_visible_columns(20)
  272. create bt_ok.button("OK")
  273. bt_ok.set_attribute_integer("TEXT_LINECOUNT", line_count)
  274. bt_ok.set_padding(10, 2)
  275. bt_ok.set_cb_action(agent goto_ok_action_cb(?))
  276. create bt_cancel.button("Cancel")
  277. bt_cancel.set_padding(10, 2)
  278. bt_cancel.set_cb_action(agent goto_cancel_action_cb(?))
  279. create f.fill
  280. create hbox.hbox({ARRAY[IUP_WIDGET] 1, << f, bt_ok, bt_cancel >>})
  281. hbox.set_normalize_size("HORIZONTAL")
  282. create vbox.vbox({ARRAY[IUP_WIDGET] 1, << lbl, txt, hbox >>})
  283. vbox.set_margin(10, 10)
  284. vbox.set_gap(5)
  285. create dlg.dialog(vbox)
  286. dlg.set_title("Go To Line")
  287. dlg.set_modal_dialog_frame(True)
  288. dlg.set_default_enter_widget(bt_ok)
  289. dlg.set_default_escape_widget(bt_cancel)
  290. if {IUP_MENU_ITEM} ?:= widget then
  291. item ::= widget
  292. dlg.set_parent_dialog_widget(item.get_dialog)
  293. elseif {IUP_DIALOG} ?:= widget then
  294. d ::= widget
  295. dlg.set_parent_dialog_widget(d)
  296. end
  297. s := dlg.popup_predefined_xy ("IUP_CENTERPARENT", "IUP_CENTERPARENT")
  298. if s.is_equal("IUP_NOERROR") and dlg.get_attribute_integer("STATUS").is_equal(1) then
  299. line := txt.get_value.to_integer
  300. pos := ml.text_convert_lin_col_to_pos(line, 0)
  301. ml.set_multiline_caret_pos(pos)
  302. ml.scroll_to_pos(pos)
  303. end
  304. dlg.destroy
  305. Result := "IUP_DEFAULT"
  306. end
  307. find_next_action_cb (widget: IUP_BUTTON): STRING
  308. local
  309. str, str_to_find, casesensitive: STRING
  310. find_pos, pos, end_pos: INTEGER
  311. txt: IUP_TEXT
  312. find_case: IUP_TOGGLE
  313. tup: TUPLE[INTEGER, INTEGER]
  314. pw: IUP_WIDGET
  315. ms: IUP_MESSAGE
  316. do
  317. str := ml.get_value
  318. find_pos := ml.get_attribute_integer("FIND_POS")
  319. if find_pos = 0 then
  320. find_pos := 1
  321. end
  322. if txt ?:= widget.get_dialog_child("FIND_TEXT") then
  323. txt ::= widget.get_dialog_child("FIND_TEXT")
  324. str_to_find := txt.get_value
  325. if find_case ?:= widget.get_dialog_child("FIND_CASE") then
  326. find_case ::= widget.get_dialog_child("FIND_CASE")
  327. casesensitive := find_case.get_value
  328. -- Rest 1 since the string start at 1, but multiline position
  329. -- start at 0.
  330. pos := str_find(str, str_to_find, casesensitive, find_pos) - 1
  331. if pos < 0 and find_pos > 0 then
  332. -- try again from the start
  333. pos := str_find(str, str_to_find, casesensitive, 1) - 1
  334. end
  335. if pos > 0 then
  336. end_pos := pos + str_to_find.count
  337. ml.set_attribute_integer("FIND_POS", end_pos)
  338. pw := ml.set_focus
  339. ml.set_multiline_selection_pos(pos, end_pos)
  340. tup := ml.text_convert_pos_to_lin_col(pos)
  341. -- position at col=0, just scroll lines
  342. pos := ml.text_convert_lin_col_to_pos(tup.item_1, 0)
  343. ml.scroll_to_pos(pos)
  344. else
  345. create ms.message("Warning", "Text not found.")
  346. end
  347. end
  348. end
  349. Result := "IUP_DEFAULT"
  350. end
  351. find_close_action_cb (widget: IUP_BUTTON): STRING
  352. do
  353. widget.get_dialog.hide
  354. Result := "IUP_DEFAULT"
  355. end
  356. item_find_action_cb (widget: IUP_WIDGET): STRING
  357. local
  358. dlg, main_dlg: IUP_DIALOG
  359. lbl: IUP_LABEL
  360. txt: IUP_TEXT
  361. btn, bt_next, bt_close: IUP_BUTTON
  362. find_case: IUP_TOGGLE
  363. f: IUP_FILL
  364. hbox: IUP_HBOX
  365. vbox: IUP_VBOX
  366. s: STRING
  367. item: IUP_MENU_ITEM
  368. do
  369. if btn ?:= widget then
  370. btn ::= widget
  371. main_dlg := btn.get_dialog
  372. elseif item ?:= widget then
  373. item ::= widget
  374. main_dlg := item.get_dialog
  375. elseif main_dlg ?:= widget then
  376. main_dlg ::= widget
  377. end
  378. if dlg ?:= main_dlg.get_attribute_widget("FIND_DIALOG") then
  379. dlg ::= main_dlg.get_attribute_widget("FIND_DIALOG")
  380. end
  381. if dlg = Void then
  382. create lbl.label("Find What:")
  383. create txt.text
  384. txt.set_name("FIND_TEXT")
  385. txt.set_visible_columns(20)
  386. create find_case.toggle("Case Sensitive")
  387. find_case.set_name("FIND_CASE")
  388. create bt_next.button("Find Next")
  389. bt_next.set_padding(10, 2)
  390. bt_next.set_cb_action(agent find_next_action_cb(?))
  391. create bt_close.button("Close")
  392. bt_close.set_padding(10, 2)
  393. bt_close.set_cb_action(agent find_close_action_cb(?))
  394. create f.fill
  395. create hbox.hbox({ARRAY[IUP_WIDGET] 1, << f, bt_next, bt_close >>})
  396. hbox.set_normalize_size("HORIZONTAL")
  397. create vbox.vbox({ARRAY[IUP_WIDGET] 1, << lbl, txt, find_case, hbox >>})
  398. vbox.set_margin(10, 10)
  399. vbox.set_gap(10)
  400. create dlg.dialog(vbox)
  401. dlg.set_title("Find")
  402. dlg.set_modal_dialog_frame(True)
  403. dlg.set_default_enter_widget(bt_next)
  404. dlg.set_default_escape_widget(bt_close)
  405. dlg.set_parent_dialog_widget(main_dlg)
  406. -- Save the dialog to reuse it
  407. main_dlg.set_attribute_widget("FIND_DIALOG", dlg)
  408. end
  409. -- center parent first time, next time reuse the last position
  410. s := dlg.show_predefined_xy("IUP_CURRENT", "IUP_CURRENT")
  411. Result := "IUP_DEFAULT"
  412. end
  413. item_copy_action_cb(item: IUP_MENU_ITEM): STRING
  414. local
  415. cp: IUP_CLIPBOARD
  416. do
  417. cp := get_clipboard
  418. cp.add_text(ml.get_selected_text)
  419. Result := "IUP_DEFAULT"
  420. end
  421. item_paste_action_cb(item: IUP_MENU_ITEM): STRING
  422. local
  423. cp: IUP_CLIPBOARD
  424. do
  425. cp := get_clipboard
  426. ml.insert(cp.get_text)
  427. Result := "IUP_DEFAULT"
  428. end
  429. item_cut_action_cb(item: IUP_MENU_ITEM): STRING
  430. local
  431. cp: IUP_CLIPBOARD
  432. do
  433. cp := get_clipboard
  434. cp.add_text(ml.get_selected_text)
  435. ml.set_selected_text("")
  436. Result := "IUP_DEFAULT"
  437. end
  438. item_delete_action_cb(item: IUP_MENU_ITEM): STRING
  439. do
  440. ml.set_selected_text("")
  441. Result := "IUP_DEFAULT"
  442. end
  443. item_select_all_action_cb(item: IUP_MENU_ITEM): STRING
  444. do
  445. ml.select_all
  446. Result := "IUP_DEFAULT"
  447. end
  448. item_toolbar_action_cb (item: IUP_MENU_ITEM): STRING
  449. local
  450. d: IUP_CONTAINER
  451. tb: IUP_HBOX
  452. do
  453. d := ml.get_parent
  454. tb ::= d.get_child(0)
  455. if item.get_value then
  456. tb.set_floating("YES")
  457. tb.set_visible(False)
  458. item.set_value(False)
  459. cfg.set_variable_integer("MainWindow", "Toolbar", 0)
  460. else
  461. tb.set_floating("NO")
  462. tb.set_visible(True)
  463. item.set_value(True)
  464. cfg.set_variable_integer("MainWindow", "Toolbar", 1)
  465. end
  466. d.refresh
  467. Result := "IUP_DEFAULT"
  468. end
  469. item_statusbar_action_cb (item: IUP_MENU_ITEM): STRING
  470. local
  471. d: IUP_CONTAINER
  472. l: IUP_LABEL
  473. do
  474. d := ml.get_parent
  475. l ::= ml.get_brother
  476. if item.get_value then
  477. l.set_floating("YES")
  478. l.set_visible(False)
  479. item.set_value(False)
  480. cfg.set_variable_integer("MainWindow", "Statusbar", 0)
  481. else
  482. l.set_floating("NO")
  483. l.set_visible(True)
  484. item.set_value(True)
  485. cfg.set_variable_integer("MainWindow", "Statusbar", 1)
  486. end
  487. d.refresh
  488. Result := "IUP_DEFAULT"
  489. end
  490. key_pressed (dlg: IUP_DIALOG; k: INTEGER): STRING
  491. do
  492. if k.is_equal(iup_open.x_key_ctrl('O')) then
  493. Result := item_open_action_cb(dlg)
  494. elseif k.is_equal(iup_open.x_key_ctrl('S')) then
  495. Result := item_saveas_action_cb(dlg)
  496. elseif k.is_equal(iup_open.x_key_ctrl('F')) then
  497. Result := item_find_action_cb(dlg)
  498. elseif k.is_equal(iup_open.x_key_ctrl('G')) then
  499. Result := item_goto_action_cb(dlg)
  500. else
  501. Result := "IUP_DEFAULT"
  502. end
  503. end
  504. --********************************** Make *****************************************
  505. make
  506. local
  507. i: STRING
  508. x: INTEGER
  509. gui: IUP
  510. v: IUP_VBOX
  511. w: IUP_DIALOG
  512. item_exit, item_open, item_saveas, item_font, item_help, item_about: IUP_MENU_ITEM
  513. item_find, item_goto, item_copy, item_paste, item_cut, item_delete, item_select_all, item_toolbar, item_statusbar: IUP_MENU_ITEM
  514. sep1, sep2, sep3: IUP_MENU_SEPARATOR
  515. file_menu, edit_menu, format_menu, help_menu, menu, recent_menu, view_menu: IUP_MENU
  516. sub_menu_file, sub_menu_edit, sub_menu_format, sub_menu_help, sub_menu_recent, sub_menu_view: IUP_SUBMENU
  517. btn_open, btn_save, btn_find: IUP_BUTTON
  518. lbl_statusbar, toolbar_sep: IUP_LABEL
  519. toolbar_hb: IUP_HBOX
  520. do
  521. gui := iup_open
  522. gui.load_images
  523. create cfg.config
  524. cfg.set_app_name("simple_notepad")
  525. x := cfg.load
  526. create ml.multiline
  527. ml.set_expand("YES")
  528. ml.set_cb_caret(agent multitext_caret_cb(?,?,?,?))
  529. i := cfg.get_variable_string("MainWindow", "Font")
  530. if not i.is_empty then
  531. ml.set_font(i)
  532. end
  533. create item_open.item("&Open... %TCtrl+O")
  534. item_open.set_hide_mark(True)
  535. item_open.set_cb_action(agent item_open_action_cb(?))
  536. create btn_open.button("")
  537. btn_open.set_image("IUP_FileOpen")
  538. btn_open.set_flat(True)
  539. btn_open.set_can_focus(False)
  540. btn_open.set_tip("Open (Ctrl+O)")
  541. btn_open.set_cb_action(agent item_open_action_cb(?))
  542. create item_saveas.item("Save &As...%TCtrl+S")
  543. item_saveas.set_hide_mark(True)
  544. item_saveas.set_cb_action(agent item_saveas_action_cb(?))
  545. create btn_save.button("")
  546. btn_save.set_image("IUP_FileSave")
  547. btn_save.set_flat(True)
  548. btn_save.set_can_focus(False)
  549. btn_save.set_tip("Save (Ctrl+S)")
  550. btn_save.set_cb_action(agent item_saveas_action_cb(?))
  551. create item_exit.item("E&xit")
  552. item_exit.set_hide_mark(True)
  553. item_exit.set_cb_action(agent item_exit_action_cb(?))
  554. create item_find.item("&Find...%TCtrl+F")
  555. item_find.set_hide_mark(True)
  556. item_find.set_cb_action(agent item_find_action_cb(?))
  557. create btn_find.button("")
  558. btn_find.set_image("IUP_EditFind")
  559. btn_find.set_flat(True)
  560. btn_find.set_can_focus(False)
  561. btn_find.set_tip("Find (Ctrl+F)")
  562. btn_find.set_cb_action(agent item_find_action_cb(?))
  563. create item_goto.item("&Go To...%TCtrl+G")
  564. item_goto.set_hide_mark(True)
  565. item_goto.set_cb_action(agent item_goto_action_cb(?))
  566. create item_font.item("&Font...%TCtrl+F")
  567. item_font.set_hide_mark(True)
  568. item_font.set_cb_action(agent item_font_action_cb(?))
  569. create item_help.item("&Help...")
  570. item_help.set_hide_mark(True)
  571. item_help.set_cb_action(agent item_help_action_cb(?))
  572. create item_about.item("&About...")
  573. item_about.set_hide_mark(True)
  574. item_about.set_cb_action(agent item_about_action_cb(?))
  575. create item_copy.item("Copy%TCtrl+C")
  576. item_copy.set_name("ITEM_COPY")
  577. item_copy.set_hide_mark(True)
  578. item_copy.set_cb_action(agent item_copy_action_cb(?))
  579. create item_paste.item("Paste%TCtrl+V")
  580. item_paste.set_name("ITEM_PASTE")
  581. item_paste.set_hide_mark(True)
  582. item_paste.set_cb_action(agent item_paste_action_cb(?))
  583. create item_cut.item("Cut%TCtrl+X")
  584. item_cut.set_name("ITEM_CUT")
  585. item_cut.set_hide_mark(True)
  586. item_cut.set_cb_action(agent item_cut_action_cb(?))
  587. create item_delete.item("Delete%TDel")
  588. item_delete.set_name("ITEM_DELETE")
  589. item_delete.set_hide_mark(True)
  590. item_delete.set_cb_action(agent item_delete_action_cb(?))
  591. create item_select_all.item("Select All%TCtrl+A")
  592. item_select_all.set_hide_mark(True)
  593. item_select_all.set_cb_action(agent item_select_all_action_cb(?))
  594. create item_toolbar.item("&Toolbar")
  595. item_toolbar.set_cb_action(agent item_toolbar_action_cb(?))
  596. item_toolbar.set_value(True)
  597. create item_statusbar.item("&Statusbar")
  598. item_statusbar.set_cb_action(agent item_statusbar_action_cb(?))
  599. item_statusbar.set_value(True)
  600. create sep1.separator
  601. create sep2.separator
  602. create sep3.separator
  603. create toolbar_sep.label_empty
  604. toolbar_sep.set_vertical_separator
  605. create recent_menu.menu_empty
  606. create sub_menu_recent.submenu("Recent &Files", recent_menu)
  607. create file_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_open, item_saveas, sep1, sub_menu_recent, item_exit >>})
  608. create edit_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_cut, item_copy, item_paste, item_delete, sep2, item_find, item_goto, sep3, item_select_all >>})
  609. create format_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_font >>})
  610. create view_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_toolbar, item_statusbar >>})
  611. create help_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_help, item_about >>})
  612. edit_menu.set_cb_open(agent edit_menu_open_cb(?))
  613. create sub_menu_file.submenu("&File", file_menu)
  614. create sub_menu_edit.submenu("&Edit", edit_menu)
  615. create sub_menu_format.submenu("F&ormat", format_menu)
  616. create sub_menu_view.submenu("&View", view_menu)
  617. create sub_menu_help.submenu("&Help", help_menu)
  618. create menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << sub_menu_file, sub_menu_edit, sub_menu_format, sub_menu_view, sub_menu_help >>})
  619. create toolbar_hb.hbox({ARRAY[IUP_WIDGET] 1, << btn_open, btn_save, toolbar_sep, btn_find >>})
  620. toolbar_hb.set_margin(5, 5)
  621. toolbar_hb.set_gap(2)
  622. create lbl_statusbar.label("Lin 1, Col 1")
  623. lbl_statusbar.set_name("STATUSBAR")
  624. lbl_statusbar.set_expand("HORIZONTAL")
  625. lbl_statusbar.set_padding(10, 5)
  626. create v.vbox({ARRAY[IUP_WIDGET] 1, << toolbar_hb, ml, lbl_statusbar >>})
  627. if cfg.get_variable_integer_default("MainWindow", "Toolbar", 1) = 0 then
  628. item_toolbar.set_value(False)
  629. toolbar_hb.set_floating("YES")
  630. toolbar_hb.set_visible(False)
  631. end
  632. if cfg.get_variable_integer_default("MainWindow", "Statusbar", 1) = 0 then
  633. item_statusbar.set_value(False)
  634. lbl_statusbar.set_floating("YES")
  635. lbl_statusbar.set_visible(False)
  636. end
  637. create w.dialog(v)
  638. w.set_menu_widget(menu)
  639. w.set_cb_k_any(agent key_pressed(?, ?))
  640. w.set_title("Simple Notepad")
  641. w.set_predefined_size("HALF", "HALF")
  642. -- parent for some pre-defined dialogs in callbak functions
  643. gui.set_global_parent_dialog_widget(w)
  644. w.set_user_size(0, 0)
  645. w.set_cb_close(agent close_dialog_cb(?))
  646. cfg.set_recent_file_menu(recent_menu, agent config_recent_cb(?), 10)
  647. cfg.show_dialog(w, "MainWindow")
  648. gui.main_loop
  649. gui.close
  650. end
  651. end