This commit is contained in:
Perberos
2011-11-07 16:46:58 -03:00
commit 528c1e5ff5
532 changed files with 709826 additions and 0 deletions

34
plugins/docinfo/Makefile.am Executable file
View File

@@ -0,0 +1,34 @@
# docinfo plugin
plugindir = $(GEDIT_PLUGINS_LIBS_DIR)
INCLUDES = \
-I$(top_srcdir) \
$(GEDIT_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS)
plugin_LTLIBRARIES = libdocinfo.la
libdocinfo_la_SOURCES = \
gedit-docinfo-plugin.h \
gedit-docinfo-plugin.c
libdocinfo_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
libdocinfo_la_LIBADD = $(GEDIT_LIBS)
uidir = $(GEDIT_PLUGINS_DATA_DIR)/docinfo
ui_DATA = docinfo.ui
plugin_in_files = docinfo.gedit-plugin.desktop.in
%.gedit-plugin: %.gedit-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
plugin_DATA = $(plugin_in_files:.gedit-plugin.desktop.in=.gedit-plugin)
EXTRA_DIST = $(ui_DATA) $(plugin_in_files)
CLEANFILES = $(plugin_DATA)
DISTCLEANFILES = $(plugin_DATA)
-include $(top_srcdir)/git.mk

View File

@@ -0,0 +1,7 @@
[Gedit Plugin]
Module=docinfo
IAge=2
_Name=Document Statistics
_Description=Analyzes the current document and reports the number of words, lines, characters and non-space characters in it.
Authors=Paolo Maggi <paolo.maggi@polito.it>;Jorge Alberto Torres <jorge@deadoak.com>
Copyright=Copyright © 2002-2005 Paolo Maggi

621
plugins/docinfo/docinfo.ui Executable file
View File

@@ -0,0 +1,621 @@
<?xml version="1.0"?>
<!--*- mode: xml -*-->
<interface>
<object class="GtkDialog" id="dialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Document Statistics</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">False</property>
<property name="destroy_with_parent">True</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">8</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<object class="GtkButton" id="close_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="update_button">
<property name="label" translatable="yes">_Update</property>
<property name="use_underline">True</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="image">update_image</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="docinfo_dialog_content">
<property name="border_width">5</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="file_name_label">
<property name="visible">True</property>
<property name="label" translatable="yes">File Name</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
<attributes>
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
</attributes>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<object class="GtkLabel" id="label28">
<property name="visible">True</property>
<property name="label" translatable="yes"> </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkTable" id="table1">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="n_rows">6</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">18</property>
<child>
<object class="GtkLabel" id="label26">
<property name="visible">True</property>
<property name="label" translatable="yes">Bytes</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="bytes_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="label" translatable="yes">Characters (no spaces)</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="chars_ns_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes">Characters (with spaces)</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="chars_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="words_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">Words</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">Lines</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="lines_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label30">
<property name="visible">True</property>
<property name="label" translatable="yes">Document</property>
<property name="use_underline">True</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"/>
</packing>
</child>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="selection_vbox">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="selection_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Selection</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="selected_lines_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="selected_words_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="selected_chars_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="selected_chars_ns_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="selected_bytes_label">
<property name="visible">True</property>
<property name="label">0</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</object>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-7">close_button</action-widget>
<action-widget response="-5">update_button</action-widget>
</action-widgets>
</object>
<object class="GtkImage" id="update_image">
<property name="visible">True</property>
<property name="stock">gtk-refresh</property>
</object>
</interface>

View File

