fbdbg  3.0
FreeBASIC Debugger
shortcuts.bas
Go to the documentation of this file.
1 
23 
24 
25 
26 #DEFINE ACCELL_FILE "dat/accelerators.rc"
27 
28 
38 SUB populateShortcuts CDECL(BYVAL Act AS gpointer, BYVAL Store AS gpointer)
39  STATIC AS GtkTreeIter iter
40  STATIC AS GtkAccelKey acck
41 
42  VAR action = GTK_ACTION(Act)
43  VAR accel_path = gtk_action_get_accel_path(action)
44 
45  IF 0 = accel_path THEN EXIT SUB
46  IF 0 = gtk_accel_map_lookup_entry(accel_path, @acck) _
47  THEN gtk_accel_map_add_entry(accel_path, 0, 0)
48 
49  gtk_list_store_append(Store, @iter)
50  gtk_list_store_set(Store, @iter _
51  , 0, acck.accel_key _
52  , 1, acck.accel_mods _
53  , 2, gtk_action_get_label(action) _ ' don't free this and next
54  , 3, gtk_action_get_tooltip(action) _
55  , 4, accel_path _
56  , -1) ' parameter list terminator
57 END SUB
58 
59 
60 
71 FUNCTION evaluateShortcuts CDECL( _
72  BYVAL Tree AS GtkTreeModel PTR _
73 , BYVAL Path AS GtkTreePath PTR _
74 , BYVAL Iter AS GtkTreeIter PTR _
75 , BYVAL user_data AS gpointer) AS gboolean
76 
77  DIM AS gpointer accel_path
78  DIM AS guint accel_key, accel_mods
79  gtk_tree_model_get(Tree, Iter _
80  , 0, @accel_key _
81  , 1, @accel_mods _
82  , 4, @accel_path _
83  , -1) ' parameter list terminator
84  gtk_accel_map_change_entry(accel_path, accel_key, accel_mods, TRUE)
85 
86  RETURN FALSE
87 END FUNCTION
88 
89 
90 
103 SUB ShortcutsForm(BYVAL Mo AS gint = 1)
104  STATIC AS GtkListStore PTR store
105  STATIC AS GObject PTR actgrp
106 
107  IF 0 = store THEN
108  VAR xml = GUI.XML ' initial get objects from GUI description
109  store = GTK_LIST_STORE(gtk_builder_get_object(xml, "liststore600"))
110  actgrp = gtk_builder_get_object(xml, "actiongroup1")
111  END IF
112 
113  SELECT CASE AS CONST Mo
114  CASE 0 ' evaluate from dialog
115  gtk_tree_model_foreach(GTK_TREE_MODEL(store), @evaluateShortcuts, NULL)
116  gtk_accel_map_save(ACCELL_FILE)
117  CASE ELSE ' populate the dialog
118  gtk_accel_map_load(ACCELL_FILE)
119  gtk_list_store_clear(store)
120  VAR list = gtk_action_group_list_actions(GTK_ACTION_GROUP(actgrp))
121  g_list_foreach(list, @populateShortcuts, store)
122  g_list_free(list)
123  END SELECT
124 END SUB
125 
126 
127 
137 SUB act_Shortcut CDECL ALIAS "act_Shortcut" ( _
138  BYVAL Action AS GtkAction PTR, _
139  BYVAL Dialog AS gpointer) EXPORT
140 
141 ?" --> callback act_Shortcut"
142 
143  SELECT CASE AS CONST gtk_dialog_run(Dialog)
144  CASE 0
145 ?" --> callback act_Shortcut -> get changed settings"
146  ShortcutsForm(0) ' load from form
147  CASE ELSE
148 ?" --> callback act_Shortcut -> dialog canceled, restore form"
149  ShortcutsForm(1) ' restore form, because user canceled
150  END SELECT
151  gtk_widget_hide(Dialog)
152 
153 END SUB
154 
155 
156 
166 SUB on_accel_cleared CDECL ALIAS "on_accel_cleared" ( _
167  BYVAL Accel AS GtkCellRendererAccel PTR, _
168  BYVAL PathString AS gchar PTR, _
169  BYVAL Store AS gpointer) EXPORT
170 
171  DIM AS GtkTreeIter iter
172  VAR model = GTK_TREE_MODEL(Store)
173  gtk_tree_model_get_iter_from_string(model, @iter, PathString)
174  gtk_list_store_set(Store, @iter _
175  , 0, CAST(guint, 0) _
176  , 1, CAST(guint, 0) _
177  , -1) ' parameter list terminator
178 
179 END SUB
180 
181 
182 
197 SUB on_accel_edited CDECL ALIAS "on_accel_edited" ( _
198  BYVAL Accel AS GtkCellRendererAccel PTR _
199  , BYVAL PathString AS gchar PTR _
200  , BYVAL AccelKey AS guint _
201  , BYVAL AccelMods AS GdkModifierType _
202  , BYVAL HardwareKeycode AS guint _
203  , BYVAL Store AS gpointer) EXPORT
204 
205  VAR model = GTK_TREE_MODEL(Store)
206 
207  DIM AS guint k, m
208  DIM AS GtkTreeIter search
209  IF gtk_tree_model_get_iter_first(model, @search) THEN
210  DO
211  gtk_tree_model_get(model, @search, 0, @k, 1, @m, -1)
212  IF k <> AccelKey ORELSE m <> AccelMods THEN CONTINUE DO
213 
214  DIM AS gchar PTR txt
215  gtk_tree_model_get(model, @search, 2, @txt, -1)
216  VAR dia = gtk_message_dialog_new_with_markup(GTK_WINDOW(GUI.window1) _
217  , GTK_DIALOG_MODAL OR GTK_DIALOG_DESTROY_WITH_PARENT _
218  , GTK_MESSAGE_QUESTION _
219  , GTK_BUTTONS_YES_NO _
220  , ( _
221  *__(!"Shortcut already defined for\n\n") _
222  & *__(!"<b>%s</b>\n\n") _
223  & *__(!"Override existing\n") _
224  ) _
225  , txt _
226  , NULL)
227  g_free(txt)
228 
229  VAR r = gtk_dialog_run(GTK_DIALOG(dia))
230  gtk_widget_destroy(dia) : IF r <> GTK_RESPONSE_YES THEN EXIT SUB
231  gtk_list_store_set(Store, @search _
232  , 0, CAST(guint, 0) _
233  , 1, CAST(guint, 0) _
234  , -1) : EXIT DO
235  LOOP UNTIL 0 = gtk_tree_model_iter_next(model, @search)
236  END IF
237 
238  IF 0 = AccelMods THEN ' shall we use this ???
239  VAR dia = gtk_message_dialog_new_with_markup(GTK_WINDOW(GUI.window1) _
240  , GTK_DIALOG_MODAL OR GTK_DIALOG_DESTROY_WITH_PARENT _
241  , GTK_MESSAGE_QUESTION _
242  , GTK_BUTTONS_YES_NO _
243  , ( _
244  *__(!"Shortcut has no modifier\n\n") _
245  & *__(!"This interferes with the search\n") _
246  & *__(!"function in the tree views\n\n") _
247  & *__(!"Anyway, use it ...") _
248  ) _
249  , NULL)
250 
251  VAR r = gtk_dialog_run(GTK_DIALOG(dia))
252  gtk_widget_destroy(dia) : IF r <> GTK_RESPONSE_YES THEN EXIT SUB
253  END IF
254 
255  DIM AS GtkTreeIter iter
256  gtk_tree_model_get_iter_from_string(model, @iter, PathString)
257  gtk_list_store_set(Store, @iter _
258  , 0, AccelKey _
259  , 1, AccelMods _
260  , -1)
261 END SUB
262 
263 
264 ' Here we initialize the dialog context (before starting the main window)
265 ShortcutsForm()
266