[ghex] Change some shortcuts and add new ones.
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex] Change some shortcuts and add new ones.
- Date: Wed, 8 Dec 2021 18:03:21 +0000 (UTC)
commit 7d01640f724eb62a289048d94c5694a9340f953e
Author: Logan Rathbone <poprocks gmail com>
Date: Wed Dec 8 13:02:21 2021 -0500
Change some shortcuts and add new ones.
src/ghex-application-window.c | 43 ++++++
src/gtkhex.c | 342 ++++++++++++++++++++++++------------------
src/help-overlay.ui | 129 +++++++++++++---
3 files changed, 353 insertions(+), 161 deletions(-)
---
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 7ea9e25..e4f7834 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -1787,6 +1787,18 @@ ghex_application_window_class_init(GHexApplicationWindowClass *klass)
"ghex.about",
NULL); /* no args. */
+ /* Insert - toggle insert mode */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_Insert,
+ 0,
+ "ghex.insert-mode",
+ NULL); /* no args. */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_KP_Insert,
+ 0,
+ "ghex.insert-mode",
+ NULL); /* no args. */
+
/* Ctrl+F - find */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_f,
@@ -1822,6 +1834,34 @@ ghex_application_window_class_init(GHexApplicationWindowClass *klass)
"ghex.copy-special",
NULL);
+ /* Ctrl+N - new */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_n,
+ GDK_CONTROL_MASK,
+ "ghex.new",
+ NULL);
+
+ /* Ctrl+O - open */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_o,
+ GDK_CONTROL_MASK,
+ "ghex.open",
+ NULL);
+
+ /* Ctrl+S - save */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_s,
+ GDK_CONTROL_MASK,
+ "ghex.save",
+ NULL);
+
+ /* Ctrl+Shift+S - save as */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_s,
+ GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "ghex.save-as",
+ NULL);
+
/* Ctrl+P - print */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_p,
@@ -1836,6 +1876,9 @@ ghex_application_window_class_init(GHexApplicationWindowClass *klass)
close_tab_shortcut_cb,
NULL);
+ /* In case you're looking for Ctrl+PageUp & PageDown - those are baked in
+ * via GtkNotebook */
+
/* WIDGET TEMPLATE .UI */
gtk_widget_class_set_template_from_resource (widget_class,
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 1a90fb1..6265cf9 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -199,6 +199,8 @@ static void gtk_hex_update_auto_highlight(GtkHex *gh, GtkHex_AutoHighlight *ahl,
static void recalc_displays(GtkHex *gh);
+static void show_cursor (GtkHex *gh, gboolean show);
+
/* GtkHex - Method Definitions */
static void
@@ -311,6 +313,30 @@ undo_action (GtkWidget *widget,
}
}
+static void
+toggle_hex_action (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter)
+{
+ GtkHex *gh = GTK_HEX (widget);
+
+ gh->active_view = VIEW_HEX;
+ gtk_widget_queue_draw (widget);
+// show_cursor (gh, TRUE);
+}
+
+static void
+toggle_ascii_action (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter)
+{
+ GtkHex *gh = GTK_HEX (widget);
+
+ gh->active_view = VIEW_ASCII;
+ gtk_widget_queue_draw (widget);
+// show_cursor (gh, TRUE);
+}
+
/*
* ?_to_pointer translates mouse coordinates in hex/ascii view
* to cursor coordinates.
@@ -1467,8 +1493,8 @@ key_press_cb (GtkEventControllerKey *controller,
file_size = hex_document_get_file_size (gh->document);
- /* don't trample over Ctrl */
- if (state & GDK_CONTROL_MASK) {
+ /* don't trample over Ctrl or Alt (reserved for actions) */
+ if (state & GDK_CONTROL_MASK || state & GDK_ALT_MASK) {
return FALSE;
}
@@ -1484,152 +1510,162 @@ key_press_cb (GtkEventControllerKey *controller,
/* FIXME - This could use a cleanup. Mostly flown in from old code.
*/
- switch(keyval) {
- case GDK_KEY_BackSpace:
- if(gh->cursor_pos > 0) {
- hex_document_set_data(gh->document, gh->cursor_pos - 1,
- 0, 1, NULL, TRUE);
- if (gh->selecting)
- gh->selecting = FALSE;
- gtk_hex_set_cursor(gh, gh->cursor_pos - 1);
- }
- break;
- case GDK_KEY_Tab:
- case GDK_KEY_KP_Tab:
- if (gh->active_view == VIEW_ASCII) {
- gh->active_view = VIEW_HEX;
- }
- else {
- gh->active_view = VIEW_ASCII;
- }
- break;
- case GDK_KEY_Delete:
- if (gh->cursor_pos < file_size) {
- hex_document_set_data(gh->document, gh->cursor_pos,
- 0, 1, NULL, TRUE);
- gtk_hex_set_cursor(gh, gh->cursor_pos);
- }
- break;
- case GDK_KEY_Up:
- gtk_hex_set_cursor(gh, gh->cursor_pos - gh->cpl);
- break;
- case GDK_KEY_Down:
- gtk_hex_set_cursor(gh, gh->cursor_pos + gh->cpl);
- break;
- case GDK_KEY_Page_Up:
- gtk_hex_set_cursor(gh, MAX(0, gh->cursor_pos - gh->vis_lines*gh->cpl));
- break;
- case GDK_KEY_Page_Down:
- gtk_hex_set_cursor(gh,
- MIN(file_size,
- gh->cursor_pos + gh->vis_lines*gh->cpl));
- break;
- default:
- if (state & GDK_ALT_MASK) {
- show_cursor (gh, TRUE);
- return FALSE;
- }
- if(gh->active_view == VIEW_HEX)
- switch(keyval) {
- case GDK_KEY_Left:
- if(!(state & GDK_SHIFT_MASK)) {
- gh->lower_nibble = !gh->lower_nibble;
- if(gh->lower_nibble)
- gtk_hex_set_cursor(gh, gh->cursor_pos - 1);
- }
- else {
- gtk_hex_set_cursor(gh, gh->cursor_pos - 1);
- }
- break;
- case GDK_KEY_Right:
- if(gh->cursor_pos >= file_size)
- break;
- if(!(state & GDK_SHIFT_MASK)) {
- gh->lower_nibble = !gh->lower_nibble;
- if(!gh->lower_nibble)
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- }
- else {
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- }
- break;
- default:
- if((keyval >= '0')&&(keyval <= '9')) {
- hex_document_set_nibble(gh->document, keyval - '0',
- gh->cursor_pos,
gh->lower_nibble,
- gh->insert, TRUE);
- if (gh->selecting)
- gh->selecting = FALSE;
- gh->lower_nibble = !gh->lower_nibble;
- if(!gh->lower_nibble)
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- }
- else if((keyval >= 'A')&&(keyval <= 'F')) {
- hex_document_set_nibble(gh->document, keyval - 'A' + 10,
- gh->cursor_pos,
gh->lower_nibble,
- gh->insert, TRUE);
- if (gh->selecting)
- gh->selecting = FALSE;
- gh->lower_nibble = !gh->lower_nibble;
- if(!gh->lower_nibble)
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- }
- else if((keyval >= 'a')&&(keyval <= 'f')) {
- hex_document_set_nibble(gh->document, keyval - 'a' + 10,
- gh->cursor_pos,
gh->lower_nibble,
- gh->insert, TRUE);
- if (gh->selecting)
- gh->selecting = FALSE;
- gh->lower_nibble = !gh->lower_nibble;
- if(!gh->lower_nibble)
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- }
- else if((keyval >= GDK_KEY_KP_0)&&(keyval <= GDK_KEY_KP_9)) {
- hex_document_set_nibble(gh->document, keyval - GDK_KEY_KP_0,
- gh->cursor_pos,
gh->lower_nibble,
- gh->insert, TRUE);
- if (gh->selecting)
- gh->selecting = FALSE;
- gh->lower_nibble = !gh->lower_nibble;
- if(!gh->lower_nibble)
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- }
- else
- ret = FALSE;
+ switch(keyval)
+ {
+ case GDK_KEY_BackSpace:
+ if (gh->cursor_pos > 0) {
+ hex_document_set_data(gh->document, gh->cursor_pos - 1,
+ 0, 1, NULL, TRUE);
+ if (gh->selecting)
+ gh->selecting = FALSE;
+ gtk_hex_set_cursor(gh, gh->cursor_pos - 1);
+ }
+ break;
- break;
+ case GDK_KEY_Delete:
+ if (gh->cursor_pos < file_size) {
+ hex_document_set_data(gh->document, gh->cursor_pos,
+ 0, 1, NULL, TRUE);
+ gtk_hex_set_cursor(gh, gh->cursor_pos);
}
- else if(gh->active_view == VIEW_ASCII)
- switch(keyval) {
- case GDK_KEY_Left:
- gtk_hex_set_cursor(gh, gh->cursor_pos - 1);
- break;
- case GDK_KEY_Right:
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- break;
- default:
- if(is_displayable(keyval)) {
- hex_document_set_byte(gh->document, keyval,
- gh->cursor_pos, gh->insert,
TRUE);
- if (gh->selecting)
- gh->selecting = FALSE;
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
- }
- else if((keyval >= GDK_KEY_KP_0)&&(keyval <= GDK_KEY_KP_9)) {
- hex_document_set_byte(gh->document, keyval - GDK_KEY_KP_0 + '0',
- gh->cursor_pos,
gh->insert, TRUE);
- if (gh->selecting)
- gh->selecting = FALSE;
- gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ break;
+
+ case GDK_KEY_Up:
+ gtk_hex_set_cursor(gh, gh->cursor_pos - gh->cpl);
+ break;
+
+ case GDK_KEY_Down:
+ gtk_hex_set_cursor(gh, gh->cursor_pos + gh->cpl);
+ break;
+
+ case GDK_KEY_Page_Up:
+ gtk_hex_set_cursor(gh, MAX(0, gh->cursor_pos - gh->vis_lines*gh->cpl));
+ break;
+
+ case GDK_KEY_Page_Down:
+ gtk_hex_set_cursor(gh, MIN(file_size,
+ gh->cursor_pos + gh->vis_lines*gh->cpl));
+ break;
+
+ default:
+ if (gh->active_view == VIEW_HEX)
+ {
+ switch(keyval)
+ {
+ case GDK_KEY_Left:
+ if (state & GDK_SHIFT_MASK) {
+ gtk_hex_set_cursor (gh, gh->cursor_pos - 1);
+ }
+ else {
+ gh->lower_nibble = !gh->lower_nibble;
+ if (gh->lower_nibble)
+ gtk_hex_set_cursor (gh, gh->cursor_pos - 1);
+ }
+ break;
+
+ case GDK_KEY_Right:
+ if (gh->cursor_pos >= file_size)
+ break;
+
+ if (state & GDK_SHIFT_MASK) {
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ else {
+ gh->lower_nibble = !gh->lower_nibble;
+ if(!gh->lower_nibble)
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ break;
+
+ default:
+ if (keyval >= '0' && keyval <= '9')
+ {
+ hex_document_set_nibble(gh->document, keyval - '0',
+ gh->cursor_pos, gh->lower_nibble,
+ gh->insert, TRUE);
+ if (gh->selecting)
+ gh->selecting = FALSE;
+ gh->lower_nibble = !gh->lower_nibble;
+ if(!gh->lower_nibble)
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ else if (keyval >= 'A' && keyval <= 'F')
+ {
+ hex_document_set_nibble(gh->document, keyval - 'A' +
10,
+ gh->cursor_pos, gh->lower_nibble,
+ gh->insert, TRUE);
+ if (gh->selecting)
+ gh->selecting = FALSE;
+ gh->lower_nibble = !gh->lower_nibble;
+ if (!gh->lower_nibble)
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ else if (keyval >= 'a' && keyval <= 'f')
+ {
+ hex_document_set_nibble(gh->document, keyval - 'a' +
10,
+ gh->cursor_pos, gh->lower_nibble,
+ gh->insert, TRUE);
+ if (gh->selecting)
+ gh->selecting = FALSE;
+ gh->lower_nibble = !gh->lower_nibble;
+ if (!gh->lower_nibble)
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ else if (keyval >= GDK_KEY_KP_0 && keyval <= GDK_KEY_KP_9)
+ {
+ hex_document_set_nibble(gh->document, keyval -
GDK_KEY_KP_0,
+ gh->cursor_pos, gh->lower_nibble,
+ gh->insert, TRUE);
+ if (gh->selecting)
+ gh->selecting = FALSE;
+ gh->lower_nibble = !gh->lower_nibble;
+ if(!gh->lower_nibble)
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ else
+ ret = FALSE;
+
+ break;
}
- else
- ret = FALSE;
+ }
+ else /* VIEW_ASCII */
+ {
+ switch (keyval)
+ {
+ case GDK_KEY_Left:
+ gtk_hex_set_cursor(gh, gh->cursor_pos - 1);
+ break;
- break;
+ case GDK_KEY_Right:
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ break;
+
+ default:
+ if (is_displayable (keyval))
+ {
+ hex_document_set_byte(gh->document, keyval,
+ gh->cursor_pos, gh->insert, TRUE);
+ if (gh->selecting)
+ gh->selecting = FALSE;
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ else if (keyval >= GDK_KEY_KP_0 && keyval <= GDK_KEY_KP_9)
+ {
+ hex_document_set_byte(gh->document, keyval -
GDK_KEY_KP_0 + '0',
+ gh->cursor_pos, gh->insert, TRUE);
+ if (gh->selecting)
+ gh->selecting = FALSE;
+ gtk_hex_set_cursor(gh, gh->cursor_pos + 1);
+ }
+ else
+ {
+ ret = FALSE;
+ }
+ break;
+ }
}
- break;
+ break;
}
-
show_cursor (gh, TRUE);
return ret;
@@ -2319,6 +2355,14 @@ gtk_hex_class_init (GtkHexClass *klass)
NULL,
redo_action);
+ gtk_widget_class_install_action (widget_class, "gtkhex.toggle-hex",
+ NULL,
+ toggle_hex_action);
+
+ gtk_widget_class_install_action (widget_class, "gtkhex.toggle-ascii",
+ NULL,
+ toggle_ascii_action);
+
/* SHORTCUTS FOR ACTIONS (not to be confused with keybindings, which are
* set up in gtk_hex_init) */
@@ -2356,6 +2400,20 @@ gtk_hex_class_init (GtkHexClass *klass)
GDK_CONTROL_MASK,
"gtkhex.redo",
NULL);
+
+ /* Alt+Left - toggle hex display */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_Left,
+ GDK_ALT_MASK,
+ "gtkhex.toggle-hex",
+ NULL);
+
+ /* Alt+Right - toggle ascii display */
+ gtk_widget_class_add_binding_action (widget_class,
+ GDK_KEY_Right,
+ GDK_ALT_MASK,
+ "gtkhex.toggle-ascii",
+ NULL);
}
static void
diff --git a/src/help-overlay.ui b/src/help-overlay.ui
index 0d66b68..61addac 100644
--- a/src/help-overlay.ui
+++ b/src/help-overlay.ui
@@ -9,6 +9,76 @@
<object class="GtkShortcutsSection">
<property name="max-height">12</property>
+ <child>
+ <object class="GtkShortcutsGroup">
+ <property name="title" translatable="true">Files</property>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>n</property>
+ <property name="title"
translatable="true">New blank hex buffer</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>o</property>
+ <property name="title"
translatable="true">Open a file for editing</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>s</property>
+ <property name="title"
translatable="true">Save file</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control><Shift>s</property>
+ <property name="title"
translatable="true">Save as</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>w</property>
+ <property name="title"
translatable="true">Close tab</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>p</property>
+ <property name="title"
translatable="true">Print the hex file</property>
+ </object>
+ </child>
+
+ </object>
+ </child> <!-- /Files -->
+
+ <child>
+ <object class="GtkShortcutsGroup">
+ <property name="title" translatable="true">Undo and
Redo</property>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>z</property>
+ <property name="title"
translatable="true">Undo</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>y</property>
+ <property name="title"
translatable="true">Redo</property>
+ </object>
+ </child>
+
+ </object>
+ </child> <!-- /Undo and Redo -->
+
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="true">Find and
Replace</property>
@@ -27,13 +97,6 @@
</object>
</child>
- <child>
- <object class="GtkShortcutsShortcut">
- <property
name="accelerator"><Control>j</property>
- <property name="title"
translatable="true">Jump to byte</property>
- </object>
- </child>
-
</object>
</child> <!-- /Find and Replace -->
@@ -41,6 +104,27 @@
<object class="GtkShortcutsGroup">
<property name="title"
translatable="true">Clipboard</property>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>c</property>
+ <property name="title"
translatable="true">Copy</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>x</property>
+ <property name="title"
translatable="true">Cut</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>v</property>
+ <property name="title"
translatable="true">Paste</property>
+ </object>
+ </child>
+
<child>
<object class="GtkShortcutsShortcut">
<property
name="accelerator"><Control><Shift>c</property>
@@ -56,23 +140,30 @@
</child>
</object>
- </child> <!-- /Data Operations -->
+ </child> <!-- /Clipboard -->
<child>
<object class="GtkShortcutsGroup">
- <property name="title" translatable="true">Files</property>
+ <property name="title"
translatable="true">Navigation</property>
<child>
<object class="GtkShortcutsShortcut">
- <property
name="accelerator"><Control>w</property>
- <property name="title"
translatable="true">Close tab</property>
+ <property
name="accelerator"><Alt>Left</property>
+ <property name="title"
translatable="true">Toggle left (hex) display</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
- <property
name="accelerator"><Control>s</property>
- <property name="title"
translatable="true">Save file</property>
+ <property
name="accelerator"><Alt>Right</property>
+ <property name="title"
translatable="true">Toggle right (ASCII) display</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property
name="accelerator"><Control>Page_Up</property>
+ <property name="title"
translatable="true">Switch to previous tab</property>
</object>
</child>
@@ -82,16 +173,16 @@
<property name="title"
translatable="true">Switch to next tab</property>
</object>
</child>
-
+
<child>
<object class="GtkShortcutsShortcut">
- <property
name="accelerator"><Control>Page_Up</property>
- <property name="title"
translatable="true">Switch to previous tab</property>
+ <property
name="accelerator"><Control>j</property>
+ <property name="title"
translatable="true">Jump to byte</property>
</object>
</child>
</object>
- </child> <!-- /Files -->
+ </child> <!-- /Navigation -->
<child>
<object class="GtkShortcutsGroup">
@@ -106,8 +197,8 @@
<child>
<object class="GtkShortcutsShortcut">
- <property
name="accelerator"><Control>p</property>
- <property name="title"
translatable="true">Print the hex file</property>
+ <property name="accelerator">Insert</property>
+ <property name="title"
translatable="true">Toggle insert mode</property>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]