From 863045633f8c756b9dc72323bd44faf16b5dd584 Mon Sep 17 00:00:00 2001 From: "David C. Rankin" Date: Sat, 28 Jul 2018 18:00:27 -0500 Subject: [PATCH] Change view menu order for right-margin and line-highlight, misc. additional cleanups. --- README.md | 13 +++++++++---- TODO.txt | 4 +--- gtk_completionsv.c | 7 ++++--- gtk_completionsv.h | 6 +++--- gtk_filebuf.c | 14 +++++++++----- gtk_menu.c | 14 +++++++------- gtk_settings.c | 6 +++--- 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index d4f4cb8..ace5c0a 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # gtkwrite -A small fast standalone text editor written in C using Gtk+2 and optionally GtkSourceView2 to provide syntax highlighting. The editor *does not* rely on any third-party editor component such as Scintilla. The included Makefile handles the build (details below) and packages are available for [OpenSuSE 13.1 through Leap 42.3](http://download.opensuse.org/repositories/home:/drankinatty/) and the current release and development branch builds are available for Archlinux [gtkwrite](https://aur.archlinux.org/packages/gtkwrite/) and [gtkwrite-git](https://aur.archlinux.org/packages/gtkwrite-git/). The editor can be compiled *with or without* GtkSourceView. Without GtkSourceView it will compile as `gtkedit`. With GtkSourceView it compiles as `gtkwrite` (requires GtkSourceView 2.x). Both gtkedit and gtkwrite compile and run under RaspberryPi/ARM and windows as well. (the Win-key accelerators are disabled on windows). gtkwrite is Licensed under GPLv2. +A small fast standalone text editor written in C using Gtk+2 and optionally GtkSourceView2 to provide syntax highlighting and word-completion (and other niceties). The editor is implemented with GtkTextView and *does not* rely on any third-party editor component such as Scintilla. The included Makefile handles the build (details below) and packages are available for [OpenSuSE 13.1 through Leap 15.0](http://download.opensuse.org/repositories/home:/drankinatty/) and the current release and development branch builds are available for Archlinux [gtkwrite](https://aur.archlinux.org/packages/gtkwrite/) and [gtkwrite-git](https://aur.archlinux.org/packages/gtkwrite-git/). The editor can be compiled *with or without* GtkSourceView. Without GtkSourceView it will compile as `gtkedit`. With GtkSourceView it compiles as `gtkwrite` (requires GtkSourceView 2.x). Both gtkedit and gtkwrite compile and run under RaspberryPi/ARM and windows as well. (the Win-key accelerators are disabled on windows). gtkwrite is Licensed under GPLv2. ### Feature Summary -Features include Open Recent Files listing, Reload Saved File, Print (with print to .pdf provided by native print dialog), Undo/Redo, Select All, robust Find/Replace, Goto Line, Font Selection, Increase/Decreate Indent, Fixed width Indent/Unindent, current line auto-indent, smart home/end, smart backspace, Current Line Highlight, Syntax Highlight, Line Numbering, Comment/Uncomment, Change Case (upper, lower, title), Join Lines, File Statistics (characters, words, whitespace, non-whitespace and line count), on-save trailing whitespace removal and POSIX end-of-line insertion. Custom keypress handlers for `Ctrl+Shift` selection to avoid default handling annoyances. End-of-line detection and conversion between LF, CRLF and CR with persistent setting to use file EOL or Operating System default EOL with prompt for conversion on file open. External File Insertion within an open buffer, Insert of Date/Time both as a menu-iterm & tool-button. GIO File Monitoring for modification by foreign process. Interface provdes menu, configurable toolbar that can be shown/hidden and statusbar. Syntax language and style selection when compiled with GtkSourceView2. Correctly detects all Byte Order Marks, but currently handles only ASCII/UTF-8 character set. +Features include Open Recent Files listing, Reload Saved File, Print (with print to .pdf provided by native print dialog), Undo/Redo, Select All, robust Find/Replace, Goto Line, Font Selection, Increase/Decreate Indent, Fixed width Indent/Unindent, current line auto-indent, smart home/end, smart backspace, Current Line Highlight, Show/Hide Right Margin at any column, Syntax Highlight, Line Numbering, Comment/Uncomment, Change Case (upper, lower, title), Join Lines, File Statistics (characters, words, whitespace, non-whitespace and line count), on-save trailing whitespace removal and POSIX end-of-line insertion. Basic word-completion is provided by GtkSourceView. Custom keypress handlers for `Ctrl+Shift` selection to avoid default textview handling annoyances. End-of-line detection and conversion between LF, CRLF and CR with persistent setting to use file EOL or Operating System default EOL with prompt for conversion on file open. External File Insertion within an open buffer, Insert of Date/Time both as a menu-iterm & tool-button. GIO File Monitoring for modification by foreign process. Interface provdes menu, configurable toolbar that can be shown/hidden and statusbar. Syntax language and style selection when compiled with GtkSourceView2. Correctly detects all Byte Order Marks, but currently handles only ASCII/UTF-8 character sets. ### Menu Layout/Use @@ -47,6 +47,7 @@ The editor has the following menu layout and shortcut key layout (if you are com - Text Only - Icons Only - Text & Icons + - Show/Hide Right Margin Ctrl+M * - Current Line Highlight Shift+Ctrl+H * - Syntax Highlight Shift+Alt+H * + Syntax Language * @@ -93,7 +94,11 @@ The editor has a full menubar and toolbar that can be shown/hidden and set to di The editor at present operates in a single-document-interface manner where requesting a 'New' document from the File menu will open another copy of the editor in its very own and separate window. Development is working toward a multi-document-interface where multiple files/buffers can be open within a single application window with the current document determined by selecting a document list on the left side of the edit window. -Configurable indent/unindent with align to softtab and separate indent/unindent by an absolute number of characters are provided. Default settings provide auto-indent for code layout and smart_backspace (unindent in leading whitespace). Selected sections of code can be commented/uncommented based on the string set in Preferences->Editing->Single-line comment. (autorecognition of file type and multi-line comemnt characters remain to be implemented). The editor also provides case-conversion, lower-to-upper, upper-to-lower, and title-case. Join lines will join any number of selected lines replacing all intervening whitespace with a single space. Current window size can be saved (if clicked), otherwise the window size on exit is saved for next use if restore window size at start is selected. +Configurable indent/unindent with align to softtab and separate indent/unindent by an absolute number of characters are provided. Default settings provide auto-indent for code layout and smart_backspace (unindent in leading whitespace). Selected sections of code can be commented/uncommented based on the string set in Preferences->Editing->Single-line comment or with autorecognition of file-type using multi-line block comemnt syntax for the appropriate language. A configurable right-margin visible guide can be shown/hidden at any column based on the value set in Settings->Appearence->Visual aids. (defautl 80 column, min 1, max 120 column) It has no effect on word-wrap, it is just a convenient visual reference for the column. + +The editor provides case-conversion, lower-to-upper, upper-to-lower, and title-case. Join lines will join any number of selected lines replacing all intervening whitespace with a single space. Current window size can be saved (if clicked), otherwise the window size on exit is saved for next use if restore window size at start is selected. + +Word-completion is provided by GtkSourceView. [Return] is used to activate the selected proposal. Word-completion can be enabled/disabed in Settings->File Load/Save->Word-completion. (disabling word-completion takes effect on the next buffer, e.g. next file opened) A custom keypress input handler for `Ctrl+Shift+Right-Arrow` and `Ctrl+Shift+Left-Arrow` to correct the annoying default gtk handler that will *select-to-end-of-next-word* when used in leading whitespace instead of the desired behavior of *select-to-beginning-of-next-word*. A configuration option in Settings, `Appearance->Cursor & Selection->Ctrl + Shift + Right-Arrow fix`. This enables a corresponding keypress handler for `Ctrl+Shift+Left-Arrow` and small stack to track sequential `Ctrl+Shift+Left/Right` events. This is set on by default. To restore default gtk handling, simply uncheck the box in settings. @@ -101,7 +106,7 @@ End-of-line detection (`LF`, `CRLF` and `CR`) is provided on file-open and can b Byte Order Mark (BOM) detection of all (UTF-8, UTF-16 (BE/LE), UTF-32 (BE/LE), UTF-7, UTF-1, UTF-EBCDIC, SCSU, BOCU-1, and GB-18030), but currently ASCII/UTF-8 is the only encoding handled by the editor. Work is progressing on character set handling for UTF-16/32 as well as on conversion routines between the different encodings. -When compiled with GtkSourceView, syntax highlighting, syntax languange selection and selectable syntax style (color schemes) are enabled in the View menu. The provided custom styles, 'styles/gtkwrite.xml' and 'styles/gtkwrite_light.xml' provide an alternative to the default styles and works well for C or bash. Both styles are continually being refined. You may install the syles folder in the normal global search location of '/usr/share/gtksourceview-2.0/' or on a per-user basis in '~/.local/share/gtksourceview-2.0/'. (for win32, install in the gtk-runtime directory structure) Single line and block-comemnts are automatically set and functional based on the sourceview language. At present all single-line comments (which can be applied to a selected block of text as well) and multi-line comment blocks are automatically handled for `ada asp awk c c-sharp cmake cpp desktop diff dosbatch erlang fortran gtkrc haskell html java js lua makefile objc octave pascal perl php python rpmspec ruby sql sh vbnet xml`. Multi-line block comment start and end strings are also set based on language detected and used by default when text is selected on the screen. (this behavior is configurable in Settings (edit)). You can check Settings page to verify whether comment syntax was automatically determined for your language. If not, you can set the single-line comment to be applied as needed by your project. +When compiled with GtkSourceView, syntax highlighting, syntax language selection and selectable syntax style (color schemes) are enabled in the View menu. The provided custom styles, 'styles/gtkwrite.xml' and 'styles/gtkwrite_light.xml' provide an alternative to the default styles and works well for C or bash. Both styles are continually being refined. You may install the syles folder in the normal global search location of '/usr/share/gtksourceview-2.0/' or on a per-user basis in '~/.local/share/gtksourceview-2.0/'. (for win32, install in the gtk-runtime directory structure) Single line and block-comemnts are automatically set and functional based on the sourceview language. At present all single-line comments (which can be applied to a selected block of text as well) and multi-line comment blocks are automatically handled for `ada asp awk c c-sharp cmake cpp desktop diff dosbatch erlang fortran gtkrc haskell html java js lua makefile objc octave pascal perl php python rpmspec ruby sql sh vbnet xml`. Multi-line block comment start and end strings are also set based on language detected and used by default when text is selected on the screen. (this behavior is configurable in Settings (edit)). You can check Settings page to verify whether comment syntax was automatically determined for your language. If not, you can set the single-line comment to be applied as needed by your project. (*Note:* for builds without GtkSourceView2, the single line comment can be set in Settings and it will be applied with the comment/uncomment commands. The automatic table lookup provided by GtkSourceView2 simply overrides this setting for the current file based on the language) diff --git a/TODO.txt b/TODO.txt index 608b870..aba705b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -21,8 +21,6 @@ file/buffer * fix auto-indent - if in col[0] of 2nd indented line, return inserts additional softtab. verify current line not already indented. - * complete 'else' in buffer_insert_file for Position cursor at end to get iterator at beginning and set insert mark. - menu/toolbar * complete @@ -37,7 +35,7 @@ save settings - * complete + * save individual file history and restore to last line/col. MainWindow0:ViewSpaceContainer-0:-ViewSpace 0 file:///home/david/dev/git/gtkwrite/gtk_filebuf.c] CursorColumn=37 diff --git a/gtk_completionsv.c b/gtk_completionsv.c index 737e0c0..3b3f3e5 100644 --- a/gtk_completionsv.c +++ b/gtk_completionsv.c @@ -1,8 +1,9 @@ -static const int stub; +#include "gtk_completionsv.h" -#if defined (WGTKSOURCEVIEW2) || defined (WGTKSOURCEVIEW3) || defined (WGTKSOURCEVIEW4) +gchar stub (void) /* NOP to prevent empty compilation unit */ +{ return 0; } /* when compiling without GtkSourceView */ -#include "gtk_completionsv.h" +#ifdef HAVESOURCEVIEW typedef struct _cmplprovider cmplprovider; typedef struct _cmplproviderClass cmplproviderClass; diff --git a/gtk_completionsv.h b/gtk_completionsv.h index f089a63..668aa09 100644 --- a/gtk_completionsv.h +++ b/gtk_completionsv.h @@ -1,7 +1,9 @@ #ifndef __completionsv_h__ #define __completionsv_h__ 1 -#if defined (WGTKSOURCEVIEW2) || defined (WGTKSOURCEVIEW3) || defined (WGTKSOURCEVIEW4) +#include "gtk_appdata.h" + +#ifdef HAVESOURCEVIEW #include #include @@ -10,8 +12,6 @@ #include #include -#include "gtk_appdata.h" - void create_completion (kwinst *app); #endif diff --git a/gtk_filebuf.c b/gtk_filebuf.c index 5b5ad44..2767ca3 100644 --- a/gtk_filebuf.c +++ b/gtk_filebuf.c @@ -1020,8 +1020,12 @@ void buffer_write_file (kwinst *app, gchar *filename) void gtkwrite_window_set_title (GtkWidget *widget, kwinst *app) { - /* TODO: create common set title function for all dialogs */ - /* (e.g. if (widget == app->window), then window title, else dialog */ + /* TODO: create common set title function for all dialogs + * (e.g. if (widget == app->window), then window title, else dialog + * + * FIXME: tooltip commented below activates *within* window, not titlebar + * need to find way to set tooltip for titlebar only. + */ gchar *title = NULL; // gchar *longtitle = NULL; if ((app->modified = gtk_text_buffer_get_modified (GTK_TEXT_BUFFER(app->buffer)))) { @@ -1036,8 +1040,7 @@ void gtkwrite_window_set_title (GtkWidget *widget, kwinst *app) else { if (app->fname) { title = g_strdup_printf ("%s - %s", app->appshort, app->fname); - // longtitle = g_strdup_printf ("%s - %s", app->appshort, app->filename);; - + // longtitle = g_strdup_printf ("%s - %s", app->appshort, app->filename); } else title = g_strdup_printf ("%s - untitled", app->appshort); @@ -1045,7 +1048,8 @@ void gtkwrite_window_set_title (GtkWidget *widget, kwinst *app) } gtk_window_set_title (GTK_WINDOW (app->window), title); - // gtk_widget_set_tooltip_text (app->window, longtitle); + // if (longtitle) + // gtk_widget_set_tooltip_text (app->window, longtitle); g_free (title); // g_free (longtitle); diff --git a/gtk_menu.c b/gtk_menu.c index f421220..ea17053 100644 --- a/gtk_menu.c +++ b/gtk_menu.c @@ -338,12 +338,12 @@ GtkWidget *create_menubar (kwinst *app, GtkAccelGroup *mainaccel) // tbiconsMi = gtk_menu_item_new_with_mnemonic ("_Icons Only"); // tbbothMi = gtk_menu_item_new_with_mnemonic ("_Both Text & Icons"); #ifdef HAVESOURCEVIEW - linehlMi = gtk_image_menu_item_new_from_stock (GTK_STOCK_INDEX, - NULL); - gtk_menu_item_set_label (GTK_MENU_ITEM (linehlMi), "_Current Line Highlight"); marginMi = gtk_image_menu_item_new_from_stock (GTK_STOCK_GOTO_LAST, NULL); gtk_menu_item_set_label (GTK_MENU_ITEM (marginMi), "Show/Hide Right _Margin"); + linehlMi = gtk_image_menu_item_new_from_stock (GTK_STOCK_INDEX, + NULL); + gtk_menu_item_set_label (GTK_MENU_ITEM (linehlMi), "_Current Line Highlight"); syntaxMi = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_COLOR, NULL); gtk_menu_item_set_label (GTK_MENU_ITEM (syntaxMi), "Syntax _Highlight (on/off)"); @@ -375,8 +375,8 @@ GtkWidget *create_menubar (kwinst *app, GtkAccelGroup *mainaccel) #ifdef HAVESOURCEVIEW gtk_menu_shell_append (GTK_MENU_SHELL (viewMenu), gtk_separator_menu_item_new()); - gtk_menu_shell_append (GTK_MENU_SHELL (viewMenu), linehlMi); gtk_menu_shell_append (GTK_MENU_SHELL (viewMenu), marginMi); + gtk_menu_shell_append (GTK_MENU_SHELL (viewMenu), linehlMi); gtk_menu_shell_append (GTK_MENU_SHELL (viewMenu), gtk_separator_menu_item_new()); gtk_menu_shell_append (GTK_MENU_SHELL (viewMenu), syntaxMi); @@ -404,12 +404,12 @@ GtkWidget *create_menubar (kwinst *app, GtkAccelGroup *mainaccel) GDK_KEY_t, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); #ifdef HAVESOURCEVIEW - gtk_widget_add_accelerator (linehlMi, "activate", mainaccel, - GDK_KEY_h, GDK_CONTROL_MASK | GDK_SHIFT_MASK, - GTK_ACCEL_VISIBLE); gtk_widget_add_accelerator (marginMi, "activate", mainaccel, GDK_KEY_m, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); + gtk_widget_add_accelerator (linehlMi, "activate", mainaccel, + GDK_KEY_h, GDK_CONTROL_MASK | GDK_SHIFT_MASK, + GTK_ACCEL_VISIBLE); gtk_widget_add_accelerator (syntaxMi, "activate", mainaccel, GDK_KEY_h, GDK_MOD1_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE); diff --git a/gtk_settings.c b/gtk_settings.c index d9c3865..5233ad7 100644 --- a/gtk_settings.c +++ b/gtk_settings.c @@ -63,9 +63,9 @@ GtkWidget *create_settings_dlg (kwinst *app) GtkObject *adjind; /* adjustment - indent spinbutton */ GtkObject *adjrec; /* adjustment - recent spinbutton */ - gint wnwidth = 480; /* initial dialog width and height */ - gint wnheight = 520; - gint pgwidth = 400; /* initial notebook page width and height */ + gint wnwidth = 500; /* initial dialog width and height */ + gint wnheight = 520; /* maintian wnwidth - pgwidth = 80 */ + gint pgwidth = 420; /* initial notebook page width and height */ gint pgheight = 440; /* (enforced by vboxnb width/height) */ /* MS Windows required additional space. */