@@ -0,0 +1,580 @@
/*
* gedit-docinfo-plugin.c
*
* Copyright (C) 2002-2005 Paolo Maggi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "gedit-docinfo-plugin.h"
#include <string.h> /* For strlen (...) */
#include <glib/gi18n-lib.h>
#include <pango/pango-break.h>
#include <gmodule.h>
#include <gedit/gedit-debug.h>
#include <gedit/gedit-utils.h>
#define WINDOW_DATA_KEY "GeditDocInfoWindowData"
#define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_2"
GEDIT_PLUGIN_REGISTER_TYPE(GeditDocInfoPlugin, gedit_docinfo_plugin)
typedef struct
{
GtkWidget *dialog;
GtkWidget *file_name_label;
GtkWidget *lines_label;
GtkWidget *words_label;
GtkWidget *chars_label;
GtkWidget *chars_ns_label;
GtkWidget *bytes_label;
GtkWidget *selection_vbox;
GtkWidget *selected_lines_label;
GtkWidget *selected_words_label;
GtkWidget *selected_chars_label;
GtkWidget *selected_chars_ns_label;
GtkWidget *selected_bytes_label;
} DocInfoDialog;
typedef struct
{
GeditPlugin *plugin;
GtkActionGroup *ui_action_group;
guint ui_id;
DocInfoDialog *dialog;
} WindowData;
static void docinfo_dialog_response_cb (GtkDialog *widget,
gint res_id,
GeditWindow *window);
static void
docinfo_dialog_destroy_cb (GtkObject *obj,
WindowData *data)
{
gedit_debug (DEBUG_PLUGINS);
if (data != NULL)
{
g_free (data->dialog);
data->dialog = NULL;
}
}
static DocInfoDialog *
get_docinfo_dialog (GeditWindow *window,
WindowData *data)
{
DocInfoDialog *dialog;
gchar *data_dir;
gchar *ui_file;
GtkWidget *content;
GtkWidget *error_widget;
gboolean ret;
gedit_debug (DEBUG_PLUGINS);
dialog = g_new (DocInfoDialog, 1);
data_dir = gedit_plugin_get_data_dir (data->plugin);
ui_file = g_build_filename (data_dir, "docinfo.ui", NULL);
ret = gedit_utils_get_ui_objects (ui_file,
NULL,
&error_widget,
"dialog", &dialog->dialog,
"docinfo_dialog_content", &content,
"file_name_label", &dialog->file_name_label,
"words_label", &dialog->words_label,
"bytes_label", &dialog->bytes_label,
"lines_label", &dialog->lines_label,
"chars_label", &dialog->chars_label,
"chars_ns_label", &dialog->chars_ns_label,
"selection_vbox", &dialog->selection_vbox,
"selected_words_label", &dialog->selected_words_label,
"selected_bytes_label", &dialog->selected_bytes_label,
"selected_lines_label", &dialog->selected_lines_label,
"selected_chars_label", &dialog->selected_chars_label,
"selected_chars_ns_label", &dialog->selected_chars_ns_label,
NULL);
g_free (data_dir);
g_free (ui_file);
if (!ret)
{
const gchar *err_message;
err_message = gtk_label_get_label (GTK_LABEL (error_widget));
gedit_warning (GTK_WINDOW (window), "%s", err_message);
g_free (dialog);
gtk_widget_destroy (error_widget);
return NULL;
}
gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
GTK_RESPONSE_OK);
gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
GTK_WINDOW (window));
g_signal_connect (dialog->dialog,
"destroy",
G_CALLBACK (docinfo_dialog_destroy_cb),
data);
g_signal_connect (dialog->dialog,
"response",
G_CALLBACK (docinfo_dialog_response_cb),
window);
return dialog;
}
static void
calculate_info (GeditDocument *doc,
GtkTextIter *start,
GtkTextIter *end,
gint *chars,
gint *words,
gint *white_chars,
gint *bytes)
{
gchar *text;
gedit_debug (DEBUG_PLUGINS);
text = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc),
start,
end,
TRUE);
*chars = g_utf8_strlen (text, -1);
*bytes = strlen (text);
if (*chars > 0)
{
PangoLogAttr *attrs;
gint i;
attrs = g_new0 (PangoLogAttr, *chars + 1);
pango_get_log_attrs (text,
-1,
0,
pango_language_from_string ("C"),
attrs,
*chars + 1);
for (i = 0; i < (*chars); i++)
{
if (attrs[i].is_white)
++(*white_chars);
if (attrs[i].is_word_start)
++(*words);
}
g_free (attrs);
}
else
{
*white_chars = 0;
*words = 0;
}
g_free (text);
}
static void
docinfo_real (GeditDocument *doc,
DocInfoDialog *dialog)
{
GtkTextIter start, end;
gint words = 0;
gint chars = 0;
gint white_chars = 0;
gint lines = 0;
gint bytes = 0;
gchar *tmp_str;
gchar *doc_name;
gedit_debug (DEBUG_PLUGINS);
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc),
&start,
&end);
lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc));
calculate_info (doc,
&start, &end,
&chars, &words, &white_chars, &bytes);
if (chars == 0)
lines = 0;
gedit_debug_message (DEBUG_PLUGINS, "Chars: %d", chars);
gedit_debug_message (DEBUG_PLUGINS, "Lines: %d", lines);
gedit_debug_message (DEBUG_PLUGINS, "Words: %d", words);
gedit_debug_message (DEBUG_PLUGINS, "Chars non-space: %d", chars - white_chars);
gedit_debug_message (DEBUG_PLUGINS, "Bytes: %d", bytes);
doc_name = gedit_document_get_short_name_for_display (doc);
tmp_str = g_strdup_printf ("<span weight=\"bold\">%s</span>", doc_name);
gtk_label_set_markup (GTK_LABEL (dialog->file_name_label), tmp_str);
g_free (doc_name);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", lines);
gtk_label_set_text (GTK_LABEL (dialog->lines_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", words);
gtk_label_set_text (GTK_LABEL (dialog->words_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars);
gtk_label_set_text (GTK_LABEL (dialog->chars_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars - white_chars);
gtk_label_set_text (GTK_LABEL (dialog->chars_ns_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", bytes);
gtk_label_set_text (GTK_LABEL (dialog->bytes_label), tmp_str);
g_free (tmp_str);
}
static void
selectioninfo_real (GeditDocument *doc,
DocInfoDialog *dialog)
{
gboolean sel;
GtkTextIter start, end;
gint words = 0;
gint chars = 0;
gint white_chars = 0;
gint lines = 0;
gint bytes = 0;
gchar *tmp_str;
gedit_debug (DEBUG_PLUGINS);
sel = gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
&start,
&end);
if (sel)
{
lines = gtk_text_iter_get_line (&end) - gtk_text_iter_get_line (&start) + 1;
calculate_info (doc,
&start, &end,
&chars, &words, &white_chars, &bytes);
gedit_debug_message (DEBUG_PLUGINS, "Selected chars: %d", chars);
gedit_debug_message (DEBUG_PLUGINS, "Selected lines: %d", lines);
gedit_debug_message (DEBUG_PLUGINS, "Selected words: %d", words);
gedit_debug_message (DEBUG_PLUGINS, "Selected chars non-space: %d", chars - white_chars);
gedit_debug_message (DEBUG_PLUGINS, "Selected bytes: %d", bytes);
gtk_widget_set_sensitive (dialog->selection_vbox, TRUE);
}
else
{
gtk_widget_set_sensitive (dialog->selection_vbox, FALSE);
gedit_debug_message (DEBUG_PLUGINS, "Selection empty");
}
if (chars == 0)
lines = 0;
tmp_str = g_strdup_printf("%d", lines);
gtk_label_set_text (GTK_LABEL (dialog->selected_lines_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", words);
gtk_label_set_text (GTK_LABEL (dialog->selected_words_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars);
gtk_label_set_text (GTK_LABEL (dialog->selected_chars_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars - white_chars);
gtk_label_set_text (GTK_LABEL (dialog->selected_chars_ns_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", bytes);
gtk_label_set_text (GTK_LABEL (dialog->selected_bytes_label), tmp_str);
g_free (tmp_str);
}
static void
docinfo_cb (GtkAction *action,
GeditWindow *window)
{
GeditDocument *doc;
WindowData *data;
gedit_debug (DEBUG_PLUGINS);
data = (WindowData *) g_object_get_data (G_OBJECT (window),
WINDOW_DATA_KEY);
doc = gedit_window_get_active_document (window);
g_return_if_fail (doc != NULL);
if (data->dialog != NULL)
{
gtk_window_present (GTK_WINDOW (data->dialog->dialog));
gtk_widget_grab_focus (GTK_WIDGET (data->dialog->dialog));
}
else
{
DocInfoDialog *dialog;
dialog = get_docinfo_dialog (window, data);
g_return_if_fail (dialog != NULL);
data->dialog = dialog;
gtk_widget_show (GTK_WIDGET (dialog->dialog));
}
docinfo_real (doc,
data->dialog);
selectioninfo_real (doc,
data->dialog);
}
static void
docinfo_dialog_response_cb (GtkDialog *widget,
gint res_id,
GeditWindow *window)
{
WindowData *data;
gedit_debug (DEBUG_PLUGINS);
data = (WindowData *) g_object_get_data (G_OBJECT (window),
WINDOW_DATA_KEY);
switch (res_id)
{
case GTK_RESPONSE_CLOSE:
{
gedit_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CLOSE");
gtk_widget_destroy (data->dialog->dialog);
break;
}
case GTK_RESPONSE_OK:
{
GeditDocument *doc;
gedit_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK");
doc = gedit_window_get_active_document (window);
g_return_if_fail (doc != NULL);
docinfo_real (doc,
data->dialog);
selectioninfo_real (doc,
data->dialog);
break;
}
}
}
static const GtkActionEntry action_entries[] =
{
{ "DocumentStatistics",
NULL,
N_("_Document Statistics"),
NULL,
N_("Get statistical information on the current document"),
G_CALLBACK (docinfo_cb) }
};
static void
free_window_data (WindowData *data)
{
g_return_if_fail (data != NULL);
gedit_debug (DEBUG_PLUGINS);
g_object_unref (data->plugin);
g_object_unref (data->ui_action_group);
if (data->dialog != NULL)
{
gtk_widget_destroy (data->dialog->dialog);
}
g_free (data);
}
static void
update_ui_real (GeditWindow *window,
WindowData *data)
{
GeditView *view;
gedit_debug (DEBUG_PLUGINS);
view = gedit_window_get_active_view (window);
gtk_action_group_set_sensitive (data->ui_action_group,
(view != NULL));
if (data->dialog != NULL)
{
gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog->dialog),
GTK_RESPONSE_OK,
(view != NULL));
}
}
static void
gedit_docinfo_plugin_init (GeditDocInfoPlugin *plugin)
{
gedit_debug_message (DEBUG_PLUGINS, "GeditDocInfoPlugin initializing");
}
static void
gedit_docinfo_plugin_finalize (GObject *object)
{
gedit_debug_message (DEBUG_PLUGINS, "GeditDocInfoPlugin finalizing");
G_OBJECT_CLASS (gedit_docinfo_plugin_parent_class)->finalize (object);
}
static void
impl_activate (GeditPlugin *plugin,
GeditWindow *window)
{
GtkUIManager *manager;
WindowData *data;
gedit_debug (DEBUG_PLUGINS);
data = g_new (WindowData, 1);
data->plugin = g_object_ref (plugin);
data->dialog = NULL;
data->ui_action_group = gtk_action_group_new ("GeditDocInfoPluginActions");
gtk_action_group_set_translation_domain (data->ui_action_group,
GETTEXT_PACKAGE);
gtk_action_group_add_actions (data->ui_action_group,
action_entries,
G_N_ELEMENTS (action_entries),
window);
manager = gedit_window_get_ui_manager (window);
gtk_ui_manager_insert_action_group (manager,
data->ui_action_group,
-1);
data->ui_id = gtk_ui_manager_new_merge_id (manager);
g_object_set_data_full (G_OBJECT (window),
WINDOW_DATA_KEY,
data,
(GDestroyNotify) free_window_data);
gtk_ui_manager_add_ui (manager,
data->ui_id,
MENU_PATH,
"DocumentStatistics",
"DocumentStatistics",
GTK_UI_MANAGER_MENUITEM,
FALSE);
update_ui_real (window,
data);
}
static void
impl_deactivate (GeditPlugin *plugin,
GeditWindow *window)
{
GtkUIManager *manager;
WindowData *data;
gedit_debug (DEBUG_PLUGINS);
manager = gedit_window_get_ui_manager (window);
data = (WindowData *) g_object_get_data (G_OBJECT (window),
WINDOW_DATA_KEY);
g_return_if_fail (data != NULL);
gtk_ui_manager_remove_ui (manager,
data->ui_id);
gtk_ui_manager_remove_action_group (manager,
data->ui_action_group);
g_object_set_data (G_OBJECT (window),
WINDOW_DATA_KEY,
NULL);
}
static void
impl_update_ui (GeditPlugin *plugin,
GeditWindow *window)
{
WindowData *data;
gedit_debug (DEBUG_PLUGINS);
data = (WindowData *) g_object_get_data (G_OBJECT (window),
WINDOW_DATA_KEY);
g_return_if_fail (data != NULL);
update_ui_real (window,
data);
}
static void
gedit_docinfo_plugin_class_init (GeditDocInfoPluginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
object_class->finalize = gedit_docinfo_plugin_finalize;
plugin_class->activate = impl_activate;
plugin_class->deactivate = impl_deactivate;
plugin_class->update_ui = impl_update_ui;
}

View File

@@ -0,0 +1,75 @@
/*
* gedit-docinfo-plugin.h
*
* Copyright (C) 2002-2005 Paolo Maggi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
#ifndef __GEDIT_DOCINFO_PLUGIN_H__
#define __GEDIT_DOCINFO_PLUGIN_H__
#include <glib.h>
#include <glib-object.h>
#include <gedit/gedit-plugin.h>
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define GEDIT_TYPE_DOCINFO_PLUGIN (gedit_docinfo_plugin_get_type ())
#define GEDIT_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocInfoPlugin))
#define GEDIT_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocInfoPluginClass))
#define GEDIT_IS_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GEDIT_TYPE_DOCINFO_PLUGIN))
#define GEDIT_IS_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_DOCINFO_PLUGIN))
#define GEDIT_DOCINFO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocInfoPluginClass))
/* Private structure type */
typedef struct _GeditDocInfoPluginPrivate GeditDocInfoPluginPrivate;
/*
* Main object structure
*/
typedef struct _GeditDocInfoPlugin GeditDocInfoPlugin;
struct _GeditDocInfoPlugin
{
GeditPlugin parent_instance;
};
/*
* Class definition
*/
typedef struct _GeditDocInfoPluginClass GeditDocInfoPluginClass;
struct _GeditDocInfoPluginClass
{
GeditPluginClass parent_class;
};
/*
* Public methods
*/
GType gedit_docinfo_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */
G_MODULE_EXPORT GType register_gedit_plugin (GTypeModule *module);
G_END_DECLS
#endif /* __GEDIT_DOCINFO_PLUGIN_H__ */