~ubuntu-branches/ubuntu/raring/notecase/raring

« back to all changes in this revision

Viewing changes to src/ShortcutsList.h

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Handler
  • Date: 2008-12-21 13:09:58 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081221130958-0ri77h0x7j1dclkq
Tags: 1.9.8-0ubuntu1
New upstream release (LP: #307752)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
////////////////////////////////////////////////////////////////////////////
2
 
// NoteCase notes manager project <http://notecase.sf.net>
3
 
//
4
 
// This code is licensed under BSD license.See "license.txt" for more details.
5
 
//
6
 
// File: Implements list of keyboard shortcuts for program actions
7
 
////////////////////////////////////////////////////////////////////////////
8
 
 
9
 
#ifndef SHORTCUTSLIST_H__
10
 
#define SHORTCUTSLIST_H__
11
 
 
12
 
#if _MSC_VER > 1000
13
 
#pragma once
14
 
#endif // _MSC_VER > 1000
15
 
 
16
 
#include <vector>
17
 
#include <string>
18
 
#include <gtk/gtk.h>
19
 
#include "lib/debug.h"
20
 
 
21
 
//define for each action (that can have a shortcut)
22
 
enum NC_Actions {
23
 
        NC_ACTION_DOC_NEW = 1,
24
 
        NC_ACTION_DOC_OPEN,
25
 
        NC_ACTION_DOC_SAVE,
26
 
        NC_ACTION_DOC_SAVE_AS,
27
 
        NC_ACTION_DOC_RELOAD,
28
 
        NC_ACTION_DOC_IMPORT,
29
 
        NC_ACTION_DOC_EXPORT,
30
 
        NC_ACTION_APP_NEW,
31
 
        NC_ACTION_APP_QUIT,
32
 
        NC_ACTION_TREE_NODE_NEW,
33
 
        NC_ACTION_TREE_NODE_NEW_CHILD,
34
 
        NC_ACTION_TREE_NODE_DELETE,
35
 
        NC_ACTION_TREE_NODE_RENAME,
36
 
        NC_ACTION_TREE_NODE_MOVE_UP,
37
 
        NC_ACTION_TREE_NODE_MOVE_DOWN,
38
 
        NC_ACTION_TREE_NODE_MOVE_LEFT,
39
 
        NC_ACTION_TREE_NODE_MOVE_RIGHT,
40
 
        NC_ACTION_TREE_NODE_PROPERTIES,
41
 
        NC_ACTION_TREE_NODE_DELETE_FINISHED,
42
 
        NC_ACTION_TREE_NODE_TOGGLE_FINISHED,
43
 
        NC_ACTION_TREE_SORT_CHILDREN_ASC,
44
 
        NC_ACTION_TREE_SORT_CHILDREN_DESC,
45
 
        NC_ACTION_TREE_SORT_ROOT_ASC,
46
 
        NC_ACTION_TREE_SORT_ROOT_DESC,
47
 
        NC_ACTION_TREE_EXPAND_ALL,
48
 
        NC_ACTION_TREE_COLAPSE_ALL,
49
 
        NC_ACTION_EDIT_UNDO,
50
 
        NC_ACTION_EDIT_REDO,
51
 
        NC_ACTION_EDIT_CUT,
52
 
        NC_ACTION_EDIT_COPY,
53
 
        NC_ACTION_EDIT_PASTE,
54
 
        NC_ACTION_EDIT_DELETE,
55
 
        NC_ACTION_EDIT_COPY_BR_STRUCT,  //copy branch structure
56
 
        NC_ACTION_EDIT_PASTE_BR_ROOT,   //paste branch to root
57
 
        NC_ACTION_EDIT_INSERT_DATETIME,
58
 
        NC_ACTION_EDIT_FIND,
59
 
        NC_ACTION_EDIT_FIND_NEXT,
60
 
        NC_ACTION_EDIT_REPLACE,
61
 
        NC_ACTION_EDIT_LINK_WIZARD,
62
 
        NC_ACTION_EDIT_INSERT_PICTURE,
63
 
        NC_ACTION_EDIT_ATTACHMENTS,
64
 
        NC_ACTION_EDIT_SHORTCUTS,
65
 
        NC_ACTION_EDIT_OPTIONS,
66
 
        NC_ACTION_FORMAT_BOLD,
67
 
        NC_ACTION_FORMAT_ITALIC,
68
 
        NC_ACTION_FORMAT_UNDERLINE,
69
 
        NC_ACTION_FORMAT_STRIKETHROUGH,
70
 
        NC_ACTION_FORMAT_COLOR,
71
 
        NC_ACTION_FORMAT_REMOVE,
72
 
        NC_ACTION_VIEW_TOOLBAR,
73
 
        NC_ACTION_VIEW_STATUS_BAR,
74
 
        NC_ACTION_VIEW_NODE_TITLEBAR,
75
 
        NC_ACTION_VIEW_WRAP,
76
 
        NC_ACTION_VIEW_CHANGE_MODE,
77
 
        NC_ACTION_VIEW_WORD_COUNT,
78
 
        NC_ACTION_HELP_INDEX,
79
 
        NC_ACTION_HELP_ABOUT,
80
 
        NC_ACTION_DOC_CLOSE,
81
 
        NC_ACTION_PASSWORD_CHANGE,
82
 
        DUMMY_ITEM2,                                    // keeps IDs sychronized with Pro version
83
 
        NC_ACTION_FORMAT_BKG_COLOR,
84
 
        NC_ACTION_READ_ONLY,
85
 
        NC_ACTION_VIEW_FULLSCREEN,
86
 
        DUMMY_ITEM3,                                    // keeps IDs sychronized with Pro version
87
 
        DUMMY_ITEM4,                                    // keeps IDs sychronized with Pro version
88
 
        NC_ACTION_LOCK_DOCUMENT,
89
 
        DUMMY_ITEM5,                                    // keeps IDs sychronized with Pro version
90
 
        DUMMY_ITEM6,                                    // keeps IDs sychronized with Pro version
91
 
        DUMMY_ITEM7,                                    // keeps IDs sychronized with Pro version
92
 
        DUMMY_ITEM8,                                    // keeps IDs sychronized with Pro version
93
 
        DUMMY_ITEM9,                                    // keeps IDs sychronized with Pro version
94
 
        DUMMY_ITEM10,                                   // keeps IDs sychronized with Pro version
95
 
        DUMMY_ITEM11,                                   // keeps IDs sychronized with Pro version
96
 
        DUMMY_ITEM12,                                   // keeps IDs sychronized with Pro version
97
 
        DUMMY_ITEM13,                                   // keeps IDs sychronized with Pro version
98
 
        DUMMY_ITEM14,                                   // keeps IDs sychronized with Pro version
99
 
        DUMMY_ITEM15,                                   // keeps IDs sychronized with Pro version
100
 
        DUMMY_ITEM16,                                   // keeps IDs sychronized with Pro version
101
 
        DUMMY_ITEM17,                                   // keeps IDs sychronized with Pro version
102
 
        DUMMY_ITEM18,                                   // keeps IDs sychronized with Pro version
103
 
        DUMMY_ITEM19,                                   // keeps IDs sychronized with Pro version
104
 
        NC_ACTION_VISIT_WEBSITE
105
 
};
106
 
 
107
 
//shortcut context
108
 
#define SH_CTX_GLOBAL           0
109
 
#define SH_CTX_TREE_WIDGET      1
110
 
 
111
 
class ShortcutDef
112
 
{
113
 
public:
114
 
        ShortcutDef(){};
115
 
        ShortcutDef(const ShortcutDef &other){ operator = (other); };
116
 
        ShortcutDef(int nCtx, int nID, const char *szName, int nKey, bool bShift, bool bCtrl, bool bAlt){
117
 
                m_strActionName = szName;
118
 
                m_nCtx                  = nCtx;                 //global, tree, text
119
 
                m_nActionID             = nID;
120
 
                m_nKey                  = nKey;
121
 
                m_bModShift             = bShift;
122
 
                m_bModCtrl              = bCtrl;
123
 
                m_bModAlt               = bAlt;
124
 
 
125
 
                //ASSERT(IsValid(m_nCtx));
126
 
        }
127
 
 
128
 
        void operator =(const ShortcutDef &other){
129
 
                m_strActionName = other.m_strActionName;
130
 
                m_nCtx                  = other.m_nCtx;
131
 
                m_nActionID             = other.m_nActionID;
132
 
                m_nKey                  = other.m_nKey;
133
 
                m_bModShift             = other.m_bModShift;
134
 
                m_bModCtrl              = other.m_bModCtrl;
135
 
                m_bModAlt               = other.m_bModAlt;
136
 
 
137
 
                //ASSERT(IsValid(m_nCtx));
138
 
        }
139
 
 
140
 
        bool IsValid(int nContext = SH_CTX_GLOBAL);
141
 
        bool IsEmpty(){ return (0 == m_nKey); };
142
 
 
143
 
        std::string GetDisplayString();
144
 
        int GetModifierFlags();
145
 
 
146
 
        bool Match(GdkEventKey *evnt);
147
 
 
148
 
        //comparison
149
 
        bool operator ==(const ShortcutDef &other);
150
 
 
151
 
public:
152
 
        std::string m_strActionName;
153
 
        int      m_nCtx;                        //global, tree, text
154
 
        int  m_nActionID;
155
 
        int  m_nKey;
156
 
        bool m_bModShift :1;
157
 
        bool m_bModCtrl  :1;
158
 
        bool m_bModAlt   :1;
159
 
};
160
 
 
161
 
class ShortcutsList : public std::vector<ShortcutDef>
162
 
{
163
 
public:
164
 
        ShortcutsList();
165
 
        virtual ~ShortcutsList();
166
 
 
167
 
        bool Load();
168
 
        bool Save();
169
 
 
170
 
        int     FindByKey(ShortcutDef &key, int nSkipLine=-1, int nActionID=-1);
171
 
        int     FindByAction(int nActionID, int nCtx = SH_CTX_GLOBAL);
172
 
        int     FindByContext(int nCtx, int nIdx);
173
 
 
174
 
        void UpdateAction(ShortcutDef &key);
175
 
        void ClearAction(int nActionID, int nCtx);
176
 
};
177
 
 
178
 
#endif // SHORTCUTSLIST_H__
 
1
////////////////////////////////////////////////////////////////////////////
 
2
// NoteCase notes manager project <http://notecase.sf.net>
 
3
//
 
4
// This code is licensed under BSD license.See "license.txt" for more details.
 
5
//
 
6
// File: Implements list of keyboard shortcuts for program actions
 
7
////////////////////////////////////////////////////////////////////////////
 
8
 
 
9
#ifndef SHORTCUTSLIST_H__
 
10
#define SHORTCUTSLIST_H__
 
11
 
 
12
#if _MSC_VER > 1000
 
13
#pragma once
 
14
#endif // _MSC_VER > 1000
 
15
 
 
16
#include <vector>
 
17
#include <string>
 
18
#include <gtk/gtk.h>
 
19
#include "lib/debug.h"
 
20
 
 
21
//define for each action (that can have a shortcut)
 
22
enum NC_Actions {
 
23
        NC_ACTION_DOC_NEW = 1,
 
24
        NC_ACTION_DOC_OPEN,
 
25
        NC_ACTION_DOC_SAVE,
 
26
        NC_ACTION_DOC_SAVE_AS,
 
27
        NC_ACTION_DOC_RELOAD,
 
28
        NC_ACTION_DOC_IMPORT,
 
29
        NC_ACTION_DOC_EXPORT,
 
30
        NC_ACTION_APP_NEW,
 
31
        NC_ACTION_APP_QUIT,
 
32
        NC_ACTION_TREE_NODE_NEW,
 
33
        NC_ACTION_TREE_NODE_NEW_CHILD,
 
34
        NC_ACTION_TREE_NODE_DELETE,
 
35
        NC_ACTION_TREE_NODE_RENAME,
 
36
        NC_ACTION_TREE_NODE_MOVE_UP,
 
37
        NC_ACTION_TREE_NODE_MOVE_DOWN,
 
38
        NC_ACTION_TREE_NODE_MOVE_LEFT,
 
39
        NC_ACTION_TREE_NODE_MOVE_RIGHT,
 
40
        NC_ACTION_TREE_NODE_PROPERTIES,
 
41
        NC_ACTION_TREE_NODE_DELETE_FINISHED,
 
42
        NC_ACTION_TREE_NODE_TOGGLE_FINISHED,
 
43
        NC_ACTION_TREE_SORT_CHILDREN_ASC,
 
44
        NC_ACTION_TREE_SORT_CHILDREN_DESC,
 
45
        NC_ACTION_TREE_SORT_ROOT_ASC,
 
46
        NC_ACTION_TREE_SORT_ROOT_DESC,
 
47
        NC_ACTION_TREE_EXPAND_ALL,
 
48
        NC_ACTION_TREE_COLAPSE_ALL,
 
49
        NC_ACTION_EDIT_UNDO,
 
50
        NC_ACTION_EDIT_REDO,
 
51
        NC_ACTION_EDIT_CUT,
 
52
        NC_ACTION_EDIT_COPY,
 
53
        NC_ACTION_EDIT_PASTE,
 
54
        NC_ACTION_EDIT_DELETE,
 
55
        NC_ACTION_EDIT_COPY_BR_STRUCT,  //copy branch structure
 
56
        NC_ACTION_EDIT_PASTE_BR_ROOT,   //paste branch to root
 
57
        NC_ACTION_EDIT_INSERT_DATETIME,
 
58
        NC_ACTION_EDIT_FIND,
 
59
        NC_ACTION_EDIT_FIND_NEXT,
 
60
        NC_ACTION_EDIT_REPLACE,
 
61
        NC_ACTION_EDIT_LINK_WIZARD,
 
62
        NC_ACTION_EDIT_INSERT_PICTURE,
 
63
        NC_ACTION_EDIT_ATTACHMENTS,
 
64
        NC_ACTION_EDIT_SHORTCUTS,
 
65
        NC_ACTION_EDIT_OPTIONS,
 
66
        NC_ACTION_FORMAT_BOLD,
 
67
        NC_ACTION_FORMAT_ITALIC,
 
68
        NC_ACTION_FORMAT_UNDERLINE,
 
69
        NC_ACTION_FORMAT_STRIKETHROUGH,
 
70
        NC_ACTION_FORMAT_COLOR,
 
71
        NC_ACTION_FORMAT_REMOVE,
 
72
        NC_ACTION_VIEW_TOOLBAR,
 
73
        NC_ACTION_VIEW_STATUS_BAR,
 
74
        NC_ACTION_VIEW_NODE_TITLEBAR,
 
75
        NC_ACTION_VIEW_WRAP,
 
76
        NC_ACTION_VIEW_CHANGE_MODE,
 
77
        NC_ACTION_VIEW_WORD_COUNT,
 
78
        NC_ACTION_HELP_INDEX,
 
79
        NC_ACTION_HELP_ABOUT,
 
80
        NC_ACTION_DOC_CLOSE,
 
81
        NC_ACTION_PASSWORD_CHANGE,
 
82
        DUMMY_ITEM2,                                    // keeps IDs sychronized with Pro version
 
83
        NC_ACTION_FORMAT_BKG_COLOR,
 
84
        NC_ACTION_READ_ONLY,
 
85
        NC_ACTION_VIEW_FULLSCREEN,
 
86
        DUMMY_ITEM3,                                    // keeps IDs sychronized with Pro version
 
87
        DUMMY_ITEM4,                                    // keeps IDs sychronized with Pro version
 
88
        NC_ACTION_LOCK_DOCUMENT,
 
89
        DUMMY_ITEM5,                                    // keeps IDs sychronized with Pro version
 
90
        DUMMY_ITEM6,                                    // keeps IDs sychronized with Pro version
 
91
        DUMMY_ITEM7,                                    // keeps IDs sychronized with Pro version
 
92
        DUMMY_ITEM8,                                    // keeps IDs sychronized with Pro version
 
93
        DUMMY_ITEM9,                                    // keeps IDs sychronized with Pro version
 
94
        DUMMY_ITEM10,                                   // keeps IDs sychronized with Pro version
 
95
        DUMMY_ITEM11,                                   // keeps IDs sychronized with Pro version
 
96
        DUMMY_ITEM12,                                   // keeps IDs sychronized with Pro version
 
97
        DUMMY_ITEM13,                                   // keeps IDs sychronized with Pro version
 
98
        DUMMY_ITEM14,                                   // keeps IDs sychronized with Pro version
 
99
        DUMMY_ITEM15,                                   // keeps IDs sychronized with Pro version
 
100
        DUMMY_ITEM16,                                   // keeps IDs sychronized with Pro version
 
101
        DUMMY_ITEM17,                                   // keeps IDs sychronized with Pro version
 
102
        DUMMY_ITEM18,                                   // keeps IDs sychronized with Pro version
 
103
        DUMMY_ITEM19,                                   // keeps IDs sychronized with Pro version
 
104
        NC_ACTION_VISIT_WEBSITE
 
105
};
 
106
 
 
107
//shortcut context
 
108
#define SH_CTX_GLOBAL           0
 
109
#define SH_CTX_TREE_WIDGET      1
 
110
 
 
111
class ShortcutDef
 
112
{
 
113
public:
 
114
        ShortcutDef(){};
 
115
        ShortcutDef(const ShortcutDef &other){ operator = (other); };
 
116
        ShortcutDef(int nCtx, int nID, const char *szName, int nKey, bool bShift, bool bCtrl, bool bAlt){
 
117
                m_strActionName = szName;
 
118
                m_nCtx                  = nCtx;                 //global, tree, text
 
119
                m_nActionID             = nID;
 
120
                m_nKey                  = nKey;
 
121
                m_bModShift             = bShift;
 
122
                m_bModCtrl              = bCtrl;
 
123
                m_bModAlt               = bAlt;
 
124
 
 
125
                //ASSERT(IsValid(m_nCtx));
 
126
        }
 
127
 
 
128
        void operator =(const ShortcutDef &other){
 
129
                m_strActionName = other.m_strActionName;
 
130
                m_nCtx                  = other.m_nCtx;
 
131
                m_nActionID             = other.m_nActionID;
 
132
                m_nKey                  = other.m_nKey;
 
133
                m_bModShift             = other.m_bModShift;
 
134
                m_bModCtrl              = other.m_bModCtrl;
 
135
                m_bModAlt               = other.m_bModAlt;
 
136
 
 
137
                //ASSERT(IsValid(m_nCtx));
 
138
        }
 
139
 
 
140
        bool IsValid(int nContext = SH_CTX_GLOBAL);
 
141
        bool IsEmpty(){ return (0 == m_nKey); };
 
142
 
 
143
        std::string GetDisplayString();
 
144
        int GetModifierFlags();
 
145
 
 
146
        bool Match(GdkEventKey *evnt);
 
147
 
 
148
        //comparison
 
149
        bool operator ==(const ShortcutDef &other);
 
150
 
 
151
public:
 
152
        std::string m_strActionName;
 
153
        int      m_nCtx;                        //global, tree, text
 
154
        int  m_nActionID;
 
155
        int  m_nKey;
 
156
        bool m_bModShift :1;
 
157
        bool m_bModCtrl  :1;
 
158
        bool m_bModAlt   :1;
 
159
};
 
160
 
 
161
class ShortcutsList : public std::vector<ShortcutDef>
 
162
{
 
163
public:
 
164
        ShortcutsList();
 
165
        virtual ~ShortcutsList();
 
166
 
 
167
        bool Load();
 
168
        bool Save();
 
169
 
 
170
        int     FindByKey(ShortcutDef &key, int nSkipLine=-1, int nActionID=-1);
 
171
        int     FindByAction(int nActionID, int nCtx = SH_CTX_GLOBAL);
 
172
        int     FindByContext(int nCtx, int nIdx);
 
173
 
 
174
        void UpdateAction(ShortcutDef &key);
 
175
        void ClearAction(int nActionID, int nCtx);
 
176
};
 
177
 
 
178
#endif // SHORTCUTSLIST_H__