1 /* 2 * This file is part of d-dazzle. 3 * 4 * d-dazzle is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * d-dazzle is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with d-dazzle; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module dazzle.ShortcutTheme; 20 21 private import dazzle.ShortcutChord; 22 private import dazzle.ShortcutContext; 23 private import dazzle.c.functions; 24 public import dazzle.c.types; 25 private import gio.Cancellable; 26 private import gio.FileIF; 27 private import gio.OutputStream; 28 private import glib.ConstructionException; 29 private import glib.ErrorG; 30 private import glib.GException; 31 private import glib.Str; 32 private import gobject.ObjectG; 33 private import gtk.Widget; 34 35 36 /** */ 37 public class ShortcutTheme : ObjectG 38 { 39 /** the main Gtk struct */ 40 protected DzlShortcutTheme* dzlShortcutTheme; 41 42 /** Get the main Gtk struct */ 43 public DzlShortcutTheme* getShortcutThemeStruct(bool transferOwnership = false) 44 { 45 if (transferOwnership) 46 ownedRef = false; 47 return dzlShortcutTheme; 48 } 49 50 /** the main Gtk struct as a void* */ 51 protected override void* getStruct() 52 { 53 return cast(void*)dzlShortcutTheme; 54 } 55 56 /** 57 * Sets our main struct and passes it to the parent class. 58 */ 59 public this (DzlShortcutTheme* dzlShortcutTheme, bool ownedRef = false) 60 { 61 this.dzlShortcutTheme = dzlShortcutTheme; 62 super(cast(GObject*)dzlShortcutTheme, ownedRef); 63 } 64 65 66 /** */ 67 public static GType getType() 68 { 69 return dzl_shortcut_theme_get_type(); 70 } 71 72 /** */ 73 public this(string name) 74 { 75 auto p = dzl_shortcut_theme_new(Str.toStringz(name)); 76 77 if(p is null) 78 { 79 throw new ConstructionException("null returned by new"); 80 } 81 82 this(cast(DzlShortcutTheme*) p, true); 83 } 84 85 /** */ 86 public void addCommand(string accelerator, string command) 87 { 88 dzl_shortcut_theme_add_command(dzlShortcutTheme, Str.toStringz(accelerator), Str.toStringz(command)); 89 } 90 91 /** */ 92 public void addContext(ShortcutContext context) 93 { 94 dzl_shortcut_theme_add_context(dzlShortcutTheme, (context is null) ? null : context.getShortcutContextStruct()); 95 } 96 97 /** */ 98 public void addCssResource(string path) 99 { 100 dzl_shortcut_theme_add_css_resource(dzlShortcutTheme, Str.toStringz(path)); 101 } 102 103 /** 104 * Gets the context named @name. If the context does not exist, it will 105 * be created. 106 * 107 * Params: 108 * name = The name of the context 109 * 110 * Returns: An #DzlShortcutContext 111 */ 112 public ShortcutContext findContextByName(string name) 113 { 114 auto p = dzl_shortcut_theme_find_context_by_name(dzlShortcutTheme, Str.toStringz(name)); 115 116 if(p is null) 117 { 118 return null; 119 } 120 121 return ObjectG.getDObject!(ShortcutContext)(cast(DzlShortcutContext*) p); 122 } 123 124 /** 125 * Finds the default context in the theme for @widget. 126 * 127 * Returns: An #DzlShortcutContext or %NULL. 128 */ 129 public ShortcutContext findDefaultContext(Widget widget) 130 { 131 auto p = dzl_shortcut_theme_find_default_context(dzlShortcutTheme, (widget is null) ? null : widget.getWidgetStruct()); 132 133 if(p is null) 134 { 135 return null; 136 } 137 138 return ObjectG.getDObject!(ShortcutContext)(cast(DzlShortcutContext*) p); 139 } 140 141 /** */ 142 public ShortcutChord getChordForAction(string detailedActionName) 143 { 144 auto p = dzl_shortcut_theme_get_chord_for_action(dzlShortcutTheme, Str.toStringz(detailedActionName)); 145 146 if(p is null) 147 { 148 return null; 149 } 150 151 return ObjectG.getDObject!(ShortcutChord)(cast(DzlShortcutChord*) p); 152 } 153 154 /** */ 155 public ShortcutChord getChordForCommand(string command) 156 { 157 auto p = dzl_shortcut_theme_get_chord_for_command(dzlShortcutTheme, Str.toStringz(command)); 158 159 if(p is null) 160 { 161 return null; 162 } 163 164 return ObjectG.getDObject!(ShortcutChord)(cast(DzlShortcutChord*) p); 165 } 166 167 /** */ 168 public string getName() 169 { 170 return Str.toString(dzl_shortcut_theme_get_name(dzlShortcutTheme)); 171 } 172 173 /** 174 * If the #DzlShortcutTheme:parent-name property has been set, this will fetch 175 * the parent #DzlShortcutTheme. 176 * 177 * Returns: A #DzlShortcutTheme or %NULL. 178 */ 179 public ShortcutTheme getParent() 180 { 181 auto p = dzl_shortcut_theme_get_parent(dzlShortcutTheme); 182 183 if(p is null) 184 { 185 return null; 186 } 187 188 return ObjectG.getDObject!(ShortcutTheme)(cast(DzlShortcutTheme*) p); 189 } 190 191 /** 192 * Gets the name of the parent shortcut theme. 193 * 194 * This is used to resolve shortcuts from the parent theme without having to 195 * copy them directly into this shortcut theme. It allows for some level of 196 * copy-on-write (CoW). 197 * 198 * Returns: The name of the parent theme, or %NULL if none is set. 199 */ 200 public string getParentName() 201 { 202 return Str.toString(dzl_shortcut_theme_get_parent_name(dzlShortcutTheme)); 203 } 204 205 /** */ 206 public string getSubtitle() 207 { 208 return Str.toString(dzl_shortcut_theme_get_subtitle(dzlShortcutTheme)); 209 } 210 211 /** */ 212 public string getTitle() 213 { 214 return Str.toString(dzl_shortcut_theme_get_title(dzlShortcutTheme)); 215 } 216 217 /** */ 218 public bool loadFromData(string data, ptrdiff_t len) 219 { 220 GError* err = null; 221 222 auto p = dzl_shortcut_theme_load_from_data(dzlShortcutTheme, Str.toStringz(data), len, &err) != 0; 223 224 if (err !is null) 225 { 226 throw new GException( new ErrorG(err) ); 227 } 228 229 return p; 230 } 231 232 /** */ 233 public bool loadFromFile(FileIF file, Cancellable cancellable) 234 { 235 GError* err = null; 236 237 auto p = dzl_shortcut_theme_load_from_file(dzlShortcutTheme, (file is null) ? null : file.getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 238 239 if (err !is null) 240 { 241 throw new GException( new ErrorG(err) ); 242 } 243 244 return p; 245 } 246 247 /** */ 248 public bool loadFromPath(string path, Cancellable cancellable) 249 { 250 GError* err = null; 251 252 auto p = dzl_shortcut_theme_load_from_path(dzlShortcutTheme, Str.toStringz(path), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 253 254 if (err !is null) 255 { 256 throw new GException( new ErrorG(err) ); 257 } 258 259 return p; 260 } 261 262 /** */ 263 public void removeCssResource(string path) 264 { 265 dzl_shortcut_theme_remove_css_resource(dzlShortcutTheme, Str.toStringz(path)); 266 } 267 268 /** */ 269 public bool saveToFile(FileIF file, Cancellable cancellable) 270 { 271 GError* err = null; 272 273 auto p = dzl_shortcut_theme_save_to_file(dzlShortcutTheme, (file is null) ? null : file.getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 274 275 if (err !is null) 276 { 277 throw new GException( new ErrorG(err) ); 278 } 279 280 return p; 281 } 282 283 /** */ 284 public bool saveToPath(string path, Cancellable cancellable) 285 { 286 GError* err = null; 287 288 auto p = dzl_shortcut_theme_save_to_path(dzlShortcutTheme, Str.toStringz(path), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 289 290 if (err !is null) 291 { 292 throw new GException( new ErrorG(err) ); 293 } 294 295 return p; 296 } 297 298 /** */ 299 public bool saveToStream(OutputStream stream, Cancellable cancellable) 300 { 301 GError* err = null; 302 303 auto p = dzl_shortcut_theme_save_to_stream(dzlShortcutTheme, (stream is null) ? null : stream.getOutputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 304 305 if (err !is null) 306 { 307 throw new GException( new ErrorG(err) ); 308 } 309 310 return p; 311 } 312 313 /** */ 314 public void setAccelForAction(string detailedActionName, string accel, DzlShortcutPhase phase) 315 { 316 dzl_shortcut_theme_set_accel_for_action(dzlShortcutTheme, Str.toStringz(detailedActionName), Str.toStringz(accel), phase); 317 } 318 319 /** 320 * This will set the command to execute when @accel is pressed. If command is 321 * %NULL, the accelerator will be cleared. If accelerator is %NULL, all 322 * accelerators for @command will be cleared. 323 * 324 * Params: 325 * command = the command to be executed 326 * accel = the shortcut accelerator 327 * phase = the phase to activate within, or 0 for the default 328 */ 329 public void setAccelForCommand(string command, string accel, DzlShortcutPhase phase) 330 { 331 dzl_shortcut_theme_set_accel_for_command(dzlShortcutTheme, Str.toStringz(command), Str.toStringz(accel), phase); 332 } 333 334 /** */ 335 public void setChordForAction(string detailedActionName, ShortcutChord chord, DzlShortcutPhase phase) 336 { 337 dzl_shortcut_theme_set_chord_for_action(dzlShortcutTheme, Str.toStringz(detailedActionName), (chord is null) ? null : chord.getShortcutChordStruct(), phase); 338 } 339 340 /** 341 * This will set the command to execute when @chord is pressed. If command is 342 * %NULL, the accelerator will be cleared. If @chord is %NULL, all 343 * accelerators for @command will be cleared. 344 * 345 * Params: 346 * command = the command to be executed 347 * chord = the chord for the command 348 * phase = the phase to activate within, or 0 for the default 349 */ 350 public void setChordForCommand(string command, ShortcutChord chord, DzlShortcutPhase phase) 351 { 352 dzl_shortcut_theme_set_chord_for_command(dzlShortcutTheme, Str.toStringz(command), (chord is null) ? null : chord.getShortcutChordStruct(), phase); 353 } 354 355 /** */ 356 public void setParentName(string parentName) 357 { 358 dzl_shortcut_theme_set_parent_name(dzlShortcutTheme, Str.toStringz(parentName)); 359 } 360 }