Skip to content

Commit

Permalink
Change view menu order for right-margin and line-highlight, misc. add…
Browse files Browse the repository at this point in the history
…itional cleanups.
  • Loading branch information
David C. Rankin committed Jul 28, 2018
1 parent c3f9634 commit 8630456
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 *
Expand Down Expand Up @@ -93,15 +94,19 @@ 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.

End-of-line detection (`LF`, `CRLF` and `CR`) is provided on file-open and can be selected in the `Tools` menu. Default EOL for new files on each operating system except DOS/Windows is `LF` (line-feed), with the DOS/Windows default being `CRLF`. Pre-OSX `CR` will be detected and set on File-Open, but no specific pre-processor check tests for earlier MacOS. After open, or change of any new file, selecting a different EOL (from the `Tools menu` or within `Settings`) will convert the file to the selected EOL. `Settings->File Load/Save->End-of-Line Handling/Selection` allows for a persistent EOL to be selected along with options for `Use EOL from File` or `Use OS Default` (default). When set to anything other than `Use EOL from File`, a prompt on file-open is presented to convert to the persistent EOL setting if the file EOL differs from the persistent setting. Once open, the `Tools->End of Line Selection` operates independent of the persistent setting allowing conversion to/from any of the line endings without affecting the persistent setting.

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)

Expand Down
4 changes: 1 addition & 3 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions gtk_completionsv.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions gtk_completionsv.h
Original file line number Diff line number Diff line change
@@ -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 <gtksourceview/gtksourceview.h>
#include <gtksourceview/gtksourcecompletion.h>
Expand All @@ -10,8 +12,6 @@
#include <gtksourceview/gtksourcelanguagemanager.h>
#include <gtksourceview/completion-providers/words/gtksourcecompletionwords.h>

#include "gtk_appdata.h"

void create_completion (kwinst *app);

#endif
Expand Down
14 changes: 9 additions & 5 deletions gtk_filebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))) {
Expand All @@ -1036,16 +1040,16 @@ 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);

}

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);
Expand Down
14 changes: 7 additions & 7 deletions gtk_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions gtk_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down

0 comments on commit 8630456

Please sign in to comment.