| 1 | /* StringsEditor.cpp |
| 2 | * |
| 3 | * Copyright (C) 2007-2012,2015-2022 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "StringsEditor.h"cxx . . $ `<file>/sys/StringsEditor.h`/ |
| 20 | #include "EditorM.h"cxx . . $ `<file>/sys/EditorM.h`/ |
| 21 | #include "machine.h"cxx . . $ `<file>/sys/machine.h`/ |
| 22 | |
| 23 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (StringsEditor, Editor, 0); |
| 24 | |
| 25 | static void menu_cb_helpcxx . . $ menu_cb_help(b38d39fce81011cb). (StringsEditorcxx . . $ StringsEditor# /* me */, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { |
| 26 | HELPcxx . . $ `sys/EditorM.h:631:9`! (U"StringsEditor") |
| 27 | } |
| 28 | |
| 29 | void structStringsEditorcxx . . $ structStringsEditor# :: v_createMenuItems_helpcxx . . $ structStringsEditor#v_createMenuItems_help(6ea9c8c6ea2f58a9). (EditorMenucxx . . $ EditorMenu# menu) { |
| 30 | StringsEditor_Parentcxx . . $ StringsEditor_Parent# :: v_createMenuItems_helpcxx . . $ structDataGui#v_createMenuItems_help(6ea9c8c6ea2f58a9). (menu); |
| 31 | EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"StringsEditor help", U'?', menu_cb_helpcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).); |
| 32 | } |
| 33 | |
| 34 | static void updateListcxx . . $ updateList(5bbde9ebd3ae3172). (StringsEditorcxx . . $ StringsEditor# me) { |
| 35 | GuiList_deleteAllItemscxx . . $ GuiList_deleteAllItems(bb293b59cc37ad76). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list.); |
| 36 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).() -> numberOfStringscxx . . $ structStrings#numberOfStrings.; i ++) |
| 37 | GuiList_insertItemcxx . . $ GuiList_insertItem(896610c612ff86cf). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list., mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).() -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), 0); |
| 38 | } |
| 39 | |
| 40 | static void gui_button_cb_insertcxx . . $ gui_button_cb_insert(1b2d8f8ab3d5d68f). (StringsEditorcxx . . $ StringsEditor# me, GuiButtonEventcxx . . $ GuiButtonEvent# /* event */) { |
| 41 | /* |
| 42 | Find the first selected item. |
| 43 | */ |
| 44 | autoINTVECcxx . . $ autoINTVEC# selected = GuiList_getSelectedPositionscxx . . $ GuiList_getSelectedPositions(21bc371a31941fa7). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list.); |
| 45 | integercxx . . $ integer# position = ( selected.sizecxx . . $ autovector#size. >= 1 ? selected [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] : mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).() -> numberOfStringscxx . . $ structStrings#numberOfStrings. + 1 ); |
| 46 | autostring32cxx . . $ autostring32# text = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textcxx . . $ structStringsEditor#text.); |
| 47 | /* |
| 48 | Change the data. |
| 49 | */ |
| 50 | Strings_insertcxx . . $ Strings_insert(48d18350c34fd7ae). (mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).(), position, text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 51 | /* |
| 52 | Change the list. |
| 53 | */ |
| 54 | GuiList_insertItemcxx . . $ GuiList_insertItem(896610c612ff86cf). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list., text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), position); |
| 55 | GuiList_deselectAllItemscxx . . $ GuiList_deselectAllItems(bb293b59cc37ad76). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list.); |
| 56 | GuiList_selectItemcxx . . $ GuiList_selectItem(f9b5f8b1da8fd2dd). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list., position); |
| 57 | /* |
| 58 | Clean up. |
| 59 | */ |
| 60 | Editor_broadcastDataChangedcxx . . $ Editor_broadcastDataChanged(c0154a85f79216c7). (me); |
| 61 | } |
| 62 | |
| 63 | static void gui_button_cb_appendcxx . . $ gui_button_cb_append(1b2d8f8ab3d5d68f). (StringsEditorcxx . . $ StringsEditor# me, GuiButtonEventcxx . . $ GuiButtonEvent# /* event */) { |
| 64 | autostring32cxx . . $ autostring32# text = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textcxx . . $ structStringsEditor#text.); |
| 65 | /* |
| 66 | Change the data. |
| 67 | */ |
| 68 | Strings_insertcxx . . $ Strings_insert(48d18350c34fd7ae). (mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).(), 0, text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 69 | /* |
| 70 | Change the list. |
| 71 | */ |
| 72 | GuiList_insertItemcxx . . $ GuiList_insertItem(896610c612ff86cf). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list., text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), 0); |
| 73 | GuiList_deselectAllItemscxx . . $ GuiList_deselectAllItems(bb293b59cc37ad76). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list.); |
| 74 | GuiList_selectItemcxx . . $ GuiList_selectItem(f9b5f8b1da8fd2dd). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list., mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).() -> numberOfStringscxx . . $ structStrings#numberOfStrings.); |
| 75 | /* |
| 76 | Clean up. |
| 77 | */ |
| 78 | Editor_broadcastDataChangedcxx . . $ Editor_broadcastDataChanged(c0154a85f79216c7). (me); |
| 79 | } |
| 80 | |
| 81 | static void gui_button_cb_removecxx . . $ gui_button_cb_remove(1b2d8f8ab3d5d68f). (StringsEditorcxx . . $ StringsEditor# me, GuiButtonEventcxx . . $ GuiButtonEvent# /* event */) { |
| 82 | autoINTVECcxx . . $ autoINTVEC# selected = GuiList_getSelectedPositionscxx . . $ GuiList_getSelectedPositions(21bc371a31941fa7). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list.); |
| 83 | for (integercxx . . $ integer# iselected = selected.sizecxx . . $ autovector#size.; iselected >= 1; iselected --) |
| 84 | Strings_removecxx . . $ Strings_remove(51f4c61c065c624). (mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).(), selected [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iselected]); |
| 85 | updateListcxx . . $ updateList(5bbde9ebd3ae3172). (me); |
| 86 | Editor_broadcastDataChangedcxx . . $ Editor_broadcastDataChanged(c0154a85f79216c7). (me); |
| 87 | } |
| 88 | |
| 89 | static void gui_button_cb_replacecxx . . $ gui_button_cb_replace(1b2d8f8ab3d5d68f). (StringsEditorcxx . . $ StringsEditor# me, GuiButtonEventcxx . . $ GuiButtonEvent# /* event */) { |
| 90 | autoINTVECcxx . . $ autoINTVEC# selected = GuiList_getSelectedPositionscxx . . $ GuiList_getSelectedPositions(21bc371a31941fa7). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list.); |
| 91 | autostring32cxx . . $ autostring32# text = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textcxx . . $ structStringsEditor#text.); |
| 92 | for (integercxx . . $ integer# iselected = 1; iselected <= selected.sizecxx . . $ autovector#size.; iselected ++) { |
| 93 | Strings_replacecxx . . $ Strings_replace(48d18350c34fd7ae). (mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStringsEditor#strings(393633bd57a7299).(), selected [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iselected], text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 94 | GuiList_replaceItemcxx . . $ GuiList_replaceItem(896610c612ff86cf). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structStringsEditor#list., text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), selected [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iselected]); |
| 95 | } |
| 96 | Editor_broadcastDataChangedcxx . . $ Editor_broadcastDataChanged(c0154a85f79216c7). (me); |
| 97 | } |
| 98 | |
| 99 | static void gui_list_cb_doubleClickcxx . . $ gui_list_cb_doubleClick(240436e78105c7a2). (StringsEditorcxx . . $ StringsEditor# me, GuiList_DoubleClickEventcxx . . $ GuiList_DoubleClickEvent# /* event */) { |
| 100 | //if (event -> position <= my strings -> numberOfStrings) // FIXME |
| 101 | // GuiText_setString (my text, my strings -> strings [event -> position]); |
| 102 | } |
| 103 | |
| 104 | void structStringsEditorcxx . . $ structStringsEditor# :: v_createChildrencxx . . $ structStringsEditor#v_createChildren(49f6e7a06ebc5aa8). () { |
| 105 | listcxx . . $ structStringsEditor#list. = GuiList_createcxx . . $ GuiList_create(88aee17cb4a88a62). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 1, 0, Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). (), -70, true, nullptr); |
| 106 | GuiList_setDoubleClickCallbackcxx . . $ GuiList_setDoubleClickCallback(1ef636283ce6f16). (listcxx . . $ structStringsEditor#list., gui_list_cb_doubleClickcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this); |
| 107 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (listcxx . . $ structStringsEditor#list.); |
| 108 | |
| 109 | textcxx . . $ structStringsEditor#text. = GuiText_createShowncxx . . $ GuiText_createShown(8bcb1f2be7fc31ee). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 0, 0, -40 - Gui_TEXTFIELD_HEIGHTcxx . . $ `sys/Gui.h:96:9`!, -40, 0); |
| 110 | GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 10, 100, -10 - Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, -10, U"Insert", gui_button_cb_insertcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this, GuiButton_DEFAULTcxx . . $ `sys/Gui.h:467:9`!); |
| 111 | GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 110, 200, -10 - Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, -10, U"Append", gui_button_cb_appendcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this, 0); |
| 112 | GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 210, 300, -10 - Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, -10, U"Replace", gui_button_cb_replacecxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this, 0); |
| 113 | GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 310, 400, -10 - Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, -10, U"Remove", gui_button_cb_removecxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this, 0); |
| 114 | } |
| 115 | |
| 116 | void structStringsEditorcxx . . $ structStringsEditor# :: v1_dataChangedcxx . . $ structStringsEditor#v1_dataChanged(c0154a85f79216c7). (Editorcxx . . $ Editor# /* sender */) { |
| 117 | updateListcxx . . $ updateList(5bbde9ebd3ae3172). (this); |
| 118 | } |
| 119 | |
| 120 | autoStringsEditorcxx . . $ autoStringsEditor# StringsEditor_createcxx . . $ StringsEditor_create(2bbb36fb3d939afd). (conststring32cxx . . $ conststring32# title, Stringscxx . . $ Strings# strings) { |
| 121 | try { |
| 122 | autoStringsEditorcxx . . $ autoStringsEditor# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (StringsEditor); |
| 123 | Editor_initcxx . . $ Editor_init(13f379e38ac41ed6). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 20, 40, 600, 600, title, strings); |
| 124 | updateListcxx . . $ updateList(5bbde9ebd3ae3172). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 125 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 126 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 127 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Strings window not created."); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /* End of file StringsEditor.cpp */ |