/** \file
* Keyboard shortcut processing.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* MenTaLguY <mental@rydia.net>
* bulia byak <buliabyak@users.sf.net>
* Peter Moulder <pmoulder@mail.csse.monash.edu.au>
*
* Copyright (C) 2005 Monash University
* Copyright (C) 2005 MenTaLguY <mental@rydia.net>
*
* as published by the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include "shortcuts.h"
#include <gdk/gdkkeysyms.h>
#include <glibmm/miscutils.h>
#include "helper/action-context.h"
#include "io/resource.h"
#include "verbs.h"
#include "xml/node-iterators.h"
#include "document.h"
#include "preferences.h"
#include "ui/tools/tool-base.h"
#include "inkscape.h"
#include "desktop.h"
#include "path-prefix.h"
#include "ui/dialog/filedialog.h"
using namespace Inkscape;
static void try_shortcuts_file(char const *filename);
unsigned int sp_shortcut_get_key(unsigned int const shortcut);
/* Returns true if action was performed */
bool
{
if (verb) {
if (action) {
return true;
}
}
return false;
}
void sp_shortcut_init()
{
if (shortcutfile.empty()) {
}
}
/* ah, if only we had an exception to catch... (permission, forgiveness) */
read_shortcuts_file(filename, true);
}
}
/*
* Inkscape expects to add the Shift modifier to any accel_keys create with Shift
* For exmaple on en_US keyboard <Shift>+6 = "&" - in this case return <Shift>+&
* See get_group0_keyval() for explanation on why
*/
unsigned int sp_gdkmodifier_to_shortcut(guint accel_key, Gdk::ModifierType gdkmodifier, guint hardware_keycode) {
unsigned int shortcut = 0;
SP_SHORTCUT_SHIFT_MASK : 0 ) |
( gdkmodifier & GDK_CONTROL_MASK ?
SP_SHORTCUT_CONTROL_MASK : 0 ) |
( gdkmodifier & GDK_MOD1_MASK ?
SP_SHORTCUT_ALT_MASK : 0 );
return shortcut;
}
if (shortcut & SP_SHORTCUT_CONTROL_MASK)
modifiers += "Ctrl,";
if (shortcut & SP_SHORTCUT_SHIFT_MASK)
modifiers += "Shift,";
if (shortcut & SP_SHORTCUT_ALT_MASK)
modifiers += "Alt,";
}
return modifiers;
}
/*
* REmove all shortucts from the users file
*/
void sp_shortcuts_delete_all_from_file() {
if (!doc) {
return;
}
while (iter) {
// some unknown element, do not complain
continue;
}
// Delete node
}
}
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> "
"<keys name=\"My custom shortcuts\">"
"</keys>";
}
/*
* Get a list of keyboard shortcut files names and paths from the system and users paths
* Dont add the users custom keyboards file
*/
void sp_shortcut_get_file_names(std::vector<Glib::ustring> *names, std::vector<Glib::ustring> *paths) {
// loop through possible keyboard shortcut file locations.
if (!directory) {
} else {
// Dont add the users custom keys file
continue;
}
// Dont add system inkscape.xml (since its a duplicate? of dfefault.xml)
continue;
}
// Get the "key name" from the root element of each file
if (!doc) {
continue;
}
continue;
}
if (name) {
}
} else {
}
}
}
}
}
}
}
}
{
//# Get the current directory for finding files
//# Test if the open_path directory exists
open_path = "";
/* Grab document directory */
if (docURI) {
}
}
//# If no open path, default to our home directory
{
open_path = g_get_home_dir();
}
return open_path;
}
//static Inkscape::UI::Dialog::FileSaveDialog * saveDialog = NULL;
void sp_shortcut_file_export()
{
*(desktop->getToplevel()),
_("Select a filename for exporting"),
"",
"",
);
if (!success) {
delete saveDialog;
return;
}
}
delete saveDialog;
}
bool sp_shortcut_file_import() {
*desktop->getToplevel(),
_("Select a file to import"));
//# Show the dialog
if (!success) {
delete importFileDialog;
return false;
}
delete importFileDialog;
return true;
}
if (!doc) {
return;
}
}
if (!doc) {
return;
}
}
/*
* Add or delete a shortcut to the users default.xml keys file
* @param addshift - when true addthe Shifg modifier to the non-display element
*
* Shortcut file consists of pairs of bind elements :
* Element (a) is used for shortcut display in menus (display="True") and contains the gdk_keyval_name of the shortcut key
* Element (b) is used in shortcut lookup and contains an uppercase version of the gdk_keyval_name,
* or a gdk_keyval_name name and the "Shift" modifier for Shift altered hardware code keys (see get_group0_keyval() for explanation)
*/
if (!doc) {
return;
}
if (!key) {
return;
}
//g_message("Removing key %s, mods %s action %s", key, modifiers.c_str(), action);
while (iter) {
// some unknown element, do not complain
continue;
}
if (!verb_name) {
continue;
}
if (!keyval_name || !*keyval_name) {
// that's ok, it's just listed for reference without assignment, skip it
continue;
}
// If deleting, then delete both the upper and lower case versions
continue;
}
//Looks like a match
// Delete node
continue;
}
}
}
if (!doc) {
if (!doc) {
return;
}
}
if (!key) {
return;
}
//g_message("Adding key %s, mods %s action %s", key, modifiers.c_str(), action);
// Add node
}
// Add another uppercase version if a character
}
}
}
if (!doc) {
return;
}
bool is_primary;
is_primary = iter->attribute("display") && strcmp(iter->attribute("display"), "false") && strcmp(iter->attribute("display"), "0");
} else {
// some unknown element, do not complain
continue;
}
if (!verb_name) {
g_warning("Missing verb name (action= attribute) for shortcut");
continue;
}
if (!verb
#if !HAVE_POTRACE
// Squash warning about disabled features
#endif
) {
continue;
}
if (!keyval_name || !*keyval_name) {
// that's ok, it's just listed for reference without assignment, skip it
continue;
}
continue;
}
if (modifiers_string) {
while (*iter) {
} else {
}
}
}
}
}
/**
* Removes a keyboard shortcut for the given verb.
* (Removes any existing binding for the given shortcut, including appropriately
* adjusting sp_shortcut_get_primary if necessary.)*
*/
void
{
if (!verbs) sp_shortcut_init();
/* Maintain the invariant that sp_shortcut_get_primary(v) returns either 0 or a valid shortcut for v. */
if (verb) {
if (old_primary == shortcut) {
(*primary_shortcuts)[verb] = 0;
}
}
}
{
if (!accel_group) {
}
return accel_group;
}
/**
* Adds a gtk accelerator to a widget
* Used to display the keyboard shortcuts in the main menu items
*/
void
{
if (shortcut == GDK_KEY_VoidSymbol) {
return;
}
if (accel_key > 0) {
"activate",
}
}
unsigned int
{
return (shortcut & (~SP_SHORTCUT_MODIFIER_MASK));
}
{
return static_cast<GdkModifierType>(
);
}
/**
* Adds a keyboard shortcut for the given verb.
* (Removes any existing binding for the given shortcut, including appropriately
* adjusting sp_shortcut_get_primary if necessary.)
*
* \param is_primary True iff this is the shortcut to be written in menu items or buttons.
*
* \post sp_shortcut_get_verb(shortcut) == verb.
* \post !is_primary or sp_shortcut_get_primary(verb) == shortcut.
*/
void
sp_shortcut_set(unsigned int const shortcut, Inkscape::Verb *const verb, bool const is_primary, bool const is_user_set)
{
if (!verbs) sp_shortcut_init();
/* Maintain the invariant that sp_shortcut_get_primary(v) returns either 0 or a valid shortcut for v. */
if (old_primary == shortcut) {
(*primary_shortcuts)[old_verb] = 0;
(*user_shortcuts)[old_verb] = 0;
}
}
if (is_primary) {
}
}
{
if (!verbs) sp_shortcut_init();
}
{
if (!primary_shortcuts) {
}
}
return result;
}
{
unsigned int result = false;
if (!primary_shortcuts) {
}
}
return result;
}
{
// The comment below was copied from the function sp_ui_shortcut_string in interface.cpp (which was subsequently removed)
/* TODO: This function shouldn't exist. Our callers should use GtkAccelLabel instead of
* a generic GtkLabel containing this string, and should call gtk_widget_add_accelerator.
* Will probably need to change sp_shortcut_invoke callers.
*
* The existing gtk_label_new_with_mnemonic call can be replaced with
* g_object_new(GTK_TYPE_ACCEL_LABEL, NULL) followed by
* gtk_label_set_text_with_mnemonic(lbl, str).
*/
if (shortcut != GDK_KEY_VoidSymbol) {
}
return result;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :