SF.net SVN: geany:[5904] trunk
colombanw at users.sourceforge.net
colombanw at xxxxx
Thu Aug 25 20:15:02 UTC 2011
Revision: 5904
http://geany.svn.sourceforge.net/geany/?rev=5904&view=rev
Author: colombanw
Date: 2011-08-25 20:15:02 +0000 (Thu, 25 Aug 2011)
Log Message:
-----------
Add menu items to detect indentation settings from document's content
Modified Paths:
--------------
trunk/ChangeLog
trunk/geany.glade
trunk/src/callbacks.c
trunk/src/callbacks.h
trunk/src/document.c
trunk/src/document.h
trunk/src/interface.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-08-25 20:14:40 UTC (rev 5903)
+++ trunk/ChangeLog 2011-08-25 20:15:02 UTC (rev 5904)
@@ -6,6 +6,10 @@
#3339420 and #3390435).
* src/callbacks.c, src/editor.c, src/editor.h:
Add editor_set_indent_width() to only set indentation width.
+ * src/callbacks.c, src/callbacks.h, src/document.c, src/document.h,
+ src/interface.c, geany.glade:
+ Add menu items to detect indentation settings from document's
+ content.
2011-08-24 Colomban Wendling <colomban(at)geany(dot)org>
Modified: trunk/geany.glade
===================================================================
--- trunk/geany.glade 2011-08-25 20:14:40 UTC (rev 5903)
+++ trunk/geany.glade 2011-08-25 20:15:02 UTC (rev 5904)
@@ -1416,6 +1416,21 @@
<widget class="GtkMenu" id="indent_type1_menu">
<child>
+ <widget class="GtkMenuItem" id="detect_type_from_file">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Detect from Content</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_detect_type_from_file_activate" last_modification_time="Thu, 25 Aug 2011 15:36:43 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separator61">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
<widget class="GtkRadioMenuItem" id="tabs1">
<property name="visible">True</property>
<property name="label" translatable="yes">_Tabs</property>
@@ -1461,6 +1476,21 @@
<widget class="GtkMenu" id="indent_width1_menu">
<child>
+ <widget class="GtkMenuItem" id="detect_width_from_file">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Detect from Content</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_detect_width_from_file_activate" last_modification_time="Thu, 25 Aug 2011 15:36:43 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="separator62">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
<widget class="GtkRadioMenuItem" id="indent_width_1">
<property name="visible">True</property>
<property name="label" translatable="yes">_1</property>
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2011-08-25 20:14:40 UTC (rev 5903)
+++ trunk/src/callbacks.c 2011-08-25 20:15:02 UTC (rev 5904)
@@ -2101,3 +2101,29 @@
{
keybindings_send_command(GEANY_KEY_GROUP_SEARCH, GEANY_KEYS_SEARCH_MARKALL);
}
+
+
+void on_detect_type_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GeanyDocument *doc = document_get_current();
+ GeanyIndentType type;
+
+ if (doc != NULL && document_detect_indent_type(doc, &type))
+ {
+ editor_set_indent_type(doc->editor, type);
+ ui_document_show_hide(doc);
+ }
+}
+
+
+void on_detect_width_from_file_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GeanyDocument *doc = document_get_current();
+ gint width;
+
+ if (doc != NULL && document_detect_indent_width(doc, &width))
+ {
+ editor_set_indent_width(doc->editor, width);
+ ui_document_show_hide(doc);
+ }
+}
Modified: trunk/src/callbacks.h
===================================================================
--- trunk/src/callbacks.h 2011-08-25 20:14:40 UTC (rev 5903)
+++ trunk/src/callbacks.h 2011-08-25 20:15:02 UTC (rev 5904)
@@ -662,3 +662,11 @@
void
on_mark_all1_activate (GtkMenuItem *menuitem,
gpointer user_data);
+
+void
+on_detect_type_from_file_activate (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+void
+on_detect_width_from_file_activate (GtkMenuItem *menuitem,
+ gpointer user_data);
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2011-08-25 20:14:40 UTC (rev 5903)
+++ trunk/src/document.c 2011-08-25 20:15:02 UTC (rev 5904)
@@ -952,8 +952,9 @@
/* Detect the indent type based on counting the leading indent characters for each line.
* Returns whether detection succeeded, and the detected type in *type_ upon success */
-static gboolean detect_indent_type(GeanyEditor *editor, GeanyIndentType *type_)
+gboolean document_detect_indent_type(GeanyDocument *doc, GeanyIndentType *type_)
{
+ GeanyEditor *editor = doc->editor;
ScintillaObject *sci = editor->sci;
gint line, line_count;
gsize tabs = 0, spaces = 0;
@@ -1052,13 +1053,20 @@
}
+/* same as detect_indent_width() but uses editor's indent type */
+gboolean document_detect_indent_width(GeanyDocument *doc, gint *width_)
+{
+ return detect_indent_width(doc->editor, doc->editor->indent_type, width_);
+}
+
+
void document_apply_indent_settings(GeanyDocument *doc)
{
const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(NULL);
GeanyIndentType type = iprefs->type;
gint width = iprefs->width;
- if (iprefs->detect_type && detect_indent_type(doc->editor, &type))
+ if (iprefs->detect_type && document_detect_indent_type(doc, &type))
{
if (type != iprefs->type)
{
Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h 2011-08-25 20:14:40 UTC (rev 5903)
+++ trunk/src/document.h 2011-08-25 20:15:02 UTC (rev 5904)
@@ -33,6 +33,7 @@
#include "Scintilla.h"
#include "ScintillaWidget.h"
+#include "editor.h"
#if defined(G_OS_WIN32)
# define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_CRLF
@@ -260,6 +261,10 @@
gboolean document_need_save_as(GeanyDocument *doc);
+gboolean document_detect_indent_type(GeanyDocument *doc, GeanyIndentType *type_);
+
+gboolean document_detect_indent_width(GeanyDocument *doc, gint *width_);
+
void document_apply_indent_settings(GeanyDocument *doc);
gint document_compare_by_display_name(gconstpointer a, gconstpointer b);
Modified: trunk/src/interface.c
===================================================================
--- trunk/src/interface.c 2011-08-25 20:14:40 UTC (rev 5903)
+++ trunk/src/interface.c 2011-08-25 20:15:02 UTC (rev 5904)
@@ -197,12 +197,16 @@
GtkWidget *menu_use_auto_indentation1;
GtkWidget *indent_type1;
GtkWidget *indent_type1_menu;
+ GtkWidget *detect_type_from_file;
+ GtkWidget *separator61;
GSList *tabs1_group = NULL;
GtkWidget *tabs1;
GtkWidget *spaces1;
GtkWidget *tabs_and_spaces1;
GtkWidget *indent_width1;
GtkWidget *indent_width1_menu;
+ GtkWidget *detect_width_from_file;
+ GtkWidget *separator62;
GSList *indent_width_1_group = NULL;
GtkWidget *indent_width_1;
GtkWidget *indent_width_2;
@@ -987,6 +991,15 @@
indent_type1_menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (indent_type1), indent_type1_menu);
+ detect_type_from_file = gtk_menu_item_new_with_mnemonic (_("_Detect from Content"));
+ gtk_widget_show (detect_type_from_file);
+ gtk_container_add (GTK_CONTAINER (indent_type1_menu), detect_type_from_file);
+
+ separator61 = gtk_separator_menu_item_new ();
+ gtk_widget_show (separator61);
+ gtk_container_add (GTK_CONTAINER (indent_type1_menu), separator61);
+ gtk_widget_set_sensitive (separator61, FALSE);
+
tabs1 = gtk_radio_menu_item_new_with_mnemonic (tabs1_group, _("_Tabs"));
tabs1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (tabs1));
gtk_widget_show (tabs1);
@@ -1012,6 +1025,15 @@
indent_width1_menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (indent_width1), indent_width1_menu);
+ detect_width_from_file = gtk_menu_item_new_with_mnemonic (_("_Detect from Content"));
+ gtk_widget_show (detect_width_from_file);
+ gtk_container_add (GTK_CONTAINER (indent_width1_menu), detect_width_from_file);
+
+ separator62 = gtk_separator_menu_item_new ();
+ gtk_widget_show (separator62);
+ gtk_container_add (GTK_CONTAINER (indent_width1_menu), separator62);
+ gtk_widget_set_sensitive (separator62, FALSE);
+
indent_width_1 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_1"));
indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_1));
gtk_widget_show (indent_width_1);
@@ -1683,6 +1705,9 @@
g_signal_connect ((gpointer) menu_use_auto_indentation1, "toggled",
G_CALLBACK (on_use_auto_indentation1_toggled),
NULL);
+ g_signal_connect ((gpointer) detect_type_from_file, "activate",
+ G_CALLBACK (on_detect_type_from_file_activate),
+ NULL);
g_signal_connect ((gpointer) tabs1, "activate",
G_CALLBACK (on_tabs1_activate),
NULL);
@@ -1692,6 +1717,9 @@
g_signal_connect ((gpointer) tabs_and_spaces1, "activate",
G_CALLBACK (on_tabs_and_spaces1_activate),
NULL);
+ g_signal_connect ((gpointer) detect_width_from_file, "activate",
+ G_CALLBACK (on_detect_width_from_file_activate),
+ NULL);
g_signal_connect ((gpointer) indent_width_1, "activate",
G_CALLBACK (on_indent_width_activate),
NULL);
@@ -1982,11 +2010,15 @@
GLADE_HOOKUP_OBJECT (window1, menu_use_auto_indentation1, "menu_use_auto_indentation1");
GLADE_HOOKUP_OBJECT (window1, indent_type1, "indent_type1");
GLADE_HOOKUP_OBJECT (window1, indent_type1_menu, "indent_type1_menu");
+ GLADE_HOOKUP_OBJECT (window1, detect_type_from_file, "detect_type_from_file");
+ GLADE_HOOKUP_OBJECT (window1, separator61, "separator61");
GLADE_HOOKUP_OBJECT (window1, tabs1, "tabs1");
GLADE_HOOKUP_OBJECT (window1, spaces1, "spaces1");
GLADE_HOOKUP_OBJECT (window1, tabs_and_spaces1, "tabs_and_spaces1");
GLADE_HOOKUP_OBJECT (window1, indent_width1, "indent_width1");
GLADE_HOOKUP_OBJECT (window1, indent_width1_menu, "indent_width1_menu");
+ GLADE_HOOKUP_OBJECT (window1, detect_width_from_file, "detect_width_from_file");
+ GLADE_HOOKUP_OBJECT (window1, separator62, "separator62");
GLADE_HOOKUP_OBJECT (window1, indent_width_1, "indent_width_1");
GLADE_HOOKUP_OBJECT (window1, indent_width_2, "indent_width_2");
GLADE_HOOKUP_OBJECT (window1, indent_width_3, "indent_width_3");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list